Fix for raw ctp decoding (Marek)
[u/mrichter/AliRoot.git] / STEER / STEER / AliQADataMakerSim.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 *
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
202374b1 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//
04236e67 25
26// --- ROOT system ---
04236e67 27#include <TFile.h>
04236e67 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"
04236e67 36
37ClassImp(AliQADataMakerSim)
38
39//____________________________________________________________________________
40AliQADataMakerSim::AliQADataMakerSim(const char * name, const char * title) :
41 AliQADataMaker(name, title),
eca4fa66 42 fDigitsQAList(NULL),
43 fHitsQAList(NULL),
6252ceeb 44 fSDigitsQAList(NULL),
45 fHitsArray(NULL),
46 fSDigitsArray(NULL)
04236e67 47{
48 // ctor
49 fDetectorDirName = GetName() ;
50}
51
52//____________________________________________________________________________
53AliQADataMakerSim::AliQADataMakerSim(const AliQADataMakerSim& qadm) :
54 AliQADataMaker(qadm.GetName(), qadm.GetTitle()),
55 fDigitsQAList(qadm.fDigitsQAList),
56 fHitsQAList(qadm.fHitsQAList),
6252ceeb 57 fSDigitsQAList(qadm.fSDigitsQAList),
58 fHitsArray(NULL),
59 fSDigitsArray(NULL)
04236e67 60{
61 //copy ctor
62 fDetectorDirName = GetName() ;
63}
64
63c6f8ae 65//____________________________________________________________________________
66AliQADataMakerSim::~AliQADataMakerSim()
67{
68 //dtor: delete the TObjArray and thei content
7ff8385d 69 if ( fDigitsQAList ) {
57acd2d2 70 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
57acd2d2 71 fDigitsQAList[specie]->Delete() ;
72 }
eca4fa66 73 delete[] fDigitsQAList ;
74 }
7ff8385d 75 if ( fHitsQAList ) {
57acd2d2 76 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
57acd2d2 77 fHitsQAList[specie]->Delete() ;
78 }
eca4fa66 79 delete[] fHitsQAList ;
80 }
7ff8385d 81 if ( fSDigitsQAList ) {
57acd2d2 82 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
57acd2d2 83 fSDigitsQAList[specie]->Delete() ;
84 }
eca4fa66 85 delete[] fSDigitsQAList ;
86 }
6252ceeb 87 if (fHitsArray) {
88 fHitsArray->Clear() ;
89 delete fHitsArray ;
90 }
91 if (fSDigitsArray) {
92 fSDigitsArray->Clear() ;
93 delete fSDigitsArray ;
94 }
63c6f8ae 95}
96
04236e67 97//__________________________________________________________________
98AliQADataMakerSim& AliQADataMakerSim::operator = (const AliQADataMakerSim& qadm )
99{
100 // Assignment operator.
101 this->~AliQADataMakerSim();
102 new(this) AliQADataMakerSim(qadm);
103 return *this;
104}
105
106//____________________________________________________________________________
930e6e3e 107void AliQADataMakerSim::EndOfCycle()
108{
109 // Finishes a cycle of QA for all tasks
4e25ac79 110 EndOfCycle(AliQAv1::kHITS) ;
111 EndOfCycle(AliQAv1::kSDIGITS) ;
112 EndOfCycle(AliQAv1::kDIGITS) ;
930e6e3e 113 ResetCycle() ;
114}
115
116//____________________________________________________________________________
4e25ac79 117void AliQADataMakerSim::EndOfCycle(AliQAv1::TASKINDEX_t task)
04236e67 118{
119 // Finishes a cycle of QA data acquistion
57acd2d2 120 TObjArray ** list = NULL ;
04236e67 121
4e25ac79 122 if ( task == AliQAv1::kHITS )
04236e67 123 list = fHitsQAList ;
4e25ac79 124 else if ( task == AliQAv1::kSDIGITS )
04236e67 125 list = fSDigitsQAList ;
4e25ac79 126 else if ( task == AliQAv1::kDIGITS )
04236e67 127 list = fDigitsQAList ;
930e6e3e 128
129 if ( ! list )
130 return ;
04236e67 131 EndOfDetectorCycle(task, list) ;
eca4fa66 132 fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ;
133 if (!fDetectorDir)
134 fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ;
135 TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ;
136 if (!subDir)
137 subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;
138 subDir->cd() ;
139 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
140 if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(specie)) )
141 continue ;
4851e489 142 if (list[specie]->GetEntries() != 0 ) {
143 TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(specie)) ;
144 if (!eventSpecieDir)
145 eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(specie)) ;
146 eventSpecieDir->cd() ;
147 TIter next(list[specie]) ;
148 TObject * obj ;
149 while ( (obj = next()) ) {
eca4fa66 150 if (!obj->TestBit(AliQAv1::GetExpertBit()))
4851e489 151 obj->Write() ;
152 }
153 if (WriteExpert()) {
154 TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ;
155 if (!expertDir)
156 expertDir = eventSpecieDir->mkdir(AliQAv1::GetExpert()) ;
157 expertDir->cd() ;
158 next.Reset() ;
159 while ( (obj = next()) ) {
160 if (!obj->TestBit(AliQAv1::GetExpertBit()))
161 continue ;
162 obj->Write() ;
163 }
164 }
6e65319c 165 }
57acd2d2 166 fOutput->Save() ;
6e65319c 167 }
04236e67 168}
eca4fa66 169
04236e67 170//____________________________________________________________________________
4e25ac79 171void AliQADataMakerSim::Exec(AliQAv1::TASKINDEX_t task, TObject * data)
04236e67 172{
173 // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
eca4fa66 174
4e25ac79 175 if ( task == AliQAv1::kHITS ) {
5379c4a3 176 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Hits QA") ;
eca4fa66 177 if (strcmp(data->ClassName(), "TClonesArray") == 0) {
6252ceeb 178 fHitsArray = static_cast<TClonesArray *>(data) ;
179 MakeHits() ;
eca4fa66 180 } else if (strcmp(data->ClassName(), "TTree") == 0) {
181 TTree * tree = static_cast<TTree *>(data) ;
182 MakeHits(tree) ;
183 } else {
184 AliWarning("data are neither a TClonesArray nor a TTree") ;
185 }
4e25ac79 186 } else if ( task == AliQAv1::kSDIGITS ) {
5379c4a3 187 AliDebug(AliQAv1::GetQADebugLevel(), "Processing SDigits QA") ;
eca4fa66 188 if (strcmp(data->ClassName(), "TClonesArray") == 0) {
6252ceeb 189 fSDigitsArray = static_cast<TClonesArray *>(data) ;
190 MakeSDigits() ;
eca4fa66 191 } else if (strcmp(data->ClassName(), "TTree") == 0) {
192 TTree * tree = static_cast<TTree *>(data) ;
193 MakeSDigits(tree) ;
194 } else {
195 AliWarning("data are neither a TClonesArray nor a TTree") ;
196 }
197 } else if ( task == AliQAv1::kDIGITS ) {
5379c4a3 198 AliDebug(AliQAv1::GetQADebugLevel(), "Processing Digits QA") ;
eca4fa66 199 if (strcmp(data->ClassName(), "TClonesArray") == 0) {
6252ceeb 200 fDigitsArray = static_cast<TClonesArray *>(data) ;
201 MakeDigits() ;
eca4fa66 202 } else if (strcmp(data->ClassName(), "TTree") == 0) {
203 TTree * tree = static_cast<TTree *>(data) ;
204 MakeDigits(tree) ;
205 } else {
206 AliWarning("data are neither a TClonesArray nor a TTree") ;
207 }
208 }
04236e67 209}
210
211//____________________________________________________________________________
4e25ac79 212TObjArray ** AliQADataMakerSim::Init(AliQAv1::TASKINDEX_t task, Int_t cycles)
04236e67 213{
214 // general intialisation
215
04236e67 216 if (cycles > 0)
217 SetCycle(cycles) ;
57acd2d2 218 TObjArray ** rv = NULL ;
4e25ac79 219 if ( task == AliQAv1::kHITS ) {
63c6f8ae 220 if ( ! fHitsQAList ) {
57acd2d2 221 fHitsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
222 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
49466ea2 223 fHitsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
4e25ac79 224 fHitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
57acd2d2 225 }
63c6f8ae 226 }
04236e67 227 rv = fHitsQAList ;
4e25ac79 228 } else if ( task == AliQAv1::kSDIGITS ) {
63c6f8ae 229 if ( ! fSDigitsQAList ) {
57acd2d2 230 fSDigitsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
231 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
49466ea2 232 fSDigitsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
4e25ac79 233 fSDigitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
57acd2d2 234 }
63c6f8ae 235 }
04236e67 236 rv = fSDigitsQAList ;
4e25ac79 237 } else if ( task == AliQAv1::kDIGITS ) {
63c6f8ae 238 if ( ! fDigitsQAList ) {
57acd2d2 239 fDigitsQAList = new TObjArray *[AliRecoParam::kNSpecies] ;
240 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
49466ea2 241 fDigitsQAList[specie] = new TObjArray(AliQAv1::GetMaxQAObj()) ;
4e25ac79 242 fDigitsQAList[specie]->SetName(Form("%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(specie))) ;
57acd2d2 243 }
63c6f8ae 244 }
04236e67 245 rv = fDigitsQAList ;
246 }
247
248 return rv ;
eca4fa66 249}
04236e67 250
251//____________________________________________________________________________
4e25ac79 252void AliQADataMakerSim::Init(AliQAv1::TASKINDEX_t task, TObjArray ** list, Int_t run, Int_t cycles)
04236e67 253{
254 // Intialisation by passing the list of QA data booked elsewhere
255
256 fRun = run ;
257 if (cycles > 0)
258 SetCycle(cycles) ;
259
4e25ac79 260 if ( task == AliQAv1::kHITS ) {
04236e67 261 fHitsQAList = list ;
4e25ac79 262 } else if ( task == AliQAv1::kSDIGITS) {
04236e67 263 fSDigitsQAList = list ;
4e25ac79 264 } else if ( task == AliQAv1::kDIGITS ) {
04236e67 265 fDigitsQAList = list ;
266 }
267}
268
9ac91920 269//____________________________________________________________________________
270void AliQADataMakerSim::ResetDetector(AliQAv1::TASKINDEX_t task)
271{
272 // default reset that resets all the QA objects.
273 // to be overloaded by detectors, if necessary
274
275 TObjArray ** list = NULL ;
276 if ( task == AliQAv1::kHITS ) {
277 list = fHitsQAList ;
278 } else if ( task == AliQAv1::kSDIGITS ) {
279 list = fSDigitsQAList ;
280 } else if ( task == AliQAv1::kDIGITS ) {
281 list = fDigitsQAList ;
282 }
283 //list was not initialized, skip
284 if (!list)
285 return ;
286
287 for (int spec = 0; spec < AliRecoParam::kNSpecies; spec++) {
288 if (!AliQAv1::Instance()->IsEventSpecieSet(AliRecoParam::ConvertIndex(spec)))
289 continue;
290 TIter next(list[spec]) ;
291 TH1 * histo = NULL ;
292 while ( (histo = dynamic_cast<TH1*> (next())) ) {
293 histo->Reset() ;
294 }
295 }
296}
297
04236e67 298//____________________________________________________________________________
930e6e3e 299void AliQADataMakerSim::StartOfCycle(Int_t run)
300{
301 // Finishes a cycle of QA for all tasks
302 Bool_t samecycle = kFALSE ;
4e25ac79 303 StartOfCycle(AliQAv1::kHITS, run, samecycle) ;
930e6e3e 304 samecycle = kTRUE ;
4e25ac79 305 StartOfCycle(AliQAv1::kSDIGITS, run, samecycle) ;
306 StartOfCycle(AliQAv1::kDIGITS, run, samecycle) ;
930e6e3e 307}
308
309//____________________________________________________________________________
4e25ac79 310void AliQADataMakerSim::StartOfCycle(AliQAv1::TASKINDEX_t task, Int_t run, const Bool_t sameCycle)
04236e67 311{
312 // Finishes a cycle of QA data acquistion
930e6e3e 313 if ( run > 0 )
314 fRun = run ;
04236e67 315 if ( !sameCycle || fCurrentCycle == -1) {
316 ResetCycle() ;
317 if (fOutput)
318 fOutput->Close() ;
4e25ac79 319 fOutput = AliQAv1::GetQADataFile(GetName(), fRun) ;
04236e67 320 }
321
5379c4a3 322 AliDebug(AliQAv1::GetQADebugLevel(), Form(" Run %d Cycle %d task %s file %s",
4e25ac79 323 fRun, fCurrentCycle, AliQAv1::GetTaskName(task).Data(), fOutput->GetName() )) ;
04236e67 324
eca4fa66 325 //fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ;
326// if (!fDetectorDir)
327// fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ;
328//
329// TDirectory * subDir = fDetectorDir->GetDirectory(AliQAv1::GetTaskName(task)) ;
330// if (!subDir)
331// subDir = fDetectorDir->mkdir(AliQAv1::GetTaskName(task)) ;
332//
333// for ( Int_t index = AliRecoParam::kDefault ; index < AliRecoParam::kNSpecies ; index++ ) {
334// TDirectory * eventSpecieDir = subDir->GetDirectory(AliRecoParam::GetEventSpecieName(index)) ;
335// if (!eventSpecieDir)
336// eventSpecieDir = subDir->mkdir(AliRecoParam::GetEventSpecieName(index)) ;
337// TDirectory * expertDir = eventSpecieDir->GetDirectory(AliQAv1::GetExpert()) ;
338// if (!expertDir)
339// expertDir = eventSpecieDir->mkdir(AliQAv1::GetExpert()) ;
340// }
04236e67 341 StartOfDetectorCycle() ;
342}
92664bc8 343
344
345//____________________________________________________________________________
346void AliQADataMakerSim::ClonePerTrigClass(AliQAv1::TASKINDEX_t task)
347{
348 // clone the histos of the array corresponding to task
349 switch (task)
350 {
351 case AliQAv1::kHITS : ClonePerTrigClassL(fHitsQAList, task); break;
352 case AliQAv1::kSDIGITS : ClonePerTrigClassL(fSDigitsQAList, task); break;
353 case AliQAv1::kDIGITS : ClonePerTrigClassL(fDigitsQAList, task); break;
354 default : AliError(Form("Task %s is invalid in this context", AliQAv1::GetTaskName(task).Data() )); break;
355 }
356 //
357}