Skip to content

Commit

Permalink
Some cleanup in CustomHierarchies class
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Aug 16, 2024
1 parent e1c6fd1 commit f28de4f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 44 deletions.
46 changes: 32 additions & 14 deletions include/openPMD/CustomHierarchy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,25 @@ namespace internal

void syncAttributables();

Container<CustomHierarchy> customHierarchies()
#if 0
inline Container<CustomHierarchy> customHierarchiesWrapped()
{
Container<CustomHierarchy> res;
res.setData(
{static_cast<ContainerData<CustomHierarchy> *>(this),
[](auto const *) {}});
return res;
}
Container<RecordComponent> embeddedDatasets()
#endif
inline Container<RecordComponent> embeddedDatasetsWrapped()
{
Container<RecordComponent> res;
res.setData(
{static_cast<ContainerData<RecordComponent> *>(this),
[](auto const *) {}});
return res;
}
Container<Mesh> embeddedMeshes()
inline Container<Mesh> embeddedMeshesWrapped()
{
Container<Mesh> res;
res.setData(
Expand All @@ -110,14 +112,40 @@ namespace internal
return res;
}

Container<ParticleSpecies> embeddedParticles()
inline Container<ParticleSpecies> embeddedParticlesWrapped()
{
Container<ParticleSpecies> res;
res.setData(
{static_cast<ContainerData<ParticleSpecies> *>(this),
[](auto const *) {}});
return res;
}

#if 0
inline Container<CustomHierarchy>::InternalContainer &
customHierarchiesInternal()
{
return static_cast<ContainerData<CustomHierarchy> *>(this)
->m_container;
}
#endif
inline Container<RecordComponent>::InternalContainer &
embeddedDatasetsInternal()
{
return static_cast<ContainerData<RecordComponent> *>(this)
->m_container;
}
inline Container<Mesh>::InternalContainer &embeddedMeshesInternal()
{
return static_cast<ContainerData<Mesh> *>(this)->m_container;
}

inline Container<ParticleSpecies>::InternalContainer &
embeddedParticlesInternal()
{
return static_cast<ContainerData<ParticleSpecies> *>(this)
->m_container;
}
};
} // namespace internal

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

/*
* @brief Check recursively whether this object is dirty.
* It is dirty if any attribute or dataset is read from or written to
* the backend.
*
* @return true If dirty.
* @return false Otherwise.
*/
bool dirtyRecursive() const;

public:
CustomHierarchy(CustomHierarchy const &other) = default;
CustomHierarchy(CustomHierarchy &&other) = default;
Expand Down
41 changes: 11 additions & 30 deletions src/CustomHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ void CustomHierarchy::read(

std::deque<std::string> constantComponentsPushback;
auto &data = get();
EraseStaleMeshes meshesMap(data.embeddedMeshes());
EraseStaleParticles particlesMap(data.embeddedParticles());
EraseStaleMeshes meshesMap(data.embeddedMeshesWrapped());
EraseStaleParticles particlesMap(data.embeddedParticlesWrapped());
for (auto const &path : *pList.paths)
{
switch (mpp.determineType(currentPath))
Expand Down Expand Up @@ -487,7 +487,8 @@ void CustomHierarchy::read(
// Group is a bit of an internal misnomer here, it just means that
// it matches neither meshes nor particles path
case internal::ContainedType::Group: {
auto &rc = data.embeddedDatasets()[path];
auto embeddedDatasets = data.embeddedDatasetsWrapped();
auto &rc = embeddedDatasets[path];
Parameter<Operation::OPEN_DATASET> dOpen;
dOpen.name = path;
IOHandler()->enqueue(IOTask(&rc, dOpen));
Expand All @@ -505,7 +506,7 @@ void CustomHierarchy::read(
<< "' at path '" << myPath().openPMDPath()
<< "' and will skip it due to read error:\n"
<< err.what() << std::endl;
data.embeddedDatasets().container().erase(path);
embeddedDatasets.erase(path);
}
break;
}
Expand All @@ -528,7 +529,8 @@ void CustomHierarchy::read(

for (auto const &path : constantComponentsPushback)
{
auto &rc = data.embeddedDatasets()[path];
auto embeddedDatasets = data.embeddedDatasetsWrapped();
auto &rc = embeddedDatasets[path];
try
{
Parameter<Operation::OPEN_PATH> pOpen;
Expand All @@ -543,7 +545,7 @@ void CustomHierarchy::read(
<< myPath().openPMDPath() << "/" << path
<< "' and will skip it due to read error:\n"
<< err.what() << std::endl;
data.embeddedDatasets().container().erase(path);
embeddedDatasets.erase(path);
}
}
setDirty(false);
Expand Down Expand Up @@ -580,7 +582,7 @@ void CustomHierarchy::flush_internal(
subpath.flush_internal(flushParams, mpp, currentPath);
currentPath.pop_back();
}
for (auto &[name, mesh] : data.embeddedMeshes())
for (auto &[name, mesh] : data.embeddedMeshesInternal())
{
if (!mpp.isMeshContainer(currentPath))
{
Expand All @@ -604,7 +606,7 @@ void CustomHierarchy::flush_internal(
}
mesh.flush(name, flushParams);
}
for (auto &[name, particleSpecies] : data.embeddedParticles())
for (auto &[name, particleSpecies] : data.embeddedParticlesInternal())
{
if (!mpp.isParticleContainer(currentPath))
{
Expand All @@ -630,7 +632,7 @@ void CustomHierarchy::flush_internal(
}
particleSpecies.flush(name, flushParams);
}
for (auto &[name, dataset] : get().embeddedDatasets())
for (auto &[name, dataset] : get().embeddedDatasetsInternal())
{
dataset.flush(name, flushParams, /* set_defaults = */ false);
}
Expand All @@ -653,27 +655,6 @@ void CustomHierarchy::linkHierarchy(Writable &w)
{
Attributable::linkHierarchy(w);
}

bool CustomHierarchy::dirtyRecursive() const
{
if (dirty())
{
return true;
}
auto check = [](auto const &container) {
for (auto const &pair : container)
{
if (pair.second.dirtyRecursive())
{
return true;
}
}
return false;
};
auto &data = const_cast<Data_t &>(get()); // @todo do this better
return check(data.embeddedMeshes()) || check(data.embeddedParticles()) ||
check(data.embeddedDatasets()) || check(data.customHierarchies());
}
} // namespace openPMD

#undef OPENPMD_LEGAL_IDENTIFIER_CHARS
Expand Down

0 comments on commit f28de4f

Please sign in to comment.