ATLAS Offline Software
Loading...
Searching...
No Matches
lumiParser.h
Go to the documentation of this file.
1/* emacs: this is -*- c++ -*- */
10
11
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
28class lumiParser : public lumiList {
29
30public:
31
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
128private:
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
177inline 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
lumiList(bool b=true)
Definition lumiList.h:41
void addRange(int run, int start, int stop)
add a lumi block range for a given run
Definition lumiList.h:48
void chomp(std::string &s, const std::string &regex)
all these string manipulation routines should all be available from elsewhere
Definition lumiParser.h:133
virtual ~lumiParser()
Definition lumiParser.h:126
void tail(std::string &s, const std::string &regex)
Definition lumiParser.h:143
lumiParser(const std::string &file)
Definition lumiParser.h:34
std::string toupper(const std::string &s)
Definition lumiParser.h:159
std::string tolower(const std::string &s)
Definition lumiParser.h:166
void chop(std::string &s, const std::string &regex)
Definition lumiParser.h:138
void clean(std::string &s, const std::string &regex)
Definition lumiParser.h:151
void read(const std::string &f)
Definition lumiParser.h:36
bool exists(const std::string &filename)
does a file exist
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
static std::vector< uint32_t > lbstart
Definition iLumiCalc.h:38
static std::vector< uint32_t > lbend
Definition iLumiCalc.h:39
std::string label(const std::string &format, int i)
Definition label.h:19
standalone implementation of a good lumi block list
std::ostream & operator<<(std::ostream &s, const lumiParser &lp)
Definition lumiParser.h:177
Definition run.py:1
TFile * file