]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliESDInputHandler.cxx
The ANALYSIS one is a modification of the AliXMLCollection which adds
[u/mrichter/AliRoot.git] / STEER / AliESDInputHandler.cxx
index defc4a0d2372d170c14643b041a54b2062908233..3a6a1988253a32633f863b3340f84464a2a54639 100644 (file)
@@ -29,6 +29,7 @@
 #include <TString.h>
 #include <TObjString.h>
 #include <TProcessID.h>
+#include <TMap.h>
 
 #include "AliESDInputHandler.h"
 #include "AliESDEvent.h"
@@ -50,6 +51,7 @@ AliESDInputHandler::AliESDInputHandler() :
   fHLTEvent(0x0),
   fHLTTree(0x0),
   fUseHLT(kFALSE),
+  fTagCutSumm(0x0),
   fUseTags(kFALSE),
   fChainT(0),
   fTreeT(0),
@@ -68,7 +70,7 @@ AliESDInputHandler::~AliESDInputHandler()
 //______________________________________________________________________________
 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
     AliInputEventHandler(name, title), fEvent(0x0), fAnalysisType(0),
-     fNEvents(0),  fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0)
+    fNEvents(0),  fHLTEvent(0x0), fHLTTree(0x0), fUseHLT(kFALSE), fTagCutSumm(0x0), fUseTags(kFALSE), fChainT(0), fTreeT(0), fRunTag(0)
 {
     // Constructor
 }
@@ -86,31 +88,11 @@ Bool_t AliESDInputHandler::Init(TTree* tree,  Option_t* opt)
     SwitchOffBranches();
     SwitchOnBranches();
     
-    if (fEvent) {
-      delete fEvent;
-      fEvent = 0;
-    }
-    fEvent = new AliESDEvent();
-
+    if (!fEvent) fEvent = new AliESDEvent();
     fEvent->ReadFromTree(fTree);
     fNEvents = fTree->GetEntries();
 
-    if (fUseHLT) {
-       // Get HLTesdTree from current file
-       TTree* cTree = tree;
-       if (fTree->GetTree()) cTree = fTree->GetTree();
-       TFile* cFile = cTree->GetCurrentFile();
-       cFile->GetObject("HLTesdTree", fHLTTree);
-       if (fHLTEvent) {
-           delete fHLTEvent;
-           fHLTEvent = 0;
-       }
-       if (fHLTTree) {
-           fHLTEvent = new AliESDEvent();
-           fHLTEvent->ReadFromTree(fHLTTree);
-       }
-    }
-    
+
     return kTRUE;
 }
 
@@ -142,6 +124,19 @@ Bool_t AliESDInputHandler::Notify(const char* path)
     // Notify a directory change
     AliInfo(Form("Directory change %s \n", path));
     //
+    if (fUseHLT) {
+       // Get HLTesdTree from current file
+       TTree* cTree = fTree;
+       if (fTree->GetTree()) cTree = fTree->GetTree();
+       TFile* cFile = cTree->GetCurrentFile();
+       cFile->GetObject("HLTesdTree", fHLTTree);
+       
+       if (fHLTTree) {
+         if (!fHLTEvent) fHLTEvent = new AliESDEvent();
+         fHLTEvent->ReadFromTree(fHLTTree);
+       }
+    }
+
     if (!fUseTags) return (kTRUE);
     
     Bool_t zip = kFALSE;
@@ -238,3 +233,172 @@ Option_t *AliESDInputHandler::GetDataType() const
 // Returns handled data type.
    return gESDDataType;
 }
