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"
27 #include "AliQADataMaker.h"
28 #include "AliQADataMakerSteer.h"
29 #include "AliRawReaderRoot.h"
31 #include "AliRunLoader.h"
33 ClassImp(AliQADataMakerSteer)
35 //_____________________________________________________________________________
36 AliQADataMakerSteer::AliQADataMakerSteer(const char* gAliceFilename, const char * name, const char * title) :
42 fGAliceFileName(gAliceFilename),
49 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
50 fLoader[iDet] = NULL ;
51 fQADataMaker[iDet] = NULL ;
52 fQACycles[iDet] = 999999 ;
56 //_____________________________________________________________________________
57 AliQADataMakerSteer::AliQADataMakerSteer(const AliQADataMakerSteer & qas) :
63 fGAliceFileName(qas.fGAliceFileName),
64 fRunNumber(qas.fRunNumber),
65 fNumberOfEvents(qas.fNumberOfEvents),
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] ;
77 //_____________________________________________________________________________
78 AliQADataMakerSteer & AliQADataMakerSteer::operator = (const AliQADataMakerSteer & qas)
80 // assignment operator
81 this->~AliQADataMakerSteer() ;
82 new(this) AliQADataMakerSteer(qas) ;
86 //_____________________________________________________________________________
87 AliQADataMakerSteer::~AliQADataMakerSteer()
90 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
92 delete fQADataMaker[iDet];
93 fQADataMaker[iDet] = NULL;
102 //_____________________________________________________________________________
103 AliLoader * AliQADataMakerSteer::GetLoader(Int_t iDet)
105 // get the loader for a detector
107 TString detName = AliQA::GetDetName(iDet) ;
108 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
110 return fLoader[iDet] ;
112 // load the QA data maker object
113 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
114 TString loaderName = "Ali" + detName + "Loader" ;
116 AliLoader * loader = NULL ;
117 // first check if a plugin is defined for the quality assurance data maker
118 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
119 // if not, add a plugin for it
120 if (!pluginHandler) {
121 AliDebug(1, Form("defining plugin for %s", loaderName.Data())) ;
122 TString libs = gSystem->GetLibraries() ;
123 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
124 pluginManager->AddHandler("AliQADataMaker", detName, loaderName, detName + "loader", loaderName + "()") ;
126 pluginManager->AddHandler("AliLoader", detName, loaderName, detName, loaderName + "()") ;
128 pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
130 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
131 loader = (AliLoader *) pluginHandler->ExecPlugin(0) ;
134 fLoader[iDet] = loader ;
138 //_____________________________________________________________________________
139 AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(Int_t iDet)
141 // get the quality assurance data maker for a detector
143 if (fQADataMaker[iDet])
144 return fQADataMaker[iDet] ;
146 AliQADataMaker * qadm = NULL ;
149 // load the QA data maker object
150 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
151 TString detName = AliQA::GetDetName(iDet) ;
152 TString qadmName = "Ali" + detName + "QADataMaker" ;
154 // first check if a plugin is defined for the quality assurance data maker
155 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
156 // if not, add a plugin for it
157 if (!pluginHandler) {
158 AliDebug(1, Form("defining plugin for %s", qadmName.Data())) ;
159 TString libs = gSystem->GetLibraries() ;
160 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
161 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ;
163 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ;
165 pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
167 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
168 qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ;
171 fQADataMaker[iDet] = qadm ;
176 //_____________________________________________________________________________
177 Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, const char * fileName )
179 // Initialize the event source and QA data makers
181 if (taskIndex == AliQA::kRAWS) {
182 fRawReader = new AliRawReaderRoot(fileName) ;
185 fRawReader->NextEvent() ;
186 fRunNumber = fRawReader->GetRunNumber() ;
187 fRawReader->RewindEvents();
188 fNumberOfEvents = 999999 ;
190 } else if (taskIndex == AliQA::kESDS) {
191 if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists
192 TFile * esdFile = TFile::Open("AliESDs.root") ;
193 fESDTree = dynamic_cast<TTree *> (esdFile->Get("esdTree")) ;
194 fESD = new AliESDEvent() ;
195 fESD->ReadFromTree(fESDTree) ;
196 fESDTree->GetEntry(0) ;
197 fRunNumber = fESD->GetRunNumber() ;
198 fNumberOfEvents = fESDTree->GetEntries() ;
200 AliError("AliESDs.root not found") ;
205 if ( !InitRunLoader() ) {
206 AliError("Problems in getting the Run Loader") ;
209 fRunNumber = fRunLoader->GetAliRun()->GetRunNumber() ;
210 fNumberOfEvents = fRunLoader->GetNumberOfEvents() ;
214 // Initialize all QA data makers for all detectors
215 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
216 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
218 AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ;
220 AliInfo(Form("Data Maker found for %s", qadm->GetName())) ;
221 qadm->Init(taskIndex, fRunNumber, GetQACycles(iDet)) ;
222 qadm->StartOfCycle(taskIndex, fCycleOption) ;
229 //_____________________________________________________________________________
230 Bool_t AliQADataMakerSteer::InitRunLoader()
232 // get or create the run loader
234 fCycleOption = "same" ;
238 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
239 // load all base libraries to get the loader classes
240 TString libs = gSystem->GetLibraries() ;
241 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
242 TString detName = AliQA::GetDetName(iDet) ;
243 if (detName == "HLT")
245 if (libs.Contains("lib" + detName + "base.so"))
247 gSystem->Load("lib" + detName + "base.so");
249 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
251 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
254 fRunLoader->CdGAFile();
255 if (fRunLoader->LoadgAlice() == 0) {
256 gAlice = fRunLoader->GetAliRun();
259 AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
263 } else { // galice.root does not exist
264 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
271 //_____________________________________________________________________________
272 Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX taskIndex)
274 // write output to file for all detectors
275 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
276 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
278 qadm->EndOfCycle(taskIndex) ;
279 qadm->Finish(taskIndex) ;
285 //_____________________________________________________________________________
286 Bool_t AliQADataMakerSteer::Run(const AliQA::TASKINDEX taskIndex, const char * fileName )
288 // Runs all the QA data Maker for every detector
291 if ( !Init(taskIndex, fileName) )
294 // Fill QA data in event loop
295 for (UInt_t iEvent = 0 ; iEvent < fNumberOfEvents ; iEvent++) {
297 AliInfo(Form("processing event %d", iEvent));
298 if ( taskIndex == AliQA::kRAWS ) {
299 if ( !fRawReader->NextEvent() )
301 } else if ( taskIndex == AliQA::kESDS ) {
302 fESDTree->GetEntry(iEvent) ;
304 fRunLoader->GetEvent(iEvent);
306 // loop over detectors
307 for (UInt_t iDet = 0 ; iDet < fgkNDetectors ; iDet++) {
308 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
312 if ( qadm->IsCycleDone() ) {
313 qadm->EndOfCycle(AliQA::kRAWS) ;
314 qadm->StartOfCycle(AliQA::kRAWS) ;
319 qadm->Exec(taskIndex, fRawReader) ;
322 GetLoader(iDet)->LoadHits() ;
323 data = GetLoader(iDet)->TreeH() ;
325 AliWarning(Form(" Hit Tree not found for %s", AliQA::GetDetName(iDet))) ;
327 qadm->Exec(taskIndex, data) ;
330 case AliQA::kSDIGITS :
331 GetLoader(iDet)->LoadSDigits() ;
332 data = GetLoader(iDet)->TreeS() ;
334 AliWarning(Form(" SDigit Tree not found for %s", AliQA::GetDetName(iDet))) ;
336 qadm->Exec(taskIndex, data) ;
339 case AliQA::kDIGITS :
340 GetLoader(iDet)->LoadDigits() ;
341 data = GetLoader(iDet)->TreeD() ;
343 AliWarning(Form(" Digit Tree not found for %s", AliQA::GetDetName(iDet))) ;
345 qadm->Exec(taskIndex, data) ;
348 case AliQA::kRECPOINTS :
349 GetLoader(iDet)->LoadRecPoints() ;
350 data = GetLoader(iDet)->TreeR() ;
352 AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ;
354 qadm->Exec(taskIndex, data) ;
357 case AliQA::kTRACKSEGMENTS :
359 case AliQA::kRECPARTICLES :
362 qadm->Exec(taskIndex, fESD) ;
369 // Save QA data for all detectors
370 rv = Finish(taskIndex) ;