]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliQADataMakerSteer.cxx
Bug fix: corrected file name (Levente)
[u/mrichter/AliRoot.git] / STEER / AliQADataMakerSteer.cxx
index 27fbe09435363afdd733213a07716be3e8378399..293937828cc91ce3e4ca5059490535c8a0ce8eb0 100644 (file)
@@ -59,6 +59,7 @@ ClassImp(AliQADataMakerSteer)
 //_____________________________________________________________________________
 AliQADataMakerSteer::AliQADataMakerSteer(const char* gAliceFilename, const char * name, const char * title) :
        TNamed(name, title), 
+       fCurrentEvent(0),  
        fCycleSame(kFALSE),
        fDetectors("ALL"), 
        fDetectorsW("ALL"), 
@@ -66,13 +67,18 @@ AliQADataMakerSteer::AliQADataMakerSteer(const char* gAliceFilename, const char
        fESDTree(NULL),
        fFirst(kTRUE),  
        fGAliceFileName(gAliceFilename), 
-       fRunNumber(0), 
+       fFirstEvent(0),        
+       fMaxEvents(0),        
        fNumberOfEvents(999999), 
+    fRunNumber(0), 
        fRawReader(NULL), 
        fRawReaderDelete(kTRUE), 
-       fRunLoader(NULL)  
+       fRunLoader(NULL),
+       fQADataMakers()
+
 {
        // default ctor
+       fMaxEvents = fNumberOfEvents ; 
        for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
                if (IsSelected(AliQA::GetDetName(iDet))) {
                        fLoader[iDet]      = NULL ;
@@ -85,6 +91,7 @@ AliQADataMakerSteer::AliQADataMakerSteer(const char* gAliceFilename, const char
 //_____________________________________________________________________________
 AliQADataMakerSteer::AliQADataMakerSteer(const AliQADataMakerSteer & qas) : 
        TNamed(qas), 
+       fCurrentEvent(qas.fCurrentEvent),  
        fCycleSame(kFALSE),
        fDetectors(qas.fDetectors), 
        fDetectorsW(qas.fDetectorsW), 
@@ -92,11 +99,14 @@ AliQADataMakerSteer::AliQADataMakerSteer(const AliQADataMakerSteer & qas) :
        fESDTree(NULL), 
        fFirst(qas.fFirst),  
        fGAliceFileName(qas.fGAliceFileName), 
-       fRunNumber(qas.fRunNumber), 
+       fFirstEvent(qas.fFirstEvent),        
+       fMaxEvents(qas.fMaxEvents),        
        fNumberOfEvents(qas.fNumberOfEvents), 
+    fRunNumber(qas.fRunNumber), 
        fRawReader(NULL), 
        fRawReaderDelete(kTRUE), 
-       fRunLoader(NULL)  
+       fRunLoader(NULL),
+       fQADataMakers()
 {
        // cpy ctor
        for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
@@ -138,13 +148,14 @@ AliQADataMakerSteer::~AliQADataMakerSteer()
 }
 
 //_____________________________________________________________________________
-Bool_t AliQADataMakerSteer::DoIt(const AliQA::TASKINDEX taskIndex, const char * mode)
+Bool_t AliQADataMakerSteer::DoIt(const AliQA::TASKINDEX_t taskIndex, const char * mode)
 {
        // Runs all the QA data Maker for every detector
-
+               
        Bool_t rv = kFALSE ;
     // Fill QA data in event loop 
-       for (UInt_t iEvent = 0 ; iEvent < fNumberOfEvents ; iEvent++) {
+       for (UInt_t iEvent = fFirstEvent ; iEvent < (UInt_t)fMaxEvents ; iEvent++) {
+               fCurrentEvent++ ; 
                // Get the event
                if ( iEvent%10 == 0  ) 
                        AliInfo(Form("processing event %d", iEvent));
@@ -158,80 +169,67 @@ Bool_t AliQADataMakerSteer::DoIt(const AliQA::TASKINDEX taskIndex, const char *
                        if ( fRunLoader->GetEvent(iEvent) != 0 )
                                break ;
                }
-               // loop over detectors
-               TObjArray* detArray = NULL ; 
-               if (fRunLoader) // check if RunLoader exists 
-                       if ( fRunLoader->GetAliRun() ) // check if AliRun exists in gAlice.root
-                               detArray = fRunLoader->GetAliRun()->Detectors() ;
-               for (UInt_t iDet = 0 ; iDet < fgkNDetectors ; iDet++) {
-                       if (detArray) {
-                               AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
-                               if (!det || !det->IsActive()) 
-                                       continue ;
+               // loop  over active loaders
+               for (Int_t i = 0; i < fQADataMakers.GetEntriesFast() ; i++) {
+                       AliQADataMaker * qadm = static_cast<AliQADataMaker *>(fQADataMakers.At(i)) ;
+                       if ( qadm->IsCycleDone() ) {
+                               qadm->EndOfCycle(AliQA::kRAWS) ;
+                               qadm->StartOfCycle(AliQA::kRAWS) ;
                        }
-                       if (!IsSelected(AliQA::GetDetName(iDet)))
-                               continue ;
-                       AliQADataMaker * qadm = GetQADataMaker(iDet, mode) ;
-                       if (!qadm) {
-                               rv = kFALSE ;
-                       } else {
-                               if ( qadm->IsCycleDone() ) {
-                                       qadm->EndOfCycle(AliQA::kRAWS) ;
-                                       qadm->StartOfCycle(AliQA::kRAWS) ;
-                               }
-                               TTree * data ; 
-                               switch (taskIndex) {
-                                       case AliQA::kRAWS :
-                                               qadm->Exec(taskIndex, fRawReader) ; 
-                                               break ; 
-                                       case AliQA::kHITS :
-                                               GetLoader(iDet)->LoadHits() ; 
-                                               data = GetLoader(iDet)->TreeH() ; 
-                                               if ( ! data ) {
-                                                       AliWarning(Form(" Hit Tree not found for  %s", AliQA::GetDetName(iDet))) ; 
-                                               } else {
-                                                       qadm->Exec(taskIndex, data) ;
-                                               } 
-                                               break ;
-                                               case AliQA::kSDIGITS :
-                                               GetLoader(iDet)->LoadSDigits() ; 
-                                               data = GetLoader(iDet)->TreeS() ; 
-                                               if ( ! data ) {
-                                                       AliWarning(Form(" SDigit Tree not found for  %s", AliQA::GetDetName(iDet))) ; 
-                                               } else {
-                                                       qadm->Exec(taskIndex, data) ; 
-                                               }
-                                               break; 
-                                               case AliQA::kDIGITS :
-                                               GetLoader(iDet)->LoadDigits() ; 
-                                               data = GetLoader(iDet)->TreeD() ; 
-                                               if ( ! data ) {
-                                                       AliWarning(Form(" Digit Tree not found for  %s", AliQA::GetDetName(iDet))) ; 
-                                               } else {
-                                                       qadm->Exec(taskIndex, data) ;
-                                               }
-                                               break; 
-                                               case AliQA::kRECPOINTS :
-                                               GetLoader(iDet)->LoadRecPoints() ; 
-                                               data = GetLoader(iDet)->TreeR() ; 
-                                               if (!data) {
-                                                       AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ; 
-                                               } else {
-                                                       qadm->Exec(taskIndex, data) ; 
-                                               }
-                                               break; 
-                                               case AliQA::kTRACKSEGMENTS :
-                                               break; 
-                                               case AliQA::kRECPARTICLES :
-                                               break; 
-                                               case AliQA::kESDS :
-                                               qadm->Exec(taskIndex, fESD) ;
-                                               break; 
-                                               case AliQA::kNTASKINDEX :
-                                               break; 
-                               } //task switch
-                               //qadm->Increment() ; 
-                       } //data maker exist
+                       TTree * data ; 
+                       Int_t iDet = qadm->GetUniqueID();
+                       AliLoader* loader = GetLoader(iDet);
+                       switch (taskIndex) {
+                               case AliQA::kRAWS :
+                                       qadm->Exec(taskIndex, fRawReader) ; 
+                                       break ; 
+                               case AliQA::kHITS :
+                                       loader->LoadHits() ; 
+                                       data = loader->TreeH() ; 
+                                       if ( ! data ) {
+                                               AliWarning(Form(" Hit Tree not found for  %s", AliQA::GetDetName(iDet))) ; 
+                                       } else {
+                                               qadm->Exec(taskIndex, data) ;
+                                       } 
+                                       break ;
+                                       case AliQA::kSDIGITS :
+                                       loader->LoadSDigits() ; 
+                                       data = loader->TreeS() ; 
+                                       if ( ! data ) {
+                                               AliWarning(Form(" SDigit Tree not found for  %s", AliQA::GetDetName(iDet))) ; 
+                                       } else {
+                                               qadm->Exec(taskIndex, data) ; 
+                                       }
+                                       break; 
+                                       case AliQA::kDIGITS :
+                                       loader->LoadDigits() ; 
+                                       data = loader->TreeD() ; 
+                                       if ( ! data ) {
+                                               AliWarning(Form(" Digit Tree not found for  %s", AliQA::GetDetName(iDet))) ; 
+                                       } else {
+                                               qadm->Exec(taskIndex, data) ;
+                                       }
+                                       break; 
+                                       case AliQA::kRECPOINTS :
+                                       loader->LoadRecPoints() ; 
+                                       data = loader->TreeR() ; 
+                                       if (!data) {
+                                               AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ; 
+                                       } else {
+                                               qadm->Exec(taskIndex, data) ; 
+                                       }
+                                       break; 
+                                       case AliQA::kTRACKSEGMENTS :
+                                       break; 
+                                       case AliQA::kRECPARTICLES :
+                                       break; 
+                                       case AliQA::kESDS :
+                                       qadm->Exec(taskIndex, fESD) ;
+                                       break; 
+                                       case AliQA::kNTASKINDEX :
+                                       break; 
+                       } //task switch
+                       //qadm->Increment() ; 
                } // detector loop
        } // event loop 
 //     // Save QA data for all detectors
@@ -241,22 +239,18 @@ Bool_t AliQADataMakerSteer::DoIt(const AliQA::TASKINDEX taskIndex, const char *
 }
 
 //_____________________________________________________________________________
-Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX taskIndex, const char * mode
+Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX_t taskIndex, const char * /*mode*/
 {
        // write output to file for all detectors
-       for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
-               if (IsSelected(AliQA::GetDetName(iDet))) {
-                       AliQADataMaker * qadm = GetQADataMaker(iDet, mode) ;
-                       if (qadm) {
-                               qadm->EndOfCycle(taskIndex) ; 
-                       }
-               }
-       }
+       for (Int_t i = 0; i < fQADataMakers.GetEntriesFast() ; i++) {
+               AliQADataMaker * qadm = static_cast<AliQADataMaker *>(fQADataMakers.At(i));
+               qadm->EndOfCycle(taskIndex) ; 
+       }    
        return kTRUE ; 
 }
 
 //_____________________________________________________________________________
-TObjArray * AliQADataMakerSteer::GetFromOCDB(AliQA::DETECTORINDEX det, AliQA::TASKINDEX task) const 
+TObjArray * AliQADataMakerSteer::GetFromOCDB(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, const char * year) const 
 {
        // Retrieve the list of QA data for a given detector and a given task 
        TObjArray * rv = NULL ;
@@ -267,13 +261,15 @@ TObjArray * AliQADataMakerSteer::GetFromOCDB(AliQA::DETECTORINDEX det, AliQA::TA
        }       
        AliCDBManager* man = AliCDBManager::Instance() ; 
        if ( ! man->IsDefaultStorageSet() ) {
-               man->SetDefaultStorage(AliQA::GetQARefDefaultStorage()) ; 
-               man->SetSpecificStorage(Form("%s/*", AliQA::GetQAOCDBDirName()), AliQA::GetQARefStorage()) ;
+               TString tmp(AliQA::GetQARefDefaultStorage()) ; 
+               tmp.Append(year) ; 
+               tmp.Append("/") ; 
+               man->SetDefaultStorage(tmp.Data()) ;            
+               man->SetSpecificStorage(Form("%s/*", AliQA::GetQAName()), AliQA::GetQARefStorage()) ;
        }
-       char detOCDBDir[10] ; 
-       sprintf(detOCDBDir, "%s/%s/%s", AliQA::GetQAOCDBDirName(), AliQA::GetDetName((Int_t)det), AliQA::GetRefOCDBDirName()) ; 
-       AliInfo(Form("Retrieving reference data from %s/%s for %s", AliQA::GetQARefStorage(), detOCDBDir, AliQA::GetTaskName(task).Data())) ; 
-       AliCDBEntry* entry = man->Get(detOCDBDir, 0) ; //FIXME 0 --> Run Number
+       TString detOCDBDir(Form("%s/%s/%s", AliQA::GetQAName(), AliQA::GetDetName((Int_t)det), AliQA::GetRefOCDBDirName())) ; 
+       AliInfo(Form("Retrieving reference data from %s/%s for %s", AliQA::GetQARefStorage(), detOCDBDir.Data(), AliQA::GetTaskName(task).Data())) ; 
+       AliCDBEntry* entry = man->Get(detOCDBDir.Data(), 0) ; //FIXME 0 --> Run Number
        TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
        if ( listDetQAD ) 
                rv = dynamic_cast<TObjArray *>(listDetQAD->FindObject(AliQA::GetTaskName(task))) ; 
@@ -284,6 +280,9 @@ TObjArray * AliQADataMakerSteer::GetFromOCDB(AliQA::DETECTORINDEX det, AliQA::TA
 AliLoader * AliQADataMakerSteer::GetLoader(Int_t iDet)
 {
        // get the loader for a detector
+
+       if ( !fRunLoader ) 
+               return NULL ; 
        
        TString detName = AliQA::GetDetName(iDet) ;
     fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
@@ -360,21 +359,13 @@ AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(const Int_t iDet, const cha
 }
 
 //_____________________________________________________________________________
-Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, const char * mode, const  char * input )
+Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX_t taskIndex, const char * mode, const  char * input )
 {
        // Initialize the event source and QA data makers
        
        if (taskIndex == AliQA::kRAWS) { 
                if (!fRawReader) {
-                       TString fileName(input);
-                       if (fileName.EndsWith("/")) {
-                               fRawReader = new AliRawReaderFile(fileName);
-                       } else if (fileName.EndsWith(".root")) {
-                               fRawReader = new AliRawReaderRoot(fileName);
-                       } else if (!fileName.IsNull()) {
-                               fRawReader = new AliRawReaderDate(fileName);
-                               fRawReader->SelectEvents(7);
-                       }
+                       fRawReader = AliRawReader::Create(input);
                }
            if ( ! fRawReader ) 
                        return kFALSE ; 
@@ -384,7 +375,9 @@ Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, const char *
                AliCDBManager::Instance()->SetRun(fRunNumber) ; 
                fRawReader->RewindEvents();
                fNumberOfEvents = 999999 ;
-       } else if (taskIndex == AliQA::kESDS) {
+               if ( fMaxEvents < 0 ) 
+                       fMaxEvents = fNumberOfEvents ; 
+               } else if (taskIndex == AliQA::kESDS) {
                if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists
                        TFile * esdFile = TFile::Open("AliESDs.root") ;
                        fESDTree = dynamic_cast<TTree *> (esdFile->Get("esdTree")) ; 
@@ -397,21 +390,34 @@ Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, const char *
                                fESDTree->GetEntry(0) ; 
                                fRunNumber = fESD->GetRunNumber() ; 
                                fNumberOfEvents = fESDTree->GetEntries() ;
+                               if ( fMaxEvents < 0 ) 
+                                       fMaxEvents = fNumberOfEvents ; 
                        }
                } else {
                        AliError("AliESDs.root not found") ; 
                        return kFALSE ; 
                }                       
-       } else {
+               } else {
                if ( !InitRunLoader() ) { 
                        AliWarning("No Run Loader not found") ; 
                } else {
                        fNumberOfEvents = fRunLoader->GetNumberOfEvents() ;
+                       if ( fMaxEvents < 0 ) 
+                               fMaxEvents = fNumberOfEvents ; 
+
                }
        }
-               // Initialize all QA data makers for all detectors
-       for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
 
+       // Get Detectors 
+       TObjArray* detArray = NULL ; 
+       if (fRunLoader) // check if RunLoader exists 
+               if ( fRunLoader->GetAliRun() ) { // check if AliRun exists in gAlice.root
+                       detArray = fRunLoader->GetAliRun()->Detectors() ;
+                       fRunNumber = fRunLoader->GetHeader()->GetRun() ; 
+               }
+       // Build array of QA data makers for all detectors
+       fQADataMakers.Clear();
+       for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
                if (IsSelected(AliQA::GetDetName(iDet))) {
                        AliQADataMaker * qadm = GetQADataMaker(iDet, mode) ;
                        if (!qadm) {
@@ -419,11 +425,25 @@ Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, const char *
                                fDetectorsW.ReplaceAll(AliQA::GetDetName(iDet), "") ; 
                        } else {
                                AliDebug(1, Form("Data Maker found for %s", qadm->GetName())) ; 
-                               qadm->Init(taskIndex, fRunNumber, GetQACycles(iDet)) ;
-                               qadm->StartOfCycle(taskIndex, fCycleSame) ;
+                               // skip non active detectors
+                               if (detArray) {
+                                       AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
+                                       if (!det || !det->IsActive())  
+                                               continue ;
+                               }
+                               qadm->SetName(AliQA::GetDetName(iDet));
+                               qadm->SetUniqueID(iDet);
+                               fQADataMakers.Add(qadm);
                        }
                }
        } 
+       // Initialize all QA data makers for all detectors
+       fRunNumber = AliCDBManager::Instance()->GetRun() ; 
+       for (Int_t i = 0; i < fQADataMakers.GetEntriesFast() ; i++) {
+               AliQADataMaker * qadm = static_cast<AliQADataMaker *>(fQADataMakers.At(i));
+               qadm->Init(taskIndex, fRunNumber, GetQACycles(qadm->GetUniqueID())) ;
+               qadm->StartOfCycle(taskIndex, fCycleSame) ;
+       } 
        fFirst = kFALSE ;
        return kTRUE ; 
 }
@@ -434,43 +454,46 @@ Bool_t AliQADataMakerSteer::InitRunLoader()
        // get or create the run loader
        if (fRunLoader) {
                fCycleSame = kTRUE ; 
-               return kTRUE ;
-       } 
-               
-       if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
-    // load all base libraries to get the loader classes
-               TString libs = gSystem->GetLibraries() ;
-               for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
-                       if (!IsSelected(AliQA::GetDetName(iDet))) 
-                               continue ; 
-                       TString detName = AliQA::GetDetName(iDet) ;
-                       if (detName == "HLT") 
-                               continue;
-                       if (libs.Contains("lib" + detName + "base.so")) 
-                               continue;
-                       gSystem->Load("lib" + detName + "base.so");
-               }
-               fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
-               if (!fRunLoader) {
-                       AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
-                       return kFALSE;
-               }
-               fRunLoader->CdGAFile();
-               if (fRunLoader->LoadgAlice() == 0) {
-                       gAlice = fRunLoader->GetAliRun();
-               }
+       } else {
+               if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
+                       // load all base libraries to get the loader classes
+                       TString libs = gSystem->GetLibraries() ;
+                       for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
+                               if (!IsSelected(AliQA::GetDetName(iDet))) 
+                                       continue ; 
+                               TString detName = AliQA::GetDetName(iDet) ;
+                               if (detName == "HLT") 
+                                       continue;
+                               if (libs.Contains("lib" + detName + "base.so")) 
+                                       continue;
+                               gSystem->Load("lib" + detName + "base.so");
+                       }
+                       fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
+                       if (!fRunLoader) {
+                               AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
+                               return kFALSE;
+                       }
+                       fRunLoader->CdGAFile();
+                       if (fRunLoader->LoadgAlice() == 0) {
+                               gAlice = fRunLoader->GetAliRun();
+                       }
+
+                       if (!gAlice) {
+                               AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
+                               return kFALSE;
+                       }
 
-               if (!gAlice) {
-                       AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
+               } else {               // galice.root does not exist
+                       AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
                        return kFALSE;
                }
+       }
 
-       } else {               // galice.root does not exist
-               AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
-               return kFALSE;
-    }
-
-  return kTRUE;
+       if (!fRunNumber) { 
+               fRunLoader->LoadHeader();
+               fRunNumber = fRunLoader->GetHeader()->GetRun() ; 
+       }
+       return kTRUE;
 }
 
 //_____________________________________________________________________________