+
+Int_t AliESDInputHandler::GetNEventAcceptedInFile()
+{
+  // Get number of events in file accepted by the tag cuts
+  // return -1 if no info is available
+  if (!fTagCutSumm) {
+    TList *luo = fTree->GetUserInfo();
+    if (!luo) {
+      AliInfo(Form("No user info in input tree - no tag cut summary\n"));
+      return -1;
+    }
+    for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
+      fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
+      if (fTagCutSumm) break;
+    }
+    if (!fTagCutSumm) {
+      AliInfo(Form("No tag summary map in input tree\n"));
+      return -1;
+    }
+  }
+
+  TObjString *ostr = 0;
+  if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
+    ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
+  else {
+    AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
+    return -1;
+  }
+  char *iTagInfo;
+  iTagInfo = strdup(ostr->GetString().Data());
+
+  Int_t iAcc = atoi(strtok(iTagInfo, ","));
+  
+  AliInfo(Form("Got %i accepted events for file %s", iAcc,  fTree->GetCurrentFile()->GetName()));
+  
+  free(iTagInfo);
+
+  return iAcc;
+}
+Int_t AliESDInputHandler::GetNEventRejectedInFile()
+{
+  // Get number of events in file rejected by the tag cuts
+  // return -1 if no info is available
+  if (!fTagCutSumm) {
+    TList *luo = fTree->GetUserInfo();
+    if (!luo) {
+      AliInfo(Form("No user info in input tree - no tag cut summary\n"));
+      return -1;
+    }
+    for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
+      fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
+      if (fTagCutSumm) break;
+    }
+    if (!fTagCutSumm) {
+      AliInfo(Form("No tag summary map in input tree\n"));
+      return -1;
+    }
+  }
+
+  TObjString *ostr = 0;
+  if (fTagCutSumm->FindObject(fTree->GetCurrentFile()->GetName()))
+    ostr = (TObjString *) fTagCutSumm->GetValue(fTree->GetCurrentFile()->GetName());
+  else {
+    AliInfo(Form("No tag cut summary for file %s\n", fTree->GetCurrentFile()->GetName()));
+    return -1;
+  }
+  char *iTagInfo;
+  iTagInfo = strdup(ostr->GetString().Data());
+
+  strtok(iTagInfo, ",");
+  Int_t iRej = atoi(strtok(NULL, ","));
+  
+  AliInfo(Form("Got %i accepted events for file %s", iRej,  fTree->GetCurrentFile()->GetName()));
+  
+  free(iTagInfo);
+
+  return iRej;
+}
+Bool_t AliESDInputHandler::GetCutSummaryForChain(Int_t *aTotal, Int_t *aAccepted, Int_t *aRejected)
+{
+  // Get number of events in the full chain
+  // Count accepted and rejected events
+  // return kFALSE if no info is available
+  if (!fTagCutSumm) {
+    TList *luo = fTree->GetUserInfo();
+    if (!luo) {
+      AliInfo(Form("No user info in input tree - no tag cut summary\n"));
+      return kFALSE;
+    }
+    for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
+      fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
+      if (fTagCutSumm) break;
+    }
+    if (!fTagCutSumm) {
+      AliInfo(Form("No tag summary map in input tree\n"));
+      return kFALSE;
+    }
+  }
+  
+  TMapIter *tIter = new TMapIter(fTagCutSumm);
+  
+  Int_t iTotList=0, iAccList=0, iRejList=0;
+
+  TObject *cobj;
+  while (cobj = tIter->Next()) {
+    TObjString *kstr = (TObjString *) cobj;
+    TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
+    //    printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
+    char *iTagInfo;
+    iTagInfo = strdup(vstr->GetString().Data());
+    
+    Int_t iAcc = atoi(strtok(iTagInfo, ","));
+    Int_t iRej = atoi(strtok(NULL, ","));
+    
+    iAccList += iAcc;
+    iRejList += iRej;
+    iTotList += (iAcc+iRej);
+  }
+
+  *aTotal = iTotList;
+  *aAccepted = iAccList;
+  *aRejected = iRejList;
+
+  return kTRUE;
+}
+
+Int_t AliESDInputHandler::GetNFilesEmpty()
+{
+  // Count number of files in which all events were de-selected
+  // For such files Notify() will NOT be called
+  // return -1 if no info is available
+  if (!fTagCutSumm) {
+    TList *luo = fTree->GetUserInfo();
+    if (!luo) {
+      AliInfo(Form("No user info in input tree - no tag cut summary\n"));
+      return -1;
+    }
+    for (int iluo=0; iluo<luo->GetEntries(); iluo++) {
+      fTagCutSumm = dynamic_cast<TMap *>(luo->At(iluo));
+      if (fTagCutSumm) break;
+    }
+    if (!fTagCutSumm) {
+      AliInfo(Form("No tag summary map in input tree\n"));
+      return -1;
+    }
+  }
+  
+  TMapIter *tIter = new TMapIter(fTagCutSumm);
+  
+  Int_t iFilesEmpty = 0;
+
+  TObject *cobj;
+  while (cobj = tIter->Next()) {
+    TObjString *kstr = (TObjString *) cobj;
+    TObjString *vstr = (TObjString *) fTagCutSumm->GetValue(kstr->GetString().Data());
+    //    printf("Got object value %s %s\n", kstr->GetString().Data(), vstr->GetString().Data());
+    char *iTagInfo;
+    iTagInfo = strdup(vstr->GetString().Data());
+    
+    Int_t iAcc = atoi(strtok(iTagInfo, ","));
+    Int_t iRej = atoi(strtok(NULL, ","));
+    
+    if ((iAcc == 0) && ((iRej+iAcc)>0))
+      iFilesEmpty++;
+  }
+
+  return iFilesEmpty;
+  
+}