BmnRoot 26.10.0-210-gc52d34b0
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
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
13#include <iomanip>
14#include <iostream>
15#include <string>
16#include <vector>
17
18using std::cout;
19using std::endl;
20using std::ios;
21using std::setw;
22using std::string;
23using std::vector;
24
26{
27 public:
29 : fName("")
30 , fReal(0.)
31 , fCpu(0.) {};
32 TimerInfo(const string& name)
33 : fName(name)
34 , fReal(0.)
35 , fCpu(0.) {};
36
38 {
39 fReal = sw.RealTime();
40 fCpu = sw.CpuTime();
41 };
43 {
44 fReal += sw.RealTime();
45 fCpu += sw.CpuTime();
46 };
47 void operator+=(const TimerInfo& t)
48 {
49 fReal += t.fReal;
50 fCpu += t.fCpu;
51 }
52 TimerInfo operator/(const float f) const
53 {
54 TimerInfo r;
55 r.fName = fName;
56 r.fReal = fReal / f;
57 r.fCpu = fCpu / f;
58 return r;
59 }
60
61 // void Print(){ cout << fReal << "/" << fCpu; };
62 void PrintReal() { cout << fReal; };
63 float Real() { return fReal; };
64 string& Name() { return fName; };
65
66 private:
67 string fName;
68 float fReal, fCpu;
69};
70
72{
73 public:
75 : fNameToI()
76 , fTIs()
77 {}
78 void Add(string name)
79 {
80 fNameToI[name] = fTIs.size();
81 fTIs.push_back(TimerInfo(name));
82 };
83 TimerInfo& operator[](string name) { return fTIs[fNameToI[name]]; };
84 TimerInfo& operator[](int i) { return fTIs[i]; };
86 {
87 for (unsigned int i = 0; i < fTIs.size(); ++i)
88 fTIs[i] += t[i];
89 }
91 {
94 r.fTIs.resize(fTIs.size());
95 for (unsigned int i = 0; i < fTIs.size(); ++i) {
96 r.fTIs[i] = fTIs[i] / f;
97 }
98 return r;
99 }
100
101 void PrintReal(int f = 0)
102 {
103 if (f) {
104 PrintNames();
105 cout << endl;
106 }
107 fTIs[0].PrintReal();
108 for (unsigned int i = 1; i < fTIs.size(); ++i) {
109 cout << " | " << setw(fTIs[i].Name().size());
110 fTIs[i].PrintReal();
111 }
112 if (f)
113 cout << endl;
114 };
116 {
117 cout << fTIs[0].Name();
118 for (unsigned int i = 1; i < fTIs.size(); ++i) {
119 cout << " | " << fTIs[i].Name();
120 }
121 };
122
123 private:
124 map<string, int> fNameToI;
125 vector<TimerInfo> fTIs;
126};
127
129{
130 public:
132 : fTIIs()
133 , fTIAll() {};
134 void SetNIter(int n) { fTIIs.resize(n); };
135
136 void Add(string name)
137 {
138 for (unsigned int i = 0; i < fTIIs.size(); ++i)
139 fTIIs[i].Add(name);
140 fTIAll.Add(name);
141 }; // use after setniter
145 {
146 for (unsigned int i = 0; i < fTIIs.size(); ++i)
147 fTIIs[i] += t[i];
148 fTIAll += t.GetAllInfo();
149 }
151 {
153 r.fTIAll = fTIAll / f;
154 r.SetNIter(fTIIs.size());
155 for (unsigned int i = 0; i < fTIIs.size(); ++i) {
156 r.fTIIs[i] = fTIIs[i] / f;
157 }
158 return r;
159 }
160
161 void Calc()
162 {
163 fTIAll = fTIIs[0];
164 for (unsigned int i = 1; i < fTIIs.size(); ++i)
165 fTIAll += fTIIs[i];
166 }
167
170 {
171 cout.precision(1);
172 cout.setf(ios::fixed);
173 cout << " stage " << " : ";
174 fTIAll.PrintNames();
175 cout << endl;
176 for (unsigned int i = 0; i < fTIIs.size(); ++i) {
177 cout << " iter " << i << " : ";
178 fTIIs[i].PrintReal();
179 cout << endl;
180 }
181 cout << " all " << " : ";
182 fTIAll.PrintReal();
183 cout << endl;
184 };
185
186 private:
187 vector<L1CATFIterTimerInfo> fTIIs;
189};
190
191#endif
int i
Definition P4_F32vec4.h:22
TimerInfo & operator[](string name)
Definition L1Timer.h:83
vector< TimerInfo > fTIs
Definition L1Timer.h:125
void PrintReal(int f=0)
Definition L1Timer.h:101
map< string, int > fNameToI
Definition L1Timer.h:124
void Add(string name)
Definition L1Timer.h:78
void operator+=(L1CATFIterTimerInfo &t)
Definition L1Timer.h:85
L1CATFIterTimerInfo operator/(float f)
Definition L1Timer.h:90
TimerInfo & operator[](int i)
Definition L1Timer.h:84
void Add(string name)
Definition L1Timer.h:136
vector< L1CATFIterTimerInfo > fTIIs
Definition L1Timer.h:187
L1CATFTimerInfo operator/(float f)
Definition L1Timer.h:150
L1CATFIterTimerInfo & GetAllInfo()
Definition L1Timer.h:168
void operator+=(L1CATFTimerInfo &t)
Definition L1Timer.h:144
L1CATFIterTimerInfo & GetTimerAll()
Definition L1Timer.h:142
L1CATFIterTimerInfo & operator[](int i)
Definition L1Timer.h:143
L1CATFIterTimerInfo fTIAll
Definition L1Timer.h:188
void PrintReal()
Definition L1Timer.h:169
void SetNIter(int n)
Definition L1Timer.h:134
Double_t RealTime()
Double_t CpuTime()
TimerInfo operator/(const float f) const
Definition L1Timer.h:52
string & Name()
Definition L1Timer.h:64
void operator=(TStopwatch &sw)
Definition L1Timer.h:37
float fReal
Definition L1Timer.h:68
TimerInfo()
Definition L1Timer.h:28
void PrintReal()
Definition L1Timer.h:62
float fCpu
Definition L1Timer.h:68
void operator+=(TStopwatch &sw)
Definition L1Timer.h:42
string fName
Definition L1Timer.h:67
TimerInfo(const string &name)
Definition L1Timer.h:32
float Real()
Definition L1Timer.h:63
void operator+=(const TimerInfo &t)
Definition L1Timer.h:47