ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
TestBeam
TBDetDescrCnv
src
TBDetDescrCnv.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
/***************************************************************************
6
Package for TestBeam Detector Description converter
7
-------------------------------------------------
8
***************************************************************************/
9
10
11
#include "
TBDetDescrCnv/TBDetDescrCnv.h
"
12
13
#include "
DetDescrCnvSvc/DetDescrConverter.h
"
14
#include "
DetDescrCnvSvc/DetDescrAddress.h
"
15
#include "
AthenaKernel/StorableConversions.h
"
16
#include "GaudiKernel/MsgStream.h"
17
#include "GaudiKernel/Bootstrap.h"
18
#include "GaudiKernel/ISvcLocator.h"
19
20
#include "
TBDetDescr/TBDetDescrManager.h
"
21
22
#include "
GeoPrimitives/GeoPrimitives.h
"
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
32
StatusCode
33
TBDetDescrCnv::initialize
()
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
51
StatusCode
52
TBDetDescrCnv::finalize
()
53
{
54
MsgStream log(msgSvc(),
"TBDetDescrCnv"
);
55
log << MSG::INFO <<
"in finalize"
<<
endmsg
;
56
57
return
StatusCode::SUCCESS;
58
}
59
60
//--------------------------------------------------------------------
61
62
StatusCode
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
101
TBElementID::TBElementID
id
= (
TBElementID::TBElementID
)iid;
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
//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
144
long
145
TBDetDescrCnv::storageType
()
146
{
147
return
DetDescr_StorageType
;
148
}
149
150
long
151
TBDetDescrCnv::repSvcType
()
const
152
{
153
return
DetDescr_StorageType
;
154
}
155
156
//--------------------------------------------------------------------
157
CLID
158
TBDetDescrCnv::classID
() {
159
return
ClassID_traits<TBDetDescrManager>::ID
();
160
}
161
162
//--------------------------------------------------------------------
163
TBDetDescrCnv::TBDetDescrCnv
(ISvcLocator* svcloc)
164
:
165
DetDescrConverter
(
ClassID_traits
<
TBDetDescrManager
>::ID(), svcloc)
166
{
167
MsgStream log(msgSvc(),
"TBDetDescrCnv"
);
168
log << MSG::DEBUG
169
<<
"in TBDetDescrCnv::TBDetDescrCnv "
170
<<
endmsg
;
171
}
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
DetDescrAddress.h
DetDescr_StorageType
const long DetDescr_StorageType
Definition
DetDescrCnvSvc.cxx:20
DetDescrConverter.h
CLID
uint32_t CLID
The Class ID type.
Definition
Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
GeoPrimitives.h
sc
static Double_t sc
Definition
LArPhysWaveHECTool.cxx:37
StorableConversions.h
convert to and from a SG storable
TBDetDescrCnv.h
TBDetDescrManager.h
DetDescrAddress
Definition
DetDescrAddress.h:32
DetDescrConverter::DetDescrConverter
DetDescrConverter(const CLID &myCLID, ISvcLocator *svcloc, const char *name=nullptr)
Definition
DetDescrConverter.cxx:34
TBDetDescrCnv::storageType
static long storageType()
Definition
TBDetDescrCnv.cxx:145
TBDetDescrCnv::initialize
virtual StatusCode initialize()
Definition
TBDetDescrCnv.cxx:33
TBDetDescrCnv::TBDetDescrCnv
TBDetDescrCnv(ISvcLocator *svcloc)
Definition
TBDetDescrCnv.cxx:163
TBDetDescrCnv::classID
static CLID classID()
Definition
TBDetDescrCnv.cxx:158
TBDetDescrCnv::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
Definition
TBDetDescrCnv.cxx:63
TBDetDescrCnv::repSvcType
virtual long repSvcType() const
Definition
TBDetDescrCnv.cxx:151
TBDetDescrCnv::finalize
virtual StatusCode finalize()
Definition
TBDetDescrCnv.cxx:52
TBDetDescrManager
Definition
TBDetDescrManager.h:21
TBDetDescrManager::getElement
const TBElement & getElement(TBElementID::TBElementID id) const
Definition
TBDetDescrManager.cxx:121
TBDetDescrManager::setElement
void setElement(const TBElement &element)
Definition
TBDetDescrManager.cxx:128
TBElement
Definition
TBElement.h:20
TBElement::name
const std::string & name() const
Definition
TBElement.h:34
r
int r
Definition
globals.cxx:22
Amg::RotationMatrix3D
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Definition
GeoPrimitives.h:50
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition
GeoPrimitives.h:48
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition
PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::asStorable
DataObject * asStorable(SG::DataObjectSharedPtr< T > pObject)
Definition
DataObjectSharedPtr.h:31
TBElementID::TBElementID
TBElementID
Definition
TBElementID.h:11
TBElementID::TotalSize
@ TotalSize
Definition
TBElementID.h:59
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition
Control/AthenaKernel/AthenaKernel/ClassID_traits.h:37
ClassID_traits::ID
static constexpr CLID ID()
Definition
Control/AthenaKernel/AthenaKernel/ClassID_traits.h:44
Generated on
for ATLAS Offline Software by
1.17.0