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