@@ -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:
@@ -418,7 +448,7 @@ void CustomHierarchy::read(
418448 currentPath.emplace_back (path);
419449 try
420450 {
421- subpath.read (mpp, currentPath);
451+ subpath.read (mpp, currentPath, meshes, particles );
422452 }
423453 catch (error::ReadError const &err)
424454 {
@@ -444,6 +474,12 @@ void CustomHierarchy::read(
444474 try
445475 {
446476 readNonscalarMesh (meshesMap, path);
477+ add_to_meshes_particles_view (
478+ currentPath,
479+ mpp.m_defaultMeshesPath ,
480+ meshes,
481+ path,
482+ meshesMap[path]);
447483 }
448484 catch (error::ReadError const &err)
449485 {
@@ -453,12 +489,19 @@ void CustomHierarchy::read(
453489 << err.what () << std::endl;
454490 meshesMap.forget (path);
455491 }
492+
456493 break ;
457494 }
458495 case internal::ContainedType::Particle: {
459496 try
460497 {
461498 readParticleSpecies (particlesMap, path);
499+ add_to_meshes_particles_view (
500+ currentPath,
501+ mpp.m_defaultParticlesPath ,
502+ particles,
503+ path,
504+ particlesMap[path]);
462505 }
463506 catch (error::ReadError const &err)
464507 {
@@ -516,12 +559,18 @@ void CustomHierarchy::read(
516559 try
517560 {
518561 readScalarMesh (meshesMap, path);
562+ add_to_meshes_particles_view (
563+ currentPath,
564+ mpp.m_defaultMeshesPath ,
565+ meshes,
566+ path,
567+ meshesMap[path]);
519568 }
520569 catch (error::ReadError const &err)
521570 {
522- std::cerr << " Cannot read scalar mesh at location '"
571+ std::cerr << " Cannot read mesh at location '"
523572 << myPath ().openPMDPath () << " /" << path
524- << " ' and will skip it due to read error:\n "
573+ << " ' and will skip them due to read error:\n "
525574 << err.what () << std::endl;
526575 meshesMap.forget (path);
527576 }
0 commit comments