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