]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliAnalysisManager.cxx
Reading friends in analysis framework inside HLT
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisManager.cxx
index 15b6425e9e52be6922c6670a6686bc7ae5a28d2c..281adc03afd2c6d653c976d772e6829a11eaa916 100644 (file)
@@ -54,6 +54,8 @@
 #include "AliVEventPool.h"
 #include "AliSysInfo.h"
 #include "AliAnalysisStatistics.h"
+#include "AliVEvent.h"
+#include "AliHLTTestInputHandler.h"
 
 using std::ofstream;
 using std::ios;
@@ -81,6 +83,7 @@ AliAnalysisManager::AliAnalysisManager(const char *name, const char *title)
                     fMustClean(kFALSE),
                     fIsRemote(kFALSE),
                     fLocked(kFALSE),
+                    fMCLoop(kFALSE),
                     fDebug(0),
                     fSpecialOutputLocation(""), 
                     fTasks(0),
@@ -90,6 +93,7 @@ AliAnalysisManager::AliAnalysisManager(const char *name, const char *title)
                     fInputs(0),
                     fOutputs(0),
                     fParamCont(0),
+                    fExchangeCont(0),
                     fDebugOptions(0),
                     fFileDescriptors(new TObjArray()),
                     fCurrentDescriptor(0),
@@ -128,6 +132,7 @@ AliAnalysisManager::AliAnalysisManager(const char *name, const char *title)
      fInputs     = new TObjArray();
      fOutputs    = new TObjArray();
      fParamCont  = new TObjArray();
+     fExchangeCont = new TObjArray();
      fGlobals    = new TMap();
    }
    fIOTimer = new TStopwatch();
@@ -151,6 +156,7 @@ AliAnalysisManager::AliAnalysisManager(const AliAnalysisManager& other)
                     fMustClean(other.fMustClean),
                     fIsRemote(other.fIsRemote),
                     fLocked(other.fLocked),
+                    fMCLoop(other.fMCLoop),
                     fDebug(other.fDebug),
                     fSpecialOutputLocation(""), 
                     fTasks(NULL),
@@ -160,6 +166,7 @@ AliAnalysisManager::AliAnalysisManager(const AliAnalysisManager& other)
                     fInputs(NULL),
                     fOutputs(NULL),
                     fParamCont(NULL),
+                    fExchangeCont(NULL),
                     fDebugOptions(NULL),
                     fFileDescriptors(new TObjArray()),
                     fCurrentDescriptor(0),
@@ -195,6 +202,7 @@ AliAnalysisManager::AliAnalysisManager(const AliAnalysisManager& other)
    fInputs     = new TObjArray(*other.fInputs);
    fOutputs    = new TObjArray(*other.fOutputs);
    fParamCont  = new TObjArray(*other.fParamCont);
+   fExchangeCont  = new TObjArray(*other.fExchangeCont);
    fgCommonFileName  = "AnalysisResults.root";
    fgAnalysisManager = this;
 }
