]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliQADataMaker.cxx
Bug corrected.
[u/mrichter/AliRoot.git] / STEER / AliQADataMaker.cxx
index 8f8cb5950695a42529df5630a7f10209b83543b5..fac179f07c8b0727ee2e6596c6e2e6a1ab3b3b2d 100644 (file)
 
 /* $Id$ */
 
-/*
-  Base Class
-  Produces the data needed to calculate the quality assurance. 
-  All data must be mergeable objects.
-  Y. Schutz CERN July 2007
-*/
+//
+//  Base Class
+//  Produces the data needed to calculate the quality assurance. 
+//  All data must be mergeable objects.
+//  Y. Schutz CERN July 2007
+//
 
 // --- ROOT system ---
+#include <TROOT.h> 
 #include <TSystem.h> 
 #include <TFile.h>
 #include <TList.h> 
 #include <TTree.h>
 #include <TClonesArray.h>
+#include <TParameter.h>
+#include <TH1K.h>
+#include <TH2C.h>
+#include <TH2D.h>
+#include <TH2F.h>
+#include <TH2I.h>
+#include <TH3C.h>
+#include <TH3D.h>
+#include <TH3F.h>
+#include <TH3I.h>
+#include <TH3S.h>
 
 // --- Standard library ---
 
 #include "AliQAChecker.h"
 #include "AliESDEvent.h"
 #include "AliRawReader.h"
+#include "AliDetectorRecoParam.h"
+
 
 ClassImp(AliQADataMaker)
              
 //____________________________________________________________________________ 
-AliQADataMaker::AliQADataMaker(const char * name, const char * title) : 
+AliQADataMaker::AliQADataMaker(const Char_t * name, const Char_t * title) : 
   TNamed(name, title), 
   fOutput(0x0),
   fDetectorDir(0x0),
   fDetectorDirName(""), 
-  fDigitsQAList(0x0), 
-  fESDsQAList(0x0), 
-  fHitsQAList(0x0),
-  fRawsQAList(0x0), 
-  fRecPointsQAList(0x0), 
-  fSDigitsQAList(0x0), 
-  fCurrentCycle(-1), 
+  fCurrentCycle(0), 
   fCycle(9999999), 
   fCycleCounter(0), 
-  fRun(0)
+  fWriteExpert(kFALSE),
+  fParameterList(new TList*[AliRecoParam::kNSpecies]), 
+  fRun(0), 
+  fEventSpecie(AliRecoParam::kDefault), 
+  fDigitsArray(NULL) 
 {
   // ctor
   fDetectorDirName = GetName() ; 
+    for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
+      fParameterList[specie] = NULL ; 
+    }
 }
 
 //____________________________________________________________________________ 
@@ -68,364 +83,171 @@ AliQADataMaker::AliQADataMaker(const AliQADataMaker& qadm) :
   fOutput(qadm.fOutput),
   fDetectorDir(qadm.fDetectorDir),
   fDetectorDirName(qadm.fDetectorDirName),
-  fDigitsQAList(qadm.fDigitsQAList),
-  fESDsQAList(qadm.fESDsQAList),
-  fHitsQAList(qadm.fHitsQAList),
-  fRawsQAList(qadm.fRawsQAList),
-  fRecPointsQAList(qadm.fRecPointsQAList),
-  fSDigitsQAList(qadm.fSDigitsQAList), 
   fCurrentCycle(qadm.fCurrentCycle), 
   fCycle(qadm.fCycle), 
   fCycleCounter(qadm.fCycleCounter), 
-  fRun(qadm.fRun)
+  fWriteExpert(qadm.fWriteExpert),
+  fParameterList(qadm.fParameterList),  
+  fRun(qadm.fRun), 
+  fEventSpecie(qadm.fEventSpecie),
+  fDigitsArray(NULL) 
 {
   //copy ctor
   fDetectorDirName = GetName() ; 
+  for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
+    fParameterList[specie] = qadm.fParameterList[specie] ; 
+  //  fImage[specie] = qadm.fImage[specie] ; 
+  }
 }
 
