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 "AliAODEvent.h"
28 #include "AliVEvent.h"
29 #include "AliAODHandler.h"
30 #include "AliMultiEventInputHandler.h"
34 ClassImp(AliAnalysisTaskME);
36 ////////////////////////////////////////////////////////////////////////
38 AliAnalysisTaskME::AliAnalysisTaskME():
42 fFreshBufferOnly(kFALSE),
46 fOfflineTriggerMask(0)
48 // Default constructor
51 AliAnalysisTaskME::AliAnalysisTaskME(const char* name):
52 AliAnalysisTask(name, "AnalysisTaskME"),
55 fFreshBufferOnly(kFALSE),
59 fOfflineTriggerMask(0)
61 // Default constructor
62 DefineInput (0, TChain::Class());
63 DefineOutput(0, TTree::Class());
66 AliAnalysisTaskME::AliAnalysisTaskME(const AliAnalysisTaskME& obj):
70 fFreshBufferOnly(kFALSE),
74 fOfflineTriggerMask(0)
79 fInputHandler = obj.fInputHandler;
80 fOutputAOD = obj.fOutputAOD;
82 fOfflineTriggerMask = obj.fOfflineTriggerMask;
86 AliAnalysisTaskME& AliAnalysisTaskME::operator=(const AliAnalysisTaskME& other)
89 AliAnalysisTask::operator=(other);
90 fDebug = other.fDebug;
91 fEntry = other.fEntry;
92 fFreshBufferOnly = other.fFreshBufferOnly;
93 fInputHandler = other.fInputHandler;
94 fOutputAOD = other.fOutputAOD;
95 fTreeA = other.fTreeA;
96 fOfflineTriggerMask = other.fOfflineTriggerMask;
101 void AliAnalysisTaskME::ConnectInputData(Option_t* /*option*/)
103 // Connect the input data
104 if (fDebug > 1) printf("AnalysisTaskME::ConnectInputData() \n");
108 fInputHandler = dynamic_cast<AliMultiEventInputHandler*>
109 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
110 if (fInputHandler == 0) {
111 AliFatal("Event Handler has to be MultiEventInputHandler !");
113 // Check that we have an event pool
114 if (!fInputHandler->GetEventPool()) {
115 fInputHandler->SetEventPool(AliAnalysisManager::GetAnalysisManager()->GetEventPool());
116 if (!fInputHandler->GetEventPool())
117 AliFatal("MultiEventInputHandler has no EventPool connected !");
122 void AliAnalysisTaskME::CreateOutputObjects()
124 // Create the output container
127 if (fDebug > 1) printf("AnalysisTaskME::CreateOutPutData() \n");
129 AliAODHandler* handler = (AliAODHandler*)
130 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
133 fOutputAOD = handler->GetAOD();
134 fTreeA = handler->GetTree();
136 AliWarning("No AOD Event Handler connected.") ;
138 UserCreateOutputObjects();
141 void AliAnalysisTaskME::Exec(Option_t* option)
144 // Exec analysis of one event
146 if (fDebug > 1) AliInfo("AliAnalysisTaskME::Exec() \n");
148 fEntry = fInputHandler->GetReadEntry();
149 if ( !((Entry()-1)%100) && fDebug > 0)
150 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
152 AliAODHandler* outputHandler = (AliAODHandler*)
153 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
155 // Was event selected ? If no event selection mechanism, the event SHOULD be selected (AG)
156 UInt_t isSelected = AliVEvent::kAny;
157 if( fInputHandler && fInputHandler->GetEventSelection()) {
158 // Get the actual offline trigger mask for the event and AND it with the
159 // requested mask. If no mask requested select by default the event.
160 if (fOfflineTriggerMask)
161 isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
164 if (fDebug > 1) AliInfo("Event rejected \n");
165 fInputHandler->EventSkipped();
168 // Call the user analysis
170 if (fInputHandler->IsBufferReady()) {
171 if ((fFreshBufferOnly && fInputHandler->IsFreshBuffer()) || !fFreshBufferOnly)
173 if (outputHandler) outputHandler->SetFillAOD(kTRUE);
177 if (outputHandler) outputHandler->SetFillAOD(kFALSE);
180 AliInfo(Form("Waiting for buffer to be ready !\n"));
184 const char* AliAnalysisTaskME::CurrentFileName()
186 // Returns the current file name
188 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
192 void AliAnalysisTaskME::AddAODBranch(const char* cname, void* addobj, const char *fname)
194 // Add a new branch to the aod tree
195 AliAODHandler* handler = (AliAODHandler*)
196 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
198 handler->AddBranch(cname, addobj, fname);
202 AliVEvent* AliAnalysisTaskME::GetEvent(Int_t iev)
204 // Get an event from the input handler
205 return (fInputHandler->GetEvent(iev));