Skip to content

Commit 21418ce

Browse files
committed
Code cleanup and in-code documentation
1 parent 7bde65b commit 21418ce

File tree

8 files changed

+68
-27
lines changed

8 files changed

+68
-27
lines changed

include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp

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

221221
private:
222222
adios2::ADIOS m_ADIOS;
223+
/*
224+
* If the iteration encoding is variableBased, we default to using the
225+
* 2021_02_09 schema since it allows mutable attributes.
226+
*/
223227
IterationEncoding m_iterationEncoding = IterationEncoding::groupBased;
224228
/**
225229
* The ADIOS2 engine type, to be passed to adios2::IO::SetEngine
@@ -1305,7 +1309,7 @@ class ADIOS2IOHandler : public AbstractIOHandler
13051309
{
13061310
#if openPMD_HAVE_ADIOS2
13071311

1308-
friend class ADIOS2IOHandlerImpl;
1312+
friend class ADIOS2IOHandlerImpl;
13091313

13101314
private:
13111315
ADIOS2IOHandlerImpl m_impl;

include/openPMD/IO/IOTask.hpp

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

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

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
@@ -259,6 +259,9 @@ class SeriesImpl : public AttributableImpl
259259
*/
260260
IterationEncoding iterationEncoding() const;
261261
/** 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.
262+
* 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.
263+
* 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.
264+
* 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.
262265
*
263266
* @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.
264267
* @return Reference to modified series.

include/openPMD/backend/Container.hpp

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

293293
std::shared_ptr< InternalContainer > m_container;
294294

295+
/**
296+
* This class wraps a Container and forwards operator[]() and at() to it.
297+
* It remembers the keys used for accessing. Upon going out of scope, all
298+
* keys not yet accessed are removed from the Container.
299+
* Note that the container is stored by non-owning reference, thus
300+
* requiring that the original Container stay in scope while using this
301+
* class.
302+
*/
295303
class EraseStaleEntries
296304
{
297305
std::set< key_type > m_accessedKeys;

src/Iteration.cpp

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

327-
void Iteration::read( std::string path, bool reread )
327+
void Iteration::read()
328328
{
329-
if( reread )
330-
{
331-
read_impl( path );
332-
return;
333-
}
334329
if( !m_deferredParseAccess->has_value() )
335330
{
336331
return;
@@ -342,12 +337,23 @@ void Iteration::read( std::string path, bool reread )
342337
}
343338
else
344339
{
345-
readGroupBased( deferred.path );
340+
readGorVBased( deferred.path );
346341
}
347342
// reset this thing
348343
*m_deferredParseAccess = auxiliary::Option< DeferredParseAccess >();
349344
}
350345

346+
void Iteration::reread( std::string const & path )
347+
{
348+
if( m_deferredParseAccess->has_value() )
349+
{
350+
throw std::runtime_error(
351+
"[Iteration] Internal control flow error: Trying to reread an "
352+
"iteration that has not yet been read for its first time." );
353+
}
354+
read_impl( path );
355+
}
356+
351357
void Iteration::readFileBased(
352358
std::string filePath, std::string const & groupPath )
353359
{
@@ -358,7 +364,7 @@ void Iteration::readFileBased(
358364
read_impl( groupPath );
359365
}
360366

361-
void Iteration::readGroupBased( std::string const & groupPath )
367+
void Iteration::readGorVBased( std::string const & groupPath )
362368
{
363369

364370
read_impl(groupPath );
@@ -665,7 +671,7 @@ void Iteration::runDeferredParseAccess()
665671
*newAccess = Access::READ_WRITE;
666672
try
667673
{
668-
read( "", false );
674+
read();
669675
}
670676
catch( ... )
671677
{

src/Mesh.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,6 @@ Mesh::flush_impl(std::string const& name)
235235
void
236236
Mesh::read()
237237
{
238-
/*
239-
* @todo This is a proof-of-concept on how we need to rework our re-parsing
240-
* procedures. Goals when parsing an iteration again:
241-
* 1. Old handles must survive
242-
* 2. Map entries that cannot be found any more must perish.
243-
* @todo This approach will kill references that users may have to mapped
244-
* components, so improve that.
245-
*/
246238
auto map = eraseStaleEntries();
247239

248240
using DT = Datatype;

src/Series.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -893,12 +893,15 @@ void SeriesImpl::readOneIterationFileBased( std::string const & filePath )
893893
}
894894
else if( encoding == "variableBased" )
895895
{
896-
// @todo should we throw? test this path
897-
series.m_iterationEncoding = IterationEncoding::variableBased;
898-
std::cerr << "Series constructor called with iteration "
899-
"regex '%T' suggests loading a "
900-
<< "time series with fileBased iteration "
901-
"encoding. Loaded file is variableBased.\n";
896+
/*
897+
* Unlike if the file were group-based, this one doesn't work
898+
* at all since the group paths are different.
899+
*/
900+
throw std::runtime_error(
901+
"Series constructor called with iteration "
902+
"regex '%T' suggests loading a "
903+
"time series with fileBased iteration "
904+
"encoding. Loaded file is variableBased." );
902905
}
903906
else
904907
throw std::runtime_error(
@@ -1026,7 +1029,7 @@ SeriesImpl::readGorVBased( bool do_init )
10261029
{
10271030
pOpen.path = path;
10281031
IOHandler()->enqueue( IOTask( &i, pOpen ) );
1029-
i.read( path, /* reread = */ true );
1032+
i.reread( path );
10301033
}
10311034
}
10321035
else

0 commit comments

Comments
 (0)