Skip to content

Commit db5f0a7

Browse files
committed
Code cleanup and in-code documentation
1 parent c12d8fc commit db5f0a7

8 files changed

Lines changed: 68 additions & 27 deletions

File tree

include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ class ADIOS2IOHandlerImpl
225225

226226
private:
227227
adios2::ADIOS m_ADIOS;
228+
/*
229+
* If the iteration encoding is variableBased, we default to using the
230+
* 2021_02_09 schema since it allows mutable attributes.
231+
*/
228232
IterationEncoding m_iterationEncoding = IterationEncoding::groupBased;
229233
/**
230234
* The ADIOS2 engine type, to be passed to adios2::IO::SetEngine
@@ -1369,7 +1373,7 @@ class ADIOS2IOHandler : public AbstractIOHandler
13691373
{
13701374
#if openPMD_HAVE_ADIOS2
13711375

1372-
friend class ADIOS2IOHandlerImpl;
1376+
friend class ADIOS2IOHandlerImpl;
13731377

13741378
private:
13751379
ADIOS2IOHandlerImpl m_impl;

include/openPMD/IO/IOTask.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ struct OPENPMDAPI_EXPORT Parameter< Operation::OPEN_FILE > : public AbstractPara
138138
}
139139

140140
std::string name = "";
141+
/*
142+
* The backends might need to ensure availability of certain features
143+
* for some iteration encodings, e.g. availability of ADIOS steps for
144+
* variableBased encoding.
145+
*/
141146
IterationEncoding encoding = IterationEncoding::groupBased;
142147
};
143148

include/openPMD/Iteration.hpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,25 @@ class Iteration : public LegacyAttributable
156156

157157
struct DeferredParseAccess
158158
{
159+
/**
160+
* The group path within /data containing this iteration.
161+
* Example: "1" for iteration 1, "" in variable-based iteration
162+
* encoding.
163+
*/
159164
std::string path;
165+
/**
166+
* The iteration index as accessed by the user in series.iterations[i]
167+
*/
160168
uint64_t iteration = 0;
169+
/**
170+
* If this iteration is part of a Series with file-based layout.
171+
* (Group- and variable-based parsing shares the same code logic.)
172+
*/
161173
bool fileBased = false;
174+
/**
175+
* If fileBased == true, the file name (without file path) of the file
176+
* containing this iteration.
177+
*/
162178
std::string filename;
163179
};
164180

@@ -179,11 +195,15 @@ class Iteration : public LegacyAttributable
179195
* allow for those different control flows.
180196
* Finally, read_impl() is called which contains the common parsing
181197
* logic for an iteration.
198+
*
199+
* reread() reads again an Iteration that has been previously read.
200+
* Calling it on an Iteration not yet parsed is an error.
182201
*
183202
*/
184-
void read( std::string path, bool reread = false );
203+
void read();
204+
void reread( std::string const & path );
185205
void readFileBased( std::string filePath, std::string const & groupPath );
186-
void readGroupBased( std::string const & groupPath );
206+
void readGorVBased( std::string const & groupPath );
187207
void read_impl( std::string const & groupPath );
188208

189209
/**

include/openPMD/Series.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ class SeriesImpl : public AttributableImpl
260260
*/
261261
IterationEncoding iterationEncoding() const;
262262
/** Set the <A HREF="https://github.com/openPMD/openPMD-standard/blob/latest/STANDARD.md#iterations-and-time-series">encoding style</A> for multiple iterations in this series.
263+
* A preview on the <A HREF="https://github.com/openPMD/openPMD-standard/pull/250">openPMD 2.0 variable-based iteration encoding</A> can be activated with this call.
264+
* Making full use of the variable-based iteration encoding requires (1) explicit support by the backend (available only in ADIOS2) and (2) use of the openPMD streaming API.
265+
* In other backends and without the streaming API, only one iteration/snapshot may be written in the variable-based encoding, making this encoding a good choice for single-snapshot data dumps.
263266
*
264267
* @param iterationEncoding Desired <A HREF="https://github.com/openPMD/openPMD-standard/blob/latest/STANDARD.md#iterations-and-time-series">encoding style</A> for multiple iterations in this series.
265268
* @return Reference to modified series.

include/openPMD/backend/Container.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,14 @@ class Container : public LegacyAttributable
326326

327327
std::shared_ptr< InternalContainer > m_container;
328328

329+
/**
330+
* This class wraps a Container and forwards operator[]() and at() to it.
331+
* It remembers the keys used for accessing. Upon going out of scope, all
332+
* keys not yet accessed are removed from the Container.
333+
* Note that the container is stored by non-owning reference, thus
334+
* requiring that the original Container stay in scope while using this
335+
* class.
336+
*/
329337
class EraseStaleEntries
330338
{
331339
std::set< key_type > m_accessedKeys;

src/Iteration.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,8 @@ void Iteration::deferParseAccess( DeferredParseAccess dr )
334334
auxiliary::makeOption< DeferredParseAccess >( std::move( dr ) );
335335
}
336336

