Skip to content

Commit 9412493

Browse files
committed
Fix flushStep() logic
1 parent 41d950a commit 9412493

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

include/openPMD/Iteration.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class Iteration : public Attributable
285285
void flushFileBased(
286286
std::string const &, IterationIndex_t, internal::FlushParams const &);
287287
void flushGroupBased(IterationIndex_t, internal::FlushParams const &);
288-
void flushVariableBased(IterationIndex_t, internal::FlushParams const &);
288+
void flushVariableBased(internal::FlushParams const &);
289289
void flush(internal::FlushParams const &);
290290
void deferParseAccess(internal::DeferredParseAccess);
291291
/*

src/IO/AbstractIOHandlerImpl.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "openPMD/IO/AbstractIOHandlerImpl.hpp"
2323

2424
#include "openPMD/auxiliary/Environment.hpp"
25+
#include "openPMD/auxiliary/TypeTraits.hpp"
2526
#include "openPMD/backend/Writable.hpp"
2627

2728
#include <iostream>
@@ -301,7 +302,28 @@ std::future<void> AbstractIOHandlerImpl::flush()
301302
"] WRITE_ATT: (",
302303
parameter.dtype,
303304
") ",
304-
parameter.name);
305+
parameter.name,
306+
"=",
307+
[&]() {
308+
return std::visit(
309+
[&](auto const &val) {
310+
using dtype = std::remove_cv_t<
311+
std::remove_reference_t<decltype(val)>>;
312+
if constexpr (
313+
auxiliary::IsArray_v<dtype> ||
314+
auxiliary::IsVector_v<dtype>)
315+
{
316+
return vec_as_string(val);
317+
}
318+
else
319+
{
320+
std::stringstream res;
321+
res << val;
322+
return res.str();
323+
}
324+
},
325+
parameter.resource);
326+
});
305327
writeAttribute(i.writable, parameter);
306328
break;
307329
}

src/Iteration.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,7 @@ void Iteration::flushGroupBased(
290290
}
291291
}
292292

293-
void Iteration::flushVariableBased(
294-
IterationIndex_t i, internal::FlushParams const &flushParams)
293+
void Iteration::flushVariableBased(internal::FlushParams const &flushParams)
295294
{
296295
setDirty(true);
297296

@@ -305,23 +304,6 @@ void Iteration::flushVariableBased(
305304
flush(flushParams);
306305
break;
307306
}
308-
309-
// @todo maybe dont repeat this upon each invocation
310-
{
311-
/*
312-
* In v-based encoding, the snapshot attribute must always be written.
313-
* Reason: Even in backends that don't support changing attributes,
314-
* variable-based iteration encoding can be used to write one single
315-
* iteration. Then, this attribute determines which iteration it is.
316-
*/
317-
Parameter<Operation::WRITE_ATT> wAttr;
318-
wAttr.changesOverSteps =
319-
Parameter<Operation::WRITE_ATT>::ChangesOverSteps::IfPossible;
320-
wAttr.name = "snapshot";
321-
wAttr.resource = (unsigned long long)i;
322-
wAttr.dtype = Datatype::ULONGLONG;
323-
IOHandler()->enqueue(IOTask(this, wAttr));
324-
}
325307
}
326308

327309
void Iteration::flush(internal::FlushParams const &flushParams)

src/Series.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,16 +1521,16 @@ void Series::flushGorVBased(
15211521
"Iterations must be the same backend object as the "
15221522
"Iterations themselves.");
15231523
}
1524-
series.m_currentlyActiveIterations.emplace(it->first);
15251524
}
1525+
series.m_currentlyActiveIterations.emplace(it->first);
15261526
switch (iterationEncoding())
15271527
{
15281528
using IE = IterationEncoding;
15291529
case IE::groupBased:
15301530
it->second.flushGroupBased(it->first, flushParams);
15311531
break;
15321532
case IE::variableBased:
1533-
it->second.flushVariableBased(it->first, flushParams);
1533+
it->second.flushVariableBased(flushParams);
15341534
break;
15351535
default:
15361536
throw std::runtime_error(
@@ -2636,8 +2636,16 @@ void Series::flushStep(bool doFlush)
26362636
* one IO step.
26372637
*/
26382638
Parameter<Operation::WRITE_ATT> wAttr;
2639+
/*
2640+
* In v-based encoding, the snapshot attribute must always be written.
2641+
* Reason: Even in backends that don't support changing attributes,
2642+
* variable-based iteration encoding can be used to write one single
2643+
* iteration. Then, this attribute determines which iteration it is.
2644+
*/
26392645
wAttr.changesOverSteps =
2640-
Parameter<Operation::WRITE_ATT>::ChangesOverSteps::Yes;
2646+
iterationEncoding() == IterationEncoding::variableBased
2647+
? Parameter<Operation::WRITE_ATT>::ChangesOverSteps::IfPossible
2648+
: Parameter<Operation::WRITE_ATT>::ChangesOverSteps::Yes;
26412649
wAttr.name = "snapshot";
26422650
wAttr.resource = std::vector<unsigned long long>{
26432651
series.m_currentlyActiveIterations.begin(),

0 commit comments

Comments
 (0)