]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliQAManager.cxx
Fix for Savannah bug report 59287
[u/mrichter/AliRoot.git] / STEER / AliQAManager.cxx
index 323674e5df25151a23ccdad1cef8b7857a122d7e..2ead4fe364d2154f788781ed6b2f0a847090449b 100644 (file)
@@ -39,6 +39,7 @@
 #include <TROOT.h>
 #include <TString.h>
 #include <TSystem.h>
+#include <TStopwatch.h>
 
 #include "AliCDBManager.h"
 #include "AliCDBEntry.h"
@@ -54,6 +55,8 @@
 #include "AliLog.h"
 #include "AliModule.h"
 #include "AliQAv1.h"
+#include "AliQAChecker.h"
+#include "AliQACheckerBase.h"
 #include "AliQADataMakerRec.h"
 #include "AliQADataMakerSim.h"
 #include "AliQAManager.h" 
@@ -88,7 +91,8 @@ AliQAManager::AliQAManager() :
   fRunLoader(NULL), 
   fTasks(""),  
   fEventSpecie(AliRecoParam::kDefault), 
-  fPrintImage(kTRUE) 
+  fPrintImage(kTRUE), 
+  fSaveData(kTRUE) 
 {
        // default ctor
        fMaxEvents = fNumberOfEvents ; 
@@ -103,7 +107,7 @@ AliQAManager::AliQAManager() :
 }
 
 //_____________________________________________________________________________
-AliQAManager::AliQAManager(const Char_t * mode, const Char_t* gAliceFilename) :
+AliQAManager::AliQAManager(AliQAv1::MODE_t mode, const Char_t* gAliceFilename) :
   AliCDBManager(), 
   fCurrentEvent(0),  
        fCycleSame(kFALSE),
@@ -114,7 +118,7 @@ AliQAManager::AliQAManager(const Char_t * mode, const Char_t* gAliceFilename) :
        fGAliceFileName(gAliceFilename), 
        fFirstEvent(0),        
        fMaxEvents(0),   
-  fMode(mode), 
+  fMode(AliQAv1::GetModeName(mode)), 
        fNumberOfEvents(999999), 
   fRecoParam(),
        fRunNumber(0), 
@@ -123,7 +127,8 @@ AliQAManager::AliQAManager(const Char_t * mode, const Char_t* gAliceFilename) :
        fRunLoader(NULL), 
   fTasks(""), 
   fEventSpecie(AliRecoParam::kDefault), 
-  fPrintImage(kTRUE) 
+  fPrintImage(kTRUE), 
+  fSaveData(kTRUE) 
 {
        // default ctor
        fMaxEvents = fNumberOfEvents ; 
@@ -135,11 +140,6 @@ AliQAManager::AliQAManager(const Char_t * mode, const Char_t* gAliceFilename) :
     }
   }
   SetWriteExpert() ; 
-  fMode.ToLower() ; 
-  if (fMode.Contains("sim")) 
-               fMode.ReplaceAll("s", "S") ; 
-  else if (fMode.Contains("rec")) 
-    fMode.ReplaceAll("r", "R") ; 
 }
 
 //_____________________________________________________________________________
@@ -163,7 +163,8 @@ AliQAManager::AliQAManager(const AliQAManager & qas) :
        fRunLoader(NULL), 
   fTasks(qas.fTasks), 
   fEventSpecie(qas.fEventSpecie), 
-  fPrintImage(qas.fPrintImage) 
+  fPrintImage(qas.fPrintImage), 
+  fSaveData(qas.fSaveData) 
 
 {
        // cpy ctor
@@ -202,9 +203,9 @@ AliQAManager::~AliQAManager()
                delete fRawReader ;
                fRawReader = NULL ;
        }
-  TCanvas fakeCanvas ; 
-  if (fPrintImage) 
-    fakeCanvas.Print(Form("%s%s%d.%s]", AliQAv1::GetImageFileName(), GetMode(), fRunNumber, AliQAv1::GetImageFileFormat())); 
+//  TCanvas fakeCanvas ; 
+//  if (fPrintImage) 
+//    fakeCanvas.Print(Form("%s%s%d.%s]", AliQAv1::GetImageFileName(), GetMode(), fRunNumber, AliQAv1::GetImageFileFormat()), "ps"); 
 }
 
 //_____________________________________________________________________________