@@ -479,23 +502,16 @@ Bool_t AliQADataMakerSteer::IsSelected(const char * det)
        // check whether detName is contained in detectors
        // if yes, it is removed from detectors
        
+       Bool_t rv = kFALSE;
        const TString detName(det) ;
        // check if all detectors are selected
-       if ((fDetectors.CompareTo("ALL") == 0) ||
-               fDetectors.BeginsWith("ALL ") ||
-               fDetectors.EndsWith(" ALL") ||
-               fDetectors.Contains(" ALL ")) {
+       if (fDetectors.Contains("ALL")) {
                fDetectors = "ALL";
-               return kTRUE;
-       }
-       
-       // search for the given detector
-       Bool_t rv = kFALSE;
-       //AliInfo(Form("SSSSSSSSSSSSS fd = %s det = %s ", fDetectors.Data(), det)) ; 
-       if ((fDetectors.CompareTo(detName) == 0) ||
-               fDetectors.BeginsWith(detName+" ") ||
-               fDetectors.EndsWith(" "+detName) ||
-               fDetectors.Contains(" "+detName+" ")) {
+               rv = kTRUE;
+       } else if ((fDetectors.CompareTo(detName) == 0) ||
+                          fDetectors.BeginsWith(detName+" ") ||
+                          fDetectors.EndsWith(" "+detName) ||
+                          fDetectors.Contains(" "+detName+" ")) {
                //              fDetectors.ReplaceAll(detName, "");
                rv = kTRUE;
        }
@@ -515,24 +531,24 @@ Bool_t AliQADataMakerSteer::IsSelected(const char * det)
 Bool_t AliQADataMakerSteer::Merge(const Int_t runNumber) const
 {
        // Merge all the cycles from all detectors in one single file per run
-       char cmd[80] ;
+       TString cmd ;
        if ( runNumber == -1 )
-               sprintf(cmd, ".! ls *%s*.*.*.root > tempo.txt", AliQA::GetQADataFileName()) ; 
+               cmd = Form(".! ls *%s*.*.*.root > tempo.txt", AliQA::GetQADataFileName()) ; 
        else 
-               sprintf(cmd, ".! ls *%s*.%d.*.root > tempo.txt", AliQA::GetQADataFileName(), runNumber) ; 
-       gROOT->ProcessLine(cmd) ;
+               cmd = Form(".! ls *%s*.%d.*.root > tempo.txt", AliQA::GetQADataFileName(), runNumber) ; 
+       gROOT->ProcessLine(cmd.Data()) ;
        ifstream in("tempo.txt") ; 
        const Int_t runMax = 10 ;  
        TString file[AliQA::kNDET*runMax] ;
-       Int_t run[AliQA::kNDET*runMax] ;
+       Int_t run[AliQA::kNDET*runMax] = {-1} ;
        
        Int_t index = 0 ; 
        while ( 1 ) {
                in >> file[index] ; 
-               AliInfo(Form("index = %d file = %s", index, (file[index]).Data())) ; 
-               index++ ;
                if ( !in.good() ) 
                        break ; 
+               AliInfo(Form("index = %d file = %s", index, (file[index]).Data())) ; 
+               index++ ;
        }
        
        if ( index == 0 ) { 
@@ -542,8 +558,7 @@ Bool_t AliQADataMakerSteer::Merge(const Int_t runNumber) const
        
        Int_t runIndex    = 0 ;  
        Int_t runIndexMax = 0 ; 
-       char stmp[10] ; 
-       sprintf(stmp, ".%s.", AliQA::GetQADataFileName()) ; 
+       TString stmp(Form(".%s.", AliQA::GetQADataFileName())) ; 
        for (Int_t ifile = 0 ; ifile < index ; ifile++) {
                TString tmp(file[ifile]) ; 
                tmp.ReplaceAll(".root", "") ; 
@@ -564,12 +579,10 @@ Bool_t AliQADataMakerSteer::Merge(const Int_t runNumber) const
        }
        for (Int_t irun = 0 ; irun < runIndexMax ; irun++) {
                TFileMerger merger ; 
-               char outFileName[20] ; 
-               sprintf(outFileName, "Merged.%s.%d.root", AliQA::GetQADataFileName(), run[irun]) ; 
-               merger.OutputFile(outFileName) ; 
+               TString outFileName(Form("Merged.%s.%d.root",AliQA::GetQADataFileName(),run[irun]));            
+               merger.OutputFile(outFileName.Data()) ; 
                for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) {
-                       char pattern[100] ; 
-                       sprintf(pattern, "%s.%d.", AliQA::GetQADataFileName(), run[irun]) ; 
+                       TString pattern(Form("%s.%d.", AliQA::GetQADataFileName(), run[irun])) ; 
                        TString tmp(file[ifile]) ; 
                        if (tmp.Contains(pattern)) {
                                merger.AddFile(tmp) ; 
@@ -585,17 +598,11 @@ Bool_t AliQADataMakerSteer::Merge(const Int_t runNumber) const
 void AliQADataMakerSteer::Reset(const Bool_t sameCycle)
 {
        // Reset the default data members
-       for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
-               if (IsSelected(AliQA::GetDetName(iDet))) {
-                       fLoader[iDet] = NULL;
-                       if (fQADataMaker[iDet]) {
-                               (fQADataMaker[iDet])->Reset(sameCycle) ; 
-                               //delete fQADataMaker[iDet] ;
-                               //fQADataMaker[iDet] = NULL ;
-                       }
-               }
-       }
 
+       for (Int_t i = 0; i < fQADataMakers.GetEntriesFast() ; i++) {
+               AliQADataMaker * qadm = static_cast<AliQADataMaker *>(fQADataMakers.At(i));
+               qadm->Reset(sameCycle);
+       } 
        if (fRawReaderDelete) { 
                delete fRawReader ;
                fRawReader      = NULL ;
@@ -609,91 +616,115 @@ void AliQADataMakerSteer::Reset(const Bool_t sameCycle)
 }
 
 //_____________________________________________________________________________
-Bool_t AliQADataMakerSteer::Run(const char * detectors, AliRawReader * rawReader
+TString AliQADataMakerSteer::Run(const char * detectors, AliRawReader * rawReader, const Bool_t sameCycle
 {
        //Runs all the QA data Maker for Raws only
-       fRawReader       = rawReader ;          
-       fRawReaderDelete = kFALSE ; 
-       fCycleSame       = kTRUE ; 
+       
+       fCycleSame       = sameCycle ;
+       fRawReader       = rawReader ;
        fDetectors       = detectors ; 
+       fDetectorsW      = detectors ;  
+       
+       AliCDBManager* man = AliCDBManager::Instance() ; 
+       if ( ! man->GetLock() ) { 
+               man->SetDefaultStorage(AliQA::GetQARefStorage()) ; 
+               man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
+       }
+       
+       if ( man->GetRun() == -1 ) {// check if run number not set previously and set it from raw data
+               rawReader->NextEvent() ; 
+               man->SetRun(fRawReader->GetRunNumber()) ;
+               rawReader->RewindEvents() ;
+       }       
+       
+       if ( !Init(AliQA::kRAWS, "rec") ) 
+               return kFALSE ; 
+       fRawReaderDelete = kFALSE ; 
 
-       // Initialize all QA data makers for all detectors
-       for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
-               if (IsSelected(AliQA::GetDetName(iDet))) {
-                       AliQADataMaker * qadm = GetQADataMaker(iDet, "rec") ;
-                       if (!qadm) {
-                               AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ; 
-                       } else {
-                               AliInfo(Form("Data Maker found for %s", qadm->GetName())) ; 
-                               qadm->Init(AliQA::kRAWS, fRunNumber, GetQACycles(iDet)) ;
-                               qadm->StartOfCycle(AliQA::kRAWS, fCycleSame) ;
-                       }
-               }
-       } 
-       fFirst = kFALSE ;
-               
-       return DoIt(AliQA::kRAWS, "rec") ; 
+       DoIt(AliQA::kRAWS, "rec") ; 
+       return  fDetectorsW ;
 }
 
 //_____________________________________________________________________________
-TString AliQADataMakerSteer::Run(const char * detectors, const char * fileName) 
+TString AliQADataMakerSteer::Run(const char * detectors, const char * fileName, const Bool_t sameCycle
 {
        //Runs all the QA data Maker for Raws only
-       //fCycleSame       = kTRUE ; 
+
+       fCycleSame       = sameCycle ;
        fDetectors       = detectors ; 
-       fDetectorsW      = detectors ; 
+       fDetectorsW      = detectors ;  
        
+       AliCDBManager* man = AliCDBManager::Instance() ; 
+       if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun
+               AliRunLoader * rl = AliRunLoader::Open("galice.root") ;
+               if ( ! rl ) {
+                       AliFatal("galice.root file not found in current directory") ; 
+               } else {
+                       rl->CdGAFile() ; 
+                       rl->LoadgAlice() ;
+                       if ( ! rl->GetAliRun() ) {
+                               AliFatal("AliRun not found in galice.root") ;
+                       } else {
+                               rl->LoadHeader() ;
+                               man->SetRun(rl->GetHeader()->GetRun());
+                       }
+               }
+       }
        
        if ( !Init(AliQA::kRAWS, "rec", fileName) ) 
                return kFALSE ; 
-
-       // Initialize all QA data makers for all detectors
-       //for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
-//             if (IsSelected(AliQA::GetDetName(iDet))) {
-//                     AliQADataMaker * qadm = GetQADataMaker(iDet, "rec") ;
-//                     if (!qadm) {
-//                             AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ; 
-//                     } else {
-//                             AliInfo(Form("Data Maker found for %s", qadm->GetName())) ; 
-//                             qadm->Init(AliQA::kRAWS, fRunNumber, GetQACycles(iDet)) ;
-//                             qadm->StartOfCycle(AliQA::kRAWS, fCycleSame) ;
-//                     }
-//             }
-//     } 
-       fFirst = kFALSE ;
+       
        DoIt(AliQA::kRAWS, "rec") ; 
        return  fDetectorsW ;
 }
 
 //_____________________________________________________________________________
-Bool_t AliQADataMakerSteer::Run(const char * detectors, const AliQA::TASKINDEX taskIndex, const  char * fileName )
+TString AliQADataMakerSteer::Run(const char * detectors, const AliQA::TASKINDEX_t taskIndex, Bool_t const sameCycle, const  char * fileName ) 
 {
        // Runs all the QA data Maker for every detector
-
-       Bool_t rv  = kFALSE ;
-       fDetectors = detectors ; 
-
-       char * mode ; 
+       
+       fCycleSame       = sameCycle ;
+       fDetectors       = detectors ; 
+       fDetectorsW      = detectors ;          
+       
+       TString mode ; 
        if ( (taskIndex == AliQA::kHITS) || (taskIndex == AliQA::kSDIGITS) || (taskIndex == AliQA::kDIGITS) ) 
                mode = "sim" ; 
        else if ( (taskIndex == AliQA::kRAWS) || (taskIndex == AliQA::kRECPOINTS) || (taskIndex == AliQA::kESDS) )
                mode = "rec" ; 
        else {
                AliError(Form("%s not implemented", AliQA::GetTaskName(taskIndex).Data())) ; 
-               return rv ;
+               return "" ;
        }
 
-       if ( !Init(taskIndex, mode, fileName) ) 
+       AliCDBManager* man = AliCDBManager::Instance() ;        
+       if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun
+               AliRunLoader * rl = AliRunLoader::Open("galice.root") ;
+               if ( ! rl ) {
+                       AliFatal("galice.root file not found in current directory") ; 
+               } else {
+                       rl->CdGAFile() ; 
+                       rl->LoadgAlice() ;
+                       if ( ! rl->GetAliRun() ) {
+                               AliFatal("AliRun not found in galice.root") ;
+                       } else {
+                               rl->LoadHeader() ;
+                               man->SetRun(rl->GetHeader()->GetRun()) ;
+                       }
+               }
+       }
+       
+       if ( !Init(taskIndex, mode.Data(), fileName) ) 
                return kFALSE ; 
 
-       rv = DoIt(taskIndex, mode) ;
+       DoIt(taskIndex, mode.Data()) ;
        
-       return rv ;   
+       return fDetectorsW ;
 
 }
 
 //_____________________________________________________________________________
-Bool_t AliQADataMakerSteer::Save2OCDB(const Int_t runNumber, const Int_t cycleNumber, const char * detectors) const
+Bool_t AliQADataMakerSteer::Save2OCDB(const Int_t runNumber, const char * year, const Int_t cycleNumber, const char * detectors) const
 {
        // take the locasl QA data merge into a single file and save in OCDB 
        Bool_t rv = kTRUE ; 
@@ -713,17 +744,15 @@ Bool_t AliQADataMakerSteer::Save2OCDB(const Int_t runNumber, const Int_t cycleNu
                rv = Merge(runNumber) ; 
                if ( ! rv )
                        return kFALSE ; 
-               char inputFileName[20] ; 
-               sprintf(inputFileName, "Merged.%s.%d.root", AliQA::GetQADataFileName(), runNumber) ; 
-               inputFile = TFile::Open(inputFileName) ; 
-               rv = SaveIt2OCDB(runNumber, inputFile) ; 
+               TString inputFileName(Form("Merged.%s.%d.root", AliQA::GetQADataFileName(), runNumber)) ; 
+               inputFile = TFile::Open(inputFileName.Data()) ; 
+               rv = SaveIt2OCDB(runNumber, inputFile, year) ; 
        } else {
                for (Int_t index = 0; index < AliQA::kNDET; index++) {
                        if (sdet.Contains(AliQA::GetDetName(index))) {
-                               char inputFileName[20] ; 
-                               sprintf(inputFileName, "%s.%s.%d.%d.root", AliQA::GetDetName(index), AliQA::GetQADataFileName(), runNumber, cycleNumber) ; 
-                               inputFile = TFile::Open(inputFileName) ;                        
-                               rv *= SaveIt2OCDB(runNumber, inputFile) ; 
+                               TString inputFileName(Form("%s.%s.%d.%d.root", AliQA::GetDetName(index), AliQA::GetQADataFileName(), runNumber, cycleNumber)) ; 
+                               inputFile = TFile::Open(inputFileName.Data()) ;                         
+                               rv *= SaveIt2OCDB(runNumber, inputFile, year) ; 
                        }
                }
        }
@@ -731,29 +760,39 @@ Bool_t AliQADataMakerSteer::Save2OCDB(const Int_t runNumber, const Int_t cycleNu
 }
 
 //_____________________________________________________________________________
-Bool_t AliQADataMakerSteer::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile) const
+Bool_t AliQADataMakerSteer::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile, const char * year) const
 {
        // reads the TH1 from file and adds it to appropriate list before saving to OCDB
        Bool_t rv = kTRUE ;
        AliInfo(Form("Saving TH1s in %s to %s", inputFile->GetName(), AliQA::GetQARefStorage())) ; 
        AliCDBManager* man = AliCDBManager::Instance() ; 
        if ( ! man->IsDefaultStorageSet() ) {
-               man->SetDefaultStorage(AliQA::GetQARefDefaultStorage()) ; 
-               man->SetSpecificStorage(Form("%s/*", AliQA::GetQAOCDBDirName()), AliQA::GetQARefStorage()) ; 
+               TString tmp( AliQA::GetQARefStorage() ) ; 
+               if ( tmp.Contains(AliQA::GetLabLocalOCDB()) ) 
+                       man->SetDefaultStorage(AliQA::GetQARefStorage()) ;
+               else {
+                       TString tmp(AliQA::GetQARefDefaultStorage()) ; 
+                       tmp.Append(year) ; 
+                       tmp.Append("?user=alidaq") ; 
+                       man->SetDefaultStorage(tmp.Data()) ; 
+               }
        }
+       man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ; 
        if(man->GetRun() < 0) 
                man->SetRun(runNumber);
 
+       AliCDBMetaData mdr ;
+       mdr.SetResponsible("yves schutz");
+
        for ( Int_t detIndex = 0 ; detIndex < AliQA::kNDET ; detIndex++) {
                TDirectory * detDir = inputFile->GetDirectory(AliQA::GetDetName(detIndex)) ; 
                if ( detDir ) {
                        AliInfo(Form("Entering %s", detDir->GetName())) ;
-                       char detOCDBDir[20] ;
-                       sprintf(detOCDBDir, "%s/%s/%s", AliQA::GetQAOCDBDirName(), AliQA::GetDetName(detIndex), AliQA::GetRefOCDBDirName()) ; 
-                       AliCDBId idr(detOCDBDir, runNumber, 999999999)  ;
+                       TString detOCDBDir(Form("%s/%s/%s", AliQA::GetDetName(detIndex), AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName())) ; 
+                       AliCDBId idr(detOCDBDir.Data(), runNumber, AliCDBRunRange::Infinity())  ;
                        TList * listDetQAD = new TList() ;
-                       char listName[20] ; 
-                       sprintf(listName, "%s QA data Reference", AliQA::GetDetName(detIndex)) ; 
+                       TString listName(Form("%s QA data Reference", AliQA::GetDetName(detIndex))) ; 
+                       mdr.SetComment("HMPID QA stuff");
                        listDetQAD->SetName(listName) ; 
                        TList * taskList = detDir->GetListOfKeys() ; 
                        TIter nextTask(taskList) ; 
@@ -769,14 +808,18 @@ Bool_t AliQADataMakerSteer::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile
                                TKey * histKey ; 
                                while ( (histKey = dynamic_cast<TKey*>(nextHist())) ) {
                                        TObject * odata = taskDir->Get(histKey->GetName()) ; 
-                                       if ( odata->IsA()->InheritsFrom("TH1") ) {
+                                       if ( !odata ) {
+                                               AliError(Form("%s in %s/%s returns a NULL pointer !!", histKey->GetName(), detDir->GetName(), taskDir->GetName())) ;
+                                       } else {
                                                AliInfo(Form("Adding %s", histKey->GetName())) ;
-                                               TH1 * hdata = static_cast<TH1*>(odata) ; 
-                                               listTaskQAD->Add(hdata) ; 
+                                               if ( odata->IsA()->InheritsFrom("TH1") ) {
+                                                       AliInfo(Form("Adding %s", histKey->GetName())) ;
+                                                       TH1 * hdata = static_cast<TH1*>(odata) ; 
+                                                       listTaskQAD->Add(hdata) ; 
+                                               }
                                        }
                                }
                        }
-                       AliCDBMetaData mdr ;
                        man->Put(listDetQAD, idr, &mdr) ;
                }
        }