File indexing completed on 2025-01-18 09:14:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DDG4/Geant4Mapping.h>
0016 #include <DD4hep/Printout.h>
0017 #include <DD4hep/VolumeManager.h>
0018 #include <G4PVPlacement.hh>
0019
0020 using namespace dd4hep::sim;
0021
0022
0023 Geant4Mapping::Geant4Mapping(const Detector& description_ref)
0024 : m_detDesc(description_ref), m_dataPtr(0) {
0025 }
0026
0027
0028 Geant4Mapping::~Geant4Mapping() {
0029 if (m_dataPtr)
0030 delete m_dataPtr;
0031 m_dataPtr = 0;
0032 }
0033
0034
0035 Geant4Mapping& Geant4Mapping::instance() {
0036 static Geant4Mapping inst(Detector::getInstance());
0037 return inst;
0038 }
0039
0040
0041 void Geant4Mapping::checkValidity() const {
0042 if (m_dataPtr)
0043 return;
0044 except("Geant4Mapping", "Attempt to access an invalid data block!");
0045 }
0046
0047
0048 Geant4GeometryInfo& Geant4Mapping::init() {
0049 Geant4GeometryInfo* p = detach();
0050 if (p)
0051 delete p;
0052 attach(new Geant4GeometryInfo());
0053 return data();
0054 }
0055
0056
0057 Geant4GeometryInfo* Geant4Mapping::detach() {
0058 Geant4GeometryInfo* p = m_dataPtr;
0059 m_dataPtr = 0;
0060 return p;
0061 }
0062
0063
0064 void Geant4Mapping::attach(Geant4GeometryInfo* data_ptr) {
0065 m_dataPtr = data_ptr;
0066 }
0067
0068
0069 Geant4VolumeManager Geant4Mapping::volumeManager() const {
0070 if ( m_dataPtr ) {
0071 if ( m_dataPtr->g4Paths.empty() ) {
0072 return Geant4VolumeManager(m_detDesc, m_dataPtr);
0073 }
0074 return Geant4VolumeManager(Handle < Geant4GeometryInfo > (m_dataPtr));
0075 }
0076 except("Geant4Mapping", "Cannot create volume manager without Geant4 geometry info [Invalid-Info]");
0077 return {};
0078 }
0079
0080
0081 dd4hep::PlacedVolume Geant4Mapping::placement(const G4VPhysicalVolume* node) const {
0082 checkValidity();
0083 const Geant4GeometryMaps::PlacementMap& pm = m_dataPtr->g4Placements;
0084 for( const auto& entry : pm ) {
0085 if ( entry.second == node )
0086 return PlacedVolume(entry.first);
0087 }
0088 return PlacedVolume(0);
0089 }