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