Skip to content

Commit

Permalink
Works in JSON and HDF5 now too
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Feb 22, 2024
1 parent 36ae6ec commit 9987204
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
1 change: 0 additions & 1 deletion include/openPMD/backend/Attributable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ namespace internal
*/
Writable m_writable;

private:
/**
* The attributes defined by this Attributable.
*/
Expand Down
11 changes: 11 additions & 0 deletions src/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 15 additions & 2 deletions src/snapshots/StatefulIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ StatefulIterator::StatefulIterator(

switch (series.iterationEncoding())
{

case IterationEncoding::fileBased: {
initIteratorFilebased();
break;
Expand Down Expand Up @@ -646,14 +645,28 @@ std::optional<StatefulIterator *> 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 &currentIteration = iterations.at(**maybe_current_iteration);
if (!currentIteration.closed())
{
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);
Expand Down
20 changes: 14 additions & 6 deletions test/Files_SerialIO/close_iteration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
{
Expand Down Expand Up @@ -257,8 +257,7 @@ auto run_test_groupbased(
{
auto it = read.snapshots()[1].open();
std::vector<int> 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<int>{0, 1, 2, 3, 4}));
}
Expand All @@ -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; },
Expand All @@ -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
Expand Down

0 comments on commit 9987204

Please sign in to comment.