Skip to content

Commit 897e5bc

Browse files
committed
Further in-code commenting
1 parent 9eed457 commit 897e5bc

File tree

6 files changed

+68
-39
lines changed

6 files changed

+68
-39
lines changed

include/openPMD/IO/AbstractIOHandlerImpl.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ class AbstractIOHandlerImpl
338338
* The attribute should be of datatype parameters.dtype.
339339
* Any existing attribute with the same name should be overwritten. If possible, only the value should be changed if the datatype stays the same.
340340
* The attribute should be written to physical storage after the operation completes successfully.
341+
* If the parameter changesOverSteps is true, then the attribute must be able
342+
* to hold different values across IO steps. If the backend does not support
343+
* IO steps in such a way, the attribute should not be written.
344+
* (IO steps are an optional backend feature and the frontend must implement
345+
* fallback measures in such a case)
341346
* All datatypes of Datatype should be supported in a type-safe way.
342347
*/
343348
virtual void writeAttribute(Writable*, Parameter< Operation::WRITE_ATT > const&) = 0;

include/openPMD/Iteration.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ class Iteration : public LegacyAttributable
256256
auxiliary::Option< std::deque< uint64_t > >;
257257

258258
AdvanceStatus stepStatus{};
259+
/*
260+
* If the iteration attribute `snapshot` is present, the value of that
261+
* attribute. Otherwise empty.
262+
*/
259263
AvailableIterations_t iterationsInOpenedStep;
260264

261265
inline operator AdvanceStatus() const

include/openPMD/Series.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ class SeriesImpl : public AttributableImpl
387387
* Note on re-parsing of a Series:
388388
* If init == false, the parsing process will seek for new
389389
* Iterations/Records/Record Components etc.
390+
* If series.iterations contains the attribute `snapshot`, returns its
391+
* value (will only be true in variable-based iteration encoding).
390392
*/
391393
auxiliary::Option< std::deque< uint64_t > >
392394
readGorVBased( bool init = true );

src/Iteration.cpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -556,43 +556,43 @@ auto Iteration::beginStep() -> BeginStepStatus
556556
internal::AttributableData * file = nullptr;
557557
switch( series.iterationEncoding() )
558558
{
559-
case IE::fileBased:
560-
file = m_attributableData.get();
561-
break;
562-
case IE::groupBased:
563-
case IE::variableBased:
564-
file = &series;
565-
break;
566-
}
559+
case IE::fileBased:
560+
file = m_attributableData.get();
561+
break;
562+
case IE::groupBased:
563+
case IE::variableBased:
564+
file = &series;
565+
break;
566+
}
567567

568-
AdvanceStatus status = series.advance(
569-
AdvanceMode::BEGINSTEP, *file, series.indexOf( *this ), *this );
570-
switch( status )
571-
{
572-
case AdvanceStatus::OVER:
573-
res.stepStatus = status;
574-
return res;
575-
case AdvanceStatus::OK:
576-
case AdvanceStatus::RANDOMACCESS:
577-
break;
578-
}
568+
AdvanceStatus status = series.advance(
569+
AdvanceMode::BEGINSTEP, *file, series.indexOf( *this ), *this );
570+
switch( status )
571+
{
572+
case AdvanceStatus::OVER:
573+
res.stepStatus = status;
574+
return res;
575+
case AdvanceStatus::OK:
576+
case AdvanceStatus::RANDOMACCESS:
577+
break;
578+
}
579579

