added error messages when task does not post data in UserCreateOutputObjects for...
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskFilter.cxx
CommitLineData
6d3a7bbf 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//////////////////////////////////////////////////////////////////////////
19//
20// Base class for filtering friends
21//
22//////////////////////////////////////////////////////////////////////////
23
24#include <TChain.h>
25#include <TFile.h>
26#include <TList.h>
27
28#include "AliAnalysisTaskFilter.h"
29#include "AliAnalysisManager.h"
30#include "AliAnalysisDataSlot.h"
31#include "AliESDEvent.h"
32#include "AliESD.h"
33#include "AliVEvent.h"
34#include "AliESDHandler.h"
35#include "AliInputEventHandler.h"
36#include "AliLog.h"
37#include "AliESDfriend.h"
38#include "AliESDfriendTrack.h"
39
40
41ClassImp(AliAnalysisTaskFilter)
42
43////////////////////////////////////////////////////////////////////////
44
45AliAnalysisTaskFilter::AliAnalysisTaskFilter():
46 AliAnalysisTask(),
47 fDebug(0),
48 fEntry(0),
49 fInputEvent(0x0),
50 fInputHandler(0x0),
6d3a7bbf 51 fOutputESDfriend(0x0),
3e341ccb 52 fTreeEF(0x0),
53 fInputESDfriend(0x0)
6d3a7bbf 54{
55 //
56 // Default constructor
57 //
58}
59
60//______________________________________________________________________
61
62AliAnalysisTaskFilter::AliAnalysisTaskFilter(const char* name):
63 AliAnalysisTask(name, "AnalysisTaskFilter"),
64 fDebug(0),
65 fEntry(0),
66 fInputEvent(0x0),
67 fInputHandler(0x0),
6d3a7bbf 68 fOutputESDfriend(0x0),
3e341ccb 69 fTreeEF(0x0),
70 fInputESDfriend(0x0)
6d3a7bbf 71{
72 //
73 // Default constructor
74 //
75
76 DefineInput (0, TChain::Class());
77 DefineOutput(0, TTree::Class());
78}
79
80//______________________________________________________________________
81
82AliAnalysisTaskFilter::AliAnalysisTaskFilter(const AliAnalysisTaskFilter& obj):
83 AliAnalysisTask(obj),
84 fDebug(0),
85 fEntry(0),
86 fInputEvent(0x0),
87 fInputHandler(0x0),
6d3a7bbf 88 fOutputESDfriend(0x0),
3e341ccb 89 fTreeEF(0x0),
90 fInputESDfriend(0x0)
6d3a7bbf 91{
92 //
93 // Copy constructor
94 //
95
96 fDebug = obj.fDebug;
97 fEntry = obj.fEntry;
98 fInputEvent = obj.fInputEvent;
99 fInputHandler = obj.fInputHandler;
6d3a7bbf 100 fOutputESDfriend = obj.fOutputESDfriend;
03a8000a 101 fTreeEF = obj.fTreeEF;
3e341ccb 102 fInputESDfriend = obj.fInputESDfriend;
6d3a7bbf 103}
104
105
106//______________________________________________________________________
107
108AliAnalysisTaskFilter& AliAnalysisTaskFilter::operator=(const AliAnalysisTaskFilter& other)
109{
110 //
111 // Assignment
112 //
113
114 AliAnalysisTask::operator=(other);
115 fDebug = other.fDebug;
116 fEntry = other.fEntry;
117 fInputEvent = other.fInputEvent;
118 fInputHandler = other.fInputHandler;
6d3a7bbf 119 fOutputESDfriend = other.fOutputESDfriend;
03a8000a 120 fTreeEF = other.fTreeEF;
3e341ccb 121 fInputESDfriend = other.fInputESDfriend;
6d3a7bbf 122 return *this;
123}
124
125
126//______________________________________________________________________
127
128void AliAnalysisTaskFilter::ConnectInputData(Option_t* /*option*/)
129{
130 //
131 // Connect the input data
132 //
133
134 if (fDebug > 1) printf("AnalysisTaskFilter::ConnectInputData() \n");
135 fInputHandler = (AliInputEventHandler*)
136 ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
137 if (fInputHandler) {
138 fInputEvent = fInputHandler->GetEvent();
3e341ccb 139 if (fInputEvent){
140 fInputESDfriend = (AliESDfriend*)(fInputEvent->FindListObject("AliESDfriend"));
141 if (!fInputESDfriend){
142 AliError("No friend found");
143 }
144 }
145 else {
146 AliError("No Input Event found, the friend will remain empty");
147 }
148 }
149 else {
6d3a7bbf 150 AliError("No Input Event Handler connected") ;
151 return ;
152 }
153}
154
155//______________________________________________________________________
156
157void AliAnalysisTaskFilter::CreateOutputObjects()
158{
159 //
160 // Create the output container
161 //
162
163 if (fDebug > 1) printf("AnalysisTaskFilter::CreateOutPutData() \n");
164
165 AliESDHandler* handler = (AliESDHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
166
167 if (handler) {
03a8000a 168 fTreeEF = handler->GetTree();
6d3a7bbf 169 }
170 else {
171 AliWarning("No AOD Event Handler connected.") ;
172 }
173
174 UserCreateOutputObjects();
175}
176
177//______________________________________________________________________
178
179void AliAnalysisTaskFilter::Exec(Option_t* option)
180{
181 //
182 // Exec analysis of one event
183 //
184
185 if (fDebug > 1) AliInfo("AliAnalysisTaskFilter::Exec() \n");
186
187 if( fInputHandler ) {
188 fEntry = fInputHandler->GetReadEntry();
189 }
190
191
192 if ( !((Entry()-1)%100) && fDebug > 0) {
193 AliInfo(Form("%s ----> Processing event # %lld", CurrentFileName(), Entry()));
194 }
195 AliESDHandler* handler = (AliESDHandler*)((AliAnalysisManager::GetAnalysisManager())->GetOutputEventHandler());
196
197 if (UserSelectESDfriendForCurrentEvent()){
198 // Call the user analysis only if the event was selected
3e341ccb 199 handler->SelectEventForFriends();
6d3a7bbf 200 fOutputESDfriend = handler->GetESDfriend();
201 UserExec(option);
3e341ccb 202 // copy the VZERO friend only if it is not already there
203 if (fOutputESDfriend->GetVZEROfriend() == 0x0){
204 AliDebug(2,"Copying VZERO friend object");
205 AliESDVZEROfriend* vZEROfriend = fInputESDfriend->GetVZEROfriend();
206 fOutputESDfriend->SetVZEROfriend(vZEROfriend);
207 }
6d3a7bbf 208 }
03a8000a 209 else {
3e341ccb 210 // Event not selected
211 AliDebug(2,"The event was not selected");
03a8000a 212 }
6d3a7bbf 213
6d3a7bbf 214 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
03a8000a 215 if (out0 && out0->IsConnected()) PostData(0, fTreeEF);
6d3a7bbf 216}
217
218//______________________________________________________________________
219
220const char* AliAnalysisTaskFilter::CurrentFileName()
221{
222 // Returns the current file name
223 if( fInputHandler ){
224 return fInputHandler->GetTree()->GetCurrentFile()->GetName();
225 }
226 else return "";
227}
228
229//______________________________________________________________________
230
231void AliAnalysisTaskFilter::AddFriendTrackAt(AliESDfriendTrack* t, Int_t index)
232{
233 //
234 // Adds the friend track at the i-th position in the TClonesArray
235 // of the ESD friend tracks
236 //
237
238 AliESDfriendTrack* currentTrack = (AliESDfriendTrack*)fOutputESDfriend->GetTrack(index);
3e341ccb 239 if(currentTrack){
240 if (currentTrack->TestSkipBit()){
241 AliDebug(2,Form("Friend at index %d already there but dummy - the skip bit will be set to FALSE", index));
242 t->SetSkipBit(kFALSE);
243 }
244 else{
245 AliDebug(2,Form("Friend at index %d already there and not dummy", index));
246 return;
247 }
248 }
249 else{
250 AliDebug(2,Form("Track at %d not there yet ",index));
251 }
252 AliDebug(2,Form("Adding track at %d",index));
253 fOutputESDfriend->AddTrackAt(t,index);
254 return;
255}
256
257//______________________________________________________________________
258
259void AliAnalysisTaskFilter::SkipFriendTrackAt(Int_t index)
260{
261 //
262 // Skip the friend track at the i-th position in the TClonesArray
263 // of the ESD friend tracks
264 //
265
266 AliESDfriendTrack* currentTrack = (AliESDfriendTrack*)fOutputESDfriend->GetTrack(index);
267 if (currentTrack){
268 AliDebug(2,Form("Track already there (no matter what validity) at %d, keeping it as it is", index));
6d3a7bbf 269 }
270 else {
3e341ccb 271 AliDebug(2,Form("Adding NULL track at %d, and setting skip bit to TRUE",index));
272 AliESDfriendTrack* tNull = new AliESDfriendTrack();
273 tNull->SetSkipBit(kTRUE);
274 fOutputESDfriend->AddTrackAt(tNull,index);
6d3a7bbf 275 }
3e341ccb 276 return;
6d3a7bbf 277}