-//__________________________________________________________________
-AliQADataMaker& AliQADataMaker::operator = (const AliQADataMaker& qadm )
+//____________________________________________________________________________ 
+AliQADataMaker::~AliQADataMaker()
 {
-  // Assignment operator.
-  this->~AliQADataMaker();
-  new(this) AliQADataMaker(qadm);
-  return *this;
+  for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
+    if (fParameterList[esIndex] )
+      delete fParameterList[esIndex] ; 
+  }
+  delete[] fParameterList ; 
+
+  if (fDigitsArray) {
+    fDigitsArray->Clear() ; 
+    delete fDigitsArray ;
+  }
 }
 
 //____________________________________________________________________________
-void AliQADataMaker::EndOfCycle(AliQA::TASKINDEX task
+Int_t AliQADataMaker::Add2List(TH1 * hist, const Int_t index, TObjArray ** list, const Bool_t expert, const Bool_t image, const Bool_t saveForCorr
 { 
-  // Finishes a cycle of QA data acquistion
+       // Set histograms memory resident and add to the list
+       // Maximm allowed is 10000
   
- TList * list = 0x0 ; 
-  
- switch (task) { 
-  
-  case AliQA::kRAWS:    
-       list = fRawsQAList ; 
-  break ; 
-
-  case AliQA::kHITS:
-       list = fHitsQAList ; 
-  break ; 
-
-  case AliQA::kSDIGITS:
-       list = fSDigitsQAList ; 
-  break ; 
-    
-  case AliQA::kDIGITS:
-       list = fDigitsQAList ; 
-  break ;  
-   case AliQA::kRECPOINTS:
-       list = fRecPointsQAList ; 
-   break ;  
+  Int_t rv = -1 ; 
+  TClass * classType = hist->Class() ;
+  TString className(classType->GetName()) ; 
+  if( ! className.BeginsWith("T") && ! classType->InheritsFrom("TH1") ) {
+    AliError(Form("QA data Object must be a generic ROOT object and derive fom TH1 and not %s", className.Data())) ; 
+       } else if ( index > AliQAv1::GetMaxQAObj() ) {
+               AliError(Form("Max number of authorized QA objects is %d", AliQAv1::GetMaxQAObj())) ; 
+  } else {
+    hist->SetDirectory(0) ; 
+    if (expert) 
+      hist->SetBit(AliQAv1::GetExpertBit()) ;
+    if (image) 
+      hist->SetBit(AliQAv1::GetImageBit()) ;  
+    const Char_t * name = Form("%s_%s", AliRecoParam::GetEventSpecieName(fEventSpecie), hist->GetName()) ;
+    hist->SetName(name) ; 
+    if(saveForCorr) {  
+      const Char_t * cname = Form("%s_%s", list[AliRecoParam::AConvert(AliRecoParam::kDefault)]->GetName(), hist->GetName()) ;  
+      TParameter<double> * p = new TParameter<double>(cname, 9999.9999) ;
+      if ( fParameterList[AliRecoParam::AConvert(fEventSpecie)] == NULL )
+        fParameterList[AliRecoParam::AConvert(fEventSpecie)] = new TList() ; 
+      fParameterList[AliRecoParam::AConvert(fEventSpecie)]->Add(p) ;
+    }
+    TObject* old = list[AliRecoParam::AConvert(fEventSpecie)]->At(index);
+    if (old) {
+      AliError(Form("%s - OUPS ! Already got an object (%p,%s) for index=%d => will most probably get a memory leak by replacing it with (%p,%s) !",
+                    GetName(),old,old->GetName(),index,hist,hist->GetName()));
+    }
+    list[AliRecoParam::AConvert(fEventSpecie)]->AddAtAndExpand(hist, index) ; 
+    rv = list[AliRecoParam::AConvert(fEventSpecie)]->GetLast() ;
+  }
+  return rv ; 
+}
 
-   case AliQA::kTRACKSEGMENTS:
-   break ;  
-  
-   case AliQA::kRECPARTICLES:
-   break ;  
-    
-   case AliQA::kESDS:
-       list = fESDsQAList ; 
-   break ;  
-  }    
-  
- EndOfDetectorCycle(task, list) ; 
- TDirectory * subDir = fDetectorDir->GetDirectory(AliQA::GetTaskName(task)) ; 
- subDir->cd() ; 
- list->Write() ; 
+//____________________________________________________________________________
+TH1 *  AliQADataMaker::CloneMe(TH1 * hist, Int_t specie) const  
+{
+  // clones a histogram 
+  const Char_t * name = Form("%s_%s", AliRecoParam::GetEventSpecieName(specie), hist->GetName()) ;
+  TH1 * hClone = static_cast<TH1 *>(hist->Clone(name)) ; 
+  if ( hist->TestBit(AliQAv1::GetExpertBit()) )
+    hClone->SetBit(AliQAv1::GetExpertBit()) ; 
+  if ( hist->TestBit(AliQAv1::GetImageBit()) )
+    hClone->SetBit(AliQAv1::GetImageBit()) ; 
+  return hClone ; 
 }
+
 //____________________________________________________________________________
-void AliQADataMaker::Exec(AliQA::TASKINDEX task, TObject * data) 
-{ 
-  // creates the quality assurance data for the various tasks (Hits, SDigits, Digits, ESDs)
-    
-       switch (task) { 
-  
-               case AliQA::kRAWS:
-               {
-                       AliDebug(1, "Processing Raws QA") ; 
-                       AliRawReader * rawReader = dynamic_cast<AliRawReader *>(data) ; 
-                       if (rawReader) 
-                               MakeRaws(rawReader) ;
-                       else
-                       AliError("Wrong data type") ;     
-                       break ; 
-               }
-               case AliQA::kHITS:
-               {  
-                       AliDebug(1, "Processing Hits QA") ; 
-                       TClonesArray * arr = dynamic_cast<TClonesArray *>(data) ; 
-                       if (arr) { 
-                               MakeHits(arr) ;
-                       } else {
-                               TTree * tree = dynamic_cast<TTree *>(data) ; 
-                               if (tree) {
-                                       MakeHits(tree) ; 
-                               } else {
-                                       AliWarning("data are neither a TClonesArray nor a TTree") ; 
-                               }
-                       }
-                       break ; 
-               }
-               case AliQA::kSDIGITS:
-               {
-                       AliDebug(1, "Processing SDigits QA") ; 
-                       TClonesArray * arr = dynamic_cast<TClonesArray *>(data) ; 
-                       if (arr) { 
-                               MakeSDigits(arr) ;
-                       } else {
-                               TTree * tree = dynamic_cast<TTree *>(data) ; 
-                               if (tree) {
-                                       MakeSDigits(tree) ; 
-                               } else {
-                                       AliWarning("data are neither a TClonesArray nor a TTree") ; 
-                               }
-                       }
-                       break ; 
-               }  
-               case AliQA::kDIGITS:
-               {
-                       AliDebug(1, "Processing Digits QA") ; 
-                       TClonesArray * arr = dynamic_cast<TClonesArray *>(data) ; 
-                       if (arr) { 
-                               MakeDigits(arr) ;
-                       } else {
-                               TTree * tree = dynamic_cast<TTree *>(data) ; 
-                               if (tree) {
-                                       MakeDigits(tree) ; 
-                               } else {
-                                       AliWarning("data are neither a TClonesArray nor a TTree") ; 
-                               }
-                       }
-                       break ;  
-               }
-               case AliQA::kRECPOINTS:
-               {
-                       AliDebug(1, "Processing RecPoints QA") ; 
-                       TTree * tree = dynamic_cast<TTree *>(data) ; 
-                       if (tree) {
-                               MakeRecPoints(tree) ; 
-                       } else {
-                               AliWarning("data are not a TTree") ; 
-                       }
-                       break ;  
-               }
-               case AliQA::kTRACKSEGMENTS:
-                       AliInfo("Processing Track Segments QA: not existing anymore") ; 
-               //       MakeTrackSegments(ts) ;
-               break ;  
-  
-               case AliQA::kRECPARTICLES:
-                       AliInfo("Processing RecParticles QA: not existing anymore") ; 
-                       //       MakeRecParticles(recpar) ;
-               break ;  
-               case AliQA::kESDS:
-               {
-                       AliDebug(1, "Processing ESDs QA") ; 
-                       AliESDEvent * esd = dynamic_cast<AliESDEvent *>(data) ; 
-                       if (esd) 
-                               MakeESDs(esd) ;
-                       else 
-                               AliError("Wrong type of esd container") ; 
-                       break ;
-               }  
-       }         
+void AliQADataMaker::DefaultEndOfDetectorCycle(AliQAv1::TASKINDEX_t task) 
+{
+       // this method must be oveloaded by detectors
+       // sets the QA result to Fatal
+       AliQAv1::Instance(AliQAv1::GetDetIndex(GetName())) ;
+       AliQAv1 * qa = AliQAv1::Instance(task) ;
+  for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) 
+    qa->Set(AliQAv1::kFATAL, specie) ; 
+       AliQAv1::GetQAResultFile()->cd() ; 
+       qa->Write(AliQAv1::GetQAName(), kWriteDelete) ;   
+       AliQAv1::GetQAResultFile()->Close() ; 
 }
 
 //____________________________________________________________________________ 
 void AliQADataMaker::Finish() const 
 { 
-  // write to the output File
-  fOutput->Close() ; 
+       // write to the output File
+       if (fOutput) 
+               fOutput->Close() ; 
 } 
 
 //____________________________________________________________________________ 
-TList *  AliQADataMaker::Init(AliQA::TASKINDEX task, Int_t run, Int_t cycles)
-{
-  // general intialisation
-  
-  fRun = run ;
-  if (cycles > 0)
-    SetCycle(cycles) ;  
-       
-  switch (task) {
-  case AliQA::kRAWS: 
-   {
-       fRawsQAList = new TList() ;      
-    InitRaws() ;
-       return fRawsQAList ;
-    break ; 
-   }
-  case AliQA::kHITS: 
-   {
-       fHitsQAList = new TList() ;      
-    InitHits() ;
-       return fHitsQAList ;
-    break ; 
-   }
-  case AliQA::kSDIGITS: 
-   {
-       fSDigitsQAList = new TList() ; 
-    InitSDigits() ;
-       return fSDigitsQAList ;
-    break ; 
-   }
-  case AliQA::kDIGITS: 
-   {
-       fDigitsQAList = new TList(); 
-       InitDigits() ;
-       return fDigitsQAList ;
-       break ; 
-   }     
-  case AliQA::kRECPOINTS: 
-   {
-       fRecPointsQAList = new TList() ; 
-    InitRecPoints() ;
-       return fRecPointsQAList ;
-    break ; 
+TObject * AliQADataMaker::GetData(TObjArray ** list, const Int_t index)  
+{ 
+       // Returns the QA object at index. Limit is AliQAv1::GetMaxQAObj() 
+  if ( ! list ) {
+               AliError("Data list is NULL !!") ; 
+               return NULL ;           
+       }
+
+  SetEventSpecie(fEventSpecie) ;  
+  Int_t esindex = AliRecoParam::AConvert(fEventSpecie) ; 
+  TH1 * histClone = NULL ; 
+  TObjArray * arr = list[esindex] ; 
+       if (arr) {
+    if ( ! arr->GetEntriesFast() ) {
+      // Initializes the histograms 
+      TString arrName(arr->GetName()) ; 
+      if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kRAWS)))
+        InitRaws() ; 
+      else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kHITS)))
+        InitHits() ; 
+      else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kSDIGITS)))
+        InitSDigits() ; 
+      else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kDIGITS)))
+        InitDigits() ; 
+      else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kDIGITSR)))
+        InitDigits() ; 
+      else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kRECPOINTS)))
+        InitRecPoints() ; 
+      else if (arrName.Contains(AliQAv1::GetTaskName(AliQAv1::kESDS)))
+        InitESDs() ; 
+    }
+               if ( index > AliQAv1::GetMaxQAObj() ) {
+                       AliError(Form("Max number of authorized QA objects is %d", AliQAv1::GetMaxQAObj())) ; 
+               } else {
+      if ( arr->At(index) )  {
+        histClone = static_cast<TH1*>(arr->At(index)) ; 
+      }        
+    }
   }
