Skip to content

Commit b0d7fe6

Browse files
committed
Some cleanup in CustomHierarchies class
1 parent d3de763 commit b0d7fe6

File tree

2 files changed

+43
-44
lines changed

2 files changed

+43
-44
lines changed

include/openPMD/CustomHierarchy.hpp

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,25 @@ namespace internal
8585

8686
void syncAttributables();
8787

88-
Container<CustomHierarchy> customHierarchies()
88+
#if 0
89+
inline Container<CustomHierarchy> customHierarchiesWrapped()
8990
{
9091
Container<CustomHierarchy> res;
9192
res.setData(
9293
{static_cast<ContainerData<CustomHierarchy> *>(this),
9394
[](auto const *) {}});
9495
return res;
9596
}
96-
Container<RecordComponent> embeddedDatasets()
97+
#endif
98+
inline Container<RecordComponent> embeddedDatasetsWrapped()
9799
{
98100
Container<RecordComponent> res;
99101
res.setData(
100102
{static_cast<ContainerData<RecordComponent> *>(this),
101103
[](auto const *) {}});
102104
return res;
103105
}
104-
Container<Mesh> embeddedMeshes()
106+
inline Container<Mesh> embeddedMeshesWrapped()
105107
{
106108
Container<Mesh> res;
107109
res.setData(
@@ -110,14 +112,40 @@ namespace internal
110112
return res;
111113
}
112114

113-
Container<ParticleSpecies> embeddedParticles()
115+
inline Container<ParticleSpecies> embeddedParticlesWrapped()
114116
{
115117
Container<ParticleSpecies> res;
116118
res.setData(
117119
{static_cast<ContainerData<ParticleSpecies> *>(this),
118120
[](auto const *) {}});
119121
return res;
120122
}
123+
124+
#if 0
125+
inline Container<CustomHierarchy>::InternalContainer &
126+
customHierarchiesInternal()
127+
{
128+
return static_cast<ContainerData<CustomHierarchy> *>(this)
129+
->m_container;
130+
}
131+
#endif
132+
inline Container<RecordComponent>::InternalContainer &
133+
embeddedDatasetsInternal()
134+
{
135+
return static_cast<ContainerData<RecordComponent> *>(this)
136+
->m_container;
137+
}
138+
inline Container<Mesh>::InternalContainer &embeddedMeshesInternal()
139+
{
140+
return static_cast<ContainerData<Mesh> *>(this)->m_container;
141+
}
142+
143+
inline Container<ParticleSpecies>::InternalContainer &
144+
embeddedParticlesInternal()
145+
{
146+
return static_cast<ContainerData<ParticleSpecies> *>(this)
147+
->m_container;
148+
}
121149
};
122150
} // namespace internal
123151

@@ -218,16 +246,6 @@ class CustomHierarchy : public ConversibleContainer<CustomHierarchy>
218246
*/
219247
void linkHierarchy(Writable &w) override;
220248

221-
/*
222-
* @brief Check recursively whether this object is dirty.
223-
* It is dirty if any attribute or dataset is read from or written to
224-
* the backend.
225-
*
226-
* @return true If dirty.
227-
* @return false Otherwise.
228-
*/
229-
bool dirtyRecursive() const;
230-
231249
public:
232250
CustomHierarchy(CustomHierarchy const &other) = default;
233251
CustomHierarchy(CustomHierarchy &&other) = default;

