FairRoot/PandaRoot
PndCATimer.h
Go to the documentation of this file.
1 #ifndef PNDCATIMER_H
2 #define PNDCATIMER_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 
27  public:
28  PndCATimerInfo():fName(""),fReal(0),fCpu(0){ };
29  PndCATimerInfo( 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 PndCATimerInfo& t ){ fReal += t.fReal; fCpu += t.fCpu; }
36  PndCATimerInfo operator/( const float f ) const { PndCATimerInfo 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(PndCATimerInfo(name)); };
55  PndCATimerInfo& operator[]( string name ) { return fTIs[fNameToI[name]]; };
56  PndCATimerInfo& operator[]( int i ) { return fTIs[i]; };
57  void operator+=( PndCATFIterTimerInfo& 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<PndCATimerInfo> fTIs;
77 };
78 
80  public:
82  PndCATFTimerInfo(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  PndCATFIterTimerInfo& operator[]( int i ) { return fTIIs[i]; };
98  void operator+=( PndCATFTimerInfo& 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  cout.precision(1);
118  cout.setf(ios::fixed);
119  cout << " stage "<< " : "; fTIAll.PrintNames(); cout << endl;
120  for( unsigned int i = 0; i < fTIIs.size(); ++i ) {
121  cout << " iter " << i << " : "; fTIIs[i].PrintReal(); cout << endl;
122  }
123  cout << " all "<< " : "; fTIAll.PrintReal(); cout << endl;
124 
125  };
126  private:
127  vector<PndCATFIterTimerInfo> fTIIs;
129 };
130 
131 #endif
132 
void Add(string name)
Definition: PndCATimer.h:54
void operator+=(PndCATFIterTimerInfo &t)
Definition: PndCATimer.h:57
string & Name()
Definition: PndCATimer.h:41
double r
Definition: RiemannTest.C:14
void Add(string name)
Definition: PndCATimer.h:91
Int_t i
Definition: run_full.C:25
PndTransMap * map
Definition: sim_emc_apd.C:99
void Clear()
Definition: PndCATimer.h:31
vector< PndCATimerInfo > fTIs
Definition: PndCATimer.h:76
PndCATimerInfo & operator[](string name)
Definition: PndCATimer.h:55
PndCATFIterTimerInfo & operator[](int i)
Definition: PndCATimer.h:97
int n
vector< PndCATFIterTimerInfo > fTIIs
Definition: PndCATimer.h:125
void operator+=(PndCATFTimerInfo &t)
Definition: PndCATimer.h:98
void SetNIter(int n)
Definition: PndCATimer.h:83
void PrintReal()
Definition: PndCATimer.h:39
float Real()
Definition: PndCATimer.h:40
PndCATFTimerInfo(int n)
Definition: PndCATimer.h:82
PndCATimerInfo & operator[](int i)
Definition: PndCATimer.h:56
void operator+=(const PndCATimerInfo &t)
Definition: PndCATimer.h:35
void operator=(TStopwatch &sw)
Definition: PndCATimer.h:33
map< string, int > fNameToI
Definition: PndCATimer.h:73
TFile * f
Definition: bump_analys.C:12
PndCATFIterTimerInfo fTIAll
Definition: PndCATimer.h:128
void operator+=(TStopwatch &sw)
Definition: PndCATimer.h:34
string fName
Definition: PndCATimer.h:41
TString name
void PrintReal(int f=0)
Definition: PndCATimer.h:68
PndCATFIterTimerInfo & GetTimerAll()
Definition: PndCATimer.h:96
PndCATimerInfo operator/(const float f) const
Definition: PndCATimer.h:36
TTree * t
Definition: bump_analys.C:13
PndCATimerInfo(const string &name)
Definition: PndCATimer.h:29
PndCATFTimerInfo operator/(float f)
Definition: PndCATimer.h:99
PndCATFIterTimerInfo & GetAllInfo()
Definition: PndCATimer.h:115
PndCATFIterTimerInfo operator/(float f)
Definition: PndCATimer.h:58