ATLAS Offline Software
Loading...
Searching...
No Matches
iLumiCalc.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
13
14#include "cmdline.h"
15
16#include <TROOT.h>
17#include <TStopwatch.h>
18#include <TString.h>
19#include <TFile.h>
20#include <TTree.h>
21
22#include <iomanip>
23#include <stdio.h>
24#include <sys/stat.h>
25#include <sys/types.h>
26
27static std::vector<std::string> tagfile;
28static std::vector<std::string> aodfile;
29static std::vector<std::string> xmlfile;
30static std::vector<std::string> rootfile;
31static std::string treename = "tree";
32static std::string d3pddirname = "Lumi";
33static std::string xmloutfile = "out.xml";
34static std::vector<std::string> triggerchain;
35static std::string livetrigger;
36static Root::TMsgLogger logger( "iLumiCalc" );
37static std::vector<uint32_t> runnumber;
38static std::vector<uint32_t> lbstart;
39static std::vector<uint32_t> lbend;
40static uint32_t minlbstart = cool::ValidityKeyMin & 0xFFFFFFFF;
41static uint32_t maxlbend = (cool::ValidityKeyMax & 0xFFFFFFFF)/2;
42static uint32_t minrunnum = (cool::ValidityKeyMin >> 32);
43static uint32_t maxrunnum = (cool::ValidityKeyMax >> 32);
44
45//______________________________________________________________
46// Mini progress bar implementation, reduced version of
47// the one from TMVA/Timer class implementation
48class ProgressBar : public TStopwatch {
49
50 public:
51 ProgressBar( Int_t, Int_t, const char * prefix = "" );
53
54 void Reset();
55 void DrawProgressBar( Int_t );
56 TString SecToText( Double_t );
57 Double_t ElapsedSeconds();
58 TString GetElapsedTime();
59 TString GetLeftTime( Int_t );
60
61 Int_t pbNbins;
62 Int_t Ncounts;
63 TString Prefix;
64
65};
66
67//_______________________________________________________________________
68ProgressBar::ProgressBar(Int_t ncounts, Int_t nbins, const char * prefix)
69 : pbNbins(nbins), Ncounts(ncounts), Prefix(TString(prefix))
70{
71 Reset();
72}
73
74//_______________________________________________________________________
77
78//_______________________________________________________________________
80{
81 TStopwatch::Start( kTRUE );
82}
83
84//_______________________________________________________________________
86{
87 // computes elapsed time in seconds
88 Double_t rt = TStopwatch::RealTime(); TStopwatch::Start( kFALSE );
89 return rt;
90}
91//_______________________________________________________________________
92
94{
95 // returns string with elapsed time
96 return SecToText( ElapsedSeconds());
97}
98
99//_______________________________________________________________________
100TString ProgressBar::GetLeftTime( Int_t icounts )
101{
102 // returns pretty string with time left
103 Double_t leftTime = ( icounts <= 0 ? -1 :
104 icounts > Ncounts ? -1 :
105 Double_t(Ncounts - icounts)/Double_t(icounts)*ElapsedSeconds() );
106
107 return SecToText( leftTime );
108}
109
110//_______________________________________________________________________
111TString ProgressBar::SecToText( Double_t seconds )
112{
113
114 TString out = "";
115 if (seconds < 0 ) out = "unknown";
116 else if (seconds <= 300) out = Form( "%i sec", Int_t(seconds) );
117 else {
118 if (seconds > 3600) {
119 Int_t h = Int_t(seconds/3600);
120 if (h <= 1) out = Form( "%i hr : ", h );
121 else out = Form( "%i hrs : ", h );
122
123 seconds = Int_t(seconds)%3600;
124 }
125 Int_t m = Int_t(seconds/60);
126 if (m <= 1) out += Form( "%i min", m );
127 else out += Form( "%i mins", m );
128 }
129
130 return out;
131}
132
133//_______________________________________________________________________
135{
136
137 // check for consistency:
138 if (i > Ncounts-1) i = Ncounts-1;
139 if (i < 0 ) i = 0;
140 Int_t ic = Int_t(Float_t(i)/Float_t(Ncounts)*pbNbins);
141
142 std::clog << Prefix << " ";
143
144 // re-print the actual bar
145 std::clog << "[";
146 for (Int_t it = 0; it<ic; it++){
147 std::clog << ">";
148 }
149
150 for (Int_t it = ic+1; it<pbNbins; it++){
151 std::clog << " ";
152 }
153 std::clog << "]";
154
155 // print timing information
156 std::clog << "(" << Int_t((100*(i+1))/Float_t(Ncounts)) << "%"
157 << ", " << "time left: " << this->GetLeftTime( i ) << ") ";
158 std::clog << "\r" << std::flush;
159}
160
161
162//______________________________________________________________
163bool FileExists(const std::string& strFilename) {
164 struct stat stFileInfo;
165 bool blnReturn;
166 int intStat;
167
168 // Attempt to get the file attributes
169 intStat = stat(strFilename.c_str(),&stFileInfo);
170 if(intStat == 0) {
171 // We were able to get the file attributes
172 // so the file obviously exists.
173
174
175 blnReturn = true;
176 } else {
177 // We were not able to get the file attributes.
178 // This may mean that we don't have permission to
179 // access the folder which contains this file. If you
180 // need to do that level of checking, lookup the
181 // return values of stat which will give you
182 // more details on why stat failed.
183 blnReturn = false;
184 }
185
186 return(blnReturn);
187}
Define macros for attributes used to control the static checker.
Header file for AthHistogramAlgorithm.
void DrawProgressBar(Int_t)
Definition iLumiCalc.h:134
Double_t ElapsedSeconds()
Definition iLumiCalc.h:85
Int_t Ncounts
Definition iLumiCalc.h:62
TString GetElapsedTime()
Definition iLumiCalc.h:93
TString GetLeftTime(Int_t)
Definition iLumiCalc.h:100
Int_t pbNbins
Definition iLumiCalc.h:61
TString SecToText(Double_t)
Definition iLumiCalc.h:111
void Reset()
Definition iLumiCalc.h:79
ProgressBar(Int_t, Int_t, const char *prefix="")
Definition iLumiCalc.h:68
TString Prefix
Definition iLumiCalc.h:63
The header file for the command line option parser generated by GNU Gengetopt version 2....
static uint32_t minlbstart
Definition iLumiCalc.h:40
bool FileExists(const std::string &strFilename)
Definition iLumiCalc.h:163
static std::vector< std::string > triggerchain
Definition iLumiCalc.h:34
static std::vector< uint32_t > lbstart
Definition iLumiCalc.h:38
static std::vector< uint32_t > runnumber
Definition iLumiCalc.h:37
static std::vector< std::string > tagfile
Definition iLumiCalc.h:27
static std::vector< std::string > xmlfile
Definition iLumiCalc.h:29
static std::vector< std::string > rootfile
Definition iLumiCalc.h:30
static std::vector< std::string > aodfile
Definition iLumiCalc.h:28
static uint32_t maxrunnum
Definition iLumiCalc.h:43
static uint32_t minrunnum
Definition iLumiCalc.h:42
static Root::TMsgLogger logger("iLumiCalc")
static uint32_t maxlbend
Definition iLumiCalc.h:41
static std::string livetrigger
Definition iLumiCalc.h:35
static std::vector< uint32_t > lbend
Definition iLumiCalc.h:39
static std::string d3pddirname
Definition iLumiCalc.h:32
static std::string treename
Definition iLumiCalc.h:31
static std::string xmloutfile
Definition iLumiCalc.h:33