Merge branch 'master', remote branch 'origin' into TPCdev
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskME.cxx
CommitLineData
b81460ad 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18#include <TROOT.h>
19#include <TSystem.h>
20#include <TInterpreter.h>
21#include <TChain.h>
22#include <TFile.h>
23#include <TList.h>
24
25#include "AliAnalysisTaskME.h"
26#include "AliAnalysisManager.h"
79478008 27#include "AliAnalysisDataSlot.h"
b81460ad 28#include "AliAODEvent.h"
cd17c2ba 29#include "AliVEvent.h"
b81460ad 30#include "AliAODHandler.h"
cd17c2ba 31#include "AliMultiEventInputHandler.h"
b81460ad 32#include "AliLog.h"
33
34
df8176e9 35ClassImp(AliAnalysisTaskME)
b81460ad 36
37////////////////////////////////////////////////////////////////////////
38
39AliAnalysisTaskME::AliAnalysisTaskME():
40 AliAnalysisTask(),
41 fDebug(0),
42 fEntry(0),
43 fFreshBufferOnly(kFALSE),
44 fInputHandler(0x0),
45 fOutputAOD(0x0),
3c329509 46 fTreeA(0x0),
47 fOfflineTriggerMask(0)
b81460ad 48{
49 // Default constructor
50}
51
52AliAnalysisTaskME::AliAnalysisTaskME(const char* name):
53 AliAnalysisTask(name, "AnalysisTaskME"),
54 fDebug(0),
55 fEntry(0),
56 fFreshBufferOnly(kFALSE),
57 fInputHandler(0x0),
58 fOutputAOD(0x0),
3c329509 59 fTreeA(0x0),
60 fOfflineTriggerMask(0)
b81460ad 61{
62 // Default constructor
63 DefineInput (0, TChain::Class());
64 DefineOutput(0, TTree::Class());
65}
66
67AliAnalysisTaskME::AliAnalysisTaskME(const AliAnalysisTaskME& obj):
68 AliAnalysisTask(obj),
69 fDebug(0),
70 fEntry(0),
71 fFreshBufferOnly(kFALSE),
72 fInputHandler(0x0),
73 fOutputAOD(0x0),
3c329509 74 fTreeA(0x0),
75 fOfflineTriggerMask(0)
b81460ad 76{
77// Copy constructor
78 fDebug = obj.fDebug;
79 fEntry = obj.fEntry;
80 fInputHandler = obj.fInputHandler;
81 fOutputAOD = obj.fOutputAOD;
3c329509 82 fTreeA = obj.fTreeA;
83 fOfflineTriggerMask = obj.fOfflineTriggerMask;
b81460ad 84}
85
86
87AliAnalysisTaskME& AliAnalysisTaskME::operator=(const AliAnalysisTaskME& other)
88{
89// Assignment
ca12346a 90 if (this != &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;
99 }
b81460ad 100 return *this;
101}
102
103
104void AliAnalysisTaskME::ConnectInputData(Option_t* /*option*/)
105{
106// Connect the input data
107 if (fDebug > 1) printf("AnalysisTaskME::ConnectInputData() \n");
108//
109// Multi AOD
110//
cd17c2ba 111 fInputHandler = dynamic_cast<AliMultiEventInputHandler*>
b81460ad 112 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
94d4e23c 113 if (fInputHandler == 0) {
cd17c2ba 114 AliFatal("Event Handler has to be MultiEventInputHandler !");
94d4e23c 115 } else {
116 // Check that we have an event pool
117 if (!fInputHandler->GetEventPool()) {
118 fInputHandler->SetEventPool(AliAnalysisManager::GetAnalysisManager()->GetEventPool());
119 if (!fInputHandler->GetEventPool())
cd17c2ba 120 AliFatal("MultiEventInputHandler has no EventPool connected !");
94d4e23c 121 }
122 }
b81460ad 123}
124
125void AliAnalysisTaskME::CreateOutputObjects()
126{
127// Create the output container
128//
129// Default AOD
130 if (fDebug > 1) printf("AnalysisTaskME::CreateOutPutData() \n");
131
132 AliAODHandler* handler = (AliAODHandler*)
133 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
134
135 if (handler) {
136 fOutputAOD = handler->GetAOD();
137 fTreeA = handler->GetTree();
138 } else {
139 AliWarning("No AOD Event Handler connected.") ;
140 }
141 UserCreateOutputObjects();
142}
143
144void AliAnalysisTaskME::Exec(Option_t* option)
145{
146//
147// Exec analysis of one event
e7d9460a 148
b81460ad 149 if (fDebug > 1) AliInfo("AliAnalysisTaskME::Exec() \n");
150 if( fInputHandler )
151 fEntry = fInputHandler->GetReadEntry();
152 if ( !((Entry()-1)%100) && fDebug > 0)
153 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
15917707 154
155 AliAODHandler* outputHandler = (AliAODHandler*)
156 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
3c329509 157//
158// Was event selected ? If no event selection mechanism, the event SHOULD be selected (AG)
159 UInt_t isSelected = AliVEvent::kAny;
9daedfd1 160 if(fInputHandler && fInputHandler->GetEventSelection()) {
3c329509 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();
165 }
9daedfd1 166
3c329509 167 if (!isSelected) {
168 if (fDebug > 1) AliInfo("Event rejected \n");
169 fInputHandler->EventSkipped();
170 return;
171 }
b81460ad 172// Call the user analysis
3c329509 173
9daedfd1 174 if (fInputHandler && fInputHandler->IsBufferReady()) {
b81460ad 175 if ((fFreshBufferOnly && fInputHandler->IsFreshBuffer()) || !fFreshBufferOnly)
176 {
cd17c2ba 177 if (outputHandler) outputHandler->SetFillAOD(kTRUE);
b81460ad 178 UserExec(option);
79478008 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);
15917707 182 } else {
cd17c2ba 183 if (outputHandler) outputHandler->SetFillAOD(kFALSE);
b81460ad 184 }
e7d9460a 185 } else {
186 AliInfo(Form("Waiting for buffer to be ready !\n"));
b81460ad 187 }
188}
189
190const char* AliAnalysisTaskME::CurrentFileName()
191{
192// Returns the current file name
193 if(fInputHandler )
194 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
195 else return "";
196}
197
c8fe2783 198void AliAnalysisTaskME::AddAODBranch(const char* cname, void* addobj, const char *fname)
b81460ad 199{
200 // Add a new branch to the aod tree
201 AliAODHandler* handler = (AliAODHandler*)
202 ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
203 if (handler) {
c8fe2783 204 handler->AddBranch(cname, addobj, fname);
b81460ad 205 }
206}
207
cd17c2ba 208AliVEvent* AliAnalysisTaskME::GetEvent(Int_t iev)
b81460ad 209{
210 // Get an event from the input handler
211 return (fInputHandler->GetEvent(iev));
212}
213