StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StiTimer.cxx
1 #include "StiTimer.h"
2 #include "TList.h"
3 #include "TNamed.h"
4 #include "StMessMgr.h"
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <assert.h>
8 
9 
10 TStopwatch *StiTimer::fgFindTimer=0;
11 int StiTimer::fgFindTally=0;
12 TList *StiTimer::fgList=0;
13 
14 class MyHolder : public TNamed
15 {
16 public:
17  MyHolder(){}
18  ~MyHolder(){ delete fSW; }
19 TStopwatch *fSW;
20 int *fTally;
21 };
22 
23 //______________________________________________________________________________
24 void StiTimer::Init(const char *name,TStopwatch *&sw,int &tally)
25 {
26  if (!fgList) {fgList= new TList; fgList->SetOwner();}
27  MyHolder *mh = (MyHolder*)fgList->FindObject(name);
28  assert(!mh);
29  mh = new MyHolder();
30  sw = new TStopwatch();
31  sw->Stop();
32  mh->fSW = sw;
33  tally = 0;
34  mh->fTally = &tally;
35  mh->SetName(name);
36  fgList->Add(mh);
37 }
38 
39 //______________________________________________________________________________
40 void StiTimer::Clear(const char *)
41 {
42  delete fgList; fgList=0;
43 }
44 
45 //______________________________________________________________________________
46 void StiTimer::Print(const char *option)
47 {
48 
49  LOG_DEBUG << Form("**** StiTimer::Print ****")<<endm;
50  TListIter next(fgList);
51  MyHolder *mh=0;
52  int n = 0;
53  while ((mh=(MyHolder*)next())) {
54  n++;
55  int tally = mh->fTally[0];
56  if (tally<=0) continue;
57 
58  double cpu = mh->fSW->CpuTime()/tally;
59  double rte = mh->fSW->RealTime()/tally;
60 
61  LOG_DEBUG << Form("StiTimer for <%s> Evts =%d CPU/Evts = %g Time/Evts = %g"
62  ,mh->GetName(),tally,cpu,rte) << endm;
63  mh->fSW->Print("u");
64 
65  }
66 }
67 
68 
69 
70