]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQADataMaker.cxx
c240b33b603190c48e37f778bc3f20328ec25c9b
[u/mrichter/AliRoot.git] / STEER / AliQADataMaker.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 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 <TSystem.h> 
28 #include <TFile.h>
29 #include <TList.h> 
30 #include <TTree.h>
31 #include <TClonesArray.h>
32
33 // --- Standard library ---
34
35 // --- AliRoot header files ---
36 #include "AliLog.h"
37 #include "AliQADataMaker.h"
38 #include "AliQAChecker.h"
39 #include "AliESDEvent.h"
40 #include "AliRawReader.h"
41
42 ClassImp(AliQADataMaker)
43              
44 //____________________________________________________________________________ 
45 AliQADataMaker::AliQADataMaker(const char * name, const char * title) : 
46   TNamed(name, title), 
47   fOutput(0x0),
48   fDetectorDir(0x0),
49   fDetectorDirName(""), 
50   fDigitsQAList(0x0), 
51   fESDsQAList(0x0), 
52   fHitsQAList(0x0),
53   fRawsQAList(0x0), 
54   fRecPointsQAList(0x0), 
55   fSDigitsQAList(0x0), 
56   fCurrentCycle(-1), 
57   fCycle(9999999), 
58   fCycleCounter(0), 
59   fRun(0)
60 {
61   // ctor
62   fDetectorDirName = GetName() ; 
63 }
64
65 //____________________________________________________________________________ 
66 AliQADataMaker::AliQADataMaker(const AliQADataMaker& qadm) :
67   TNamed(qadm.GetName(), qadm.GetTitle()),
68   fOutput(qadm.fOutput),
69   fDetectorDir(qadm.fDetectorDir),
70   fDetectorDirName(qadm.fDetectorDirName),
71   fDigitsQAList(qadm.fDigitsQAList),
72   fESDsQAList(qadm.fESDsQAList),
73   fHitsQAList(qadm.fHitsQAList),
74   fRawsQAList(qadm.fRecPointsQAList),
75   fRecPointsQAList(qadm.fRecPointsQAList),
76   fSDigitsQAList(qadm.fSDigitsQAList), 
77   fCurrentCycle(qadm.fCurrentCycle), 
78   fCycle(qadm.fCycle), 
79   fCycleCounter(qadm.fCycleCounter), 
80   fRun(qadm.fRun)
81 {
82   //copy ctor
83   fDetectorDirName = GetName() ; 
84 }
85
86 //__________________________________________________________________
87 AliQADataMaker& AliQADataMaker::operator = (const AliQADataMaker& qadm )
88 {
89   // Assignment operator.
90   this->~AliQADataMaker();
91   new(this) AliQADataMaker(qadm);
92   return *this;
93 }
94
95 //____________________________________________________________________________
96 void AliQADataMaker::EndOfCycle(AliQA::TASKINDEX task) 
97
98   // Finishes a cycle of QA data acquistion
99   
100  TList * list = 0x0 ; 
101   
102  switch (task) { 
103   
104   case AliQA::kRAWS:    
105         list = fRawsQAList ; 
106   break ; 
107
108   case AliQA::kHITS:
109         list = fHitsQAList ; 
110   break ; 
111
112   case AliQA::kSDIGITS:
113         list = fSDigitsQAList ; 
114   break ; 
115     
116   case AliQA::kDIGITS:
117         list = fDigitsQAList ; 
118   break ;  
119  
120    case AliQA::kRECPOINTS:
121         list = fRecPointsQAList ; 
122    break ;  
123
124    case AliQA::kTRACKSEGMENTS:
125    break ;  
126   
127    case AliQA::kRECPARTICLES:
128    break ;  
129     
130    case AliQA::kESDS:
131         list = fESDsQAList ; 
132    break ;  
133   }     
134   
135  EndOfDetectorCycle(task, list) ; 
136  TDirectory * subDir = fDetectorDir->GetDirectory(AliQA::GetTaskName(task)) ; 
137  subDir->cd() ; 
138  list->Write() ; 
139 }
140  
141 //____________________________________________________________________________
142 void AliQADataMaker::Exec(AliQA::TASKINDEX task, TObject * data) 
143
144   // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
145     
146         switch (task) { 
147   
148                 case AliQA::kRAWS:
149                 {
150                         AliDebug(1, "Processing Raws QA") ; 
151                         AliRawReader * rawReader = dynamic_cast<AliRawReader *>(data) ; 
152                         if (rawReader) 
153                                 MakeRaws(rawReader) ;
154                         else
155                         AliError("Wrong data type") ;     
156                         break ; 
157                 }
158                 case AliQA::kHITS:
159                 {  
160                         AliDebug(1, "Processing Hits QA") ; 
161                         TClonesArray * arr = dynamic_cast<TClonesArray *>(data) ; 
162                         if (arr) { 
163                                 MakeHits(arr) ;
164                         } else {
165                                 TTree * tree = dynamic_cast<TTree *>(data) ; 
166                                 if (tree) {
167                                         MakeHits(tree) ; 
168                                 } else {
169                                         AliWarning("data are neither a TClonesArray nor a TTree") ; 
170                                 }
171                         }
172                         break ; 
173                 }
174                 case AliQA::kSDIGITS:
175                 {
176                         AliDebug(1, "Processing SDigits QA") ; 
177                         TClonesArray * arr = dynamic_cast<TClonesArray *>(data) ; 
178                         if (arr) { 
179                                 MakeSDigits(arr) ;
180                         } else {
181                                 TTree * tree = dynamic_cast<TTree *>(data) ; 
182                                 if (tree) {
183                                         MakeSDigits(tree) ; 
184                                 } else {
185                                         AliWarning("data are neither a TClonesArray nor a TTree") ; 
186                                 }
187                         }
188                         break ; 
189                 }  
190                 case AliQA::kDIGITS:
191                 {
192                         AliDebug(1, "Processing Digits QA") ; 
193                         TClonesArray * arr = dynamic_cast<TClonesArray *>(data) ; 
194                         if (arr) { 
195                                 MakeDigits(arr) ;
196                         } else {
197                                 TTree * tree = dynamic_cast<TTree *>(data) ; 
198                                 if (tree) {
199                                         MakeDigits(tree) ; 
200                                 } else {
201                                         AliWarning("data are neither a TClonesArray nor a TTree") ; 
202                                 }
203                         }
204                         break ;  
205                 }
206                 case AliQA::kRECPOINTS:
207                 {
208                         AliDebug(1, "Processing RecPoints QA") ; 
209                         TTree * tree = dynamic_cast<TTree *>(data) ; 
210                         if (tree) {
211                                 MakeRecPoints(tree) ; 
212                         } else {
213                                 AliWarning("data are not a TTree") ; 
214                         }
215                         break ;  
216                 }
217                 case AliQA::kTRACKSEGMENTS:
218                         AliInfo("Processing Track Segments QA: not existing anymore") ; 
219                 //       MakeTrackSegments(ts) ;
220                 break ;  
221   
222                 case AliQA::kRECPARTICLES:
223                         AliInfo("Processing RecParticles QA: not existing anymore") ; 
224                         //       MakeRecParticles(recpar) ;
225                 break ;  
226                 case AliQA::kESDS:
227                 {
228                         AliDebug(1, "Processing ESDs QA") ; 
229                         AliESDEvent * esd = dynamic_cast<AliESDEvent *>(data) ; 
230                         if (esd) 
231                                 MakeESDs(esd) ;
232                         else 
233                                 AliError("Wrong type of esd container") ; 
234                         break ;
235                 }  
236         }         
237 }
238
239 //____________________________________________________________________________ 
240 void AliQADataMaker::Finish() const 
241
242   // write to the output File
243   fOutput->Close() ; 
244
245
246 //____________________________________________________________________________ 
247 TList *  AliQADataMaker::Init(AliQA::TASKINDEX task, Int_t run, Int_t cycles)
248 {
249   // general intialisation
250   
251   fRun = run ;
252   if (cycles > 0)
253     SetCycle(cycles) ;  
254         
255   switch (task) {
256   case AliQA::kRAWS: 
257    {
258         fRawsQAList = new TList() ;      
259     InitRaws() ;
260         return fRawsQAList ;
261     break ; 
262    }
263   case AliQA::kHITS: 
264    {
265         fHitsQAList = new TList() ;      
266     InitHits() ;
267         return fHitsQAList ;
268     break ; 
269    }
270   case AliQA::kSDIGITS: 
271    {
272         fSDigitsQAList = new TList() ; 
273     InitSDigits() ;
274         return fSDigitsQAList ;
275     break ; 
276    }
277   case AliQA::kDIGITS: 
278    {
279         fDigitsQAList = new TList(); 
280         InitDigits() ;
281         return fDigitsQAList ;
282         break ; 
283    }      
284   case AliQA::kRECPOINTS: 
285    {
286         fRecPointsQAList = new TList() ; 
287     InitRecPoints() ;
288         return fRecPointsQAList ;
289     break ; 
290   }
291   case AliQA::kTRACKSEGMENTS: 
292 //  InitTrackSegments() ;
293     break ; 
294     
295   case AliQA::kRECPARTICLES: 
296 //    InitRecParticles() ;
297     break ; 
298     
299   case AliQA::kESDS: 
300    {
301         fESDsQAList = new TList() ; 
302         InitESDs() ;
303         return fRecPointsQAList ;
304     break ; 
305    }
306   }  
307   return 0x0 ; 
308 }
309
310 //____________________________________________________________________________ 
311 void AliQADataMaker::Init(AliQA::TASKINDEX task, TList * list, Int_t run, Int_t cycles)
312 {
313   // Intialisation by passing the list of QA data booked elsewhere
314   
315   fRun = run ;
316   if (cycles > 0)
317     SetCycle(cycles) ;  
318         
319   switch (task) {
320   case AliQA::kRAWS: 
321    {
322         fRawsQAList = list ;     
323     break ; 
324    }
325   case AliQA::kHITS: 
326    {
327         fHitsQAList = list ;     
328     break ; 
329    }
330   case AliQA::kSDIGITS: 
331    {
332         fSDigitsQAList = list ; 
333     break ; 
334    }
335   case AliQA::kDIGITS: 
336    {
337         fDigitsQAList = list ; 
338         break ; 
339    }      
340   case AliQA::kRECPOINTS: 
341    {
342         fRecPointsQAList = list ; 
343     break ; 
344   }
345   case AliQA::kTRACKSEGMENTS: 
346     break ; 
347     
348   case AliQA::kRECPARTICLES: 
349     break ; 
350     
351   case AliQA::kESDS: 
352    {
353         fESDsQAList = list ; 
354     break ; 
355    }
356   }  
357 }
358
359 //____________________________________________________________________________
360 void AliQADataMaker::Reset() 
361
362   // Resets defaut value of data members 
363   fCurrentCycle = -1 ;  
364   fCycleCounter = 0 ; 
365 }
366
367 //____________________________________________________________________________
368 void AliQADataMaker::StartOfCycle(AliQA::TASKINDEX task, const Bool_t sameCycle) 
369
370   // Finishes a cycle of QA data acquistion
371  
372  if ( !sameCycle ) {
373         ResetCycle() ;
374         if (fOutput) 
375                 fOutput->Close() ; 
376         fOutput = AliQA::GetQADMOutFile(GetName(), fRun, fCurrentCycle) ;       
377  }      
378  AliInfo(Form(" Run %d Cycle %d task %s file %s", 
379         fRun, fCurrentCycle, AliQA::GetTaskName(task).Data(), fOutput->GetName() )) ;
380
381  fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ; 
382  if (!fDetectorDir)
383    fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ; 
384
385  TDirectory * subDir = fDetectorDir->GetDirectory(AliQA::GetTaskName(task)) ; 
386  if (!subDir)
387    subDir = fDetectorDir->mkdir(AliQA::GetTaskName(task)) ;  
388  subDir->cd() ; 
389
390   TList * list = 0x0 ; 
391   
392   switch (task) { 
393   case AliQA::kRAWS: 
394         list = fRawsQAList ; 
395     break ; 
396
397   case AliQA::kHITS: 
398         list = fHitsQAList ; 
399     break ; 
400   
401   case AliQA::kSDIGITS: 
402         list = fSDigitsQAList ;
403     break ; 
404
405   case AliQA::kDIGITS: 
406         list = fDigitsQAList ;
407         break ; 
408           
409   case AliQA::kRECPOINTS: 
410         list = fRecPointsQAList ;
411         break ; 
412
413   case AliQA::kTRACKSEGMENTS: 
414     break ; 
415     
416   case AliQA::kRECPARTICLES: 
417     break ; 
418     
419   case AliQA::kESDS: 
420         list = fESDsQAList ;
421     break ; 
422   }  
423
424  TIter next(list) ;
425  TH1 * h ; 
426  while ( (h = dynamic_cast<TH1 *>(next())) )
427     h->Reset() ;  
428
429  StartOfDetectorCycle() ; 
430
431 }