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