ATLAS Offline Software
Loading...
Searching...
No Matches
TBDetDescrCnv.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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
32StatusCode
34{
35 // First call parent init
36 StatusCode sc = DetDescrConverter::initialize();
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
51StatusCode
53{
54 MsgStream log(msgSvc(), "TBDetDescrCnv");
55 log << MSG::INFO << "in finalize" << endmsg;
56
57 return StatusCode::SUCCESS;
58}
59
60//--------------------------------------------------------------------
61
62StatusCode
63TBDetDescrCnv::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
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());
121 rotationEigen<<rotation.xx(),rotation.xy(),rotation.xz(),
122 rotation.yx(),rotation.yy(),rotation.yz(),
123 rotation.zx(),rotation.zy(),rotation.zz();
124 //coverity[UNINIT]
125 TBmgr->setElement(TBElement(id,name,positionEigen,rotationEigen));
126 log << MSG::DEBUG
127 << (std::string)TBmgr->getElement(id)
128 << endmsg;
129
130 } else {
131 log << MSG::DEBUG
132 << "TBElement '" << name << "' not found among G4 volumes"
133 << endmsg;
134 }
135 }
136 }
137
138 return StatusCode::SUCCESS;
139
140}
141
142//--------------------------------------------------------------------
143
144long
149
150long
155
156//--------------------------------------------------------------------
157const CLID&
161
162//--------------------------------------------------------------------
164 :
166{
167 MsgStream log(msgSvc(), "TBDetDescrCnv");
168 log << MSG::DEBUG
169 << "in TBDetDescrCnv::TBDetDescrCnv "
170 << endmsg;
171}
#define endmsg
std::vector< Identifier > ID
const long DetDescr_StorageType
uint32_t CLID
The Class ID type.
static Double_t sc
convert to and from a SG storable
DetDescrConverter(const CLID &myCLID, ISvcLocator *svcloc, const char *name=nullptr)
static long storageType()
virtual StatusCode initialize()
TBDetDescrCnv(ISvcLocator *svcloc)
static const CLID & classID()
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
virtual long repSvcType() const
virtual StatusCode finalize()
const TBElement & getElement(TBElementID::TBElementID id) const
void setElement(const TBElement &element)
const std::string & name() const
Definition TBElement.h:34
int r
Definition globals.cxx:22
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Eigen::Matrix< double, 3, 1 > Vector3D
DataObject * asStorable(SG::DataObjectSharedPtr< T > pObject)
Default, invalid implementation of ClassID_traits.