1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 // Author: Andrei Gheata, 20/12/2010
19 //==============================================================================
20 // AliAnalysisStatistics - basic class for storing statistics for the processed
21 // events. The object is mergeable and can be used for general purpose. In case
22 // a AliAnalysisTaskStat is used, this will set the global statistics object
23 // to the analysis manager and will update it for the accepted events.
24 //==============================================================================
26 #include "AliAnalysisStatistics.h"
28 #include "Riostream.h"
29 #include "TObjArray.h"
30 #include "TStopwatch.h"
32 #include "AliVEvent.h"
36 ClassImp(AliAnalysisStatistics)
38 //______________________________________________________________________________
39 AliAnalysisStatistics::AliAnalysisStatistics(const AliAnalysisStatistics &other)
41 fNinput(other.fNinput),
42 fNprocessed(other.fNprocessed),
43 fNfailed(other.fNfailed),
44 fNaccepted(other.fNaccepted),
45 fOfflineMask(other.fOfflineMask),
46 fMaxTasks(other.fMaxTasks),
47 fNtasks(other.fNtasks),
48 fCurrentTask(other.fCurrentTask),
56 fTaskTimer = new TStopwatch();
57 fTaskTimeReal = new Double_t[fMaxTasks];
58 memset(fTaskTimeReal, 0, fMaxTasks*sizeof(Double_t));
59 memcpy(fTaskTimeReal, other.fTaskTimeReal, fNtasks*sizeof(Double_t));
60 fTaskTimeCPU = new Double_t[fMaxTasks];
61 memset(fTaskTimeCPU, 0, fMaxTasks*sizeof(Double_t));
62 memcpy(fTaskTimeCPU, other.fTaskTimeCPU, fNtasks*sizeof(Double_t));
63 fTaskNames = new TObjArray(fMaxTasks);
64 for (Int_t i=0; i<fNtasks; i++) fTaskNames->AddAt(new TObjString(other.GetTaskName(i)), i);
68 //______________________________________________________________________________
69 AliAnalysisStatistics &AliAnalysisStatistics::operator=(const AliAnalysisStatistics &other)
72 if (&other == this) return *this;
73 fNinput = other.fNinput;
74 fNprocessed = other.fNprocessed;
75 fNfailed = other.fNfailed;
76 fNaccepted = other.fNaccepted;
77 fOfflineMask = other.fOfflineMask;
78 fMaxTasks = other.fMaxTasks;
79 fNtasks = other.fNtasks;
80 fCurrentTask = other.fCurrentTask;
86 fTaskTimer = new TStopwatch();
87 fTaskTimeReal = new Double_t[fMaxTasks];
88 memset(fTaskTimeReal, 0, fMaxTasks*sizeof(Double_t));
89 memcpy(fTaskTimeReal, other.fTaskTimeReal, fNtasks*sizeof(Double_t));
90 fTaskTimeCPU = new Double_t[fMaxTasks];
91 memset(fTaskTimeCPU, 0, fMaxTasks*sizeof(Double_t));
92 memcpy(fTaskTimeCPU, other.fTaskTimeCPU, fNtasks*sizeof(Double_t));
93 fTaskNames = new TObjArray(fMaxTasks);
94 for (Int_t i=0; i<fNtasks; i++) fTaskNames->AddAt(new TObjString(other.GetTaskName(i)), i);
99 //______________________________________________________________________________
100 void AliAnalysisStatistics::StartTimer(Int_t itask, const char *name, const char *classname)
102 // Measure the CPU time done by this task in the interval
104 // Create the arrays with timings with the initial size
105 if (!fMaxTasks) fMaxTasks = 100;
106 fTaskTimer = new TStopwatch();
107 fTaskTimeReal = new Double_t[fMaxTasks];
108 memset(fTaskTimeReal, 0, fMaxTasks*sizeof(Double_t));
109 fTaskTimeCPU = new Double_t[fMaxTasks];
110 memset(fTaskTimeCPU, 0, fMaxTasks*sizeof(Double_t));
111 fTaskNames = new TObjArray(fMaxTasks);
113 // Stop the timer if it was timing some task
117 if (fNtasks<itask+1) {
118 // Double the array size
119 if (itask>=fMaxTasks) {
120 Int_t newsize = TMath::Max(2*fMaxTasks, itask+1);
121 Double_t *taskTimeReal = new Double_t[newsize];
122 memset(taskTimeReal, 0, newsize*sizeof(Double_t));
123 memcpy(taskTimeReal, fTaskTimeReal, fMaxTasks*sizeof(Double_t));
124 delete [] fTaskTimeReal;
125 fTaskTimeReal = taskTimeReal;
126 Double_t *taskTimeCPU = new Double_t[newsize];
127 memset(taskTimeCPU, 0, newsize*sizeof(Double_t));
128 memcpy(taskTimeCPU, fTaskTimeCPU, fMaxTasks*sizeof(Double_t));
129 delete [] fTaskTimeCPU;
130 fTaskTimeCPU = taskTimeCPU;
135 // Start the timer for the new task
136 fCurrentTask = itask;
137 if (!fTaskNames->At(fCurrentTask)) {
138 TString sname = name;
139 if (strlen(classname)) sname += Form("(%s)", classname);
140 fTaskNames->AddAt(new TObjString(sname), fCurrentTask);
142 fTaskTimer->Start(kTRUE);
145 //______________________________________________________________________________
146 void AliAnalysisStatistics::StopTimer()
148 // Stop the current task timing.
149 if (fCurrentTask>=0) {
151 fTaskTimeReal[fCurrentTask] += fTaskTimer->RealTime();
152 fTaskTimeCPU[fCurrentTask] += fTaskTimer->CpuTime();
157 //______________________________________________________________________________
158 Long64_t AliAnalysisStatistics::Merge(TCollection* list)
160 // Merge statistics objets from list on top of this.
162 AliAnalysisStatistics *current;
164 while ((current = (AliAnalysisStatistics*)next())) {
165 fNinput += current->GetNinput();
166 fNprocessed += current->GetNprocessed();
167 fNfailed += current->GetNfailed();
168 fNaccepted += current->GetNaccepted();
169 for (Int_t i=0; i<fNtasks; i++) {
170 fTaskTimeReal[i] += current->GetRealTime(i);
171 fTaskTimeCPU[i] += current->GetCPUTime(i);
177 //______________________________________________________________________________
178 void AliAnalysisStatistics::Print(const Option_t *) const
180 // Print info about the processed statistics.
181 cout << "### Input events : " << fNinput << endl;
182 cout << "### Processed events w/o errors : " << fNprocessed << endl;
183 cout << "### Failed events : " << fNfailed << endl;
184 cout << "### Accepted events for mask: " << GetMaskAsString(fOfflineMask) << ": " << fNaccepted << endl;
186 cout << "Timing per task:" <<endl;
188 for (Int_t i=0; i<fNtasks; i++) {
189 s = Form("%03d: real: %9.2f cpu: %9.2f => %s", i,fTaskTimeReal[i], fTaskTimeCPU[i], GetTaskName(i));
195 //______________________________________________________________________________
196 const char *AliAnalysisStatistics::GetMaskAsString(UInt_t mask)
198 // Returns a string corresponding to the offline mask.
199 static TString smask;
201 if (!mask) return smask.Data();
203 if (mask & AliVEvent::kMB) smask = "MB";
204 if (mask & AliVEvent::kMUON) {
205 if (!smask.IsNull()) smask += " | ";
208 if (mask & AliVEvent::kHighMult) {
209 if (!smask.IsNull()) smask += " | ";
212 if (mask & AliVEvent::kUserDefined) {
213 if (!smask.IsNull()) smask += " | ";
214 smask += "UserDefined";
216 if (mask == AliVEvent::kAny) smask = "ANY";
220 //______________________________________________________________________________
221 const char *AliAnalysisStatistics::GetTaskName(Int_t itask) const
224 if (!fTaskNames || !fTaskNames->At(itask)) return 0;
225 return fTaskNames->At(itask)->GetName();