ATLAS Offline Software
TGoodRunsListReader.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 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 
27 #include "GoodRunsLists/TGoodRun.h"
29 #include "GoodRunsLists/StrUtil.h"
30 
32 
33 using namespace std;
34 
35 
37  : TObject()
38  , m_logger( "TGoodRunsListReader" )
39 {
40  m_grlvec.SetCheckGRLInfo( checkGRLInfo );
41 }
42 
43 
44 Root::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 
54 {
55  this->Reset();
56 }
57 
58 
59 void
61 {
62  m_grlvec.Reset();
63  m_dataCardList.clear();
64  m_xmlstringList.clear();
65  m_xmlstring=""; //Clear() only works in root5.24
66  m_dataCardName="";
67 }
68 
69 
70 Bool_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) {
87  m_dataCardName = m_dataCardList[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) {
124  m_xmlstring = m_xmlstringList[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 
165 void
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 
180 void
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 
257 void
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();
268  Root::TGoodRunsList grl(m_dataCardName.Data());
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()) {
308  Root::TGoodRun goodrun = this->GetLumiBlockCollection(node);
309  if (!goodrun.IsEmpty()) grl[goodrun.GetRunNumber()] = goodrun ;
310  }
311  }
312 
313  if (!grl.IsEmpty()) m_grlvec.push_back(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 
Root::TGoodRunsListReader
Definition: TGoodRunsListReader.h:34
TGoodRunsList.h
TLumiBlockRange.h
Root::kWARNING
@ kWARNING
Definition: TMsgLogger.h:51
Root::TGoodRun
Definition: TGoodRun.h:27
Root::TGRLCollection::SetCheckGRLInfo
void SetCheckGRLInfo(Bool_t check=kTRUE)
Definition: TGRLCollection.h:41
Root::TGoodRun::Sort
void Sort()
Definition: TGoodRun.cxx:193
Root::TGoodRunsListReader::TGoodRunsListReader
TGoodRunsListReader(Bool_t checkGRLInfo=kFALSE)
Definition: TGoodRunsListReader.cxx:36
Root::TGoodRun::SetRunNumber
void SetRunNumber(const Int_t &runnr)
Definition: TGoodRun.h:53
Root::kERROR
@ kERROR
Definition: TMsgLogger.h:52
collisions.grl
grl
Definition: collisions.py:25
Root::TGoodRunsListReader::m_grlvec
TGRLCollection m_grlvec
Definition: TGoodRunsListReader.h:74
GEndl
#define GEndl
Definition: TMsgLogger.h:151
Root::TLumiBlockRange::IsEmpty
Bool_t IsEmpty() const
Definition: TLumiBlockRange.h:50
Root::kDEBUG
@ kDEBUG
Definition: TMsgLogger.h:49
Root::TGoodRunsListReader::~TGoodRunsListReader
~TGoodRunsListReader()
Definition: TGoodRunsListReader.cxx:53
grl
Definition: ZLumiScripts/grid/grl.py:1
Root::TGoodRunsListReader::ReadNamedLumiRange
void ReadNamedLumiRange(TXMLNode *)
Definition: TGoodRunsListReader.cxx:258
Root::TGoodRun::IsEmpty
Bool_t IsEmpty() const
Definition: TGoodRun.cxx:251
Root::TLumiBlockRange::SetEnd
void SetEnd(const Int_t &end)
Definition: TLumiBlockRange.h:53
TGoodRun.h
Root::TGRLCollection::GetMergedGRLCollection
const Root::TGRLCollection GetMergedGRLCollection(const Root::BoolOperation &operation=OR) const
Definition: TGRLCollection.cxx:182
Root::TGRLCollection
Definition: TGRLCollection.h:29
Root::TGoodRunsListReader::ReadAttribs
void ReadAttribs(TXMLNode *)
Definition: TGoodRunsListReader.cxx:166
Root::TGoodRunsListReader::GetLumiBlockCollection
TGoodRun GetLumiBlockCollection(TXMLNode *dataNode)
Definition: TGoodRunsListReader.cxx:212
StrUtil.h
Root::TGoodRunsList
Definition: TGoodRunsList.h:31
TGoodRunsListReader.h
Root::TLumiBlockRange::SetBegin
void SetBegin(const Int_t &begin)
Definition: TLumiBlockRange.h:52
Root::TGoodRunsListReader::ReadLumiBlockCollection
void ReadLumiBlockCollection(TXMLNode *)
Definition: TGoodRunsListReader.cxx:181
Root::TGoodRunsListReader::Interpret
Bool_t Interpret()
Definition: TGoodRunsListReader.cxx:71
Root::TGoodRunsListReader::m_dataCardList
std::vector< TString > m_dataCardList
Definition: TGoodRunsListReader.h:71
Root::TLumiBlockRange
Definition: TLumiBlockRange.h:26
Root::TGoodRunsListReader::GetMergedGRLCollection
const TGRLCollection GetMergedGRLCollection(const Root::BoolOperation &operation=OR) const
Definition: TGoodRunsListReader.cxx:332
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
GRLStrUtil::trim
void trim(std::string &input)
Definition: StrUtil.cxx:12
Root::TGoodRun::GetRunNumber
Int_t GetRunNumber() const
Definition: TGoodRun.h:52
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
Root::TGoodRunsListReader::Reset
void Reset()
Definition: TGoodRunsListReader.cxx:60
Root::BoolOperation
BoolOperation
Definition: TGRLCollection.h:27
Root::TGoodRunsListReader::GetMergedGoodRunsList
const TGoodRunsList GetMergedGoodRunsList(const Root::BoolOperation &operation=OR) const
Definition: TGoodRunsListReader.cxx:318
node
Definition: memory_hooks-stdcmalloc.h:74
ClassImp
ClassImp(Root::TGoodRunsListReader) using namespace std
Root::TGoodRunsListReader::GetGoodRunsList
const TGoodRunsList GetGoodRunsList(unsigned int idx) const
Definition: TGoodRunsListReader.cxx:325