Optional common MC Truth Service added.
authormorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 6 Aug 2007 17:23:06 +0000 (17:23 +0000)
committermorsch <morsch@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 6 Aug 2007 17:23:06 +0000 (17:23 +0000)
ANALYSIS/AliAnalysisManager.cxx
ANALYSIS/AliAnalysisManager.h

index 7762575..ce70632 100644 (file)
@@ -48,10 +48,12 @@ AliAnalysisManager *AliAnalysisManager::fgAnalysisManager = NULL;
 AliAnalysisManager::AliAnalysisManager() 
                    :TNamed(),
                     fTree(NULL),
-                   fEventHandler(NULL),
+                   fOutputEventHandler(NULL),
+                   fMCtruthEventHandler(NULL),
                     fCurrentEntry(-1),
                     fMode(kLocalAnalysis),
                     fInitOK(kFALSE),
+                    fDebug(0),
                     fTasks(NULL),
                     fTopTasks(NULL),
                     fZombies(NULL),
@@ -68,7 +70,8 @@ AliAnalysisManager::AliAnalysisManager()
 AliAnalysisManager::AliAnalysisManager(const char *name, const char *title)
                    :TNamed(name,title),
                     fTree(NULL),
-                   fEventHandler(NULL),
+                   fOutputEventHandler(NULL),
+                   fMCtruthEventHandler(NULL),
                     fCurrentEntry(-1),
                     fMode(kLocalAnalysis),
                     fInitOK(kFALSE),
@@ -95,7 +98,8 @@ AliAnalysisManager::AliAnalysisManager(const char *name, const char *title)
 AliAnalysisManager::AliAnalysisManager(const AliAnalysisManager& other)
                    :TNamed(other),
                     fTree(NULL),
-                   fEventHandler(NULL),
+                   fOutputEventHandler(NULL),
+                   fMCtruthEventHandler(NULL),
                     fCurrentEntry(-1),
                     fMode(other.fMode),
                     fInitOK(other.fInitOK),
@@ -123,8 +127,9 @@ AliAnalysisManager& AliAnalysisManager::operator=(const AliAnalysisManager& othe
 // Assignment
    if (&other != this) {
       TNamed::operator=(other);
+      fOutputEventHandler  = other.fOutputEventHandler;
+      fMCtruthEventHandler = other.fMCtruthEventHandler;
       fTree       = NULL;
-      fEventHandler = other.fEventHandler;
       fCurrentEntry = -1;
       fMode       = other.fMode;
       fInitOK     = other.fInitOK;
@@ -212,15 +217,13 @@ void AliAnalysisManager::SlaveBegin(TTree *tree)
       cout << "->AliAnalysisManager::SlaveBegin()" << endl;
    }
    // Call InitIO of EventHandler
-   if (fEventHandler) {
+   if (fOutputEventHandler) {
        if (fMode == kProofAnalysis) {
-          fEventHandler->InitIO("proof");
+          fOutputEventHandler->InitIO("proof");
        } else {
-          fEventHandler->InitIO("local");
+          fOutputEventHandler->InitIO("local");
        }
    }
-   
-
    //
    TIter next(fTasks);
    AliAnalysisTask *task;
@@ -251,7 +254,9 @@ Bool_t AliAnalysisManager::Notify()
       AliAnalysisTask *task;
       // Call Notify for all tasks
       while ((task=(AliAnalysisTask*)next())) 
-         task->Notify();      
+         task->Notify();
+      // Call Notify of the MC truth handler
+      if (fMCtruthEventHandler) fMCtruthEventHandler->Notify();
    }
    return kTRUE;
 }    
@@ -279,6 +284,10 @@ Bool_t AliAnalysisManager::Process(Long64_t entry)
    if (fDebug > 1) {
       cout << "->AliAnalysisManager::Process()" << endl;
    }
+
+   if (fOutputEventHandler)  fOutputEventHandler ->BeginEvent();
+   if (fMCtruthEventHandler) fMCtruthEventHandler->BeginEvent();
+   
    GetEntry(entry);
    ExecAnalysis();
    if (fDebug > 1) {
@@ -300,7 +309,8 @@ void AliAnalysisManager::PackOutput(TList *target)
       return;
    }
 
-   if (fEventHandler) fEventHandler->Terminate();
+   if (fOutputEventHandler)  fOutputEventHandler ->Terminate();
+   if (fMCtruthEventHandler) fMCtruthEventHandler->Terminate();
    
    if (fMode == kProofAnalysis) {
       TIter next(fOutputs);
@@ -385,7 +395,7 @@ void AliAnalysisManager::UnpackOutput(TList *source)
       // Check if the output need to be written to a file.
       const char *filename = output->GetFileName();
       if (!(strcmp(filename, "default"))) {
-         if (fEventHandler) filename = fEventHandler->GetOutputFileName();
+         if (fOutputEventHandler) filename = fOutputEventHandler->GetOutputFileName();
       }
       
       if (!filename || !strlen(filename)) continue;
@@ -425,7 +435,7 @@ void AliAnalysisManager::Terminate()
       cout << "<-AliAnalysisManager::Terminate()" << endl;
    }   
    //
-   if (fEventHandler) fEventHandler->TerminateIO();
+   if (fOutputEventHandler) fOutputEventHandler->TerminateIO();
 }
 
 //______________________________________________________________________________
