Skip to content

Commit 89f4c24

Browse files
committed
Fix flushStep() logic
1 parent 4f065a9 commit 89f4c24

4 files changed

Lines changed: 36 additions & 24 deletions

File tree

include/openPMD/Iteration.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ class Iteration : public Attributable
311311
void flushFileBased(
312312
std::string const &, IterationIndex_t, internal::FlushParams const &);
313313
void flushGroupBased(IterationIndex_t, internal::FlushParams const &);
314-
void flushVariableBased(IterationIndex_t, internal::FlushParams const &);
314+
void flushVariableBased(internal::FlushParams const &);
315315
void flush(internal::FlushParams const &);
316316
void deferParseAccess(internal::DeferredParseAccess);
317317
/*

src/IO/AbstractIOHandlerImpl.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "openPMD/Streaming.hpp"
2626
#include "openPMD/auxiliary/Environment.hpp"
2727
#include "openPMD/auxiliary/StringManip.hpp"
28+
#include "openPMD/auxiliary/TypeTraits.hpp"
2829
#include "openPMD/auxiliary/Variant.hpp"
2930
#include "openPMD/backend/Writable.hpp"
3031

@@ -283,7 +284,28 @@ std::future<void> AbstractIOHandlerImpl::flush()
283284
"] WRITE_ATT: (",
284285
parameter.dtype,
285286
") ",
286-
parameter.name);
287+
parameter.name,
288+
"=",
289+
[&]() {
290+
return std::visit(
291+
[&](auto const &val) {
292+
using dtype = std::remove_cv_t<
293+
std::remove_reference_t<decltype(val)>>;
294+
if constexpr (
295+
auxiliary::IsArray_v<dtype> ||
296+
auxiliary::IsVector_v<dtype>)
297+
{
298+
return vec_as_string(val);
299+
}
300+
else
301+
{
302+
std::stringstream res;
303+
res << val;
304+
return res.str();
305+
}
306+
},
307+
parameter.resource);
308+
});
287309
writeAttribute(i.writable, parameter);
288310
break;
289311
}

src/Iteration.cpp

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

295-
void Iteration::flushVariableBased(
296-
IterationIndex_t i, internal::FlushParams const &flushParams)
295+
void Iteration::flushVariableBased(internal::FlushParams const &flushParams)
297296
{
298297
setDirty(true);
299298

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

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

src/Series.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,16 +1501,16 @@ void Series::flushGorVBased(
15011501
"Iterations must be the same backend object as the "
15021502
"Iterations themselves.");
15031503
}
1504-
series.m_currentlyActiveIterations.emplace(it->first);
15051504
}
1505+
series.m_currentlyActiveIterations.emplace(it->first);
15061506
switch (iterationEncoding())
15071507
{
15081508
using IE = IterationEncoding;
15091509
case IE::groupBased:
15101510
it->second.flushGroupBased(it->first, flushParams);
15111511
break;
15121512
case IE::variableBased:
1513-
it->second.flushVariableBased(it->first, flushParams);
1513+
it->second.flushVariableBased(flushParams);
15141514
break;
15151515
default:
15161516
throw std::runtime_error(
@@ -2640,8 +2640,16 @@ void Series::flushStep(bool doFlush)
26402640
* one IO step.
26412641
*/
26422642
Parameter<Operation::WRITE_ATT> wAttr;
2643+
/*
2644+
* In v-based encoding, the snapshot attribute must always be written.
2645+
* Reason: Even in backends that don't support changing attributes,
2646+
* variable-based iteration encoding can be used to write one single
2647+
* iteration. Then, this attribute determines which iteration it is.
2648+
*/
26432649
wAttr.changesOverSteps =
2644-
Parameter<Operation::WRITE_ATT>::ChangesOverSteps::Yes;
2650+
iterationEncoding() == IterationEncoding::variableBased
2651+
? Parameter<Operation::WRITE_ATT>::ChangesOverSteps::IfPossible
2652+
: Parameter<Operation::WRITE_ATT>::ChangesOverSteps::Yes;
26452653
wAttr.name = "snapshot";
26462654
wAttr.resource = std::vector<unsigned long long>{
26472655
series.m_currentlyActiveIterations.begin(),

0 commit comments

Comments
 (0)