-  case AliQA::kTRACKSEGMENTS: 
-//  InitTrackSegments() ;
-    break ; 
-    
-  case AliQA::kRECPARTICLES: 
-//    InitRecParticles() ;
-    break ; 
-    
-  case AliQA::kESDS: 
-   {
-       fESDsQAList = new TList() ; 
-       InitESDs() ;
-       return fRecPointsQAList ;
-    break ; 
-   }
-  }  
-  return 0x0 ; 
+  return histClone ;           
 }
 
 //____________________________________________________________________________ 
-void AliQADataMaker::Init(AliQA::TASKINDEX task, TList * list, Int_t run, Int_t cycles)
+TObjArray*  AliQADataMaker::Init(AliQAv1::TASKINDEX_t task, AliRecoParam::EventSpecie_t es, Int_t cycles)
 {
-  // Intialisation by passing the list of QA data booked elsewhere
-  
-  fRun = run ;
-  if (cycles > 0)
-    SetCycle(cycles) ;  
-       
-  switch (task) {
-  case AliQA::kRAWS: 
-   {
-       fRawsQAList = list ;     
-    break ; 
-   }
-  case AliQA::kHITS: 
-   {
-       fHitsQAList = list ;     
-    break ; 
-   }
-  case AliQA::kSDIGITS: 
-   {
-       fSDigitsQAList = list ; 
-    break ; 
-   }
-  case AliQA::kDIGITS: 
-   {
-       fDigitsQAList = list ; 
-       break ; 
-   }     
-  case AliQA::kRECPOINTS: 
-   {
-       fRecPointsQAList = list ; 
-    break ; 
-  }
-  case AliQA::kTRACKSEGMENTS: 
-    break ; 
-    
-  case AliQA::kRECPARTICLES: 
-    break ; 
-    
-  case AliQA::kESDS: 
-   {
-       fESDsQAList = list ; 
-    break ; 
-   }
-  }  
+  // Initialializes and  returns the QAData list for a given event specie
+  TObjArray ** ar = Init(task, cycles) ; 
+  return ar[AliRecoParam::AConvert(es)] ;  
 }
 
