ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
DataQuality
GoodRunsLists
Root
TGoodRunsListReader.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
/**********************************************************************************
7
* Class : TGoodRunsReader *
8
* *
9
* Authors (alphabetical): *
10
* Max Baak <mbaak@cern.ch> - CERN, Switzerland *
11
**********************************************************************************/
12
13
#include <iostream>
14
#include <stdlib.h>
15
#include <string>
16
17
#include "TFormula.h"
18
#include "TObjString.h"
19
#include "TDOMParser.h"
20
#include "TXMLNode.h"
21
#include "TXMLDocument.h"
22
#include "TXMLAttr.h"
23
24
#include "
GoodRunsLists/TGoodRunsListReader.h
"
25
#include "
GoodRunsLists/TGoodRunsList.h
"
26
#include "
GoodRunsLists/TGoodRun.h
"
27
#include "
GoodRunsLists/TLumiBlockRange.h
"
28
#include "
GoodRunsLists/StrUtil.h
"
29
30
ClassImp
(
Root::TGoodRunsListReader
)
31
32
using namespace
std
;
33
34
35
Root::TGoodRunsListReader::TGoodRunsListReader
( Bool_t checkGRLInfo )
36
: TObject()
37
,
m_logger
(
"TGoodRunsListReader"
)
38
{
39
m_grlvec
.SetCheckGRLInfo( checkGRLInfo );
40
}
41
42
43
Root::TGoodRunsListReader::TGoodRunsListReader
(
const
TString& dataCardName, Bool_t checkGRLInfo )
44
: TObject()
45
,
m_logger
(
"TGoodRunsListReader"
)
46
{
47
m_dataCardList
.push_back(dataCardName);
48
m_grlvec
.SetCheckGRLInfo( checkGRLInfo );
49
}
50
51
52
Root::TGoodRunsListReader::~TGoodRunsListReader
()
53
{
54
this->
Reset
();
55
}
56
57
58
void
59
Root::TGoodRunsListReader::Reset
()
60
{
61
m_grlvec
.Reset();
62
m_dataCardList
.clear();
63
m_xmlstringList
.clear();
64
m_xmlstring
=
""
;
//Clear() only works in root5.24
65
m_dataCardName
=
""
;
66
}
67
68
69
Bool_t
70
Root::TGoodRunsListReader::Interpret
()
71
{
72
Bool_t xmlInterpret(kTRUE);
73
74
if
(
m_dataCardList
.empty() &&
m_xmlstringList
.empty()) {
75
m_logger
<<
kWARNING
<<
"No xml data-card or string set. Return false."
<<
GEndl
;
76
return
kFALSE;
77
}
78
79
Int_t parseCode(1);
80
TDOMParser* xmlparser =
new
TDOMParser();
81
83
84
// --------------- xml file read
85
for
(
unsigned
int
j=0; j<
m_dataCardList
.size() && xmlInterpret; ++j) {
86
m_dataCardName
=
m_dataCardList
[j];
87
88
if
(!
m_dataCardName
.IsNull()) {
89
m_logger
<<
kDEBUG
<<
"Read xml data-card: \""
<<
m_dataCardName
<<
"\""
<<
GEndl
;
90
xmlparser->SetValidate(kFALSE);
// MB 14/4/'10 : don't validate structure of dtd file in case runquery down
91
parseCode = xmlparser->ParseFile(
m_dataCardName
);
92
}
else
{
93
m_logger
<<
kWARNING
<<
"No xml data-card set. Skip."
<<
GEndl
;
94
continue
;
95
}
96
97
m_logger
<<
kDEBUG
<<
"XML parser returned code: "
<< parseCode <<
GEndl
;
98
if
(parseCode != 0) {
99
m_logger
<<
kERROR
<<
"loading of xml document failed"
<<
GEndl
;
100
xmlInterpret = kFALSE;
101
}
else
{
102
// --------------- parse JobConfiguration
103
TXMLDocument* xmldoc = xmlparser->GetXMLDocument();
104
105
TXMLNode* jobConfig_node = xmldoc->GetRootNode();
106
TXMLNode* jobConfig_elem = jobConfig_node->GetChildren();
107
108
while
(jobConfig_elem != 0) {
109
if
(jobConfig_elem->GetNodeName() == TString(
"NamedLumiRange"
)) {
110
this->
ReadNamedLumiRange
( jobConfig_elem );
111
}
112
// crawl on...
113
jobConfig_elem = jobConfig_elem->GetNextNode();
114
}
115
}
116
}
117
m_dataCardList
.clear();
// Can now add fresh xml files
118
120
121
// --------------- xml string read
122
for
(
unsigned
int
j=0; j<
m_xmlstringList
.size() && xmlInterpret; ++j) {
123
m_xmlstring
=
m_xmlstringList
[j];
124
125
if
(!
m_xmlstring
.IsNull()) {
126
m_logger
<<
kDEBUG
<<
"Read xml string."
<<
GEndl
;
127
xmlparser->SetValidate(kFALSE);
// MB 14/4/'10 : don't validate structure of dtd file in case runquery down
128
parseCode = xmlparser->ParseBuffer(
m_xmlstring
.Data(),
m_xmlstring
.Length() );
129
}
else
{
130
m_logger
<<
kWARNING
<<
"No xml string set. Skip."
<<
GEndl
;
131
continue
;
132
}
133
134
m_logger
<<
kDEBUG
<<
"XML parser returned code: "
<< parseCode <<
GEndl
;
135
if
(parseCode != 0) {
136
m_logger
<<
kERROR
<<
"loading of xml document failed"
<<
GEndl
;
137
xmlInterpret = kFALSE;
138
}
else
{
139
// --------------- parse JobConfiguration
140
TXMLDocument* xmldoc = xmlparser->GetXMLDocument();
141
142
TXMLNode* jobConfig_node = xmldoc->GetRootNode();
143
TXMLNode* jobConfig_elem = jobConfig_node->GetChildren();
144
145
while
(jobConfig_elem != 0) {
146
if
(jobConfig_elem->GetNodeName() == TString(
"NamedLumiRange"
)) {
147
this->
ReadNamedLumiRange
( jobConfig_elem );
148
}
149
// crawl on...
150
jobConfig_elem = jobConfig_elem->GetNextNode();
151
}
152
}
153
}
154
m_xmlstringList
.clear();
// Can now add fresh xml strings
155
157
158
delete
xmlparser;
159
160
return
xmlInterpret;
161
}
162
163
164
void
165
Root::TGoodRunsListReader::ReadAttribs
( TXMLNode*
node
)
166
{
167
if
(!
node
->HasAttributes())
return
;
168
169
TListIter attribIt(
node
->GetAttributes() );
170
TXMLAttr* curAttr( 0 );
171
while
((curAttr = (TXMLAttr*)attribIt()) != 0) {
172
m_logger
<<
kDEBUG
<<
node
->GetNodeName() <<
": "
<< curAttr->GetName()
173
<<
" = \""
<< curAttr->GetValue() <<
"\""
<<
GEndl
;
174
// add variable
175
}
176
}
177
178
179
void
180
Root::TGoodRunsListReader::ReadLumiBlockCollection
( TXMLNode* dataNode )
181
{
182
// retrieve childrens of node
183
TXMLNode*
node
= dataNode->GetChildren();
184
185
for
(;
node
!= 0;
node
=
node
->GetNextNode()) {
186
187
// read run
188
if
(TString(
"Run"
)==
node
->GetNodeName()) {
189
m_logger
<<
kDEBUG
<<
"subchild node value: "
<<
node
->GetText() <<
GEndl
;
190
}
191
192
// read lumi block
193
if
(TString(
"LBRange"
)==
node
->GetNodeName() &&
node
->HasAttributes()) {
194
TXMLAttr* curAttr( 0 );
195
TListIter attribIt(
node
->GetAttributes());
196
while
((curAttr = (TXMLAttr*)attribIt()) != 0) {
197
if
(TString(
"Start"
)==curAttr->GetName()) {
198
m_logger
<<
kDEBUG
<<
node
->GetNodeName() <<
": "
<< curAttr->GetName()
199
<<
" = \""
<< curAttr->GetValue() <<
"\""
<<
GEndl
;
200
}
else
if
(TString(
"End"
)==curAttr->GetName()) {
201
m_logger
<<
kDEBUG
<<
node
->GetNodeName() <<
": "
<< curAttr->GetName()
202
<<
" = \""
<< curAttr->GetValue() <<
"\""
<<
GEndl
;
203
}
204
}
205
}
206
}
207
}
208
209
210
Root::TGoodRun
211
Root::TGoodRunsListReader::GetLumiBlockCollection
( TXMLNode* dataNode )
212
{
213
Root::TGoodRun
goodrun;
214
215
// sanity check
216
if
(!dataNode->HasChildren()) {
217
m_logger
<<
kWARNING
<<
"<Data> ... </Data> Part does not contain any parameters"
<<
GEndl
;
218
return
goodrun;
219
}
220
221
// retrieve childrens of node
222
TXMLNode*
node
= dataNode->GetChildren();
223
224
for
(;
node
!= 0;
node
=
node
->GetNextNode()) {
225
// read run
226
if
(TString(
"Run"
)==
node
->GetNodeName()) {
227
m_logger
<<
kDEBUG
<<
"subchild node value: "
<<
node
->GetText() <<
GEndl
;
228
goodrun.
SetRunNumber
(atoi(
node
->GetText()));
229
}
230
// read lumi block
231
if
(TString(
"LBRange"
)==
node
->GetNodeName() &&
node
->HasAttributes()) {
232
Root::TLumiBlockRange
lbr;
233
lbr.
SetEnd
(2147483647);
// set in case lb turns out to be open-ended
234
TXMLAttr* curAttr( 0 );
235
TListIter attribIt(
node
->GetAttributes());
236
while
((curAttr = (TXMLAttr*)attribIt()) != 0) {
237
if
(TString(
"Start"
)==curAttr->GetName()) {
238
m_logger
<<
kDEBUG
<<
node
->GetNodeName() <<
": "
<< curAttr->GetName()
239
<<
" = \""
<< curAttr->GetValue() <<
"\""
<<
GEndl
;
240
lbr.
SetBegin
(atoi(curAttr->GetValue()));
241
}
else
if
(TString(
"End"
)==curAttr->GetName()) {
242
m_logger
<<
kDEBUG
<<
node
->GetNodeName() <<
": "
<< curAttr->GetName()
243
<<
" = \""
<< curAttr->GetValue() <<
"\""
<<
GEndl
;
244
lbr.
SetEnd
(atoi(curAttr->GetValue()));
245
}
246
}
247
if
(!lbr.
IsEmpty
()) goodrun.push_back(lbr);
248
}
249
}
250
251
goodrun.
Sort
();
252
return
goodrun;
253
}
254
255
256
void
257
Root::TGoodRunsListReader::ReadNamedLumiRange
( TXMLNode* dataNode )
258
{
259
// sanity check
260
if
(!dataNode->HasChildren()) {
261
m_logger
<<
kWARNING
<<
"<Data> ... </Data> Part does not contain any parameters"
<<
GEndl
;
262
return
;
263
}
264
265
// retrieve childrens of node
266
TXMLNode*
node
= dataNode->GetChildren();
267
Root::TGoodRunsList
grl(
m_dataCardName
.Data());
268
std::string nameStr, valueStr;
269
270
for
(;
node
!= 0;
node
=
node
->GetNextNode()) {
272
if
(TString(
"Name"
) ==
node
->GetNodeName()) {
273
if
(
node
->GetText()!=0) {
274
m_logger
<<
kDEBUG
<<
"child node value: "
<<
node
->GetText() <<
GEndl
;
275
nameStr=
node
->GetText();
276
}
else
{ nameStr=
""
; }
277
GRLStrUtil::trim
(nameStr);
278
grl.SetName(nameStr.c_str());
279
}
281
else
if
(TString(
"Version"
) ==
node
->GetNodeName()) {
282
if
(
node
->GetText()!=0) {
283
m_logger
<<
kDEBUG
<<
"child node value: "
<<
node
->GetText() <<
GEndl
;
284
valueStr=
node
->GetText();
285
}
else
{ valueStr=
""
; }
286
GRLStrUtil::trim
(valueStr);
287
grl.SetVersion(valueStr);
288
}
290
else
if
(TString(
"Metadata"
) ==
node
->GetNodeName()) {
291
if
(
node
->GetText()!=0)
m_logger
<<
kDEBUG
<<
node
->GetNodeName() <<
" value: "
<<
node
->GetText() <<
GEndl
;
292
this->
ReadAttribs
(
node
);
293
294
if
(
node
->HasAttributes()) {
295
TListIter attribIt(
node
->GetAttributes() );
296
TXMLAttr* curAttr( 0 );
297
while
((curAttr = (TXMLAttr*)attribIt()) != 0) {
298
if
(curAttr->GetValue()!=0) { nameStr=curAttr->GetValue(); }
else
{ nameStr=
""
; }
299
if
(
node
->GetText()!=0) { valueStr=
node
->GetText(); }
else
{ valueStr=
""
; }
300
GRLStrUtil::trim
(nameStr);
GRLStrUtil::trim
(valueStr);
301
if
(!nameStr.empty() && !valueStr.empty()) grl.AddMetaData(nameStr,valueStr);
302
}
303
}
304
}
306
else
if
(TString(
"LumiBlockCollection"
) ==
node
->GetNodeName()) {
307
Root::TGoodRun
goodrun = this->
GetLumiBlockCollection
(
node
);
308
if
(!goodrun.
IsEmpty
()) grl[goodrun.
GetRunNumber
()] = goodrun ;
309
}
310
}
311
312
if
(!grl.IsEmpty())
m_grlvec
.push_back(std::move(grl));
313
}
314
315
316
const
Root::TGoodRunsList
317
Root::TGoodRunsListReader::GetMergedGoodRunsList
(
const
Root::BoolOperation
& operation )
const
318
{
319
return
m_grlvec
.GetMergedGoodRunsList(operation);
320
}
321
322
323
const
Root::TGoodRunsList
324
Root::TGoodRunsListReader::GetGoodRunsList
(
unsigned
int
idx )
const
325
{
326
return
m_grlvec
.GetGoodRunsList(idx);
327
}
328
329
330
const
Root::TGRLCollection
331
Root::TGoodRunsListReader::GetMergedGRLCollection
(
const
Root::BoolOperation
& operation )
const
332
{
333
return
m_grlvec
.GetMergedGRLCollection(operation);
334
}
335
StrUtil.h
TGoodRun.h
ClassImp
ClassImp(Root::TGoodRunsListReader) using namespace std
TGoodRunsListReader.h
TGoodRunsList.h
TLumiBlockRange.h
GEndl
#define GEndl
Definition
TMsgLogger.h:147
Root::TGRLCollection
Definition
TGRLCollection.h:24
Root::TGoodRun
Definition
TGoodRun.h:22
Root::TGoodRun::IsEmpty
Bool_t IsEmpty() const
Definition
TGoodRun.cxx:249
Root::TGoodRun::Sort
void Sort()
Definition
TGoodRun.cxx:193
Root::TGoodRun::SetRunNumber
void SetRunNumber(const Int_t &runnr)
Definition
TGoodRun.h:43
Root::TGoodRun::GetRunNumber
Int_t GetRunNumber() const
Definition
TGoodRun.h:42
Root::TGoodRunsListReader
Definition
TGoodRunsListReader.h:34
Root::TGoodRunsListReader::m_dataCardList
std::vector< TString > m_dataCardList
Definition
TGoodRunsListReader.h:71
Root::TGoodRunsListReader::~TGoodRunsListReader
~TGoodRunsListReader()
Definition
TGoodRunsListReader.cxx:52
Root::TGoodRunsListReader::m_xmlstring
TString m_xmlstring
Definition
TGoodRunsListReader.h:69
Root::TGoodRunsListReader::Reset
void Reset()
Definition
TGoodRunsListReader.cxx:59
Root::TGoodRunsListReader::ReadAttribs
void ReadAttribs(TXMLNode *)
Definition
TGoodRunsListReader.cxx:165
Root::TGoodRunsListReader::m_xmlstringList
std::vector< TString > m_xmlstringList
Definition
TGoodRunsListReader.h:72
Root::TGoodRunsListReader::GetGoodRunsList
const TGoodRunsList GetGoodRunsList(unsigned int idx) const
Definition
TGoodRunsListReader.cxx:324
Root::TGoodRunsListReader::m_logger
TMsgLogger m_logger
Definition
TGoodRunsListReader.h:73
Root::TGoodRunsListReader::TGoodRunsListReader
TGoodRunsListReader(Bool_t checkGRLInfo=kFALSE)
Definition
TGoodRunsListReader.cxx:35
Root::TGoodRunsListReader::ReadNamedLumiRange
void ReadNamedLumiRange(TXMLNode *)
Definition
TGoodRunsListReader.cxx:257
Root::TGoodRunsListReader::GetMergedGoodRunsList
const TGoodRunsList GetMergedGoodRunsList(const Root::BoolOperation &operation=OR) const
Definition
TGoodRunsListReader.cxx:317
Root::TGoodRunsListReader::m_grlvec
TGRLCollection m_grlvec
Definition
TGoodRunsListReader.h:74
Root::TGoodRunsListReader::GetLumiBlockCollection
TGoodRun GetLumiBlockCollection(TXMLNode *dataNode)
Definition
TGoodRunsListReader.cxx:211
Root::TGoodRunsListReader::Interpret
Bool_t Interpret()
Definition
TGoodRunsListReader.cxx:70
Root::TGoodRunsListReader::GetMergedGRLCollection
const TGRLCollection GetMergedGRLCollection(const Root::BoolOperation &operation=OR) const
Definition
TGoodRunsListReader.cxx:331
Root::TGoodRunsListReader::m_dataCardName
TString m_dataCardName
Definition
TGoodRunsListReader.h:70
Root::TGoodRunsListReader::ReadLumiBlockCollection
void ReadLumiBlockCollection(TXMLNode *)
Definition
TGoodRunsListReader.cxx:180
Root::TGoodRunsList
Definition
TGoodRunsList.h:26
Root::TLumiBlockRange
Definition
TLumiBlockRange.h:21
Root::TLumiBlockRange::SetBegin
void SetBegin(const Int_t &begin)
Definition
TLumiBlockRange.h:42
Root::TLumiBlockRange::IsEmpty
Bool_t IsEmpty() const
Definition
TLumiBlockRange.h:40
Root::TLumiBlockRange::SetEnd
void SetEnd(const Int_t &end)
Definition
TLumiBlockRange.h:43
node
Definition
node.h:24
GRLStrUtil::trim
void trim(std::string &input)
Definition
StrUtil.cxx:12
Root::kERROR
@ kERROR
Definition
TMsgLogger.h:42
Root::kWARNING
@ kWARNING
Definition
TMsgLogger.h:41
Root::kDEBUG
@ kDEBUG
Definition
TMsgLogger.h:39
Root::BoolOperation
BoolOperation
Definition
TGRLCollection.h:22
std
STL namespace.
Generated on
for ATLAS Offline Software by
1.17.0