337-
void Iteration::read( std::string path, bool reread )
337+
void Iteration::read()
338338
{
339-
if( reread )
340-
{
341-
read_impl( path );
342-
return;
343-
}
344339
if( !m_deferredParseAccess->has_value() )
345340
{
346341
return;
@@ -352,12 +347,23 @@ void Iteration::read( std::string path, bool reread )
352347
}
353348
else
354349
{
355-
readGroupBased( deferred.path );
350+
readGorVBased( deferred.path );
356351
}
357352
// reset this thing
358353
*m_deferredParseAccess = auxiliary::Option< DeferredParseAccess >();
359354
}
360355

356+
void Iteration::reread( std::string const & path )
357+
{
358+
if( m_deferredParseAccess->has_value() )
359+
{
360+
throw std::runtime_error(
361+
"[Iteration] Internal control flow error: Trying to reread an "
362+
"iteration that has not yet been read for its first time." );
363+
}
364+
read_impl( path );
365+
}
366+
361367
void Iteration::readFileBased(
362368
std::string filePath, std::string const & groupPath )
363369
{
@@ -368,7 +374,7 @@ void Iteration::readFileBased(
368374
read_impl( groupPath );
369375
}
370376

371-
void Iteration::readGroupBased( std::string const & groupPath )
377+
void Iteration::readGorVBased( std::string const & groupPath )
372378
{
373379

374380
read_impl(groupPath );
@@ -687,7 +693,7 @@ void Iteration::runDeferredParseAccess()
687693
*newAccess = Access::READ_WRITE;
688694
try
689695
{
690-
read( "", false );
696+
read();
691697
}
692698
catch( ... )
693699
{

src/Mesh.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,6 @@ Mesh::flush_impl(std::string const& name)
247247
void
248248
Mesh::read()
249249
{
250-
/*
251-
* @todo This is a proof-of-concept on how we need to rework our re-parsing
252-
* procedures. Goals when parsing an iteration again:
253-
* 1. Old handles must survive
254-
* 2. Map entries that cannot be found any more must perish.
255-
* @todo This approach will kill references that users may have to mapped
256-
* components, so improve that.
257-
*/
258250
auto map = eraseStaleEntries();
259251

260252
using DT = Datatype;

src/Series.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -910,12 +910,15 @@ void SeriesImpl::readOneIterationFileBased( std::string const & filePath )
910910
}
911911
else if( encoding == "variableBased" )
912912
{
913-
// @todo should we throw? test this path
914-
series.m_iterationEncoding = IterationEncoding::variableBased;
915-
std::cerr << "Series constructor called with iteration "
916-
"regex '%T' suggests loading a "
917-
<< "time series with fileBased iteration "
918-
"encoding. Loaded file is variableBased.\n";
913+
/*
914+
* Unlike if the file were group-based, this one doesn't work
915+
* at all since the group paths are different.
916+
*/
917+
throw std::runtime_error(
918+
"Series constructor called with iteration "
919+
"regex '%T' suggests loading a "
920+
"time series with fileBased iteration "
921+
"encoding. Loaded file is variableBased." );
919922
}
920923
else
921924
throw std::runtime_error(
@@ -1043,7 +1046,7 @@ SeriesImpl::readGorVBased( bool do_init )
10431046
{
10441047
pOpen.path = path;
10451048
IOHandler()->enqueue( IOTask( &i, pOpen ) );
1046-
i.read( path, /* reread = */ true );
1049+
i.reread( path );
10471050
}
10481051
}
10491052
else

0 commit comments

Comments
 (0)