-//____________________________________________________________________________
-void AliQADataMaker::Reset() 
-{ 
-  // Resets defaut value of data members 
-  fCurrentCycle = -1 ;  
-  fCycleCounter = 0 ; 
+//____________________________________________________________________________ 
+Bool_t AliQADataMaker::IsValidEventSpecie(Int_t eventSpecieIndex, TObjArray ** list)
+{
+  // check if event specie was present in current run or 
+  // if histograms of this event specie have been created
+  if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(eventSpecieIndex)) || ! list[eventSpecieIndex]->GetEntriesFast() )
+    return kFALSE ;
+  else
+    return kTRUE ;
 }
 
-//____________________________________________________________________________
-void AliQADataMaker::StartOfCycle(AliQA::TASKINDEX task, const Bool_t sameCycle) 
-{ 
-  // Finishes a cycle of QA data acquistion
- if ( !sameCycle || fCurrentCycle == -1) {
-       ResetCycle() ;
-       if (fOutput) 
-               fOutput->Close() ; 
-       fOutput = AliQA::GetQADataFile(GetName(), fRun, fCurrentCycle) ;        
-}      
- AliInfo(Form(" Run %d Cycle %d task %s file %s", 
-       fRun, fCurrentCycle, AliQA::GetTaskName(task).Data(), fOutput->GetName() )) ;
-
- fDetectorDir = fOutput->GetDirectory(GetDetectorDirName()) ; 
- if (!fDetectorDir)
-   fDetectorDir = fOutput->mkdir(GetDetectorDirName()) ; 
-
- TDirectory * subDir = fDetectorDir->GetDirectory(AliQA::GetTaskName(task)) ; 
- if (!subDir)
-   subDir = fDetectorDir->mkdir(AliQA::GetTaskName(task)) ;  
- subDir->cd() ; 
-
-  TList * list = 0x0 ; 
-  
-  switch (task) { 
-  case AliQA::kRAWS: 
-       list = fRawsQAList ; 
-    break ; 
-
-  case AliQA::kHITS: 
-       list = fHitsQAList ; 
-    break ; 
-  
-  case AliQA::kSDIGITS: 
-       list = fSDigitsQAList ;
-    break ; 
-
-  case AliQA::kDIGITS: 
-       list = fDigitsQAList ;
-       break ; 
-         
-  case AliQA::kRECPOINTS: 
-       list = fRecPointsQAList ;
-       break ; 
-
-  case AliQA::kTRACKSEGMENTS: 
-    break ; 
-    
-  case AliQA::kRECPARTICLES: 
-    break ; 
-    
-  case AliQA::kESDS: 
-       list = fESDsQAList ;
-    break ; 
-  }  
-
- TIter next(list) ;
- TH1 * h ; 
- while ( (h = dynamic_cast<TH1 *>(next())) )
-    h->Reset() ;  
-
- StartOfDetectorCycle() ; 
-
-}