Skip to content

Commit 9679d74

Browse files
Reactivate iteration closed check (#1829)
* Reactivate Iteration::closed() check seems to fail in some instances * Fix test * Add a test if the RecordComponent is contained by any Iteration
1 parent d79e29b commit 9679d74

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/RecordComponent.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,20 @@ namespace internal
5151
Attributable a;
5252
a.setData(std::shared_ptr<AttributableData>{this, [](auto const &) {}});
5353
// this check can be too costly in some setups
54-
#if 0
55-
if (a.containingIteration().closed())
54+
#if openPMD_USE_INVASIVE_TESTS
55+
56+
auto maybe_an_iteration = a.containingIteration().first;
57+
if (!maybe_an_iteration.has_value())
5658
{
57-
throw error::WrongAPIUsage(
59+
throw std::runtime_error(
60+
"Trying to write to/read from a RecordComponent that is not "
61+
"contained by any Iteration.");
62+
}
63+
auto &iterationData = *maybe_an_iteration.value();
64+
auto iteration = iterationData.asInternalCopyOf<Iteration>();
65+
if (iteration.closed() && !iterationData.allow_reopening_implicitly)
66+
{
67+
throw std::runtime_error(
5868
"Cannot write/read chunks to/from closed Iterations.");
5969
}
6070
#endif

0 commit comments

Comments
 (0)