@@ -216,6 +224,7 @@ AliAnalysisManager& AliAnalysisManager::operator=(const AliAnalysisManager& othe
       fInitOK     = other.fInitOK;
       fIsRemote   = other.fIsRemote;
       fLocked     = other.fLocked;
+      fMCLoop     = other.fMCLoop;
       fDebug      = other.fDebug;
       fTasks      = new TObjArray(*other.fTasks);
       fTopTasks   = new TObjArray(*other.fTopTasks);
@@ -224,6 +233,7 @@ AliAnalysisManager& AliAnalysisManager::operator=(const AliAnalysisManager& othe
       fInputs     = new TObjArray(*other.fInputs);
       fOutputs    = new TObjArray(*other.fOutputs);
       fParamCont  = new TObjArray(*other.fParamCont);
+      fExchangeCont  = new TObjArray(*other.fExchangeCont);
       fDebugOptions = NULL;
       fFileDescriptors = new TObjArray();
       fCurrentDescriptor = 0;
@@ -261,18 +271,19 @@ AliAnalysisManager::~AliAnalysisManager()
 {
 // Destructor.
    if (fTasks) {fTasks->Delete(); delete fTasks;}
-   if (fTopTasks) delete fTopTasks;
-   if (fZombies) delete fZombies;
+   delete fTopTasks;
+   delete fZombies;
    if (fContainers) {fContainers->Delete(); delete fContainers;}
-   if (fInputs) delete fInputs;
-   if (fOutputs) delete fOutputs;
-   if (fParamCont) delete fParamCont;
-   if (fDebugOptions) delete fDebugOptions;
-   if (fGridHandler) delete fGridHandler;
-   if (fInputEventHandler) delete fInputEventHandler;
-   if (fOutputEventHandler) delete fOutputEventHandler;
-   if (fMCtruthEventHandler) delete fMCtruthEventHandler;
-   if (fEventPool) delete fEventPool;
+   delete fInputs;
+   delete fOutputs;
+   delete fParamCont;
+   delete fExchangeCont;
+   delete fDebugOptions;
+   delete fGridHandler;
+   delete fInputEventHandler;
+   delete fOutputEventHandler;
+   delete fMCtruthEventHandler;
+   delete fEventPool;
    if (fgAnalysisManager==this) fgAnalysisManager = NULL;
    if (fGlobals) {fGlobals->DeleteAll(); delete fGlobals;}
    if (fFileDescriptors) {fFileDescriptors->Delete(); delete fFileDescriptors;}
@@ -298,7 +309,16 @@ void AliAnalysisManager::CreateReadCache()
    if (fAsyncReading) gEnv->SetValue("TFile.AsyncReading",1);
    fTree->SetCacheSize(fCacheSize);
    TTreeCache::SetLearnEntries(1);  //<<< we can take the decision after 1 entry
-   fTree->AddBranchToCache("*",kTRUE);    //<<< add all branches to the cache
+   if (!fAutoBranchHandling && !fRequestedBranches.IsNull()) {
+      TObjArray *arr = fRequestedBranches.Tokenize(",");
+      TIter next(arr);
+      TObject *obj;
+      while ((obj=next()))
+         fTree->AddBranchToCache(obj->GetName(),kTRUE);  //<<< add requested branches to cache
+      delete arr;   
+   } else {
+      fTree->AddBranchToCache("*", kTRUE);  //<<< add all branches to cache
+   }   
    if (fDebug) {
       Info("CreateReadCache","Read cache enabled %lld bytes with async reading=%d",fCacheSize, (Int_t)fAsyncReading);
    }
@@ -318,19 +338,17 @@ Bool_t AliAnalysisManager::EventLoop(Long64_t nevents)
      Error("EventLoop", "No input handler: exiting");
      return kFALSE;
    }
-   TTree *tree = fInputEventHandler->MakeTree();
-   if (!tree) {
-     Error("EventLoop", "The input handler must provide MakeTree()");
-     return kFALSE;
-  }
-  SetExternalLoop(kTRUE);
-  if (!Init(tree)) return kFALSE;
-  for (Long64_t iev=0; iev<nevents; iev++) {
-    fInputEventHandler->BeginEvent(iev);
-    ExecAnalysis();
-    fInputEventHandler->FinishEvent();
-  }
-  return kTRUE;
+   TTree *tree = new TTree("DummyTree", "Dummy tree for AliAnalysisManager::EventLoop");
+   SetExternalLoop(kTRUE);
+   if (!Init(tree)) return kFALSE;
+   SlaveBegin(tree);
+   for (Long64_t iev=0; iev<nevents; iev++)
+      ExecAnalysis();
+   TList dummyList;
+   PackOutput(&dummyList);
+   fIsRemote = kTRUE;
+   Terminate();
+   return kTRUE;
 }
       
 //______________________________________________________________________________
@@ -445,7 +463,10 @@ Bool_t AliAnalysisManager::Init(TTree *tree)
    if (!fInitOK) return kFALSE;
    fTree = tree;
    if (fMode != kProofAnalysis) CreateReadCache();
-   fTable.Rehash(100);
+   else {
+     // cholm - here we should re-add to the table or branches 
+     fTable.Clear();
+   }
    AliAnalysisDataContainer *top = fCommonInput;
    if (!top) top = (AliAnalysisDataContainer*)fInputs->At(0);
    if (!top) {
@@ -454,6 +475,7 @@ Bool_t AliAnalysisManager::Init(TTree *tree)
    }
    top->SetData(tree);
    CheckBranches(kFALSE);
+   fTable.Rehash(100);
    if (fDebug > 1) {
       printf("<-AliAnalysisManager::Init(%s)\n", tree->GetName());
    }
@@ -1427,6 +1449,9 @@ AliAnalysisDataContainer *AliAnalysisManager::CreateContainer(const char *name,
          }   
          break;
       case kExchangeContainer:
+         cont->SetExchange(kTRUE);
+         fExchangeCont->Add(cont);
+         cont->SetDataOwned(kFALSE); // data owned by the publisher
          break;   
    }
    return cont;
@@ -1638,8 +1663,8 @@ void AliAnalysisManager::CheckBranches(Bool_t load)
             Error("CheckBranches", "Could not find branch %s",obj->GetName());
             continue;
          }
+         fTable.Add(br);
       }   
-      fTable.Add(br);
       if (load && br->GetReadEntry()!=GetCurrentEntry()) {
          br->GetEntry(GetCurrentEntry());
       }      
@@ -1682,10 +1707,17 @@ void AliAnalysisManager::PrintStatus(Option_t *option) const
    Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
    if (getsysInfo)
       Info("PrintStatus", "System information will be collected each %lld events", fNSysInfo);
