FairRoot/PandaRoot
L1Timer.h
Go to the documentation of this file.
1 #ifndef _L1Timer_H
2 #define _L1Timer_H
3 
4 /*
5  *=====================================================
6  *
7  * Authors: I.Kulakov
8  *
9  */
10 
11 #include "TStopwatch.h"
12 #include <iostream>
13 #include <iomanip>
14 #include <string>
15 #include <vector>
16 #include <map>
17 
18 using std::cout;
19 using std::endl;
20 using std::ios;
21 using std::setw;
22 using std::string;
23 using std::vector;
24 using std::map;
25 
26 class TimerInfo {
27  public:
28  TimerInfo():fName(""),fReal(0),fCpu(0){ };
29  TimerInfo( const string& name ):fName(name),fReal(0),fCpu(0){ };
30 
31  void Clear() { fReal = 0; fCpu = 0; }
32 
33  void operator =( TStopwatch& sw ) { fReal = sw.RealTime(); fCpu = sw.CpuTime(); };
34  void operator+=( TStopwatch& sw ) { fReal += sw.RealTime(); fCpu += sw.CpuTime(); };
35  void operator+=( const TimerInfo& t ){ fReal += t.fReal; fCpu += t.fCpu; }
36  TimerInfo operator/( const float f ) const { TimerInfo r; r.fName = fName; r.fReal = fReal/f; r.fCpu = fCpu/f; return r; }
37 
38  // void Print(){ cout << fReal << "/" << fCpu; };
39  void PrintReal(){ cout << fReal ; };
40  float Real(){ return fReal; };
41  string& Name(){ return fName; };
42  private:
43  string fName;
44  float fReal, fCpu;
45 };
46 
48  public:
49  void Clear() {
50  for( unsigned int i = 0; i < fTIs.size(); i++ )
51  fTIs[i].Clear();
52  };
53 
54  void Add( string name ) { fNameToI[name] = fTIs.size(); fTIs.push_back(TimerInfo(name)); };
55  TimerInfo& operator[]( string name ) { return fTIs[fNameToI[name]]; };
56  TimerInfo& operator[]( int i ) { return fTIs[i]; };
57  void operator+=( L1CATFIterTimerInfo& t ){ for( unsigned int i = 0; i < fTIs.size(); ++i ) fTIs[i] += t[i]; }
60  r.fNameToI = fNameToI;
61  r.fTIs.resize(fTIs.size());
62  for( unsigned int i = 0; i < fTIs.size(); ++i ) {
63  r.fTIs[i] = fTIs[i]/f;
64  }
65  return r;
66  }
67 
68  void PrintReal( int f = 0 ){
69  if (f) { PrintNames(); cout << endl; }
70  fTIs[0].PrintReal(); for( unsigned int i = 1; i < fTIs.size(); ++i ) { cout << " | " << setw(fTIs[i].Name().size()); fTIs[i].PrintReal(); }
71  if (f) cout << endl;
72  };
73  void PrintNames(){ cout << fTIs[0].Name(); for( unsigned int i = 1; i < fTIs.size(); ++i ) { cout << " | " << fTIs[i].Name(); } };
74  private:
75  map< string, int > fNameToI;
76  vector<TimerInfo> fTIs;
77 };
78 
80  public:
82  L1CATFTimerInfo(int n ) { fTIIs.resize(n); };
83  void SetNIter( int n ) { fTIIs.resize(n); };
84 
85  void Clear() {
86  for( unsigned int i = 0; i < fTIIs.size(); i++ )
87  fTIIs[i].Clear();
88  fTIAll.Clear();
89  };
90 
91  void Add( string name ) {
92  for( unsigned int i = 0; i < fTIIs.size(); ++i )
93  fTIIs[i].Add(name);
94  fTIAll.Add(name);
95  }; // use after setniter
97  L1CATFIterTimerInfo& operator[]( int i ) { return fTIIs[i]; };
98  void operator+=( L1CATFTimerInfo& t ){ for( unsigned int i = 0; i < fTIIs.size(); ++i ) fTIIs[i] += t[i]; fTIAll += t.GetAllInfo(); }
101  r.fTIAll = fTIAll/f;
102  r.SetNIter( fTIIs.size() );
103  for( unsigned int i = 0; i < fTIIs.size(); ++i ) {
104  r.fTIIs[i] = fTIIs[i]/f;
105  }
106  return r;
107  }
108 
109  void Calc() {
110  fTIAll = fTIIs[0];
111  for( unsigned int i = 1; i < fTIIs.size(); ++i )
112  fTIAll += fTIIs[i];
113  }
114 
116  void PrintReal() {
117  //save original cout flags
118  std::ios_base::fmtflags coutFlags = cout.flags();
119 
120  int old_precision = cout.precision(1);
121  cout.setf(ios::fixed);
122  cout << " stage "<< " : "; fTIAll.PrintNames(); cout << endl;
123  for( unsigned int i = 0; i < fTIIs.size(); ++i ) {
124  cout << " iter " << i << " : "; fTIIs[i].PrintReal(); cout << endl;
125  }
126  cout << " all "<< " : "; fTIAll.PrintReal(); cout << endl;
127 
128  //restore original cout flags
129  cout.flags(coutFlags);
130  cout.precision(old_precision);
131  };
132  private:
133  vector<L1CATFIterTimerInfo> fTIIs;
135 };
136 
137 #endif
138 
L1CATFIterTimerInfo & GetTimerAll()
Definition: L1Timer.h:96
double r
Definition: RiemannTest.C:14
Int_t i
Definition: run_full.C:25
L1CATFTimerInfo(int n)
Definition: L1Timer.h:82
void SetNIter(int n)
Definition: L1Timer.h:83
string fName
Definition: L1Timer.h:41
PndTransMap * map
Definition: sim_emc_apd.C:99
L1CATFIterTimerInfo & GetAllInfo()
Definition: L1Timer.h:115
int n
void Clear()
Definition: L1Timer.h:85
TimerInfo(const string &name)
Definition: L1Timer.h:29
vector< TimerInfo > fTIs
Definition: L1Timer.h:76
TimerInfo & operator[](string name)
Definition: L1Timer.h:55
void operator=(TStopwatch &sw)
Definition: L1Timer.h:33
string & Name()
Definition: L1Timer.h:41
L1CATFTimerInfo operator/(float f)
Definition: L1Timer.h:99
void PrintReal()
Definition: L1Timer.h:39
void Calc()
Definition: L1Timer.h:109
void Clear()
Definition: L1Timer.h:31
float fCpu
Definition: L1Timer.h:44
void Add(string name)
Definition: L1Timer.h:54
L1CATFIterTimerInfo & operator[](int i)
Definition: L1Timer.h:97
L1CATFIterTimerInfo fTIAll
Definition: L1Timer.h:134
float Real()
Definition: L1Timer.h:40
L1CATFIterTimerInfo operator/(float f)
Definition: L1Timer.h:58
void PrintNames()
Definition: L1Timer.h:73
void operator+=(TStopwatch &sw)
Definition: L1Timer.h:34
TFile * f
Definition: bump_analys.C:12
TimerInfo()
Definition: L1Timer.h:28
TString name
vector< L1CATFIterTimerInfo > fTIIs
Definition: L1Timer.h:131
void operator+=(const TimerInfo &t)
Definition: L1Timer.h:35
void PrintReal(int f=0)
Definition: L1Timer.h:68
void PrintReal()
Definition: L1Timer.h:116
TimerInfo & operator[](int i)
Definition: L1Timer.h:56
TTree * t
Definition: bump_analys.C:13
void operator+=(L1CATFTimerInfo &t)
Definition: L1Timer.h:98
TimerInfo operator/(const float f) const
Definition: L1Timer.h:36
map< string, int > fNameToI
Definition: L1Timer.h:73
float fReal
Definition: L1Timer.h:44
void operator+=(L1CATFIterTimerInfo &t)
Definition: L1Timer.h:57
void Add(string name)
Definition: L1Timer.h:91