Newer
Older
Markus Frank
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// $Id: Geant4Mapping.cpp 588 2013-06-03 11:41:35Z markus.frank $
//====================================================================
// AIDA Detector description implementation for LCD
//--------------------------------------------------------------------
//
// Author : M.Frank
//
//====================================================================
#include "DDG4/Geant4Mapping.h"
#include "G4PVPlacement.hh"
#include <stdexcept>
using namespace DD4hep::Simulation;
using namespace DD4hep::Geometry;
using namespace std;
/// Initializing Constructor
Geant4Mapping::Geant4Mapping( LCDD& lcdd, G4GeometryInfo* data)
: m_lcdd(lcdd), m_dataPtr(data)
{
}
/// Standard destructor
Geant4Mapping::~Geant4Mapping() {
if ( m_dataPtr ) delete m_dataPtr;
m_dataPtr = 0;
}
/// Possibility to define a singleton instance
Geant4Mapping& Geant4Mapping::instance() {
static Geant4Mapping inst(LCDD::getInstance(),0);
return inst;
}
/// When resolving pointers, we must check for the validity of the data block
void Geant4Mapping::checkValidity() const {
if ( m_dataPtr ) return;
throw runtime_error("Geant4Mapping: Attempt to access an invalid data block!");
}
/// Release data and pass over the ownership
Geant4Mapping::G4GeometryInfo* Geant4Mapping::detach() {
G4GeometryInfo* p = m_dataPtr;
m_dataPtr = 0;
return p;
}
/// Set a new data block
void Geant4Mapping::attach(G4GeometryInfo* data) {
m_dataPtr = data;
}
/// Accessor to resolve G4 placements
G4PVPlacement* Geant4Mapping::g4Placement(const TGeoNode* node) const {
checkValidity();
const PlacementMap& m = m_dataPtr->g4Placements;
PlacementMap::const_iterator i = m.find(node);
if ( i != m.end() ) return (*i).second;
return 0;
}
/// Accessor to resolve geometry placements
PlacedVolume Geant4Mapping::placement(const G4VPhysicalVolume* node) const {
checkValidity();
const PlacementMap& m = m_dataPtr->g4Placements;
for(PlacementMap::const_iterator i = m.begin(); i != m.end(); ++i)
if ( (*i).second == node ) return PlacedVolume((*i).first);
return PlacedVolume(0);
}