]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliQA.cxx
To test the retrieval and storage of raw tag files, return in case of DCS problems...
[u/mrichter/AliRoot.git] / STEER / AliQA.cxx
index 19904bdb186c7745639d40ba0bded259100e0b59..daa921b6694edafcf98c99f5aeabf25cbfc1ae26 100644 (file)
 // --- ROOT system ---
 #include <TFile.h>
 #include <TSystem.h>
+#include <TROOT.h>
 
 // --- Standard library ---
 
 // --- AliRoot header files ---
-#include "AliCDBManager.h"
-#include "AliCDBMetaData.h"
-#include "AliCDBEntry.h"
 #include "AliLog.h"
 #include "AliQA.h"
-#include "AliQAChecker.h"
 
 
 ClassImp(AliQA)
-  AliQA    * AliQA::fgQA                = 0x0 ;
-  TFile    * AliQA::fgDataFile          = 0x0 ;   
-  TString    AliQA::fgDataName          = "QA" ;  // will transform into Det.QA.run.cycle.root  
-  TString    AliQA::fgQARefDirName             = "local://Ref/" ; 
-  TString    AliQA::fgQARefFileName     = "QA.root" ;
-  TString    AliQA::fgQAResultDirName   = "local://RUN/" ;  
-  TString    AliQA::fgQAResultFileName  = "QA.root" ; 
-  TString    AliQA::fgDetNames[]  = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD",
-                                       "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"} ;   
-  TString   AliQA::fgTaskNames[]  = {"Raws", "Hits", "SDigits", "Digits", "RecPoints", "TrackSegments", "RecParticles", "ESDs"} ;   
-
+AliQA    * AliQA::fgQA                   = 0x0 ;
+TFile    * AliQA::fgQADataFile           = 0x0 ;   
+TString    AliQA::fgQADataFileName       = "QA" ;  // will transform into Det.QA.run.cycle.root  
+TFile    * AliQA::fgQARefFile            = 0x0 ;   
+TString    AliQA::fgQARefDirName            = "" ; 
+TString    AliQA::fgQARefFileName        = "QA.root" ;
+TFile    * AliQA::fgQAResultFile         = 0x0 ;  
+TString    AliQA::fgQAResultDirName      = "" ;  
+TString    AliQA::fgQAResultFileName     = "QA.root" ; 
+TString    AliQA::fgDetNames[]           = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD",
+                                                                                   "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"} ;   
+TString       AliQA::fgTaskNames[]       = {"Raws", "Hits", "SDigits", "Digits", "RecPoints", "TrackSegments", "RecParticles", "ESDs"} ;   
+const TString AliQA::fkgLabLocalFile     = "file://"  ; 
+const TString AliQA::fkgLabLocalOCDB     = "local://" ;  
+const TString AliQA::fkgLabAliEnOCDB     = "alien://" ;  
+const TString AliQA::fkgRefFileName      = "QA.root" ; 
+const TString AliQA::fkgQAOCDBDirName    = "QA"  ; 
+const TString AliQA::fkgRefOCDBDirName   = "Ref"  ; 
+const TString AliQA::fkgQARefOCDBDefault = "local://$ALICE_ROOT"  ; 
 //____________________________________________________________________________
 AliQA::AliQA() : 
   TNamed("", ""), 
@@ -65,6 +70,7 @@ AliQA::AliQA() :
   fQA(new ULong_t[fNdet]), 
   fDet(kNULLDET),
   fTask(kNULLTASK)
+       
 {
   // default constructor
   // beware singleton: not to be used
@@ -100,7 +106,7 @@ AliQA::AliQA(const DETECTORINDEX det) :
   fNdet(kNDET),  
   fQA(new ULong_t[fNdet]), 
   fDet(det),
-  fTask(kNULLTASK)
+  fTask(kNULLTASK) 
 {
   // constructor to be used
   if (! CheckRange(det) ) {
@@ -138,19 +144,19 @@ AliQA::~AliQA()
 }
 
 //_______________________________________________________________
-const Bool_t AliQA::AddQAData2CDB(const char * defSto) const 
+void AliQA::Close() 
 {
-       // loads the QA data into the OCDB
-       Bool_t rv = kTRUE ; 
-       AliCDBManager* man = AliCDBManager::Instance() ;
-       man->SetDefaultStorage(defSto) ;
-       AliCDBMetaData md ; 
-       // loop over detectors  
-       AliCDBId id("QA/Ref/PHOS",0,999999999) ;
-
-       
-       return rv ; 
-}  
+       // close the open files
+       if (fgQADataFile) 
+               if (fgQADataFile->IsOpen())
+                       fgQADataFile->Close() ; 
+       if (fgQAResultFile) 
+               if (fgQAResultFile->IsOpen()) 
+                       fgQAResultFile->Close() ;
+       if (fgQARefFile)
+               if (fgQARefFile->IsOpen())
+                       fgQARefFile->Close() ; 
+} 
 
 //_______________________________________________________________
 const Bool_t AliQA::CheckFatal() const
@@ -195,42 +201,7 @@ const Bool_t AliQA::CheckRange(QABIT bit) const
   return rv ;
 }
 
