DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4Mapping.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DDG4/Geant4Mapping.h>
16 #include <DD4hep/Printout.h>
17 #include <DD4hep/VolumeManager.h>
18 #include <G4PVPlacement.hh>
19 
20 using namespace dd4hep::sim;
21 
23 Geant4Mapping::Geant4Mapping(const Detector& description_ref)
24  : m_detDesc(description_ref), m_dataPtr(0) {
25 }
26 
29  if (m_dataPtr)
30  delete m_dataPtr;
31  m_dataPtr = 0;
32 }
33 
36  static Geant4Mapping inst(Detector::getInstance());
37  return inst;
38 }
39 
42  if (m_dataPtr)
43  return;
44  except("Geant4Mapping", "Attempt to access an invalid data block!");
45 }
46 
50  if (p)
51  delete p;
53  return data();
54 }
55 
59  m_dataPtr = 0;
60  return p;
61 }
62 
65  m_dataPtr = data_ptr;
66 }
67 
70  if ( m_dataPtr ) {
71  if ( m_dataPtr->g4Paths.empty() ) {
73  }
75  }
76  except("Geant4Mapping", "Cannot create volume manager without Geant4 geometry info [Invalid-Info]");
77  return {};
78 }
79 
81 dd4hep::PlacedVolume Geant4Mapping::placement(const G4VPhysicalVolume* node) const {
82  checkValidity();
84  for( const auto& entry : pm ) {
85  if ( entry.second == node )
86  return PlacedVolume(entry.first);
87  }
88  return PlacedVolume(0);
89 }
dd4hep::sim::Geant4Mapping::placement
PlacedVolume placement(const G4VPhysicalVolume *node) const
Accessor to resolve geometry placements.
Definition: Geant4Mapping.cpp:81
dd4hep::sim::Geant4Mapping::init
Geant4GeometryInfo & init()
Create and attach new data block. Delete old data block if present.
Definition: Geant4Mapping.cpp:48
Geant4Mapping.h
dd4hep::sim::Geant4Mapping::data
Geant4GeometryInfo & data() const
Access to the data pointer.
Definition: Geant4Mapping.h:58
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:163
dd4hep::Handle< Geant4GeometryInfo >
dd4hep::sim::Geant4Mapping::~Geant4Mapping
virtual ~Geant4Mapping()
Standard destructor.
Definition: Geant4Mapping.cpp:28
dd4hep::sim::Geant4Mapping::instance
static Geant4Mapping & instance()
Possibility to define a singleton instance.
Definition: Geant4Mapping.cpp:35
dd4hep::sim::Geant4Mapping::Geant4Mapping
Geant4Mapping(const Detector &description)
Initializing Constructor.
Definition: Geant4Mapping.cpp:23
VolumeManager.h
dd4hep::Detector::getInstance
static Detector & getInstance(const std::string &name="default")
—Factory method----—
Definition: DetectorImp.cpp:150
dd4hep::sim::Geant4Mapping
Geometry mapping from dd4hep to Geant 4.
Definition: Geant4Mapping.h:35
dd4hep::sim::Geant4GeometryInfo::g4Placements
Geant4GeometryMaps::PlacementMap g4Placements
Definition: Geant4GeometryInfo.h:117
dd4hep::sim::Geant4VolumeManager
The Geant4VolumeManager to facilitate optimized lookups of cell IDs from touchables.
Definition: Geant4VolumeManager.h:42
dd4hep::sim::Geant4Mapping::volumeManager
Geant4VolumeManager volumeManager() const
Access the volume manager.
Definition: Geant4Mapping.cpp:69
dd4hep::sim::Geant4Mapping::m_detDesc
const Detector & m_detDesc
Definition: Geant4Mapping.h:37
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4GeometryInfo
Concreate class holding the relation information between geant4 objects and dd4hep objects.
Definition: Geant4GeometryInfo.h:93
dd4hep::sim::Geant4Mapping::attach
void attach(Geant4GeometryInfo *data)
Set a new data block.
Definition: Geant4Mapping.cpp:64
dd4hep::sim::Geant4GeometryInfo::g4Paths
std::map< Geant4PlacementPath, Placement > g4Paths
Definition: Geant4GeometryInfo.h:136
dd4hep::sim::Geant4Mapping::m_dataPtr
Geant4GeometryInfo * m_dataPtr
Definition: Geant4Mapping.h:38
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::sim::Geant4Mapping::checkValidity
void checkValidity() const
When resolving pointers, we must check for the validity of the data block.
Definition: Geant4Mapping.cpp:41
dd4hep::sim::Geant4Mapping::detach
Geant4GeometryInfo * detach()
Release data and pass over the ownership.
Definition: Geant4Mapping.cpp:57
Printout.h
dd4hep::sim::Geant4GeometryMaps::PlacementMap
std::map< PlacedVolume, G4VPhysicalVolume * > PlacementMap
Definition: Geant4GeometryInfo.h:72