ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaExamples
AthExHive
src
condEx
ASCIICondDbSvc.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
#include "
ASCIICondDbSvc.h
"
6
#include "
AthenaKernel/CondCont.h
"
7
8
#include <regex>
9
#include <ranges>
10
11
#include <fstream>
12
13
const
std::string
r_t
(
"\\[([0-9]+),([0-9]+)\\]"
);
14
const
std::string
r_r
=
"\\s*\\{"
+
r_t
+
"-"
+
r_t
+
"\\}\\s*"
;
15
const
std::string
r_e
=
"\\s*\\{"
+
r_t
+
"-"
+
r_t
+
"\\}=([0-9]+)\\s*"
;
16
const
std::string
r_ef
=
"\\s*\\{"
+
r_t
+
"-"
+
r_t
+
"\\}=(-*[0-9]*\\.*[0-9]*)\\s*"
;
17
const
std::regex
rr
(
r_r
);
18
const
std::regex
re
(
r_e
);
19
const
std::regex
ref
(
r_ef
);
20
21
22
//---------------------------------------------------------------------------
23
24
ASCIICondDbSvc::ASCIICondDbSvc
(
const
std::string& name, ISvcLocator* svcLoc ):
25
base_class(name,svcLoc)
26
{}
27
28
//---------------------------------------------------------------------------
29
30
StatusCode
31
ASCIICondDbSvc::initialize
() {
32
33
// Initialise mother class in order to print DEBUG messages during initialize()
34
StatusCode
sc
(AthService::initialize());
35
msg
().setLevel( m_outputLevel.value() );
36
37
if
(!
sc
.isSuccess()) {
38
warning () <<
"Base class could not be initialized"
<<
endmsg
;
39
return
StatusCode::FAILURE;
40
}
41
42
if
(
m_file
==
""
) {
43
ATH_MSG_DEBUG
(
"db file not set"
);
44
return
StatusCode::SUCCESS;
45
}
46
47
if
(
readDbFile
(
m_file
).isFailure()) {
48
return
StatusCode::FAILURE;
49
}
50
51
std::ostringstream ost;
52
ost <<
" Printing CondDB registry"
;
53
for
(
const
auto
& e :
m_registry
) {
54
ost << std::endl <<
" - id: "
<< e.first <<
" r:"
;
55
for
(
const
IOVEntryT<IASCIICondDbSvc::dbData_t>
&
r
: e.second) {
56
ost <<
" "
<<
r
.range() <<
" :: "
<< *
r
.objPtr();
57
}
58
}
59
60
ATH_MSG_DEBUG
( ost.str() );
61
62
return
StatusCode::SUCCESS;
63
64
}
65
//---------------------------------------------------------------------------
66
67
StatusCode
68
ASCIICondDbSvc::readDbFile
(
const
std::string& fname) {
69
70
StatusCode
sc
(StatusCode::SUCCESS);
71
72
ATH_MSG_DEBUG
(
"reading cond db from \""
<< fname <<
"\""
);
73
74
std::ifstream ifs (fname);
75
std::string line;
76
if
(ifs.is_open()) {
77
78
IOVEntryT<IASCIICondDbSvc::dbData_t>
ie;
79
80
while
( getline (ifs, line) ) {
81
82
// ignore anything after a "#" and blank lines
83
size_t
fh = line.find(
"#"
);
84
if
(fh != std::string::npos)
85
line.erase(fh,line.length()-fh);
86
if
(line.length() == 0)
continue
;
87
88
std::vector<std::string> tokens;
89
for
(
auto
&& token : line | std::views::split(
' '
))
if
(!token.empty()) tokens.emplace_back(token.begin(), token.end());
90
auto
it = tokens.begin();
91
92
std::string dbKey = *it;
93
94
++it;
95
96
while
(it != tokens.end()) {
97
if
(
parse
(ie,*it)) {
98
m_registry
[dbKey].push_back( ie );
99
}
else
{
100
error
() <<
"while reading "
<< fname <<
" problem parsing "
<< *it
101
<<
" in line\n"
<< line <<
endmsg
;
102
sc
= StatusCode::FAILURE;
103
}
104
++it;
105
}
106
}
107
ifs.close();
108
}
else
{
109
error
() <<
"unable to open file "
<< (std::string)
m_file
<<
endmsg
;
110
sc
= StatusCode::FAILURE;
111
}
112
113
return
sc
;
114
115
}
116
//---------------------------------------------------------------------------
117
118
void
119
ASCIICondDbSvc::dump
()
const
{
120
121
std::ostringstream ost;
122
dump
(ost);
123
124
info() << ost.str() <<
endmsg
;
125
126
}
127
128
129
//---------------------------------------------------------------------------
130
131
void
132
ASCIICondDbSvc::dump
(std::ostringstream& ost)
const
{
133
134
std::lock_guard<std::mutex>
lock
(
m_lock
);
135
136
ost <<
"ASCIICondDbSvc::dump()"
;
137
138
ost <<
"\n"
;
139
140
}
141
142
//---------------------------------------------------------------------------
143
144
StatusCode
145
ASCIICondDbSvc::finalize
() {
146
147
ATH_MSG_DEBUG
(
"ASCIICondDbSvc::finalize()"
);
148
149
if
(msgLvl(MSG::DEBUG)) {
150
std::ostringstream ost;
151
dump
(ost);
152
153
ATH_MSG_DEBUG
( ost.str() );
154
}
155
156
for
(
auto
e :
m_registry
) {
157
for
(
auto
ie : e.second ) {
158
delete
ie.objPtr();
159
ie.setPtr(0);
160
}
161
}
162
163
164
return
StatusCode::SUCCESS;
165
166
}
167
168
//---------------------------------------------------------------------------
169
170
bool
171
ASCIICondDbSvc::parse
(EventIDRange& t,
const
std::string& s) {
172
173
std::smatch m;
174
std::regex_match(s,m,
rr
);
175
176
// for (auto res : m) {
177
// cout << " - " << res << endl;
178
// }
179
180
if
(m.size() != 5) {
return
false
; }
181
182
// set run# and timestamp
183
EventIDBase start(std::stoi(m[1]), EventIDBase::UNDEFEVT, std::stoi(m[2]));
184
EventIDBase end(std::stoi(m[3]), EventIDBase::UNDEFEVT, std::stoi(m[4]));
185
186
start.set_lumi_block(
m_lbn
);
187
end.set_lumi_block(
m_lbn
);
188
189
t = EventIDRange(start, end);
190
191
return
true
;
192
193
}
194
195
//---------------------------------------------------------------------------
196
197
bool
198
ASCIICondDbSvc::parse
(
IOVEntryT<IASCIICondDbSvc::dbData_t>
& ie,
const
std::string& s) {
199
200
std::smatch m;
201
std::regex_match(s,m,
ref
);
202
203
if
(m.size() != 6) {
return
false
; }
204
205
// set run#, lumi and timestamp
206
// EventIDBase start(std::stoi(m[1]), EventIDBase::UNDEFEVT, std::stoi(m[2]));
207
// EventIDBase end(std::stoi(m[3]), EventIDBase::UNDEFEVT, std::stoi(m[4]));
208
// start.set_lumi_block(m_lbn);
209
// end.set_lumi_block(m_lbn);
210
211
// set lumi and Timestamp
212
EventIDBase start(0, EventIDBase::UNDEFEVT,
213
std::stoi(m[2]));
214
EventIDBase end(EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT,
215
std::stoi(m[4]));
216
start.set_lumi_block(std::stoi(m[1]));
217
end.set_lumi_block(std::stoi(m[3]));
218
219
// Set Run/Lumi
220
// EventIDBase start(std::stoi(m[1]), EventIDBase::UNDEFEVT);
221
// EventIDBase end(std::stoi(m[3]), EventIDBase::UNDEFEVT);
222
// start.set_lumi_block(std::stoi(m[2]));
223
// end.set_lumi_block(std::stoi(m[4]));
224
225
ie.setRange(EventIDRange(start,end));
226
227
IASCIICondDbSvc::dbData_t
*v =
new
IASCIICondDbSvc::dbData_t
( std::stof(m[5]) );
228
ie.setPtr(v);
229
230
return
true
;
231
232
}
233
234
//---------------------------------------------------------------------------
235
236
StatusCode
237
ASCIICondDbSvc::getRange
(
const
std::string& dbKey ,
const
EventContext& ctx,
238
EventIDRange& rng,
IASCIICondDbSvc::dbData_t
& val)
const
{
239
240
std::lock_guard<std::mutex>
lock
(
m_lock
);
241
242
registry_t::const_iterator itr =
m_registry
.find(dbKey);
243
244
if
(itr ==
m_registry
.end()) {
245
error
() <<
"getRange: no dbKey "
<< dbKey <<
" found in registry"
246
<<
endmsg
;
247
return
StatusCode::FAILURE;
248
}
249
250
for
(
const
IOVEntryT<IASCIICondDbSvc::dbData_t>
& e : itr->second) {
251
debug
() <<
"compare "
<< e.range() <<
" with "
<< ctx.eventID()
252
<<
endmsg
;
253
if
(e.range().isInRange(EventIDBase(ctx.eventID()))) {
254
rng = e.range();
255
val = *(e.objPtr());
256
return
StatusCode::SUCCESS;
257
}
258
}
259
260
error
() <<
"getRange: no range for Time "
<< ctx.eventID()
261
<<
" found for dbKey "
<< dbKey <<
endmsg
;
262
263
return
StatusCode::FAILURE;
264
}
r_e
const std::string r_e
Definition
ASCIICondDbSvc.cxx:15
ref
const std::regex ref(r_ef)
re
const std::regex re(r_e)
r_t
const std::string r_t("\\[([0-9]+),([0-9]+)\\]")
r_ef
const std::string r_ef
Definition
ASCIICondDbSvc.cxx:16
r_r
const std::string r_r
Definition
ASCIICondDbSvc.cxx:14
rr
const std::regex rr(r_r)
ASCIICondDbSvc.h
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
CondCont.h
Hold mappings of ranges to condition objects.
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
sc
static Double_t sc
Definition
LArPhysWaveHECTool.cxx:37
debug
const bool debug
Definition
MakeUncertaintyPlots.cxx:53
ASCIICondDbSvc::getRange
virtual StatusCode getRange(const std::string &, const EventContext &, EventIDRange &, IASCIICondDbSvc::dbData_t &) const override
Definition
ASCIICondDbSvc.cxx:237
ASCIICondDbSvc::m_lbn
Gaudi::Property< unsigned int > m_lbn
Definition
ASCIICondDbSvc.h:49
ASCIICondDbSvc::finalize
virtual StatusCode finalize() override
Definition
ASCIICondDbSvc.cxx:145
ASCIICondDbSvc::m_file
Gaudi::Property< std::string > m_file
Definition
ASCIICondDbSvc.h:48
ASCIICondDbSvc::initialize
virtual StatusCode initialize() override
Definition
ASCIICondDbSvc.cxx:31
ASCIICondDbSvc::ASCIICondDbSvc
ASCIICondDbSvc(const std::string &name, ISvcLocator *svc)
Definition
ASCIICondDbSvc.cxx:24
ASCIICondDbSvc::m_registry
registry_t m_registry
Definition
ASCIICondDbSvc.h:52
ASCIICondDbSvc::m_lock
std::mutex m_lock
Definition
ASCIICondDbSvc.h:54
ASCIICondDbSvc::parse
bool parse(EventIDRange &t, const std::string &s)
Definition
ASCIICondDbSvc.cxx:171
ASCIICondDbSvc::readDbFile
StatusCode readDbFile(const std::string &)
Definition
ASCIICondDbSvc.cxx:68
ASCIICondDbSvc::dump
virtual void dump() const override
Definition
ASCIICondDbSvc.cxx:119
IASCIICondDbSvc::dbData_t
float dbData_t
Definition
IASCIICondDbSvc.h:19
IOVEntryT
Definition
IOVEntryT.h:26
r
int r
Definition
globals.cxx:22
error
Definition
IImpactPoint3dEstimator.h:72
msg
MsgStream & msg
Definition
testRead.cxx:32
Generated on
for ATLAS Offline Software by
1.17.0