diff --git a/include/openPMD/backend/Attributable.hpp b/include/openPMD/backend/Attributable.hpp index fb95ef77d4..499b9aea8e 100644 --- a/include/openPMD/backend/Attributable.hpp +++ b/include/openPMD/backend/Attributable.hpp @@ -74,7 +74,6 @@ namespace internal */ Writable m_writable; - private: /** * The attributes defined by this Attributable. */ diff --git a/src/Series.cpp b/src/Series.cpp index b5833aecda..c6c1bdc3e3 100644 --- a/src/Series.cpp +++ b/src/Series.cpp @@ -1987,6 +1987,12 @@ void Series::readBase() "string, found " + datatypeToString(Attribute(*aRead.resource).dtype) + ")"); } + else + { + // Make sure that the meshesPath does not leak from one iteration into + // the other in file-based iteration encoding + get().m_attributes.erase("meshesPath"); + } if (std::count( aList.attributes->begin(), @@ -2017,6 +2023,11 @@ void Series::readBase() "string, found " + datatypeToString(Attribute(*aRead.resource).dtype) + ")"); } + { + // Make sure that the particlesPath does not leak from one iteration + // into the other in file-based iteration encoding + get().m_attributes.erase("particlesPath"); + } } std::string Series::iterationFilename(IterationIndex_t i) diff --git a/src/snapshots/StatefulIterator.cpp b/src/snapshots/StatefulIterator.cpp index ee0fdb1bfc..522f126f47 100644 --- a/src/snapshots/StatefulIterator.cpp +++ b/src/snapshots/StatefulIterator.cpp @@ -471,7 +471,6 @@ StatefulIterator::StatefulIterator( switch (series.iterationEncoding()) { - case IterationEncoding::fileBased: { initIteratorFilebased(); break; @@ -646,6 +645,17 @@ std::optional StatefulIterator::loopBody(Seek const &seek) */ auto maybe_current_iteration = data.currentStep.get_iteration_index(); if (maybe_current_iteration.has_value() && + // don't deactivate the iteration if it's the one that's currently + // active anyway + std::visit( + auxiliary::overloaded{ + [&](detail::seek_types::Next_t const &) { return true; }, + [&](detail::seek_types::Seek_Iteration_t const + &go_to_iteration) { + return go_to_iteration.iteration_idx != + **maybe_current_iteration; + }}, + seek) && iterations.contains(**maybe_current_iteration)) { auto ¤tIteration = iterations.at(**maybe_current_iteration); @@ -653,7 +663,10 @@ std::optional StatefulIterator::loopBody(Seek const &seek) { currentIteration.close(); } - if (series.IOHandler()->m_frontendAccess == Access::READ_LINEAR) + // sic! only erase if the Iteration was explicitly closed, don't + // implicitly sweep the iteration away from under the user + else if ( + series.IOHandler()->m_frontendAccess == Access::READ_LINEAR) { data.series.iterations.container().erase( **maybe_current_iteration); diff --git a/test/Files_SerialIO/close_iteration_test.cpp b/test/Files_SerialIO/close_iteration_test.cpp index 092602fd05..d8dcf5ea20 100644 --- a/test/Files_SerialIO/close_iteration_test.cpp +++ b/test/Files_SerialIO/close_iteration_test.cpp @@ -201,9 +201,9 @@ auto run_test_groupbased( it.close(); it.open(); - auto e_position_x = it.particles["e"]["position"]["x"]; - e_position_x.resetDataset({Datatype::INT, {5}}); - e_position_x.storeChunk(data, {0}, {5}); + auto E_y = it.meshes["E"]["y"]; + E_y.resetDataset({Datatype::INT, {5}}); + E_y.storeChunk(data, {0}, {5}); it.close(); } { @@ -257,8 +257,7 @@ auto run_test_groupbased( { auto it = read.snapshots()[1].open(); std::vector data(5); - it.particles["e"]["position"]["x"].loadChunkRaw( - data.data(), {0}, {5}); + it.meshes["E"]["y"].loadChunkRaw(data.data(), {0}, {5}); it.close(); REQUIRE((data == std::vector{0, 1, 2, 3, 4})); } @@ -270,7 +269,10 @@ auto close_and_reopen_test() -> void run_test_filebased([](Series &s) { return s.iterations; }, "bp"); run_test_filebased([](Series &s) { return s.writeIterations(); }, "bp"); run_test_filebased([](Series &s) { return s.snapshots(); }, "bp"); - // run_test_filebased([](Series &s) { return s.snapshots(); }, "json"); + run_test_filebased([](Series &s) { return s.snapshots(); }, "json"); +#if openPMD_HAVE_HDF5 + run_test_filebased([](Series &s) { return s.snapshots(); }, "h5"); +#endif run_test_groupbased( [](Series &s) { return s.iterations; }, @@ -291,6 +293,12 @@ auto close_and_reopen_test() -> void [](Series &s) { return s.snapshots(); }, "json", {Access::READ_RANDOM_ACCESS, Access::READ_LINEAR}); +#if openPMD_HAVE_HDF5 + run_test_groupbased( + [](Series &s) { return s.snapshots(); }, + "h5", + {Access::READ_RANDOM_ACCESS, Access::READ_LINEAR}); +#endif } #else auto close_and_reopen_test() -> void