AliRoot Core  3dc7879 (3dc7879)
AliAnalysisTaskME.cxx
Go to the documentation of this file.
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 #include <TROOT.h>
17 #include <TSystem.h>
18 #include <TInterpreter.h>
19 #include <TChain.h>
20 #include <TFile.h>
21 #include <TList.h>
22 
23 #include "AliAnalysisTaskME.h"
24 #include "AliAnalysisManager.h"
25 #include "AliAnalysisDataSlot.h"
26 #include "AliAODEvent.h"
27 #include "AliVEvent.h"
28 #include "AliAODHandler.h"
30 #include "AliLog.h"
31 
32 
33 ClassImp(AliAnalysisTaskME)
34 
35 
39  fDebug(0),
40  fEntry(0),
41  fFreshBufferOnly(kFALSE),
42  fInputHandler(0x0),
43  fOutputAOD(0x0),
44  fTreeA(0x0),
45  fOfflineTriggerMask(0)
46 {
47  // Default constructor
48 }
49 
51  AliAnalysisTask(name, "AnalysisTaskME"),
52  fDebug(0),
53  fEntry(0),
54  fFreshBufferOnly(kFALSE),
55  fInputHandler(0x0),
56  fOutputAOD(0x0),
57  fTreeA(0x0),
58  fOfflineTriggerMask(0)
59 {
61 
62  DefineInput (0, TChain::Class());
63  DefineOutput(0, TTree::Class());
64 }
65 
67  AliAnalysisTask(obj),
68  fDebug(0),
69  fEntry(0),
70  fFreshBufferOnly(kFALSE),
71  fInputHandler(0x0),
72  fOutputAOD(0x0),
73  fTreeA(0x0),
75 {
77 
78  fDebug = obj.fDebug;
79  fEntry = obj.fEntry;
81  fOutputAOD = obj.fOutputAOD;
82  fTreeA = obj.fTreeA;
84 }
85 
86 
88 {
90 
91  if (this != &other) {
93  fDebug = other.fDebug;
94  fEntry = other.fEntry;
97  fOutputAOD = other.fOutputAOD;
98  fTreeA = other.fTreeA;
100  }
101  return *this;
102 }
103 
104 
105 void AliAnalysisTaskME::ConnectInputData(Option_t* /*option*/)
106 {
108 
109  if (fDebug > 1) printf("AnalysisTaskME::ConnectInputData() \n");
110 //
111 // Multi AOD
112 //
113  fInputHandler = dynamic_cast<AliMultiEventInputHandler*>
114  ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
115  if (fInputHandler == 0) {
116  AliFatal("Event Handler has to be MultiEventInputHandler !");
117  } else {
118  // Check that we have an event pool
119  if (!fInputHandler->GetEventPool()) {
121  if (!fInputHandler->GetEventPool())
122  AliFatal("MultiEventInputHandler has no EventPool connected !");
123  }
124  }
125 }
126 
128 {
132 
133  if (fDebug > 1) printf("AnalysisTaskME::CreateOutPutData() \n");
134 
135  AliAODHandler* handler = (AliAODHandler*)
136  ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
137 
138  if (handler) {
139  fOutputAOD = handler->GetAOD();
140  fTreeA = handler->GetTree();
141  } else {
142  AliWarning("No AOD Event Handler connected.") ;
143  }
145 }
146 
147 void AliAnalysisTaskME::Exec(Option_t* option)
148 {
150 
151  if (fDebug > 1) AliInfo("AliAnalysisTaskME::Exec() \n");
152  if( fInputHandler )
154  if ( !((Entry()-1)%100) && fDebug > 0)
155  AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
156 
157  AliAODHandler* outputHandler = (AliAODHandler*)
158  ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
159 //
160 // Was event selected ? If no event selection mechanism, the event SHOULD be selected (AG)
161  UInt_t isSelected = AliVEvent::kAny;
163  // Get the actual offline trigger mask for the event and AND it with the
164  // requested mask. If no mask requested select by default the event.
167  }
168 
169  if (!isSelected) {
170  if (fDebug > 1) AliInfo("Event rejected \n");
172  return;
173  }
174 // Call the user analysis
175 
178  {
179  if (outputHandler) outputHandler->SetFillAOD(kTRUE);
180  UserExec(option);
181  // Added protection in case the derived task is not an AOD producer.
183  if (out0 && out0->IsConnected()) PostData(0, fTreeA);
184  } else {
185  if (outputHandler) outputHandler->SetFillAOD(kFALSE);
186  }
187  } else {
188  AliInfo(Form("Waiting for buffer to be ready !\n"));
189  }
190 }
191 
193 {
195 
196  if(fInputHandler )
197  return fInputHandler->GetTree()->GetCurrentFile()->GetName();
198  else return "";
199 }
200 
201 void AliAnalysisTaskME::AddAODBranch(const char* cname, void* addobj, const char *fname)
202 {
204 
205  AliAODHandler* handler = (AliAODHandler*)
206  ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
207  if (handler) {
208  handler->AddBranch(cname, addobj, fname);
209  }
210 }
211 
213 {
215 
216  return (fInputHandler->GetEvent(iev));
217 }
218 
AliAnalysysTask - Class representing a basic analysis task. Any user-defined task should derive from...
virtual Long64_t GetReadEntry() const
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
Implementation of the Event Handler Interface for AOD.
Definition: AliAODHandler.h:27
Multi VEvent Input Handler realisation of the AliVEventHandler interface.
virtual TTree * GetTree() const
Definition: AliAODHandler.h:73
Bool_t IsConnected() const
static AliAnalysisManager * GetAnalysisManager()
void SetEventPool(AliVEventPool *pool)
AliVEventPool * GetEventPool() const
virtual UInt_t IsEventSelected()
Bool_t PostData(Int_t iout, TObject *data, Option_t *option="")
void DefineInput(Int_t islot, TClass *type)
AliAnalysisTask & operator=(const AliAnalysisTask &task)
UInt_t fOfflineTriggerMask
Task processes collision candidates only.
#define AliWarning(message)
Definition: AliLog.h:541
TTree * fTreeA
AOD output Tree.
virtual TTree * GetTree() const
virtual void SetFillAOD(Bool_t b)
Definition: AliAODHandler.h:50
virtual void AddAODBranch(const char *cname, void *addobj, const char *fname="")
AliAnalysysDataSlot Class representing a data slot of an analysis task. An analysis slot enforces a c...
#define AliInfo(message)
Definition: AliLog.h:484
AliAnalysisDataSlot * GetOutputSlot(Int_t islot) const
Int_t fDebug
Debug flag.
virtual void UserCreateOutputObjects()
virtual void ConnectInputData(Option_t *option="")
virtual AliVCuts * GetEventSelection() const
Bool_t fFreshBufferOnly
Flag for Exec call for fresh buffer only.
#define AliFatal(message)
Definition: AliLog.h:640
virtual void UserExec(Option_t *)
virtual AliVEvent * GetEvent() const
AliAODEvent * GetAOD()
Definition: AliAODHandler.h:72
AliMultiEventInputHandler * fInputHandler
! Input Handler
void AddBranch(const char *cname, void *addobj, const char *fname="")
AliAODEvent * fOutputAOD
! AOD out
virtual void CreateOutputObjects()
void DefineOutput(Int_t islot, TClass *type)
Int_t fEntry
Current entry in the chain.
AliAnalysisTaskME & operator=(const AliAnalysisTaskME &other)
virtual Long64_t Entry()
char * fname
virtual AliVEvent * GetEvent(Int_t iev)
virtual const char * CurrentFileName()
virtual void Exec(Option_t *option)