ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/mstein/triggerStudy/timing.h
Revision: 1.1
Committed: Thu Nov 22 15:32:47 2012 UTC (12 years, 5 months ago) by mstein
Content type: text/plain
Branch: MAIN
CVS Tags: v1
Log Message:
first skeleton

File Contents

# Content
1 #include <iostream>
2 #include <map>
3 #include <vector>
4 #include "TString.h"
5 #include "TStopwatch.h"
6
7 #ifndef timing_h
8 #define timing_h
9
10 //================================================================================= class: timing
11 class timing{
12 private:
13 map<TString, Bool_t> isRunning;
14 vector<TString> names;
15 map<TString, TStopwatch> myTimer;
16 Bool_t isNew(TString name){return (myTimer.find(name) == myTimer.end());}
17
18 public:
19 void PrintReport(ostream& os=cout);
20 void Reset(TString name, ostream& os=cout);
21 void Start(TString name, ostream& os=cout);
22 void Stop(TString name, ostream& os=cout);
23 timing(){}
24 virtual ~timing(){
25 // for(Int_t i=0,N=names.size(); i<N; ++i){
26 // myTimer[names[i]].Delete();
27 // }
28
29
30 }
31 };
32
33
34 //================================================================================= PrintReport
35 void timing::PrintReport(ostream& os){
36 if(myTimer.size()==0){
37 os<<"No timer is set!"<<endl;
38 return;
39 }
40 os<<endl;
41 os<<"/////////////////////////////////////// Timing Report //////////////////////////////////////"<<endl;
42 os<<endl;
43 os<<setw(50)<<"name"
44 <<setw(15)<<"CPU-Time"
45 <<setw(15)<<"Real-Time"
46 //<<setw(30)<<myTimer[names[i]].Print()
47 <<endl;
48 os<<"____________________________________________________________________________________________"<<endl;
49
50 for(Int_t i=0,N=names.size(); i<N; ++i){
51 os<<setw(50)<<names[i]
52 <<setw(15)<<myTimer[names[i]].CpuTime()
53 <<setw(15)<<myTimer[names[i]].RealTime()
54 //<<setw(30)<<myTimer[names[i]].Print()
55 <<endl;
56 }
57 os<<endl;
58 os<<"////////////////////////////////////////////////////////////////////////////////////////////"<<endl;
59 os<<endl;
60
61 }
62
63
64 //================================================================================= Reset
65 void timing::Reset(TString name, ostream& os){
66 if(isNew(name)){
67 os<<"WARNING: No timer with name \"" << name << "\" to reset. No Action is done." << endl;
68 return;
69 }
70 myTimer[name].Reset();
71 }
72
73
74 //================================================================================= Start
75 void timing::Start(TString name, ostream& os){
76 if(isRunning[name]){
77 os<<"WARNING: timer with name \"" << name << "\" is already running. No Action is done." << endl;
78 return;
79 }
80 //TStopwatch *t = new TStopwatch();
81 //t->Start();
82 //myTimer[name] = t;
83 myTimer[name].Start();
84 names.push_back(name);
85 }
86
87
88 //================================================================================= Stop
89 void timing::Stop(TString name, ostream& os){
90 if(isNew(name)){
91 os<<"WARNING: No timer with name \"" << name << "\" to stop. No Action is done." << endl;
92 return;
93 }
94 myTimer[name].Stop();
95 isRunning[name]=false;
96 }
97
98
99
100
101
102
103
104
105
106
107 #endif
108
109
110
111
112
113 // //================================================================================= testPassArray
114 // void testTiming(){
115 // timing timer;
116 // timer.Start("OverAllTime");
117 //
118 // timer.Start("Small Loop");
119 // for(Int_t i=0; i<10000; ++i) cout<<"i = " << i << endl;
120 // timer.Stop("Small Loop");
121 //
122 // timer.Start("Big Loop");
123 // for(Int_t i=0,N=100000; i<N; ++i) cout<<"i = " << i << endl;
124 // timer.Stop("Big Loop");
125 //
126 // timer.Stop("OverAllTime");
127 // timer.PrintReport();
128 // }
129
130
131
132
133
134
135
136
137
138
139