change the trave of Reset
[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
4d52736b 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
4edbc5bc 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
312e6f8d 266//_____________________________________________________________________________
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) ;
9afca7a6 316 TString tmp(mode) ;
317 if (tmp.Contains("sim"))
318 tmp.ReplaceAll("s", "S") ;
319 else if (tmp.Contains("rec"))
320 tmp.ReplaceAll("r", "R") ;
321 TString qadmName = "Ali" + detName + "QADataMaker" + tmp ;
312e6f8d 322
323 // first check if a plugin is defined for the quality assurance data maker
324 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
325 // if not, add a plugin for it
326 if (!pluginHandler) {
327 AliDebug(1, Form("defining plugin for %s", qadmName.Data())) ;
328 TString libs = gSystem->GetLibraries() ;
04236e67 329 if (libs.Contains("lib" + detName + mode + ".so") || (gSystem->Load("lib" + detName + mode + ".so") >= 0)) {
312e6f8d 330 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ;
331 } else {
332 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ;
333 }
334 pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
335 }
336 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
337 qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ;
338 }
339 if (qadm)
340 fQADataMaker[iDet] = qadm ;
341 }
342 return qadm ;
343}
344
345//_____________________________________________________________________________
04236e67 346Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, const char * mode, const char * input )
312e6f8d 347{
348 // Initialize the event source and QA data makers
349
6441b07a 350 if (taskIndex == AliQA::kRAWS) {
351 if (!fRawReader) {
352 TString fileName(input);
353 if (fileName.EndsWith("/")) {
354 fRawReader = new AliRawReaderFile(fileName);
355 } else if (fileName.EndsWith(".root")) {
356 fRawReader = new AliRawReaderRoot(fileName);
357 } else if (!fileName.IsNull()) {
358 fRawReader = new AliRawReaderDate(fileName);
359 fRawReader->SelectEvents(7);
360 }
4ecde5fc 361 }
312e6f8d 362 if ( ! fRawReader )
363 return kFALSE ;
04236e67 364 fRawReaderDelete = kFALSE ;
312e6f8d 365 fRawReader->NextEvent() ;
366 fRunNumber = fRawReader->GetRunNumber() ;
04236e67 367 AliCDBManager::Instance()->SetRun(fRunNumber) ;
312e6f8d 368 fRawReader->RewindEvents();
369 fNumberOfEvents = 999999 ;
ad265f3e 370 } else if (taskIndex == AliQA::kESDS) {
371 if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists
372 TFile * esdFile = TFile::Open("AliESDs.root") ;
373 fESDTree = dynamic_cast<TTree *> (esdFile->Get("esdTree")) ;
04236e67 374 if ( !fESDTree ) {
375 AliError("esdTree not found") ;
376 return kFALSE ;
377 } else {
378 fESD = new AliESDEvent() ;
379 fESD->ReadFromTree(fESDTree) ;
380 fESDTree->GetEntry(0) ;
381 fRunNumber = fESD->GetRunNumber() ;
382 fNumberOfEvents = fESDTree->GetEntries() ;
383 }
ad265f3e 384 } else {
385 AliError("AliESDs.root not found") ;
386 return kFALSE ;
387 }
312e6f8d 388 } else {
774ac967 389 if ( !InitRunLoader() ) {
390 AliWarning("No Run Loader not found") ;
312e6f8d 391 } else {
312e6f8d 392 fNumberOfEvents = fRunLoader->GetNumberOfEvents() ;
393 }
ad265f3e 394 }
774ac967 395 // Initialize all QA data makers for all detectors
312e6f8d 396 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4d52736b 397 if (IsSelected(AliQA::GetDetName(iDet))) {
04236e67 398 AliQADataMaker * qadm = GetQADataMaker(iDet, mode) ;
4d52736b 399 if (!qadm) {
400 AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ;
401 } else {
402 AliInfo(Form("Data Maker found for %s", qadm->GetName())) ;
403 qadm->Init(taskIndex, fRunNumber, GetQACycles(iDet)) ;
404 qadm->StartOfCycle(taskIndex, fCycleSame) ;
405 }
312e6f8d 406 }
407 }
408 fFirst = kFALSE ;
409 return kTRUE ;
410}
411
412//_____________________________________________________________________________
413Bool_t AliQADataMakerSteer::InitRunLoader()
414{
415 // get or create the run loader
416 if (fRunLoader) {
c65c502a 417 fCycleSame = kTRUE ;
312e6f8d 418 return kTRUE ;
419 }
420
421 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
422 // load all base libraries to get the loader classes
423 TString libs = gSystem->GetLibraries() ;
424 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4d52736b 425 if (!IsSelected(AliQA::GetDetName(iDet)))
426 continue ;
312e6f8d 427 TString detName = AliQA::GetDetName(iDet) ;
428 if (detName == "HLT")
429 continue;
430 if (libs.Contains("lib" + detName + "base.so"))
431 continue;
432 gSystem->Load("lib" + detName + "base.so");
433 }
434 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
435 if (!fRunLoader) {
436 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
437 return kFALSE;
438 }
439 fRunLoader->CdGAFile();
440 if (fRunLoader->LoadgAlice() == 0) {
441 gAlice = fRunLoader->GetAliRun();
442 }
4d52736b 443
312e6f8d 444 if (!gAlice) {
445 AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
446 return kFALSE;
447 }
448
449 } else { // galice.root does not exist
450 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
451 return kFALSE;
452 }
453
454 return kTRUE;
455}
456
04236e67 457//_____________________________________________________________________________
458Bool_t AliQADataMakerSteer::IsSelected(const char * det)
459{
460 // check whether detName is contained in detectors
461 // if yes, it is removed from detectors
462
463 const TString detName(det) ;
464 // check if all detectors are selected
465 if ((fDetectors.CompareTo("ALL") == 0) ||
466 fDetectors.BeginsWith("ALL ") ||
467 fDetectors.EndsWith(" ALL") ||
468 fDetectors.Contains(" ALL ")) {
469 fDetectors = "ALL";
470 return kTRUE;
471 }
472
473 // search for the given detector
474 Bool_t rv = kFALSE;
475 if ((fDetectors.CompareTo(detName) == 0) ||
476 fDetectors.BeginsWith(detName+" ") ||
477 fDetectors.EndsWith(" "+detName) ||
478 fDetectors.Contains(" "+detName+" ")) {
479 // fDetectors.ReplaceAll(detName, "");
480 rv = kTRUE;
481 }
482
483 // clean up the detectors string
484 // while (fDetectors.Contains(" "))
485 // fDetectors.ReplaceAll(" ", " ");
486 // while (fDetectors.BeginsWith(" "))
487 // fDetectors.Remove(0, 1);
488 // while (fDetectors.EndsWith(" "))
489 // fDetectors.Remove(fDetectors.Length()-1, 1);
490
491 return rv ;
492}
493
312e6f8d 494//_____________________________________________________________________________
4edbc5bc 495Bool_t AliQADataMakerSteer::Merge(const Int_t runNumber) const
315bba70 496{
567d83d9 497 // Merge all the cycles from all detectors in one single file per run
4edbc5bc 498 char cmd[80] ;
499 if ( runNumber == -1 )
500 sprintf(cmd, ".! ls *%s*.*.*.root > tempo.txt", AliQA::GetQADataFileName()) ;
501 else
502 sprintf(cmd, ".! ls *%s*.%d.*.root > tempo.txt", AliQA::GetQADataFileName(), runNumber) ;
503 gROOT->ProcessLine(cmd) ;
567d83d9 504 ifstream in("tempo.txt") ;
505 const Int_t runMax = 10 ;
506 TString file[AliQA::kNDET*runMax] ;
507 Int_t run[AliQA::kNDET*runMax] ;
508
509 Int_t index = 0 ;
510 while ( 1 ) {
4edbc5bc 511 in >> file[index] ;
567d83d9 512 if ( !in.good() )
513 break ;
4edbc5bc 514 index++ ;
515 }
516
517 if ( index == 0 ) {
518 AliError(Form("run number %d not found", runNumber)) ;
519 return kFALSE ;
567d83d9 520 }
4edbc5bc 521
436a9f16 522 Int_t runIndex = 1 ;
4edbc5bc 523 char stmp[10] ;
524 sprintf(stmp, ".%s.", AliQA::GetQADataFileName()) ;
567d83d9 525 for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) {
526 TString tmp(file[ifile]) ;
527 tmp.ReplaceAll(".root", "") ;
528 TString det = tmp(0, tmp.Index(".")) ;
4edbc5bc 529 tmp.Remove(0, tmp.Index(stmp)+4) ;
567d83d9 530 TString ttmp = tmp(0, tmp.Index(".")) ;
531 Int_t newRun = ttmp.Atoi() ;
436a9f16 532 for (Int_t irun = 0; irun < runIndex; irun++) {
533 if (newRun == run[irun])
534 break ;
567d83d9 535 run[runIndex] = newRun ;
567d83d9 536 runIndex++ ;
537 }
538 ttmp = tmp(tmp.Index("."), tmp.Length()) ;
539 Int_t cycle = ttmp.Atoi() ;
540 AliInfo(Form("%s : det = %s run = %d cycle = %d \n", file[ifile].Data(), det.Data(), newRun, cycle)) ;
541 }
542 for (Int_t irun = 0 ; irun < runIndex ; irun++) {
543 TFileMerger merger ;
4edbc5bc 544 char outFileName[20] ;
436a9f16 545 sprintf(outFileName, "Merged.%s.%d.root", AliQA::GetQADataFileName(), run[irun]) ;
567d83d9 546 merger.OutputFile(outFileName) ;
547 for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) {
548 char pattern[100] ;
436a9f16 549 sprintf(pattern, "%s.%d.", AliQA::GetQADataFileName(), run[irun]) ;
567d83d9 550 TString tmp(file[ifile]) ;
551 if (tmp.Contains(pattern))
552 merger.AddFile(tmp) ;
553 }
554 merger.Merge() ;
555 }
556
557 return kTRUE ;
315bba70 558}
559
c65c502a 560//_____________________________________________________________________________
561void AliQADataMakerSteer::Reset()
562{
563 // Reset the default data members
564 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4d52736b 565 if (IsSelected(AliQA::GetDetName(iDet))) {
566 fLoader[iDet] = NULL;
567 if (fQADataMaker[iDet]) {
568 (fQADataMaker[iDet])->Reset() ;
569 //delete fQADataMaker[iDet] ;
570 //fQADataMaker[iDet] = NULL ;
571 }
c65c502a 572 }
573 }
574
6441b07a 575 if (fRawReaderDelete) {
576 delete fRawReader ;
577 fRawReader = NULL ;
578 }
c65c502a 579
580 fCycleSame = kFALSE ;
581 fESD = NULL ;
582 fESDTree = NULL ;
583 fFirst = kTRUE ;
774ac967 584 fNumberOfEvents = 999999 ;
c65c502a 585}
586
6441b07a 587//_____________________________________________________________________________
4d52736b 588Bool_t AliQADataMakerSteer::Run(const char * detectors, AliRawReader * rawReader)
6441b07a 589{
590 //Runs all the QA data Maker for Raws only
4d52736b 591 fRawReader = rawReader ;
6441b07a 592 fRawReaderDelete = kFALSE ;
4d52736b 593 fCycleSame = kTRUE ;
594 fDetectors = detectors ;
6441b07a 595
596 // Initialize all QA data makers for all detectors
597 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4d52736b 598 if (IsSelected(AliQA::GetDetName(iDet))) {
1aa42107 599 AliQADataMaker * qadm = GetQADataMaker(iDet, "rec") ;
4d52736b 600 if (!qadm) {
601 AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ;
602 } else {
603 AliInfo(Form("Data Maker found for %s", qadm->GetName())) ;
604 qadm->Init(AliQA::kRAWS, fRunNumber, GetQACycles(iDet)) ;
605 qadm->StartOfCycle(AliQA::kRAWS, fCycleSame) ;
606 }
6441b07a 607 }
608 }
609 fFirst = kFALSE ;
610
1aa42107 611 return DoIt(AliQA::kRAWS, "rec") ;
04236e67 612}
613
614//_____________________________________________________________________________
615Bool_t AliQADataMakerSteer::Run(const char * detectors, const char * fileName)
616{
617 //Runs all the QA data Maker for Raws only
618 fCycleSame = kTRUE ;
619 fDetectors = detectors ;
620
1aa42107 621 if ( !Init(AliQA::kRAWS, "rec", fileName) )
04236e67 622 return kFALSE ;
623
624 // Initialize all QA data makers for all detectors
625 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
626 if (IsSelected(AliQA::GetDetName(iDet))) {
1aa42107 627 AliQADataMaker * qadm = GetQADataMaker(iDet, "rec") ;
04236e67 628 if (!qadm) {
629 AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ;
630 } else {
631 AliInfo(Form("Data Maker found for %s", qadm->GetName())) ;
632 qadm->Init(AliQA::kRAWS, fRunNumber, GetQACycles(iDet)) ;
633 qadm->StartOfCycle(AliQA::kRAWS, fCycleSame) ;
634 }
635 }
636 }
637 fFirst = kFALSE ;
638
1aa42107 639 return DoIt(AliQA::kRAWS, "rec") ;
6441b07a 640}
641
312e6f8d 642//_____________________________________________________________________________
4d52736b 643Bool_t AliQADataMakerSteer::Run(const char * detectors, const AliQA::TASKINDEX taskIndex, const char * fileName )
312e6f8d 644{
645 // Runs all the QA data Maker for every detector
6441b07a 646
4d52736b 647 Bool_t rv = kFALSE ;
648 fDetectors = detectors ;
04236e67 649
650 char * mode ;
651 if ( (taskIndex == AliQA::kHITS) || (taskIndex == AliQA::kSDIGITS) || (taskIndex == AliQA::kDIGITS) )
1aa42107 652 mode = "sim" ;
04236e67 653 else if ( (taskIndex == AliQA::kRAWS) || (taskIndex == AliQA::kRECPOINTS) || (taskIndex == AliQA::kESDS) )
1aa42107 654 mode = "rec" ;
04236e67 655 else {
656 AliError(Form("%s not implemented", AliQA::GetTaskName(taskIndex).Data())) ;
657 return rv ;
658 }
312e6f8d 659
04236e67 660 if ( !Init(taskIndex, mode, fileName) )
312e6f8d 661 return kFALSE ;
04236e67 662
663 rv = DoIt(taskIndex, mode) ;
4d52736b 664
665 return rv ;
6441b07a 666
14e1eccc 667}
4edbc5bc 668
669//_____________________________________________________________________________
670Bool_t AliQADataMakerSteer::Save2OCDB(const Int_t runNumber, const Int_t cycleNumber, const char * detectors) const
671{
672 // take the locasl QA data merge into a single file and save in OCDB
673 Bool_t rv = kTRUE ;
674 TString tmp(AliQA::GetQARefStorage()) ;
675 if ( tmp.IsNull() ) {
676 AliError("No storage defined, use AliQA::SetQARefStorage") ;
677 return kFALSE ;
678 }
679 if ( !(tmp.Contains(AliQA::GetLabLocalOCDB()) || tmp.Contains(AliQA::GetLabAliEnOCDB())) ) {
680 AliError(Form("%s is a wrong storage, use %s or %s", AliQA::GetQARefStorage(), AliQA::GetLabLocalOCDB().Data(), AliQA::GetLabAliEnOCDB().Data())) ;
681 return kFALSE ;
682 }
683 TString sdet(detectors) ;
684 sdet.ToUpper() ;
685 TFile * inputFile ;
686 if ( sdet.Contains("ALL") ) {
687 rv = Merge(runNumber) ;
688 if ( ! rv )
689 return kFALSE ;
690 char inputFileName[20] ;
691 sprintf(inputFileName, "Merged.%s.%d.root", AliQA::GetQADataFileName(), runNumber) ;
692 inputFile = TFile::Open(inputFileName) ;
f73f556a 693 rv = SaveIt2OCDB(runNumber, inputFile) ;
4edbc5bc 694 } else {
695 for (Int_t index = 0; index < AliQA::kNDET; index++) {
696 if (sdet.Contains(AliQA::GetDetName(index))) {
697 char inputFileName[20] ;
698 sprintf(inputFileName, "%s.%s.%d.%d.root", AliQA::GetDetName(index), AliQA::GetQADataFileName(), runNumber, cycleNumber) ;
699 inputFile = TFile::Open(inputFileName) ;
f73f556a 700 rv *= SaveIt2OCDB(runNumber, inputFile) ;
4edbc5bc 701 }
702 }
703 }
704 return rv ;
705}
706
707//_____________________________________________________________________________
f73f556a 708Bool_t AliQADataMakerSteer::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile) const
4edbc5bc 709{
710 // reads the TH1 from file and adds it to appropriate list before saving to OCDB
711 Bool_t rv = kTRUE ;
712 AliInfo(Form("Saving TH1s in %s to %s", inputFile->GetName(), AliQA::GetQARefStorage())) ;
713 AliCDBManager* man = AliCDBManager::Instance() ;
f73f556a 714 if ( ! man->IsDefaultStorageSet() ) {
715 man->SetDefaultStorage(AliQA::GetQARefDefaultStorage()) ;
716 man->SetSpecificStorage(Form("%s/*", AliQA::GetQAOCDBDirName()), AliQA::GetQARefStorage()) ;
717 }
04236e67 718 if(man->GetRun() < 0)
719 man->SetRun(runNumber);
720
4edbc5bc 721 for ( Int_t detIndex = 0 ; detIndex < AliQA::kNDET ; detIndex++) {
722 TDirectory * detDir = inputFile->GetDirectory(AliQA::GetDetName(detIndex)) ;
723 if ( detDir ) {
724 AliInfo(Form("Entering %s", detDir->GetName())) ;
f73f556a 725 char detOCDBDir[20] ;
726 sprintf(detOCDBDir, "%s/%s/%s", AliQA::GetQAOCDBDirName(), AliQA::GetDetName(detIndex), AliQA::GetRefOCDBDirName()) ;
727 AliCDBId idr(detOCDBDir, runNumber, 999999999) ;
4edbc5bc 728 TList * listDetQAD = new TList() ;
729 char listName[20] ;
730 sprintf(listName, "%s QA data Reference", AliQA::GetDetName(detIndex)) ;
731 listDetQAD->SetName(listName) ;
732 TList * taskList = detDir->GetListOfKeys() ;
733 TIter nextTask(taskList) ;
734 TKey * taskKey ;
735 while ( (taskKey = dynamic_cast<TKey*>(nextTask())) ) {
736 TDirectory * taskDir = detDir->GetDirectory(taskKey->GetName()) ;
737 AliInfo(Form("Saving %s", taskDir->GetName())) ;
f73f556a 738 TObjArray * listTaskQAD = new TObjArray(100) ;
4edbc5bc 739 listTaskQAD->SetName(taskKey->GetName()) ;
740 listDetQAD->Add(listTaskQAD) ;
741 TList * histList = taskDir->GetListOfKeys() ;
742 TIter nextHist(histList) ;
743 TKey * histKey ;
744 while ( (histKey = dynamic_cast<TKey*>(nextHist())) ) {
745 TObject * odata = taskDir->Get(histKey->GetName()) ;
746 if ( odata->IsA()->InheritsFrom("TH1") ) {
747 AliInfo(Form("Adding %s", histKey->GetName())) ;
748 TH1 * hdata = static_cast<TH1*>(odata) ;
749 listTaskQAD->Add(hdata) ;
750 }
751 }
752 }
753 AliCDBMetaData mdr ;
754 man->Put(listDetQAD, idr, &mdr) ;
755 }
756 }
757 return rv ;
758}