-   TIter next(fTopTasks);
+   AliAnalysisDataContainer *cont = fCommonInput;
+   if (!cont) cont = (AliAnalysisDataContainer*)fInputs->At(0);
+   printf("=== TOP CONTAINER:\n");
+   cont->PrintContainer(option,0);
+   // Reset "touched" flag
+   TIter next(fContainers);
+   while ((cont = (AliAnalysisDataContainer*)next())) cont->SetTouched(kFALSE);
+   TIter nextt(fTasks);
    AliAnalysisTask *task;
-   while ((task=(AliAnalysisTask*)next()))
-      task->PrintTask(option);
+   while ((task=(AliAnalysisTask*)nextt()))
+      task->SetActive(kFALSE);
   
    if (!fAutoBranchHandling && !fRequestedBranches.IsNull()) 
       printf("Requested input branches:\n%s\n", fRequestedBranches.Data());
@@ -1708,7 +1740,13 @@ void AliAnalysisManager::PrintStatus(Option_t *option) const
 void AliAnalysisManager::ResetAnalysis()
 {
 // Reset all execution flags and clean containers.
-   CleanContainers();
+   TIter nextTask(fTasks);
+   AliAnalysisTask *task;
+   while ((task=(AliAnalysisTask*)nextTask())) {
+      // Clean all tasks
+      task->Reset();
+   }         
+//   CleanContainers();
 }
 
 //______________________________________________________________________________
@@ -2236,13 +2274,15 @@ void AliAnalysisManager::ExecAnalysis(Option_t *option)
    }
    fNcalls++;
    AliAnalysisTask *task;
+   // Reset the analysis
+   ResetAnalysis();
    // Check if the top tree is active.
    if (fTree) {
       if (getsysInfo && ((fNcalls%fNSysInfo)==0)) 
          AliSysInfo::AddStamp("Handlers_BeginEventGroup",fNcalls, 1002, 0);
       TIter next(fTasks);
-   // De-activate all tasks
-      while ((task=(AliAnalysisTask*)next())) task->SetActive(kFALSE);
+   // De-activate all tasks (not needed anymore after ResetAnalysis
+//      while ((task=(AliAnalysisTask*)next())) task->SetActive(kFALSE);
       AliAnalysisDataContainer *cont = fCommonInput;
       if (!cont) cont = (AliAnalysisDataContainer*)fInputs->At(0);
       if (!cont) {
@@ -2250,8 +2290,8 @@ void AliAnalysisManager::ExecAnalysis(Option_t *option)
          if (cdir) cdir->cd();
          return;
       }   
-      cont->SetData(fTree); // This will notify all consumers
-      Long64_t entry = fTree->GetTree()->GetReadEntry();      
+      cont->SetData(fTree); // This set activity for all tasks reading only from the top container
+      Long64_t entry = fTree->GetTree()->GetReadEntry();
 //
 //    Call BeginEvent() for optional input/output and MC services 
       if (fInputEventHandler)   fInputEventHandler  ->BeginEvent(entry);
@@ -2269,7 +2309,8 @@ void AliAnalysisManager::ExecAnalysis(Option_t *option)
       TIter next1(fTopTasks);
       Int_t itask = 0;
       while ((task=(AliAnalysisTask*)next1())) {
-         if (fDebug >1) {
+         task->SetActive(kTRUE);
+         if (fDebug >1) {
             cout << "    Executing task " << task->GetName() << endl;
          }
          if (fStatistics) fStatistics->StartTimer(GetTaskIndex(task), task->GetName(), task->ClassName());
@@ -2845,7 +2886,7 @@ void AliAnalysisManager::ApplyDebugOptions()
 }
 
 //______________________________________________________________________________
-Bool_t AliAnalysisManager::IsMacroLoaded(const char filename)
+Bool_t AliAnalysisManager::IsMacroLoaded(const char filename)
 {
 // Check if a macro was loaded.
    return fgMacroNames.Contains(filename);
@@ -2907,3 +2948,26 @@ void AliAnalysisManager::Changed()
 // in case the lock was set.
    if (fLocked) Fatal("Changed","Critical setter called in locked mode");
 }
+
+//______________________________________________________________________________
+void AliAnalysisManager::InitInputData(AliVEvent* esdEvent, AliESDfriend* esdFriend)
+{
+
+// Method to propagte to all the connected tasks the HLT event.
+// This method expects that the input hanlder is of type HLT, should 
+// not be used otherwise
+
+  if (fInputEventHandler)  {
+    TString classInputHandler = fInputEventHandler->ClassName();
+    if (classInputHandler.Contains("HLT")){
+      TObjArray* arrTasks = GetTasks();
+      fInputEventHandler->InitTaskInputData(esdEvent, esdFriend, arrTasks);
+    }
+    else {
+      Fatal("PropagateHLTEvent", "Input Handler not of type HLT, we cannot use this method!");
+    }
+  }
+  else {
+    Fatal("PropagateHLTEvent", "Input Handler not found, we cannot use this method!");
+  }
+}