Skip to content

Commit 6bb3c8a

Browse files
committed
Avoid infinite loops if there is no stream active
The backends will explicitly report in their status if it is currently random-accessing. The frontend will then fall back to stepping linearly.
1 parent 9e9cc88 commit 6bb3c8a

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

include/openPMD/IO/AbstractIOHandlerImpl.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ class AbstractIOHandlerImpl
153153
* The return status code shall be stored as parameters.status.
154154
*/
155155
virtual void
156-
advance( Writable *, Parameter< Operation::ADVANCE > & )
157-
{}
156+
advance( Writable *, Parameter< Operation::ADVANCE > & parameters )
157+
{
158+
*parameters.status = AdvanceStatus::RANDOMACCESS;
159+
}
158160

159161
/** Close an openPMD group.
160162
*

include/openPMD/Streaming.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ namespace openPMD
1919
*/
2020
enum class AdvanceStatus : unsigned char
2121
{
22-
OK, /* stream goes on */
23-
OVER /* stream is over */
22+
OK, /* stream goes on */
23+
OVER, /* stream is over */
24+
RANDOMACCESS /* there is no stream, it will never be over */
2425
};
2526

2627
/**

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2534,7 +2534,7 @@ namespace detail
25342534
m_IO.DefineAttribute< bool_representation >(
25352535
ADIOS2Defaults::str_usesstepsAttribute, 0 );
25362536
flush( /* writeAttributes = */ false );
2537-
return AdvanceStatus::OK;
2537+
return AdvanceStatus::RANDOMACCESS;
25382538
}
25392539

25402540
m_IO.DefineAttribute< bool_representation >(

src/ReadIterations.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ 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+
if( availableIterations.has_value()
87+
&& status != AdvanceStatus::RANDOMACCESS )
8788
{
8889
m_iterationsInCurrentStep = availableIterations.get();
8990
if( !m_iterationsInCurrentStep.empty() )
@@ -188,7 +189,8 @@ SeriesIterator & SeriesIterator::operator++()
188189
AdvanceStatus status;
189190
Iteration::BeginStepStatus::AvailableIterations_t availableIterations;
190191
std::tie( status, availableIterations ) = currentIteration.beginStep();
191-
if( availableIterations.has_value() )
192+
if( availableIterations.has_value()
193+
&& status != AdvanceStatus::RANDOMACCESS )
192194
{
193195
m_iterationsInCurrentStep = availableIterations.get();
194196
}

0 commit comments

Comments
 (0)