]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQADataMakerRec.cxx
upgraded the version number
[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
31 // --- Standard library ---
32
33 // --- AliRoot header files ---
34 #include "AliLog.h"
35 #include "AliQADataMakerRec.h"
36 #include "AliESDEvent.h"
37 #include "AliRawReader.h"
38
39 ClassImp(AliQADataMakerRec)
40              
41 //____________________________________________________________________________ 
42 AliQADataMakerRec::AliQADataMakerRec(const char * name, const char * title) : 
43   AliQADataMaker(name, title), 
44   fESDsQAList(NULL), 
45   fRawsQAList(NULL), 
46   fRecPointsQAList(NULL),
47   fCorrNt(NULL), 
48   fRecoParam(NULL) 
49 {
50   // ctor
51         fDetectorDirName = GetName() ; 
52 }
53
54 //____________________________________________________________________________ 
55 AliQADataMakerRec::AliQADataMakerRec(const AliQADataMakerRec& qadm) :
56   AliQADataMaker(qadm.GetName(), qadm.GetTitle()), 
57   fESDsQAList(qadm.fESDsQAList),
58   fRawsQAList(qadm.fRawsQAList),
59   fRecPointsQAList(qadm.fRecPointsQAList),
60   fCorrNt(qadm.fCorrNt),  
61   fRecoParam(qadm.fRecoParam) 
62 {
63   //copy ctor
64         SetName(qadm.GetName()) ; 
65         SetTitle(qadm.GetTitle()) ; 
66         fDetectorDirName = GetName() ; 
67 }
68
69 //____________________________________________________________________________ 
70 AliQADataMakerRec::~AliQADataMakerRec()
71 {
72         //dtor: delete the TObjArray and thei content
73         if ( fESDsQAList ) {
74     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
75       if ( fESDsQAList[specie] ) {
76         if ( fESDsQAList[specie]->IsOwner() ) 
77           fESDsQAList[specie]->Delete() ;     
78       }
79     }
80     delete[] fESDsQAList ;
81         }
82         if ( fRawsQAList ) {
83     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
84       if ( fRawsQAList[specie] ) {
85         if ( fRawsQAList[specie]->IsOwner() ) 
86           fRawsQAList[specie]->Delete() ;
87       }
88     }
89     delete[] fRawsQAList ;
90   }
91         if ( fRecPointsQAList ) {
92     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
93       if ( fRecPointsQAList[specie] ) {
94         if ( fRecPointsQAList[specie]->IsOwner() ) 
95           fRecPointsQAList[specie]->Delete() ;
96       }
97     }
98                 delete[] fRecPointsQAList ; 
99         }
100 }
101
102 //__________________________________________________________________
103 AliQADataMakerRec& AliQADataMakerRec::operator = (const AliQADataMakerRec& qadm )
104 {
105   // Assignment operator.
106   this->~AliQADataMakerRec();
107   new(this) AliQADataMakerRec(qadm);
108   return *this;
109 }
110
111 //____________________________________________________________________________
112 void AliQADataMakerRec::EndOfCycle() 
113 {
114   // Finishes a cycle of QA for all the tasks
115   EndOfCycle(AliQA::kRAWS) ; 
116   EndOfCycle(AliQA::kRECPOINTS) ; 
117   EndOfCycle(AliQA::kESDS) ; 
118   ResetCycle() ; 
119 }
120
121 //____________________________________________________________________________
122 void AliQADataMakerRec::EndOfCycle(AliQA::TASKINDEX_t task) 
123 {
124         // Finishes a cycle of QA 
125         
126         TObjArray ** list = NULL ; 
127         
128         if ( task == AliQA::kRAWS )     
129                 list = fRawsQAList ; 
130         else if ( task == AliQA::kRECPOINTS ) 
131                 list = fRecPointsQAList ; 
132         else if ( task == AliQA::kESDS )
133                 list = fESDsQAList ; 
134
135  
136         if ( ! list && ! fCorrNt ) 
137     return ; 
138   //DefaultEndOfDetectorCycle(task) ;
139         EndOfDetectorCycle(task, list) ;
140         TDirectory * subDir = NULL ;
141         if (fDetectorDir) 
142                 subDir = fDetectorDir->GetDirectory(AliQA::GetTaskName(task)) ; 
143         if ( subDir ) {
144                 subDir->cd() ; 
145     for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
146       TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
147       if (eventSpecieDir) {
148         eventSpecieDir->cd() ;    
149         if (list[specie]) {
150           TIter next(list[specie]) ; 
151           TObject * obj ; 
152           while( (obj = next()) ) {
153             if (!obj->TestBit(AliQA::GetExpertBit()))
154               obj->Write() ;
155           }
156           if (WriteExpert()) {
157             TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQA::GetExpert()) ; 
158             if ( expertDir ) { // Write only if requested
159               expertDir->cd() ;
160               next.Reset() ; 
161               while( (obj = next()) ) {
162                 if (!obj->TestBit(AliQA::GetExpertBit()))
163                   continue ; 
164                 obj->Write() ;
165               }      
166             }
167           }
168         }
169         if ( !fCorrNt )
170           continue ; 
171         if (fCorrNt[specie] && AliQA::GetDetIndex(GetName()) == AliQA::kCORR) {
172           eventSpecieDir->cd() ; 
173           fCorrNt[specie]->Write() ; 
174         }
175       }
176     }
177     fOutput->Save() ; 
178         }
179 }
180  
181 //____________________________________________________________________________
182 void AliQADataMakerRec::Exec(AliQA::TASKINDEX_t task, TObject * data) 
183
184   // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
185         
186         if ( task == AliQA::kRAWS ) {
187                 AliDebug(1, "Processing Raws QA") ; 
188                 AliRawReader * rawReader = dynamic_cast<AliRawReader *>(data) ; 
189                 if (rawReader) 
190                         MakeRaws(rawReader) ;
191                 else
192                 AliInfo("Raw data are not processed") ;     
193         } else if ( task == AliQA::kRECPOINTS ) {
194                 AliDebug(1, "Processing RecPoints QA") ; 
195                 TTree * tree = dynamic_cast<TTree *>(data) ; 
196                 if (tree) {
197                         MakeRecPoints(tree) ; 
198                 } else {
199                         AliWarning("data are not a TTree") ; 
200                 }
201         } else if ( task == AliQA::kESDS ) {
202                 AliDebug(1, "Processing ESDs QA") ; 
203                 AliESDEvent * esd = dynamic_cast<AliESDEvent *>(data) ; 
204                 if (esd) 
205                         MakeESDs(esd) ;
206                 else 
207                         AliError("Wrong type of esd container") ; 
208         }  
209 }
210
211 //____________________________________________________________________________ 
212 TObjArray **  AliQADataMakerRec::Init(AliQA::TASKINDEX_t task, Int_t cycles)
213 {
214   // general intialisation
215
216         TObjArray ** rv = NULL ; 
217   
218         if (cycles > 0)
219                 SetCycle(cycles) ;  
220         
221         if ( task == AliQA::kRAWS ) {
222                 if (! fRawsQAList ) { 
223       fRawsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
224       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
225         fRawsQAList[specie] = new TObjArray(100) ;       
226         fRawsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQA::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
227       }
228                         InitRaws() ;
229                 }
230                 rv = fRawsQAList ;
231         } else if ( task == AliQA::kRECPOINTS ) {
232                 if ( ! fRecPointsQAList ) {
233       fRecPointsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
234       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
235         fRecPointsQAList[specie] = new TObjArray(100) ; 
236         fRecPointsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQA::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
237       }
238       InitRecPoints() ;
239                 }
240                 rv = fRecPointsQAList ;
241         } else if ( task == AliQA::kESDS ) {
242                 if ( ! fESDsQAList ) {
243       fESDsQAList = new TObjArray *[AliRecoParam::kNSpecies] ; 
244       for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
245         fESDsQAList[specie] = new TObjArray(100) ;
246         fESDsQAList[specie]->SetName(Form("%s_%s", GetName(), AliQA::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ; 
247       }
248                         InitESDs() ;
249                 }
250                 rv = fESDsQAList ;
251         }
252         return rv ; 
253 }
254
255 //____________________________________________________________________________ 
256 void AliQADataMakerRec::Init(AliQA::TASKINDEX_t task, TObjArray ** list, Int_t run, Int_t cycles)
257 {
258   // Intialisation by passing the list of QA data booked elsewhere
259   
260         fRun = run ;
261         if (cycles > 0)
262                 SetCycle(cycles) ;  
263         
264         if ( task == AliQA::kRAWS ) {
265                 fRawsQAList = list ;     
266         } else if ( task == AliQA::kRECPOINTS ) {
267                 fRecPointsQAList = list ; 
268         } else if ( task == AliQA::kESDS ) {
269                 fESDsQAList = list ; 
270         }
271 }
272
273 //____________________________________________________________________________
274 void AliQADataMakerRec::StartOfCycle(Int_t run) 
275 {
276   // Finishes a cycle of QA for all the tasks
277   Bool_t samecycle = kFALSE ; 
278   StartOfCycle(AliQA::kRAWS,      run, samecycle) ;
279   samecycle = kTRUE ; 
280   StartOfCycle(AliQA::kRECPOINTS, run, samecycle) ; 
281   StartOfCycle(AliQA::kESDS,      run, samecycle) ; 
282 }
283
284 //____________________________________________________________________________
285 void AliQADataMakerRec::StartOfCycle(AliQA::TASKINDEX_t task, Int_t run, const Bool_t sameCycle) 
286
287   // Finishes a cycle of QA data acquistion
288   if ( run > 0 ) 
289     fRun = run ; 
290         if ( !sameCycle || fCurrentCycle == -1) {
291                 ResetCycle() ;
292                 if (fOutput) 
293                         fOutput->Close() ; 
294                 fOutput = AliQA::GetQADataFile(GetName(), fRun) ;       
295         }       
296         AliInfo(Form(" Run %d Cycle %d task %s file %s", 
297                                  fRun, fCurrentCycle, AliQA::GetTaskName(task).Data(), fOutput->GetName() )) ;
298
299         fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ; 
300         if (!fDetectorDir)
301                 fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ; 
302
303         TDirectory * subDir = fDetectorDir->GetDirectory(AliQA::GetTaskName(task)) ; 
304         if (!subDir)
305                 subDir = fDetectorDir->mkdir(AliQA::GetTaskName(task)) ;  
306   
307   for ( Int_t specie = AliRecoParam::kDefault ; specie < AliRecoParam::kNSpecies ; specie++ ) {
308     TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ; 
309     if (!eventSpecieDir) 
310       eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ; 
311     TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQA::GetExpert()) ; 
312     if (!expertDir)
313       expertDir = eventSpecieDir->mkdir(AliQA::GetExpert()) ; 
314   } 
315         StartOfDetectorCycle() ; 
316 }