580-
// re-read -> new datasets might be available
581-
if( ( series.iterationEncoding() == IE::groupBased ||
582-
series.iterationEncoding() == IE::variableBased ) &&
583-
( this->IOHandler()->m_frontendAccess == Access::READ_ONLY ||
584-
this->IOHandler()->m_frontendAccess == Access::READ_WRITE ) )
585-
{
586-
bool previous = series.iterations.written();
587-
series.iterations.written() = false;
588-
auto oldType = this->IOHandler()->m_frontendAccess;
589-
auto newType =
590-
const_cast< Access * >( &this->IOHandler()->m_frontendAccess );
591-
*newType = Access::READ_WRITE;
592-
res.iterationsInOpenedStep = series.readGorVBased( false );
593-
*newType = oldType;
594-
series.iterations.written() = previous;
595-
}
580+
// re-read -> new datasets might be available
581+
if( ( series.iterationEncoding() == IE::groupBased ||
582+
series.iterationEncoding() == IE::variableBased ) &&
583+
( this->IOHandler()->m_frontendAccess == Access::READ_ONLY ||
584+
this->IOHandler()->m_frontendAccess == Access::READ_WRITE ) )
585+
{
586+
bool previous = series.iterations.written();
587+
series.iterations.written() = false;
588+
auto oldType = this->IOHandler()->m_frontendAccess;
589+
auto newType =
590+
const_cast< Access * >( &this->IOHandler()->m_frontendAccess );
591+
*newType = Access::READ_WRITE;
592+
res.iterationsInOpenedStep = series.readGorVBased( false );
593+
*newType = oldType;
594+
series.iterations.written() = previous;
595+
}
596596

597597
res.stepStatus = status;
598598
return res;

src/ReadIterations.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@ SeriesIterator::SeriesIterator( Series series )
8383
Iteration::BeginStepStatus::AvailableIterations_t
8484
availableIterations;
8585
std::tie( status, availableIterations ) = it->second.beginStep();
86-
if( availableIterations.has_value() )
86+
/*
87+
* In random-access mode, do not use the information read in the
88+
* `snapshot` attribute, instead simply go through iterations
89+
* one by one in ascending order (fallback implementation in the
90+
* second if branch).
91+
*/
92+
if( availableIterations.has_value() &&
93+
status != AdvanceStatus::RANDOMACCESS )
8794
{
8895
m_iterationsInCurrentStep = availableIterations.get();
8996
if( !m_iterationsInCurrentStep.empty() )
@@ -173,9 +180,12 @@ SeriesIterator & SeriesIterator::operator++()
173180
series.iterations[ m_currentIteration ].beginStep();
174181
return *this;
175182
}
176-
throw std::runtime_error( "Control flow error!" );
183+
throw std::runtime_error( "Unreachable!" );
177184
}
178185

186+
// The currently active iterations have been exhausted.
187+
// Now see if there are further iterations to be found.
188+
179189
if( series.iterationEncoding() == IterationEncoding::fileBased )
180190
{
181191
// this one is handled above, stream is over once it proceeds to here
@@ -193,8 +203,9 @@ SeriesIterator & SeriesIterator::operator++()
193203
AdvanceStatus status;
194204
Iteration::BeginStepStatus::AvailableIterations_t availableIterations;
195205
std::tie( status, availableIterations ) = currentIteration.beginStep();
196-
if( availableIterations.has_value()
197-
&& status != AdvanceStatus::RANDOMACCESS )
206+
207+
if( availableIterations.has_value() &&
208+
status != AdvanceStatus::RANDOMACCESS )
198209
{
199210
m_iterationsInCurrentStep = availableIterations.get();
200211
}

src/Series.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,13 @@ SeriesImpl::readGorVBased( bool do_init )
10841084
[ &series ]() -> auxiliary::Option< std::vector< uint64_t > >
10851085
{
10861086
using vec_t = std::vector< uint64_t >;
1087+
/*
1088+
* In variable-based iteration encoding, iterations have no distinct
1089+
* group within `series.iterations`, meaning that the `snapshot`
1090+
* attribute is not found at `/data/0/snapshot`, but at
1091+
* `/data/snapshot`. This makes it possible to retrieve it from
1092+
* `series.iterations`.
1093+
*/
10871094
if( series.iterations.containsAttribute( "snapshot" ) )
10881095
{
10891096
auto const & attribute =

0 commit comments

Comments
 (0)