-//_______________________________________________________________
-TFile * AliQA::GetQADMOutFile(const char * name, const Int_t run, const Int_t cycle) 
-{
-  // opens the file to store the detectors Quality Assurance Data Maker results
-  char temp[100] ; 
-  sprintf(temp, "%s.%s.%d.%d.root", name, fgDataName.Data(), run, cycle) ; 
-  TString opt ; 
-  if (! fgDataFile ) {     
-    if  (gSystem->AccessPathName(temp))
-      opt = "NEW" ;
-    else 
-      opt = "UPDATE" ; 
-    fgDataFile = TFile::Open(temp, opt.Data()) ;
-  } else {
-   if ( (strcmp(temp, fgDataFile->GetName()) != 0) ) {
-     if  (gSystem->AccessPathName(temp))
-      opt = "NEW" ;
-    else 
-      opt = "UPDATE" ; 
-    fgDataFile = TFile::Open(temp, opt.Data()) ;
-   }
-  }
-  return fgDataFile ; 
-} 
-
 
-//_______________________________________________________________
-const char * AliQA::GetDetName(Int_t det) 
-{
-       // returns the detector name corresponding to a given index (needed in a loop)
-
-       if ( det >= 0 &&  det < kNDET) 
-               return (fgDetNames[det]).Data() ; 
-       else 
-               return NULL ; 
-}
 
 //_______________________________________________________________
 const char * AliQA::GetAliTaskName(ALITASK tsk)
@@ -263,33 +234,83 @@ const char * AliQA::GetAliTaskName(ALITASK tsk)
 }
 
 //_______________________________________________________________
-TFile * AliQA::GetQARefFile(
+const char * AliQA::GetDetName(Int_t det
 {
-  // opens the file whwre Quality Assurance Reference Data are stored
-
-       TString fileName(fgQARefDirName + fgQARefFileName) ; 
+       // returns the detector name corresponding to a given index (needed in a loop)
 
-       if ( fileName.Contains("local://")) 
-               fileName.ReplaceAll("local://", "") ;
+       if ( det >= 0 &&  det < kNDET) 
+               return (fgDetNames[det]).Data() ; 
+       else 
+               return NULL ; 
+}
 
-       return TFile::Open(fileName.Data(), "READ") ;
+//_______________________________________________________________
+TFile * AliQA::GetQADataFile(const char * name, const Int_t run, const Int_t cycle) 
+{
+  // opens the file to store the detectors Quality Assurance Data Maker results
+  char temp[20] ; 
+  sprintf(temp, "%s.%s.%d.%d.root", name, fgQADataFileName.Data(), run, cycle) ; 
+  TString opt ; 
+  if (! fgQADataFile ) {     
+    if  (gSystem->AccessPathName(temp))
+      opt = "NEW" ;
+    else 
+      opt = "UPDATE" ; 
+    fgQADataFile = TFile::Open(temp, opt.Data()) ;
+  } else {
+         if ( strcmp(temp, fgQADataFile->GetName()) != 0 ) {
+                 fgQADataFile = dynamic_cast<TFile *>(gROOT->FindObject(temp)) ; 
+                 if ( !fgQADataFile ) {
+                         if  (gSystem->AccessPathName(temp))
+                                 opt = "NEW" ;
+                         else 
+                                 opt = "UPDATE" ; 
+                         fgQADataFile = TFile::Open(temp, opt.Data()) ;
+                 }
+         }
+  }
+  return fgQADataFile ; 
 } 
 
+//_____________________________________________________________________________
+TFile * AliQA::GetQADataFile(const char * fileName)
+{
+  // Open if necessary the Data file and return its pointer
+
+  if (!fgQADataFile) 
+       if (!fileName) 
+               fileName = AliQA::GetQADataFileName() ; 
+       if  (!gSystem->AccessPathName(fileName)) {
+               fgQADataFile =  TFile::Open(fileName) ;
+       } else {
+               printf("File %s not found", fileName) ;
+               exit(1) ;  
+       }
+  return fgQADataFile ; 
+}
+
 //_______________________________________________________________
 TFile * AliQA::GetQAResultFile() 
 {
   // opens the file to store the  Quality Assurance Data Checker results
    
-       TString fileName(fgQAResultDirName + fgQAResultFileName) ; 
-       if ( fileName.Contains("local://")) 
-               fileName.ReplaceAll("local://", "") ;
-       TString opt("") ; 
-       if ( !gSystem->AccessPathName(fileName) )
-               opt = "UPDATE" ; 
-       else 
-               opt = "NEW" ; 
-      
-       return TFile::Open(fileName, opt) ;   
+       if (!fgQAResultFile) { 
+               TString dirName(fgQAResultDirName) ; 
+               if ( dirName.Contains(fkgLabLocalFile)) 
+                       dirName.ReplaceAll(fkgLabLocalFile, "") ;
+               TString fileName(dirName + fgQAResultFileName) ; 
+               TString opt("") ; 
+               if ( !gSystem->AccessPathName(fileName) )
+                       opt = "UPDATE" ; 
+               else { 
+                       if ( gSystem->AccessPathName(dirName) )
+                               gSystem->mkdir(dirName) ; 
+                       opt = "NEW" ; 
+               }
+               fgQAResultFile = TFile::Open(fileName, opt) ;   
+       }
+       
+       return fgQAResultFile ;
 }
 
 //_______________________________________________________________
@@ -323,7 +344,7 @@ AliQA * AliQA::Instance(const DETECTORINDEX det)
   // Get an instance of the singleton. The only authorized way to call the ctor
   
   if ( ! fgQA) {
-    TFile * f = AliQAChecker::GetQAResultFile() ; 
+    TFile * f = GetQAResultFile() ; 
        fgQA = dynamic_cast<AliQA *>(f->Get("QA")) ; 
     if ( ! fgQA ) 
                fgQA = new AliQA(det) ;
@@ -406,15 +427,22 @@ void AliQA::Set(QABIT bit)
 }
 
 //_____________________________________________________________________________
-void AliQA::SetQARefDir(const char * name)
+void AliQA::SetQARefStorage(const char * name)
 {
   // Set the root directory where the QA reference data are stored
 
-  fgQARefDirName.Prepend(name) ; 
-  printf("AliQA::SetQARefDir: QA references are in  %s\n", fgQARefDirName.Data()) ;
-  if ( fgQARefDirName.Contains("local://")) 
-    fgQARefDirName.ReplaceAll("local:/", "") ;
-  fgQARefFileName.Prepend(fgQARefDirName) ;
+  fgQARefDirName = name ; 
+  if ( fgQARefDirName.Contains(fkgLabLocalFile) )
+        fgQARefFileName =  fkgRefFileName ; 
+  else if (    fgQARefDirName.Contains(fkgLabLocalOCDB) )
+         fgQARefFileName =  fkgQAOCDBDirName ; 
+  else {
+         printf("ERROR: %s is an invalid storage definition\n", name) ; 
+         fgQARefDirName  = "" ; 
+         fgQARefFileName = "" ; 
+  }    
+       TString tmp(fgQARefDirName + fgQARefFileName) ;
+       printf("AliQA::SetQARefDir: QA references are in  %s\n", tmp.Data() ) ;
 }
 
 //_____________________________________________________________________________
@@ -424,8 +452,8 @@ void AliQA::SetQAResultDirName(const char * name)
 
   fgQAResultDirName.Prepend(name) ; 
   printf("AliQA::SetQAResultDirName: QA results are in  %s\n", fgQAResultDirName.Data()) ;
-  if ( fgQAResultDirName.Contains("local://")) 
-    fgQAResultDirName.ReplaceAll("local:/", "") ;
+  if ( fgQAResultDirName.Contains(fkgLabLocalFile)) 
+    fgQAResultDirName.ReplaceAll(fkgLabLocalFile, "") ;
   fgQAResultFileName.Prepend(fgQAResultDirName) ;
 }