]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/src/AliL3Benchmark.cxx
Possibility to define the magnetic field in the reconstruction (Yu.Belikov)
[u/mrichter/AliRoot.git] / HLT / src / AliL3Benchmark.cxx
1 #include <TFile.h>
2 #include "TGraphAsymmErrors.h"
3 #include "TString.h"
4 #include "TStopwatch.h"
5 #include "AliL3Benchmark.h"
6 #include "TStopwatch.h"
7 #include "TMath.h"
8 #include "AliL3Logging.h"
9
10 ClassImp(AliL3Benchmark)
11
12 AliL3Benchmark::AliL3Benchmark()
13 {
14    fNbench = 0;
15    fNmax   = 20;
16    fNames  = 0;
17    fTimer  = 0;
18    fSum    = 0;
19    fMin    = 0;
20    fMax    = 0;
21    fCount  = 0;
22 //   fStopwatch = 0;
23 }
24
25 AliL3Benchmark::~AliL3Benchmark()
26 {
27    fNbench   = 0;
28    if (fNames)  {delete [] fNames; fNames  = 0;}
29    if (fTimer)  {delete [] fTimer; fTimer  = 0;}
30    if (fSum)    {delete [] fSum;   fSum   = 0;}
31    if (fMin)    {delete [] fMin;   fMin   = 0;}
32    if (fMax)    {delete [] fMax;   fMax   = 0;}
33    if (fCount)  {delete [] fCount; fCount =0;}
34 //   if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
35 }
36
37 Int_t AliL3Benchmark::GetBench(const char *name)
38 {
39    for (Int_t i=0;i<fNbench;i++) {
40       if (!strcmp(name,(const char*)fNames[i])) return i;
41    }
42    return -1;
43 }
44
45
46 void AliL3Benchmark::Start(const char *name)
47 {
48    if (!fNbench) {
49       fNames = new TString[fNmax];
50       fTimer = new TStopwatch[fNmax];
51       fSum   = new Float_t[fNmax];
52       fMin   = new Float_t[fNmax];
53       fMax   = new Float_t[fNmax];
54       fCount = new Int_t[fNmax];
55       for(Int_t i =0;i<fNmax;i++){
56          fSum[i]=0;
57          fMin[i]=0;
58          fMax[i]=0;
59          fCount[i]=0;
60       }
61    }
62    Int_t bench = GetBench(name);
63    if (bench < 0 && fNbench < fNmax ) {
64    // define a new benchmark to Start
65       fNames[fNbench] = name;
66       bench = fNbench;
67       fNbench++;
68       fTimer[bench].Reset();
69       fTimer[bench].Start();
70 //      if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
71 //      fStopwatch = new TStopwatch();
72 //      fStopwatch->Reset();
73 //      fStopwatch->Start();
74    } else if (bench >=0) {
75    // Resume the existen benchmark
76       fTimer[bench].Reset();
77       fTimer[bench].Start();
78 //      if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
79 //      fStopwatch = new TStopwatch();
80 //      fStopwatch->Reset();
81 //      fStopwatch->Start();
82    }
83    else
84      LOG(AliL3Log::kWarning,"AliL3Benchmark::Start","Start")
85      <<"too many benches"<<ENDLOG;
86 }
87
88 void AliL3Benchmark::Stop(const char *name)
89 {
90    Int_t bench = GetBench(name);
91    if (bench < 0) return;
92
93    fTimer[bench].Stop();
94    Float_t val = fTimer[bench].CpuTime();
95 //   fStopwatch->Stop();
96 //   Float_t val = fStopwatch->CpuTime();
97    
98    fSum[bench] += val; 
99    fCount[bench]++;
100    if(fCount[bench]==1){
101      fMin[bench] = val;
102      fMax[bench] = val;
103    }
104    else{
105      if(val<fMin[bench])fMin[bench]=val;
106      if(val>fMax[bench])fMax[bench]=val;
107    }
108 }
109
110 void AliL3Benchmark::Analyze(const char* name){
111   Float_t *x = new Float_t[fNbench]; 
112   Float_t *y = new Float_t[fNbench];
113   Float_t *eyl = new Float_t[fNbench]; 
114   Float_t *eyh = new Float_t[fNbench];
115   char filename[256];
116   sprintf(filename,"%s.dat",name);
117   FILE *f= fopen(filename,"w");
118   for (Int_t i=0;i<fNbench;i++) {
119     Float_t av =0;
120     if(fCount[i]) av = fSum[i]/fCount[i]; 
121     x[i]=i+1;
122     y[i]=av*1000;
123     eyl[i]=(av-fMin[i])*1000;
124     eyh[i]=(fMax[i]-av)*1000;
125     fprintf(f,"%2d. %s: ",i+1,fNames[i].Data());
126     fprintf(f,"%4.0f ms\n",av*1000);
127   }
128   fclose(f);
129   sprintf(filename,"%s.tmp",name);
130 /* only a workaround!!
131   FILE *f2= fopen(filename,"w");
132   for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",x[i]); fprintf(f2,"\n");
133   for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",y[i]); fprintf(f2,"\n");
134   for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",eyl[i]); fprintf(f2,"\n");
135   for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",eyh[i]); fprintf(f2,"\n");
136   fclose(f2);
137 */
138   sprintf(filename,"%s.root",name);
139   TFile *file = new TFile(filename,"RECREATE");
140   TGraphAsymmErrors *gr = new TGraphAsymmErrors(fNbench,x,y,0,0,eyl,eyh);
141   gr->SetTitle("benchmark");
142   gr->SetMarkerStyle(8);
143   gr->SetMinimum(0);
144   gr->Draw("ALP");
145   gr->Write();
146   file->Close();
147   delete file; 
148   file=0;
149   delete[] x;
150   delete[] y;
151   delete[] eyl;
152   delete[] eyh;
153 }
154
155