Skip to content

Commit fd65afd

Browse files
committed
Fix wrong application of EraseScalarEntries
1 parent ab49962 commit fd65afd

2 files changed

Lines changed: 24 additions & 29 deletions

File tree

include/openPMD/CustomHierarchy.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,12 @@ class CustomHierarchy : public Container<CustomHierarchy>
101101
return *m_customHierarchyData;
102102
}
103103

104-
void readNonscalarMesh(std::string const &name);
105-
void readScalarMesh(std::string const &name);
106-
void readParticleSpecies(std::string const &name);
104+
using EraseStaleMeshes = internal::EraseStaleEntries<Container<Mesh>>;
105+
using EraseStaleParticles =
106+
internal::EraseStaleEntries<Container<ParticleSpecies>>;
107+
void readNonscalarMesh(EraseStaleMeshes &map, std::string const &name);
108+
void readScalarMesh(EraseStaleMeshes &map, std::string const &name);
109+
void readParticleSpecies(EraseStaleParticles &map, std::string const &name);
107110

108111
void flush_internal(
109112
internal::FlushParams const &,

src/CustomHierarchy.cpp

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,12 @@ CustomHierarchy::CustomHierarchy()
167167
CustomHierarchy::CustomHierarchy(NoInit) : Container_t(NoInit())
168168
{}
169169

170-
void CustomHierarchy::readNonscalarMesh(std::string const &mesh_name)
170+
void CustomHierarchy::readNonscalarMesh(
171+
EraseStaleMeshes &map, std::string const &mesh_name)
171172
{
172173
Parameter<Operation::OPEN_PATH> pOpen;
173174
Parameter<Operation::LIST_ATTS> aList;
174175

175-
internal::EraseStaleEntries<decltype(get().m_embeddedMeshes)> map{
176-
get().m_embeddedMeshes};
177176
Mesh &m = map[mesh_name];
178177

179178
pOpen.path = mesh_name;
@@ -207,16 +206,12 @@ void CustomHierarchy::readNonscalarMesh(std::string const &mesh_name)
207206
}
208207
}
209208

210-
void CustomHierarchy::readScalarMesh(std::string const &mesh_name)
209+
void CustomHierarchy::readScalarMesh(
210+
EraseStaleMeshes &map, std::string const &mesh_name)
211211
{
212212
Parameter<Operation::OPEN_PATH> pOpen;
213213
Parameter<Operation::LIST_PATHS> pList;
214214

215-
auto &data = get();
216-
217-
internal::EraseStaleEntries<decltype(data.m_embeddedMeshes)> map{
218-
data.m_embeddedMeshes};
219-
220215
Parameter<Operation::OPEN_DATASET> dOpen;
221216
Mesh &m = map[mesh_name];
222217
dOpen.name = mesh_name;
@@ -239,13 +234,12 @@ void CustomHierarchy::readScalarMesh(std::string const &mesh_name)
239234
}
240235
}
241236

242-
void CustomHierarchy::readParticleSpecies(std::string const &species_name)
237+
void CustomHierarchy::readParticleSpecies(
238+
EraseStaleParticles &map, std::string const &species_name)
243239
{
244240
Parameter<Operation::OPEN_PATH> pOpen;
245241
Parameter<Operation::LIST_PATHS> pList;
246242

247-
internal::EraseStaleEntries<decltype(get().m_embeddedParticles)> map{
248-
get().m_embeddedParticles};
249243
ParticleSpecies &p = map[species_name];
250244
pOpen.path = species_name;
251245
IOHandler()->enqueue(IOTask(&p, pOpen));
@@ -291,9 +285,10 @@ void CustomHierarchy::read(
291285
IOHandler()->enqueue(IOTask(this, dList));
292286
IOHandler()->flush(internal::defaultFlushParams);
293287

294-
meshes.dirty() = false;
295-
particles.dirty() = false;
296288
std::deque<std::string> constantComponentsPushback;
289+
auto &data = get();
290+
EraseStaleMeshes meshesMap(data.m_embeddedMeshes);
291+
EraseStaleParticles particlesMap(data.m_embeddedParticles);
297292
for (auto const &path : *pList.paths)
298293
{
299294
switch (mpp.determineType(currentPath, path))
@@ -334,38 +329,35 @@ void CustomHierarchy::read(
334329
case internal::ContainedType::Mesh: {
335330
try
336331
{
337-
readNonscalarMesh(path);
332+
readNonscalarMesh(meshesMap, path);
338333
}
339334
catch (error::ReadError const &err)
340335
{
341-
std::cerr << "Cannot read meshes at location '"
342-
<< myPath().printGroup()
336+
std::cerr << "Cannot read mesh at location '"
337+
<< myPath().printGroup() << "/" << path
343338
<< "' and will skip them due to read error:\n"
344339
<< err.what() << std::endl;
345-
meshes = {};
346-
meshes.dirty() = false;
340+
meshesMap.forget(path);
347341
}
348342
break;
349343
}
350344
case internal::ContainedType::Particle: {
351345
try
352346
{
353-
readParticleSpecies(path);
347+
readParticleSpecies(particlesMap, path);
354348
}
355349
catch (error::ReadError const &err)
356350
{
357-
std::cerr << "Cannot read particles at location '"
358-
<< myPath().printGroup()
351+
std::cerr << "Cannot read particle species at location '"
352+
<< myPath().printGroup() << "/" << path
359353
<< "' and will skip them due to read error:\n"
360354
<< err.what() << std::endl;
361-
particles = {};
362-
particles.dirty() = false;
355+
particlesMap.forget(path);
363356
}
364357
break;
365358
}
366359
}
367360
}
368-
auto &data = get();
369361
for (auto const &path : *dList.datasets)
370362
{
371363
switch (mpp.determineType(currentPath, path))
@@ -385,7 +377,7 @@ void CustomHierarchy::read(
385377
break;
386378
}
387379
case internal::ContainedType::Mesh:
388-
readScalarMesh(path);
380+
readScalarMesh(meshesMap, path);
389381
break;
390382
case internal::ContainedType::Particle:
391383
std::cerr

0 commit comments

Comments
 (0)