Skip to content

Commit 8c34387

Browse files
committed
populateDefaultMetadata -> commitStructuralSetup
available on all attributables
1 parent 110abeb commit 8c34387

11 files changed

Lines changed: 47 additions & 45 deletions

File tree

include/openPMD/Iteration.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class Iteration
185185
template <typename>
186186
friend struct traits::GenerationPolicy;
187187
friend class internal::ScientificDefaults;
188+
friend class Attributable;
188189

189190
public:
190191
Iteration(Iteration const &) = default;
@@ -307,11 +308,6 @@ class Iteration
307308
particles.visitHierarchy(v);
308309
}
309310

310-
// TODO: make this available on every class that inherits from
311-
// scientificdefaults for this, somehow make visitHierarchy a non-template,
312-
// so we can use it as a virtual function of attributable
313-
void populateDefaultMetadata();
314-
315311
Meshes meshes{};
316312
Particles particles{}; // particleSpecies?
317313

include/openPMD/Mesh.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Mesh : public BaseRecord<MeshRecordComponent>
4444
friend class Container<Mesh>;
4545
friend class Iteration;
4646
friend class internal::ScientificDefaults;
47+
friend class Attributable;
4748

4849
public:
4950
Mesh(Mesh const &) = default;

include/openPMD/ParticleSpecies.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ParticleSpecies
4242
template <typename T>
4343
friend T &internal::makeOwning(T &self, Series);
4444
friend class internal::ScientificDefaults;
45+
friend class Attributable;
4546

4647
public:
4748
ParticlePatches particlePatches;

include/openPMD/RecordComponent.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class RecordComponent
133133
template <typename T>
134134
friend T &internal::makeOwning(T &self, Series);
135135
friend class internal::ScientificDefaults;
136+
friend class Attributable;
136137

137138
public:
138139
enum class Allocation

include/openPMD/backend/Attributable.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ class Attributable
408408
template <typename Lambda>
409409
void visitHierarchyFromLambda(Lambda &&lambda);
410410

411+
void commitStructuralSetup();
412+
411413
[[nodiscard]] OpenpmdStandard openPMDStandard() const;
412414

413415
// clang-format off

include/openPMD/backend/BaseRecordComponent.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class BaseRecordComponent : virtual public Attributable
8282
{
8383
template <typename T, typename T_key, typename T_container>
8484
friend class Container;
85+
friend class Attributable;
8586

8687
public:
8788
/*

include/openPMD/backend/HierarchyVisitorImpl.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ class HierarchyVisitorFromLambda : public HierarchyVisitor
1414
{
1515
Lambda lambda;
1616

17-
public:
1817
template <typename Arg>
1918
HierarchyVisitorFromLambda(uint8_t /* constructor_tag */, Arg &&arg)
2019
: lambda(std::forward<Arg>(arg))
2120
{}
21+
22+
template <typename Lambda_in>
23+
friend auto makeHierarchyVisitorFromLambda(Lambda_in &&lambda);
24+
25+
public:
2226
void operator()(Iteration &obj) override
2327
{
2428
lambda(obj);

src/Iteration.cpp

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "openPMD/auxiliary/Variant.hpp"
3535
#include "openPMD/backend/Attributable.hpp"
3636
#include "openPMD/backend/BaseRecordComponent.hpp"
37-
#include "openPMD/backend/HierarchyVisitorImpl.hpp"
3837
#include "openPMD/backend/Variant_internal.hpp"
3938
#include "openPMD/backend/Writable.hpp"
4039
#include "openPMD/backend/scientific_defaults/ConfigAttribute.hpp"
@@ -128,7 +127,7 @@ Iteration &Iteration::close(bool _flush)
128127

129128
// if (access::write(IOHandler()->m_frontendAccess))
130129
// {
131-
// populateDefaultMetadata();
130+
// commitStructuralSetup();
132131
// }
133132

134133
if (_flush)
@@ -245,41 +244,6 @@ bool Iteration::closedByWriter() const
245244
}
246245
}
247246

248-
void Iteration::populateDefaultMetadata()
249-
{
250-
auto standard = IOHandler()->m_standard;
251-
visitHierarchyFromLambda([standard](auto &component) {
252-
using ComponentType = std::remove_reference_t<decltype(component)>;
253-
if constexpr (auxiliary::IsTemplateBaseOf_v<BaseRecord, ComponentType>)
254-
{
255-
if (component.empty() && !component.datasetDefined())
256-
{
257-
std::cerr
258-
<< "Cannot flush Record without any contained components:'"
259-
<< component.myPath().openPMDPath() << "'. Will ignore.";
260-
if (component.written())
261-
{
262-
std::cerr
263-
<< "\n(Note: The Record seems to have been written "
264-
"previously?)";
265-
}
266-
std::cerr << std::endl;
267-
return;
268-
}
269-
}
270-
271-
if constexpr (
272-
!std::is_same_v<ComponentType, Iterations> &&
273-
!std::is_same_v<ComponentType, Meshes> &&
274-
!std::is_same_v<ComponentType, ParticlePatches> &&
275-
!std::is_same_v<ComponentType, Particles> &&
276-
!std::is_same_v<ComponentType, Series>)
277-
{
278-
component.writeDefaults(standard);
279-
}
280-
});
281-
}
282-
283247
void Iteration::flushFileBased(
284248
std::string const &filename,
285249
IterationIndex_t i,

src/backend/Attributable.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "openPMD/auxiliary/DerefDynamicCast.hpp"
2828
#include "openPMD/auxiliary/StringManip.hpp"
2929
#include "openPMD/backend/Attribute.hpp"
30+
#include "openPMD/backend/HierarchyVisitorImpl.hpp"
3031

3132
#include <algorithm>
3233
#include <complex>
@@ -300,6 +301,37 @@ void Attributable::visitHierarchy(HierarchyVisitor &)
300301
throw std::runtime_error("Cannot call this on base class");
301302
}
302303

304+
void Attributable::commitStructuralSetup()
305+
{
306+
auto standard = IOHandler()->m_standard;
307+
visitHierarchyFromLambda([standard](auto &component) {
308+
using ComponentType = std::remove_reference_t<decltype(component)>;
309+
if constexpr (auxiliary::IsTemplateBaseOf_v<BaseRecord, ComponentType>)
310+
{
311+
if (component.empty() && !component.datasetDefined())
312+
{
313+
std::cerr
314+
<< "Cannot flush Record without any contained components:'"
315+
<< component.myPath().openPMDPath() << "'. Will ignore.";
316+
if (component.written())
317+
{
318+
std::cerr
319+
<< "\n(Note: The Record seems to have been written "
320+
"previously?)";
321+
}
322+
std::cerr << std::endl;
323+
return;
324+
}
325+
}
326+
327+
if constexpr (
328+
std::is_base_of_v<internal::ScientificDefaults, ComponentType>)
329+
{
330+
component.writeDefaults(standard);
331+
}
332+
});
333+
}
334+
303335
OpenpmdStandard Attributable::openPMDStandard() const
304336
{
305337
return IOHandler()->m_standard;

src/binding/python/Attributable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,8 @@ void init_Attributable(py::module &m)
647647
"comment", &Attributable::comment, &Attributable::setComment)
648648
// TODO remove in future versions (deprecated)
649649
.def("set_comment", &Attributable::setComment)
650-
.def("my_path", &Attributable::myPath);
650+
.def("my_path", &Attributable::myPath)
651+
.def("commit_structural_setup", &Iteration::commitStructuralSetup);
651652

652653
py::bind_vector<PyAttributeKeys>(m, "Attribute_Keys");
653654
}

0 commit comments

Comments
 (0)