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