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