Skip to content

Commit 5ec174b

Browse files
committed
commitStructuralSetup --> populateMissingMetadata(bool recursive)
1 parent 2c60cae commit 5ec174b

25 files changed

+110
-103
lines changed

include/openPMD/Iteration.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ namespace internal
151151
class Meshes : public Container<Mesh>
152152
{
153153
public:
154-
void visitHierarchy(HierarchyVisitor &v) override;
154+
void visitHierarchy(HierarchyVisitor &v, bool recursive) override;
155155
};
156156

157157
class Particles : public Container<ParticleSpecies>
158158
{
159159
public:
160-
void visitHierarchy(HierarchyVisitor &v) override;
160+
void visitHierarchy(HierarchyVisitor &v, bool recursive) override;
161161
};
162162

163163
/** @brief Logical compilation of data from one snapshot (e.g. a single
@@ -298,7 +298,7 @@ class Iteration
298298
[[deprecated("This attribute is no longer set by the openPMD-api.")]] bool
299299
closedByWriter() const;
300300

301-
void visitHierarchy(HierarchyVisitor &v) override;
301+
void visitHierarchy(HierarchyVisitor &v, bool recursive) override;
302302

303303
Meshes meshes{};
304304
Particles particles{};

include/openPMD/Mesh.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ class Mesh : public BaseRecord<MeshRecordComponent>
326326
typename = std::enable_if_t<std::is_floating_point<T>::value>>
327327
Mesh &setTimeOffset(T timeOffset);
328328

329-
void visitHierarchy(HierarchyVisitor &v) override;
329+
void visitHierarchy(HierarchyVisitor &v, bool recursive) override;
330330

331331
private:
332332
Mesh();

include/openPMD/ParticlePatches.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ParticlePatches : public Container<PatchRecord>
3838
size_t numPatches() const;
3939
~ParticlePatches() override = default;
4040

41-
void visitHierarchy(HierarchyVisitor &v) override;
41+
void visitHierarchy(HierarchyVisitor &v, bool recursive) override;
4242

4343
private:
4444
ParticlePatches() = default;

include/openPMD/ParticleSpecies.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ class ParticleSpecies
4747
public:
4848
ParticlePatches particlePatches;
4949

50-
void visitHierarchy(HierarchyVisitor &v) override
51-
{
52-
visitHierarchyImpl<ParticleSpecies>(v);
53-
particlePatches.visitHierarchy(v);
54-
}
50+
void visitHierarchy(HierarchyVisitor &v, bool recursive) override;
5551

5652
private:
5753
ParticleSpecies();

include/openPMD/Record.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Record : public BaseRecord<RecordComponent>
5050
template <typename T>
5151
Record &setTimeOffset(T);
5252

53-
void visitHierarchy(HierarchyVisitor &v) override;
53+
void visitHierarchy(HierarchyVisitor &v, bool recursive) override;
5454

5555
private:
5656
Record();

include/openPMD/RecordComponent.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ class RecordComponent
488488
auto visit(Args &&...args) -> decltype(Visitor::template call<char>(
489489
std::declval<RecordComponent &>(), std::forward<Args>(args)...));
490490

491-
void visitHierarchy(HierarchyVisitor &v) override;
491+
void visitHierarchy(HierarchyVisitor &v, bool recursive) override;
492492

493493
static constexpr char const *const SCALAR = "\vScalar";
494494

include/openPMD/Series.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Series;
6969
class Iterations : public Container<Iteration, Iteration::IterationIndex_t>
7070
{
7171
public:
72-
void visitHierarchy(HierarchyVisitor &v) override;
72+
void visitHierarchy(HierarchyVisitor &v, bool recursive) override;
7373
};
7474

7575
namespace internal
@@ -784,7 +784,7 @@ class Series : public Attributable
784784
*/
785785
void close();
786786

787-
void visitHierarchy(HierarchyVisitor &v) override;
787+
void visitHierarchy(HierarchyVisitor &v, bool recursive) override;
788788

789789
/**
790790
* This overrides Attributable::iterationFlush() which will fail on Series.

include/openPMD/backend/Attributable.hpp

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,14 @@ class Attributable
408408
* @note As the HierarchyVisitor interface can be tedious to implement,
409409
* consider using visitHierarchyFromLambda for a more convenient
410410
* interface.
411+
412+
* @note to developers: if at any point a prefix traversal should become
413+
* necessary, consider emplacing configuration options for this inside
414+
* HierarchyVisitor to keep the interface clean.
411415
*
412416
* @param visitor Operations to run for each object.
413417
*/
414-
virtual void visitHierarchy(HierarchyVisitor &visitor);
418+
virtual void visitHierarchy(HierarchyVisitor &visitor, bool recursive);
415419

