![]() |
|
|||
File indexing completed on 2025-09-17 08:59:57
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/g4/VisitVolumes.hh 0006 //---------------------------------------------------------------------------// 0007 #pragma once 0008 0009 #include <G4LogicalVolume.hh> 0010 #include <G4VPhysicalVolume.hh> 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<G4VPhysicalVolume> 0022 { 0023 using PV = G4VPhysicalVolume; 0024 using LV = G4LogicalVolume; 0025 0026 static LV const& get_lv(PV const& pv) { return *pv.GetLogicalVolume(); } 0027 0028 static void get_children(PV const& parent, std::vector<PV const*>& dst) 0029 { 0030 LV const& lv = get_lv(parent); 0031 auto num_children = lv.GetNoDaughters(); 0032 for (auto i : range(num_children)) 0033 { 0034 dst.push_back(lv.GetDaughter(i)); 0035 } 0036 } 0037 }; 0038 0039 //---------------------------------------------------------------------------// 0040 /*! 0041 * Perform a depth-first traversal of physical volumes. 0042 * 0043 * The function must have the signature 0044 * <code>bool(*)(G4VPhysicalVolume const&, int)</code> 0045 * where the return value indicates whether the volume's children should be 0046 * visited, and the integer is the depth of the volume being visited. 0047 * 0048 * By default this will visit the entire "touchable" hierarchy: this may be 0049 * very expensive! If it's desired to only visit single physical volumes, mark 0050 * them as visited using a set. 0051 */ 0052 template<class F> 0053 void visit_volume_instances(F&& visit, G4VPhysicalVolume const& world) 0054 { 0055 ScopedProfiling profile_this{"visit-geant-volume-instance"}; 0056 VolumeVisitor{world}(std::forward<F>(visit)); 0057 } 0058 0059 //---------------------------------------------------------------------------// 0060 /*! 0061 * Perform a depth-first listing of Geant4 logical volumes. 0062 * 0063 * This will visit each volume exactly once based on when it's encountered in 0064 * the hierarchy. The visitor function F should have the signature 0065 * \code void(*)(G4LogicalVolume const&) \endcode . 0066 */ 0067 template<class F> 0068 void visit_volumes(F&& vis, G4VPhysicalVolume const& parent_vol) 0069 { 0070 ScopedProfiling profile_this{"visit-geant-volume"}; 0071 0072 visit_logical_volumes(std::forward<F>(vis), parent_vol); 0073 } 0074 0075 //---------------------------------------------------------------------------// 0076 } // namespace celeritas
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |