Added methods for finding a given module in the DDL map (F. Prino)
[u/mrichter/AliRoot.git] / STEER / AliQADataMakerSteer.cxx
index 6c0df97..2d7519e 100644 (file)
  **************************************************************************/
 
 /* $Id$ */
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+// class for running the QA makers                                           //
+//                                                                           //
+//   AliQADataMakerSteer qas;                                                //
+//   qas.Run(AliQA::kRAWS, rawROOTFileName);                                 //
+//   qas.Run(AliQA::kHITS);                                                  //
+//   qas.Run(AliQA::kSDIGITS);                                               //
+//   qas.Run(AliQA::kDIGITS);                                                //
+//   qas.Run(AliQA::kRECPOINTS);                                             //
+//   qas.Run(AliQA::kESDS);                                                  //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
 
 #include <TKey.h>
 #include <TFile.h>
@@ -32,7 +45,8 @@
 #include "AliLog.h"
 #include "AliModule.h"
 #include "AliQA.h"
-#include "AliQADataMaker.h"
+#include "AliQADataMakerRec.h"
+#include "AliQADataMakerSim.h"
 #include "AliQADataMakerSteer.h" 
 #include "AliRawReaderDate.h"
 #include "AliRawReaderFile.h"
@@ -45,19 +59,23 @@ ClassImp(AliQADataMakerSteer)
 //_____________________________________________________________________________
 AliQADataMakerSteer::AliQADataMakerSteer(const char* gAliceFilename, const char * name, const char * title) :
        TNamed(name, title), 
+       fCurrentEvent(0),  
        fCycleSame(kFALSE),
-    fDetectors("ALL"), 
+       fDetectors("ALL"), 
+       fDetectorsW("ALL"), 
        fESD(NULL), 
        fESDTree(NULL),
        fFirst(kTRUE),  
        fGAliceFileName(gAliceFilename), 
-       fRunNumber(0), 
+    fMaxEvents(0),        
        fNumberOfEvents(999999), 
+    fRunNumber(0), 
        fRawReader(NULL), 
        fRawReaderDelete(kTRUE), 
        fRunLoader(NULL)  
 {
        // default ctor
+       fMaxEvents = fNumberOfEvents ; 
        for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
                if (IsSelected(AliQA::GetDetName(iDet))) {
                        fLoader[iDet]      = NULL ;
@@ -70,14 +88,17 @@ AliQADataMakerSteer::AliQADataMakerSteer(const char* gAliceFilename, const char
 //_____________________________________________________________________________
 AliQADataMakerSteer::AliQADataMakerSteer(const AliQADataMakerSteer & qas) : 
        TNamed(qas), 
+       fCurrentEvent(qas.fCurrentEvent),  
        fCycleSame(kFALSE),
-    fDetectors(qas.fDetectors), 
+       fDetectors(qas.fDetectors), 
+       fDetectorsW(qas.fDetectorsW), 
        fESD(NULL), 
        fESDTree(NULL), 
        fFirst(qas.fFirst),  
        fGAliceFileName(qas.fGAliceFileName), 
-       fRunNumber(qas.fRunNumber), 
+    fMaxEvents(qas.fMaxEvents),        
        fNumberOfEvents(qas.fNumberOfEvents), 
+    fRunNumber(qas.fRunNumber), 
        fRawReader(NULL), 
        fRawReaderDelete(kTRUE), 
        fRunLoader(NULL)  
@@ -122,15 +143,17 @@ AliQADataMakerSteer::~AliQADataMakerSteer()
 }
 
 //_____________________________________________________________________________
-Bool_t AliQADataMakerSteer::DoIt(const AliQA::TASKINDEX taskIndex)
+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 = 0 ; iEvent < (UInt_t)fMaxEvents ; iEvent++) {
+               fCurrentEvent++ ; 
                // Get the event
-               AliDebug(1, Form("processing event %d", iEvent));
+               if ( iEvent%10 == 0  ) 
+                       AliInfo(Form("processing event %d", iEvent));
                if ( taskIndex == AliQA::kRAWS ) {
                        if ( !fRawReader->NextEvent() )
                                break ;
@@ -154,7 +177,7 @@ Bool_t AliQADataMakerSteer::DoIt(const AliQA::TASKINDEX taskIndex)
                        }
                        if (!IsSelected(AliQA::GetDetName(iDet)))
                                continue ;
-                       AliQADataMaker * qadm = GetQADataMaker(iDet) ;
+                       AliQADataMaker * qadm = GetQADataMaker(iDet, mode) ;
                        if (!qadm) {
                                rv = kFALSE ;
                        } else {
@@ -213,22 +236,23 @@ Bool_t AliQADataMakerSteer::DoIt(const AliQA::TASKINDEX taskIndex)
                                                case AliQA::kNTASKINDEX :
                                                break; 
                                } //task switch
-                               qadm->Increment() ; 
+                               //qadm->Increment() ; 
                        } //data maker exist
                } // detector loop
        } // event loop 
-       // Save QA data for all detectors
-       rv = Finish(taskIndex) ;
+//     // Save QA data for all detectors
+       rv = Finish(taskIndex, mode) ;
+
        return rv ; 
 }
 
 //_____________________________________________________________________________
-Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX taskIndex) 
+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) ;
+                       AliQADataMaker * qadm = GetQADataMaker(iDet, mode) ;
                        if (qadm) {
                                qadm->EndOfCycle(taskIndex) ; 
                        }
@@ -238,20 +262,30 @@ Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX taskIndex)
 }
 
 //_____________________________________________________________________________
-TList * 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 
-       TList * rv = NULL ;
+       TObjArray * rv = NULL ;
+       TString tmp(AliQA::GetQARefStorage()) ; 
+       if ( tmp.IsNull() ) { 
+               AliError("No storage defined, use AliQA::SetQARefStorage") ; 
+               return NULL ; 
+       }       
        AliCDBManager* man = AliCDBManager::Instance() ; 
-       man->SetDefaultStorage("local://TestCDB")  ; 
-       char detOCDBDir[20] ; 
-       sprintf(detOCDBDir, "QA/Ref/%s", AliQA::GetDetName((Int_t)det)) ; 
-       AliInfo(Form("Retrieving reference data from local://TestCDB/%s %s", detOCDBDir, AliQA::GetTaskName(task).Data())) ; 
-       AliCDBEntry* entry = man->Get(detOCDBDir,0) ;
+       if ( ! man->IsDefaultStorageSet() ) {
+               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::GetQAName(), 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
        TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
        if ( listDetQAD ) 
-               rv = dynamic_cast<TList *>(listDetQAD->FindObject(AliQA::GetTaskName(task))) ; 
-
+               rv = dynamic_cast<TObjArray *>(listDetQAD->FindObject(AliQA::GetTaskName(task))) ; 
        return rv ; 
 }
 
@@ -292,7 +326,7 @@ AliLoader * AliQADataMakerSteer::GetLoader(Int_t iDet)
 }
 
 //_____________________________________________________________________________
-AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(Int_t iDet)
+AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(const Int_t iDet, const char * mode )
 {
        // get the quality assurance data maker for a detector
        
@@ -305,7 +339,12 @@ AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(Int_t iDet)
                // load the QA data maker object
                TPluginManager* pluginManager = gROOT->GetPluginManager() ;
                TString detName = AliQA::GetDetName(iDet) ;
-               TString qadmName = "Ali" + detName + "QADataMaker" ;
+               TString tmp(mode) ; 
+               if (tmp.Contains("sim")) 
+                       tmp.ReplaceAll("s", "S") ; 
+               else if (tmp.Contains("rec")) 
+                       tmp.ReplaceAll("r", "R") ; 
+               TString qadmName = "Ali" + detName + "QADataMaker" + tmp ;
 
                // first check if a plugin is defined for the quality assurance data maker
                TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
@@ -313,7 +352,7 @@ AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(Int_t iDet)
                if (!pluginHandler) {
                        AliDebug(1, Form("defining plugin for %s", qadmName.Data())) ;
                        TString libs = gSystem->GetLibraries() ;
-                       if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
+                       if (libs.Contains("lib" + detName + mode + ".so") || (gSystem->Load("lib" + detName + mode + ".so") >= 0)) {
                                pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ;
                        } else {
                                pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ;
@@ -330,7 +369,7 @@ AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(Int_t iDet)
 }
 
 //_____________________________________________________________________________
-Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, 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
        
@@ -348,19 +387,30 @@ Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, const  char *
                }
            if ( ! fRawReader ) 
                        return kFALSE ; 
+               fRawReaderDelete = kTRUE ; 
                fRawReader->NextEvent() ; 
                fRunNumber = fRawReader->GetRunNumber() ; 
+               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")) ; 
-                       fESD     = new AliESDEvent() ;
-                       fESD->ReadFromTree(fESDTree) ;
-                       fESDTree->GetEntry(0) ; 
-                       fRunNumber = fESD->GetRunNumber() ; 
-                       fNumberOfEvents = fESDTree->GetEntries() ;
+                       if ( !fESDTree ) {
+                               AliError("esdTree not found") ; 
+                               return kFALSE ; 
+                       } else {
+                               fESD     = new AliESDEvent() ;
+                               fESD->ReadFromTree(fESDTree) ;
+                               fESDTree->GetEntry(0) ; 
+                               fRunNumber = fESD->GetRunNumber() ; 
+                               fNumberOfEvents = fESDTree->GetEntries() ;
+                               if ( fMaxEvents < 0 ) 
+                                       fMaxEvents = fNumberOfEvents ; 
+                       }
                } else {
                        AliError("AliESDs.root not found") ; 
                        return kFALSE ; 
@@ -370,16 +420,21 @@ Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, const  char *
                        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++) {
+
                if (IsSelected(AliQA::GetDetName(iDet))) {
-                       AliQADataMaker * qadm = GetQADataMaker(iDet) ;
+                       AliQADataMaker * qadm = GetQADataMaker(iDet, mode) ;
                        if (!qadm) {
-                               AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ; 
+                               AliError(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ; 
+                               fDetectorsW.ReplaceAll(AliQA::GetDetName(iDet), "") ; 
                        } else {
-                               AliInfo(Form("Data Maker found for %s", qadm->GetName())) ; 
+                               AliDebug(1, Form("Data Maker found for %s", qadm->GetName())) ; 
                                qadm->Init(taskIndex, fRunNumber, GetQACycles(iDet)) ;
                                qadm->StartOfCycle(taskIndex, fCycleSame) ;
                        }
@@ -390,43 +445,6 @@ Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, const  char *
 }
 
 //_____________________________________________________________________________
-Bool_t AliQADataMakerSteer::IsSelected(const char * det) 
-{
-       // check whether detName is contained in detectors
-       // if yes, it is removed from detectors
-       
-       const TString detName(det) ;
-       // check if all detectors are selected
-       if ((fDetectors.CompareTo("ALL") == 0) ||
-               fDetectors.BeginsWith("ALL ") ||
-               fDetectors.EndsWith(" ALL") ||
-               fDetectors.Contains(" ALL ")) {
-               fDetectors = "ALL";
-               return kTRUE;
-       }
-       
-       // search for the given detector
-       Bool_t rv = kFALSE;
-       if ((fDetectors.CompareTo(detName) == 0) ||
-               fDetectors.BeginsWith(detName+" ") ||
-               fDetectors.EndsWith(" "+detName) ||
-               fDetectors.Contains(" "+detName+" ")) {
-//             fDetectors.ReplaceAll(detName, "");
-               rv = kTRUE;
-       }
-       
-       // clean up the detectors string
-//     while (fDetectors.Contains("  ")) 
-//             fDetectors.ReplaceAll("  ", " ");
-//     while (fDetectors.BeginsWith(" ")) 
-//             fDetectors.Remove(0, 1);
-//     while (fDetectors.EndsWith(" ")) 
-//             fDetectors.Remove(fDetectors.Length()-1, 1);
-       
-       return rv ;
-}
-
-//_____________________________________________________________________________
 Bool_t AliQADataMakerSteer::InitRunLoader()
 {
        // get or create the run loader
@@ -472,6 +490,43 @@ Bool_t AliQADataMakerSteer::InitRunLoader()
 }
 
 //_____________________________________________________________________________
+Bool_t AliQADataMakerSteer::IsSelected(const char * det) 
+{
+       // check whether detName is contained in detectors
+       // if yes, it is removed from detectors
+       
+       const TString detName(det) ;
+       // check if all detectors are selected
+       if ((fDetectors.CompareTo("ALL") == 0) ||
+               fDetectors.BeginsWith("ALL ") ||
+               fDetectors.EndsWith(" ALL") ||
+               fDetectors.Contains(" ALL ")) {
+               fDetectors = "ALL";
+               return kTRUE;
+       }
+       
+       // search for the given detector
+       Bool_t rv = kFALSE;
+       if ((fDetectors.CompareTo(detName) == 0) ||
+               fDetectors.BeginsWith(detName+" ") ||
+               fDetectors.EndsWith(" "+detName) ||
+               fDetectors.Contains(" "+detName+" ")) {
+               //              fDetectors.ReplaceAll(detName, "");
+               rv = kTRUE;
+       }
+       
+       // clean up the detectors string
+       //      while (fDetectors.Contains("  ")) 
+       //              fDetectors.ReplaceAll("  ", " ");
+       //      while (fDetectors.BeginsWith(" ")) 
+       //              fDetectors.Remove(0, 1);
+       //      while (fDetectors.EndsWith(" ")) 
+       //              fDetectors.Remove(fDetectors.Length()-1, 1);
+       
+       return rv ;
+}
+
+//_____________________________________________________________________________
 Bool_t AliQADataMakerSteer::Merge(const Int_t runNumber) const
 {
        // Merge all the cycles from all detectors in one single file per run
@@ -491,6 +546,7 @@ Bool_t AliQADataMakerSteer::Merge(const Int_t runNumber) const
                in >> file[index] ; 
                if ( !in.good() ) 
                        break ; 
+               AliInfo(Form("index = %d file = %s", index, (file[index]).Data())) ; 
                index++ ;
        }
        
@@ -499,37 +555,40 @@ Bool_t AliQADataMakerSteer::Merge(const Int_t runNumber) const
                return kFALSE ; 
        }
        
-       Int_t previousRun = -1 ;
-       Int_t runIndex = 0 ;  
+       Int_t runIndex    = 0 ;  
+       Int_t runIndexMax = 0 ; 
        char stmp[10] ; 
        sprintf(stmp, ".%s.", AliQA::GetQADataFileName()) ; 
-       for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) {
+       for (Int_t ifile = 0 ; ifile < index ; ifile++) {
                TString tmp(file[ifile]) ; 
                tmp.ReplaceAll(".root", "") ; 
                TString det = tmp(0, tmp.Index(".")) ; 
                tmp.Remove(0, tmp.Index(stmp)+4) ; 
                TString ttmp = tmp(0, tmp.Index(".")) ; 
                Int_t newRun = ttmp.Atoi() ;
-               if (newRun != previousRun) {
+               for (Int_t irun = 0; irun <= runIndexMax; irun++) {
+                       if (newRun == run[irun]) 
+                               break ; 
                        run[runIndex] = newRun ; 
-                       previousRun = newRun ; 
                        runIndex++ ; 
                }
-               ttmp = tmp(tmp.Index("."), tmp.Length()) ; 
+               runIndexMax = runIndex ; 
+               ttmp = tmp(tmp.Index(".")+1, tmp.Length()) ; 
                Int_t cycle = ttmp.Atoi() ;  
-               AliInfo(Form("%s : det = %s run = %d cycle = %d \n", file[ifile].Data(), det.Data(), newRun, cycle)) ; 
+               AliDebug(1, Form("%s : det = %s run = %d cycle = %d \n", file[ifile].Data(), det.Data(), newRun, cycle)) ; 
        }
-       for (Int_t irun = 0 ; irun < runIndex ; irun++) {
+       for (Int_t irun = 0 ; irun < runIndexMax ; irun++) {
                TFileMerger merger ; 
                char outFileName[20] ; 
-               sprintf(outFileName, "Merged.%s.%d.root", AliQA::GetQADataFileName(), runIndex-1) ; 
+               sprintf(outFileName, "Merged.%s.%d.root", AliQA::GetQADataFileName(), run[irun]) ; 
                merger.OutputFile(outFileName) ; 
                for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) {
                        char pattern[100] ; 
-                       sprintf(pattern, "%s.%d.", AliQA::GetQADataFileName(), runIndex-1) ; 
+                       sprintf(pattern, "%s.%d.", AliQA::GetQADataFileName(), run[irun]) ; 
                        TString tmp(file[ifile]) ; 
-                       if (tmp.Contains(pattern))
+                       if (tmp.Contains(pattern)) {
                                merger.AddFile(tmp) ; 
+                       }
                }
                merger.Merge() ; 
        }
@@ -538,14 +597,14 @@ Bool_t AliQADataMakerSteer::Merge(const Int_t runNumber) const
 }
 
 //_____________________________________________________________________________
-void AliQADataMakerSteer::Reset()
+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() ; 
+                               (fQADataMaker[iDet])->Reset(sameCycle) ; 
                                //delete fQADataMaker[iDet] ;
                                //fQADataMaker[iDet] = NULL ;
                        }
@@ -557,7 +616,7 @@ void AliQADataMakerSteer::Reset()
                fRawReader      = NULL ;
        }
 
-       fCycleSame      = kFALSE ; 
+       fCycleSame      = sameCycle ; 
        fESD            = NULL ; 
        fESDTree        = NULL ; 
        fFirst          = kTRUE ;   
@@ -565,51 +624,69 @@ void AliQADataMakerSteer::Reset()
 }
 
 //_____________________________________________________________________________
-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 ;          
+       
+       fCycleSame       = sameCycle ;
+       fRawReader       = rawReader ;
+       fDetectors       = detectors ; 
+       fDetectorsW      = detectors ;  
+       
+       if ( !Init(AliQA::kRAWS, "rec") ) 
+               return kFALSE ; 
        fRawReaderDelete = kFALSE ; 
-       fCycleSame       = kTRUE ; 
+
+       DoIt(AliQA::kRAWS, "rec") ; 
+       return  fDetectorsW ;
+}
+
+//_____________________________________________________________________________
+TString AliQADataMakerSteer::Run(const char * detectors, const char * fileName, const Bool_t sameCycle) 
+{
+       //Runs all the QA data Maker for Raws only
+
+       fCycleSame       = sameCycle ;
        fDetectors       = detectors ; 
+       fDetectorsW      = detectors ;  
+       
+       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) ;
-                       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) ; 
+       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 ; 
        
