1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
20 #include <TInterpreter.h>
25 #include "AliAnalysisTaskME.h"
26 #include "AliAnalysisManager.h"
27 #include "AliAnalysisDataSlot.h"
28 #include "AliAODEvent.h"
29 #include "AliVEvent.h"
30 #include "AliAODHandler.h"
31 #include "AliMultiEventInputHandler.h"
35 ClassImp(AliAnalysisTaskME)
37 ////////////////////////////////////////////////////////////////////////
39 AliAnalysisTaskME::AliAnalysisTaskME():
43 fFreshBufferOnly(kFALSE),
47 fOfflineTriggerMask(0)
49 // Default constructor
52 AliAnalysisTaskME::AliAnalysisTaskME(const char* name):
53 AliAnalysisTask(name, "AnalysisTaskME"),
56 fFreshBufferOnly(kFALSE),
60 fOfflineTriggerMask(0)
62 // Default constructor
63 DefineInput (0, TChain::Class());
64 DefineOutput(0, TTree::Class());
67 AliAnalysisTaskME::AliAnalysisTaskME(const AliAnalysisTaskME& obj):
71 fFreshBufferOnly(kFALSE),
75 fOfflineTriggerMask(0)
80 fInputHandler = obj.fInputHandler;
81 fOutputAOD = obj.fOutputAOD;
83 fOfflineTriggerMask = obj.fOfflineTriggerMask;
87 AliAnalysisTaskME& AliAnalysisTaskME::operator=(const AliAnalysisTaskME& other)
91 AliAnalysisTask::operator=(other);
92 fDebug = other.fDebug;
93 fEntry = other.fEntry;
94 fFreshBufferOnly = other.fFreshBufferOnly;
95 fInputHandler = other.fInputHandler;
96 fOutputAOD = other.fOutputAOD;
97 fTreeA = other.fTreeA;
98 fOfflineTriggerMask = other.fOfflineTriggerMask;
104 void AliAnalysisTaskME::ConnectInputData(Option_t* /*option*/)
106 // Connect the input data
107 if (fDebug > 1) printf("AnalysisTaskME::ConnectInputData() \n");
111 fInputHandler = dynamic_cast<AliMultiEventInputHandler*>
112 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
113 if (fInputHandler == 0) {
114 AliFatal("Event Handler has to be MultiEventInputHandler !");
116 // Check that we have an event pool
117 if (!fInputHandler->GetEventPool()) {
118 fInputHandler->SetEventPool(AliAnalysisManager::GetAnalysisManager()->GetEventPool());
119 if (!fInputHandler->GetEventPool())
120 AliFatal("MultiEventInputHandler has no EventPool connected !");
125 void AliAnalysisTaskME::CreateOutputObjects()
127 // Create the output container
130 if (fDebug > 1) printf("AnalysisTaskME::CreateOutPutData() \n");
132 AliAODHandler* handler = (AliAODHandler*)
133 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
136 fOutputAOD = handler->GetAOD();
137 fTreeA = handler->GetTree();
139 AliWarning("No AOD Event Handler connected.") ;
141 UserCreateOutputObjects();
144 void AliAnalysisTaskME::Exec(Option_t* option)
147 // Exec analysis of one event
149 if (fDebug > 1) AliInfo("AliAnalysisTaskME::Exec() \n");
151 fEntry = fInputHandler->GetReadEntry();
152 if ( !((Entry()-1)%100) && fDebug > 0)
153 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
155 AliAODHandler* outputHandler = (AliAODHandler*)
156 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
158 // Was event selected ? If no event selection mechanism, the event SHOULD be selected (AG)
159 UInt_t isSelected = AliVEvent::kAny;
160 if(fInputHandler && fInputHandler->GetEventSelection()) {
161 // Get the actual offline trigger mask for the event and AND it with the
162 // requested mask. If no mask requested select by default the event.
163 if (fOfflineTriggerMask)
164 isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
168 if (fDebug > 1) AliInfo("Event rejected \n");
169 fInputHandler->EventSkipped();
172 // Call the user analysis
174 if (fInputHandler && fInputHandler->IsBufferReady()) {
175 if ((fFreshBufferOnly && fInputHandler->IsFreshBuffer()) || !fFreshBufferOnly)
177 if (outputHandler) outputHandler->SetFillAOD(kTRUE);
179 // Added protection in case the derived task is not an AOD producer.
180 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
181 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
183 if (outputHandler) outputHandler->SetFillAOD(kFALSE);
186 AliInfo(Form("Waiting for buffer to be ready !\n"));
190 const char* AliAnalysisTaskME::CurrentFileName()
192 // Returns the current file name
194 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
198 void AliAnalysisTaskME::AddAODBranch(const char* cname, void* addobj, const char *fname)
200 // Add a new branch to the aod tree
201 AliAODHandler* handler = (AliAODHandler*)
202 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
204 handler->AddBranch(cname, addobj, fname);
208 AliVEvent* AliAnalysisTaskME::GetEvent(Int_t iev)
210 // Get an event from the input handler
211 return (fInputHandler->GetEvent(iev));