ATLAS Offline Software
Loading...
Searching...
No Matches
lumiParser Class Reference

#include <lumiParser.h>

Inheritance diagram for lumiParser:
Collaboration diagram for lumiParser:

Public Types

typedef std::map< int, grl_runfull_type
 full map type
typedef std::map< int, grl_run >::iterator iterator
 iterators over the full map
typedef std::map< int, grl_run >::const_iterator const_iterator

Public Member Functions

 lumiParser ()
 lumiParser (const std::string &file)
void read (const std::string &f)
virtual ~lumiParser ()
void setterse (bool b)
void addRange (int run, int start, int stop)
 add a lumi block range for a given run
bool inRange (int run, int lb)
 is this run, lumiblock in any of the ranges?
void sort ()
 sort the runs by the number of good lumi blocks

Public Attributes

keys
 STL member.
elements
 STL member.

Private Member Functions

void chomp (std::string &s, const std::string &regex)
 all these string manipulation routines should all be available from elsewhere
void chop (std::string &s, const std::string &regex)
void tail (std::string &s, const std::string &regex)
void clean (std::string &s, const std::string &regex)
std::string toupper (const std::string &s)
std::string tolower (const std::string &s)

Private Attributes

bool m_terse

Detailed Description

Definition at line 28 of file lumiParser.h.

Member Typedef Documentation

◆ const_iterator

typedef std::map<int,grl_run>::const_iterator lumiList::const_iterator
inherited

Definition at line 37 of file lumiList.h.

◆ full_type

typedef std::map< int, grl_run > lumiList::full_type
inherited

full map type

Definition at line 32 of file lumiList.h.

◆ iterator

typedef std::map<int,grl_run>::iterator lumiList::iterator
inherited

iterators over the full map

Definition at line 35 of file lumiList.h.

Constructor & Destructor Documentation

◆ lumiParser() [1/2]

lumiParser::lumiParser ( )
inline

Definition at line 32 of file lumiParser.h.

32{ }

◆ lumiParser() [2/2]

lumiParser::lumiParser ( const std::string & file)
inline

Definition at line 34 of file lumiParser.h.

34{ read( file ); }
void read(const std::string &f)
Definition lumiParser.h:36
TFile * file

◆ ~lumiParser()

virtual lumiParser::~lumiParser ( )
inlinevirtual

Definition at line 126 of file lumiParser.h.

126{ }

Member Function Documentation

◆ addRange()

void lumiList::addRange ( int run,
int start,
int stop )
inlineinherited

add a lumi block range for a given run

Definition at line 48 of file lumiList.h.

48 {
49
50 iterator it = find(run);
51
52 if ( it == end() ) {
53 std::pair< iterator, bool > in = insert( std::pair<int, grl_run >( run, grl_run( run ) ) );
54 it = in.first;
55 }
56
57 it->second.add_range( start, stop );
58
59 if ( !m_terse ) std::cout << "lumiList::addRange() run " << run << ";\t" << start << " - " << stop << std::endl;
60 }
std::map< int, grl_run >::iterator iterator
iterators over the full map
Definition lumiList.h:35
bool m_terse
Definition lumiList.h:120
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138

◆ chomp()

void lumiParser::chomp ( std::string & s,
const std::string & regex )
inlineprivate

all these string manipulation routines should all be available from elsewhere

Definition at line 133 of file lumiParser.h.

133 {
134 size_t pos = s.find( regex );
135 if ( pos!=std::string::npos ) s.erase( pos, s.size() );
136 }

◆ chop()

void lumiParser::chop ( std::string & s,
const std::string & regex )
inlineprivate

Definition at line 138 of file lumiParser.h.

138 {
139 size_t pos = s.find( regex );
140 if ( pos!=std::string::npos ) s.erase( 0, pos+regex.size() );
141 }

◆ clean()

void lumiParser::clean ( std::string & s,
const std::string & regex )
inlineprivate

Definition at line 151 of file lumiParser.h.

151 {
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 }

◆ inRange()

bool lumiList::inRange ( int run,
int lb )
inlineinherited

is this run, lumiblock in any of the ranges?

if the run is not in the list, it is assumed that all events from that run are required

Definition at line 67 of file lumiList.h.

67 {
68
69 iterator itr = find(run);
70
71 if ( itr == end() ) return true;
72 else {
73 grl_run& v = itr->second;
74 for ( unsigned i=0 ; i<v.size() ; i++ ) {
75 if ( lb>=v[i].first && lb<=v[i].second ) return true;
76 }
77 }
78 return false;
79 }
int lb
Definition globals.cxx:23

◆ read()

void lumiParser::read ( const std::string & f)
inline

read GRL from web if required

save file if it exists to download again in case it has changed

open the file

go through all the lines ...

got a run

parse the run number

really need to check for upper or lower case in addition

parse the lumiblock ranges

Definition at line 36 of file lumiParser.h.

36 {
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 }
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
void tail(std::string &s, const std::string &regex)
Definition lumiParser.h:143
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
bool exists(const std::string &filename)
does a file exist
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

◆ setterse()

void lumiList::setterse ( bool b)
inlineinherited

Definition at line 45 of file lumiList.h.

◆ sort()

void lumiList::sort ( )
inlineinherited

sort the runs by the number of good lumi blocks

sort the vector

print out

Definition at line 83 of file lumiList.h.

83 {
84
85 std::cout << "lumiList::sort() sorting ..." << std::endl;
86
87 std::vector< const grl_run* > vec;
88
89 const_iterator itr = begin();
90
91 while ( itr!=end() ) {
92 vec.push_back( &(itr->second) );
93 ++itr;
94 }
95
97 std::sort(vec.begin(), vec.end(), grl_run::comparison );
98
100
101 double total = 0;
102 for ( unsigned i=vec.size() ; i-- ; ) total += vec[i]->lbsize();
103
104
105 double integral = 0;
106 for ( unsigned i=0 ; i<vec.size() ; i++ ) {
107
108 integral += vec[i]->lbsize();
109
110 std::cout << i
111 << "\t" << int(100*(i+1.0)/vec.size())
112 << "\t" << int(integral/total*1000)*0.1
113 << "\t" << *vec[i] << "\tfraction: " << vec[i]->lbsize()/total << std::endl;
114
115 }
116 }
std::vector< size_t > vec
static bool comparison(const grl_run *r1, const grl_run *r2)
Definition grl_run.h:55
std::map< int, grl_run >::const_iterator const_iterator
Definition lumiList.h:37
double integral(TH1 *h)
Definition computils.cxx:59
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.

◆ tail()

void lumiParser::tail ( std::string & s,
const std::string & regex )
inlineprivate

Definition at line 143 of file lumiParser.h.

143 {
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 }

◆ tolower()

std::string lumiParser::tolower ( const std::string & s)
inlineprivate

Definition at line 166 of file lumiParser.h.

166 {
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 }

◆ toupper()

std::string lumiParser::toupper ( const std::string & s)
inlineprivate

Definition at line 159 of file lumiParser.h.

159 {
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 }

Member Data Documentation

◆ elements

T std::map< K, T >::elements
inherited

STL member.

◆ keys

K std::map< K, T >::keys
inherited

STL member.

◆ m_terse

bool lumiList::m_terse
privateinherited

Definition at line 120 of file lumiList.h.


The documentation for this class was generated from the following file: