Skip to content

Commit 1e33d86

Browse files
committed
Do not automatically open an Iteration
1 parent 4009784 commit 1e33d86

3 files changed

Lines changed: 59 additions & 14 deletions

File tree

include/openPMD/Iteration.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,12 @@ class Iteration : public LegacyAttributable
190190
*/
191191
enum class CloseStatus
192192
{
193+
NotYetAccessed,
193194
Open, //!< Iteration has not been closed
194195
ClosedInFrontend, /*!< Iteration has been closed, but task has not yet
195196
been propagated to the backend */
196-
ClosedInBackend, /*!< Iteration has been closed and task has been
197-
propagated to the backend */
197+
ClosedInBackend, /*!< Iteration has been closed and task has been
198+
propagated to the backend */
198199
ClosedTemporarily /*!< Iteration has been closed internally and may
199200
be reopened later */
200201
};

src/Iteration.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,10 @@ Iteration::close( bool _flush )
106106
*m_closed = CloseStatus::ClosedInBackend;
107107
}
108108
break;
109+
case CloseStatus::NotYetAccessed:
109110
case CloseStatus::ClosedInBackend:
110111
// just keep it like it is
111112
break;
112-
default:
113-
throw std::runtime_error( "Unreachable!" );
114113
}
115114
if( _flush )
116115
{
@@ -145,6 +144,10 @@ Iteration::close( bool _flush )
145144
Iteration &
146145
Iteration::open()
147146
{
147+
if( *m_closed == CloseStatus::NotYetAccessed )
148+
{
149+
*m_closed = CloseStatus::Open;
150+
}
148151
accessLazily();
149152
internal::SeriesInternal * s = &retrieveSeries();
150153
// figure out my iteration number
@@ -164,6 +167,7 @@ Iteration::closed() const
164167
{
165168
switch( *m_closed )
166169
{
170+
case CloseStatus::NotYetAccessed:
167171
case CloseStatus::Open:
168172
/*
169173
* Temporarily closing a file is something that the openPMD API

src/Series.cpp

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,10 @@ SeriesImpl::flushFileBased( iterations_iterator begin, iterations_iterator end )
500500
if( IOHandler()->m_frontendAccess == Access::READ_ONLY )
501501
for( auto it = begin; it != end; ++it )
502502
{
503+
if( *it->second.m_closed == Iteration::CloseStatus::NotYetAccessed )
504+
{
505+
continue;
506+
}
503507
bool const dirtyRecursive = it->second.dirtyRecursive();
504508
if( *it->second.m_closed
505509
== Iteration::CloseStatus::ClosedInBackend )
@@ -544,6 +548,10 @@ SeriesImpl::flushFileBased( iterations_iterator begin, iterations_iterator end )
544548
bool allDirty = dirty();
545549
for( auto it = begin; it != end; ++it )
546550
{
551+
if( *it->second.m_closed == Iteration::CloseStatus::NotYetAccessed )
552+
{
553+
continue;
554+
}
547555
bool const dirtyRecursive = it->second.dirtyRecursive();
548556
if( *it->second.m_closed
549557
== Iteration::CloseStatus::ClosedInBackend )
@@ -629,6 +637,10 @@ SeriesImpl::flushGroupBased( iterations_iterator begin, iterations_iterator end
629637
if( IOHandler()->m_frontendAccess == Access::READ_ONLY )
630638
for( auto it = begin; it != end; ++it )
631639
{
640+
if( *it->second.m_closed == Iteration::CloseStatus::NotYetAccessed )
641+
{
642+
continue;
643+
}
632644
if( *it->second.m_closed ==
633645
Iteration::CloseStatus::ClosedInBackend )
634646
{
@@ -665,6 +677,10 @@ SeriesImpl::flushGroupBased( iterations_iterator begin, iterations_iterator end
665677

666678
for( auto it = begin; it != end; ++it )
667679
{
680+
if( *it->second.m_closed == Iteration::CloseStatus::NotYetAccessed )
681+
{
682+
continue;
683+
}
668684
if( *it->second.m_closed ==
669685
Iteration::CloseStatus::ClosedInBackend )
670686
{
@@ -774,6 +790,10 @@ SeriesImpl::readFileBased( )
774790
};
775791
if( series.m_parseLazily )
776792
{
793+
for( auto & iteration : series.iterations )
794+
{
795+
*iteration.second.m_closed = Iteration::CloseStatus::NotYetAccessed;
796+
}
777797
// open the last iteration, just to parse Series attributes
778798
auto getLastIteration = series.iterations.end();
779799
getLastIteration--;
@@ -929,17 +949,38 @@ SeriesImpl::readGroupBased( bool do_init )
929949
IOHandler()->enqueue(IOTask(&series.iterations, pList));
930950
IOHandler()->flush();
931951

932-
for( auto const& it : *pList.paths )
952+
for( auto const & it : *pList.paths )
933953
{
934-
Iteration& i = series.iterations[std::stoull(it)];
935-
if ( i.closedByWriter( ) )
954+
uint64_t index = std::stoull( it );
955+
if( series.iterations.contains( index ) )
936956
{
937-
continue;
957+
// maybe re-read
958+
auto & i = series.iterations.at( index );
959+
if( i.closedByWriter() )
960+
{
961+
continue;
962+
}
963+
if( *i.m_closed != Iteration::CloseStatus::NotYetAccessed )
964+
{
965+
pOpen.path = it;
966+
IOHandler()->enqueue( IOTask( &i, pOpen ) );
967+
i.read();
968+
}
938969
}
939-
i.deferRead( {it, false, ""} );
940-
if( !series.m_parseLazily )
970+
else
941971
{
942-
i.accessLazily();
972+
// parse for the first time, resp. delay the parsing process
973+
Iteration & i = series.iterations[ std::stoull( it ) ];
974+
i.deferRead( { it, false, "" } );
975+
if( !series.m_parseLazily )
976+
{
977+
i.accessLazily();
978+
*i.m_closed = Iteration::CloseStatus::Open;
979+
}
980+
else
981+
{
982+
*i.m_closed = Iteration::CloseStatus::NotYetAccessed;
983+
}
943984
}
944985
}
945986
}
@@ -1177,16 +1218,15 @@ SeriesImpl::openIteration( uint64_t index, Iteration iteration )
11771218
throw std::runtime_error(
11781219
"[Series] Detected illegal access to iteration that "
11791220
"has been closed previously." );
1221+
case CL::NotYetAccessed:
11801222
case CL::Open:
11811223
case CL::ClosedTemporarily:
11821224
*iteration.m_closed = CL::Open;
11831225
break;
11841226
case CL::ClosedInFrontend:
11851227
// just keep it like it is
11861228
break;
1187-
default:
1188-
throw std::runtime_error( "Unreachable!" );
1189-
}
1229+
}
11901230
}
11911231

11921232
namespace internal

0 commit comments

Comments
 (0)