In mapping:
[u/mrichter/AliRoot.git] / STEER / AliQADataMakerRec.cxx
CommitLineData
04236e67 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 *
940d8e5f 10 * copies and that both the copyright notice and this permission notifce *
04236e67 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
202374b1 19//
20// Base Class
21// Produces the data needed to calculate the quality assurance for Reconstruction
22// All data must be mergeable objects.
23// Y. Schutz CERN July 2007
24//
04236e67 25
26// --- ROOT system ---
04236e67 27#include <TFile.h>
04236e67 28#include <TTree.h>
57acd2d2 29#include <TNtupleD.h>
04236e67 30
31// --- Standard library ---
32
33// --- AliRoot header files ---
34#include "AliLog.h"
35#include "AliQADataMakerRec.h"
04236e67 36#include "AliESDEvent.h"
37#include "AliRawReader.h"
38
39ClassImp(AliQADataMakerRec)
40
41//____________________________________________________________________________
42AliQADataMakerRec::AliQADataMakerRec(const char * name, const char * title) :
43 AliQADataMaker(name, title),
a2b64fbd 44 fESDsQAList(NULL),
45 fRawsQAList(NULL),
46 fRecPointsQAList(NULL),
57acd2d2 47 fCorrNt(NULL),
a2b64fbd 48 fRecoParam(NULL)
04236e67 49{
50 // ctor
51 fDetectorDirName = GetName() ;
52}
53
54//____________________________________________________________________________
55AliQADataMakerRec::AliQADataMakerRec(const AliQADataMakerRec& qadm) :
b8bd1ab8 56 AliQADataMaker(qadm.GetName(), qadm.GetTitle()),
57 fESDsQAList(qadm.fESDsQAList),
58 fRawsQAList(qadm.fRawsQAList),
59 fRecPointsQAList(qadm.fRecPointsQAList),
57acd2d2 60 fCorrNt(qadm.fCorrNt),
a2b64fbd 61 fRecoParam(qadm.fRecoParam)
04236e67 62{
63 //copy ctor
64 SetName(qadm.GetName()) ;
65 SetTitle(qadm.GetTitle()) ;
66 fDetectorDirName = GetName() ;
67}
68
63c6f8ae 69//____________________________________________________________________________
70AliQADataMakerRec::~AliQADataMakerRec()
71{
72 //dtor: delete the TObjArray and thei content
7ff8385d 73 if ( fESDsQAList ) {
57acd2d2 74 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
75 if ( fESDsQAList[specie] ) {
76 if ( fESDsQAList[specie]->IsOwner() )
77 fESDsQAList[specie]->Delete() ;
78 }
79 }
80 delete[] fESDsQAList ;
7ff8385d 81 }
82 if ( fRawsQAList ) {
57acd2d2 83 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
84 if ( fRawsQAList[specie] ) {
85 if ( fRawsQAList[specie]->IsOwner() )
86 fRawsQAList[specie]->Delete() ;
87 }
88 }
89 delete[] fRawsQAList ;
90 }
7ff8385d 91 if ( fRecPointsQAList ) {
57acd2d2 92 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
93 if ( fRecPointsQAList[specie] ) {
94 if ( fRecPointsQAList[specie]->IsOwner() )
95 fRecPointsQAList[specie]->Delete() ;
96 }
97 }
98 delete[] fRecPointsQAList ;
7ff8385d 99 }
63c6f8ae 100}
101
04236e67 102//__________________________________________________________________
103AliQADataMakerRec& AliQADataMakerRec::operator = (const AliQADataMakerRec& qadm )
104{
105 // Assignment operator.
106 this->~AliQADataMakerRec();
107 new(this) AliQADataMakerRec(qadm);
108 return *this;
109}
110
111//____________________________________________________________________________
930e6e3e 112void AliQADataMakerRec::EndOfCycle()
113{
114 // Finishes a cycle of QA for all the tasks
115 EndOfCycle(AliQA::kRAWS) ;
116 EndOfCycle(AliQA::kRECPOINTS) ;
117 EndOfCycle(AliQA::kESDS) ;
118 ResetCycle() ;
119}
120
121//____________________________________________________________________________
92a357bf 122void AliQADataMakerRec::EndOfCycle(AliQA::TASKINDEX_t task)
04236e67 123{
930e6e3e 124 // Finishes a cycle of QA
04236e67 125
57acd2d2 126 TObjArray ** list = NULL ;
04236e67 127
128 if ( task == AliQA::kRAWS )
129 list = fRawsQAList ;
130 else if ( task == AliQA::kRECPOINTS )
131 list = fRecPointsQAList ;
132 else if ( task == AliQA::kESDS )
133 list = fESDsQAList ;
7c002d48 134
930e6e3e 135
57acd2d2 136 if ( ! list && ! fCorrNt )
930e6e3e 137 return ;
138 //DefaultEndOfDetectorCycle(task) ;
0774e4a4 139 EndOfDetectorCycle(task, list) ;
a2b64fbd 140 TDirectory * subDir = NULL ;
7c002d48 141 if (fDetectorDir)
142 subDir = fDetectorDir->GetDirectory(AliQA::GetTaskName(task)) ;
45c5be2d 143 if ( subDir ) {
eecc22a3 144 subDir->cd() ;
57acd2d2 145 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
146 TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
147 if (eventSpecieDir) {
148 eventSpecieDir->cd() ;
149 if (list[specie]) {
150 TIter next(list[specie]) ;
151 TObject * obj ;
750730d8 152 while( (obj = next()) ) {
153 if (!obj->TestBit(AliQA::GetExpertBit()))
57acd2d2 154 obj->Write() ;
155 }
156 if (WriteExpert()) {
157 TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQA::GetExpert()) ;
158 if ( expertDir ) { // Write only if requested
159 expertDir->cd() ;
160 next.Reset() ;
161 while( (obj = next()) ) {
162 if (!obj->TestBit(AliQA::GetExpertBit()))
163 continue ;
164 obj->Write() ;
165 }
166 }
167 }
168 }
169 if ( !fCorrNt )
170 continue ;
171 if (fCorrNt[specie] && AliQA::GetDetIndex(GetName()) == AliQA::kCORR) {
172 eventSpecieDir->cd() ;
173 fCorrNt[specie]->Write() ;
b1af1125 174 }
6e65319c 175 }
176 }
a595ac34 177 fOutput->Save() ;
eecc22a3 178 }
04236e67 179}
180
181//____________________________________________________________________________
92a357bf 182void AliQADataMakerRec::Exec(AliQA::TASKINDEX_t task, TObject * data)
04236e67 183{
184 // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
185
186 if ( task == AliQA::kRAWS ) {
187 AliDebug(1, "Processing Raws QA") ;
188 AliRawReader * rawReader = dynamic_cast<AliRawReader *>(data) ;
189 if (rawReader)
190 MakeRaws(rawReader) ;
191 else
930e6e3e 192 AliInfo("Raw data are not processed") ;
04236e67 193 } else if ( task == AliQA::kRECPOINTS ) {
194 AliDebug(1, "Processing RecPoints QA") ;
195 TTree * tree = dynamic_cast<TTree *>(data) ;
196 if (tree) {
197 MakeRecPoints(tree) ;
198 } else {
199 AliWarning("data are not a TTree") ;
200 }
201 } else if ( task == AliQA::kESDS ) {
202 AliDebug(1, "Processing ESDs QA") ;
203 AliESDEvent * esd = dynamic_cast<AliESDEvent *>(data) ;
204 if (esd)
205 MakeESDs(esd) ;
206 else
207 AliError("Wrong type of esd container") ;
208 }
209}
210
211//____________________________________________________________________________
57acd2d2 212TObjArray ** AliQADataMakerRec::Init(AliQA::TASKINDEX_t task, Int_t cycles)
04236e67 213{
214 // general intialisation
57acd2d2 215
216 TObjArray ** rv = NULL ;
04236e67 217
04236e67 218 if (cycles > 0)
219 SetCycle(cycles) ;
220
221 if ( task == AliQA::kRAWS ) {
63c6f8ae 222 if (! fRawsQAList ) {
57acd2d2 223 fRawsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
224 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
225 fRawsQAList[specie] = new TObjArray(100) ;
226 fRawsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQA::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
227 }
63c6f8ae 228 InitRaws() ;
229 }
04236e67 230 rv = fRawsQAList ;
231 } else if ( task == AliQA::kRECPOINTS ) {
63c6f8ae 232 if ( ! fRecPointsQAList ) {
57acd2d2 233 fRecPointsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
234 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
235 fRecPointsQAList[specie] = new TObjArray(100) ;
236 fRecPointsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQA::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
237 }
238 InitRecPoints() ;
63c6f8ae 239 }
04236e67 240 rv = fRecPointsQAList ;
241 } else if ( task == AliQA::kESDS ) {
63c6f8ae 242 if ( ! fESDsQAList ) {
57acd2d2 243 fESDsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
244 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
245 fESDsQAList[specie] = new TObjArray(100) ;
246 fESDsQAList[specie]->SetName(Form("%s_%s", GetName(), AliQA::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
247 }
63c6f8ae 248 InitESDs() ;
249 }
04236e67 250 rv = fESDsQAList ;
251 }
04236e67 252 return rv ;
253}
254
255//____________________________________________________________________________
57acd2d2 256void AliQADataMakerRec::Init(AliQA::TASKINDEX_t task, TObjArray ** list, Int_t run, Int_t cycles)
04236e67 257{
258 // Intialisation by passing the list of QA data booked elsewhere
259
260 fRun = run ;
261 if (cycles > 0)
262 SetCycle(cycles) ;
263
264 if ( task == AliQA::kRAWS ) {
265 fRawsQAList = list ;
266 } else if ( task == AliQA::kRECPOINTS ) {
267 fRecPointsQAList = list ;
268 } else if ( task == AliQA::kESDS ) {
269 fESDsQAList = list ;
270 }
271}
272
273//____________________________________________________________________________
930e6e3e 274void AliQADataMakerRec::StartOfCycle(Int_t run)
275{
276 // Finishes a cycle of QA for all the tasks
277 Bool_t samecycle = kFALSE ;
278 StartOfCycle(AliQA::kRAWS, run, samecycle) ;
279 samecycle = kTRUE ;
280 StartOfCycle(AliQA::kRECPOINTS, run, samecycle) ;
281 StartOfCycle(AliQA::kESDS, run, samecycle) ;
282}
283
284//____________________________________________________________________________
285void AliQADataMakerRec::StartOfCycle(AliQA::TASKINDEX_t task, Int_t run, const Bool_t sameCycle)
04236e67 286{
287 // Finishes a cycle of QA data acquistion
930e6e3e 288 if ( run > 0 )
289 fRun = run ;
04236e67 290 if ( !sameCycle || fCurrentCycle == -1) {
291 ResetCycle() ;
292 if (fOutput)
293 fOutput->Close() ;
930e6e3e 294 fOutput = AliQA::GetQADataFile(GetName(), fRun) ;
04236e67 295 }
7c002d48 296 AliInfo(Form(" Run %d Cycle %d task %s file %s",
04236e67 297 fRun, fCurrentCycle, AliQA::GetTaskName(task).Data(), fOutput->GetName() )) ;
298
299 fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ;
300 if (!fDetectorDir)
301 fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ;
302
303 TDirectory * subDir = fDetectorDir->GetDirectory(AliQA::GetTaskName(task)) ;
304 if (!subDir)
305 subDir = fDetectorDir->mkdir(AliQA::GetTaskName(task)) ;
6e65319c 306
57acd2d2 307 for ( Int_t specie = AliRecoParam::kDefault ; specie < AliRecoParam::kNSpecies ; specie++ ) {
308 TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
309 if (!eventSpecieDir)
310 eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ;
311 TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQA::GetExpert()) ;
312 if (!expertDir)
313 expertDir = eventSpecieDir->mkdir(AliQA::GetExpert()) ;
314 }
04236e67 315 StartOfDetectorCycle() ;
316}