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