Skip to content

Commit 6b358ee

Browse files
committed
Backport the fix
1 parent 6a32ffc commit 6b358ee

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

include/openPMD/ReadIterations.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace openPMD
3333
{
3434
class SeriesIterator
3535
{
36+
friend class Series;
3637
using iteration_index_t = IndexedIteration::index_t;
3738

3839
using maybe_series_t = std::optional<Series>;

include/openPMD/WriteIterations.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,6 @@ class WriteIterations
105105
* Return the iteration that is currently being written to, if it exists.
106106
*/
107107
std::optional<IndexedIteration> currentIteration();
108+
std::optional<Iteration::IterationIndex_t> currentIterationIndex() const;
108109
};
109110
} // namespace openPMD

src/Series.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2568,7 +2568,8 @@ auto Series::openIterationIfDirty(IterationIndex_t index, Iteration iteration)
25682568
{
25692569
return IterationOpened::RemainsClosed;
25702570
}
2571-
bool const dirtyRecursive = iteration.dirtyRecursive();
2571+
bool dirtyRecursive = iteration.dirtyRecursive();
2572+
25722573
if (iteration.get().m_closed == internal::CloseStatus::ClosedInBackend)
25732574
{
25742575
// file corresponding with the iteration has previously been
@@ -2589,6 +2590,33 @@ auto Series::openIterationIfDirty(IterationIndex_t index, Iteration iteration)
25892590
return IterationOpened::RemainsClosed;
25902591
}
25912592

2593+
/*
2594+
* When using writeIterations(), the currently active Iteration should
2595+
* always be flushed (unless, as checked above, it is already closed).
2596+
* These two blocks checks if an Iteration is currently collectively opened.
2597+
*/
2598+
auto &series = get();
2599+
[&]() {
2600+
if (!series.m_sharedStatefulIterator)
2601+
{
2602+
return;
2603+
}
2604+
auto const current_iteration =
2605+
series.m_sharedStatefulIterator->peekCurrentIteration();
2606+
dirtyRecursive |=
2607+
current_iteration.has_value() && *current_iteration == index;
2608+
}();
2609+
[&]() {
2610+
if (!series.m_writeIterations)
2611+
{
2612+
return;
2613+
}
2614+
auto const current_iteration =
2615+
series.m_writeIterations->currentIterationIndex();
2616+
dirtyRecursive |=
2617+
current_iteration.has_value() && *current_iteration == index;
2618+
}();
2619+
25922620
switch (iterationEncoding())
25932621
{
25942622
using IE = IterationEncoding;

src/WriteIterations.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,29 @@ WriteIterations::mapped_type &WriteIterations::operator[](key_type &&key)
104104

105105
std::optional<IndexedIteration> WriteIterations::currentIteration()
106106
{
107-
if (!shared || !shared->has_value())
107+
auto current_index = currentIterationIndex();
108+
if (!current_index.has_value())
108109
{
109110
return std::nullopt;
110111
}
111112
auto &s = shared->value();
112-
if (!s.currentlyOpen.has_value())
113-
{
114-
return std::nullopt;
115-
}
116-
Iteration &currentIteration = s.iterations.at(s.currentlyOpen.value());
113+
Iteration &currentIteration = s.iterations.at(current_index.value());
117114
if (currentIteration.closed())
118115
{
119116
return std::nullopt;
120117
}
121118
return std::make_optional<IndexedIteration>(
122119
IndexedIteration(currentIteration, s.currentlyOpen.value()));
123120
}
121+
122+
std::optional<Iteration::IterationIndex_t>
123+
WriteIterations::currentIterationIndex() const
124+
{
125+
if (!shared || !shared->has_value())
126+
{
127+
return std::nullopt;
128+
}
129+
auto &s = shared->value();
130+
return s.currentlyOpen;
131+
}
124132
} // namespace openPMD

0 commit comments

Comments
 (0)