ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetConditions
TRT_ConditionsAlgs
src
TRTCondWrite.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 <fstream>
6
#include <iostream>
7
#include <string>
8
#include "
TRTCondWrite.h
"
9
#include "
TRT_ConditionsData/BasicRtRelation.h
"
10
#include "
TRT_ConditionsData/DinesRtRelation.h
"
11
#include "
TRT_ConditionsData/BinnedRtRelation.h
"
12
#include "
TRT_ConditionsData/RtRelationFactory.h
"
13
#include "
StoreGate/WriteCondHandle.h
"
14
22
TRTCondWrite::TRTCondWrite
(
const
std::string &name, ISvcLocator *pSvcLocator)
23
:
AthCondAlgorithm
(name, pSvcLocator) {}
24
25
StatusCode
TRTCondWrite::initialize
()
26
{
27
28
ATH_MSG_DEBUG
(
"TRTCondWrite::initialize() called"
);
29
30
// Get ID helper
31
ATH_CHECK
(
detStore
()->retrieve(
m_trtid
,
"TRT_ID"
));
32
33
// Get condSvc
34
ATH_CHECK
(
m_condSvc
.retrieve());
35
36
// Format of input text file
37
int
format = 0;
38
if
(
m_par_caltextfile
!=
""
)
39
{
40
ATH_MSG_INFO
(
" input text file supplied "
<<
m_par_caltextfile
);
41
if
(StatusCode::SUCCESS !=
checkTextFile
(
m_par_caltextfile
, format))
42
{
43
ATH_MSG_INFO
(
"Could not find or could not read text file"
<<
m_par_caltextfile
);
44
return
StatusCode::SUCCESS;
45
}
46
ATH_MSG_INFO
(
" Found format "
<< format <<
" in text file "
<<
m_par_caltextfile
);
47
}
48
else
49
{
50
ATH_MSG_ERROR
(
" No input text file supplied. Initialization done. "
);
51
return
StatusCode::FAILURE;
52
}
53
54
// Write keys
55
// If an input text file is specified, initialize write keys. The corresponding folders must be blocked.
56
57
if
(
m_par_caltextfile
!=
""
&& format > 0)
58
{
59
ATH_CHECK
(
m_rtWriteKey
.initialize());
60
ATH_CHECK
(
m_t0WriteKey
.initialize());
61
}
62
ATH_MSG_INFO
(
" Initilization done with WriteKey Registraton "
);
63
64
return
StatusCode::SUCCESS;
65
}
66
67
StatusCode
TRTCondWrite::execute
(
const
EventContext& ctx)
const
68
{
69
70
// Read from text file?
71
if
(!
m_par_caltextfile
.empty())
72
{
73
std::ifstream infile(
m_par_caltextfile
.value().c_str());
74
if
(infile)
75
{
76
ATH_MSG_INFO
(
" Read calibration constants from text file "
<<
m_par_caltextfile
);
77
int
format = 0;
78
if
(StatusCode::SUCCESS !=
readTextFile
(ctx,
m_par_caltextfile
, format))
79
{
80
ATH_MSG_FATAL
(
"Could not read calibration objects from text file "
<<
m_par_caltextfile
);
81
return
StatusCode::FAILURE;
82
}
83
}
84
else
85
{
86
ATH_MSG_ERROR
(
"Input file does not exist "
<<
m_par_caltextfile
.value().c_str());
87
return
StatusCode::FAILURE;
88
}
89
infile.close();
90
}
91
else
92
{
93
ATH_MSG_ERROR
(
"No input filename supplied "
);
94
return
StatusCode::FAILURE;
95
}
96
97
return
StatusCode::SUCCESS;
98
;
99
}
100
101
StatusCode
TRTCondWrite::finalize
()
102
{
103
return
StatusCode::SUCCESS;
104
}
105
106
StatusCode
TRTCondWrite::checkTextFile
(
const
std::string &filename,
int
&format)
107
{
108
109
StatusCode
sc
= StatusCode::SUCCESS;
110
std::ifstream infile(filename.c_str());
111
if
(!infile)
112
{
113
sc
= StatusCode::FAILURE;
114
}
115
else
116
{
117
// read the format tag. if none, default to 0
118
format = 0;
119
char
line[512];
120
infile.getline(line, 512);
121
std::string linestring(line);
122
size_t
pos = linestring.find(
"Fileformat"
);
123
if
(pos != std::string::npos)
124
{
125
sscanf(line,
"# Fileformat=%d"
, &format);
126
}
127
else
128
{
129
ATH_MSG_WARNING
(
"Input file has no Fileformat identifier. Assuming format=0."
);
130
// 'rewind' the file
131
132
infile.close();
133
infile.open(filename.c_str());
134
}
135
}
136
infile.close();
137
return
sc
;
138
}
139
140
StatusCode
TRTCondWrite::readTextFile
(
const
EventContext& ctx,
const
std::string &filename,
int
&format)
const
141
{
142
143
StatusCode
sc
= StatusCode::SUCCESS;
144
std::ifstream infile(filename.c_str());
145
if
(!infile)
146
{
147
ATH_MSG_ERROR
(
"Cannot find input file "
<< filename);
148
sc
= StatusCode::FAILURE;
149
}
150
else
151
{
152
// read the format tag. if none, default to 0
153
format = 0;
154
char
line[512];
155
infile.getline(line, 512);
156
std::string linestring(line);
157
size_t
pos = linestring.find(
"Fileformat"
);
158
if
(pos != std::string::npos)
159
{
160
sscanf(line,
"# Fileformat=%d"
, &format);
161
}
162
else
163
{
164
ATH_MSG_WARNING
(
"Input file has no Fileformat identifier. Assuming format=1"
);
165
// 'rewind' the file
166
167
infile.close();
168
infile.open(filename.c_str());
169
}
170
ATH_MSG_INFO
(
"Reading calibration data from text file "
<< filename <<
" format "
<< format);
171
// force format 1 here
172
sc
=
readTextFile_Format1
(ctx, infile);
173
}
174
infile.close();
175
return
sc
;
176
}
177
178
StatusCode
TRTCondWrite::readTextFile_Format1
(
const
EventContext& ctx, std::istream &infile)
const
179
{
180
181
enum
ReadMode
182
{
183
ReadingRtRelation,
184
ReadingStrawT0,
185
ReadingGarbage
186
};
187
ReadMode readmode = ReadingGarbage;
188
189
// Make containers for access via ReadCondHandle for the reconstruction.
190
std::unique_ptr<RtRelationContainer> rtCdo{std::make_unique<RtRelationContainer>()};
191
std::unique_ptr<StrawT0Container> t0Cdo{std::make_unique<StrawT0Container>()};
192
193
char
line[512];
194
int
nrtrelations(0), nstrawt0(0);
195
while
(infile.getline(line, 512))
196
{
197
if
(line[0] ==
'#'
)
198
{
199
// line with tag
200
std::string linestring(line);
201
if
(linestring.find(
"RtRelation"
) != std::string::npos)
202
{
203
readmode = ReadingRtRelation;
204
ATH_MSG_INFO
(
" Found line with Rt tag "
);
205
}
206
else
if
(linestring.find(
"StrawT0"
) != std::string::npos)
207
{
208
readmode = ReadingStrawT0;
209
ATH_MSG_INFO
(
" Found line with T0 tag "
);
210
}
211
else
212
readmode = ReadingGarbage;
213
}
214
else
if
(readmode != ReadingGarbage)
215
{
216
std::istringstream is(line);
217
// read the id
218
TRTCond::ExpandedIdentifier
id;
219
is >> id;
220
// read the semicolon that end the id
221
char
dummy;
222
is >> dummy;
223
224
// read the object
225
if
(readmode == ReadingRtRelation)
226
{
227
228
TRTCond::RtRelation
*rt =
TRTCond::RtRelationFactory::readFromFile
(is);
229
//Values read in should have their values checked against sensible limits.
230
//We assume the input is trusted however.
231
//coverity[TAINTED_SCALAR]
232
rtCdo->set(
id
, rt);
233
delete
rt;
234
++nrtrelations;
235
}
236
else
if
(readmode == ReadingStrawT0)
237
{
238
239
float
t0
(0), t0err(0);
240
is >>
t0
>> t0err;
241
if
(
t0
> 0)
242
{
243
//Values read in should have their values checked against sensible limits.
244
//We assume the input is trusted however.
245
//coverity[TAINTED_SCALAR]
246
t0Cdo->setT0(
id
,
t0
, t0err);
247
++nstrawt0;
248
}
249
}
250
}
251
}
252
253
// Check that containers were filled
254
255
size_t
t0footprint = t0Cdo->footprint();
256
size_t
rtfootprint = rtCdo->footprint();
257
258
ATH_MSG_INFO
(
"read "
<< nstrawt0 <<
" t0 and "
<< nrtrelations <<
" rt from file. "
259
<<
" t0/rt footprints "
<< t0footprint <<
" / "
<< rtfootprint <<
" t0 footprint after crunch "
<< t0Cdo->footprint());
260
261
// Record the containers for access via ReadCondHandle during reconstruction
262
const
EventIDRange rangeW =
IOVInfRange
();
263
SG::WriteCondHandle<RtRelationContainer>
rtWriteHandle{
m_rtWriteKey
, ctx};
264
if
(rtWriteHandle.
isValid
())
265
{
266
ATH_MSG_DEBUG
(
" RtRelationContainer already available "
);
267
return
StatusCode::SUCCESS;
268
}
269
270
if
(rtWriteHandle.
record
(rangeW, std::move(rtCdo)).isFailure())
271
{
272
ATH_MSG_ERROR
(
"Could not record RT Container for key "
<<
m_rtWriteKey
.fullKey() <<
" with WriteHandle "
);
273
return
StatusCode::FAILURE;
274
}
275
else
276
{
277
ATH_MSG_INFO
(
"Recorded RT Container for key "
<<
m_rtWriteKey
.fullKey() <<
" with range "
<< rtWriteHandle.
getRange
());
278
}
279
280
SG::WriteCondHandle<StrawT0Container>
t0WriteHandle{
m_t0WriteKey
, ctx};
281
if
(t0WriteHandle.
isValid
())
282
{
283
ATH_MSG_DEBUG
(
" StrawT0Container already available "
);
284
return
StatusCode::SUCCESS;
285
}
286
287
if
(t0Cdo->initialize().isFailure())
288
ATH_MSG_WARNING
(
"Could not initialize T0 Container for key "
<<
m_t0WriteKey
.fullKey());
289
290
if
(t0WriteHandle.
record
(rangeW, std::move(t0Cdo)).isFailure())
291
{
292
ATH_MSG_ERROR
(
"Could not record T0 Container for key "
<<
m_t0WriteKey
.fullKey() <<
" with WriteHandle "
);
293
return
StatusCode::FAILURE;
294
}
295
else
296
{
297
ATH_MSG_INFO
(
"Recorded T0 Container for key "
<<
m_t0WriteKey
.fullKey() <<
" with range "
<< t0WriteHandle.
getRange
());
298
}
299
300
return
StatusCode::SUCCESS;
301
}
302
303
TRTCond::ExpandedIdentifier
TRTCondWrite::trtcondid
(
const
Identifier
&
id
,
int
level)
const
304
{
305
return
TRTCond::ExpandedIdentifier
(
m_trtid
->barrel_ec(
id
),
m_trtid
->layer_or_wheel(
id
),
306
m_trtid
->phi_module(
id
),
m_trtid
->straw_layer(
id
),
307
m_trtid
->straw(
id
), level);
308
}
309
EventIDRange
TRTCondWrite::IOVInfRange
()
const
310
{
311
const
EventIDBase start{1, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM, 0};
312
const
EventIDBase stop{EventIDBase::UNDEFNUM - 1, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM - 1};
313
return
EventIDRange{start, stop};
314
}
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_FATAL
#define ATH_MSG_FATAL(x)
Definition
AthMsgStreamMacros.h:34
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
BasicRtRelation.h
BinnedRtRelation.h
DinesRtRelation.h
sc
static Double_t sc
Definition
LArPhysWaveHECTool.cxx:37
t0
static Double_t t0
Definition
LArPhysWaveHECTool.cxx:38
RtRelationFactory.h
TRTCondWrite.h
CondAlg to read TRT calibration constants in from text file and load them in ConditionsStore.
WriteCondHandle.h
AthCommonAlgorithm< Gaudi::Algorithm >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
Definition
AthCommonDataStore.h:95
AthCondAlgorithm
Base class for conditions algorithms.
Definition
AthCondAlgorithm.h:22
SG::WriteCondHandle
Definition
WriteCondHandle.h:26
SG::WriteCondHandle::getRange
const EventIDRange & getRange() const
Definition
WriteCondHandle.h:93
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition
WriteCondHandle.h:161
SG::WriteCondHandle::isValid
bool isValid() const
Definition
WriteCondHandle.h:252
TRTCondWrite::TRTCondWrite
TRTCondWrite(const std::string &name, ISvcLocator *pSvcLocator)
constructor
Definition
TRTCondWrite.cxx:22
TRTCondWrite::trtcondid
virtual TRTCond::ExpandedIdentifier trtcondid(const Identifier &id, int level=TRTCond::ExpandedIdentifier::STRAW) const
create an TRTCond::ExpandedIdentifier from a TRTID identifier
Definition
TRTCondWrite.cxx:303
TRTCondWrite::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
TRTCondWrite.cxx:67
TRTCondWrite::checkTextFile
virtual StatusCode checkTextFile(const std::string &file, int &format)
read calibration from text file into TDS
Definition
TRTCondWrite.cxx:106
TRTCondWrite::m_par_caltextfile
Gaudi::Property< std::string > m_par_caltextfile
Definition
TRTCondWrite.h:60
TRTCondWrite::m_t0WriteKey
SG::WriteCondHandleKey< StrawT0Container > m_t0WriteKey
Definition
TRTCondWrite.h:64
TRTCondWrite::initialize
virtual StatusCode initialize(void) override
Definition
TRTCondWrite.cxx:25
TRTCondWrite::m_trtid
const TRT_ID * m_trtid
trt id helper
Definition
TRTCondWrite.h:58
TRTCondWrite::m_condSvc
ServiceHandle< ICondSvc > m_condSvc
Definition
TRTCondWrite.h:59
TRTCondWrite::IOVInfRange
virtual EventIDRange IOVInfRange() const
Definition
TRTCondWrite.cxx:309
TRTCondWrite::readTextFile_Format1
virtual StatusCode readTextFile_Format1(const EventContext &, std::istream &) const
Definition
TRTCondWrite.cxx:178
TRTCondWrite::m_rtWriteKey
SG::WriteCondHandleKey< RtRelationContainer > m_rtWriteKey
Definition
TRTCondWrite.h:63
TRTCondWrite::finalize
virtual StatusCode finalize(void) override
Definition
TRTCondWrite.cxx:101
TRTCondWrite::readTextFile
virtual StatusCode readTextFile(const EventContext &ctx, const std::string &file, int &format) const
Definition
TRTCondWrite.cxx:140
TRTCond::ExpandedIdentifier
Identifier for TRT detector elements in the conditions code.
Definition
InnerDetector/InDetConditions/TRT_ConditionsData/TRT_ConditionsData/ExpandedIdentifier.h:30
TRTCond::RtRelationFactory::readFromFile
static RtRelation * readFromFile(std::istream &is)
read method
Definition
RtRelationFactory.h:33
TRTCond::RtRelation
Base class for rt-relations in the TRT.
Definition
RtRelation.h:27
Identifier
Definition
IdentifierFieldParser.cxx:14
Generated on
for ATLAS Offline Software by
1.17.0