Skip to content

Commit ada85a2

Browse files
committed
Write defaults upon flush, thats good enough actually
1 parent 36e464c commit ada85a2

File tree

9 files changed

+33
-8
lines changed

9 files changed

+33
-8
lines changed

include/openPMD/backend/Attributable.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ OPENPMD_protected
428428

429429
void flushAttributes(internal::FlushParams const &);
430430

431+
void populateDefaults(
432+
internal::ScientificDefaults *self,
433+
internal::FlushParams const &params);
434+
431435
enum ReadMode
432436
{
433437
/**

include/openPMD/backend/BaseRecord.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ template <typename T_elem>
180180
class BaseRecord
181181
: public Container<T_elem>
182182
, public T_elem // T_RecordComponent
183-
// ScientificDefaults already inherited via Container
183+
// ScientificDefaults already inherited via RecordComponent
184184
// , internal::ScientificDefaults
185185
{
186186
public:

include/openPMD/backend/scientific_defaults/ScientificDefaults.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
#include "openPMD/backend/Attributable.hpp"
44
#include "openPMD/backend/scientific_defaults/ConfigAttribute.hpp"
55

6+
namespace openPMD
7+
{
8+
class Attributable;
9+
}
10+
611
namespace openPMD::internal
712
{
813
/*
@@ -15,6 +20,8 @@ namespace openPMD::internal
1520
*/
1621
class ScientificDefaults
1722
{
23+
friend class ::openPMD::Attributable;
24+
1825
protected:
1926
[[nodiscard]] auto defaultAttribute(Attributable &, char const *attrName)
2027
-> ConfigAttribute;

src/Iteration.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ Iteration &Iteration::close(bool _flush)
125125
break;
126126
}
127127

128-
if (access::write(IOHandler()->m_frontendAccess))
129-
{
130-
populateDefaultMetadata();
131-
}
128+
// if (access::write(IOHandler()->m_frontendAccess))
129+
// {
130+
// populateDefaultMetadata();
131+
// }
132132

133133
if (_flush)
134134
{
@@ -459,6 +459,7 @@ void Iteration::flush(internal::FlushParams const &flushParams)
459459
particles.setDirty(false);
460460
}
461461

462+
populateDefaults(this, flushParams);
462463
flushAttributes(flushParams);
463464
}
464465
if (flushParams.flushLevel != FlushLevel::SkeletonOnly)

src/ParticleSpecies.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ void ParticleSpecies::flush(
176176
}
177177
else
178178
{
179+
populateDefaults(this, flushParams);
179180
Container<Record>::flush(path, flushParams);
180181

181182
for (auto &record : *this)

src/RecordComponent.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ void RecordComponent::flush(
516516
rc.m_chunks.pop();
517517
}
518518

519+
populateDefaults(this, flushParams);
519520
flushAttributes(flushParams);
520521
}
521522
if (flushParams.flushLevel != FlushLevel::SkeletonOnly)

src/backend/Attributable.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,16 @@ void Attributable::flushAttributes(internal::FlushParams const &flushParams)
340340
}
341341
}
342342

343+
void Attributable::populateDefaults(
344+
internal::ScientificDefaults *self, internal::FlushParams const &params)
345+
{
346+
if (params.flushLevel != FlushLevel::UserFlush)
347+
{
348+
return;
349+
}
350+
self->writeDefaults(IOHandler()->m_standard);
351+
}
352+
343353
void Attributable::readAttributes(ReadMode mode)
344354
{
345355
auto &attri = get();

src/backend/BaseRecord.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,10 @@ inline void BaseRecord<T_elem>::flush(
792792
"one or more regular components.");
793793
}
794794

795+
if (access::write(this->IOHandler()->m_backendAccess))
796+
{
797+
this->populateDefaults(this, flushParams);
798+
}
795799
this->flush_impl(name, flushParams);
796800
if (flushParams.flushLevel != FlushLevel::SkeletonOnly)
797801
{

test/python/unittest/API/APITest.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,7 +2383,6 @@ def get_component_only():
23832383
mesh.axis_labels = ["x", "y"]
23842384
component.reset_dataset(io.Dataset(np.dtype("float"), [10, 10]))
23852385

2386-
iteration.populate_default_metadata()
23872386
del iteration
23882387
del mesh
23892388
del series
@@ -2431,7 +2430,6 @@ def get_component_only():
24312430
position.reset_dataset(
24322431
io.Dataset(np.dtype("float"), [num_particles]))
24332432

2434-
iteration.populate_default_metadata()
24352433
del iteration
24362434
del particles
24372435
del series
@@ -2483,7 +2481,6 @@ def get_component_only():
24832481
num_particles_comp.store(0, np.uint64(10))
24842482
num_particles_comp.store(1, np.uint64(20))
24852483

2486-
iteration.populate_default_metadata()
24872484
del iteration
24882485
del particles
24892486
del series

0 commit comments

Comments
 (0)