src/CustomHierarchy.cpp

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ void CustomHierarchy::read(
402402

403403
std::deque<std::string> constantComponentsPushback;
404404
auto &data = get();
405-
EraseStaleMeshes meshesMap(data.embeddedMeshes());
406-
EraseStaleParticles particlesMap(data.embeddedParticles());
405+
EraseStaleMeshes meshesMap(data.embeddedMeshesWrapped());
406+
EraseStaleParticles particlesMap(data.embeddedParticlesWrapped());
407407
for (auto const &path : *pList.paths)
408408
{
409409
switch (mpp.determineType(currentPath))
@@ -487,7 +487,8 @@ void CustomHierarchy::read(
487487
// Group is a bit of an internal misnomer here, it just means that
488488
// it matches neither meshes nor particles path
489489
case internal::ContainedType::Group: {
490-
auto &rc = data.embeddedDatasets()[path];
490+
auto embeddedDatasets = data.embeddedDatasetsWrapped();
491+
auto &rc = embeddedDatasets[path];
491492
Parameter<Operation::OPEN_DATASET> dOpen;
492493
dOpen.name = path;
493494
IOHandler()->enqueue(IOTask(&rc, dOpen));
@@ -505,7 +506,7 @@ void CustomHierarchy::read(
505506
<< "' at path '" << myPath().openPMDPath()
506507
<< "' and will skip it due to read error:\n"
507508
<< err.what() << std::endl;
508-
data.embeddedDatasets().container().erase(path);
509+
embeddedDatasets.erase(path);
509510
}
510511
break;
511512
}
@@ -528,7 +529,8 @@ void CustomHierarchy::read(
528529

529530
for (auto const &path : constantComponentsPushback)
530531
{
531-
auto &rc = data.embeddedDatasets()[path];
532+
auto embeddedDatasets = data.embeddedDatasetsWrapped();
533+
auto &rc = embeddedDatasets[path];
532534
try
533535
{
534536
Parameter<Operation::OPEN_PATH> pOpen;
@@ -543,7 +545,7 @@ void CustomHierarchy::read(
543545
<< myPath().openPMDPath() << "/" << path
544546
<< "' and will skip it due to read error:\n"
545547
<< err.what() << std::endl;
546-
data.embeddedDatasets().container().erase(path);
548+
embeddedDatasets.erase(path);
547549
}
548550
}
549551
setDirty(false);
@@ -580,7 +582,7 @@ void CustomHierarchy::flush_internal(
580582
subpath.flush_internal(flushParams, mpp, currentPath);
581583
currentPath.pop_back();
582584
}
583-
for (auto &[name, mesh] : data.embeddedMeshes())
585+
for (auto &[name, mesh] : data.embeddedMeshesInternal())
584586
{
585587
if (!mpp.isMeshContainer(currentPath))
586588
{
@@ -604,7 +606,7 @@ void CustomHierarchy::flush_internal(
604606
}
605607
mesh.flush(name, flushParams);
606608
}
607-
for (auto &[name, particleSpecies] : data.embeddedParticles())
609+
for (auto &[name, particleSpecies] : data.embeddedParticlesInternal())
608610
{
609611
if (!mpp.isParticleContainer(currentPath))
610612
{
@@ -630,7 +632,7 @@ void CustomHierarchy::flush_internal(
630632
}
631633
particleSpecies.flush(name, flushParams);
632634
}
633-
for (auto &[name, dataset] : get().embeddedDatasets())
635+
for (auto &[name, dataset] : get().embeddedDatasetsInternal())
634636
{
635637
dataset.flush(name, flushParams, /* set_defaults = */ false);
636638
}
@@ -653,27 +655,6 @@ void CustomHierarchy::linkHierarchy(Writable &w)
653655
{
654656
Attributable::linkHierarchy(w);
655657
}
656-
657-
bool CustomHierarchy::dirtyRecursive() const
658-
{
659-
if (dirty())
660-
{
661-
return true;
662-
}
663-
auto check = [](auto const &container) {
664-
for (auto const &pair : container)
665-
{
666-
if (pair.second.dirtyRecursive())
667-
{
668-
return true;
669-
}
670-
}
671-
return false;
672-
};
673-
auto &data = const_cast<Data_t &>(get()); // @todo do this better
674-
return check(data.embeddedMeshes()) || check(data.embeddedParticles()) ||
675-
check(data.embeddedDatasets()) || check(data.customHierarchies());
676-
}
677658
} // namespace openPMD
678659

679660
#undef OPENPMD_LEGAL_IDENTIFIER_CHARS

0 commit comments

Comments
 (0)