ATLAS Offline Software
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 
6 #include "LumiCalc/CoolQuery.h"
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 
27 static std::vector<std::string> tagfile;
28 static std::vector<std::string> aodfile;
29 static std::vector<std::string> xmlfile;
30 static std::vector<std::string> rootfile;
31 static std::string treename = "tree";
32 static std::string d3pddirname = "Lumi";
33 static std::string xmloutfile = "out.xml";
34 static std::vector<std::string> triggerchain;
35 static std::string livetrigger;
36 static Root::TMsgLogger logger( "iLumiCalc" );
37 static std::vector<uint32_t> runnumber;
38 static std::vector<uint32_t> lbstart;
39 static std::vector<uint32_t> lbend;
40 static uint32_t minlbstart = cool::ValidityKeyMin & 0xFFFFFFFF;
41 static uint32_t maxlbend = (cool::ValidityKeyMax & 0xFFFFFFFF)/2;
42 static uint32_t minrunnum = (cool::ValidityKeyMin >> 32);
43 static uint32_t maxrunnum = (cool::ValidityKeyMax >> 32);
44 
45 //______________________________________________________________
46 // Mini progress bar implementation, reduced version of
47 // the one from TMVA/Timer class implementation
48 class ProgressBar : public TStopwatch {
49 
50  public:
51  ProgressBar( Int_t, Int_t, const char * prefix = "" );
52  ~ProgressBar();
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 //_______________________________________________________________________
68 ProgressBar::ProgressBar(Int_t ncounts, Int_t nbins, const char * prefix)
69  : pbNbins(nbins), Ncounts(ncounts), Prefix(TString(prefix))
70 {
71  Reset();
72 }
73 
74 //_______________________________________________________________________
76 {}
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 //_______________________________________________________________________
100 TString 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 //_______________________________________________________________________
111 TString 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 //______________________________________________________________
163 bool 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 }
ProgressBar::ElapsedSeconds
Double_t ElapsedSeconds()
Definition: iLumiCalc.h:85
TGoodRunsList.h
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
ProgressBar::Ncounts
Int_t Ncounts
Definition: iLumiCalc.h:62
FullCPAlgorithmsTest_eljob.flush
flush
Definition: FullCPAlgorithmsTest_eljob.py:168
TGRLCollection.h
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
skel.it
it
Definition: skel.GENtoEVGEN.py:423
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
ProgressBar::Prefix
TString Prefix
Definition: iLumiCalc.h:63
ProgressBar::ProgressBar
ProgressBar(Int_t, Int_t, const char *prefix="")
Definition: iLumiCalc.h:68
ProgressBar::Reset
void Reset()
Definition: iLumiCalc.h:79
LumiCalculator.h
LArCalib_HVScale2NtupleConfig.rootfile
string rootfile
Definition: LArCalib_HVScale2NtupleConfig.py:74
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
lumiFormat.i
int i
Definition: lumiFormat.py:92
FileExists
bool FileExists(const std::string &strFilename)
Definition: iLumiCalc.h:163
ProgressBar::GetElapsedTime
TString GetElapsedTime()
Definition: iLumiCalc.h:93
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
ProgressBar::DrawProgressBar
void DrawProgressBar(Int_t)
Definition: iLumiCalc.h:134
python.LArCalib_HVCorrConfig.seconds
seconds
Definition: LArCalib_HVCorrConfig.py:86
beamspotman.stat
stat
Definition: beamspotman.py:266
DeMoScan.runnumber
runnumber
Definition: DeMoScan.py:266
grepfile.ic
int ic
Definition: grepfile.py:33
LumiBlockRangeContainerConverter.h
ProgressBar
Definition: iLumiCalc.h:48
ProgressBar::SecToText
TString SecToText(Double_t)
Definition: iLumiCalc.h:111
TGoodRunsListReader.h
cmdline.h
The header file for the command line option parser generated by GNU Gengetopt version 2....
h
TMsgLogger.h
Root::TMsgLogger
Definition: TMsgLogger.h:52
CoolQuery.h
ProgressBar::GetLeftTime
TString GetLeftTime(Int_t)
Definition: iLumiCalc.h:100
checker_macros.h
Define macros for attributes used to control the static checker.
python.iconfTool.gui.pad.logger
logger
Definition: pad.py:14
ProgressBar::pbNbins
Int_t pbNbins
Definition: iLumiCalc.h:61
ProgressBar::~ProgressBar
~ProgressBar()
Definition: iLumiCalc.h:75