Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:27

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   m_dataPtr = 0;
0032 }
0033 
0034 /// Possibility to define a singleton instance
0035 Geant4Mapping& Geant4Mapping::instance() {
0036   static Geant4Mapping inst(Detector::getInstance());
0037   return inst;
0038 }
0039 
0040 /// When resolving pointers, we must check for the validity of the data block
0041 void Geant4Mapping::checkValidity() const {
0042   if (m_dataPtr)
0043     return;
0044   except("Geant4Mapping", "Attempt to access an invalid data block!");
0045 }
0046 
0047 /// Create new data block. Delete old data block if present.
0048 Geant4GeometryInfo& Geant4Mapping::init() {
0049   Geant4GeometryInfo* p = detach();
0050   if (p)
0051     delete p;
0052   attach(new Geant4GeometryInfo());
0053   return data();
0054 }
0055 
0056 /// Release data and pass over the ownership
0057 Geant4GeometryInfo* Geant4Mapping::detach() {
0058   Geant4GeometryInfo* p = m_dataPtr;
0059   m_dataPtr = 0;
0060   return p;
0061 }
0062 
0063 /// Set a new data block
0064 void Geant4Mapping::attach(Geant4GeometryInfo* data_ptr) {
0065   m_dataPtr = data_ptr;
0066 }
0067 
0068 /// Access the volume manager
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 /// Accessor to resolve geometry placements
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 }