Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:59:59

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file geocel/vg/VisitVolumes.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <VecGeom/volumes/LogicalVolume.h>
0010 #include <VecGeom/volumes/PlacedVolume.h>
0011 
0012 #include "corecel/Assert.hh"
0013 #include "corecel/cont/Range.hh"
0014 #include "corecel/sys/ScopedProfiling.hh"
0015 #include "geocel/VolumeVisitor.hh"
0016 
0017 namespace celeritas
0018 {
0019 //---------------------------------------------------------------------------//
0020 template<>
0021 struct VolumeVisitorTraits<vecgeom::VPlacedVolume>
0022 {
0023     using PV = vecgeom::VPlacedVolume;
0024     using LV = vecgeom::LogicalVolume;
0025 
0026     static void get_children(PV const& parent, std::vector<PV const*>& dst)
0027     {
0028         auto const& daughters = parent.GetDaughters();
0029         dst.assign(daughters.begin(), daughters.end());
0030     }
0031 
0032     static LV const& get_lv(PV const& pv) { return *pv.GetLogicalVolume(); }
0033 };
0034 
0035 //---------------------------------------------------------------------------//
0036 /*!
0037  * Perform a depth-first traversal of physical volumes.
0038  *
0039  * The function must have the signature
0040  * <code>bool(*)(G4VPhysicalVolume const&, int)</code>
0041  * where the return value indicates whether the volume's children should be
0042  * visited, and the integer is the depth of the volume being visited.
0043  *
0044  * By default this will visit the entire "touchable" hierarchy: this may be
0045  * very expensive! If it's desired to only visit single physical volumes, mark
0046  * them as visited using a set.
0047  */
0048 template<class F>
0049 void visit_volume_instances(F&& visit, vecgeom::VPlacedVolume const& world)
0050 {
0051     ScopedProfiling profile_this{"visit-vecgeom-volume-instance"};
0052     VolumeVisitor{world}(std::forward<F>(visit));
0053 }
0054 
0055 //---------------------------------------------------------------------------//
0056 /*!
0057  * Perform a depth-first listing of Geant4 logical volumes.
0058  *
0059  * This will visit each volume exactly once based on when it's encountered in
0060  * the hierarchy. The visitor function F should have the signature
0061  * \code void(*)(G4LogicalVolume const&) \endcode .
0062  */
0063 template<class F>
0064 void visit_volumes(F&& vis, vecgeom::VPlacedVolume const& parent_vol)
0065 {
0066     ScopedProfiling profile_this{"visit-vecgeom-volume"};
0067 
0068     visit_logical_volumes(std::forward<F>(vis), parent_vol);
0069 }
0070 
0071 //---------------------------------------------------------------------------//
0072 }  // namespace celeritas