File indexing completed on 2026-09-19 08:32:16
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 }
0032 m_dataPtr = nullptr;
0033 }
0034
0035
0036 Geant4Mapping& Geant4Mapping::instance() {
0037 static Geant4Mapping inst(Detector::getInstance());
0038 return inst;
0039 }
0040
0041
0042 void Geant4Mapping::checkValidity() const {
0043 if ( m_dataPtr ) {
0044 return;
0045 }
0046 except("Geant4Mapping", "Attempt to access an invalid data block!");
0047 }
0048
0049
0050 Geant4GeometryInfo& Geant4Mapping::init() {
0051 Geant4GeometryInfo* p = detach();
0052 delete p;
0053 attach(new Geant4GeometryInfo());
0054 return data();
0055 }
0056
0057
0058 Geant4GeometryInfo* Geant4Mapping::detach() {
0059 Geant4GeometryInfo* p = m_dataPtr;
0060 m_dataPtr = 0;
0061 return p;
0062 }
0063
0064
0065 void Geant4Mapping::attach(Geant4GeometryInfo* data_ptr) {
0066 m_dataPtr = data_ptr;
0067 }
0068
0069
0070 Geant4VolumeManager Geant4Mapping::volumeManager() const {
0071 if ( m_dataPtr ) {
0072 if ( haveVolManager ) {
0073 if ( !m_dataPtr->has_volmgr ) {
0074 return Geant4VolumeManager(m_detDesc, m_dataPtr, this->debugVolManager);
0075 }
0076 return Geant4VolumeManager(Handle < Geant4GeometryInfo > (m_dataPtr));
0077 }
0078 except("Geant4Mapping",
0079 "Volume manager creation/access was disabled. "
0080 "No access to Geant4VolumeManager!");
0081 }
0082 except("Geant4Mapping", "Cannot create volume manager without Geant4 geometry info [Invalid-Info]");
0083 return {};
0084 }
0085
0086
0087 dd4hep::PlacedVolume Geant4Mapping::placement(const G4VPhysicalVolume* node) const {
0088 checkValidity();
0089 const Geant4GeometryMaps::PlacementMap& pm = m_dataPtr->g4Placements;
0090 for ( const auto& entry : pm ) {
0091 if ( entry.second == node )
0092 return PlacedVolume(entry.first);
0093 }
0094 return PlacedVolume(0);
0095 }