AliRoot Core  edcc906 (edcc906)
AliQADataMakerSim.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
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  **************************************************************************/
15 
16 
17 /* $Id$ */
18 
19 //
20 // Base Class
21 // Produces the data needed to calculate the quality assurance.
22 // All data must be mergeable objects.
23 // Y. Schutz CERN July 2007
24 //
25 
26 // --- ROOT system ---
27 #include <TFile.h>
28 #include <TTree.h>
29 #include <TClonesArray.h>
30 
31 // --- Standard library ---
32 
33 // --- AliRoot header files ---
34 #include "AliLog.h"
35 #include "AliQADataMakerSim.h"
36 
37 ClassImp(AliQADataMakerSim)
38 
39 //____________________________________________________________________________
40 AliQADataMakerSim::AliQADataMakerSim(const char * name, const char * title) :
41  AliQADataMaker(name, title),
42  fDigitsQAList(NULL),
43  fHitsQAList(NULL),
44  fSDigitsQAList(NULL),
45  fHitsArray(NULL),
46  fSDigitsArray(NULL)
47 {
48  // ctor
49  fDetectorDirName = GetName() ;
50 }
51 
52 //____________________________________________________________________________
54  AliQADataMaker(qadm.GetName(), qadm.GetTitle()),
55  fDigitsQAList(qadm.fDigitsQAList),
56  fHitsQAList(qadm.fHitsQAList),
57  fSDigitsQAList(qadm.fSDigitsQAList),
58  fHitsArray(NULL),
59  fSDigitsArray(NULL)
60 {
61  //copy ctor
62  fDetectorDirName = GetName() ;
63 }
64 
65 //____________________________________________________________________________
67 {
68  //dtor: delete the TObjArray and thei content
69  if ( fDigitsQAList ) {
70  for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
71  fDigitsQAList[specie]->Delete() ;
72  }
73  delete[] fDigitsQAList ;
74  }
75  if ( fHitsQAList ) {
76  for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
77  fHitsQAList[specie]->Delete() ;
78  }
79  delete[] fHitsQAList ;
80  }
81  if ( fSDigitsQAList ) {
82  for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
83  fSDigitsQAList[specie]->Delete() ;
84  }
85  delete[] fSDigitsQAList ;
86  }
87  if (fHitsArray) {
88  fHitsArray->Clear() ;
89  delete fHitsArray ;
90  }
91  if (fSDigitsArray) {
92  fSDigitsArray->Clear() ;
93  delete fSDigitsArray ;
94  }
95 }
96 
97 //__________________________________________________________________
99 {
100  // Assignment operator.
101  this->~AliQADataMakerSim();
102  new(this) AliQADataMakerSim(qadm);
103  return *this;
104 }
105 
106 //____________________________________________________________________________
108 {
109  // Finishes a cycle of QA for all tasks
113  ResetCycle() ;
114 }
115 
116 //____________________________________________________________________________
118 {
119  // Finishes a cycle of QA data acquistion
120  TObjArray ** list = NULL ;
121 
122  if ( task == AliQAv1::kHITS )
123  list = fHitsQAList ;
124  else if ( task == AliQAv1::kSDIGITS )
125  list = fSDigitsQAList ;
126  else if ( task == AliQAv1::kDIGITS )
127  list = fDigitsQAList ;
128 
129  if ( ! list )
130  return ;
131  EndOfDetectorCycle(task, list) ;
132  fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ;
133  if (!fDetectorDir)
135  TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ;
136  if (!subDir)
137  subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;
138  subDir->cd() ;
139  for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
140  if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(specie)) )
141  continue ;
142  if (list[specie]->GetEntries() != 0 ) {
143  TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
144  if (!eventSpecieDir)
145  eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ;
146  eventSpecieDir->cd() ;
147  TIter next(list[specie]) ;
148  TObject * obj ;
149  while ( (obj = next()) ) {
150  if (!obj->TestBit(AliQAv1::GetExpertBit()))
151  obj->Write() ;
152  }
153  if (WriteExpert()) {
154  TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ;
155  if (!expertDir)
156  expertDir = eventSpecieDir->mkdir(AliQAv1::GetExpert()) ;
157  expertDir->cd() ;
158  next.Reset() ;
159  while ( (obj = next()) ) {
160  if (!obj->TestBit(AliQAv1::GetExpertBit()))
161  continue ;
162  obj->Write() ;
163  }
164  }
165  }
166  fOutput->Save() ;
167  }
168 }
169 
170 //____________________________________________________________________________
172 {
173  // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
174 
175  if ( task == AliQAv1::kHITS ) {
176  AliDebug(AliQAv1::GetQADebugLevel(), "Processing Hits QA") ;
177  if (strcmp(data->ClassName(), "TClonesArray") == 0) {
178  fHitsArray = static_cast<TClonesArray *>(data) ;
179  MakeHits() ;
180  } else if (strcmp(data->ClassName(), "TTree") == 0) {
181  TTree * tree = static_cast<TTree *>(data) ;
182  MakeHits(tree) ;
183  } else {
184  AliWarning("data are neither a TClonesArray nor a TTree") ;
185  }
186  } else if ( task == AliQAv1::kSDIGITS ) {
187  AliDebug(AliQAv1::GetQADebugLevel(), "Processing SDigits QA") ;
188  if (strcmp(data->ClassName(), "TClonesArray") == 0) {
189  fSDigitsArray = static_cast<TClonesArray *>(data) ;
190  MakeSDigits() ;
191  } else if (strcmp(data->ClassName(), "TTree") == 0) {
192  TTree * tree = static_cast<TTree *>(data) ;
193  MakeSDigits(tree) ;
194  } else {
195  AliWarning("data are neither a TClonesArray nor a TTree") ;
196  }
197  } else if ( task == AliQAv1::kDIGITS ) {
198  AliDebug(AliQAv1::GetQADebugLevel(), "Processing Digits QA") ;
199  if (strcmp(data->ClassName(), "TClonesArray") == 0) {
200  fDigitsArray = static_cast<TClonesArray *>(data) ;
201  MakeDigits() ;
202  } else if (strcmp(data->ClassName(), "TTree") == 0) {
203  TTree * tree = static_cast<TTree *>(data) ;
204  MakeDigits(tree) ;
205  } else {
206  AliWarning("data are neither a TClonesArray nor a TTree") ;
207  }
208  }
209 }
210 
211 //____________________________________________________________________________
213 {
214  // general intialisation
215 
216  if (cycles > 0)
217  SetCycle(cycles) ;
218  TObjArray ** rv = NULL ;
219  if ( task == AliQAv1::kHITS ) {
220  if ( ! fHitsQAList ) {
222  for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
223  fHitsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
224  fHitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
225  }
226  }
227  rv = fHitsQAList ;
228  } else if ( task == AliQAv1::kSDIGITS ) {
229  if ( ! fSDigitsQAList ) {
231  for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
232  fSDigitsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
233  fSDigitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
234  }
235  }
236  rv = fSDigitsQAList ;
237  } else if ( task == AliQAv1::kDIGITS ) {
238  if ( ! fDigitsQAList ) {
240  for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
241  fDigitsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
242  fDigitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
243  }
244  }
245  rv = fDigitsQAList ;
246  }
247 
248  return rv ;
249 }
250 
251 //____________________________________________________________________________
252 void AliQADataMakerSim::Init(AliQAv1::TASKINDEX_t task, TObjArray ** list, Int_t run, Int_t cycles)
253 {
254  // Intialisation by passing the list of QA data booked elsewhere
255 
256  fRun = run ;
257  if (cycles > 0)
258  SetCycle(cycles) ;
259 
260  if ( task == AliQAv1::kHITS ) {
261  fHitsQAList = list ;
262  } else if ( task == AliQAv1::kSDIGITS) {
263  fSDigitsQAList = list ;
264  } else if ( task == AliQAv1::kDIGITS ) {
265  fDigitsQAList = list ;
266  }
267 }
268 
269 //____________________________________________________________________________
271 {
272  // default reset that resets all the QA objects.
273  // to be overloaded by detectors, if necessary
274 
275  TObjArray ** list = NULL ;
276  if ( task == AliQAv1::kHITS ) {
277  list = fHitsQAList ;
278  } else if ( task == AliQAv1::kSDIGITS ) {
279  list = fSDigitsQAList ;
280  } else if ( task == AliQAv1::kDIGITS ) {
281  list = fDigitsQAList ;
282  }
283  //list was not initialized, skip
284  if (!list)
285  return ;
286 
287  for (int spec = 0; spec < AliRecoParam::kNSpecies; spec++) {
288  if (!AliQAv1::Instance()->IsEventSpecieSet(AliRecoParam::ConvertIndex(spec)))
289  continue;
290  TIter next(list[spec]) ;
291  TH1 * histo = NULL ;
292  while ( (histo = dynamic_cast<TH1*> (next())) ) {
293  histo->Reset() ;
294  }
295  }
296 }
297 
298 //____________________________________________________________________________
300 {
301  // Finishes a cycle of QA for all tasks
302  Bool_t samecycle = kFALSE ;
303  StartOfCycle(AliQAv1::kHITS, run, samecycle) ;
304  samecycle = kTRUE ;
305  StartOfCycle(AliQAv1::kSDIGITS, run, samecycle) ;
306  StartOfCycle(AliQAv1::kDIGITS, run, samecycle) ;
307 }
308 
309 //____________________________________________________________________________
310 void AliQADataMakerSim::StartOfCycle(AliQAv1::TASKINDEX_t task, Int_t run, const Bool_t sameCycle)
311 {
312  // Finishes a cycle of QA data acquistion
313  if ( run > 0 )
314  fRun = run ;
315  if ( !sameCycle || fCurrentCycle == -1) {
316  ResetCycle() ;
317  if (fOutput)
318  fOutput->Close() ;
319  fOutput = AliQAv1::GetQADataFile(GetName(), fRun) ;
320  }
321 
322  AliDebug(AliQAv1::GetQADebugLevel(), Form(" Run %d Cycle %d task %s file %s",
323  fRun, fCurrentCycle, AliQAv1::GetTaskName(task).Data(), fOutput->GetName() )) ;
324 
325  //fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ;
326 // if (!fDetectorDir)
327 // fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ;
328 //
329 // TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ;
330 // if (!subDir)
331 // subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;
332 //
333 // for ( Int_t index = AliRecoParam::kDefault ; index < AliRecoParam::kNSpecies ; index++ ) {
334 // TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(index)) ;
335 // if (!eventSpecieDir)
336 // eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(index)) ;
337 // TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ;
338 // if (!expertDir)
339 // expertDir = eventSpecieDir->mkdir(AliQAv1::GetExpert()) ;
340 // }
342 }
343 
344 
345 //____________________________________________________________________________
347 {
348  // clone the histos of the array corresponding to task
349  switch (task)
350  {
351  case AliQAv1::kHITS : ClonePerTrigClassL(fHitsQAList, task); break;
354  default : AliError(Form("Task %s is invalid in this context", AliQAv1::GetTaskName(task).Data() )); break;
355  }
356  //
357 }
static UShort_t GetMaxQAObj()
Definition: AliQAv1.h:75
static const char * GetEventSpecieName(EventSpecie_t es)
static UInt_t GetExpertBit()
Definition: AliQAv1.h:54
const Char_t * GetDetectorDirName() const
virtual void ClonePerTrigClass(AliQAv1::TASKINDEX_t task)
#define TObjArray
virtual void Exec(AliQAv1::TASKINDEX_t task, TObject *data)
virtual void MakeDigits()
Bool_t WriteExpert()
TObjArray ** fSDigitsQAList
list of the hits QA data objects
AliQADataMakerSim & operator=(const AliQADataMakerSim &qadm)
TDirectory * fDetectorDir
output root file
void SetCycle(Int_t nevts)
TTree * tree
#define AliWarning(message)
Definition: AliLog.h:541
TObjArray ** fHitsQAList
list of the digits QA data objects
virtual void ResetDetector(AliQAv1::TASKINDEX_t task)
TClonesArray * fDigitsArray
event specie, see AliRecoParam
TObjArray ** fDigitsQAList
TString fDetectorDirName
directory for the given detector in the file
static DETECTORINDEX_t GetDetIndex(const char *name)
Definition: AliQAv1.cxx:348
virtual void ClonePerTrigClassL(TObjArray **list, AliQAv1::TASKINDEX_t task)
virtual void EndOfDetectorCycle(AliQAv1::TASKINDEX_t, TObjArray **)
static EventSpecie_t ConvertIndex(Int_t index)
virtual void EndOfCycle()
virtual void MakeHits()
static const TString GetExpert()
Definition: AliQAv1.h:53
static TFile * GetQADataFile(const char *name, Int_t run)
Definition: AliQAv1.cxx:374
AliQADataMakerSim(const char *name="", const char *title="")
TClonesArray * fHitsArray
list of the sdigits QA data objects
virtual TObjArray ** Init(AliQAv1::TASKINDEX_t task, Int_t cycles=-1)
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
TASKINDEX_t
Definition: AliQAv1.h:30
virtual void StartOfDetectorCycle()
virtual void MakeSDigits()
virtual void StartOfCycle(Int_t run=-1)
#define AliError(message)
Definition: AliLog.h:591
static Int_t GetQADebugLevel()
Definition: AliQAv1.h:72
TClonesArray * fSDigitsArray
array to hold the hits
static TString GetTaskName(UInt_t tsk)
Definition: AliQAv1.h:90
Int_t fCurrentCycle
detector directory name in the quality assurance data file
static AliQAv1 * Instance()
Definition: AliQAv1.cxx:585
Int_t fRun
list of QA data parameters