ATLAS Offline Software
lumiParser.h
Go to the documentation of this file.
1 /* emacs: this is -*- c++ -*- */
12 #ifndef LUMIPARSER_H
13 #define LUMIPARSER_H
14 
15 #include <iostream>
16 #include <fstream>
17 #include <sstream>
18 #include <string>
19 #include <vector>
20 #include <set>
21 #include <cstdlib>
22 #include <cmath>
23 
24 #include "lumiList.h"
25 #include "computils.h"
26 
27 
28 class lumiParser : public lumiList {
29 
30 public:
31 
32  lumiParser() { }
33 
34  lumiParser( const std::string& file ) { read( file ); }
35 
36  void read( const std::string& f ) {
37 
39  std::string file = f;
40  size_t pos = file.find("http");
41  if ( pos!=std::string::npos ) {
42  std::string cmd = "wget ";
43  cmd += file;
44  tail( file, "/" );
45  if ( exists( file ) ) {
48  std::string mvcmd = "mv ";
49  mvcmd += file + " " + file + ".bak";
50  std::system( mvcmd.c_str() );
51  }
52  std::system( cmd.c_str() );
53  }
54 
55  std::cout << "lumiParser file: " << file << std::endl;
56 
58  std::ifstream input( file.c_str() );
59 
60  int run;
61  std::vector<int> lbstart;
62  std::vector<int> lbend;
63 
65  for( std::string line; getline( input, line ); ) {
66 
67  // std::string s;
68  // std::cout << line << std::endl;
69 
70  std::string inputline = tolower(line);
71 
73  if ( inputline.find("run:")!=std::string::npos ||
74  inputline.find("<run>")!=std::string::npos ) {
75 
77 
80  std::string label = line;
81  chop( label, "Run:" );
82  chop( label, "<Run>" );
83  chomp( label, "</Run>" );
84  clean( label, " " );
85 
86  run = std::atoi(label.c_str());
87  lbstart.clear();
88  lbend.clear();
89 
90  // std::cout << "\n\n" << line << "\trun: " << label << std::endl;
91 
93  for( std::string fline ; getline( input, fline ) ; ) {
94  if ( tolower(fline).find("from:")!=std::string::npos ) {
95  chop( fline, "From:" );
96  clean( fline, " ");
97  std::string start = fline;
98  chomp( start, "to");
99  chop( fline, "to" );
100  lbstart.push_back( std::atoi(start.c_str()) );
101  lbend.push_back( std::atoi(fline.c_str()) );
102  }
103  else if ( tolower(fline).find("lbrange")!=std::string::npos ) {
104  clean( fline, "\"" );
105  clean( fline, " " );
106  chop( fline, "LBRange");
107  chomp( fline, "/>" );
108  chop( fline, "Start=" );
109  std::string start = fline;
110  chomp( start, "End");
111  chop( fline, "End=");
112  lbstart.push_back( std::atoi(start.c_str()) );
113  lbend.push_back( std::atoi(fline.c_str()) );
114  }
115  else break;
116  }
117 
118  for ( unsigned il=0 ; il<lbstart.size() ; il++ ) this->addRange( run, lbstart[il], lbend[il] );
119 
120  }
121  }
122 
123  std::cout << "lumiParser: read " << size() << " runs" << std::endl;
124  }
125 
126  virtual ~lumiParser() { }
127 
128 private:
129 
132 
133  void chomp( std::string& s, const std::string& regex ) {
134  size_t pos = s.find( regex );
135  if ( pos!=std::string::npos ) s.erase( pos, s.size() );
136  }
137 
138  void chop( std::string& s, const std::string& regex ) {
139  size_t pos = s.find( regex );
140  if ( pos!=std::string::npos ) s.erase( 0, pos+regex.size() );
141  }
142 
143  void tail( std::string& s, const std::string& regex ) {
144  size_t pos = s.find( regex );
145  while( pos!=std::string::npos ) {
146  s.erase( 0, pos+regex.size() );
147  pos = s.find( regex );
148  }
149  }
150 
151  void clean( std::string& s, const std::string& regex ) {
152  size_t pos = s.find( regex );
153  while( pos!=std::string::npos ) {
154  s.erase( pos, regex.size() );
155  pos = s.find( regex );
156  }
157  }
158 
159  std::string toupper( const std::string& s ) {
160  std::string t = s;
161  for ( unsigned i=0 ; i<t.size() ; i++ ) if ( t[i]>='a' && t[i]<='z' ) t[i] += 'A'-'a';
162  return t;
163  }
164 
165 
166  std::string tolower( const std::string& s ) {
167  std::string t = s;
168  for ( unsigned i=0 ; i<t.size() ; i++ ) if ( t[i]>='A' && t[i]<='Z' ) t[i] -= 'A'-'a';
169  return t;
170  }
171 
172 
173 };
174 
175 
176 
177 inline std::ostream& operator<<( std::ostream& s, const lumiParser& lp ) {
178  // return s << *dynamic_cast<const lumiList*>(&_l);
179  return s << (const lumiList&)lp;
180 }
181 
182 
183 #endif // LUMIPARSER_H
184 
185 
186 
187 
188 
189 
190 
191 
192 
193 
PlotCalibFromCool.il
il
Definition: PlotCalibFromCool.py:381
lumiParser::chomp
void chomp(std::string &s, const std::string &regex)
all these string manipulation routines should all be available from elsewhere
Definition: lumiParser.h:133
checkFileSG.line
line
Definition: checkFileSG.py:75
lumiParser::clean
void clean(std::string &s, const std::string &regex)
Definition: lumiParser.h:151
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
lumiParser::read
void read(const std::string &f)
Definition: lumiParser.h:36
operator<<
std::ostream & operator<<(std::ostream &s, const lumiParser &lp)
Definition: lumiParser.h:177
lumiParser::toupper
std::string toupper(const std::string &s)
Definition: lumiParser.h:159
rerun_display.cmd
string cmd
Definition: rerun_display.py:67
lumiParser
Definition: lumiParser.h:28
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
lumiParser::lumiParser
lumiParser()
Definition: lumiParser.h:32
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
lumiList::addRange
void addRange(int run, int start, int stop)
add a lumi block range for a given run
Definition: lumiList.h:48
lumiParser::chop
void chop(std::string &s, const std::string &regex)
Definition: lumiParser.h:138
lumiParser::tail
void tail(std::string &s, const std::string &regex)
Definition: lumiParser.h:143
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
lumiFormat.i
int i
Definition: lumiFormat.py:85
lumiParser::tolower
std::string tolower(const std::string &s)
Definition: lumiParser.h:166
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
add-xsec-uncert-quadrature-N.label
label
Definition: add-xsec-uncert-quadrature-N.py:104
file
TFile * file
Definition: tile_monitor.h:29
hist_file_dump.f
f
Definition: hist_file_dump.py:135
run
Definition: run.py:1
lumiParser::~lumiParser
virtual ~lumiParser()
Definition: lumiParser.h:126
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
lumiParser::lumiParser
lumiParser(const std::string &file)
Definition: lumiParser.h:34
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
python.dummyaccess.exists
def exists(filename)
Definition: dummyaccess.py:9
computils.h
lumiList.h
standalone implementation of a good lumi block list
lumiList
Definition: lumiList.h:27