@@ -257,15 +258,21 @@ Bool_t AliQAManager::DoIt(const AliQAv1::TASKINDEX_t taskIndex)
             } 
                                                break ;
                                                case AliQAv1::kSDIGITS :
-            if( loader ) {      
-              loader->LoadSDigits() ; 
-              data = loader->TreeS() ; 
-              if ( ! data ) {
-                AliWarning(Form(" SDigit Tree not found for  %s", AliQAv1::GetDetName(iDet))) ; 
-                break ; 
-              } 
-              qadm->Exec(taskIndex, data) ; 
+          {
+            
+            TString fileName(Form("%s.SDigits.root", AliQAv1::GetDetName(iDet))) ; 
+            if (gSystem->FindFile("./", fileName)) {
+              if( loader ) {      
+                loader->LoadSDigits() ; 
+                data = loader->TreeS() ; 
+                if ( ! data ) {
+                  AliWarning(Form(" SDigit Tree not found for  %s", AliQAv1::GetDetName(iDet))) ; 
+                  break ; 
+                } 
+                qadm->Exec(taskIndex, data) ; 
+              }
             }
+          }
                                                break; 
                                                case AliQAv1::kDIGITS :
               if( loader ) {      
@@ -312,9 +319,10 @@ Bool_t AliQAManager::DoIt(const AliQAv1::TASKINDEX_t taskIndex)
                                } //task switch
                        }
                } // detector loop
-    Increment() ; 
+    Increment(taskIndex) ; 
        } // event loop 
        // Save QA data for all detectors
+
        rv = Finish(taskIndex) ;
        
        if ( taskIndex == AliQAv1::kRAWS ) 
@@ -327,6 +335,9 @@ Bool_t AliQAManager::DoIt(const AliQAv1::TASKINDEX_t taskIndex)
 Bool_t AliQAManager::Finish(const AliQAv1::TASKINDEX_t taskIndex) 
 {
        // write output to file for all detectors
+  
+  AliQAChecker::Instance()->SetRunNumber(fRunNumber) ; 
+
        for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
                if (IsSelected(AliQAv1::GetDetName(iDet))) {
                        AliQADataMaker * qadm = GetQADataMaker(iDet) ;
@@ -368,8 +379,8 @@ TCanvas ** AliQAManager::GetImage(Char_t * detName)
   // retrieves QA Image for the given detector
   TCanvas ** rv = NULL ; 
   Int_t detIndex = AliQAv1::GetDetIndex(detName) ; 
-  AliQADataMaker * qadm = GetQADataMaker(detIndex) ; 
-  rv = qadm->GetImage() ;
+  AliQACheckerBase * qac = AliQAChecker::Instance()->GetDetQAChecker(detIndex) ; 
+  rv = qac->GetImage() ;
   return rv ; 
 }
 
@@ -471,7 +482,7 @@ AliQADataMaker * AliQAManager::GetQADataMaker(const Int_t iDet)
       if ( AliRecoParam::Convert(qadm->GetRecoParam()->GetEventSpecie()) != AliRecoParam::kDefault)  
         qadm->SetEventSpecie(qadm->GetRecoParam()->GetEventSpecie()) ; 
 
-  } else if ( iDet < AliQAv1::kHLT ) {
+  } else if ( iDet < AliQAv1::kGLOBAL ) {
     
     // load the QA data maker object
     TPluginManager* pluginManager = gROOT->GetPluginManager() ;
@@ -514,13 +525,14 @@ void  AliQAManager::EndOfCycle(TObjArray * detArray)
 {
        // End of cycle QADataMakers 
        
-  if (fPrintImage) {
-    TCanvas fakeCanvas ; 
-    fakeCanvas.Print(Form("%s%s%d.%s[", AliQAv1::GetImageFileName(), GetMode(), fRunNumber, AliQAv1::GetImageFileFormat())) ; 
-  }
+  AliQAChecker::Instance()->SetRunNumber(fRunNumber) ; 
+  TCanvas fakeCanvas ; 
+  if (fPrintImage) 
+    fakeCanvas.Print(Form("%s%s%d.%s[", AliQAv1::GetImageFileName(), GetMode(), fRunNumber, AliQAv1::GetImageFileFormat()), "ps") ; 
        for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
                if (IsSelected(AliQAv1::GetDetName(iDet))) {
                        AliQADataMaker * qadm = GetQADataMaker(iDet) ;
+                       AliQACheckerBase * qac = AliQAChecker::Instance()->GetDetQAChecker(iDet) ;
                        if (!qadm) 
                                continue ;      
                        // skip non active detectors
@@ -529,15 +541,17 @@ void  AliQAManager::EndOfCycle(TObjArray * detArray)
                                if (!det || !det->IsActive())  
                                        continue ;
                        }
-      qadm->SetPrintImage(fPrintImage) ;
-      
-                       for (UInt_t taskIndex = 0; taskIndex < AliQAv1::kNTASKINDEX; taskIndex++) {
-                               if ( fTasks.Contains(Form("%d", taskIndex)) ) 
-                                       qadm->EndOfCycle(AliQAv1::GetTaskIndex(AliQAv1::GetTaskName(taskIndex))) ;
-                       }
+      if (qac) 
+        qac->SetPrintImage(fPrintImage) ;
+      for (UInt_t taskIndex = 0; taskIndex < AliQAv1::kNTASKINDEX; taskIndex++) {
+        if ( fTasks.Contains(Form("%d", taskIndex)) ) 
+          qadm->EndOfCycle(AliQAv1::GetTaskIndex(AliQAv1::GetTaskName(taskIndex))) ;
+      }
                        qadm->Finish();
                }
        }
+  if (fPrintImage) 
+    fakeCanvas.Print(Form("%s%s%d.%s]", AliQAv1::GetImageFileName(), GetMode(), fRunNumber, AliQAv1::GetImageFileFormat()), "ps"); 
 }
 
 //_____________________________________________________________________________
@@ -545,32 +559,41 @@ void  AliQAManager::EndOfCycle(TString detectors)
 {
        // End of cycle QADataMakers 
        
-  if (fPrintImage) {
-    TCanvas fakeCanvas ; 
-    fakeCanvas.Print(Form("%s%s%d.%s[", AliQAv1::GetImageFileName(), GetMode(), fRunNumber, AliQAv1::GetImageFileFormat())) ; 
-  }
+  AliQAChecker::Instance()->SetRunNumber(fRunNumber) ; 
+  TCanvas fakeCanvas ; 
+  if (fPrintImage) 
+    fakeCanvas.Print(Form("%s%s%d.%s[", AliQAv1::GetImageFileName(), GetMode(), fRunNumber, AliQAv1::GetImageFileFormat()), "ps") ; 
   for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
                if (IsSelected(AliQAv1::GetDetName(iDet))) {
                        AliQADataMaker * qadm = GetQADataMaker(iDet) ;
+      AliQACheckerBase * qac = AliQAChecker::Instance()->GetDetQAChecker(iDet) ;
                        if (!qadm) 
                                continue ;      
                        // skip non active detectors
       if (!detectors.Contains(AliQAv1::GetDetName(iDet))) 
         continue ;
-      qadm->SetPrintImage(fPrintImage) ;
-               for (UInt_t taskIndex = 0; taskIndex < AliQAv1::kNTASKINDEX; taskIndex++) {
-                               if ( fTasks.Contains(Form("%d", taskIndex)) ) 
-                                       qadm->EndOfCycle(AliQAv1::GetTaskIndex(AliQAv1::GetTaskName(taskIndex))) ;
-                       }
+      if (qac) 
+        qac->SetPrintImage(fPrintImage) ;
+      for (UInt_t taskIndex = 0; taskIndex < AliQAv1::kNTASKINDEX; taskIndex++) {
+        if ( fTasks.Contains(Form("%d", taskIndex)) ) 
+          qadm->EndOfCycle(AliQAv1::GetTaskIndex(AliQAv1::GetTaskName(taskIndex))) ;
+      }
                        qadm->Finish();
                }
        }
+  if (fPrintImage) 
+    fakeCanvas.Print(Form("%s%s%d.%s]", AliQAv1::GetImageFileName(), GetMode(), fRunNumber, AliQAv1::GetImageFileFormat()), "ps"); 
 }
 
 //_____________________________________________________________________________
-void AliQAManager::Increment()
+void AliQAManager::Increment(const AliQAv1::TASKINDEX_t taskIndex)
 {
   // Increments the cycle counter for all QA Data Makers
+  static AliQAv1::TASKINDEX_t currentTask = AliQAv1::kNTASKINDEX ; 
+  if (currentTask == taskIndex) 
+    return ; 
+  else 
+    currentTask = taskIndex ; 
        for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
                if (IsSelected(AliQAv1::GetDetName(iDet))) {
                        AliQADataMaker * qadm = GetQADataMaker(iDet) ;
@@ -648,7 +671,13 @@ Bool_t AliQAManager::InitQA(const AliQAv1::TASKINDEX_t taskIndex, const  Char_t
        InitQADataMaker(fRunNumber, detArray) ; //, fCycleSame, kTRUE, detArray) ; 
   if (fPrintImage) {
     TCanvas fakeCanvas ; 
-    fakeCanvas.Print(Form("%s%s%d.%s[", AliQAv1::GetImageFileName(), GetMode(), fRunNumber, AliQAv1::GetImageFileFormat())) ;    
+    TStopwatch timer ; 
+    timer.Start() ; 
+    while (timer.CpuTime()<5) {
+      timer.Continue();
+      gSystem->ProcessEvents();
+    }
+    fakeCanvas.Print(Form("%s%s%d.%s[", AliQAv1::GetImageFileName(), GetMode(), fRunNumber, AliQAv1::GetImageFileFormat()), "ps") ;    
   }    
        return kTRUE ; 
 }
@@ -746,7 +775,7 @@ Bool_t AliQAManager::IsSelected(const Char_t * det)
        Bool_t rv = kFALSE;
        const TString detName(det) ;
   // always activates Correlation
-  if ( detName.Contains(AliQAv1::GetDetName(AliQAv1::kCORR))) {
+  if ( detName.Contains(AliQAv1::GetDetName(AliQAv1::kCORR)) || detName.Contains(AliQAv1::GetDetName(AliQAv1::kGLOBAL))) {
     rv = kTRUE ; 
   } else {
     // check if all detectors are selected
@@ -1078,13 +1107,13 @@ void AliQAManager::Reset(const Bool_t sameCycle)
 }
 
 //_____________________________________________________________________________
-AliQAManager * AliQAManager::QAManager(const Char_t * mode, TMap *entryCache, Int_t run) 
+AliQAManager * AliQAManager::QAManager(AliQAv1::MODE_t mode, TMap *entryCache, Int_t run) 
 {
   // returns AliQAManager instance (singleton)
   
        if (!fgQAInstance) {
-    if ( (strcmp(mode, "sim") != 0) && (strcmp(mode, "rec") != 0) ) {
-      AliErrorClass("You must specify sim or rec") ; 
+    if ( (mode != AliQAv1::kSIMMODE) && (mode != AliQAv1::kRECMODE) ) {
+      AliErrorClass("You must specify kSIMMODE or kRECMODE") ; 
       return NULL ; 
     }
     fgQAInstance = new AliQAManager(mode) ;  
@@ -1096,6 +1125,13 @@ AliQAManager * AliQAManager::QAManager(const Char_t * mode, TMap *entryCache, In
        return fgQAInstance;
 }
 
+//_____________________________________________________________________________
+AliQAManager * AliQAManager::QAManager(AliQAv1::TASKINDEX_t task) 
+{
+  // returns AliQAManager instance (singleton)
+  return QAManager(AliQAv1::Mode(task)) ; 
+}
+
 //_____________________________________________________________________________
 TString AliQAManager::Run(const Char_t * detectors, AliRawReader * rawReader, const Bool_t sameCycle) 
 {
@@ -1206,7 +1242,6 @@ void AliQAManager::RunOneEvent(AliRawReader * rawReader)
        //Runs all the QA data Maker for Raws only and on one event only (event loop done by calling method)
   if ( ! rawReader ) 
     return ; 
-       AliCodeTimerAuto("") ;
   if (fTasks.Contains(Form("%d", AliQAv1::kRAWS))){
     for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
       if (!IsSelected(AliQAv1::GetDetName(iDet))) 
@@ -1217,13 +1252,11 @@ void AliQAManager::RunOneEvent(AliRawReader * rawReader)
       if ( qadm->IsCycleDone() ) {
         qadm->EndOfCycle() ;
       }
-      AliCodeTimerStart(Form("running RAW quality assurance data maker for %s", AliQAv1::GetDetName(iDet))); 
       qadm->SetEventSpecie(fEventSpecie) ;  
       if ( qadm->GetRecoParam() ) 
         if ( AliRecoParam::Convert(qadm->GetRecoParam()->GetEventSpecie()) != AliRecoParam::kDefault)  
           qadm->SetEventSpecie(qadm->GetRecoParam()->GetEventSpecie()) ; 
                        qadm->Exec(AliQAv1::kRAWS, rawReader) ;
-      AliCodeTimerStop(Form("running RAW quality assurance data maker for %s", AliQAv1::GetDetName(iDet)));
                }
   }
 }
@@ -1233,7 +1266,6 @@ void AliQAManager::RunOneEvent(AliESDEvent *& esd)
 {
        //Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
        
-  AliCodeTimerAuto("") ;
   if (fTasks.Contains(Form("%d", AliQAv1::kESDS))) {
     for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
       if (!IsSelected(AliQAv1::GetDetName(iDet))) 
@@ -1248,9 +1280,7 @@ void AliQAManager::RunOneEvent(AliESDEvent *& esd)
       if ( qadm->IsCycleDone() ) {
         qadm->EndOfCycle() ;
       }
-      AliCodeTimerStart(Form("running ESD quality assurance data maker for %s", AliQAv1::GetDetName(iDet)));
                        qadm->Exec(AliQAv1::kESDS, esd) ;
-      AliCodeTimerStop(Form("running ESD quality assurance data maker for %s", AliQAv1::GetDetName(iDet)));
                }
        }
 }
@@ -1261,24 +1291,24 @@ void AliQAManager::RunOneEventInOneDetector(Int_t det, TTree * tree)
        // Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
   
   TString test(tree->GetName()) ; 
-       AliCodeTimerAuto("") ;
   if (fTasks.Contains(Form("%d", AliQAv1::kRECPOINTS))) {
     if (IsSelected(AliQAv1::GetDetName(det))) {
       AliQADataMaker *qadm = GetQADataMaker(det);  
       if (qadm) { 
         qadm->SetEventSpecie(fEventSpecie) ;  
-        if ( qadm->GetRecoParam() ) 
+        if ( qadm->GetRecoParam() ) {
           if ( AliRecoParam::Convert(qadm->GetRecoParam()->GetEventSpecie()) != AliRecoParam::kDefault)  
-            qadm->SetEventSpecie(qadm->GetRecoParam()->GetEventSpecie()) ;         
+            qadm->SetEventSpecie(qadm->GetRecoParam()->GetEventSpecie()) ; 
+          else
+            AliError(Form("%d defined by %s is not an event specie", qadm->GetRecoParam()->GetEventSpecie(), qadm->GetName())) ; 
+        }                    
         if ( qadm->IsCycleDone() ) {
           qadm->EndOfCycle() ;
         }
-        AliCodeTimerStart(Form("running RecPoints quality assurance data maker for %s", AliQAv1::GetDetName(det)));
         if (test.Contains("TreeD")) {
           qadm->Exec(AliQAv1::kDIGITSR, tree) ;
         } else  if (test.Contains("TreeR")) {
           qadm->Exec(AliQAv1::kRECPOINTS, tree) ;
-          AliCodeTimerStop(Form("running RecPoints quality assurance data maker for %s", AliQAv1::GetDetName(det)));
         }
       }
     }
@@ -1408,6 +1438,16 @@ Bool_t AliQAManager::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile, const
        return rv ; 
 }      
 
+//_____________________________________________________________________________
+
+void AliQAManager::SetCheckerExternParam(AliQAv1::DETECTORINDEX_t detIndex, TList * parameterList) 
+{
+  // set the external parameters list for the detector checkers 
+  AliQACheckerBase * qac = AliQAChecker::Instance()->GetDetQAChecker(detIndex) ; 
+  qac->SetExternParamlist(parameterList) ; 
+  qac->PrintExternParam() ;  
+}
+
 //_____________________________________________________________________________
 void AliQAManager::SetEventSpecie(AliRecoParam::EventSpecie_t es) 
 {