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 <TFileMerger.h>
20 #include <TPluginManager.h>
25 #include "AliESDEvent.h"
27 #include "AliModule.h"
29 #include "AliQADataMaker.h"
30 #include "AliQADataMakerSteer.h"
31 #include "AliRawReaderDate.h"
32 #include "AliRawReaderFile.h"
33 #include "AliRawReaderRoot.h"
35 #include "AliRunLoader.h"
37 ClassImp(AliQADataMakerSteer)
39 //_____________________________________________________________________________
40 AliQADataMakerSteer::AliQADataMakerSteer(const char* gAliceFilename, const char * name, const char * title) :
46 fGAliceFileName(gAliceFilename),
53 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
54 fLoader[iDet] = NULL ;
55 fQADataMaker[iDet] = NULL ;
56 fQACycles[iDet] = 999999 ;
60 //_____________________________________________________________________________
61 AliQADataMakerSteer::AliQADataMakerSteer(const AliQADataMakerSteer & qas) :
67 fGAliceFileName(qas.fGAliceFileName),
68 fRunNumber(qas.fRunNumber),
69 fNumberOfEvents(qas.fNumberOfEvents),
74 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
75 fLoader[iDet] = qas.fLoader[iDet] ;
76 fQADataMaker[iDet] = qas.fQADataMaker[iDet] ;
77 fQACycles[iDet] = qas.fQACycles[iDet] ;
81 //_____________________________________________________________________________
82 AliQADataMakerSteer & AliQADataMakerSteer::operator = (const AliQADataMakerSteer & qas)
84 // assignment operator
85 this->~AliQADataMakerSteer() ;
86 new(this) AliQADataMakerSteer(qas) ;
90 //_____________________________________________________________________________
91 AliQADataMakerSteer::~AliQADataMakerSteer()
94 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
96 if (fQADataMaker[iDet]) {
97 (fQADataMaker[iDet])->Finish() ;
98 delete fQADataMaker[iDet] ;
99 fQADataMaker[iDet] = NULL ;
108 //_____________________________________________________________________________
109 AliLoader * AliQADataMakerSteer::GetLoader(Int_t iDet)
111 // get the loader for a detector
113 TString detName = AliQA::GetDetName(iDet) ;
114 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
116 return fLoader[iDet] ;
118 // load the QA data maker object
119 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
120 TString loaderName = "Ali" + detName + "Loader" ;
122 AliLoader * loader = NULL ;
123 // first check if a plugin is defined for the quality assurance data maker
124 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
125 // if not, add a plugin for it
126 if (!pluginHandler) {
127 AliDebug(1, Form("defining plugin for %s", loaderName.Data())) ;
128 TString libs = gSystem->GetLibraries() ;
129 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
130 pluginManager->AddHandler("AliQADataMaker", detName, loaderName, detName + "loader", loaderName + "()") ;
132 pluginManager->AddHandler("AliLoader", detName, loaderName, detName, loaderName + "()") ;
134 pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
136 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
137 loader = (AliLoader *) pluginHandler->ExecPlugin(0) ;
140 fLoader[iDet] = loader ;
144 //_____________________________________________________________________________
145 AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(Int_t iDet)
147 // get the quality assurance data maker for a detector
149 if (fQADataMaker[iDet])
150 return fQADataMaker[iDet] ;
152 AliQADataMaker * qadm = NULL ;
155 // load the QA data maker object
156 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
157 TString detName = AliQA::GetDetName(iDet) ;
158 TString qadmName = "Ali" + detName + "QADataMaker" ;
160 // first check if a plugin is defined for the quality assurance data maker
161 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
162 // if not, add a plugin for it
163 if (!pluginHandler) {
164 AliDebug(1, Form("defining plugin for %s", qadmName.Data())) ;
165 TString libs = gSystem->GetLibraries() ;
166 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
167 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ;
169 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ;
171 pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
173 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
174 qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ;
177 fQADataMaker[iDet] = qadm ;
182 //_____________________________________________________________________________
183 Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, const char * input )
185 // Initialize the event source and QA data makers
187 if (taskIndex == AliQA::kRAWS) {
188 TString fileName(input);
189 if (fileName.EndsWith("/")) {
190 fRawReader = new AliRawReaderFile(fileName);
191 } else if (fileName.EndsWith(".root")) {
192 fRawReader = new AliRawReaderRoot(fileName);
193 } else if (!fileName.IsNull()) {
194 fRawReader = new AliRawReaderDate(fileName);
195 fRawReader->SelectEvents(7);
199 fRawReader->NextEvent() ;
200 fRunNumber = fRawReader->GetRunNumber() ;
201 fRawReader->RewindEvents();
202 fNumberOfEvents = 999999 ;
203 } else if (taskIndex == AliQA::kESDS) {
204 if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists
205 TFile * esdFile = TFile::Open("AliESDs.root") ;
206 fESDTree = dynamic_cast<TTree *> (esdFile->Get("esdTree")) ;
207 fESD = new AliESDEvent() ;
208 fESD->ReadFromTree(fESDTree) ;
209 fESDTree->GetEntry(0) ;
210 fRunNumber = fESD->GetRunNumber() ;
211 fNumberOfEvents = fESDTree->GetEntries() ;
213 AliError("AliESDs.root not found") ;
217 if ( !InitRunLoader() ) {
218 AliError("Run Loader not found") ;
221 if (fRunLoader->GetAliRun())
222 fRunNumber = fRunLoader->GetAliRun()->GetRunNumber() ;
223 fNumberOfEvents = fRunLoader->GetNumberOfEvents() ;
227 // Initialize all QA data makers for all detectors
228 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
229 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
231 AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ;
233 AliInfo(Form("Data Maker found for %s", qadm->GetName())) ;
234 qadm->Init(taskIndex, fRunNumber, GetQACycles(iDet)) ;
235 qadm->StartOfCycle(taskIndex, fCycleSame) ;
242 //_____________________________________________________________________________
243 Bool_t AliQADataMakerSteer::InitRunLoader()
245 // get or create the run loader
251 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
252 // load all base libraries to get the loader classes
253 TString libs = gSystem->GetLibraries() ;
254 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
255 TString detName = AliQA::GetDetName(iDet) ;
256 if (detName == "HLT")
258 if (libs.Contains("lib" + detName + "base.so"))
260 gSystem->Load("lib" + detName + "base.so");
262 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
264 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
267 fRunLoader->CdGAFile();
268 if (fRunLoader->LoadgAlice() == 0) {
269 gAlice = fRunLoader->GetAliRun();
272 AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
276 } else { // galice.root does not exist
277 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
284 //_____________________________________________________________________________
285 Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX taskIndex)
287 // write output to file for all detectors
288 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
289 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
291 qadm->EndOfCycle(taskIndex) ;
297 //_____________________________________________________________________________
298 Bool_t AliQADataMakerSteer::Merge()
300 // Merge all the cycles from all detectors in one single file per run
302 gROOT->ProcessLine(".! ls *QA*.*.*.root > tempo.txt") ;
303 ifstream in("tempo.txt") ;
304 const Int_t runMax = 10 ;
305 TString file[AliQA::kNDET*runMax] ;
306 Int_t run[AliQA::kNDET*runMax] ;
310 in >> file[index++] ;
314 Int_t previousRun = -1 ;
316 for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) {
317 TString tmp(file[ifile]) ;
318 tmp.ReplaceAll(".root", "") ;
319 TString det = tmp(0, tmp.Index(".")) ;
320 tmp.Remove(0, tmp.Index(".QA.")+4) ;
321 TString ttmp = tmp(0, tmp.Index(".")) ;
322 Int_t newRun = ttmp.Atoi() ;
323 if (newRun != previousRun) {
324 run[runIndex] = newRun ;
325 previousRun = newRun ;
328 ttmp = tmp(tmp.Index("."), tmp.Length()) ;
329 Int_t cycle = ttmp.Atoi() ;
330 AliInfo(Form("%s : det = %s run = %d cycle = %d \n", file[ifile].Data(), det.Data(), newRun, cycle)) ;
332 for (Int_t irun = 0 ; irun < runIndex ; irun++) {
334 char outFileName[runMax] ;
335 sprintf(outFileName, "Merged.QA.%d.root", runIndex-1) ;
336 merger.OutputFile(outFileName) ;
337 for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) {
339 sprintf(pattern, "QA.%d.", runIndex-1) ;
340 TString tmp(file[ifile]) ;
341 if (tmp.Contains(pattern))
342 merger.AddFile(tmp) ;
350 //_____________________________________________________________________________
351 void AliQADataMakerSteer::Reset()
353 // Reset the default data members
354 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
355 fLoader[iDet] = NULL;
356 if (fQADataMaker[iDet]) {
357 (fQADataMaker[iDet])->Reset() ;
358 // delete fQADataMaker[iDet] ;
359 // fQADataMaker[iDet] = NULL ;
366 fCycleSame = kFALSE ;
370 fNumberOfEvents = 0 ;
373 //_____________________________________________________________________________
374 Bool_t AliQADataMakerSteer::Run(const AliQA::TASKINDEX taskIndex, const char * fileName )
376 // Runs all the QA data Maker for every detector
379 if ( !Init(taskIndex, fileName) )
382 // Fill QA data in event loop
383 for (UInt_t iEvent = 0 ; iEvent < fNumberOfEvents ; iEvent++) {
385 AliDebug(1, Form("processing event %d", iEvent));
386 if ( taskIndex == AliQA::kRAWS ) {
387 if ( !fRawReader->NextEvent() )
389 } else if ( taskIndex == AliQA::kESDS ) {
390 fESDTree->GetEntry(iEvent) ;
392 fRunLoader->GetEvent(iEvent);
394 // loop over detectors
395 TObjArray* detArray = NULL ;
396 if (fRunLoader) // check if RunLoader exists
397 if ( fRunLoader->GetAliRun() ) // check if AliRun exists in gAlice.root
398 detArray = fRunLoader->GetAliRun()->Detectors() ;
399 for (UInt_t iDet = 0 ; iDet < fgkNDetectors ; iDet++) {
401 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
402 if (!det || !det->IsActive())
405 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
409 if ( qadm->IsCycleDone() ) {
410 qadm->EndOfCycle(AliQA::kRAWS) ;
411 qadm->StartOfCycle(AliQA::kRAWS) ;
416 qadm->Exec(taskIndex, fRawReader) ;
419 GetLoader(iDet)->LoadHits() ;
420 data = GetLoader(iDet)->TreeH() ;
422 AliWarning(Form(" Hit Tree not found for %s", AliQA::GetDetName(iDet))) ;
424 qadm->Exec(taskIndex, data) ;
427 case AliQA::kSDIGITS :
428 GetLoader(iDet)->LoadSDigits() ;
429 data = GetLoader(iDet)->TreeS() ;
431 AliWarning(Form(" SDigit Tree not found for %s", AliQA::GetDetName(iDet))) ;
433 qadm->Exec(taskIndex, data) ;
436 case AliQA::kDIGITS :
437 GetLoader(iDet)->LoadDigits() ;
438 data = GetLoader(iDet)->TreeD() ;
440 AliWarning(Form(" Digit Tree not found for %s", AliQA::GetDetName(iDet))) ;
442 qadm->Exec(taskIndex, data) ;
445 case AliQA::kRECPOINTS :
446 GetLoader(iDet)->LoadRecPoints() ;
447 data = GetLoader(iDet)->TreeR() ;
449 AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ;
451 qadm->Exec(taskIndex, data) ;
454 case AliQA::kTRACKSEGMENTS :
456 case AliQA::kRECPARTICLES :
459 qadm->Exec(taskIndex, fESD) ;
466 // Save QA data for all detectors
467 rv = Finish(taskIndex) ;