@@ -730,18 +740,32 @@ void AliAnalysisManager::ExecAnalysis(Option_t *option)
          return;
       }   
       cont->SetData(fTree); // This will notify all consumers
+//
+//    Call BeginEvent() for optional output and MC services 
+      if (fOutputEventHandler)  fOutputEventHandler ->BeginEvent();
+      if (fMCtruthEventHandler) fMCtruthEventHandler->BeginEvent();
+//
+//    Execute the tasks
       TIter next1(cont->GetConsumers());
       while ((task=(AliAnalysisTask*)next1())) {
-//         task->SetActive(kTRUE);
          if (fDebug >1) {
             cout << "    Executing task " << task->GetName() << endl;
          }   
+        
          task->ExecuteTask(option);
       }
-      if (fEventHandler) fEventHandler->FinishEvent();
+//
+//    Call FinishEvent() for optional output and MC services 
+      if (fOutputEventHandler)  fOutputEventHandler ->FinishEvent();
+      if (fMCtruthEventHandler) fMCtruthEventHandler->FinishEvent();
+//
       return;
    }   
    // The event loop is not controlled by TSelector   
+//
+//  Call BeginEvent() for optional output and MC services 
+   if (fOutputEventHandler)  fOutputEventHandler ->BeginEvent();
+   if (fMCtruthEventHandler) fMCtruthEventHandler->BeginEvent();
    TIter next2(fTopTasks);
    while ((task=(AliAnalysisTask*)next2())) {
       task->SetActive(kTRUE);
@@ -750,7 +774,10 @@ void AliAnalysisManager::ExecAnalysis(Option_t *option)
       }   
       task->ExecuteTask(option);
    }   
-   if (fEventHandler) fEventHandler->FinishEvent();
+//
+// Call FinishEvent() for optional output and MC services 
+   if (fOutputEventHandler)  fOutputEventHandler->FinishEvent();
+   if (fMCtruthEventHandler) fMCtruthEventHandler->FinishEvent();
 }
 
 //______________________________________________________________________________
index ef553d4..2d982c7 100644 (file)
@@ -83,9 +83,12 @@ enum EAliAnalysisFlags {
    void                SetCurrentEntry(Long64_t entry) {fCurrentEntry = entry;}
    void                SetDebugLevel(UInt_t level) {fDebug = level;}
    void                SetDisableBranches(Bool_t disable=kTRUE) {TObject::SetBit(kDisableBranches,disable);}
-   void                SetEventHandler(AliVirtualEventHandler* handler) {fEventHandler = handler;}
+   void                SetOutputEventHandler(AliVirtualEventHandler*  handler) {fOutputEventHandler  = handler;}
+   void                SetMCtruthEventHandler(AliVirtualEventHandler* handler) {fMCtruthEventHandler = handler;}
    AliVirtualEventHandler*
-                       GetEventHandler() {return fEventHandler;}
+       GetOutputEventHandler()  {return fOutputEventHandler;}
+   AliVirtualEventHandler*
+       GetMCtruthEventHandler() {return fMCtruthEventHandler;}
 
    // Container handling
    AliAnalysisDataContainer *CreateContainer(const char *name, TClass *datatype, 
@@ -118,18 +121,19 @@ protected:
    void                 SetEventLoop(Bool_t flag=kTRUE) {TObject::SetBit(kEventLoop,flag);}
 
 private:
-   TTree                  *fTree;         //! Input tree in case of TSelector model
-   AliVirtualEventHandler *fEventHandler; //  Output event handler
-   Long64_t                fCurrentEntry; //! Current processed entry in the tree
-   EAliAnalysisExecMode    fMode;         // Execution mode
-   Bool_t                  fInitOK;       // Initialisation done
-   UInt_t                  fDebug;        // Debug level
-   TObjArray              *fTasks;        // List of analysis tasks
-   TObjArray              *fTopTasks;     // List of top tasks
-   TObjArray              *fZombies;      // List of zombie tasks
-   TObjArray              *fContainers;   // List of all containers
-   TObjArray              *fInputs;       // List of containers with input data
-   TObjArray              *fOutputs;      // List of containers with results
+   TTree                  *fTree;                //! Input tree in case of TSelector model
+   AliVirtualEventHandler *fOutputEventHandler;  //  Optional common output event handler
+   AliVirtualEventHandler *fMCtruthEventHandler; //  Optional common MC Truth event handler
+   Long64_t                fCurrentEntry;        //! Current processed entry in the tree
+   EAliAnalysisExecMode    fMode;                // Execution mode
+   Bool_t                  fInitOK;              // Initialisation done
+   UInt_t                  fDebug;               // Debug level
+   TObjArray              *fTasks;               // List of analysis tasks
+   TObjArray              *fTopTasks;            // List of top tasks
+   TObjArray              *fZombies;             // List of zombie tasks
+   TObjArray              *fContainers;          // List of all containers
+   TObjArray              *fInputs;              // List of containers with input data
+   TObjArray              *fOutputs;             // List of containers with results
 
    static AliAnalysisManager *fgAnalysisManager; //! static pointer to object instance
    ClassDef(AliAnalysisManager,1)  // Analysis manager class