]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQADataMakerSim.cxx
eaf35619eacbdbc8d3a1f2f5535d31238c4b8a10
[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     if (WriteExpert()) {
131       TDirectory * expertDir = subDir->GetDirectory(AliQA::GetExpert()) ; 
132       if ( expertDir ) {
133         expertDir->cd() ;
134         next.Reset() ; 
135         while ( (obj = dynamic_cast<TH1 *>(next())) ) {
136           TString name(obj->GetTitle()) ;
137           if (name.Contains(AliQA::GetExpert())) 
138             continue ; 
139           name.ReplaceAll(AliQA::GetExpert(), "") ;
140           obj->SetTitle(name) ; 
141           obj->Write() ;
142         }      
143       }
144     }
145   }
146   fOutput->Save() ; 
147   ResetCycle() ; 
148 }
149  
150 //____________________________________________________________________________
151 void AliQADataMakerSim::Exec(AliQA::TASKINDEX_t task, TObject * data) 
152
153   // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
154     
155         if ( task == AliQA::kHITS ) {  
156                 AliDebug(1, "Processing Hits QA") ; 
157                 TClonesArray * arr = dynamic_cast<TClonesArray *>(data) ; 
158                 if (arr) { 
159                         MakeHits(arr) ;
160                 } else {
161                         TTree * tree = dynamic_cast<TTree *>(data) ; 
162                         if (tree) {
163                                 MakeHits(tree) ; 
164                         } else {
165                                 AliWarning("data are neither a TClonesArray nor a TTree") ; 
166                         }
167                 }
168         } else if ( task == AliQA::kSDIGITS ) {
169                 AliDebug(1, "Processing SDigits QA") ; 
170                 TClonesArray * arr = dynamic_cast<TClonesArray *>(data) ; 
171                 if (arr) { 
172                         MakeSDigits(arr) ;
173                 } else {
174                         TTree * tree = dynamic_cast<TTree *>(data) ; 
175                         if (tree) {
176                                 MakeSDigits(tree) ; 
177                         } else {
178                                 AliWarning("data are neither a TClonesArray nor a TTree") ; 
179                         }
180                 }
181         } else if ( task == AliQA::kDIGITS ) {
182                 AliDebug(1, "Processing Digits QA") ; 
183                 TClonesArray * arr = dynamic_cast<TClonesArray *>(data) ; 
184                 if (arr) { 
185                         MakeDigits(arr) ;
186                 } else {
187                         TTree * tree = dynamic_cast<TTree *>(data) ; 
188                         if (tree) {
189                                 MakeDigits(tree) ; 
190                         } else {
191                                 AliWarning("data are neither a TClonesArray nor a TTree") ; 
192                         }
193                 }
194         }
195 }
196
197 //____________________________________________________________________________ 
198 TObjArray *  AliQADataMakerSim::Init(AliQA::TASKINDEX_t task, Int_t cycles)
199 {
200   // general intialisation
201         
202         if (cycles > 0)
203                 SetCycle(cycles) ;  
204         TObjArray * rv = NULL ; 
205         if ( task == AliQA::kHITS ) {
206                 if ( ! fHitsQAList ) {
207                         fHitsQAList = new TObjArray(100) ;       
208    fHitsQAList->SetName(Form("%s/%s", GetName(), AliQA::GetTaskName(task).Data())) ; 
209                         InitHits() ;
210                 }
211                 rv = fHitsQAList ;
212         } else if ( task == AliQA::kSDIGITS ) {
213                 if ( ! fSDigitsQAList ) {
214                         fSDigitsQAList = new TObjArray(100) ; 
215    fSDigitsQAList->SetName(Form("%s/%s", GetName(), AliQA::GetTaskName(task).Data())) ; 
216                         InitSDigits() ;
217                 }
218                 rv = fSDigitsQAList ;
219    } else if ( task == AliQA::kDIGITS ) {
220            if ( ! fDigitsQAList ) {
221                    fDigitsQAList = new TObjArray(100) ;
222      fDigitsQAList->SetName(Form("%s/%s", GetName(), AliQA::GetTaskName(task).Data())) ; 
223                    InitDigits() ;
224            }
225            rv =  fDigitsQAList ;
226    }
227   
228         return rv ; 
229 }
230
231 //____________________________________________________________________________ 
232 void AliQADataMakerSim::Init(AliQA::TASKINDEX_t task, TObjArray * list, Int_t run, Int_t cycles)
233 {
234   // Intialisation by passing the list of QA data booked elsewhere
235   
236         fRun = run ;
237         if (cycles > 0)
238                 SetCycle(cycles) ;  
239         
240         if ( task == AliQA::kHITS ) {
241                 fHitsQAList = list ;     
242         } else if ( task == AliQA::kSDIGITS) {
243                 fSDigitsQAList = list ; 
244         } else if ( task == AliQA::kDIGITS ) {
245                 fDigitsQAList = list ; 
246         } 
247 }
248
249 //____________________________________________________________________________
250 void AliQADataMakerSim::StartOfCycle(Int_t run) 
251
252   // Finishes a cycle of QA for all tasks
253   Bool_t samecycle = kFALSE ; 
254   StartOfCycle(AliQA::kHITS,    run, samecycle) ;
255   samecycle = kTRUE ; 
256   StartOfCycle(AliQA::kSDIGITS, run, samecycle) ;
257   StartOfCycle(AliQA::kDIGITS,  run, samecycle) ;
258 }
259
260 //____________________________________________________________________________
261 void AliQADataMakerSim::StartOfCycle(AliQA::TASKINDEX_t task, Int_t run, const Bool_t sameCycle) 
262
263   // Finishes a cycle of QA data acquistion
264   if ( run > 0 ) 
265     fRun = run ; 
266         if ( !sameCycle || fCurrentCycle == -1) {
267                 ResetCycle() ;
268         if (fOutput) 
269                 fOutput->Close() ; 
270         fOutput = AliQA::GetQADataFile(GetName(), fRun) ;       
271         }       
272
273         AliInfo(Form(" Run %d Cycle %d task %s file %s", 
274                                  fRun, fCurrentCycle, AliQA::GetTaskName(task).Data(), fOutput->GetName() )) ;
275
276         fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ; 
277         if (!fDetectorDir)
278                 fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ; 
279
280         TDirectory * subDir = fDetectorDir->GetDirectory(AliQA::GetTaskName(task)) ; 
281         if (!subDir)
282                 subDir = fDetectorDir->mkdir(AliQA::GetTaskName(task)) ;  
283   
284   TDirectory * expertDir = subDir->GetDirectory(AliQA::GetExpert()) ; 
285   if (!expertDir)
286     expertDir = subDir->mkdir(AliQA::GetExpert()) ; 
287
288         subDir->cd() ; 
289           
290         StartOfDetectorCycle() ; 
291 }