]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/STEER/AliQADataMakerRec.cxx
Memory leak fixed.
[u/mrichter/AliRoot.git] / STEER / STEER / AliQADataMakerRec.cxx
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 notifce   *
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 for Reconstruction
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 <TNtupleD.h>
30 #include <TObjArray.h>
31
32 // --- Standard library ---
33
34 // --- AliRoot header files ---
35 #include "AliCDBPath.h"
36 #include "AliCDBEntry.h"
37 #include "AliDetectorRecoParam.h"
38 #include "AliCDBManager.h"
39
40 #include "AliLog.h"
41 #include "AliQADataMakerRec.h"
42 #include "AliQAManager.h"
43 #include "AliESDEvent.h"
44 #include "AliRawReader.h"
45
46 ClassImp(AliQADataMakerRec)
47              
48 //____________________________________________________________________________ 
49 AliQADataMakerRec::AliQADataMakerRec(const char * name, const char * title) : 
50 AliQADataMaker(name, title), 
51   fDigitsQAList(NULL),
52   fESDsQAList(NULL), 
53   fRawsQAList(NULL), 
54   fRecPointsQAList(NULL),
55   fCorrNt(NULL), 
56   fRecoParam(NULL),
57   fRecPointsArray(NULL)
58 {
59   // ctor
60   fDetectorDirName = GetName() ; 
61 }
62
63 //____________________________________________________________________________ 
64 AliQADataMakerRec::AliQADataMakerRec(const AliQADataMakerRec& qadm) :
65   AliQADataMaker(qadm.GetName(), qadm.GetTitle()), 
66   fDigitsQAList(qadm.fDigitsQAList),
67   fESDsQAList(qadm.fESDsQAList),
68   fRawsQAList(qadm.fRawsQAList),
69   fRecPointsQAList(qadm.fRecPointsQAList),
70   fCorrNt(qadm.fCorrNt),  
71   fRecoParam(qadm.fRecoParam),
72   fRecPointsArray(NULL)
73 {
74   //copy ctor
75   SetName(qadm.GetName()) ; 
76   SetTitle(qadm.GetTitle()) ; 
77   fDetectorDirName = GetName() ; 
78 }
79
80 //____________________________________________________________________________ 
81 AliQADataMakerRec::~AliQADataMakerRec()
82 {
83   //dtor: delete the TObjArray and thei content
84   if ( fESDsQAList ) {
85     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
86       if ( fESDsQAList[specie] ) {
87         fESDsQAList[specie]->Delete() ;     
88       }
89     }
90     delete[] fESDsQAList ;
91   }
92   if ( fRawsQAList ) {
93     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
94       if ( fRawsQAList[specie] ) {
95         fRawsQAList[specie]->Delete() ;
96       }
97     }
98     delete[] fRawsQAList ;
99   }
100   if ( fDigitsQAList ) {
101     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
102       if ( fDigitsQAList[specie] ) {
103         fDigitsQAList[specie]->Delete() ;
104       }
105     }
106     delete[] fDigitsQAList ; 
107   }
108   if ( fRecPointsQAList ) {
109     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
110       if ( fRecPointsQAList[specie] ) {
111         fRecPointsQAList[specie]->Delete() ;
112       }
113     }
114     delete[] fRecPointsQAList ; 
115   }
116   if (fRecPointsArray) {
117     fRecPointsArray->Clear() ; 
118     delete fRecPointsArray ; 
119   }
120 }
121
122 //__________________________________________________________________
123 AliQADataMakerRec& AliQADataMakerRec::operator = (const AliQADataMakerRec& qadm )
124 {
125   // Assignment operator.
126   this->~AliQADataMakerRec();
127   new(this) AliQADataMakerRec(qadm);
128   return *this;
129 }
130
131 //____________________________________________________________________________
132 void AliQADataMakerRec::EndOfCycle() 
133 {
134   // Finishes a cycle of QA for all the tasks
135   EndOfCycle(AliQAv1::kRAWS) ; 
136   EndOfCycle(AliQAv1::kDIGITSR) ; 
137   EndOfCycle(AliQAv1::kRECPOINTS) ; 
138   EndOfCycle(AliQAv1::kESDS) ; 
139   ResetCycle() ; 
140 }
141
142 //____________________________________________________________________________
143 void AliQADataMakerRec::EndOfCycle(AliQAv1::TASKINDEX_t task) 
144 {
145   // Finishes a cycle of QA 
146         
147     
148   TObjArray ** list = NULL ; 
149         
150   if ( task == AliQAv1::kRAWS )     
151     list = fRawsQAList ; 
152   else if ( task == AliQAv1::kDIGITSR ) 
153     list = fDigitsQAList ; 
154   else if ( task == AliQAv1::kRECPOINTS ) 
155     list = fRecPointsQAList ; 
156   else if ( task == AliQAv1::kESDS )
157     list = fESDsQAList ; 
158
159  
160   if ( ! list && ! fCorrNt ) 
161     return ; 
162   //DefaultEndOfDetectorCycle(task) ;
163   EndOfDetectorCycle(task, list) ;
164   
165   if (! AliQAManager::QAManager(AliQAv1::kRECMODE)->IsSaveData()) return; 
166
167   fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ; 
168   if (!fDetectorDir) fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ; 
169   TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ; 
170   if (!subDir) subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;  
171   subDir->cd();
172   // 
173   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) { // skip Default
174     if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(specie)) || AliRecoParam::ConvertIndex(specie) == AliRecoParam::kDefault) continue ; 
175     TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
176     if (!eventSpecieDir) eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ; 
177     eventSpecieDir->cd();    
178     if (list) {
179       if (list[specie]) {
180         TIter next(list[specie]) ; 
181         TObject * obj ; 
182         while( (obj = next()) ) {
183           if (!obj->TestBit(AliQAv1::GetExpertBit())) obj->Write(); // RS: Note, this can be also TObjArray of clones
184         }
185         if (WriteExpert()) {
186           TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ; 
187           if (!expertDir)
188             expertDir = eventSpecieDir->mkdir(AliQAv1::GetExpert()) ; 
189           expertDir->cd() ;
190           next.Reset() ; 
191           while( (obj = next()) ) {
192             if (!obj->TestBit(AliQAv1::GetExpertBit())) continue; 
193             obj->Write();  // RS: Note, this can be also TObjArray of clones
194           }      
195         }
196       }
197     } 
198     else if ( fCorrNt ) {
199       if (fCorrNt[specie] && AliQAv1::GetDetIndex(GetName()) == AliQAv1::kCORR) {
200         if (fCorrNt[specie]->GetNvar() != 0) {
201           eventSpecieDir->cd() ; 
202           fCorrNt[specie]->Write() ; 
203         }
204       }
205       fOutput->Save() ; 
206     }
207   }
208 }
209
210 //____________________________________________________________________________
211 void AliQADataMakerRec::Exec(AliQAv1::TASKINDEX_t task, TObject * data) 
212
213   // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
214         
215   if ( task == AliQAv1::kRAWS ) {
216     AliDebug(AliQAv1::GetQADebugLevel(), "Processing Raws QA") ; 
217     AliRawReader * rawReader = static_cast<AliRawReader *>(data) ; 
218     if (rawReader) 
219       MakeRaws(rawReader) ;
220     else
221       AliDebug(AliQAv1::GetQADebugLevel(), "Raw data are not processed") ;     
222   } else if ( task == AliQAv1::kDIGITSR ) {
223     AliDebug(AliQAv1::GetQADebugLevel(), "Processing Digits QA") ; 
224     TTree * tree = static_cast<TTree *>(data) ; 
225     if (strcmp(tree->ClassName(), "TTree") == 0) {
226       MakeDigits(tree) ; 
227     } else {
228       AliWarning("data are not a TTree") ; 
229     }
230   } else if ( task == AliQAv1::kRECPOINTS ) {
231     AliDebug(AliQAv1::GetQADebugLevel(), "Processing RecPoints QA") ; 
232     TTree * tree = static_cast<TTree *>(data) ; 
233     if (strcmp(tree->ClassName(), "TTree") == 0) {
234       MakeRecPoints(tree) ; 
235     } else {
236       AliWarning("data are not a TTree") ; 
237     }
238   } else if ( task == AliQAv1::kESDS ) {
239     AliDebug(AliQAv1::GetQADebugLevel(), "Processing ESDs QA") ; 
240     AliESDEvent * esd = static_cast<AliESDEvent *>(data) ; 
241     if (strcmp(esd->ClassName(), "AliESDEvent") == 0) 
242       MakeESDs(esd) ;
243     else 
244       AliError("Wrong type of esd container") ; 
245   }  
246 }
247
248 //____________________________________________________________________________ 
249 TObjArray **  AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, Int_t cycles)
250 {
251   // general intialisation
252   InitRecoParams() ;
253   TObjArray ** rv = NULL ; 
254   
255   if (cycles > 0)
256     SetCycle(cycles) ;  
257         
258   if ( task == AliQAv1::kRAWS ) {
259     if (! fRawsQAList ) { 
260       fRawsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
261       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
262         fRawsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;    
263         fRawsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
264       }
265     }
266     rv = fRawsQAList ;
267   } else if ( task == AliQAv1::kDIGITSR ) {
268     if ( ! fDigitsQAList ) {
269       fDigitsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
270       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
271         fDigitsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ; 
272         fDigitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
273       }
274     }
275     rv = fDigitsQAList ;
276   } else if ( task == AliQAv1::kRECPOINTS ) {
277     if ( ! fRecPointsQAList ) {
278       fRecPointsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
279       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
280         fRecPointsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ; 
281         fRecPointsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
282       }
283     }
284     rv = fRecPointsQAList ;
285   } else if ( task == AliQAv1::kESDS ) {
286     if ( ! fESDsQAList ) {
287       fESDsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
288       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
289         fESDsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
290         fESDsQAList[specie]->SetName(Form("%s_%s", GetName(), AliQAv1::GetTaskName(task).Data())); //, AliRecoParam::GetEventSpecieName(specie))) ; 
291       }
292     }
293     rv = fESDsQAList ;
294   }
295   return rv ; 
296 }
297
298 //____________________________________________________________________________ 
299 void AliQADataMakerRec::Init(AliQAv1::TASKINDEX_t task, TObjArray ** list, Int_t run, Int_t cycles)
300 {
301   // Intialisation by passing the list of QA data booked elsewhere
302   
303   InitRecoParams() ;
304   fRun = run ;
305   if (cycles > 0)
306     SetCycle(cycles) ;  
307         
308   if ( task == AliQAv1::kRAWS ) {
309     fRawsQAList = list ;         
310   } else if ( task == AliQAv1::kDIGITSR ) {
311     fDigitsQAList = list ; 
312   } else if ( task == AliQAv1::kRECPOINTS ) {
313     fRecPointsQAList = list ; 
314   } else if ( task == AliQAv1::kESDS ) {
315     fESDsQAList = list ; 
316   }
317 }
318
319 //____________________________________________________________________________
320 void AliQADataMakerRec::InitRecoParams() 
321 {
322   // Get the recoparam form the OCDB 
323   if (!fRecoParam) {
324     AliDebug(AliQAv1::GetQADebugLevel(), Form("Loading reconstruction parameter objects for detector %s", GetName()));
325     AliCDBPath path(GetName(),"Calib","RecoParam");
326     AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath());    
327     if(!entry) {
328       fRecoParam = NULL ; 
329       AliDebug(AliQAv1::GetQADebugLevel(), Form("Couldn't find RecoParam entry in OCDB for detector %s",GetName()));
330     }
331     else {
332       //      entry->SetOwner(kTRUE);
333       TObject * recoParamObj = entry->GetObject() ; 
334       if ( strcmp(recoParamObj->ClassName(), "TObjArray") == 0 ) {
335         // The detector has only one set of reco parameters
336         AliDebug(AliQAv1::GetQADebugLevel(), Form("Array of reconstruction parameters found for detector %s",GetName()));
337         TObjArray *recoParamArray = static_cast<TObjArray*>(recoParamObj) ;
338         //        recoParamArray->SetOwner(kTRUE);
339         for (Int_t iRP=0; iRP<recoParamArray->GetEntriesFast(); iRP++) {
340           fRecoParam = static_cast<AliDetectorRecoParam*>(recoParamArray->At(iRP)) ;
341           if (!fRecoParam) 
342             break ; 
343           else if (fRecoParam->IsDefault()) 
344             break ; 
345         }
346       }
347       else if (recoParamObj->InheritsFrom("AliDetectorRecoParam")) {
348         // The detector has only one set of reco parameters
349         // Registering it in AliRecoParam
350         AliDebug(AliQAv1::GetQADebugLevel(), Form("Single set of reconstruction parameters found for detector %s",GetName()));
351         fRecoParam = static_cast<AliDetectorRecoParam*>(recoParamObj) ;
352         static_cast<AliDetectorRecoParam*>(recoParamObj)->SetAsDefault();
353       } else { 
354         AliError(Form("No valid RecoParam object found in the OCDB for detector %s",GetName()));
355       }
356     }
357   }
358 }
359
360 //____________________________________________________________________________ 
361 void AliQADataMakerRec::ResetDetector(AliQAv1::TASKINDEX_t task)
362 {
363   // default reset that resets all the QA objects.
364   // to be overloaded by detectors, if necessary
365
366   TObjArray ** list = NULL ; 
367   if ( task == AliQAv1::kRAWS ) {
368     list = fRawsQAList ;         
369   } else if ( task == AliQAv1::kDIGITSR ) {
370     list = fDigitsQAList ; 
371   } else if ( task == AliQAv1::kRECPOINTS ) {
372     list = fRecPointsQAList ; 
373   } else if ( task == AliQAv1::kESDS ) {
374     list = fESDsQAList ; 
375   }
376   //list was not initialized, skip
377   if (!list) return ; 
378   
379   for (int spec = 0; spec < AliRecoParam::kNSpecies; spec++) {
380     if (!AliQAv1::Instance()->IsEventSpecieSet(AliRecoParam::ConvertIndex(spec))) continue;
381     TIter next(list[spec]) ; 
382     TObject *obj = NULL; 
383     while ( (obj = next()) ) {
384       if (obj->TestBit(AliQAv1::GetClonedBit())) { // this is array of cloned histos
385         TObjArray* arr = (TObjArray*)obj;
386         for (int ih=arr->GetEntriesFast();ih--;) {
387           TH1* histo = (TH1*)arr->At(ih); 
388           if (!ih) continue;
389           histo->Reset("ICE");
390           histo->ResetStats();
391         }
392       }
393       else {
394         ((TH1*)obj)->Reset("ICE");
395         ((TH1*)obj)->ResetStats();
396       }
397     }
398     ResetEvCountCycle(AliRecoParam::ConvertIndex(spec));
399     ResetEvCountTotal(AliRecoParam::ConvertIndex(spec));
400   }
401 }
402
403 //____________________________________________________________________________
404 void AliQADataMakerRec::StartOfCycle(Int_t run) 
405 {
406   // Finishes a cycle of QA for all the tasks
407   Bool_t samecycle = kFALSE ; 
408   StartOfCycle(AliQAv1::kRAWS,      run, samecycle) ;
409   samecycle = kTRUE ; 
410   StartOfCycle(AliQAv1::kDIGITSR,   run, samecycle) ; 
411   StartOfCycle(AliQAv1::kRECPOINTS, run, samecycle) ; 
412   StartOfCycle(AliQAv1::kESDS,      run, samecycle) ;
413 }
414
415 //____________________________________________________________________________
416 void AliQADataMakerRec::StartOfCycle(AliQAv1::TASKINDEX_t task, Int_t run, const Bool_t sameCycle) 
417
418   // Finishes a cycle of QA data acquistion
419   if ( run > 0 ) fRun = run ; 
420   if ( !sameCycle || fCurrentCycle == -1) {
421     ResetCycle() ;
422     if (fOutput) 
423       fOutput->Close() ; 
424     if (AliQAManager::QAManager(AliQAv1::kRECMODE)->IsSaveData())
425       fOutput = AliQAv1::GetQADataFile(GetName(), fRun) ;       
426   }     
427   AliDebug(AliQAv1::GetQADebugLevel(), Form(" Run %d Cycle %d task %s file %s", 
428                                             fRun, fCurrentCycle, AliQAv1::GetTaskName(task).Data(), fOutput->GetName() )) ;
429
430   //    fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ; 
431   //    if (!fDetectorDir)
432   //            fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ; 
433   //  
434   //    TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ; 
435   //    if (!subDir)
436   //            subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;  
437   //  
438   //  for ( Int_t specie = AliRecoParam::kDefault ; specie < AliRecoParam::kNSpecies ; specie++ ) {
439   //    TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ; 
440   //    if (!eventSpecieDir) 
441   //      eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ; 
442   //    TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ; 
443   //    if (!expertDir)
444   //      expertDir = eventSpecieDir->mkdir(AliQAv1::GetExpert()) ; 
445   //  } 
446   StartOfDetectorCycle();
447   ResetEvCountCycle();
448 }
449
450 //____________________________________________________________________________
451 void AliQADataMakerRec::ClonePerTrigClass(AliQAv1::TASKINDEX_t task)
452 {
453   // clone the histos of the array corresponding to task
454   switch (task) 
455     {
456     case AliQAv1::kRAWS      : ClonePerTrigClassL(fRawsQAList, task);      break;
457     case AliQAv1::kDIGITS    : ClonePerTrigClassL(fDigitsQAList, task);    break;
458     case AliQAv1::kRECPOINTS : ClonePerTrigClassL(fRecPointsQAList, task); break;
459     case AliQAv1::kESDS      : ClonePerTrigClassL(fESDsQAList, task);      break;
460     default : AliError(Form("Task %s is invalid in this context", AliQAv1::GetTaskName(task).Data() )); break;
461     }
462   //
463 }