@@ -376,15 +376,45 @@ void CustomHierarchy::readParticleSpecies(
376376 }
377377}
378378
379- void CustomHierarchy::read (internal::MeshesParticlesPath const &mpp)
379+ void CustomHierarchy::read (
380+ internal::MeshesParticlesPath const &mpp,
381+ Container<Mesh> meshes,
382+ Container<ParticleSpecies> particles)
380383{
381384 std::vector<std::string> currentPath;
382- read (mpp, currentPath);
385+ read (mpp, currentPath, meshes, particles );
383386}
384387
388+ namespace
389+ {
390+ template <typename T>
391+ void add_to_meshes_particles_view (
392+ std::vector<std::string> const ¤tPath,
393+ std::string const &defaultMeshesParticlesPath,
394+ Container<T> &meshesOrParticles,
395+ std::string const &name,
396+ T &meshOrParticle)
397+ {
398+ if (currentPath.empty ())
399+ {
400+ throw std::runtime_error (
401+ " Meshes or particles cannot be part of the root group." );
402+ }
403+ auto concatenatedName = concatWithSep (currentPath, " /" );
404+ concatenatedName.append (1 , ' /' ).append (name);
405+ meshesOrParticles[concatenatedName] = meshOrParticle;
406+ if (concatenatedName == defaultMeshesParticlesPath + ' /' + name)
407+ {
408+ meshesOrParticles[name] = meshOrParticle;
409+ }
410+ }
411+ } // namespace
412+
385413void CustomHierarchy::read (
386414 internal::MeshesParticlesPath const &mpp,
387- std::vector<std::string> ¤tPath)
415+ std::vector<std::string> ¤tPath,
416+ Container<Mesh> meshes,
417+ Container<ParticleSpecies> particles)
388418{
389419 /*
390420 * Convention for CustomHierarchy::flush and CustomHierarchy::read:
@@ -416,7 +446,7 @@ void CustomHierarchy::read(
416446 currentPath.emplace_back (path);
417447 try
418448 {
419- subpath.read (mpp, currentPath);
449+ subpath.read (mpp, currentPath, meshes, particles );
420450 }
421451 catch (error::ReadError const &err)
422452 {
@@ -442,6 +472,12 @@ void CustomHierarchy::read(
442472 try
443473 {
444474 readNonscalarMesh (meshesMap, path);
475+ add_to_meshes_particles_view (
476+ currentPath,
477+ mpp.m_defaultMeshesPath ,
478+ meshes,
479+ path,
480+ meshesMap[path]);
445481 }
446482 catch (error::ReadError const &err)
447483 {
@@ -451,12 +487,19 @@ void CustomHierarchy::read(
451487 << err.what () << std::endl;
452488 meshesMap.forget (path);
453489 }
490+
454491 break ;
455492 }
456493 case internal::ContainedType::Particle: {
457494 try
458495 {
459496 readParticleSpecies (particlesMap, path);
497+ add_to_meshes_particles_view (
498+ currentPath,
499+ mpp.m_defaultParticlesPath ,
500+ particles,
501+ path,
502+ particlesMap[path]);
460503 }
461504 catch (error::ReadError const &err)
462505 {
@@ -514,12 +557,18 @@ void CustomHierarchy::read(
514557 try
515558 {
516559 readScalarMesh (meshesMap, path);
560+ add_to_meshes_particles_view (
561+ currentPath,
562+ mpp.m_defaultMeshesPath ,
563+ meshes,
564+ path,
565+ meshesMap[path]);
517566 }
518567 catch (error::ReadError const &err)
519568 {
520- std::cerr << " Cannot read scalar mesh at location '"
569+ std::cerr << " Cannot read mesh at location '"
521570 << myPath ().openPMDPath () << " /" << path
522- << " ' and will skip it due to read error:\n "
571+ << " ' and will skip them due to read error:\n "
523572 << err.what () << std::endl;
524573 meshesMap.forget (path);
525574 }
0 commit comments