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),
47 // Default constructor
50 AliAnalysisTaskME::AliAnalysisTaskME(const char* name):
51 AliAnalysisTask(name, "AnalysisTaskME"),
54 fFreshBufferOnly(kFALSE),
59 // Default constructor
60 DefineInput (0, TChain::Class());
61 DefineOutput(0, TTree::Class());
64 AliAnalysisTaskME::AliAnalysisTaskME(const AliAnalysisTaskME& obj):
68 fFreshBufferOnly(kFALSE),
76 fInputHandler = obj.fInputHandler;
77 fOutputAOD = obj.fOutputAOD;
82 AliAnalysisTaskME& AliAnalysisTaskME::operator=(const AliAnalysisTaskME& other)
85 AliAnalysisTask::operator=(other);
86 fDebug = other.fDebug;
87 fEntry = other.fEntry;
88 fFreshBufferOnly = other.fFreshBufferOnly;
89 fInputHandler = other.fInputHandler;
90 fOutputAOD = other.fOutputAOD;
91 fTreeA = other.fTreeA;
96 void AliAnalysisTaskME::ConnectInputData(Option_t* /*option*/)
98 // Connect the input data
99 if (fDebug > 1) printf("AnalysisTaskME::ConnectInputData() \n");
103 fInputHandler = dynamic_cast<AliMultiEventInputHandler*>
104 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
105 if (fInputHandler == 0) {
106 AliFatal("Event Handler has to be MultiEventInputHandler !");
108 // Check that we have an event pool
109 if (!fInputHandler->GetEventPool()) {
110 fInputHandler->SetEventPool(AliAnalysisManager::GetAnalysisManager()->GetEventPool());
111 if (!fInputHandler->GetEventPool())
112 AliFatal("MultiEventInputHandler has no EventPool connected !");
117 void AliAnalysisTaskME::CreateOutputObjects()
119 // Create the output container
122 if (fDebug > 1) printf("AnalysisTaskME::CreateOutPutData() \n");
124 AliAODHandler* handler = (AliAODHandler*)
125 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
128 fOutputAOD = handler->GetAOD();
129 fTreeA = handler->GetTree();
131 AliWarning("No AOD Event Handler connected.") ;
133 UserCreateOutputObjects();
136 void AliAnalysisTaskME::Exec(Option_t* option)
139 // Exec analysis of one event
141 if (fDebug > 1) AliInfo("AliAnalysisTaskME::Exec() \n");
143 fEntry = fInputHandler->GetReadEntry();
144 if ( !((Entry()-1)%100) && fDebug > 0)
145 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
147 AliAODHandler* outputHandler = (AliAODHandler*)
148 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
149 // Call the user analysis
150 if (fInputHandler->IsBufferReady()) {
151 if ((fFreshBufferOnly && fInputHandler->IsFreshBuffer()) || !fFreshBufferOnly)
153 if (outputHandler) outputHandler->SetFillAOD(kTRUE);
157 if (outputHandler) outputHandler->SetFillAOD(kFALSE);
160 AliInfo(Form("Waiting for buffer to be ready !\n"));
164 const char* AliAnalysisTaskME::CurrentFileName()
166 // Returns the current file name
168 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
172 void AliAnalysisTaskME::AddAODBranch(const char* cname, void* addobj)
174 // Add a new branch to the aod tree
175 AliAODHandler* handler = (AliAODHandler*)
176 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
178 handler->AddBranch(cname, addobj);
182 AliVEvent* AliAnalysisTaskME::GetEvent(Int_t iev)
184 // Get an event from the input handler
185 return (fInputHandler->GetEvent(iev));