]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliAnalysisTaskME.cxx
T0 ESD convert:only time from triggered interaction used for T0 raw vertex calculations
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskME.cxx
index 5371f7482fb3524e97d016ba6a8b7c6d09567156..6900da35b982c8d917a05f235d978173b20ef6cb 100644 (file)
 
 #include "AliAnalysisTaskME.h"
 #include "AliAnalysisManager.h"
+#include "AliAnalysisDataSlot.h"
 #include "AliAODEvent.h"
+#include "AliVEvent.h"
 #include "AliAODHandler.h"
-#include "AliMultiAODInputHandler.h"
+#include "AliMultiEventInputHandler.h"
 #include "AliLog.h"
 
 
@@ -41,7 +43,8 @@ AliAnalysisTaskME::AliAnalysisTaskME():
     fFreshBufferOnly(kFALSE),
     fInputHandler(0x0),
     fOutputAOD(0x0),
-    fTreeA(0x0)
+    fTreeA(0x0),
+    fOfflineTriggerMask(0)
 {
   // Default constructor
 }
@@ -53,7 +56,8 @@ AliAnalysisTaskME::AliAnalysisTaskME(const char* name):
     fFreshBufferOnly(kFALSE),
     fInputHandler(0x0),
     fOutputAOD(0x0),
-    fTreeA(0x0)
+    fTreeA(0x0),
+    fOfflineTriggerMask(0)
 {
   // Default constructor
     DefineInput (0, TChain::Class());
@@ -67,27 +71,32 @@ AliAnalysisTaskME::AliAnalysisTaskME(const AliAnalysisTaskME& obj):
     fFreshBufferOnly(kFALSE),
     fInputHandler(0x0),
     fOutputAOD(0x0),
-    fTreeA(0x0)
+    fTreeA(0x0),
+    fOfflineTriggerMask(0)
 {
 // Copy constructor
     fDebug        = obj.fDebug;
     fEntry        = obj.fEntry;
     fInputHandler = obj.fInputHandler;
     fOutputAOD    = obj.fOutputAOD;
-    fTreeA        = obj.fTreeA;    
+    fTreeA        = obj.fTreeA; 
+    fOfflineTriggerMask = obj.fOfflineTriggerMask;
 }
 
 
 AliAnalysisTaskME& AliAnalysisTaskME::operator=(const AliAnalysisTaskME& other)
 {
 // Assignment
-    AliAnalysisTask::operator=(other);
-    fDebug           = other.fDebug;
-    fEntry           = other.fEntry;
-    fFreshBufferOnly = other.fFreshBufferOnly;
-    fInputHandler    = other.fInputHandler;
-    fOutputAOD       = other.fOutputAOD;
-    fTreeA           = other.fTreeA;    
+    if (this != &other) {
+       AliAnalysisTask::operator=(other);
+       fDebug           = other.fDebug;
+       fEntry           = other.fEntry;
+       fFreshBufferOnly = other.fFreshBufferOnly;
+       fInputHandler    = other.fInputHandler;
+       fOutputAOD       = other.fOutputAOD;
+       fTreeA           = other.fTreeA;    
+       fOfflineTriggerMask = other.fOfflineTriggerMask;
+    }
     return *this;
 }
 
@@ -99,10 +108,18 @@ void AliAnalysisTaskME::ConnectInputData(Option_t* /*option*/)
 //
 //  Multi AOD
 //
-    fInputHandler = dynamic_cast<AliMultiAODInputHandler*> 
+    fInputHandler = dynamic_cast<AliMultiEventInputHandler*> 
        ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
-    if (fInputHandler == 0) 
-       AliFatal("Event Handler has to be MultiAODHandler !");
+    if (fInputHandler == 0) {
+       AliFatal("Event Handler has to be MultiEventInputHandler !");
+    } else {
+       // Check that we have an event pool
+       if (!fInputHandler->GetEventPool()) {
+           fInputHandler->SetEventPool(AliAnalysisManager::GetAnalysisManager()->GetEventPool());
+           if (!fInputHandler->GetEventPool()) 
+               AliFatal("MultiEventInputHandler has no EventPool connected !");
+       }
+    }
 }
 
 void AliAnalysisTaskME::CreateOutputObjects()
@@ -134,13 +151,36 @@ void AliAnalysisTaskME::Exec(Option_t* option)
        fEntry = fInputHandler->GetReadEntry();
     if ( !((Entry()-1)%100) && fDebug > 0) 
          AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
-         
+
+    AliAODHandler* outputHandler = (AliAODHandler*) 
+       ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());         
+//
+// Was event selected ? If no event selection mechanism, the event SHOULD be selected (AG)
+    UInt_t isSelected = AliVEvent::kAny;
+    if(fInputHandler && fInputHandler->GetEventSelection()) {
+      // Get the actual offline trigger mask for the event and AND it with the
+      // requested mask. If no mask requested select by default the event.
+      if (fOfflineTriggerMask)
+       isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
+    }
+    
+    if (!isSelected) { 
+       if (fDebug > 1) AliInfo("Event rejected \n");
+       fInputHandler->EventSkipped();
+       return;
+    }
 // Call the user analysis    
-    if (fInputHandler->IsBufferReady()) {
+    
+    if (fInputHandler && fInputHandler->IsBufferReady()) {
        if ((fFreshBufferOnly && fInputHandler->IsFreshBuffer()) || !fFreshBufferOnly)
        {
+           if (outputHandler) outputHandler->SetFillAOD(kTRUE);
            UserExec(option);
-           PostData(0, fTreeA);
+           // Added protection in case the derived task is not an AOD producer.
+           AliAnalysisDataSlot *out0 = GetOutputSlot(0);
+           if (out0 && out0->IsConnected()) PostData(0, fTreeA);
+       } else {
+           if (outputHandler) outputHandler->SetFillAOD(kFALSE);
        }
     } else {
        AliInfo(Form("Waiting for buffer to be ready !\n"));
@@ -155,17 +195,17 @@ const char* AliAnalysisTaskME::CurrentFileName()
     else return "";
 }
 
-void AliAnalysisTaskME::AddAODBranch(const char* cname, void* addobj)
+void AliAnalysisTaskME::AddAODBranch(const char* cname, void* addobj, const char *fname)
 {
     // Add a new branch to the aod tree
     AliAODHandler* handler = (AliAODHandler*) 
        ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
     if (handler) {
-       handler->AddBranch(cname, addobj);
+       handler->AddBranch(cname, addobj, fname);
     }
 }
 
-AliAODEvent*  AliAnalysisTaskME::GetEvent(Int_t iev)
+AliVEvent*  AliAnalysisTaskME::GetEvent(Int_t iev)
 {
     // Get an event from the input handler
     return (fInputHandler->GetEvent(iev));