1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 #include <TPluginManager.h>
24 #include "AliESDEvent.h"
26 #include "AliModule.h"
28 #include "AliQADataMaker.h"
29 #include "AliQADataMakerSteer.h"
30 #include "AliRawReaderRoot.h"
32 #include "AliRunLoader.h"
34 ClassImp(AliQADataMakerSteer)
36 //_____________________________________________________________________________
37 AliQADataMakerSteer::AliQADataMakerSteer(const char* gAliceFilename, const char * name, const char * title) :
43 fGAliceFileName(gAliceFilename),
50 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
51 fLoader[iDet] = NULL ;
52 fQADataMaker[iDet] = NULL ;
53 fQACycles[iDet] = 999999 ;
57 //_____________________________________________________________________________
58 AliQADataMakerSteer::AliQADataMakerSteer(const AliQADataMakerSteer & qas) :
64 fGAliceFileName(qas.fGAliceFileName),
65 fRunNumber(qas.fRunNumber),
66 fNumberOfEvents(qas.fNumberOfEvents),
71 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
72 fLoader[iDet] = qas.fLoader[iDet] ;
73 fQADataMaker[iDet] = qas.fQADataMaker[iDet] ;
74 fQACycles[iDet] = qas.fQACycles[iDet] ;
78 //_____________________________________________________________________________
79 AliQADataMakerSteer & AliQADataMakerSteer::operator = (const AliQADataMakerSteer & qas)
81 // assignment operator
82 this->~AliQADataMakerSteer() ;
83 new(this) AliQADataMakerSteer(qas) ;
87 //_____________________________________________________________________________
88 AliQADataMakerSteer::~AliQADataMakerSteer()
91 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
93 if (fQADataMaker[iDet]) {
94 (fQADataMaker[iDet])->Finish() ;
95 delete fQADataMaker[iDet] ;
96 fQADataMaker[iDet] = NULL ;
105 //_____________________________________________________________________________
106 AliLoader * AliQADataMakerSteer::GetLoader(Int_t iDet)
108 // get the loader for a detector
110 TString detName = AliQA::GetDetName(iDet) ;
111 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
113 return fLoader[iDet] ;
115 // load the QA data maker object
116 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
117 TString loaderName = "Ali" + detName + "Loader" ;
119 AliLoader * loader = NULL ;
120 // first check if a plugin is defined for the quality assurance data maker
121 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
122 // if not, add a plugin for it
123 if (!pluginHandler) {
124 AliDebug(1, Form("defining plugin for %s", loaderName.Data())) ;
125 TString libs = gSystem->GetLibraries() ;
126 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
127 pluginManager->AddHandler("AliQADataMaker", detName, loaderName, detName + "loader", loaderName + "()") ;
129 pluginManager->AddHandler("AliLoader", detName, loaderName, detName, loaderName + "()") ;
131 pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
133 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
134 loader = (AliLoader *) pluginHandler->ExecPlugin(0) ;
137 fLoader[iDet] = loader ;
141 //_____________________________________________________________________________
142 AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(Int_t iDet)
144 // get the quality assurance data maker for a detector
146 if (fQADataMaker[iDet])
147 return fQADataMaker[iDet] ;
149 AliQADataMaker * qadm = NULL ;
152 // load the QA data maker object
153 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
154 TString detName = AliQA::GetDetName(iDet) ;
155 TString qadmName = "Ali" + detName + "QADataMaker" ;
157 // first check if a plugin is defined for the quality assurance data maker
158 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
159 // if not, add a plugin for it
160 if (!pluginHandler) {
161 AliDebug(1, Form("defining plugin for %s", qadmName.Data())) ;
162 TString libs = gSystem->GetLibraries() ;
163 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
164 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ;
166 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ;
168 pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
170 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
171 qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ;
174 fQADataMaker[iDet] = qadm ;
179 //_____________________________________________________________________________
180 Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, const char * fileName )
182 // Initialize the event source and QA data makers
184 if (taskIndex == AliQA::kRAWS) {
185 fRawReader = new AliRawReaderRoot(fileName) ;
188 fRawReader->NextEvent() ;
189 fRunNumber = fRawReader->GetRunNumber() ;
190 fRawReader->RewindEvents();
191 fNumberOfEvents = 999999 ;
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() ;
202 AliError("AliESDs.root not found") ;
206 if ( !InitRunLoader() ) {
207 AliError("Problems in getting the Run Loader") ;
210 if (fRunLoader->GetAliRun())
211 fRunNumber = fRunLoader->GetAliRun()->GetRunNumber() ;
212 fNumberOfEvents = fRunLoader->GetNumberOfEvents() ;
216 // Initialize all QA data makers for all detectors
217 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
218 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
220 AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ;
222 AliInfo(Form("Data Maker found for %s", qadm->GetName())) ;
223 qadm->Init(taskIndex, fRunNumber, GetQACycles(iDet)) ;
224 qadm->StartOfCycle(taskIndex, fCycleSame) ;
231 //_____________________________________________________________________________
232 Bool_t AliQADataMakerSteer::InitRunLoader()
234 // get or create the run loader
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")
247 if (libs.Contains("lib" + detName + "base.so"))
249 gSystem->Load("lib" + detName + "base.so");
251 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
253 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
256 fRunLoader->CdGAFile();
257 if (fRunLoader->LoadgAlice() == 0) {
258 gAlice = fRunLoader->GetAliRun();
261 AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
265 } else { // galice.root does not exist
266 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
273 //_____________________________________________________________________________
274 Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX taskIndex)
276 // write output to file for all detectors
277 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
278 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
280 qadm->EndOfCycle(taskIndex) ;
286 //_____________________________________________________________________________
287 Bool_t AliQADataMakerSteer::Merge()
293 //_____________________________________________________________________________
294 void AliQADataMakerSteer::Reset()
296 // Reset the default data members
297 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
298 fLoader[iDet] = NULL;
299 if (fQADataMaker[iDet]) {
300 (fQADataMaker[iDet])->Reset() ;
301 // delete fQADataMaker[iDet] ;
302 // fQADataMaker[iDet] = NULL ;
309 fCycleSame = kFALSE ;
313 fNumberOfEvents = 0 ;
316 //_____________________________________________________________________________
317 Bool_t AliQADataMakerSteer::Run(const AliQA::TASKINDEX taskIndex, const char * fileName )
319 // Runs all the QA data Maker for every detector
322 if ( !Init(taskIndex, fileName) )
325 // Fill QA data in event loop
326 for (UInt_t iEvent = 0 ; iEvent < fNumberOfEvents ; iEvent++) {
328 AliInfo(Form("processing event %d", iEvent));
329 if ( taskIndex == AliQA::kRAWS ) {
330 if ( !fRawReader->NextEvent() )
332 } else if ( taskIndex == AliQA::kESDS ) {
333 fESDTree->GetEntry(iEvent) ;
335 fRunLoader->GetEvent(iEvent);
337 // loop over detectors
338 TObjArray* detArray = fRunLoader->GetAliRun()->Detectors() ;
339 for (UInt_t iDet = 0 ; iDet < fgkNDetectors ; iDet++) {
340 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
341 if (!det || !det->IsActive())
343 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
347 if ( qadm->IsCycleDone() ) {
348 qadm->EndOfCycle(AliQA::kRAWS) ;
349 qadm->StartOfCycle(AliQA::kRAWS) ;
354 qadm->Exec(taskIndex, fRawReader) ;
357 GetLoader(iDet)->LoadHits() ;
358 data = GetLoader(iDet)->TreeH() ;
360 AliWarning(Form(" Hit Tree not found for %s", AliQA::GetDetName(iDet))) ;
362 qadm->Exec(taskIndex, data) ;
365 case AliQA::kSDIGITS :
366 GetLoader(iDet)->LoadSDigits() ;
367 data = GetLoader(iDet)->TreeS() ;
369 AliWarning(Form(" SDigit Tree not found for %s", AliQA::GetDetName(iDet))) ;
371 qadm->Exec(taskIndex, data) ;
374 case AliQA::kDIGITS :
375 GetLoader(iDet)->LoadDigits() ;
376 data = GetLoader(iDet)->TreeD() ;
378 AliWarning(Form(" Digit Tree not found for %s", AliQA::GetDetName(iDet))) ;
380 qadm->Exec(taskIndex, data) ;
383 case AliQA::kRECPOINTS :
384 GetLoader(iDet)->LoadRecPoints() ;
385 data = GetLoader(iDet)->TreeR() ;
387 AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ;
389 qadm->Exec(taskIndex, data) ;
392 case AliQA::kTRACKSEGMENTS :
394 case AliQA::kRECPARTICLES :
397 qadm->Exec(taskIndex, fESD) ;
404 // Save QA data for all detectors
405 rv = Finish(taskIndex) ;