Splitting of the QA maker into simulation and reconstruction dependent parts (Yves)
[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
4edbc5bc 18#include <TKey.h>
312e6f8d 19#include <TFile.h>
567d83d9 20#include <TFileMerger.h>
312e6f8d 21#include <TPluginManager.h>
22#include <TROOT.h>
23#include <TString.h>
24#include <TSystem.h>
25
4edbc5bc 26#include "AliCDBManager.h"
27#include "AliCDBEntry.h"
28#include "AliCDBId.h"
29#include "AliCDBMetaData.h"
312e6f8d 30#include "AliESDEvent.h"
6441b07a 31#include "AliHeader.h"
312e6f8d 32#include "AliLog.h"
007fcebb 33#include "AliModule.h"
312e6f8d 34#include "AliQA.h"
04236e67 35#include "AliQADataMakerRec.h"
36#include "AliQADataMakerSim.h"
312e6f8d 37#include "AliQADataMakerSteer.h"
4ecde5fc 38#include "AliRawReaderDate.h"
39#include "AliRawReaderFile.h"
312e6f8d 40#include "AliRawReaderRoot.h"
41#include "AliRun.h"
42#include "AliRunLoader.h"
43
44ClassImp(AliQADataMakerSteer)
45
46//_____________________________________________________________________________
47AliQADataMakerSteer::AliQADataMakerSteer(const char* gAliceFilename, const char * name, const char * title) :
48 TNamed(name, title),
c65c502a 49 fCycleSame(kFALSE),
4d52736b 50 fDetectors("ALL"),
312e6f8d 51 fESD(NULL),
52 fESDTree(NULL),
53 fFirst(kTRUE),
54 fGAliceFileName(gAliceFilename),
55 fRunNumber(0),
774ac967 56 fNumberOfEvents(999999),
312e6f8d 57 fRawReader(NULL),
6441b07a 58 fRawReaderDelete(kTRUE),
312e6f8d 59 fRunLoader(NULL)
60{
61 // default ctor
62 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4d52736b 63 if (IsSelected(AliQA::GetDetName(iDet))) {
64 fLoader[iDet] = NULL ;
65 fQADataMaker[iDet] = NULL ;
66 fQACycles[iDet] = 999999 ;
67 }
312e6f8d 68 }
69}
70
71//_____________________________________________________________________________
72AliQADataMakerSteer::AliQADataMakerSteer(const AliQADataMakerSteer & qas) :
73 TNamed(qas),
c65c502a 74 fCycleSame(kFALSE),
4d52736b 75 fDetectors(qas.fDetectors),
312e6f8d 76 fESD(NULL),
77 fESDTree(NULL),
78 fFirst(qas.fFirst),
79 fGAliceFileName(qas.fGAliceFileName),
80 fRunNumber(qas.fRunNumber),
81 fNumberOfEvents(qas.fNumberOfEvents),
82 fRawReader(NULL),
6441b07a 83 fRawReaderDelete(kTRUE),
312e6f8d 84 fRunLoader(NULL)
85{
86 // cpy ctor
87 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
88 fLoader[iDet] = qas.fLoader[iDet] ;
89 fQADataMaker[iDet] = qas.fQADataMaker[iDet] ;
90 fQACycles[iDet] = qas.fQACycles[iDet] ;
91 }
92}
93
94//_____________________________________________________________________________
95AliQADataMakerSteer & AliQADataMakerSteer::operator = (const AliQADataMakerSteer & qas)
96{
97 // assignment operator
98 this->~AliQADataMakerSteer() ;
99 new(this) AliQADataMakerSteer(qas) ;
100 return *this ;
101}
102
103//_____________________________________________________________________________
104AliQADataMakerSteer::~AliQADataMakerSteer()
105{
106 // dtor
107 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4d52736b 108 if (IsSelected(AliQA::GetDetName(iDet))) {
109 fLoader[iDet] = NULL;
110 if (fQADataMaker[iDet]) {
111 (fQADataMaker[iDet])->Finish() ;
112 delete fQADataMaker[iDet] ;
113 fQADataMaker[iDet] = NULL ;
114 }
115 }
312e6f8d 116 }
117
6441b07a 118 if (fRawReaderDelete) {
119 fRunLoader = NULL ;
120 delete fRawReader ;
121 fRawReader = NULL ;
122 }
312e6f8d 123}
124
125//_____________________________________________________________________________
04236e67 126Bool_t AliQADataMakerSteer::DoIt(const AliQA::TASKINDEX taskIndex, const char * mode)
4d52736b 127{
128 // Runs all the QA data Maker for every detector
129 Bool_t rv = kFALSE ;
130
131 // Fill QA data in event loop
132 for (UInt_t iEvent = 0 ; iEvent < fNumberOfEvents ; iEvent++) {
133 // Get the event
134 AliDebug(1, Form("processing event %d", iEvent));
135 if ( taskIndex == AliQA::kRAWS ) {
136 if ( !fRawReader->NextEvent() )
137 break ;
138 } else if ( taskIndex == AliQA::kESDS ) {
774ac967 139 if ( fESDTree->GetEntry(iEvent) == 0 )
140 break ;
4d52736b 141 } else {
774ac967 142 if ( fRunLoader->GetEvent(iEvent) != 0 )
143 break ;
4d52736b 144 }
145 // loop over detectors
146 TObjArray* detArray = NULL ;
147 if (fRunLoader) // check if RunLoader exists
148 if ( fRunLoader->GetAliRun() ) // check if AliRun exists in gAlice.root
149 detArray = fRunLoader->GetAliRun()->Detectors() ;
150 for (UInt_t iDet = 0 ; iDet < fgkNDetectors ; iDet++) {
151 if (detArray) {
152 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
153 if (!det || !det->IsActive())
154 continue ;
155 }
156 if (!IsSelected(AliQA::GetDetName(iDet)))
157 continue ;
04236e67 158 AliQADataMaker * qadm = GetQADataMaker(iDet, mode) ;
4d52736b 159 if (!qadm) {
160 rv = kFALSE ;
161 } else {
162 if ( qadm->IsCycleDone() ) {
163 qadm->EndOfCycle(AliQA::kRAWS) ;
164 qadm->StartOfCycle(AliQA::kRAWS) ;
165 }
166 TTree * data ;
167 switch (taskIndex) {
168 case AliQA::kRAWS :
169 qadm->Exec(taskIndex, fRawReader) ;
170 break ;
171 case AliQA::kHITS :
172 GetLoader(iDet)->LoadHits() ;
173 data = GetLoader(iDet)->TreeH() ;
174 if ( ! data ) {
175 AliWarning(Form(" Hit Tree not found for %s", AliQA::GetDetName(iDet))) ;
176 } else {
177 qadm->Exec(taskIndex, data) ;
178 }
179 break ;
180 case AliQA::kSDIGITS :
181 GetLoader(iDet)->LoadSDigits() ;
182 data = GetLoader(iDet)->TreeS() ;
183 if ( ! data ) {
184 AliWarning(Form(" SDigit Tree not found for %s", AliQA::GetDetName(iDet))) ;
185 } else {
186 qadm->Exec(taskIndex, data) ;
187 }
188 break;
189 case AliQA::kDIGITS :
190 GetLoader(iDet)->LoadDigits() ;
191 data = GetLoader(iDet)->TreeD() ;
192 if ( ! data ) {
193 AliWarning(Form(" Digit Tree not found for %s", AliQA::GetDetName(iDet))) ;
194 } else {
195 qadm->Exec(taskIndex, data) ;
196 }
197 break;
198 case AliQA::kRECPOINTS :
199 GetLoader(iDet)->LoadRecPoints() ;
200 data = GetLoader(iDet)->TreeR() ;
201 if (!data) {
202 AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ;
203 } else {
204 qadm->Exec(taskIndex, data) ;
205 }
206 break;
207 case AliQA::kTRACKSEGMENTS :
208 break;
209 case AliQA::kRECPARTICLES :
210 break;
211 case AliQA::kESDS :
212 qadm->Exec(taskIndex, fESD) ;
213 break;
4edbc5bc 214 case AliQA::kNTASKINDEX :
215 break;
4d52736b 216 } //task switch
217 qadm->Increment() ;
218 } //data maker exist
219 } // detector loop
220 } // event loop
221 // Save QA data for all detectors
04236e67 222 rv = Finish(taskIndex, mode) ;
4d52736b 223 return rv ;
224}
225
226//_____________________________________________________________________________
04236e67 227Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX taskIndex, const char * mode)
4edbc5bc 228{
229 // write output to file for all detectors
230 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
231 if (IsSelected(AliQA::GetDetName(iDet))) {
04236e67 232 AliQADataMaker * qadm = GetQADataMaker(iDet, mode) ;
4edbc5bc 233 if (qadm) {
234 qadm->EndOfCycle(taskIndex) ;
235 }
236 }
237 }
238 return kTRUE ;
239}
240
241//_____________________________________________________________________________
f73f556a 242TObjArray * AliQADataMakerSteer::GetFromOCDB(AliQA::DETECTORINDEX det, AliQA::TASKINDEX task) const
4edbc5bc 243{
244 // Retrieve the list of QA data for a given detector and a given task
f73f556a 245 TObjArray * rv = NULL ;
246 TString tmp(AliQA::GetQARefStorage()) ;
247 if ( tmp.IsNull() ) {
248 AliError("No storage defined, use AliQA::SetQARefStorage") ;
249 return NULL ;
250 }
4edbc5bc 251 AliCDBManager* man = AliCDBManager::Instance() ;
f73f556a 252 if ( ! man->IsDefaultStorageSet() ) {
253 man->SetDefaultStorage(AliQA::GetQARefDefaultStorage()) ;
254 man->SetSpecificStorage(Form("%s/*", AliQA::GetQAOCDBDirName()), AliQA::GetQARefStorage()) ;
255 }
256 char detOCDBDir[10] ;
257 sprintf(detOCDBDir, "%s/%s/%s", AliQA::GetQAOCDBDirName(), AliQA::GetDetName((Int_t)det), AliQA::GetRefOCDBDirName()) ;
258 AliInfo(Form("Retrieving reference data from %s/%s for %s", AliQA::GetQARefStorage(), detOCDBDir, AliQA::GetTaskName(task).Data())) ;
259 AliCDBEntry* entry = man->Get(detOCDBDir, 0) ; //FIXME 0 --> Run Number
4edbc5bc 260 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
261 if ( listDetQAD )
f73f556a 262 rv = dynamic_cast<TObjArray *>(listDetQAD->FindObject(AliQA::GetTaskName(task))) ;
4edbc5bc 263 return rv ;
264}
265
266//_____________________________________________________________________________
312e6f8d 267AliLoader * AliQADataMakerSteer::GetLoader(Int_t iDet)
268{
269 // get the loader for a detector
270
271 TString detName = AliQA::GetDetName(iDet) ;
272 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
273 if (fLoader[iDet])
274 return fLoader[iDet] ;
275
276 // load the QA data maker object
277 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
278 TString loaderName = "Ali" + detName + "Loader" ;
279
280 AliLoader * loader = NULL ;
281 // first check if a plugin is defined for the quality assurance data maker
282 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
283 // if not, add a plugin for it
284 if (!pluginHandler) {
285 AliDebug(1, Form("defining plugin for %s", loaderName.Data())) ;
286 TString libs = gSystem->GetLibraries() ;
287 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
288 pluginManager->AddHandler("AliQADataMaker", detName, loaderName, detName + "loader", loaderName + "()") ;
289 } else {
290 pluginManager->AddHandler("AliLoader", detName, loaderName, detName, loaderName + "()") ;
291 }
292 pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
293 }
294 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
295 loader = (AliLoader *) pluginHandler->ExecPlugin(0) ;
296 }
297 if (loader)
298 fLoader[iDet] = loader ;
299 return loader ;
300}
301
302//_____________________________________________________________________________
04236e67 303AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(const Int_t iDet, const char * mode )
312e6f8d 304{
305 // get the quality assurance data maker for a detector
306
307 if (fQADataMaker[iDet])
308 return fQADataMaker[iDet] ;
309
310 AliQADataMaker * qadm = NULL ;
311
312 if (fFirst) {
313 // load the QA data maker object
314 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
315 TString detName = AliQA::GetDetName(iDet) ;
04236e67 316 TString qadmName = "Ali" + detName + "QADataMaker" + mode ;
312e6f8d 317
318 // first check if a plugin is defined for the quality assurance data maker
319 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
320 // if not, add a plugin for it
321 if (!pluginHandler) {
322 AliDebug(1, Form("defining plugin for %s", qadmName.Data())) ;
323 TString libs = gSystem->GetLibraries() ;
04236e67 324 if (libs.Contains("lib" + detName + mode + ".so") || (gSystem->Load("lib" + detName + mode + ".so") >= 0)) {
312e6f8d 325 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ;
326 } else {
327 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ;
328 }
329 pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
330 }
331 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
332 qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ;
333 }
334 if (qadm)
335 fQADataMaker[iDet] = qadm ;
336 }
337 return qadm ;
338}
339
340//_____________________________________________________________________________
04236e67 341Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, const char * mode, const char * input )
312e6f8d 342{
343 // Initialize the event source and QA data makers
344
6441b07a 345 if (taskIndex == AliQA::kRAWS) {
346 if (!fRawReader) {
347 TString fileName(input);
348 if (fileName.EndsWith("/")) {
349 fRawReader = new AliRawReaderFile(fileName);
350 } else if (fileName.EndsWith(".root")) {
351 fRawReader = new AliRawReaderRoot(fileName);
352 } else if (!fileName.IsNull()) {
353 fRawReader = new AliRawReaderDate(fileName);
354 fRawReader->SelectEvents(7);
355 }
4ecde5fc 356 }
312e6f8d 357 if ( ! fRawReader )
358 return kFALSE ;
04236e67 359 fRawReaderDelete = kFALSE ;
312e6f8d 360 fRawReader->NextEvent() ;
361 fRunNumber = fRawReader->GetRunNumber() ;
04236e67 362 AliCDBManager::Instance()->SetRun(fRunNumber) ;
312e6f8d 363 fRawReader->RewindEvents();
364 fNumberOfEvents = 999999 ;
ad265f3e 365 } else if (taskIndex == AliQA::kESDS) {
366 if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists
367 TFile * esdFile = TFile::Open("AliESDs.root") ;
368 fESDTree = dynamic_cast<TTree *> (esdFile->Get("esdTree")) ;
04236e67 369 if ( !fESDTree ) {
370 AliError("esdTree not found") ;
371 return kFALSE ;
372 } else {
373 fESD = new AliESDEvent() ;
374 fESD->ReadFromTree(fESDTree) ;
375 fESDTree->GetEntry(0) ;
376 fRunNumber = fESD->GetRunNumber() ;
377 fNumberOfEvents = fESDTree->GetEntries() ;
378 }
ad265f3e 379 } else {
380 AliError("AliESDs.root not found") ;
381 return kFALSE ;
382 }
312e6f8d 383 } else {
774ac967 384 if ( !InitRunLoader() ) {
385 AliWarning("No Run Loader not found") ;
312e6f8d 386 } else {
312e6f8d 387 fNumberOfEvents = fRunLoader->GetNumberOfEvents() ;
388 }
ad265f3e 389 }
774ac967 390 // Initialize all QA data makers for all detectors
312e6f8d 391 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4d52736b 392 if (IsSelected(AliQA::GetDetName(iDet))) {
04236e67 393 AliQADataMaker * qadm = GetQADataMaker(iDet, mode) ;
4d52736b 394 if (!qadm) {
395 AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ;
396 } else {
397 AliInfo(Form("Data Maker found for %s", qadm->GetName())) ;
398 qadm->Init(taskIndex, fRunNumber, GetQACycles(iDet)) ;
399 qadm->StartOfCycle(taskIndex, fCycleSame) ;
400 }
312e6f8d 401 }
402 }
403 fFirst = kFALSE ;
404 return kTRUE ;
405}
406
407//_____________________________________________________________________________
408Bool_t AliQADataMakerSteer::InitRunLoader()
409{
410 // get or create the run loader
411 if (fRunLoader) {
c65c502a 412 fCycleSame = kTRUE ;
312e6f8d 413 return kTRUE ;
414 }
415
416 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
417 // load all base libraries to get the loader classes
418 TString libs = gSystem->GetLibraries() ;
419 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4d52736b 420 if (!IsSelected(AliQA::GetDetName(iDet)))
421 continue ;
312e6f8d 422 TString detName = AliQA::GetDetName(iDet) ;
423 if (detName == "HLT")
424 continue;
425 if (libs.Contains("lib" + detName + "base.so"))
426 continue;
427 gSystem->Load("lib" + detName + "base.so");
428 }
429 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
430 if (!fRunLoader) {
431 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
432 return kFALSE;
433 }
434 fRunLoader->CdGAFile();
435 if (fRunLoader->LoadgAlice() == 0) {
436 gAlice = fRunLoader->GetAliRun();
437 }
4d52736b 438
312e6f8d 439 if (!gAlice) {
440 AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
441 return kFALSE;
442 }
443
444 } else { // galice.root does not exist
445 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
446 return kFALSE;
447 }
448
449 return kTRUE;
450}
451
452//_____________________________________________________________________________
04236e67 453Bool_t AliQADataMakerSteer::IsSelected(const char * det)
454{
455 // check whether detName is contained in detectors
456 // if yes, it is removed from detectors
457
458 const TString detName(det) ;
459 // check if all detectors are selected
460 if ((fDetectors.CompareTo("ALL") == 0) ||
461 fDetectors.BeginsWith("ALL ") ||
462 fDetectors.EndsWith(" ALL") ||
463 fDetectors.Contains(" ALL ")) {
464 fDetectors = "ALL";
465 return kTRUE;
466 }
467
468 // search for the given detector
469 Bool_t rv = kFALSE;
470 if ((fDetectors.CompareTo(detName) == 0) ||
471 fDetectors.BeginsWith(detName+" ") ||
472 fDetectors.EndsWith(" "+detName) ||
473 fDetectors.Contains(" "+detName+" ")) {
474 // fDetectors.ReplaceAll(detName, "");
475 rv = kTRUE;
476 }
477
478 // clean up the detectors string
479 // while (fDetectors.Contains(" "))
480 // fDetectors.ReplaceAll(" ", " ");
481 // while (fDetectors.BeginsWith(" "))
482 // fDetectors.Remove(0, 1);
483 // while (fDetectors.EndsWith(" "))
484 // fDetectors.Remove(fDetectors.Length()-1, 1);
485
486 return rv ;
487}
488
489//_____________________________________________________________________________
4edbc5bc 490Bool_t AliQADataMakerSteer::Merge(const Int_t runNumber) const
315bba70 491{
567d83d9 492 // Merge all the cycles from all detectors in one single file per run
4edbc5bc 493 char cmd[80] ;
494 if ( runNumber == -1 )
495 sprintf(cmd, ".! ls *%s*.*.*.root > tempo.txt", AliQA::GetQADataFileName()) ;
496 else
497 sprintf(cmd, ".! ls *%s*.%d.*.root > tempo.txt", AliQA::GetQADataFileName(), runNumber) ;
498 gROOT->ProcessLine(cmd) ;
567d83d9 499 ifstream in("tempo.txt") ;
500 const Int_t runMax = 10 ;
501 TString file[AliQA::kNDET*runMax] ;
502 Int_t run[AliQA::kNDET*runMax] ;
503
504 Int_t index = 0 ;
505 while ( 1 ) {
4edbc5bc 506 in >> file[index] ;
567d83d9 507 if ( !in.good() )
508 break ;
4edbc5bc 509 index++ ;
510 }
511
512 if ( index == 0 ) {
513 AliError(Form("run number %d not found", runNumber)) ;
514 return kFALSE ;
567d83d9 515 }
4edbc5bc 516
567d83d9 517 Int_t previousRun = -1 ;
518 Int_t runIndex = 0 ;
4edbc5bc 519 char stmp[10] ;
520 sprintf(stmp, ".%s.", AliQA::GetQADataFileName()) ;
567d83d9 521 for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) {
522 TString tmp(file[ifile]) ;
523 tmp.ReplaceAll(".root", "") ;
524 TString det = tmp(0, tmp.Index(".")) ;
4edbc5bc 525 tmp.Remove(0, tmp.Index(stmp)+4) ;
567d83d9 526 TString ttmp = tmp(0, tmp.Index(".")) ;
527 Int_t newRun = ttmp.Atoi() ;
528 if (newRun != previousRun) {
529 run[runIndex] = newRun ;
530 previousRun = newRun ;
531 runIndex++ ;
532 }
533 ttmp = tmp(tmp.Index("."), tmp.Length()) ;
534 Int_t cycle = ttmp.Atoi() ;
535 AliInfo(Form("%s : det = %s run = %d cycle = %d \n", file[ifile].Data(), det.Data(), newRun, cycle)) ;
536 }
537 for (Int_t irun = 0 ; irun < runIndex ; irun++) {
538 TFileMerger merger ;
4edbc5bc 539 char outFileName[20] ;
540 sprintf(outFileName, "Merged.%s.%d.root", AliQA::GetQADataFileName(), runIndex-1) ;
567d83d9 541 merger.OutputFile(outFileName) ;
542 for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) {
543 char pattern[100] ;
4edbc5bc 544 sprintf(pattern, "%s.%d.", AliQA::GetQADataFileName(), runIndex-1) ;
567d83d9 545 TString tmp(file[ifile]) ;
546 if (tmp.Contains(pattern))
547 merger.AddFile(tmp) ;
548 }
549 merger.Merge() ;
550 }
551
552 return kTRUE ;
315bba70 553}
554
555//_____________________________________________________________________________
c65c502a 556void AliQADataMakerSteer::Reset()
557{
558 // Reset the default data members
559 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4d52736b 560 if (IsSelected(AliQA::GetDetName(iDet))) {
561 fLoader[iDet] = NULL;
562 if (fQADataMaker[iDet]) {
563 (fQADataMaker[iDet])->Reset() ;
564 //delete fQADataMaker[iDet] ;
565 //fQADataMaker[iDet] = NULL ;
566 }
c65c502a 567 }
568 }
569
6441b07a 570 if (fRawReaderDelete) {
571 delete fRawReader ;
572 fRawReader = NULL ;
573 }
c65c502a 574
575 fCycleSame = kFALSE ;
576 fESD = NULL ;
577 fESDTree = NULL ;
578 fFirst = kTRUE ;
774ac967 579 fNumberOfEvents = 999999 ;
c65c502a 580}
581
582//_____________________________________________________________________________
4d52736b 583Bool_t AliQADataMakerSteer::Run(const char * detectors, AliRawReader * rawReader)
6441b07a 584{
585 //Runs all the QA data Maker for Raws only
4d52736b 586 fRawReader = rawReader ;
6441b07a 587 fRawReaderDelete = kFALSE ;
4d52736b 588 fCycleSame = kTRUE ;
589 fDetectors = detectors ;
6441b07a 590
591 // Initialize all QA data makers for all detectors
592 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4d52736b 593 if (IsSelected(AliQA::GetDetName(iDet))) {
04236e67 594 AliQADataMaker * qadm = GetQADataMaker(iDet, "Rec") ;
4d52736b 595 if (!qadm) {
596 AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ;
597 } else {
598 AliInfo(Form("Data Maker found for %s", qadm->GetName())) ;
599 qadm->Init(AliQA::kRAWS, fRunNumber, GetQACycles(iDet)) ;
600 qadm->StartOfCycle(AliQA::kRAWS, fCycleSame) ;
601 }
6441b07a 602 }
603 }
604 fFirst = kFALSE ;
605
04236e67 606 return DoIt(AliQA::kRAWS, "Rec") ;
607}
608
609//_____________________________________________________________________________
610Bool_t AliQADataMakerSteer::Run(const char * detectors, const char * fileName)
611{
612 //Runs all the QA data Maker for Raws only
613 fCycleSame = kTRUE ;
614 fDetectors = detectors ;
615
616 if ( !Init(AliQA::kRAWS, "Rec", fileName) )
617 return kFALSE ;
618
619 // Initialize all QA data makers for all detectors
620 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
621 if (IsSelected(AliQA::GetDetName(iDet))) {
622 AliQADataMaker * qadm = GetQADataMaker(iDet, "Rec") ;
623 if (!qadm) {
624 AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ;
625 } else {
626 AliInfo(Form("Data Maker found for %s", qadm->GetName())) ;
627 qadm->Init(AliQA::kRAWS, fRunNumber, GetQACycles(iDet)) ;
628 qadm->StartOfCycle(AliQA::kRAWS, fCycleSame) ;
629 }
630 }
631 }
632 fFirst = kFALSE ;
633
634 return DoIt(AliQA::kRAWS, "Rec") ;
6441b07a 635}
636
637//_____________________________________________________________________________
4d52736b 638Bool_t AliQADataMakerSteer::Run(const char * detectors, const AliQA::TASKINDEX taskIndex, const char * fileName )
312e6f8d 639{
640 // Runs all the QA data Maker for every detector
6441b07a 641
4d52736b 642 Bool_t rv = kFALSE ;
643 fDetectors = detectors ;
04236e67 644
645 char * mode ;
646 if ( (taskIndex == AliQA::kHITS) || (taskIndex == AliQA::kSDIGITS) || (taskIndex == AliQA::kDIGITS) )
647 mode = "Sim" ;
648 else if ( (taskIndex == AliQA::kRAWS) || (taskIndex == AliQA::kRECPOINTS) || (taskIndex == AliQA::kESDS) )
649 mode = "Rec" ;
650 else {
651 AliError(Form("%s not implemented", AliQA::GetTaskName(taskIndex).Data())) ;
652 return rv ;
653 }
312e6f8d 654
04236e67 655 if ( !Init(taskIndex, mode, fileName) )
312e6f8d 656 return kFALSE ;
04236e67 657
658 rv = DoIt(taskIndex, mode) ;
4d52736b 659
660 return rv ;
6441b07a 661
14e1eccc 662}
4edbc5bc 663
664//_____________________________________________________________________________
665Bool_t AliQADataMakerSteer::Save2OCDB(const Int_t runNumber, const Int_t cycleNumber, const char * detectors) const
666{
667 // take the locasl QA data merge into a single file and save in OCDB
668 Bool_t rv = kTRUE ;
669 TString tmp(AliQA::GetQARefStorage()) ;
670 if ( tmp.IsNull() ) {
671 AliError("No storage defined, use AliQA::SetQARefStorage") ;
672 return kFALSE ;
673 }
674 if ( !(tmp.Contains(AliQA::GetLabLocalOCDB()) || tmp.Contains(AliQA::GetLabAliEnOCDB())) ) {
675 AliError(Form("%s is a wrong storage, use %s or %s", AliQA::GetQARefStorage(), AliQA::GetLabLocalOCDB().Data(), AliQA::GetLabAliEnOCDB().Data())) ;
676 return kFALSE ;
677 }
678 TString sdet(detectors) ;
679 sdet.ToUpper() ;
680 TFile * inputFile ;
681 if ( sdet.Contains("ALL") ) {
682 rv = Merge(runNumber) ;
683 if ( ! rv )
684 return kFALSE ;
685 char inputFileName[20] ;
686 sprintf(inputFileName, "Merged.%s.%d.root", AliQA::GetQADataFileName(), runNumber) ;
687 inputFile = TFile::Open(inputFileName) ;
f73f556a 688 rv = SaveIt2OCDB(runNumber, inputFile) ;
4edbc5bc 689 } else {
690 for (Int_t index = 0; index < AliQA::kNDET; index++) {
691 if (sdet.Contains(AliQA::GetDetName(index))) {
692 char inputFileName[20] ;
693 sprintf(inputFileName, "%s.%s.%d.%d.root", AliQA::GetDetName(index), AliQA::GetQADataFileName(), runNumber, cycleNumber) ;
694 inputFile = TFile::Open(inputFileName) ;
f73f556a 695 rv *= SaveIt2OCDB(runNumber, inputFile) ;
4edbc5bc 696 }
697 }
698 }
699 return rv ;
700}
701
702//_____________________________________________________________________________
f73f556a 703Bool_t AliQADataMakerSteer::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile) const
4edbc5bc 704{
705 // reads the TH1 from file and adds it to appropriate list before saving to OCDB
706 Bool_t rv = kTRUE ;
707 AliInfo(Form("Saving TH1s in %s to %s", inputFile->GetName(), AliQA::GetQARefStorage())) ;
708 AliCDBManager* man = AliCDBManager::Instance() ;
f73f556a 709 if ( ! man->IsDefaultStorageSet() ) {
710 man->SetDefaultStorage(AliQA::GetQARefDefaultStorage()) ;
711 man->SetSpecificStorage(Form("%s/*", AliQA::GetQAOCDBDirName()), AliQA::GetQARefStorage()) ;
712 }
04236e67 713 if(man->GetRun() < 0)
714 man->SetRun(runNumber);
715
4edbc5bc 716 for ( Int_t detIndex = 0 ; detIndex < AliQA::kNDET ; detIndex++) {
717 TDirectory * detDir = inputFile->GetDirectory(AliQA::GetDetName(detIndex)) ;
718 if ( detDir ) {
719 AliInfo(Form("Entering %s", detDir->GetName())) ;
f73f556a 720 char detOCDBDir[20] ;
721 sprintf(detOCDBDir, "%s/%s/%s", AliQA::GetQAOCDBDirName(), AliQA::GetDetName(detIndex), AliQA::GetRefOCDBDirName()) ;
722 AliCDBId idr(detOCDBDir, runNumber, 999999999) ;
4edbc5bc 723 TList * listDetQAD = new TList() ;
724 char listName[20] ;
725 sprintf(listName, "%s QA data Reference", AliQA::GetDetName(detIndex)) ;
726 listDetQAD->SetName(listName) ;
727 TList * taskList = detDir->GetListOfKeys() ;
728 TIter nextTask(taskList) ;
729 TKey * taskKey ;
730 while ( (taskKey = dynamic_cast<TKey*>(nextTask())) ) {
731 TDirectory * taskDir = detDir->GetDirectory(taskKey->GetName()) ;
732 AliInfo(Form("Saving %s", taskDir->GetName())) ;
f73f556a 733 TObjArray * listTaskQAD = new TObjArray(100) ;
4edbc5bc 734 listTaskQAD->SetName(taskKey->GetName()) ;
735 listDetQAD->Add(listTaskQAD) ;
736 TList * histList = taskDir->GetListOfKeys() ;
737 TIter nextHist(histList) ;
738 TKey * histKey ;
739 while ( (histKey = dynamic_cast<TKey*>(nextHist())) ) {
740 TObject * odata = taskDir->Get(histKey->GetName()) ;
741 if ( odata->IsA()->InheritsFrom("TH1") ) {
742 AliInfo(Form("Adding %s", histKey->GetName())) ;
743 TH1 * hdata = static_cast<TH1*>(odata) ;
744 listTaskQAD->Add(hdata) ;
745 }
746 }
747 }
748 AliCDBMetaData mdr ;
749 man->Put(listDetQAD, idr, &mdr) ;
750 }
751 }
752 return rv ;
753}