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