]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQADataMakerSteer.cxx
The standalone QA data maker is called from AliSimulation and AliReconstruction outsi...
[u/mrichter/AliRoot.git] / STEER / AliQADataMakerSteer.cxx
CommitLineData
312e6f8d 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/* $Id$ */
17
18#include <TFile.h>
19#include <TPluginManager.h>
20#include <TROOT.h>
21#include <TString.h>
22#include <TSystem.h>
23
24#include "AliESDEvent.h"
25#include "AliLog.h"
26#include "AliQA.h"
27#include "AliQADataMaker.h"
28#include "AliQADataMakerSteer.h"
29#include "AliRawReaderRoot.h"
30#include "AliRun.h"
31#include "AliRunLoader.h"
32
33ClassImp(AliQADataMakerSteer)
34
35//_____________________________________________________________________________
36AliQADataMakerSteer::AliQADataMakerSteer(const char* gAliceFilename, const char * name, const char * title) :
37 TNamed(name, title),
c65c502a 38 fCycleSame(kFALSE),
312e6f8d 39 fESD(NULL),
40 fESDTree(NULL),
41 fFirst(kTRUE),
42 fGAliceFileName(gAliceFilename),
43 fRunNumber(0),
44 fNumberOfEvents(0),
45 fRawReader(NULL),
46 fRunLoader(NULL)
47{
48 // default ctor
49 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
50 fLoader[iDet] = NULL ;
51 fQADataMaker[iDet] = NULL ;
52 fQACycles[iDet] = 999999 ;
53 }
54}
55
56//_____________________________________________________________________________
57AliQADataMakerSteer::AliQADataMakerSteer(const AliQADataMakerSteer & qas) :
58 TNamed(qas),
c65c502a 59 fCycleSame(kFALSE),
312e6f8d 60 fESD(NULL),
61 fESDTree(NULL),
62 fFirst(qas.fFirst),
63 fGAliceFileName(qas.fGAliceFileName),
64 fRunNumber(qas.fRunNumber),
65 fNumberOfEvents(qas.fNumberOfEvents),
66 fRawReader(NULL),
67 fRunLoader(NULL)
68{
69 // cpy ctor
70 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
71 fLoader[iDet] = qas.fLoader[iDet] ;
72 fQADataMaker[iDet] = qas.fQADataMaker[iDet] ;
73 fQACycles[iDet] = qas.fQACycles[iDet] ;
74 }
75}
76
77//_____________________________________________________________________________
78AliQADataMakerSteer & AliQADataMakerSteer::operator = (const AliQADataMakerSteer & qas)
79{
80 // assignment operator
81 this->~AliQADataMakerSteer() ;
82 new(this) AliQADataMakerSteer(qas) ;
83 return *this ;
84}
85
86//_____________________________________________________________________________
87AliQADataMakerSteer::~AliQADataMakerSteer()
88{
89 // dtor
90 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
91 fLoader[iDet] = NULL;
c65c502a 92 if (fQADataMaker[iDet]) {
93 (fQADataMaker[iDet])->Finish() ;
94 delete fQADataMaker[iDet] ;
95 fQADataMaker[iDet] = NULL ;
96 }
312e6f8d 97 }
98
c65c502a 99 fRunLoader = NULL ;
100 delete fRawReader ;
101 fRawReader = NULL ;
312e6f8d 102}
103
104//_____________________________________________________________________________
105AliLoader * AliQADataMakerSteer::GetLoader(Int_t iDet)
106{
107 // get the loader for a detector
108
109 TString detName = AliQA::GetDetName(iDet) ;
110 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
111 if (fLoader[iDet])
112 return fLoader[iDet] ;
113
114 // load the QA data maker object
115 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
116 TString loaderName = "Ali" + detName + "Loader" ;
117
118 AliLoader * loader = NULL ;
119 // first check if a plugin is defined for the quality assurance data maker
120 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
121 // if not, add a plugin for it
122 if (!pluginHandler) {
123 AliDebug(1, Form("defining plugin for %s", loaderName.Data())) ;
124 TString libs = gSystem->GetLibraries() ;
125 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
126 pluginManager->AddHandler("AliQADataMaker", detName, loaderName, detName + "loader", loaderName + "()") ;
127 } else {
128 pluginManager->AddHandler("AliLoader", detName, loaderName, detName, loaderName + "()") ;
129 }
130 pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
131 }
132 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
133 loader = (AliLoader *) pluginHandler->ExecPlugin(0) ;
134 }
135 if (loader)
136 fLoader[iDet] = loader ;
137 return loader ;
138}
139
140//_____________________________________________________________________________
141AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(Int_t iDet)
142{
143 // get the quality assurance data maker for a detector
144
145 if (fQADataMaker[iDet])
146 return fQADataMaker[iDet] ;
147
148 AliQADataMaker * qadm = NULL ;
149
150 if (fFirst) {
151 // load the QA data maker object
152 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
153 TString detName = AliQA::GetDetName(iDet) ;
154 TString qadmName = "Ali" + detName + "QADataMaker" ;
155
156 // first check if a plugin is defined for the quality assurance data maker
157 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
158 // if not, add a plugin for it
159 if (!pluginHandler) {
160 AliDebug(1, Form("defining plugin for %s", qadmName.Data())) ;
161 TString libs = gSystem->GetLibraries() ;
162 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
163 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ;
164 } else {
165 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ;
166 }
167 pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
168 }
169 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
170 qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ;
171 }
172 if (qadm)
173 fQADataMaker[iDet] = qadm ;
174 }
175 return qadm ;
176}
177
178//_____________________________________________________________________________
179Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, const char * fileName )
180{
181 // Initialize the event source and QA data makers
182
183 if (taskIndex == AliQA::kRAWS) {
184 fRawReader = new AliRawReaderRoot(fileName) ;
185 if ( ! fRawReader )
186 return kFALSE ;
187 fRawReader->NextEvent() ;
188 fRunNumber = fRawReader->GetRunNumber() ;
189 fRawReader->RewindEvents();
190 fNumberOfEvents = 999999 ;
191
192 } else if (taskIndex == AliQA::kESDS) {
193 if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists
194 TFile * esdFile = TFile::Open("AliESDs.root") ;
195 fESDTree = dynamic_cast<TTree *> (esdFile->Get("esdTree")) ;
196 fESD = new AliESDEvent() ;
197 fESD->ReadFromTree(fESDTree) ;
198 fESDTree->GetEntry(0) ;
199 fRunNumber = fESD->GetRunNumber() ;
200 fNumberOfEvents = fESDTree->GetEntries() ;
201 } else {
202 AliError("AliESDs.root not found") ;
203 return kFALSE ;
204 }
205
206 } else {
207 if ( !InitRunLoader() ) {
208 AliError("Problems in getting the Run Loader") ;
209 return kFALSE ;
210 } else {
211 fRunNumber = fRunLoader->GetAliRun()->GetRunNumber() ;
212 fNumberOfEvents = fRunLoader->GetNumberOfEvents() ;
213 }
214 }
215
216 // Initialize all QA data makers for all detectors
217 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
218 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
219 if (!qadm) {
220 AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ;
221 } else {
222 AliInfo(Form("Data Maker found for %s", qadm->GetName())) ;
223 qadm->Init(taskIndex, fRunNumber, GetQACycles(iDet)) ;
c65c502a 224 qadm->StartOfCycle(taskIndex, fCycleSame) ;
312e6f8d 225 }
226 }
227 fFirst = kFALSE ;
228 return kTRUE ;
229}
230
231//_____________________________________________________________________________
232Bool_t AliQADataMakerSteer::InitRunLoader()
233{
234 // get or create the run loader
235 if (fRunLoader) {
c65c502a 236 fCycleSame = kTRUE ;
312e6f8d 237 return kTRUE ;
238 }
239
240 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
241 // load all base libraries to get the loader classes
242 TString libs = gSystem->GetLibraries() ;
243 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
244 TString detName = AliQA::GetDetName(iDet) ;
245 if (detName == "HLT")
246 continue;
247 if (libs.Contains("lib" + detName + "base.so"))
248 continue;
249 gSystem->Load("lib" + detName + "base.so");
250 }
251 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
252 if (!fRunLoader) {
253 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
254 return kFALSE;
255 }
256 fRunLoader->CdGAFile();
257 if (fRunLoader->LoadgAlice() == 0) {
258 gAlice = fRunLoader->GetAliRun();
259 }
260 if (!gAlice) {
261 AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
262 return kFALSE;
263 }
264
265 } else { // galice.root does not exist
266 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
267 return kFALSE;
268 }
269
270 return kTRUE;
271}
272
273//_____________________________________________________________________________
274Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX taskIndex)
275{
276 // write output to file for all detectors
277 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
278 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
279 if (qadm) {
280 qadm->EndOfCycle(taskIndex) ;
312e6f8d 281 }
282 }
283 return kTRUE ;
284}
285
c65c502a 286//_____________________________________________________________________________
287void AliQADataMakerSteer::Reset()
288{
289 // Reset the default data members
290 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
291 fLoader[iDet] = NULL;
292 if (fQADataMaker[iDet]) {
293 (fQADataMaker[iDet])->Reset() ;
294// delete fQADataMaker[iDet] ;
295// fQADataMaker[iDet] = NULL ;
296 }
297 }
298
299 fRunLoader = NULL ;
300 delete fRawReader ;
301 fRawReader = NULL ;
302
303 fCycleSame = kFALSE ;
304 fESD = NULL ;
305 fESDTree = NULL ;
306 fFirst = kTRUE ;
307 fNumberOfEvents = 0 ;
308}
309
312e6f8d 310//_____________________________________________________________________________
311Bool_t AliQADataMakerSteer::Run(const AliQA::TASKINDEX taskIndex, const char * fileName )
312{
313 // Runs all the QA data Maker for every detector
314 Bool_t rv = kFALSE ;
315
316 if ( !Init(taskIndex, fileName) )
317 return kFALSE ;
318
319 // Fill QA data in event loop
320 for (UInt_t iEvent = 0 ; iEvent < fNumberOfEvents ; iEvent++) {
321 // Get the event
322 AliInfo(Form("processing event %d", iEvent));
323 if ( taskIndex == AliQA::kRAWS ) {
324 if ( !fRawReader->NextEvent() )
325 break ;
326 } else if ( taskIndex == AliQA::kESDS ) {
327 fESDTree->GetEntry(iEvent) ;
328 } else {
329 fRunLoader->GetEvent(iEvent);
330 }
331 // loop over detectors
332 for (UInt_t iDet = 0 ; iDet < fgkNDetectors ; iDet++) {
333 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
334 if (!qadm) {
335 rv = kFALSE ;
336 } else {
337 if ( qadm->IsCycleDone() ) {
338 qadm->EndOfCycle(AliQA::kRAWS) ;
339 qadm->StartOfCycle(AliQA::kRAWS) ;
340 }
341 TTree * data ;
342 switch (taskIndex) {
343 case AliQA::kRAWS :
344 qadm->Exec(taskIndex, fRawReader) ;
345 break ;
346 case AliQA::kHITS :
347 GetLoader(iDet)->LoadHits() ;
348 data = GetLoader(iDet)->TreeH() ;
349 if ( ! data ) {
350 AliWarning(Form(" Hit Tree not found for %s", AliQA::GetDetName(iDet))) ;
351 } else {
352 qadm->Exec(taskIndex, data) ;
353 }
354 break ;
355 case AliQA::kSDIGITS :
356 GetLoader(iDet)->LoadSDigits() ;
357 data = GetLoader(iDet)->TreeS() ;
358 if ( ! data ) {
359 AliWarning(Form(" SDigit Tree not found for %s", AliQA::GetDetName(iDet))) ;
360 } else {
361 qadm->Exec(taskIndex, data) ;
362 }
363 break;
364 case AliQA::kDIGITS :
365 GetLoader(iDet)->LoadDigits() ;
366 data = GetLoader(iDet)->TreeD() ;
367 if ( ! data ) {
368 AliWarning(Form(" Digit Tree not found for %s", AliQA::GetDetName(iDet))) ;
369 } else {
370 qadm->Exec(taskIndex, data) ;
371 }
372 break;
373 case AliQA::kRECPOINTS :
374 GetLoader(iDet)->LoadRecPoints() ;
375 data = GetLoader(iDet)->TreeR() ;
376 if (!data) {
377 AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ;
378 } else {
379 qadm->Exec(taskIndex, data) ;
380 }
381 break;
382 case AliQA::kTRACKSEGMENTS :
383 break;
384 case AliQA::kRECPARTICLES :
385 break;
386 case AliQA::kESDS :
387 qadm->Exec(taskIndex, fESD) ;
388 break;
389 } //task switch
390 qadm->Increment() ;
391 } //data maker exist
392 } // detector loop
393 } // event loop
394 // Save QA data for all detectors
395 rv = Finish(taskIndex) ;
396 return rv ;
14e1eccc 397}