ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArAlignment
LArAlignmentAlgs
src
LArAlignDbAlg.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
#include "
LArAlignDbAlg.h
"
6
#include "
DetDescrConditions/DetCondKeyTrans.h
"
7
8
#include <fstream>
9
10
#define LAR_ALIGN "/LAR/Align"
11
12
using
HepGeom::Translate3D;
13
using
HepGeom::Rotate3D;
14
using
CLHEP::Hep3Vector;
15
17
18
LArAlignDbAlg::LArAlignDbAlg
(
const
std::string& name, ISvcLocator* pSvcLocator) :
19
AthAlgorithm
(name, pSvcLocator),
20
m_regSvc
(
"IOVRegistrationSvc"
,name),
21
m_streamer
(
"AthenaOutputStreamTool"
)
22
{
23
}
24
25
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
26
LArAlignDbAlg::~LArAlignDbAlg
()
27
{
28
}
29
30
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
31
StatusCode
LArAlignDbAlg::initialize
()
32
{
33
ATH_MSG_DEBUG
(
" in initialize()"
);
34
35
// Get Output Stream tool for writing
36
if
(
m_writeCondObjs
) {
37
ATH_CHECK
(
m_streamer
.retrieve() );
38
}
39
40
// Get the IOVRegistrationSvc when needed
41
if
(
m_regIOV
) {
42
ATH_CHECK
(
m_regSvc
.retrieve() );
43
ATH_MSG_DEBUG
(
"Found IOVRegistrationSvc "
);
44
}
45
46
return
StatusCode::SUCCESS;
47
}
48
49
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
50
51
StatusCode
LArAlignDbAlg::execute
(
const
EventContext& ctx)
52
{
53
ATH_MSG_DEBUG
(
" in execute() "
);
54
55
int
nrun = ctx.eventID().run_number();
56
int
nevt = ctx.eventID().event_number();
57
58
ATH_MSG_DEBUG
(
" Event: ["
<< nrun <<
","
<< nevt <<
"]"
);
59
60
// If I need to write out the conditions object I'll do that on the first event
61
if
(
m_writeCondObjs
&& nevt==1) {
62
ATH_MSG_DEBUG
(
"Creating conditions objects for run "
<< nrun );
63
64
ATH_CHECK
(
createCondObjects
() );
65
ATH_CHECK
(
printCondObjects
() );
66
}
else
{
67
// Read objects from DetectorStore
68
ATH_CHECK
(
printCondObjects
() );
69
}
70
71
return
StatusCode::SUCCESS;
72
}
73
74
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
75
76
StatusCode
LArAlignDbAlg::finalize
()
77
{
78
ATH_MSG_DEBUG
(
" in finalize() "
);
79
if
(
m_writeCondObjs
) {
80
ATH_CHECK
(
streamOutCondObjects
() );
81
ATH_MSG_DEBUG
(
" Streamed out OK "
);
82
}
83
84
if
(
m_regIOV
) {
85
ATH_CHECK
(
registerCondObjects
() );
86
ATH_MSG_DEBUG
(
" Register OK "
);
87
}
88
89
return
StatusCode::SUCCESS;
90
}
91
92
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
93
94
StatusCode
LArAlignDbAlg::createCondObjects
()
95
{
96
ATH_MSG_INFO
(
" in createCondObjects() "
);
97
98
if
(
detStore
()->
contains<DetCondKeyTrans>
(
LAR_ALIGN
)) {
99
ATH_MSG_INFO
(
" DetCondKeyTrans already exists, do nothing "
);
100
return
StatusCode::SUCCESS;
101
}
102
103
// Read input file, construct relevant transforms
104
std::ifstream infile;
105
infile.open(
m_inpFile
.value().c_str());
106
107
if
(!infile.is_open()) {
108
ATH_MSG_ERROR
(
"Unable to open "
<<
m_inpFile
<<
" for reading"
);
109
return
StatusCode::FAILURE;
110
}
111
112
auto
transforms = std::make_unique<DetCondKeyTrans>();
113
114
char
commentSign =
'#'
;
115
std::string commentLine;
116
std::string key;
117
double
x
,
y
,
z
,
theta
,
phi
, rotationAngle;
118
119
while
(!infile.eof()) {
120
infile >> key;
121
if
(key.empty())
continue
;
122
if
(key[0]==commentSign)
123
std::getline(infile,commentLine);
124
else
{
125
infile >>
theta
>>
phi
>> rotationAngle >>
x
>>
y
>>
z
;
126
127
Hep3Vector axis(sin(
theta
)*cos(
phi
),sin(
theta
)*sin(
phi
),cos(
theta
));
128
transforms->setTransform(key,Translate3D(
x
,
y
,
z
)*Rotate3D(rotationAngle,axis));
129
}
130
}
131
infile.close();
132
133
ATH_CHECK
(
detStore
()->record(std::move(transforms),
LAR_ALIGN
) );
134
ATH_MSG_DEBUG
(
" Recorded LAr/Align "
);
135
136
return
StatusCode::SUCCESS;
137
}
138
139
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
140
141
StatusCode
LArAlignDbAlg::printCondObjects
()
142
{
143
const
DetCondKeyTrans
* align;
144
StatusCode
sc
=
detStore
()->retrieve(align,
LAR_ALIGN
);
145
146
if
(
sc
.isFailure())
147
ATH_MSG_WARNING
(
" Could not find DetCondKeyTrans"
);
148
else
if
(
nullptr
== align)
149
ATH_MSG_WARNING
(
" DetCondKeyTrans ptr is 0"
);
150
else
{
151
std::cout <<
" \n\n**************************************************** \n"
;
152
std::cout <<
" **** **** \n"
;
153
std::cout <<
" **** Printing Conditions Objects **** \n"
;
154
std::cout <<
" **** **** \n"
;
155
std::cout <<
" **************************************************** \n"
;
156
157
align->
print
();
158
159
std::cout <<
" **** **** **** **** END **** **** **** **** \n\n\n"
;
160
}
161
162
return
StatusCode::SUCCESS;
163
}
164
165
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
166
167
StatusCode
LArAlignDbAlg::streamOutCondObjects
()
168
{
169
ATH_MSG_DEBUG
(
" entering streamOutCondObjects "
);
170
171
ATH_CHECK
(
m_streamer
->connectOutput(
m_outpFile
.value()) );
172
ATH_MSG_DEBUG
(
" Did connect stream to output"
);
173
174
int
npairs = 1;
175
176
IAthenaOutputStreamTool::TypeKeyPairs
typeKeys(npairs);
177
178
IAthenaOutputStreamTool::TypeKeyPair
align(
"DetCondKeyTrans"
,
LAR_ALIGN
);
179
typeKeys[0] = std::move(align);
180
181
ATH_CHECK
(
m_streamer
->streamObjects(typeKeys) );
182
ATH_CHECK
(
m_streamer
->commitOutput() );
183
184
return
StatusCode::SUCCESS;
185
}
186
187
188
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
189
190
StatusCode
LArAlignDbAlg::registerCondObjects
()
191
{
192
ATH_MSG_DEBUG
(
"entering registerCondObject()"
);
193
194
std::string objname =
"DetCondKeyTrans"
;
195
196
// Register the IOV DB with the conditions data written out
197
ATH_CHECK
(
m_regSvc
->registerIOV(objname,
m_outpTag
) );
198
return
StatusCode::SUCCESS;
199
}
200
phi
Scalar phi() const
phi method
Definition
AmgMatrixBasePlugin.h:67
theta
Scalar theta() const
theta method
Definition
AmgMatrixBasePlugin.h:75
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
DetCondKeyTrans.h
LAR_ALIGN
#define LAR_ALIGN
Definition
LArAlignDbAlg.cxx:10
LArAlignDbAlg.h
sc
static Double_t sc
Definition
LArPhysWaveHECTool.cxx:37
y
#define y
x
#define x
z
#define z
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
Definition
AthCommonDataStore.h:95
DetCondKeyTrans
Class to hold set of HepGeom::Transform3D keyed by string value for storage in the conditions DB typi...
Definition
DetCondKeyTrans.h:27
DetCondKeyTrans::print
void print() const
Definition
DetCondKeyTrans.cxx:30
IAthenaOutputStreamTool::TypeKeyPair
std::pair< std::string, std::string > TypeKeyPair
Stream out objects.
Definition
IAthenaOutputStreamTool.h:99
IAthenaOutputStreamTool::TypeKeyPairs
std::vector< TypeKeyPair > TypeKeyPairs
Definition
IAthenaOutputStreamTool.h:100
LArAlignDbAlg::m_inpFile
StringProperty m_inpFile
Definition
LArAlignDbAlg.h:42
LArAlignDbAlg::m_regIOV
BooleanProperty m_regIOV
Definition
LArAlignDbAlg.h:40
LArAlignDbAlg::m_regSvc
ServiceHandle< IIOVRegistrationSvc > m_regSvc
Definition
LArAlignDbAlg.h:46
LArAlignDbAlg::registerCondObjects
StatusCode registerCondObjects()
Definition
LArAlignDbAlg.cxx:190
LArAlignDbAlg::~LArAlignDbAlg
~LArAlignDbAlg()
Definition
LArAlignDbAlg.cxx:26
LArAlignDbAlg::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
LArAlignDbAlg.cxx:51
LArAlignDbAlg::m_outpTag
StringProperty m_outpTag
Definition
LArAlignDbAlg.h:44
LArAlignDbAlg::m_outpFile
StringProperty m_outpFile
Definition
LArAlignDbAlg.h:43
LArAlignDbAlg::initialize
virtual StatusCode initialize() override
Definition
LArAlignDbAlg.cxx:31
LArAlignDbAlg::finalize
virtual StatusCode finalize() override
Definition
LArAlignDbAlg.cxx:76
LArAlignDbAlg::LArAlignDbAlg
LArAlignDbAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
LArAlignDbAlg.cxx:18
LArAlignDbAlg::m_streamer
ToolHandle< IAthenaOutputStreamTool > m_streamer
Definition
LArAlignDbAlg.h:47
LArAlignDbAlg::printCondObjects
StatusCode printCondObjects()
Definition
LArAlignDbAlg.cxx:141
LArAlignDbAlg::createCondObjects
StatusCode createCondObjects()
Definition
LArAlignDbAlg.cxx:94
LArAlignDbAlg::m_writeCondObjs
BooleanProperty m_writeCondObjs
Definition
LArAlignDbAlg.h:39
LArAlignDbAlg::streamOutCondObjects
StatusCode streamOutCondObjects()
Definition
LArAlignDbAlg.cxx:167
contains
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
Definition
hcg.cxx:116
Generated on
for ATLAS Offline Software by
1.17.0