ATLAS Offline Software
TBDetDescrCnv.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /***************************************************************************
6  Package for TestBeam Detector Description converter
7  -------------------------------------------------
8  ***************************************************************************/
9 
10 
12 
16 #include "GaudiKernel/MsgStream.h"
17 #include "GaudiKernel/Bootstrap.h"
18 #include "GaudiKernel/ISvcLocator.h"
19 
21 
23 
24 //needed to access G4 geometry
25 #include "G4PhysicalVolumeStore.hh"
26 #include "G4VPhysicalVolume.hh"
27 
28 #include <CLHEP/Geometry/Vector3D.h>
29 
30 #include <string>
31 
34 {
35  // First call parent init
37 
38  MsgStream log(msgSvc(), "TBDetDescrCnv");
39  log << MSG::INFO << "in initialize" << endmsg;
40 
41  if (sc.isFailure()) {
42  log << MSG::ERROR << "DetDescrConverter::initialize failed" << endmsg;
43  return sc;
44  }
45 
46  return StatusCode::SUCCESS;
47 }
48 
49 //--------------------------------------------------------------------
50 
53 {
54  MsgStream log(msgSvc(), "TBDetDescrCnv");
55  log << MSG::INFO << "in finalize" << endmsg;
56 
57  return StatusCode::SUCCESS;
58 }
59 
60 //--------------------------------------------------------------------
61 
63 TBDetDescrCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
64 {
65  //StatusCode sc = StatusCode::SUCCESS;
66  MsgStream log(msgSvc(), "TBDetDescrCnv");
67  log << MSG::INFO
68  << "in createObj: creating a TBDetDescrManager object in the detector store"
69  << endmsg;
70 
71  // Create a new TBDetDescrManager
72 
73  DetDescrAddress* ddAddr;
74  ddAddr = dynamic_cast<DetDescrAddress*> (pAddr);
75  if(!ddAddr) {
76  log << MSG::FATAL << "Could not cast to DetDescrAddress." << endmsg;
77  return StatusCode::FAILURE;
78  }
79 
80  // Get the StoreGate key of this container.
81  std::string mgrKey = *( ddAddr->par() );
82  if ("" == mgrKey) {
83  log << MSG::DEBUG << "No Manager key " << endmsg;
84  }
85  else {
86  log << MSG::DEBUG << "Manager key is " << mgrKey << endmsg;
87  }
88 
89  // Create the manager
90  TBDetDescrManager* TBmgr = new TBDetDescrManager();
91 
92  // Pass a pointer to the container to the Persistency service by reference.
93  pObj = SG::asStorable(TBmgr);
94 
95  // Initialize the TBDetDescr manager from FADS
96 
97  // Go through the physical volumes and hook the SDs up
98  G4PhysicalVolumeStore *physicalVolumeStore = G4PhysicalVolumeStore::GetInstance();
99  for (unsigned int iid=0; iid<TBElementID::TotalSize; ++iid) {
100 
102  std::string name=TBmgr->getElement(id).name();
103 
104  if (name.length() > 0) {
105 
106  G4String det = name;
107  G4VPhysicalVolume *thePhysicalVolume = physicalVolumeStore->GetVolume(det,false);
108  //NB This call will just return the first one which matches,
109  //there is no protection against multiple volumes with the same
110  //name.
111  if (thePhysicalVolume) {
112  HepGeom::Vector3D<double> position = thePhysicalVolume->GetTranslation();//possibly GetFrameTranslation() or GetObjectTranslation()??
113  CLHEP::HepRotation rotation;
114  G4RotationMatrix *r=thePhysicalVolume->GetRotation(); //possibly GetFrameRotation() or GetObjectRotation()??
115  if(r)
116  {
117  rotation = (*r);
118  }
119  Amg::Vector3D positionEigen=Amg::Vector3D(position.x(), position.y(), position.z());
120  Amg::RotationMatrix3D rotationEigen=Amg::RotationMatrix3D(3,3);
121  rotationEigen<<rotation.xx(),rotation.xy(),rotation.xz(),
122  rotation.yx(),rotation.yy(),rotation.yz(),
123  rotation.zx(),rotation.zy(),rotation.zz();
124  TBmgr->setElement(TBElement(id,name,positionEigen,rotationEigen));
125  log << MSG::DEBUG
126  << (std::string)TBmgr->getElement(id)
127  << endmsg;
128 
129  } else {
130  log << MSG::DEBUG
131  << "TBElement '" << name << "' not found among G4 volumes"
132  << endmsg;
133  }
134  }
135  }
136 
137  return StatusCode::SUCCESS;
138 
139 }
140 
141 //--------------------------------------------------------------------
142 
143 long
145 {
146  return DetDescr_StorageType;
147 }
148 
149 long
151 {
152  return DetDescr_StorageType;
153 }
154 
155 //--------------------------------------------------------------------
156 const CLID&
159 }
160 
161 //--------------------------------------------------------------------
162 TBDetDescrCnv::TBDetDescrCnv(ISvcLocator* svcloc)
163  :
165 {
166  MsgStream log(msgSvc(), "TBDetDescrCnv");
167  log << MSG::DEBUG
168  << "in TBDetDescrCnv::TBDetDescrCnv "
169  << endmsg;
170 }
beamspotman.r
def r
Definition: beamspotman.py:676
TBElement::name
const std::string & name() const
Definition: TBElement.h:34
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
DetDescr_StorageType
const long DetDescr_StorageType
Definition: DetDescrCnvSvc.cxx:20
ID
std::vector< Identifier > ID
Definition: CalibHitIDCheck.h:24
TBDetDescrManager.h
StorableConversions.h
convert to and from a SG storable
TRTCalib_Extractor.det
det
Definition: TRTCalib_Extractor.py:36
initialize
void initialize()
Definition: run_EoverP.cxx:894
TBElementID::TBElementID
TBElementID
Definition: TBElementID.h:11
DetDescrAddress.h
SG::asStorable
DataObject * asStorable(T *pObject)
Definition: StorableConversions.h:158
TBDetDescrManager::setElement
void setElement(const TBElement &element)
Definition: TBDetDescrManager.cxx:128
TBDetDescrManager::getElement
const TBElement & getElement(TBElementID::TBElementID id) const
Definition: TBDetDescrManager.cxx:121
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
GeoPrimitives.h
ClassID_traits::ID
static const CLID & ID()
the CLID of T
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:50
DetDescrConverter
Definition: DetDescrConverter.h:25
TBDetDescrCnv.h
DetDescrAddress
Definition: DetDescrAddress.h:32
TBDetDescrCnv::storageType
static long storageType()
Definition: TBDetDescrCnv.cxx:144
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
TBDetDescrCnv::TBDetDescrCnv
TBDetDescrCnv(ISvcLocator *svcloc)
Definition: TBDetDescrCnv.cxx:162
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::rotation
rotation
Definition: TrackSurface_v1.cxx:15
TBDetDescrCnv::classID
static const CLID & classID()
Definition: TBDetDescrCnv.cxx:157
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
TBDetDescrCnv::finalize
virtual StatusCode finalize()
Definition: TBDetDescrCnv.cxx:52
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
TBDetDescrCnv::initialize
virtual StatusCode initialize()
Definition: TBDetDescrCnv.cxx:33
DetDescrConverter.h
TBDetDescrManager
Definition: TBDetDescrManager.h:21
Amg::RotationMatrix3D
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Definition: GeoPrimitives.h:49
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
TBElement
Definition: TBElement.h:20
TBElementID::TotalSize
@ TotalSize
Definition: TBElementID.h:59
TBDetDescrCnv::repSvcType
virtual long repSvcType() const
Definition: TBDetDescrCnv.cxx:150
TBDetDescrCnv::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
Definition: TBDetDescrCnv.cxx:63