]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQAManager.cxx
correction naming of QA data object
[u/mrichter/AliRoot.git] / STEER / AliQAManager.cxx
CommitLineData
2e331c8b 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: AliQAManager.cxx 30894 2009-02-05 13:46:48Z schutz $ */
17///////////////////////////////////////////////////////////////////////////////
18// //
19// class for running the QA makers //
20// //
21// AliQAManager qas; //
4e25ac79 22// qas.Run(AliQAv1::kRAWS, rawROOTFileName); //
23// qas.Run(AliQAv1::kHITS); //
24// qas.Run(AliQAv1::kSDIGITS); //
25// qas.Run(AliQAv1::kDIGITS); //
26// qas.Run(AliQAv1::kRECPOINTS); //
27// qas.Run(AliQAv1::kESDS); //
2e331c8b 28// //
29///////////////////////////////////////////////////////////////////////////////
30
31#include <TKey.h>
32#include <TFile.h>
33#include <TFileMerger.h>
149a2367 34#include <TGrid.h>
35#include <TGridCollection.h>
36#include <TGridResult.h>
2e331c8b 37#include <TPluginManager.h>
38#include <TROOT.h>
39#include <TString.h>
40#include <TSystem.h>
41
42#include "AliCDBManager.h"
43#include "AliCDBEntry.h"
44#include "AliCDBId.h"
45#include "AliCDBMetaData.h"
46#include "AliCodeTimer.h"
47#include "AliCorrQADataMakerRec.h"
48#include "AliDetectorRecoParam.h"
49#include "AliESDEvent.h"
50#include "AliGeomManager.h"
51#include "AliGlobalQADataMaker.h"
52#include "AliHeader.h"
53#include "AliLog.h"
54#include "AliModule.h"
4e25ac79 55#include "AliQAv1.h"
2e331c8b 56#include "AliQADataMakerRec.h"
57#include "AliQADataMakerSim.h"
58#include "AliQAManager.h"
59#include "AliRawReaderDate.h"
60#include "AliRawReaderFile.h"
61#include "AliRawReaderRoot.h"
62#include "AliRun.h"
63#include "AliRunLoader.h"
64#include "AliRunTag.h"
65
66ClassImp(AliQAManager)
67AliQAManager* AliQAManager::fgQAInstance = 0x0;
68
69//_____________________________________________________________________________
70AliQAManager::AliQAManager() :
71 AliCDBManager(),
72 fCurrentEvent(0),
73 fCycleSame(kFALSE),
74 fDetectors("ALL"),
75 fDetectorsW("ALL"),
76 fESD(NULL),
77 fESDTree(NULL),
78 fGAliceFileName(""),
79 fFirstEvent(0),
80 fMaxEvents(0),
81 fMode(""),
82 fNumberOfEvents(999999),
83 fRecoParam(),
84 fRunNumber(0),
85 fRawReader(NULL),
86 fRawReaderDelete(kTRUE),
87 fRunLoader(NULL),
bc8761a0 88 fTasks(""),
89 fEventSpecie(AliRecoParam::kDefault)
2e331c8b 90{
91 // default ctor
92 fMaxEvents = fNumberOfEvents ;
93 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4e25ac79 94 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 95 fLoader[iDet] = NULL ;
96 fQADataMaker[iDet] = NULL ;
97 fQACycles[iDet] = 999999 ;
2e331c8b 98 }
99 }
75373542 100 SetWriteExpert() ;
2e331c8b 101}
102
103//_____________________________________________________________________________
104AliQAManager::AliQAManager(const Char_t * mode, const Char_t* gAliceFilename) :
105 AliCDBManager(),
106 fCurrentEvent(0),
107 fCycleSame(kFALSE),
108 fDetectors("ALL"),
109 fDetectorsW("ALL"),
110 fESD(NULL),
111 fESDTree(NULL),
112 fGAliceFileName(gAliceFilename),
113 fFirstEvent(0),
114 fMaxEvents(0),
115 fMode(mode),
116 fNumberOfEvents(999999),
117 fRecoParam(),
118 fRunNumber(0),
119 fRawReader(NULL),
120 fRawReaderDelete(kTRUE),
121 fRunLoader(NULL),
bc8761a0 122 fTasks(""),
123 fEventSpecie(AliRecoParam::kDefault)
2e331c8b 124{
125 // default ctor
126 fMaxEvents = fNumberOfEvents ;
127 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4e25ac79 128 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 129 fLoader[iDet] = NULL ;
130 fQADataMaker[iDet] = NULL ;
131 fQACycles[iDet] = 999999 ;
65660bf3 132 }
133 }
75373542 134 SetWriteExpert() ;
2e331c8b 135}
136
137//_____________________________________________________________________________
138AliQAManager::AliQAManager(const AliQAManager & qas) :
139 AliCDBManager(),
140 fCurrentEvent(qas.fCurrentEvent),
141 fCycleSame(kFALSE),
142 fDetectors(qas.fDetectors),
143 fDetectorsW(qas.fDetectorsW),
144 fESD(NULL),
145 fESDTree(NULL),
146 fGAliceFileName(qas.fGAliceFileName),
147 fFirstEvent(qas.fFirstEvent),
148 fMaxEvents(qas.fMaxEvents),
149 fMode(qas.fMode),
150 fNumberOfEvents(qas.fNumberOfEvents),
151 fRecoParam(),
152 fRunNumber(qas.fRunNumber),
153 fRawReader(NULL),
154 fRawReaderDelete(kTRUE),
155 fRunLoader(NULL),
bc8761a0 156 fTasks(qas.fTasks),
157 fEventSpecie(qas.fEventSpecie)
2e331c8b 158{
159 // cpy ctor
160 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
161 fLoader[iDet] = qas.fLoader[iDet] ;
162 fQADataMaker[iDet] = qas.fQADataMaker[iDet] ;
163 fQACycles[iDet] = qas.fQACycles[iDet] ;
164 fQAWriteExpert[iDet] = qas.fQAWriteExpert[iDet] ;
165 }
166}
167
168//_____________________________________________________________________________
169AliQAManager & AliQAManager::operator = (const AliQAManager & qas)
170{
171 // assignment operator
172 this->~AliQAManager() ;
173 new(this) AliQAManager(qas) ;
174 return *this ;
175}
176
177//_____________________________________________________________________________
178AliQAManager::~AliQAManager()
179{
180 // dtor
181 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4e25ac79 182 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 183 fLoader[iDet] = NULL;
184 if (fQADataMaker[iDet]) {
185 (fQADataMaker[iDet])->Finish() ;
186 delete fQADataMaker[iDet] ;
187 }
188 }
189 }
190 if (fRawReaderDelete) {
191 fRunLoader = NULL ;
192 delete fRawReader ;
193 fRawReader = NULL ;
194 }
195}
196
197//_____________________________________________________________________________
4e25ac79 198Bool_t AliQAManager::DoIt(const AliQAv1::TASKINDEX_t taskIndex)
2e331c8b 199{
200 // Runs all the QA data Maker for every detector
201
202 Bool_t rv = kFALSE ;
203 // Fill QA data in event loop
204 for (UInt_t iEvent = fFirstEvent ; iEvent < (UInt_t)fMaxEvents ; iEvent++) {
205 fCurrentEvent++ ;
206 // Get the event
207 if ( iEvent%10 == 0 )
5379c4a3 208 AliDebug(AliQAv1::GetQADebugLevel(), Form("processing event %d", iEvent));
4e25ac79 209 if ( taskIndex == AliQAv1::kRAWS ) {
2e331c8b 210 if ( !fRawReader->NextEvent() )
211 break ;
4e25ac79 212 } else if ( taskIndex == AliQAv1::kESDS ) {
2e331c8b 213 if ( fESDTree->GetEntry(iEvent) == 0 )
214 break ;
215 } else {
216 if ( fRunLoader->GetEvent(iEvent) != 0 )
217 break ;
218 }
219 // loop over active loaders
220 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4e25ac79 221 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 222 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
223 if (!qadm) continue; // This detector doesn't have any QA (for example, HLT)
224 if ( qadm->IsCycleDone() ) {
225 qadm->EndOfCycle(taskIndex) ;
226 }
227 TTree * data = NULL ;
228 AliLoader* loader = GetLoader(qadm->GetUniqueID());
229 switch (taskIndex) {
4e25ac79 230 case AliQAv1::kNULLTASKINDEX :
2e331c8b 231 break ;
4e25ac79 232 case AliQAv1::kRAWS :
2e331c8b 233 qadm->Exec(taskIndex, fRawReader) ;
234 break ;
4e25ac79 235 case AliQAv1::kHITS :
2e331c8b 236 if( loader ) {
237 loader->LoadHits() ;
238 data = loader->TreeH() ;
239 if ( ! data ) {
4e25ac79 240 AliWarning(Form(" Hit Tree not found for %s", AliQAv1::GetDetName(iDet))) ;
2e331c8b 241 break ;
242 }
243 }
244 qadm->Exec(taskIndex, data) ;
245 break ;
4e25ac79 246 case AliQAv1::kSDIGITS :
2e331c8b 247 if( loader ) {
248 loader->LoadSDigits() ;
249 data = loader->TreeS() ;
250 if ( ! data ) {
4e25ac79 251 AliWarning(Form(" SDigit Tree not found for %s", AliQAv1::GetDetName(iDet))) ;
2e331c8b 252 break ;
253 }
254 }
255 qadm->Exec(taskIndex, data) ;
256 break;
4e25ac79 257 case AliQAv1::kDIGITS :
2e331c8b 258 if( loader ) {
259 loader->LoadDigits() ;
260 data = loader->TreeD() ;
261 if ( ! data ) {
4e25ac79 262 AliWarning(Form(" Digit Tree not found for %s", AliQAv1::GetDetName(iDet))) ;
2e331c8b 263 break ;
264 }
265 }
266 qadm->Exec(taskIndex, data) ;
267 break;
4e25ac79 268 case AliQAv1::kRECPOINTS :
2e331c8b 269 if( loader ) {
270 loader->LoadRecPoints() ;
271 data = loader->TreeR() ;
272 if (!data) {
4e25ac79 273 AliWarning(Form("RecPoints not found for %s", AliQAv1::GetDetName(iDet))) ;
2e331c8b 274 break ;
275 }
276 }
277 qadm->Exec(taskIndex, data) ;
278 break;
4e25ac79 279 case AliQAv1::kTRACKSEGMENTS :
2e331c8b 280 break;
4e25ac79 281 case AliQAv1::kRECPARTICLES :
2e331c8b 282 break;
4e25ac79 283 case AliQAv1::kESDS :
2e331c8b 284 qadm->Exec(taskIndex, fESD) ;
285 break;
4e25ac79 286 case AliQAv1::kNTASKINDEX :
2e331c8b 287 break;
288 } //task switch
289 }
290 } // detector loop
291 Increment() ;
292 } // event loop
293 // Save QA data for all detectors
294 rv = Finish(taskIndex) ;
295
4e25ac79 296 if ( taskIndex == AliQAv1::kRAWS )
2e331c8b 297 fRawReader->RewindEvents() ;
298
299 return rv ;
300}
301
302//_____________________________________________________________________________
4e25ac79 303Bool_t AliQAManager::Finish(const AliQAv1::TASKINDEX_t taskIndex)
2e331c8b 304{
305 // write output to file for all detectors
306 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4e25ac79 307 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 308 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
309 if (qadm)
310 qadm->EndOfCycle(taskIndex) ;
311 }
312 }
313 return kTRUE ;
314}
315
316//_____________________________________________________________________________
4e25ac79 317TObjArray * AliQAManager::GetFromOCDB(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, const char * year) const
2e331c8b 318{
319 // Retrieve the list of QA data for a given detector and a given task
320 TObjArray * rv = NULL ;
4e25ac79 321 if ( !strlen(AliQAv1::GetQARefStorage()) ) {
322 AliError("No storage defined, use AliQAv1::SetQARefStorage") ;
2e331c8b 323 return NULL ;
324 }
325 if ( ! IsDefaultStorageSet() ) {
4e25ac79 326 TString tmp(AliQAv1::GetQARefDefaultStorage()) ;
2e331c8b 327 tmp.Append(year) ;
328 tmp.Append("/") ;
329 Instance()->SetDefaultStorage(tmp.Data()) ;
4e25ac79 330 Instance()->SetSpecificStorage(Form("%s/*", AliQAv1::GetQAName()), AliQAv1::GetQARefStorage()) ;
2e331c8b 331 }
4e25ac79 332 TString detOCDBDir(Form("%s/%s/%s", AliQAv1::GetQAName(), AliQAv1::GetDetName((Int_t)det), AliQAv1::GetRefOCDBDirName())) ;
5379c4a3 333 AliDebug(AliQAv1::GetQADebugLevel(), Form("Retrieving reference data from %s/%s for %s", AliQAv1::GetQARefStorage(), detOCDBDir.Data(), AliQAv1::GetTaskName(task).Data())) ;
2e331c8b 334 AliCDBEntry* entry = QAManager()->Get(detOCDBDir.Data(), 0) ; //FIXME 0 --> Run Number
335 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
336 if ( listDetQAD )
4e25ac79 337 rv = dynamic_cast<TObjArray *>(listDetQAD->FindObject(AliQAv1::GetTaskName(task))) ;
2e331c8b 338 return rv ;
339}
340
341//_____________________________________________________________________________
342AliLoader * AliQAManager::GetLoader(Int_t iDet)
343{
344 // get the loader for a detector
345
4e25ac79 346 if ( !fRunLoader || iDet == AliQAv1::kCORR)
2e331c8b 347 return NULL ;
348
4e25ac79 349 TString detName = AliQAv1::GetDetName(iDet) ;
2e331c8b 350 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
351 if (fLoader[iDet])
352 return fLoader[iDet] ;
353
354 // load the QA data maker object
355 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
356 TString loaderName = "Ali" + detName + "Loader" ;
357
358 AliLoader * loader = NULL ;
359 // first check if a plugin is defined for the quality assurance data maker
360 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
361 // if not, add a plugin for it
362 if (!pluginHandler) {
5379c4a3 363 AliDebug(AliQAv1::GetQADebugLevel(), Form("defining plugin for %s", loaderName.Data())) ;
2e331c8b 364 TString libs = gSystem->GetLibraries() ;
365 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
366 pluginManager->AddHandler("AliQADataMaker", detName, loaderName, detName + "loader", loaderName + "()") ;
367 } else {
368 pluginManager->AddHandler("AliLoader", detName, loaderName, detName, loaderName + "()") ;
369 }
370 pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
371 }
372 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
373 loader = (AliLoader *) pluginHandler->ExecPlugin(0) ;
374 }
375 if (loader)
376 fLoader[iDet] = loader ;
377 return loader ;
378}
379
380//_____________________________________________________________________________
4e25ac79 381AliQAv1 * AliQAManager::GetQA(UInt_t run, UInt_t evt)
2e331c8b 382{
383// retrieves the QA object stored in a file named "Run{run}.Event{evt}_1.ESD.tag.root"
384 char * fileName = Form("Run%d.Event%d_1.ESD.tag.root", run, evt) ;
385 TFile * tagFile = TFile::Open(fileName) ;
386 if ( !tagFile ) {
387 AliError(Form("File %s not found", fileName)) ;
388 return NULL ;
389 }
390 TTree * tagTree = dynamic_cast<TTree *>(tagFile->Get("T")) ;
391 if ( !tagTree ) {
392 AliError(Form("Tree T not found in %s", fileName)) ;
393 tagFile->Close() ;
394 return NULL ;
395 }
396 AliRunTag * tag = new AliRunTag ;
397 tagTree->SetBranchAddress("AliTAG", &tag) ;
398 tagTree->GetEntry(evt) ;
4e25ac79 399 AliQAv1 * qa = AliQAv1::Instance(tag->GetQALength(), tag->GetQAArray(), tag->GetESLength(), tag->GetEventSpecies()) ;
2e331c8b 400 tagFile->Close() ;
401 return qa ;
402}
403
404//_____________________________________________________________________________
405AliQADataMaker * AliQAManager::GetQADataMaker(const Int_t iDet)
406{
407 // get the quality assurance data maker for a detector
408
409 if (fQADataMaker[iDet]) {
bc8761a0 410 if ( fQADataMaker[iDet]->GetRecoParam() )
411 fQADataMaker[iDet]->SetEventSpecie(fQADataMaker[iDet]->GetRecoParam()->GetEventSpecie()) ;
412 else
13a2370e 413 fQADataMaker[iDet]->SetEventSpecie(fEventSpecie) ;
2e331c8b 414 return fQADataMaker[iDet] ;
415 }
416
417 AliQADataMaker * qadm = NULL ;
418
4e25ac79 419 if (iDet == AliQAv1::kGLOBAL) { //Global QA
2e331c8b 420 qadm = new AliGlobalQADataMaker();
4e25ac79 421 qadm->SetName(AliQAv1::GetDetName(iDet));
2e331c8b 422 qadm->SetUniqueID(iDet);
423 fQADataMaker[iDet] = qadm;
bc8761a0 424 if ( qadm->GetRecoParam() )
425 qadm->SetEventSpecie(qadm->GetRecoParam()->GetEventSpecie()) ;
426 else
13a2370e 427 qadm->SetEventSpecie(fEventSpecie) ;
2e331c8b 428 return qadm;
429 }
430
4e25ac79 431 if (iDet == AliQAv1::kCORR) { //the data maker for correlations among detectors
2e331c8b 432 qadm = new AliCorrQADataMakerRec(fQADataMaker) ;
4e25ac79 433 qadm->SetName(AliQAv1::GetDetName(iDet));
2e331c8b 434 qadm->SetUniqueID(iDet);
435 fQADataMaker[iDet] = qadm;
bc8761a0 436 if ( qadm->GetRecoParam() )
437 qadm->SetEventSpecie(qadm->GetRecoParam()->GetEventSpecie()) ;
438 else
13a2370e 439 qadm->SetEventSpecie(fEventSpecie) ;
2e331c8b 440 return qadm;
441 }
442
443 // load the QA data maker object
444 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
4e25ac79 445 TString detName = AliQAv1::GetDetName(iDet) ;
2e331c8b 446 TString tmp(fMode) ;
447 if (tmp.Contains("sim"))
448 tmp.ReplaceAll("s", "S") ;
449 else if (tmp.Contains("rec"))
450 tmp.ReplaceAll("r", "R") ;
451
452 TString qadmName = "Ali" + detName + "QADataMaker" + tmp ;
453
454 // first check if a plugin is defined for the quality assurance data maker
455 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
456 // if not, add a plugin for it
457 if (!pluginHandler) {
5379c4a3 458 AliDebug(AliQAv1::GetQADebugLevel(), Form("defining plugin for %s", qadmName.Data())) ;
2e331c8b 459 TString libs = gSystem->GetLibraries() ;
460 if (libs.Contains("lib" + detName + fMode + ".so") || (gSystem->Load("lib" + detName + fMode + ".so") >= 0)) {
461 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ;
462 } else {
463 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ;
464 }
465 pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
466 }
467 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
468 qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ;
469 }
470 if (qadm) {
4e25ac79 471 qadm->SetName(AliQAv1::GetDetName(iDet));
2e331c8b 472 qadm->SetUniqueID(iDet);
473 fQADataMaker[iDet] = qadm ;
bc8761a0 474 if ( qadm->GetRecoParam() )
475 qadm->SetEventSpecie(qadm->GetRecoParam()->GetEventSpecie()) ;
476 else
13a2370e 477 qadm->SetEventSpecie(fEventSpecie) ;
2e331c8b 478 }
479
480 return qadm ;
481}
482
483//_____________________________________________________________________________
484void AliQAManager::EndOfCycle(TObjArray * detArray)
485{
486 // End of cycle QADataMakers
487
488 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4e25ac79 489 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 490 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
491 if (!qadm)
492 continue ;
493 // skip non active detectors
494 if (detArray) {
4e25ac79 495 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQAv1::GetDetName(iDet))) ;
2e331c8b 496 if (!det || !det->IsActive())
497 continue ;
498 }
4e25ac79 499 for (UInt_t taskIndex = 0; taskIndex < AliQAv1::kNTASKINDEX; taskIndex++) {
2e331c8b 500 if ( fTasks.Contains(Form("%d", taskIndex)) )
4e25ac79 501 qadm->EndOfCycle(AliQAv1::GetTaskIndex(AliQAv1::GetTaskName(taskIndex))) ;
2e331c8b 502 }
503 qadm->Finish();
504 }
505 }
506}
507
508//_____________________________________________________________________________
509void AliQAManager::EndOfCycle(TString detectors)
510{
511 // End of cycle QADataMakers
512
513 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4e25ac79 514 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 515 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
516 if (!qadm)
517 continue ;
518 // skip non active detectors
4e25ac79 519 if (!detectors.Contains(AliQAv1::GetDetName(iDet)))
2e331c8b 520 continue ;
4e25ac79 521 for (UInt_t taskIndex = 0; taskIndex < AliQAv1::kNTASKINDEX; taskIndex++) {
2e331c8b 522 if ( fTasks.Contains(Form("%d", taskIndex)) )
4e25ac79 523 qadm->EndOfCycle(AliQAv1::GetTaskIndex(AliQAv1::GetTaskName(taskIndex))) ;
2e331c8b 524 }
525 qadm->Finish();
526 }
527 }
528}
529
530//_____________________________________________________________________________
531void AliQAManager::Increment()
532{
533 // Increments the cycle counter for all QA Data Makers
534 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4e25ac79 535 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 536 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
537 if (qadm)
538 qadm->Increment() ;
539 }
540 }
541}
542
543//_____________________________________________________________________________
4e25ac79 544Bool_t AliQAManager::InitQA(const AliQAv1::TASKINDEX_t taskIndex, const char * input )
2e331c8b 545{
546 // Initialize the event source and QA data makers
547
548 fTasks += Form("%d", taskIndex) ;
549
4e25ac79 550 if (taskIndex == AliQAv1::kRAWS) {
2e331c8b 551 if (!fRawReader) {
552 fRawReader = AliRawReader::Create(input);
553 }
554 if ( ! fRawReader )
555 return kFALSE ;
556 fRawReaderDelete = kTRUE ;
557 fRawReader->NextEvent() ;
558 fRunNumber = fRawReader->GetRunNumber() ;
559 SetRun(fRunNumber) ;
560 fRawReader->RewindEvents();
561 fNumberOfEvents = 999999 ;
562 if ( fMaxEvents < 0 )
563 fMaxEvents = fNumberOfEvents ;
4e25ac79 564 } else if (taskIndex == AliQAv1::kESDS) {
565 fTasks = AliQAv1::GetTaskName(AliQAv1::kESDS) ;
2e331c8b 566 if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists
567 TFile * esdFile = TFile::Open("AliESDs.root") ;
568 fESDTree = dynamic_cast<TTree *> (esdFile->Get("esdTree")) ;
569 if ( !fESDTree ) {
570 AliError("esdTree not found") ;
571 return kFALSE ;
572 } else {
573 fESD = new AliESDEvent() ;
574 fESD->ReadFromTree(fESDTree) ;
575 fESDTree->GetEntry(0) ;
576 fRunNumber = fESD->GetRunNumber() ;
577 fNumberOfEvents = fESDTree->GetEntries() ;
578 if ( fMaxEvents < 0 )
579 fMaxEvents = fNumberOfEvents ;
580 }
581 } else {
582 AliError("AliESDs.root not found") ;
583 return kFALSE ;
584 }
585 } else {
586 if ( !InitRunLoader() ) {
587 AliWarning("No Run Loader not found") ;
588 } else {
589 fNumberOfEvents = fRunLoader->GetNumberOfEvents() ;
590 if ( fMaxEvents < 0 )
591 fMaxEvents = fNumberOfEvents ;
592 }
593 }
594
595 // Get Detectors
596 TObjArray* detArray = NULL ;
597 if (fRunLoader) // check if RunLoader exists
598 if ( fRunLoader->GetAliRun() ) { // check if AliRun exists in gAlice.root
599 detArray = fRunLoader->GetAliRun()->Detectors() ;
600 fRunNumber = fRunLoader->GetHeader()->GetRun() ;
601 }
602
603 // Initialize all QA data makers for all detectors
604 fRunNumber = AliCDBManager::Instance()->GetRun() ;
605 if ( ! AliGeomManager::GetGeometry() )
606 AliGeomManager::LoadGeometry() ;
607
608 InitQADataMaker(fRunNumber, detArray) ; //, fCycleSame, kTRUE, detArray) ;
609 return kTRUE ;
610}
611
612//_____________________________________________________________________________
613void AliQAManager::InitQADataMaker(UInt_t run, TObjArray * detArray)
614{
615 // Initializes The QADataMaker for all active detectors and for all active tasks
616 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4e25ac79 617 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 618 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
619 if (!qadm) {
4e25ac79 620 AliError(Form("AliQADataMaker not found for %s", AliQAv1::GetDetName(iDet))) ;
621 fDetectorsW.ReplaceAll(AliQAv1::GetDetName(iDet), "") ;
2e331c8b 622 } else {
623 if (fQAWriteExpert[iDet])
624 qadm->SetWriteExpert() ;
5379c4a3 625 AliDebug(AliQAv1::GetQADebugLevel(), Form("Data Maker found for %s %d", qadm->GetName(), qadm->WriteExpert())) ;
2e331c8b 626 // skip non active detectors
627 if (detArray) {
4e25ac79 628 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQAv1::GetDetName(iDet))) ;
2e331c8b 629 if (!det || !det->IsActive())
630 continue ;
631 }
2e331c8b 632 // Set default reco params
633 Bool_t sameCycle = kFALSE ;
4e25ac79 634 for (UInt_t taskIndex = 0; taskIndex < AliQAv1::kNTASKINDEX; taskIndex++) {
2e331c8b 635 if ( fTasks.Contains(Form("%d", taskIndex)) ) {
4e25ac79 636 qadm->Init(AliQAv1::GetTaskIndex(AliQAv1::GetTaskName(taskIndex)), GetQACycles(qadm->GetUniqueID())) ;
637 qadm->StartOfCycle(AliQAv1::GetTaskIndex(AliQAv1::GetTaskName(taskIndex)), run, sameCycle) ;
2e331c8b 638 sameCycle = kTRUE ;
639 }
640 }
641 }
642 }
643 }
644}
645
646
647//_____________________________________________________________________________
648Bool_t AliQAManager::InitRunLoader()
649{
650 // get or create the run loader
651 if (fRunLoader) {
652 fCycleSame = kTRUE ;
653 } else {
654 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
655 // load all base libraries to get the loader classes
656 TString libs = gSystem->GetLibraries() ;
657 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4e25ac79 658 if (!IsSelected(AliQAv1::GetDetName(iDet)))
2e331c8b 659 continue ;
4e25ac79 660 TString detName = AliQAv1::GetDetName(iDet) ;
2e331c8b 661 if (detName == "HLT")
662 continue;
663 if (libs.Contains("lib" + detName + "base.so"))
664 continue;
665 gSystem->Load("lib" + detName + "base.so");
666 }
667 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
668 if (!fRunLoader) {
669 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
670 return kFALSE;
671 }
672 fRunLoader->CdGAFile();
673 if (fRunLoader->LoadgAlice() == 0) {
674 gAlice = fRunLoader->GetAliRun();
675 }
676
677 if (!gAlice) {
678 AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
679 return kFALSE;
680 }
681
682 } else { // galice.root does not exist
683 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
684 return kFALSE;
685 }
686 }
687
688 if (!fRunNumber) {
689 fRunLoader->LoadHeader();
690 fRunNumber = fRunLoader->GetHeader()->GetRun() ;
691 }
692 return kTRUE;
693}
694
695//_____________________________________________________________________________
696Bool_t AliQAManager::IsSelected(const char * det)
697{
698 // check whether detName is contained in detectors
699 // if yes, it is removed from detectors
700
701 Bool_t rv = kFALSE;
702 const TString detName(det) ;
703 // always activates Correlation
4e25ac79 704 if ( detName.Contains(AliQAv1::GetDetName(AliQAv1::kCORR))) {
2e331c8b 705 rv = kTRUE ;
706 } else {
707 // check if all detectors are selected
708 if (fDetectors.Contains("ALL")) {
709 fDetectors = "ALL";
710 rv = kTRUE;
711 } else if ((fDetectors.CompareTo(detName) == 0) ||
712 fDetectors.BeginsWith(detName+" ") ||
713 fDetectors.EndsWith(" "+detName) ||
714 fDetectors.Contains(" "+detName+" ")) {
715 rv = kTRUE;
716 }
717 }
718 return rv ;
719}
720
721//_____________________________________________________________________________
bededc30 722Bool_t AliQAManager::Merge(Int_t runNumber) const
2e331c8b 723{
bededc30 724 // Merge data from all detectors from a given run in one single file
2e331c8b 725 // Merge the QA results from all the data chunks in one run
bededc30 726 if ( runNumber == -1)
727 runNumber = fRunNumber ;
2e331c8b 728 Bool_t rv = MergeData(runNumber) ;
bededc30 729 //rv *= MergeResults(runNumber) ; // not needed for the time being
2e331c8b 730 return rv ;
731}
732
149a2367 733//______________________________________________________________________
734Bool_t AliQAManager::MergeXML(const char * collectionFile, const char * subFile, const char * outFile)
735{
736 // merges files listed in a xml collection
737 // usage Merge(collection, outputFile))
738 // collection: is a xml collection
739
740 Bool_t rv = kFALSE ;
741
742 if ( strstr(collectionFile, ".xml") == 0 ) {
743 AliError("Input collection file must be an \".xml\" file\n") ;
744 return kFALSE ;
745 }
746
747 if ( !gGrid )
748 TGrid::Connect("alien://");
749 if ( !gGrid )
750 return kFALSE ;
751
752 // Open the file collection
753 printf("*** Create Collection ***\n");
754 printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory());
755 printf("*** Coll = |%s| \n",collectionFile);
756
bededc30 757 TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\")",collectionFile));
149a2367 758 TGridResult* result = collection->GetGridResult("", 0, 0);
759
760 Int_t index = 0 ;
761 const char * turl ;
adae62c9 762 TFileMerger merger(kFALSE) ;
149a2367 763 if (!outFile) {
764 TString tempo(collectionFile) ;
765 if ( subFile)
766 tempo.ReplaceAll(".xml", subFile) ;
767 else
768 tempo.ReplaceAll(".xml", "_Merged.root") ;
769 outFile = tempo.Data() ;
770 }
771 merger.OutputFile(outFile) ;
772
773 while ( (turl = result->GetKey(index, "turl")) ) {
774 char * file ;
775 if ( subFile )
776 file = Form("%s#%s", turl, subFile) ;
777 else
778 file = Form("%s", turl) ;
779
5379c4a3 780 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s\n", file)) ;
149a2367 781 merger.AddFile(file) ;
782 index++ ;
783 }
784
785 if (index)
786 merger.Merge() ;
787
5379c4a3 788 AliDebug(AliQAv1::GetQADebugLevel(), Form("Files merged into %s\n", outFile)) ;
149a2367 789
790 rv = kFALSE;
791 return rv ;
792}
793
69a898e3 794//_____________________________________________________________________________
795void AliQAManager::MergeCustom() const
796{
797 // Custom Merge of QA data from all detectors for all runs in one single file
798 // search all the run numbers
799 // search all the run numbers
800 gROOT->ProcessLine(".! ls *QA*.root > QAtempo.txt") ;
801 TString QAfile ;
802 FILE * QAfiles = fopen("QAtempo.txt", "r") ;
803 Int_t index = 0 ;
804 TList srunList ;
805 TIter nextRun(&srunList) ;
806 TObjString * srun = NULL ;
807 Int_t loRun = 999999999 ;
808 Int_t hiRun = 0 ;
809 while ( QAfile.Gets(QAfiles) ) {
810 Bool_t runExist = kFALSE ;
811 TString srunNew(QAfile(QAfile.Index("QA.")+3, QAfile.Index(".root")-(QAfile.Index("QA.")+3))) ;
812 Int_t cuRun = srunNew.Atoi() ;
813 if (cuRun < loRun)
814 loRun = cuRun ;
815 if (cuRun > hiRun)
816 hiRun = cuRun ;
817 while ( (srun = dynamic_cast<TObjString *> (nextRun())) ) {
818 if ( cuRun == (srun->String()).Atoi() ) {
819 runExist = kTRUE ;
820 break ;
821 }
822 }
823 nextRun.Reset() ;
824 if ( ! runExist )
825 srunList.Add(new TObjString(srunNew.Data()));
826 }
827 nextRun.Reset() ;
828 Int_t runNumber = 0 ;
4e25ac79 829 TFile mergedFile(Form("Merged.%s.Data.root", AliQAv1::GetQADataFileName()), "RECREATE") ;
69a898e3 830 TH1I * hisRun = new TH1I("hLMR", "List of merged runs", hiRun-loRun+10, loRun, hiRun+10) ;
831 // create the structure into the merged file
4e25ac79 832 for (Int_t iDet = 0; iDet < AliQAv1::kNDET ; iDet++) {
833 TDirectory * detDir = mergedFile.mkdir(AliQAv1::GetDetName(iDet)) ;
834 for (Int_t taskIndex = 0; taskIndex < AliQAv1::kNTASKINDEX; taskIndex++) {
69a898e3 835 detDir->cd() ;
4e25ac79 836 TDirectory * taskDir = gDirectory->mkdir(AliQAv1::GetTaskName(taskIndex)) ;
69a898e3 837 for (Int_t es = 0 ; es < AliRecoParam::kNSpecies ; es++) {
838 taskDir->cd() ;
839 TDirectory * esDir = gDirectory->mkdir(AliRecoParam::GetEventSpecieName(es)) ;
840 esDir->cd() ;
4e25ac79 841 gDirectory->mkdir(AliQAv1::GetExpert()) ;
69a898e3 842 }
843 }
844 }
845 while ( (srun = dynamic_cast<TObjString *> (nextRun())) ) {
846 runNumber = (srun->String()).Atoi() ;
847 hisRun->Fill(runNumber) ;
5379c4a3 848 AliDebug(AliQAv1::GetQADebugLevel(), Form("Merging run number %d", runNumber)) ;
69a898e3 849 // search all QA files for runNumber in the current directory
4e25ac79 850 char * fileList[AliQAv1::kNDET] ;
69a898e3 851 index = 0 ;
4e25ac79 852 for (Int_t iDet = 0; iDet < AliQAv1::kNDET ; iDet++) {
853 char * file = gSystem->Which(gSystem->WorkingDirectory(), Form("%s.%s.%d.root", AliQAv1::GetDetName(iDet), AliQAv1::GetQADataFileName(), runNumber));
69a898e3 854 if (file)
855 fileList[index++] = file ;
856 }
857 if ( index == 0 ) {
858 AliError("No QA data file found\n") ;
859 return ;
860 }
861 for ( Int_t i = 0 ; i < index ; i++) {
862 TFile * inFile = TFile::Open(fileList[i]) ;
863 TList * listOfKeys =inFile->GetListOfKeys() ;
864 TIter nextkey(listOfKeys) ;
865 TObject * obj1 ;
866 TString dirName("") ;
867 while ( (obj1 = nextkey()) ) {
868 TDirectory * directoryDet = inFile->GetDirectory(obj1->GetName()) ;
869 if ( directoryDet ) {
5379c4a3 870 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s dir = %s", inFile->GetName(), directoryDet->GetName())) ;
69a898e3 871 dirName += Form("%s/", directoryDet->GetName() ) ;
872 directoryDet->cd() ;
873 TList * listOfTasks = directoryDet->GetListOfKeys() ;
874 TIter nextTask(listOfTasks) ;
875 TObject * obj2 ;
876 while ( (obj2 = nextTask()) ) {
877 TDirectory * directoryTask = directoryDet->GetDirectory(obj2->GetName()) ;
878 if ( directoryTask ) {
879 dirName += Form("%s", obj2->GetName()) ;
5379c4a3 880 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s", dirName.Data())) ;
69a898e3 881 directoryTask->cd() ;
882 TList * listOfEventSpecie = directoryTask->GetListOfKeys() ;
883 TIter nextEventSpecie(listOfEventSpecie) ;
884 TObject * obj3 ;
885 while ( (obj3 = nextEventSpecie()) ) {
886 TDirectory * directoryEventSpecie = directoryTask->GetDirectory(obj3->GetName()) ;
887 if ( directoryEventSpecie ) {
888 dirName += Form("/%s/", obj3->GetName()) ;
5379c4a3 889 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s\n", dirName.Data())) ;
69a898e3 890 directoryEventSpecie->cd() ;
891 // histograms are here
892 TDirectory * mergedDirectory = mergedFile.GetDirectory(dirName.Data()) ;
893 TList * listOfData = directoryEventSpecie->GetListOfKeys() ;
894 TIter nextData(listOfData) ;
895 TKey * key ;
896 while ( (key = dynamic_cast<TKey *>(nextData())) ) {
897 TString className(key->GetClassName()) ;
898 if ( className.Contains("TH") || className.Contains("TProfile") ) {
899 TH1 * histIn = dynamic_cast<TH1*> (key->ReadObj()) ;
900 TH1 * histOu = dynamic_cast<TH1*> (mergedDirectory->FindObjectAny(histIn->GetName())) ;
5379c4a3 901 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s %x %x\n", key->GetName(), histIn, histOu)) ;
69a898e3 902 mergedDirectory->cd() ;
903 if ( ! histOu ) {
904 histIn->Write() ;
905 } else {
906 histOu->Add(histIn) ;
907 histOu->Write(histOu->GetName(), kOverwrite) ;
908 }
909 }
910 else if ( className.Contains("TDirectoryFile") ) {
911 TDirectory * dirExpert = directoryEventSpecie->GetDirectory(key->GetName()) ;
912 dirExpert->cd() ;
913 TDirectory * mergedDirectoryExpert = mergedDirectory->GetDirectory(dirExpert->GetName()) ;
914 TList * listOfExpertData = dirExpert->GetListOfKeys() ;
915 TIter nextExpertData(listOfExpertData) ;
916 TKey * keykey ;
917 while ( (keykey = dynamic_cast<TKey *>(nextExpertData())) ) {
918 TString classNameExpert(keykey->GetClassName()) ;
919 if (classNameExpert.Contains("TH")) {
920 TH1 * histInExpert = dynamic_cast<TH1*> (keykey->ReadObj()) ;
921 TH1 * histOuExpert = dynamic_cast<TH1*> (mergedDirectory->FindObjectAny(histInExpert->GetName())) ;
922 mergedDirectoryExpert->cd() ;
923 if ( ! histOuExpert ) {
924 histInExpert->Write() ;
925 } else {
926 histOuExpert->Add(histInExpert) ;
927 histOuExpert->Write(histOuExpert->GetName(), kOverwrite) ;
928 }
929 }
930 }
931 } else {
932 AliError(Form("No merge done for this object %s in %s", key->GetName(), dirName.Data())) ;
933 }
934 }
935 dirName.ReplaceAll(Form("/%s/",obj3->GetName()), "") ;
936 }
937 }
938 dirName.ReplaceAll(obj2->GetName(), "") ;
939 }
940 }
941 }
942 }
943 inFile->Close() ;
944 }
945 }
946 mergedFile.cd() ;
947 hisRun->Write() ;
948 mergedFile.Close() ;
949 srunList.Delete() ;
950}
951
2e331c8b 952//_____________________________________________________________________________
953Bool_t AliQAManager::MergeData(const Int_t runNumber) const
954{
bededc30 955 // Merge QA data from all detectors for a given run in one single file
956
2e331c8b 957 TFileMerger merger ;
4e25ac79 958 TString outFileName = Form("Merged.%s.Data.root",AliQAv1::GetQADataFileName()) ;
2e331c8b 959 merger.OutputFile(outFileName.Data()) ;
bededc30 960 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4e25ac79 961 char * file = gSystem->Which(gSystem->WorkingDirectory(), Form("%s.%s.%d.root", AliQAv1::GetDetName(iDet), AliQAv1::GetQADataFileName(), runNumber));
bededc30 962 if (file)
963 merger.AddFile(file) ;
964 }
2e331c8b 965 merger.Merge() ;
966 return kTRUE ;
967}
968
969//_____________________________________________________________________________
970Bool_t AliQAManager::MergeResults(const Int_t runNumber) const
971{
972 // Merge the QA result from all the data chunks in a run
bededc30 973 // to be revised whwn it will be used (see MergeData)
2e331c8b 974 TString cmd ;
4e25ac79 975 cmd = Form(".! ls %s*.root > tempo.txt", AliQAv1::GetQADataFileName()) ;
2e331c8b 976 gROOT->ProcessLine(cmd.Data()) ;
977 ifstream in("tempo.txt") ;
978 const Int_t chunkMax = 100 ;
979 TString fileList[chunkMax] ;
980
981 Int_t index = 0 ;
982 while ( 1 ) {
983 TString file ;
984 in >> fileList[index] ;
985 if ( !in.good() )
986 break ;
5379c4a3 987 AliDebug(AliQAv1::GetQADebugLevel(), Form("index = %d file = %s", index, (fileList[index].Data()))) ;
2e331c8b 988 index++ ;
989 }
990
991 if ( index == 0 ) {
992 AliError("No QA Result File found") ;
993 return kFALSE ;
994 }
995
996 TFileMerger merger ;
fc07289e 997 TString outFileName ;
998 if (runNumber != -1)
4e25ac79 999 outFileName = Form("Merged.%s.Result.%d.root",AliQAv1::GetQADataFileName(),runNumber);
fc07289e 1000 else
4e25ac79 1001 outFileName = Form("Merged.%s.Result.root",AliQAv1::GetQADataFileName());
2e331c8b 1002 merger.OutputFile(outFileName.Data()) ;
1003 for (Int_t ifile = 0 ; ifile < index ; ifile++) {
1004 TString file = fileList[ifile] ;
1005 merger.AddFile(file) ;
1006 }
1007 merger.Merge() ;
1008
1009 return kTRUE ;
1010}
1011
1012//_____________________________________________________________________________
1013void AliQAManager::Reset(const Bool_t sameCycle)
1014{
1015 // Reset the default data members
1016
1017 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4e25ac79 1018 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 1019 AliQADataMaker * qadm = GetQADataMaker(iDet);
1020 qadm->Reset();
1021 }
1022 }
1023 if (fRawReaderDelete) {
1024 delete fRawReader ;
1025 fRawReader = NULL ;
1026 }
1027
1028 fCycleSame = sameCycle ;
1029 fESD = NULL ;
1030 fESDTree = NULL ;
1031 //fFirst = kTRUE ;
1032 fNumberOfEvents = 999999 ;
1033}
1034
1035//_____________________________________________________________________________
1036AliQAManager * AliQAManager::QAManager(const Char_t * mode, TMap *entryCache, Int_t run)
1037{
1038 // returns AliQAManager instance (singleton)
1039
1040 if (!fgQAInstance) {
1041 fgQAInstance = new AliQAManager(mode) ;
1042 if (!entryCache)
1043 fgQAInstance->Init();
1044 else
1045 fgQAInstance->InitFromCache(entryCache,run);
1046 }
1047 return fgQAInstance;
1048}
1049
1050//_____________________________________________________________________________
1051TString AliQAManager::Run(const char * detectors, AliRawReader * rawReader, const Bool_t sameCycle)
1052{
1053 //Runs all the QA data Maker for Raws only
1054
1055 fCycleSame = sameCycle ;
1056 fRawReader = rawReader ;
1057 fDetectors = detectors ;
1058 fDetectorsW = detectors ;
1059
1060 AliCDBManager* man = AliCDBManager::Instance() ;
1061
1062 if ( man->GetRun() == -1 ) {// check if run number not set previously and set it from raw data
1063 rawReader->NextEvent() ;
1064 man->SetRun(fRawReader->GetRunNumber()) ;
1065 rawReader->RewindEvents() ;
1066 }
1067
1068 if (!fCycleSame)
4e25ac79 1069 if ( !InitQA(AliQAv1::kRAWS) )
2e331c8b 1070 return kFALSE ;
1071 fRawReaderDelete = kFALSE ;
1072
4e25ac79 1073 DoIt(AliQAv1::kRAWS) ;
2e331c8b 1074 return fDetectorsW ;
1075}
1076
1077//_____________________________________________________________________________
1078TString AliQAManager::Run(const char * detectors, const char * fileName, const Bool_t sameCycle)
1079{
1080 //Runs all the QA data Maker for Raws only
1081
1082 fCycleSame = sameCycle ;
1083 fDetectors = detectors ;
1084 fDetectorsW = detectors ;
1085
1086 AliCDBManager* man = AliCDBManager::Instance() ;
1087 if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun
1088 AliRunLoader * rl = AliRunLoader::Open("galice.root") ;
1089 if ( ! rl ) {
1090 AliFatal("galice.root file not found in current directory") ;
1091 } else {
1092 rl->CdGAFile() ;
1093 rl->LoadgAlice() ;
1094 if ( ! rl->GetAliRun() ) {
1095 AliFatal("AliRun not found in galice.root") ;
1096 } else {
1097 rl->LoadHeader() ;
1098 man->SetRun(rl->GetHeader()->GetRun());
1099 }
1100 }
1101 }
1102
1103 if (!fCycleSame)
4e25ac79 1104 if ( !InitQA(AliQAv1::kRAWS, fileName) )
2e331c8b 1105 return kFALSE ;
1106
4e25ac79 1107 DoIt(AliQAv1::kRAWS) ;
2e331c8b 1108 return fDetectorsW ;
1109}
1110
1111//_____________________________________________________________________________
4e25ac79 1112TString AliQAManager::Run(const char * detectors, const AliQAv1::TASKINDEX_t taskIndex, Bool_t const sameCycle, const char * fileName )
2e331c8b 1113{
1114 // Runs all the QA data Maker for every detector
1115
1116 fCycleSame = sameCycle ;
1117 fDetectors = detectors ;
1118 fDetectorsW = detectors ;
1119
1120 AliCDBManager* man = AliCDBManager::Instance() ;
1121 if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun
1122 AliRunLoader * rl = AliRunLoader::Open("galice.root") ;
1123 if ( ! rl ) {
1124 AliFatal("galice.root file not found in current directory") ;
1125 } else {
1126 rl->CdGAFile() ;
1127 rl->LoadgAlice() ;
1128 if ( ! rl->GetAliRun() ) {
5379c4a3 1129 AliDebug(AliQAv1::GetQADebugLevel(), "AliRun not found in galice.root") ;
2e331c8b 1130 } else {
1131 rl->LoadHeader() ;
1132 man->SetRun(rl->GetHeader()->GetRun()) ;
1133 }
1134 }
1135 }
1136
1137
4e25ac79 1138 if ( taskIndex == AliQAv1::kNULLTASKINDEX) {
1139 for (UInt_t task = 0; task < AliQAv1::kNTASKINDEX; task++) {
2e331c8b 1140 if ( fTasks.Contains(Form("%d", task)) ) {
1141 if (!fCycleSame)
4e25ac79 1142 if ( !InitQA(AliQAv1::GetTaskIndex(AliQAv1::GetTaskName(task)), fileName) )
2e331c8b 1143 return kFALSE ;
4e25ac79 1144 DoIt(AliQAv1::GetTaskIndex(AliQAv1::GetTaskName(task))) ;
2e331c8b 1145 }
1146 }
1147 } else {
1148 if (! fCycleSame )
1149 if ( !InitQA(taskIndex, fileName) )
1150 return kFALSE ;
1151 DoIt(taskIndex) ;
1152 }
1153
1154 return fDetectorsW ;
1155
1156}
1157
1158//_____________________________________________________________________________
1159void AliQAManager::RunOneEvent(AliRawReader * rawReader)
1160{
1161 //Runs all the QA data Maker for Raws only and on one event only (event loop done by calling method)
1162 if ( ! rawReader )
1163 return ;
1164 AliCodeTimerAuto("") ;
4e25ac79 1165 if (fTasks.Contains(Form("%d", AliQAv1::kRAWS))){
2e331c8b 1166 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4e25ac79 1167 if (!IsSelected(AliQAv1::GetDetName(iDet)))
2e331c8b 1168 continue;
1169 AliQADataMaker *qadm = GetQADataMaker(iDet);
1170 if (!qadm)
1171 continue;
1172 if ( qadm->IsCycleDone() ) {
1173 qadm->EndOfCycle() ;
1174 }
4e25ac79 1175 AliCodeTimerStart(Form("running RAW quality assurance data maker for %s", AliQAv1::GetDetName(iDet)));
13a2370e 1176 if ( qadm->GetRecoParam() )
1177 qadm->SetEventSpecie(qadm->GetRecoParam()->GetEventSpecie()) ;
1178 else
1179 qadm->SetEventSpecie(fEventSpecie) ;
4e25ac79 1180 qadm->Exec(AliQAv1::kRAWS, rawReader) ;
1181 AliCodeTimerStop(Form("running RAW quality assurance data maker for %s", AliQAv1::GetDetName(iDet)));
2e331c8b 1182 }
1183 }
1184}
1185
1186//_____________________________________________________________________________
1187void AliQAManager::RunOneEvent(AliESDEvent *& esd)
1188{
1189 //Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
1190
1191 AliCodeTimerAuto("") ;
4e25ac79 1192 if (fTasks.Contains(Form("%d", AliQAv1::kESDS))) {
2e331c8b 1193 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4e25ac79 1194 if (!IsSelected(AliQAv1::GetDetName(iDet)))
2e331c8b 1195 continue;
1196 AliQADataMaker *qadm = GetQADataMaker(iDet);
1197 if (!qadm)
1198 continue;
1199 if ( qadm->IsCycleDone() ) {
1200 qadm->EndOfCycle() ;
1201 }
4e25ac79 1202 AliCodeTimerStart(Form("running ESD quality assurance data maker for %s", AliQAv1::GetDetName(iDet)));
1203 qadm->Exec(AliQAv1::kESDS, esd) ;
1204 AliCodeTimerStop(Form("running ESD quality assurance data maker for %s", AliQAv1::GetDetName(iDet)));
2e331c8b 1205 }
1206 }
1207}
1208
1209//_____________________________________________________________________________
1210void AliQAManager::RunOneEventInOneDetector(Int_t det, TTree * tree)
1211{
1212 // Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
1213 AliCodeTimerAuto("") ;
4e25ac79 1214 if (fTasks.Contains(Form("%d", AliQAv1::kRECPOINTS))) {
1215 if (IsSelected(AliQAv1::GetDetName(det))) {
2e331c8b 1216 AliQADataMaker *qadm = GetQADataMaker(det);
1217 if (qadm) {
1218 if ( qadm->IsCycleDone() ) {
1219 qadm->EndOfCycle() ;
1220 }
4e25ac79 1221 AliCodeTimerStart(Form("running RecPoints quality assurance data maker for %s", AliQAv1::GetDetName(det)));
1222 qadm->Exec(AliQAv1::kRECPOINTS, tree) ;
1223 AliCodeTimerStop(Form("running RecPoints quality assurance data maker for %s", AliQAv1::GetDetName(det)));
2e331c8b 1224 }
1225 }
1226 }
1227}
1228
1229//_____________________________________________________________________________
1230Bool_t AliQAManager::Save2OCDB(const Int_t runNumber, AliRecoParam::EventSpecie_t es, const char * year, const char * detectors) const
1231{
1232 // take the locasl QA data merge into a single file and save in OCDB
1233 Bool_t rv = kTRUE ;
4e25ac79 1234 TString tmp(AliQAv1::GetQARefStorage()) ;
2e331c8b 1235 if ( tmp.IsNull() ) {
4e25ac79 1236 AliError("No storage defined, use AliQAv1::SetQARefStorage") ;
2e331c8b 1237 return kFALSE ;
1238 }
4e25ac79 1239 if ( !(tmp.Contains(AliQAv1::GetLabLocalOCDB()) || tmp.Contains(AliQAv1::GetLabAliEnOCDB())) ) {
1240 AliError(Form("%s is a wrong storage, use %s or %s", AliQAv1::GetQARefStorage(), AliQAv1::GetLabLocalOCDB().Data(), AliQAv1::GetLabAliEnOCDB().Data())) ;
2e331c8b 1241 return kFALSE ;
1242 }
1243 TString sdet(detectors) ;
1244 sdet.ToUpper() ;
1245 TFile * inputFile ;
1246 if ( sdet.Contains("ALL") ) {
1247 rv = Merge(runNumber) ;
1248 if ( ! rv )
1249 return kFALSE ;
4e25ac79 1250 TString inputFileName(Form("Merged.%s.Data.%d.root", AliQAv1::GetQADataFileName(), runNumber)) ;
2e331c8b 1251 inputFile = TFile::Open(inputFileName.Data()) ;
1252 rv = SaveIt2OCDB(runNumber, inputFile, year, es) ;
1253 } else {
4e25ac79 1254 for (Int_t index = 0; index < AliQAv1::kNDET; index++) {
1255 if (sdet.Contains(AliQAv1::GetDetName(index))) {
1256 TString inputFileName(Form("%s.%s.%d.root", AliQAv1::GetDetName(index), AliQAv1::GetQADataFileName(), runNumber)) ;
2e331c8b 1257 inputFile = TFile::Open(inputFileName.Data()) ;
1258 rv *= SaveIt2OCDB(runNumber, inputFile, year, es) ;
1259 }
1260 }
1261 }
1262 return rv ;
1263}
1264
1265//_____________________________________________________________________________
1266Bool_t AliQAManager::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile, const char * year, AliRecoParam::EventSpecie_t es) const
1267{
1268 // reads the TH1 from file and adds it to appropriate list before saving to OCDB
1269 Bool_t rv = kTRUE ;
5379c4a3 1270 AliDebug(AliQAv1::GetQADebugLevel(), Form("Saving TH1s in %s to %s", inputFile->GetName(), AliQAv1::GetQARefStorage())) ;
2e331c8b 1271 if ( ! IsDefaultStorageSet() ) {
4e25ac79 1272 TString tmp( AliQAv1::GetQARefStorage() ) ;
1273 if ( tmp.Contains(AliQAv1::GetLabLocalOCDB()) )
1274 Instance()->SetDefaultStorage(AliQAv1::GetQARefStorage()) ;
2e331c8b 1275 else {
4e25ac79 1276 TString tmp1(AliQAv1::GetQARefDefaultStorage()) ;
2e331c8b 1277 tmp1.Append(year) ;
1278 tmp1.Append("?user=alidaq") ;
1279 Instance()->SetDefaultStorage(tmp1.Data()) ;
1280 }
1281 }
4e25ac79 1282 Instance()->SetSpecificStorage("*", AliQAv1::GetQARefStorage()) ;
2e331c8b 1283 if(GetRun() < 0)
1284 Instance()->SetRun(runNumber);
1285
1286 AliCDBMetaData mdr ;
1287 mdr.SetResponsible("yves schutz");
1288
4e25ac79 1289 for ( Int_t detIndex = 0 ; detIndex < AliQAv1::kNDET ; detIndex++) {
1290 TDirectory * detDir = inputFile->GetDirectory(AliQAv1::GetDetName(detIndex)) ;
2e331c8b 1291 if ( detDir ) {
5379c4a3 1292 AliDebug(AliQAv1::GetQADebugLevel(), Form("Entering %s", detDir->GetName())) ;
4e25ac79 1293 AliQAv1::SetQARefDataDirName(es) ;
1294 TString detOCDBDir(Form("%s/%s/%s", AliQAv1::GetDetName(detIndex), AliQAv1::GetRefOCDBDirName(), AliQAv1::GetRefDataDirName())) ;
2e331c8b 1295 AliCDBId idr(detOCDBDir.Data(), runNumber, AliCDBRunRange::Infinity()) ;
1296 TList * listDetQAD = new TList() ;
4e25ac79 1297 TString listName(Form("%s QA data Reference", AliQAv1::GetDetName(detIndex))) ;
1298 mdr.SetComment(Form("%s QA stuff", AliQAv1::GetDetName(detIndex)));
2e331c8b 1299 listDetQAD->SetName(listName) ;
1300 TList * taskList = detDir->GetListOfKeys() ;
1301 TIter nextTask(taskList) ;
1302 TKey * taskKey ;
1303 while ( (taskKey = dynamic_cast<TKey*>(nextTask())) ) {
1304 TDirectory * taskDir = detDir->GetDirectory(taskKey->GetName()) ;
1305 TDirectory * esDir = taskDir->GetDirectory(AliRecoParam::GetEventSpecieName(es)) ;
5379c4a3 1306 AliDebug(AliQAv1::GetQADebugLevel(), Form("Saving %s", esDir->GetName())) ;
2e331c8b 1307 TObjArray * listTaskQAD = new TObjArray(100) ;
1308 listTaskQAD->SetName(Form("%s/%s", taskKey->GetName(), AliRecoParam::GetEventSpecieName(es))) ;
1309 listDetQAD->Add(listTaskQAD) ;
1310 TList * histList = esDir->GetListOfKeys() ;
1311 TIter nextHist(histList) ;
1312 TKey * histKey ;
1313 while ( (histKey = dynamic_cast<TKey*>(nextHist())) ) {
1314 TObject * odata = esDir->Get(histKey->GetName()) ;
1315 if ( !odata ) {
1316 AliError(Form("%s in %s/%s returns a NULL pointer !!", histKey->GetName(), detDir->GetName(), taskDir->GetName())) ;
1317 } else {
4e25ac79 1318 if ( AliQAv1::GetExpert() == histKey->GetName() ) {
2e331c8b 1319 TDirectory * expertDir = esDir->GetDirectory(histKey->GetName()) ;
1320 TList * expertHistList = expertDir->GetListOfKeys() ;
1321 TIter nextExpertHist(expertHistList) ;
1322 TKey * expertHistKey ;
1323 while ( (expertHistKey = dynamic_cast<TKey*>(nextExpertHist())) ) {
1324 TObject * expertOdata = expertDir->Get(expertHistKey->GetName()) ;
1325 if ( !expertOdata ) {
1326 AliError(Form("%s in %s/%s/Expert returns a NULL pointer !!", expertHistKey->GetName(), detDir->GetName(), taskDir->GetName())) ;
1327 } else {
5379c4a3 1328 AliDebug(AliQAv1::GetQADebugLevel(), Form("Adding %s", expertHistKey->GetName())) ;
2e331c8b 1329 if ( expertOdata->IsA()->InheritsFrom("TH1") ) {
5379c4a3 1330 AliDebug(AliQAv1::GetQADebugLevel(), Form("Adding %s", expertHistKey->GetName())) ;
2e331c8b 1331 TH1 * hExpertdata = static_cast<TH1*>(expertOdata) ;
1332 listTaskQAD->Add(hExpertdata) ;
1333 }
1334 }
1335 }
1336 }
5379c4a3 1337 AliDebug(AliQAv1::GetQADebugLevel(), Form("Adding %s", histKey->GetName())) ;
2e331c8b 1338 if ( odata->IsA()->InheritsFrom("TH1") ) {
5379c4a3 1339 AliDebug(AliQAv1::GetQADebugLevel(), Form("Adding %s", histKey->GetName())) ;
2e331c8b 1340 TH1 * hdata = static_cast<TH1*>(odata) ;
1341 listTaskQAD->Add(hdata) ;
1342 }
1343 }
1344 }
1345 }
1346 Instance()->Put(listDetQAD, idr, &mdr) ;
1347 }
1348 }
1349 return rv ;
1350}
1351
1352//_____________________________________________________________________________
1353void AliQAManager::SetEventSpecie(AliRecoParam::EventSpecie_t es)
1354{
4e25ac79 1355 // set the current event specie and inform AliQAv1 that this event specie has been encountered
bc8761a0 1356 fEventSpecie = es ;
4e25ac79 1357 AliQAv1::Instance()->SetEventSpecie(es) ;
2e331c8b 1358}
1359
1360//_____________________________________________________________________________
1361void AliQAManager::SetRecoParam(const Int_t det, const AliDetectorRecoParam *par)
1362{
1363 // Set custom reconstruction parameters for a given detector
1364 // Single set of parameters for all the events
1365 GetQADataMaker(det)->SetRecoParam(par) ;
1366}
1367
75373542 1368//_____________________________________________________________________________
1369void AliQAManager::SetWriteExpert()
1370{
1371 // enable the writing of QA expert data
1372 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4e25ac79 1373 if (IsSelected(AliQAv1::GetDetName(iDet)))
75373542 1374 fQAWriteExpert[iDet] = kTRUE ;
1375 }
1376}