416420
/**
417421
* Visitor pattern for the openPMD object hierarchy in postfix traversal,
@@ -422,42 +426,31 @@ class Attributable
422426
*
423427
* @note Definition inside include/openPMD/backend/HierarchyVisitorImpl.hpp.
424428
* @param lambda Operations to run for each object.
429+
* @param recursive Extend the operation recursively to children.
425430
*/
426431
template <typename Lambda>
427-
void visitHierarchyFromLambda(Lambda &&lambda);
432+
void visitHierarchyFromLambda(Lambda &&lambda, bool recursive);
428433

429-
/**
430-
* Recursively freeze structural definitions made so far on the current
431-
* object and all its children.
432-
*
433-
* This includes:
434-
* 1. Explicit attribute writes
435-
* 2. Implicit attributes, i.e.: Attributes defined by the openPMD standard
436-
* will now be populated with sensible default values
437-
* 3. Dataset creation: The Dataset declarations set by resetDataset() will
438-
* now be fixed. Datasets can no longer be changed to constant components
439-
* after this.
440-
* 4. Hierarchy setup, i.e. creation of group paths.
441-
*
442-
* WARNING: this is still under development and not fully implemented yet
443-
* (implementation status: only bullet 2. from above. ref.
444-
* https://github.com/openPMD/openPMD-api/pull/1862 for the rest.)
445-
*
446-
* Uses of this include:
447-
* 1. Setting up the metadata is a collective operation in some backends
448-
* (read: HDF5). When interacting with a dataset non-collectively (e.g.
449-
* single ranks without data contribution, variable number of blocks per
450-
* rank), this call harmonizes the collective metadata setup.
451-
* 2. Forcing the creation of default attributes. By default, these are
452-
* written upon closing the containing Iteration / Series. Calling this
453-
* soon can make data available for early readers (e.g. read while the
454-
* writer is still modifying).
455-
*
456-
* Modifying the frozen structural setup is only possible insofar as the
457-
* backend supports this, e.g. by dataset extension, attribute overwrite or
458-
* group deletion.
434+
/** Create standard defined attributes with default values now, insofar they
435+
* are still missing.
436+
*
437+
* Refer to
438+
* https://github.com/openPMD/openPMD-standard/blob/latest/STANDARD.md
439+
* for the attributes implied by this operation.
440+
*
441+
* By default, standard defined attributes are written upon closing the
442+
* containing Iteration / Series. Calling this soon can make data available
443+
* for early readers (e.g. read while the writer is still modifying). In
444+
* workflows that keep single Iterations open over an extended period of
445+
* time (e.g. back-transformed diagnostics), this can help creating readable
446+
* files earlier than without.
447+
*
448+
* Attributes may still be modified after this as usual. Attributes defined
449+
* before this call will not be modified by it.
450+
*
451+
* @param recursive Extend the operation recursively to children.
459452
*/
460-
void commitStructuralSetup();
453+
void populateMissingMetadata(bool recursive);
461454

462455
[[nodiscard]] OpenpmdStandard openPMDStandard() const;
463456

include/openPMD/backend/Container.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,14 @@ class Container : virtual public Attributable
264264
}
265265

266266
template <typename ChildClass>
267-
void visitHierarchyImpl(HierarchyVisitor &v)
267+
void visitHierarchyImpl(HierarchyVisitor &v, bool recursive)
268268
{
269-
for (auto &p : *this)
269+
if (recursive)
270270
{
271-
p.second.visitHierarchy(v);
271+
for (auto &p : *this)
272+
{
273+
p.second.visitHierarchy(v, recursive);
274+
}
272275
}
273276
v(*static_cast<ChildClass *>(this));
274277
}

include/openPMD/backend/HierarchyVisitorImpl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ auto makeHierarchyVisitorFromLambda(Lambda &&lambda)
8181
}
8282

8383
template <typename Lambda>
84-
void Attributable::visitHierarchyFromLambda(Lambda &&lambda)
84+
void Attributable::visitHierarchyFromLambda(Lambda &&lambda, bool recursive)
8585
{
8686
auto visitor = makeHierarchyVisitorFromLambda(std::forward<Lambda>(lambda));
87-
this->visitHierarchy(visitor);
87+
this->visitHierarchy(visitor, recursive);
8888
}
8989
} // namespace openPMD

0 commit comments

Comments
 (0)