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)
90 AliAnalysisTask::operator=(other);
91 fDebug = other.fDebug;
92 fEntry = other.fEntry;
93 fFreshBufferOnly = other.fFreshBufferOnly;
94 fInputHandler = other.fInputHandler;
95 fOutputAOD = other.fOutputAOD;
96 fTreeA = other.fTreeA;
97 fOfflineTriggerMask = other.fOfflineTriggerMask;
102 void AliAnalysisTaskME::ConnectInputData(Option_t* /*option*/)
104 // Connect the input data
105 if (fDebug > 1) printf("AnalysisTaskME::ConnectInputData() \n");
109 fInputHandler = dynamic_cast<AliMultiEventInputHandler*>
110 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
111 if (fInputHandler == 0) {
112 AliFatal("Event Handler has to be MultiEventInputHandler !");
114 // Check that we have an event pool
115 if (!fInputHandler->GetEventPool()) {
116 fInputHandler->SetEventPool(AliAnalysisManager::GetAnalysisManager()->GetEventPool());
117 if (!fInputHandler->GetEventPool())
118 AliFatal("MultiEventInputHandler has no EventPool connected !");
123 void AliAnalysisTaskME::CreateOutputObjects()
125 // Create the output container
128 if (fDebug > 1) printf("AnalysisTaskME::CreateOutPutData() \n");
130 AliAODHandler* handler = (AliAODHandler*)
131 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
134 fOutputAOD = handler->GetAOD();
135 fTreeA = handler->GetTree();
137 AliWarning("No AOD Event Handler connected.") ;
139 UserCreateOutputObjects();
142 void AliAnalysisTaskME::Exec(Option_t* option)
145 // Exec analysis of one event
147 if (fDebug > 1) AliInfo("AliAnalysisTaskME::Exec() \n");
149 fEntry = fInputHandler->GetReadEntry();
150 if ( !((Entry()-1)%100) && fDebug > 0)
151 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
153 AliAODHandler* outputHandler = (AliAODHandler*)
154 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
156 // Was event selected ? If no event selection mechanism, the event SHOULD be selected (AG)
157 UInt_t isSelected = AliVEvent::kAny;
158 if(fInputHandler && fInputHandler->GetEventSelection()) {
159 // Get the actual offline trigger mask for the event and AND it with the
160 // requested mask. If no mask requested select by default the event.
161 if (fOfflineTriggerMask)
162 isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
166 if (fDebug > 1) AliInfo("Event rejected \n");
167 fInputHandler->EventSkipped();
170 // Call the user analysis
172 if (fInputHandler && fInputHandler->IsBufferReady()) {
173 if ((fFreshBufferOnly && fInputHandler->IsFreshBuffer()) || !fFreshBufferOnly)
175 if (outputHandler) outputHandler->SetFillAOD(kTRUE);
177 // Added protection in case the derived task is not an AOD producer.
178 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
179 if (out0 && out0->IsConnected()) PostData(0, fTreeA);
181 if (outputHandler) outputHandler->SetFillAOD(kFALSE);
184 AliInfo(Form("Waiting for buffer to be ready !\n"));
188 const char* AliAnalysisTaskME::CurrentFileName()
190 // Returns the current file name
192 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
196 void AliAnalysisTaskME::AddAODBranch(const char* cname, void* addobj, const char *fname)
198 // Add a new branch to the aod tree
199 AliAODHandler* handler = (AliAODHandler*)
200 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
202 handler->AddBranch(cname, addobj, fname);
206 AliVEvent* AliAnalysisTaskME::GetEvent(Int_t iev)
208 // Get an event from the input handler
209 return (fInputHandler->GetEvent(iev));