Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 08:32:16

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
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 /// Initializing Constructor
0023 Geant4Mapping::Geant4Mapping(const Detector& description_ref)
0024   : m_detDesc(description_ref), m_dataPtr(0) {
0025 }
0026 
0027 /// Standard destructor
0028 Geant4Mapping::~Geant4Mapping() {
0029   if ( m_dataPtr )  {
0030     delete m_dataPtr;
0031   }
0032   m_dataPtr = nullptr;
0033 }
0034 
0035 /// Possibility to define a singleton instance
0036 Geant4Mapping& Geant4Mapping::instance() {
0037   static Geant4Mapping inst(Detector::getInstance());
0038   return inst;
0039 }
0040 
0041 /// When resolving pointers, we must check for the validity of the data block
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 /// Create new data block. Delete old data block if present.
0050 Geant4GeometryInfo& Geant4Mapping::init() {
0051   Geant4GeometryInfo* p = detach();
0052   delete p;
0053   attach(new Geant4GeometryInfo());
0054   return data();
0055 }
0056 
0057 /// Release data and pass over the ownership
0058 Geant4GeometryInfo* Geant4Mapping::detach() {
0059   Geant4GeometryInfo* p = m_dataPtr;
0060   m_dataPtr = 0;
0061   return p;
0062 }
0063 
0064 /// Set a new data block
0065 void Geant4Mapping::attach(Geant4GeometryInfo* data_ptr) {
0066   m_dataPtr = data_ptr;
0067 }
0068 
0069 /// Access the volume manager
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 /// Accessor to resolve geometry placements
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 }