ATLAS Offline Software
Loading...
Searching...
No Matches
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
29
31
32using namespace std;
33
34
36 : TObject()
37 , m_logger( "TGoodRunsListReader" )
38{
39 m_grlvec.SetCheckGRLInfo( checkGRLInfo );
40}
41
42
43Root::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
56
57
58void
60{
61 m_grlvec.Reset();
62 m_dataCardList.clear();
63 m_xmlstringList.clear();
64 m_xmlstring=""; //Clear() only works in root5.24
66}
67
68
69Bool_t
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) {
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) {
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
164void
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
179void
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
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()) {
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
256void
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();
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()) {
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
318{
319 return m_grlvec.GetMergedGoodRunsList(operation);
320}
321
322
325{
326 return m_grlvec.GetGoodRunsList(idx);
327}
328
329
332{
333 return m_grlvec.GetMergedGRLCollection(operation);
334}
335
ClassImp(Root::TGoodRunsListReader) using namespace std
#define GEndl
Definition TMsgLogger.h:147
Bool_t IsEmpty() const
Definition TGoodRun.cxx:249
void SetRunNumber(const Int_t &runnr)
Definition TGoodRun.h:43
Int_t GetRunNumber() const
Definition TGoodRun.h:42
std::vector< TString > m_dataCardList
std::vector< TString > m_xmlstringList
const TGoodRunsList GetGoodRunsList(unsigned int idx) const
TGoodRunsListReader(Bool_t checkGRLInfo=kFALSE)
const TGoodRunsList GetMergedGoodRunsList(const Root::BoolOperation &operation=OR) const
TGoodRun GetLumiBlockCollection(TXMLNode *dataNode)
const TGRLCollection GetMergedGRLCollection(const Root::BoolOperation &operation=OR) const
void SetBegin(const Int_t &begin)
void SetEnd(const Int_t &end)
Definition node.h:24
void trim(std::string &input)
Definition StrUtil.cxx:12
@ kERROR
Definition TMsgLogger.h:42
@ kWARNING
Definition TMsgLogger.h:41
@ kDEBUG
Definition TMsgLogger.h:39
STL namespace.