]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQADataMakerSim.cxx
Fixes in the memory managment, additional protections
[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 <TSystem.h> 
28 #include <TFile.h>
29 #include <TList.h> 
30 #include <TTree.h>
31 #include <TClonesArray.h>
32
33 // --- Standard library ---
34
35 // --- AliRoot header files ---
36 #include "AliLog.h"
37 #include "AliQADataMakerSim.h"
38 #include "AliQAChecker.h"
39
40 ClassImp(AliQADataMakerSim)
41              
42 //____________________________________________________________________________ 
43 AliQADataMakerSim::AliQADataMakerSim(const char * name, const char * title) : 
44   AliQADataMaker(name, title), 
45   fDigitsQAList(0x0), 
46   fHitsQAList(0x0),
47   fSDigitsQAList(0x0)
48 {
49         // ctor
50         fDetectorDirName = GetName() ; 
51 }
52
53 //____________________________________________________________________________ 
54 AliQADataMakerSim::AliQADataMakerSim(const AliQADataMakerSim& qadm) :
55   AliQADataMaker(qadm.GetName(), qadm.GetTitle()), 
56   fDigitsQAList(qadm.fDigitsQAList),
57   fHitsQAList(qadm.fHitsQAList),
58   fSDigitsQAList(qadm.fSDigitsQAList) 
59 {
60   //copy ctor
61   fDetectorDirName = GetName() ; 
62 }
63
64 //__________________________________________________________________
65 AliQADataMakerSim& AliQADataMakerSim::operator = (const AliQADataMakerSim& qadm )
66 {
67   // Assignment operator.
68   this->~AliQADataMakerSim();
69   new(this) AliQADataMakerSim(qadm);
70   return *this;
71 }
72
73 //____________________________________________________________________________
74 void AliQADataMakerSim::EndOfCycle(AliQA::TASKINDEX task) 
75
76   // Finishes a cycle of QA data acquistion
77         TObjArray * list = 0x0 ; 
78         
79         if ( task == AliQA::kHITS ) 
80                 list = fHitsQAList ; 
81         else if ( task == AliQA::kSDIGITS )
82                 list = fSDigitsQAList ; 
83         else if ( task == AliQA::kDIGITS ) 
84                 list = fDigitsQAList ; 
85         
86         EndOfDetectorCycle(task, list) ; 
87         TDirectory * subDir = fDetectorDir->GetDirectory(AliQA::GetTaskName(task)) ; 
88         if (subDir) { 
89                 subDir->cd() ; 
90                 list->Write() ; 
91         }
92 }
93  
94 //____________________________________________________________________________
95 void AliQADataMakerSim::Exec(AliQA::TASKINDEX task, TObject * data) 
96
97   // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
98     
99         if ( task == AliQA::kHITS ) {  
100                 AliDebug(1, "Processing Hits QA") ; 
101                 TClonesArray * arr = dynamic_cast<TClonesArray *>(data) ; 
102                 if (arr) { 
103                         MakeHits(arr) ;
104                 } else {
105                         TTree * tree = dynamic_cast<TTree *>(data) ; 
106                         if (tree) {
107                                 MakeHits(tree) ; 
108                         } else {
109                                 AliWarning("data are neither a TClonesArray nor a TTree") ; 
110                         }
111                 }
112         } else if ( task == AliQA::kSDIGITS ) {
113                 AliDebug(1, "Processing SDigits QA") ; 
114                 TClonesArray * arr = dynamic_cast<TClonesArray *>(data) ; 
115                 if (arr) { 
116                         MakeSDigits(arr) ;
117                 } else {
118                         TTree * tree = dynamic_cast<TTree *>(data) ; 
119                         if (tree) {
120                                 MakeSDigits(tree) ; 
121                         } else {
122                                 AliWarning("data are neither a TClonesArray nor a TTree") ; 
123                         }
124                 }
125         } else if ( task == AliQA::kDIGITS ) {
126                 AliDebug(1, "Processing Digits QA") ; 
127                 TClonesArray * arr = dynamic_cast<TClonesArray *>(data) ; 
128                 if (arr) { 
129                         MakeDigits(arr) ;
130                 } else {
131                         TTree * tree = dynamic_cast<TTree *>(data) ; 
132                         if (tree) {
133                                 MakeDigits(tree) ; 
134                         } else {
135                                 AliWarning("data are neither a TClonesArray nor a TTree") ; 
136                         }
137                 }
138         }
139 }
140
141 //____________________________________________________________________________ 
142 TObjArray *  AliQADataMakerSim::Init(AliQA::TASKINDEX task, Int_t run, Int_t cycles)
143 {
144   // general intialisation
145         
146         fRun = run ;
147         if (cycles > 0)
148                 SetCycle(cycles) ;  
149         TObjArray * rv = NULL ; 
150         if ( task == AliQA::kHITS ) {
151                 fHitsQAList = new TObjArray(100) ;       
152                 InitHits() ;
153                 rv = fHitsQAList ;
154         } else if ( task == AliQA::kSDIGITS ) {
155                 fSDigitsQAList = new TObjArray(100) ; 
156                 InitSDigits() ;
157                 rv = fSDigitsQAList ;
158    } else if ( task == AliQA::kDIGITS ) {
159            fDigitsQAList = new TObjArray(100); 
160            InitDigits() ;
161            rv =  fDigitsQAList ;
162    }
163   
164         return rv ; 
165 }
166
167 //____________________________________________________________________________ 
168 void AliQADataMakerSim::Init(AliQA::TASKINDEX task, TObjArray * list, Int_t run, Int_t cycles)
169 {
170   // Intialisation by passing the list of QA data booked elsewhere
171   
172         fRun = run ;
173         if (cycles > 0)
174                 SetCycle(cycles) ;  
175         
176         if ( task == AliQA::kHITS ) {
177                 fHitsQAList = list ;     
178         } else if ( task == AliQA::kSDIGITS) {
179                 fSDigitsQAList = list ; 
180         } else if ( task == AliQA::kDIGITS ) {
181                 fDigitsQAList = list ; 
182         } 
183 }
184
185 //____________________________________________________________________________
186 void AliQADataMakerSim::StartOfCycle(AliQA::TASKINDEX task, const Bool_t sameCycle) 
187
188   // Finishes a cycle of QA data acquistion
189         if ( !sameCycle || fCurrentCycle == -1) {
190                 ResetCycle() ;
191         if (fOutput) 
192                 fOutput->Close() ; 
193         fOutput = AliQA::GetQADataFile(GetName(), fRun, fCurrentCycle) ;        
194         }       
195
196         AliInfo(Form(" Run %d Cycle %d task %s file %s", 
197                                  fRun, fCurrentCycle, AliQA::GetTaskName(task).Data(), fOutput->GetName() )) ;
198
199         fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ; 
200         if (!fDetectorDir)
201                 fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ; 
202
203         TDirectory * subDir = fDetectorDir->GetDirectory(AliQA::GetTaskName(task)) ; 
204         if (!subDir)
205                 subDir = fDetectorDir->mkdir(AliQA::GetTaskName(task)) ;  
206         subDir->cd() ; 
207         
208         TObjArray * list = 0x0 ; 
209   
210         if ( task == AliQA::kHITS )  
211                 list = fHitsQAList ;
212         else if ( task == AliQA::kSDIGITS )  
213                 list = fSDigitsQAList ;
214         else  if ( task == AliQA::kDIGITS ) 
215                 list = fDigitsQAList ;
216
217         TIter next(list) ;
218         TH1 * h ; 
219         while ( (h = dynamic_cast<TH1 *>(next())) )
220                 h->Reset() ;  
221
222         StartOfDetectorCycle() ; 
223 }