-       if ( !Init(taskIndex, fileName) ) 
+       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 "" ;
+       }
+
+       if ( !Init(taskIndex, mode.Data(), fileName) ) 
                return kFALSE ; 
 
-       rv = DoIt(taskIndex) ;
+       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 ; 
@@ -632,14 +709,14 @@ Bool_t AliQADataMakerSteer::Save2OCDB(const Int_t runNumber, const Int_t cycleNu
                char inputFileName[20] ; 
                sprintf(inputFileName, "Merged.%s.%d.root", AliQA::GetQADataFileName(), runNumber) ; 
                inputFile = TFile::Open(inputFileName) ; 
-               rv = SaveIt2OCDB(inputFile) ; 
+               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(inputFile) ; 
+                               rv *= SaveIt2OCDB(runNumber, inputFile, year) ; 
                        }
                }
        }
@@ -647,24 +724,36 @@ Bool_t AliQADataMakerSteer::Save2OCDB(const Int_t runNumber, const Int_t cycleNu
 }
 
 //_____________________________________________________________________________
-Bool_t AliQADataMakerSteer::SaveIt2OCDB(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() ; 
-       man->SetDefaultStorage(AliQA::GetQARefStorage()) ; 
+       if ( ! man->IsDefaultStorageSet() ) {
+               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, "QA/Ref/%s", AliQA::GetDetName(detIndex)) ; 
-                       AliCDBId idr(detOCDBDir,0,999999999)  ;
+                       char detOCDBDir[20] ;
+                       sprintf(detOCDBDir, "%s/%s/%s", AliQA::GetDetName(detIndex), AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName()) ; 
+                       AliCDBId idr(detOCDBDir, runNumber, AliCDBRunRange::Infinity())  ;
                        TList * listDetQAD = new TList() ;
                        char listName[20] ; 
                        sprintf(listName, "%s QA data Reference", AliQA::GetDetName(detIndex)) ; 
+                       mdr.SetComment("HMPID QA stuff");
                        listDetQAD->SetName(listName) ; 
                        TList * taskList = detDir->GetListOfKeys() ; 
                        TIter nextTask(taskList) ; 
@@ -672,7 +761,7 @@ Bool_t AliQADataMakerSteer::SaveIt2OCDB(TFile * inputFile) const
                        while ( (taskKey = dynamic_cast<TKey*>(nextTask())) ) {
                                TDirectory * taskDir = detDir->GetDirectory(taskKey->GetName()) ; 
                                AliInfo(Form("Saving %s", taskDir->GetName())) ; 
-                               TList * listTaskQAD = new TList() ; 
+                               TObjArray * listTaskQAD = new TObjArray(100) ; 
                                listTaskQAD->SetName(taskKey->GetName()) ;
                                listDetQAD->Add(listTaskQAD) ; 
                                TList * histList = taskDir->GetListOfKeys() ; 
@@ -687,9 +776,9 @@ Bool_t AliQADataMakerSteer::SaveIt2OCDB(TFile * inputFile) const
                                        }
                                }
                        }
-                       AliCDBMetaData mdr ;
                        man->Put(listDetQAD, idr, &mdr) ;
                }
        }
        return rv ; 
 }      
+