]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/ANALYSIS/AliAnalysisTask.cxx
Update z position of ADA (Z=1699.7)
[u/mrichter/AliRoot.git] / ANALYSIS / ANALYSIS / AliAnalysisTask.cxx
CommitLineData
d3106602 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// Author: Andrei Gheata, 31/05/2006
18
19//==============================================================================
20// AliAnalysysTask - Class representing a basic analysis task. Any
21// user-defined task should derive from it and implement the Exec() virtual
22// method.
23//==============================================================================
24//
25// A specific user analysis task have to derive from this class. The list of
26// specific input and output slots have to be defined in the derived class ctor:
27//
28// UserTask::UserTask(name, title)
29// {
30// DefineInput(0, TTree::Class());
31// DefineInput(1, TH1::Class());
32// ...
33// DefineOutput(0, TTree::Class());
34// DefineOutput(1, MyObject::Class());
35// ...
36// }
37//
38// An existing data contaner (AliAnalysisDataContainer) can be connected to the
39// input/output slots of an analysis task. Containers should not be defined and
40// connected by the derived analysis task, but from the level of AliAnalysisManager:
41//
42// AliAnalysisManager::ConnectInput(AliAnalysisTask *task, Int_t islot,
43// AliAnalysisDataContainer *cont)
44// AliAnalysisManager::ConnectOutput(AliAnalysisTask *task, Int_t islot,
45// AliAnalysisDataContainer *cont)
46// To connect a slot to a data container, the data types declared by both must
47// match.
327eaf46 48//
c52c2132 49// The method ConnectInputData() has to be overloaded by the derived class in order to
50// set the branch address or connect to a branch address in case the input
51// slots are connected to trees.
327eaf46 52// Example:
c52c2132 53// MyAnalysisTask::ConnectInputData(Option_t *)
327eaf46 54// {
c52c2132 55// // One should first check if the branch address was taken by some other task
56// char ** address = (char **)GetBranchAddress(0, "ESD");
57// if (address) {
58// fESD = (AliESD*)(*address);
59// } else {
60// fESD = new AliESD();
61// SetBranchAddress(0, "ESD", &fESD);
62// }
63// }
64//
9b33830a 65// The method LocalInit() may be implemented to call locally (on the client)
66// all initialization methods of the class. It is not mandatory and was created
67// in order to minimize the complexity and readability of the analysis macro.
68// DO NOT create in this method the histigrams or task output objects that will
69// go in the task output containers. Use CreateOutputObjects for that.
70//
71// The method CreateOutputObjects() has to be implemented an will contain the
c52c2132 72// objects that should be created only once per session (e.g. output
73// histograms)
74//
75// void MyAnalysisTask::CreateOutputObjects()
76//{
77 // create histograms
78// fhPt = new TH1F("fhPt","This is the Pt distribution",15,0.1,3.1);
79// fhPt->SetStats(kTRUE);
80// fhPt->GetXaxis()->SetTitle("P_{T} [GeV]");
81// fhPt->GetYaxis()->SetTitle("#frac{dN}{dP_{T}}");
82// fhPt->GetXaxis()->SetTitleColor(1);
83// fhPt->SetMarkerStyle(kFullCircle);
327eaf46 84// }
85//
86// The method Terminate() will be called by the framework once at the end of
c52c2132 87// data processing. Overload this if needed. DO NOT ASSUME that the pointers
88// to histograms defined in CreateOutputObjects() are valid, since this is
89// not true in case of PROOF. Restore the pointer values like:
90//
91//void MyAnalysisTask::Terminate(Option_t *)
92//{
93// fhPt = (TH1F*)GetOutputData(0);
94// ...
95//}
96
327eaf46 97//
d3106602 98//==============================================================================
99
0b28fd57 100#include <Riostream.h>
c5a87c56 101#include <TFile.h>
c52c2132 102#include <TClass.h>
b2fce16b 103#include <TCollection.h>
b1310ef5 104#include <TTree.h>
8e6e6fe8 105#include <TROOT.h>
d3106602 106
d3106602 107#include "AliAnalysisTask.h"
108#include "AliAnalysisDataSlot.h"
109#include "AliAnalysisDataContainer.h"
c5a87c56 110#include "AliAnalysisManager.h"
d3106602 111
112ClassImp(AliAnalysisTask)
113
114//______________________________________________________________________________
115AliAnalysisTask::AliAnalysisTask()
37a26056 116 :fReady(kFALSE),
327eaf46 117 fInitialized(kFALSE),
37a26056 118 fNinputs(0),
119 fNoutputs(0),
120 fOutputReady(NULL),
121 fPublishedData(NULL),
122 fInputs(NULL),
7acc5b9d 123 fOutputs(NULL),
124 fBranchNames()
d3106602 125{
126// Default constructor.
d3106602 127}
128
129//______________________________________________________________________________
130AliAnalysisTask::AliAnalysisTask(const char *name, const char *title)
37a26056 131 :TTask(name,title),
132 fReady(kFALSE),
327eaf46 133 fInitialized(kFALSE),
37a26056 134 fNinputs(0),
135 fNoutputs(0),
136 fOutputReady(NULL),
137 fPublishedData(NULL),
138 fInputs(NULL),
7acc5b9d 139 fOutputs(NULL),
140 fBranchNames()
d3106602 141{
37a26056 142// Constructor.
d3106602 143 fInputs = new TObjArray(2);
144 fOutputs = new TObjArray(2);
145}
146
147//______________________________________________________________________________
148AliAnalysisTask::AliAnalysisTask(const AliAnalysisTask &task)
37a26056 149 :TTask(task),
150 fReady(task.fReady),
327eaf46 151 fInitialized(task.fInitialized),
37a26056 152 fNinputs(task.fNinputs),
153 fNoutputs(task.fNoutputs),
154 fOutputReady(NULL),
155 fPublishedData(NULL),
156 fInputs(NULL),
7acc5b9d 157 fOutputs(NULL),
158 fBranchNames(task.fBranchNames)
d3106602 159{
160// Copy ctor.
d3106602 161 fInputs = new TObjArray((fNinputs)?fNinputs:2);
162 fOutputs = new TObjArray((fNoutputs)?fNoutputs:2);
163 fPublishedData = 0;
164 Int_t i;
165 for (i=0; i<fNinputs; i++) fInputs->AddAt(task.GetInputSlot(i),i);
166 fOutputReady = new Bool_t[(fNoutputs)?fNoutputs:2];
167 for (i=0; i<fNoutputs; i++) {
168 fOutputReady[i] = IsOutputReady(i);
169 fOutputs->AddAt(task.GetOutputSlot(i),i);
170 }
171}
172
173//______________________________________________________________________________
174AliAnalysisTask::~AliAnalysisTask()
175{
176// Dtor.
c52c2132 177 if (fTasks) fTasks->Clear();
d3106602 178 if (fInputs) {fInputs->Delete(); delete fInputs;}
179 if (fOutputs) {fOutputs->Delete(); delete fOutputs;}
180}
181
182//______________________________________________________________________________
183AliAnalysisTask& AliAnalysisTask::operator=(const AliAnalysisTask& task)
184{
185// Assignment
37a26056 186 if (&task == this) return *this;
187 TTask::operator=(task);
188 fReady = task.IsReady();
327eaf46 189 fInitialized = task.IsInitialized();
37a26056 190 fNinputs = task.GetNinputs();
191 fNoutputs = task.GetNoutputs();
192 fInputs = new TObjArray((fNinputs)?fNinputs:2);
193 fOutputs = new TObjArray((fNoutputs)?fNoutputs:2);
194 fPublishedData = 0;
195 Int_t i;
196 for (i=0; i<fNinputs; i++) fInputs->AddAt(new AliAnalysisDataSlot(*task.GetInputSlot(i)),i);
197 fOutputReady = new Bool_t[(fNoutputs)?fNoutputs:2];
198 for (i=0; i<fNoutputs; i++) {
199 fOutputReady[i] = IsOutputReady(i);
200 fOutputs->AddAt(new AliAnalysisDataSlot(*task.GetOutputSlot(i)),i);
201 }
7acc5b9d 202 fBranchNames = task.fBranchNames;
d3106602 203 return *this;
204}
205
206//______________________________________________________________________________
207Bool_t AliAnalysisTask::AreSlotsConnected()
208{
209// Check if all input/output slots are connected. If this is the case fReady=true
210 fReady = kFALSE;
211 if (!fNinputs || !fNoutputs) return kFALSE;
212 Int_t i;
213 AliAnalysisDataSlot *slot;
214 for (i=0; i<fNinputs; i++) {
215 slot = (AliAnalysisDataSlot*)fInputs->At(i);
216 if (!slot) {
c52c2132 217 Error("AreSlotsConnected", "Input slot %d of task %s not defined !",i,GetName());
d3106602 218 return kFALSE;
219 }
220 if (!slot->IsConnected()) return kFALSE;
221 }
222 for (i=0; i<fNoutputs; i++) {
223 slot = (AliAnalysisDataSlot*)fOutputs->At(i);
224 if (!slot) {
c52c2132 225 Error("AreSlotsConnected", "Output slot %d of task %s not defined !",i,GetName());
d3106602 226 return kFALSE;
227 }
228 if (!slot->IsConnected()) return kFALSE;
229 }
230 fReady = kTRUE;
231 return kTRUE;
232}
233
234//______________________________________________________________________________
327eaf46 235void AliAnalysisTask::CheckNotify(Bool_t init)
d3106602 236{
237// Check if data is available from all inputs. Change the status of the task
238// accordingly. This method is called automatically for all tasks connected
239// to a container where the data was published.
327eaf46 240 if (init) fInitialized = kFALSE;
b1310ef5 241 Bool_t single_shot = IsPostEventLoop();
efd53803 242 AliAnalysisDataContainer *cinput;
d3106602 243 for (Int_t islot=0; islot<fNinputs; islot++) {
efd53803 244 cinput = GetInputSlot(islot)->GetContainer();
b1310ef5 245 if (!cinput->GetData() || (single_shot && !cinput->IsPostEventLoop())) {
d3106602 246 SetActive(kFALSE);
247 return;
248 }
249 }
250 SetActive(kTRUE);
327eaf46 251 if (fInitialized) return;
252 TDirectory *cursav = gDirectory;
c52c2132 253 ConnectInputData();
327eaf46 254 if (cursav) cursav->cd();
255 fInitialized = kTRUE;
d3106602 256}
257
4747b4a7 258//______________________________________________________________________________
259Bool_t AliAnalysisTask::CheckPostData() const
260{
261// Checks if data was posted to all outputs defined by the task. If task does
262// not have output slots this returns always kTRUE.
8c1f7958 263 Bool_t dataPosted = kTRUE;
4747b4a7 264 AliAnalysisDataContainer *coutput;
b2fce16b 265 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
4747b4a7 266 for (Int_t islot=0; islot<fNoutputs; islot++) {
267 coutput = GetOutputSlot(islot)->GetContainer();
4ff26233 268 if (!coutput) continue;
269 if (coutput->IsExchange() || !mgr->GetOutputs()->FindObject(coutput) || coutput==mgr->GetCommonOutputContainer()) continue;
8c1f7958 270 if (!coutput->GetData()) {
271 Error("CheckPostData", "Data not posted for slot #%d of task %s (%s)",
272 islot, GetName(), ClassName());
273 dataPosted = kFALSE;
274 }
4747b4a7 275 }
b2fce16b 276 CheckOwnership();
8c1f7958 277 return dataPosted;
4747b4a7 278}
279
b2fce16b 280//______________________________________________________________________________
281Bool_t AliAnalysisTask::CheckOwnership() const
282{
283// Check ownership of containers posted on output slots (1 level only)
284 TObject *outdata;
285 for (Int_t islot=0; islot<fNoutputs; islot++) {
286 outdata = GetOutputData(islot);
287 if (outdata && outdata->InheritsFrom(TCollection::Class())) {
288 TCollection *coll = (TCollection*)outdata;
289 if (!coll->IsOwner()) {
290 Error("CheckOwnership","####### IMPORTANT! ####### \n\n\n\
291 Task %s (%s) posts a container that is not owner at output #%d. This may apply for other embedded containers. \n\n\
292 ####### FIX YOUR CODE, THIS WILL PRODUCE A FATAL ERROR IN FUTURE! ##########", GetName(), ClassName(), islot);
293 return kFALSE;
294 }
295 }
296 }
297 return kTRUE;
298}
299
d3106602 300//______________________________________________________________________________
301Bool_t AliAnalysisTask::ConnectInput(Int_t islot, AliAnalysisDataContainer *cont)
302{
303// Connect an input slot to a data container.
304 AliAnalysisDataSlot *input = GetInputSlot(islot);
305 if (!input) {
c52c2132 306 Error("ConnectInput","Input slot %i not defined for analysis task %s", islot, GetName());
d3106602 307 return kFALSE;
308 }
309 // Check type matching
310 if (!input->GetType()->InheritsFrom(cont->GetType())) {
c52c2132 311 Error("ConnectInput","Data type %s for input %i of task %s not matching container %s of type %s",input->GetType()->GetName(), islot, GetName(), cont->GetName(), cont->GetType()->GetName());
d3106602 312 return kFALSE;
313 }
314 // Connect the slot to the container as input
315 if (!input->ConnectContainer(cont)) return kFALSE;
316 // Add this to the list of container consumers
317 cont->AddConsumer(this, islot);
318 AreSlotsConnected();
319 return kTRUE;
320}
321
322//______________________________________________________________________________
323Bool_t AliAnalysisTask::ConnectOutput(Int_t islot, AliAnalysisDataContainer *cont)
324{
325// Connect an output slot to a data container.
326 AliAnalysisDataSlot *output = GetOutputSlot(islot);
327 if (!output) {
c52c2132 328 Error("ConnectOutput","Output slot %i not defined for analysis task %s", islot, GetName());
d3106602 329 return kFALSE;
330 }
331 // Check type matching
332 if (!output->GetType()->InheritsFrom(cont->GetType())) {
c52c2132 333 Error("ConnectOutput","Data type %s for output %i of task %s not matching container %s of type %s",output->GetType()->GetName(), islot, GetName(), cont->GetName(), cont->GetType()->GetName());
d3106602 334 return kFALSE;
335 }
336 // Connect the slot to the container as output
337 if (!output->ConnectContainer(cont)) return kFALSE;
b1310ef5 338 // Set event loop type the same as for the task
339 cont->SetPostEventLoop(IsPostEventLoop());
d3106602 340 // Declare this as the data producer
341 cont->SetProducer(this, islot);
342 AreSlotsConnected();
343 return kTRUE;
344}
345
346//______________________________________________________________________________
347void AliAnalysisTask::DefineInput(Int_t islot, TClass *type)
348{
349// Define an input slot and its type.
350 AliAnalysisDataSlot *input = new AliAnalysisDataSlot(type, this);
351 if (fNinputs<islot+1) fNinputs = islot+1;
6ae18197 352 fInputs->AddAtAndExpand(input, islot);
d3106602 353}
354
355//______________________________________________________________________________
356void AliAnalysisTask::DefineOutput(Int_t islot, TClass *type)
357{
358// Define an output slot and its type.
d3106602 359 AliAnalysisDataSlot *output = new AliAnalysisDataSlot(type, this);
360 if (fNoutputs<islot+1) {
361 fNoutputs = islot+1;
362 if (fOutputReady) delete [] fOutputReady;
363 fOutputReady = new Bool_t[fNoutputs];
364 memset(fOutputReady, 0, fNoutputs*sizeof(Bool_t));
365 }
6ae18197 366 fOutputs->AddAtAndExpand(output, islot);
d3106602 367}
368
369//______________________________________________________________________________
370TClass *AliAnalysisTask::GetInputType(Int_t islot) const
371{
372// Retreive type of a given input slot.
373 AliAnalysisDataSlot *input = GetInputSlot(islot);
374 if (!input) {
c52c2132 375 Error("GetInputType","Input slot %d not defined for analysis task %s", islot, GetName());
d3106602 376 return NULL;
377 }
378 return (input->GetType());
379}
380
381//______________________________________________________________________________
382TClass *AliAnalysisTask::GetOutputType(Int_t islot) const
383{
384// Retreive type of a given output slot.
385 AliAnalysisDataSlot *output = GetOutputSlot(islot);
386 if (!output) {
c52c2132 387 Error("GetOutputType","Output slot %d not defined for analysis task %s", islot, GetName());
d3106602 388 return NULL;
389 }
390 return (output->GetType());
391}
392
393//______________________________________________________________________________
394TObject *AliAnalysisTask::GetInputData(Int_t islot) const
395{
396// Retreive input data for a slot if ready. Normally called by Exec() and
397// the object has to be statically cast to the appropriate type.
398 AliAnalysisDataSlot *input = GetInputSlot(islot);
399 if (!input) {
c52c2132 400 Error("GetInputData","Input slot %d not defined for analysis task %s", islot, GetName());
d3106602 401 return NULL;
402 }
403 return (input->GetData());
404}
405
c52c2132 406//______________________________________________________________________________
407TObject *AliAnalysisTask::GetOutputData(Int_t islot) const
408{
409// Retreive output data for a slot. Normally called in UserTask::Terminate to
410// get a valid pointer to data even in case of Proof.
411 AliAnalysisDataSlot *output = GetOutputSlot(islot);
412 if (!output) {
413 Error("GetOutputData","Input slot %d not defined for analysis task %s", islot, GetName());
414 return NULL;
415 }
416 return (output->GetData());
417}
418
327eaf46 419//______________________________________________________________________________
420char *AliAnalysisTask::GetBranchAddress(Int_t islot, const char *branch) const
421{
422// Check if a branch with a given name from the specified input is connected
423// to some address. Call this in Init() before trying to call SetBranchAddress()
424// since the adress may be set by other task.
425 return (char *)GetInputSlot(islot)->GetBranchAddress(branch);
426}
427
428//______________________________________________________________________________
429Bool_t AliAnalysisTask::SetBranchAddress(Int_t islot, const char *branch, void *address) const
430{
431// Connect an object address to a branch of the specified input.
432 return GetInputSlot(islot)->SetBranchAddress(branch, address);
433}
434
b1310ef5 435//______________________________________________________________________________
436void AliAnalysisTask::EnableBranch(Int_t islot, const char *bname) const
437{
438// Call this in ConnectInputData() to enable only the branches needed by this
439// task. "*" will enable everything.
440 AliAnalysisDataSlot *input = GetInputSlot(islot);
441 if (!input || !input->GetType()->InheritsFrom(TTree::Class())) {
442 Error("EnableBranch", "Wrong slot type #%d for task %s: not TTree-derived type", islot, GetName());
443 return;
444 }
445 TTree *tree = (TTree*)input->GetData();
446 if (!strcmp(bname, "*")) {
447 tree->SetBranchStatus("*",1);
448 return;
449 }
450 AliAnalysisDataSlot::EnableBranch(bname, tree);
451}
8508e09f 452
453//______________________________________________________________________________
8d7d3b59 454void AliAnalysisTask::FinishTaskOutput()
8508e09f 455{
8d7d3b59 456// Optional method that is called in SlaveTerminate phase.
457// Used for calling aditional methods just after the last event was processed ON
458// THE WORKING NODE. The call is made also in local case.
459// Do NOT delete output objects here since they will have to be sent for
460// merging in PROOF mode - use class destructor for cleanup.
8508e09f 461}
b1310ef5 462
327eaf46 463//______________________________________________________________________________
c52c2132 464void AliAnalysisTask::ConnectInputData(Option_t *)
327eaf46 465{
c52c2132 466// Overload and connect your branches here.
327eaf46 467}
468
9b33830a 469//______________________________________________________________________________
470void AliAnalysisTask::LocalInit()
471{
472// The method LocalInit() may be implemented to call locally (on the client)
473// all initialization methods of the class. It is not mandatory and was created
474// in order to minimize the complexity and readability of the analysis macro.
475// DO NOT create in this method the histigrams or task output objects that will
476// go in the task output containers. Use CreateOutputObjects for that.
477}
478
327eaf46 479//______________________________________________________________________________
c52c2132 480void AliAnalysisTask::CreateOutputObjects()
327eaf46 481{
981f2614 482// Called once per task either in PROOF or local mode. Overload to put some
483// task initialization and/or create your output objects here.
484}
485
c5a87c56 486//______________________________________________________________________________
13ef3bb0 487TFile *AliAnalysisTask::OpenFile(Int_t iout, Option_t *option) const
c5a87c56 488{
489// This method has to be called INSIDE the user redefined CreateOutputObjects
490// method, before creating each object corresponding to the output containers
491// that are to be written to a file. This need to be done in general for the big output
492// objects that may not fit memory during processing.
493// - 'option' is the file opening option.
494//=========================================================================
495// NOTE !: The method call will be ignored in PROOF mode, in which case the
496// results have to be streamed back to the client and written just before Terminate()
497//=========================================================================
498//
499// Example:
500// void MyAnaTask::CreateOutputObjects() {
501// OpenFile(0); // Will open the file for the object to be written at output #0
502// fAOD = new TTree("AOD for D0toKPi");
503// OpenFile(1);
504// now some histos that should go in the file of the second output container
505// fHist1 = new TH1F("my quality check hist1",...);
506// fHist2 = new TH2F("my quality check hist2",...);
507// }
508
13ef3bb0 509 if (iout<0 || iout>=fNoutputs) {
510 Error("OpenFile", "No output slot for task %s with index %d", GetName(), iout);
511 return NULL;
512 }
84fcd93f 513 // Method delegated to the analysis manager (A.G. 02/11/09)
c5a87c56 514 AliAnalysisDataContainer *cont = GetOutputSlot(iout)->GetContainer();
84fcd93f 515 return AliAnalysisManager::OpenFile(cont, option);
c5a87c56 516}
517
981f2614 518//______________________________________________________________________________
519Bool_t AliAnalysisTask::Notify()
520{
521// Overload this IF you need to treat input file change.
522 return kTRUE;
327eaf46 523}
524
aee5ee44 525//______________________________________________________________________________
526Bool_t AliAnalysisTask::NotifyBinChange()
527{
528// Overload this IF you need to treat bin change in event mixing.
529 return kTRUE;
530}
531
327eaf46 532//______________________________________________________________________________
c52c2132 533void AliAnalysisTask::Terminate(Option_t *)
327eaf46 534{
c52c2132 535// Method called by the framework at the end of data processing.
536}
327eaf46 537
d3106602 538//______________________________________________________________________________
539Bool_t AliAnalysisTask::PostData(Int_t iout, TObject *data, Option_t *option)
540{
541// Post output data for a given ouput slot in the corresponding data container.
542// Published data becomes owned by the data container.
543// If option is specified, the container connected to the output slot must have
544// an associated file name defined. The option represents the method to open the file.
545 fPublishedData = 0;
546 AliAnalysisDataSlot *output = GetOutputSlot(iout);
547 if (!output) {
c52c2132 548 Error("PostData","Output slot %i not defined for analysis task %s", iout, GetName());
d3106602 549 return kFALSE;
550 }
551 if (!output->IsConnected()) {
c52c2132 552 Error("PostData","Output slot %i of analysis task %s not connected to any data container", iout, GetName());
d3106602 553 return kFALSE;
554 }
555 if (!fOutputReady) {
556 fOutputReady = new Bool_t[fNoutputs];
557 memset(fOutputReady, 0, fNoutputs*sizeof(Bool_t));
558 }
559 fOutputReady[iout] = kTRUE;
560 fPublishedData = data;
561 return (output->GetContainer()->SetData(data, option));
562}
563
564//______________________________________________________________________________
565void AliAnalysisTask::SetUsed(Bool_t flag)
566{
567// Set 'used' flag recursively to task and all daughter tasks.
568 if (TestBit(kTaskUsed)==flag) return;
569 TObject::SetBit(kTaskUsed,flag);
570 Int_t nd = fTasks->GetSize();
571 AliAnalysisTask *task;
572 for (Int_t i=0; i<nd; i++) {
573 task = (AliAnalysisTask*)fTasks->At(i);
574 task->SetUsed(flag);
575 }
576}
577
4ff26233 578//______________________________________________________________________________
579void AliAnalysisTask::Reset()
580{
581// Clear activity flag. Reset data for exchange containers.
582 fActive = kFALSE;
583 fHasExecuted = kFALSE;
584 // Call PostData(islot, 0) for all slots connected to exchange containers
585 Int_t islot;
586 AliAnalysisDataContainer *cont;
587 for (islot=0; islot<fNinputs; islot++) {
588 cont = GetInputSlot(islot)->GetContainer();
589 if (cont && cont->IsExchange()) cont->Reset();
590 }
591}
592
d3106602 593//______________________________________________________________________________
594Bool_t AliAnalysisTask::CheckCircularDeps()
595{
596// Check for illegal circular dependencies, e.g. a daughter task should not have
597// a hierarchical parent as subtask.
598 if (IsChecked()) return kTRUE;
599 SetChecked();
600 TList *tasks = GetListOfTasks();
601 Int_t ntasks = tasks->GetSize();
602 AliAnalysisTask *task;
603 for (Int_t i=0; i<ntasks; i++) {
604 task = (AliAnalysisTask*)tasks->At(i);
605 if (task->CheckCircularDeps()) return kTRUE;
606 }
607 SetChecked(kFALSE);
608 return kFALSE;
609}
4ff26233 610
611//______________________________________________________________________________
612Bool_t AliAnalysisTask::ProducersTouched() const
613{
614// Check if all producer containers are in the "touched" state.
615 Int_t islot;
616 AliAnalysisDataContainer *cont;
617 for (islot=0; islot<fNinputs; islot++) {
618 cont = GetInputSlot(islot)->GetContainer();
619 // Simulate the data flow so the tasks are printed only when all inputs
620 // are touched
621 if (cont && !cont->IsTouched()) return kFALSE;
622 }
623 return kTRUE;
624}
625
d3106602 626//______________________________________________________________________________
627void AliAnalysisTask::PrintTask(Option_t *option, Int_t indent) const
628{
629// Print task info.
4ff26233 630 Int_t islot;
631 AliAnalysisDataContainer *cont;
632 if (fActive) return;
633 if (!ProducersTouched()) return;
d3106602 634 TString opt(option);
635 opt.ToLower();
636 Bool_t dep = (opt.Contains("dep"))?kTRUE:kFALSE;
637 TString ind;
d3106602 638 for (Int_t i=0; i<indent; i++) ind += " ";
639 if (!dep || (dep && IsChecked())) {
7acc5b9d 640 printf("______________________________________________________________________________\n");
b1310ef5 641 printf("%s\n", Form("%stask: %s ACTIVE=%i POST_LOOP=%i", ind.Data(), GetName(),IsActive(),IsPostEventLoop()));
dcc1f876 642 if (dep) const_cast<AliAnalysisTask*>(this)->SetChecked(kFALSE);
d3106602 643 else {
644 for (islot=0; islot<fNinputs; islot++) {
645 printf("%s", Form("%s INPUT #%i: %s <- ",ind.Data(),islot, GetInputType(islot)->GetName()));
646 cont = GetInputSlot(islot)->GetContainer();
647 if (cont) printf(" [%s]\n", cont->GetName());
648 else printf(" [NO CONTAINER]\n");
649 }
650 for (islot=0; islot<fNoutputs; islot++) {
651 printf("%s", Form("%s OUTPUT #%i: %s -> ",ind.Data(),islot, GetOutputType(islot)->GetName()));
652 cont = GetOutputSlot(islot)->GetContainer();
653 if (cont) printf(" [%s]\n", cont->GetName());
654 else printf(" [NO CONTAINER]\n");
655 }
656 }
657 }
4ff26233 658 ((AliAnalysisTask*)this)->SetActive(kTRUE);
d3106602 659 PrintContainers(option, indent+3);
4ff26233 660 if (!fBranchNames.IsNull()) printf("%sRequested branches: %s\n", ind.Data(), fBranchNames.Data());
d3106602 661}
662
663//______________________________________________________________________________
664void AliAnalysisTask::PrintContainers(Option_t *option, Int_t indent) const
665{
666// Print containers info.
667 AliAnalysisDataContainer *cont;
668 TString ind;
669 for (Int_t i=0; i<indent; i++) ind += " ";
670 Int_t islot;
671 for (islot=0; islot<fNoutputs; islot++) {
672 cont = GetOutputSlot(islot)->GetContainer();
efd53803 673 if (cont) cont->PrintContainer(option, indent);
d3106602 674 }
675}
efd53803 676
677//______________________________________________________________________________
b1310ef5 678void AliAnalysisTask::SetPostEventLoop(Bool_t flag)
efd53803 679{
b1310ef5 680// Set the task execution mode - run after event loop or not. All output
efd53803 681// containers of this task will get the same type.
b1310ef5 682 TObject::SetBit(kTaskPostEventLoop,flag);
efd53803 683 AliAnalysisDataContainer *cont;
684 Int_t islot;
685 for (islot=0; islot<fNoutputs; islot++) {
686 cont = GetOutputSlot(islot)->GetContainer();
b1310ef5 687 if (cont) cont->SetPostEventLoop(flag);
efd53803 688 }
689}
690
7acc5b9d 691//______________________________________________________________________________
692void AliAnalysisTask::GetBranches(const char *type, TString &result) const
693{
694// Get the list of branches for a given type (ESD, AOD). The list of branches
695// requested by a task has to ve declared in the form:
696// SetBranches("ESD:branch1,branch2,...,branchN AOD:branch1,branch2,...,branchM")
697 result = "";
698 if (fBranchNames.IsNull()) return;
699 Int_t index1 = fBranchNames.Index(type);
700 if (index1<0) return;
701 index1 += 1+strlen(type);
702 Int_t index2 = fBranchNames.Index(" ", index1);
703 if (index2<0) index2 = fBranchNames.Length();
704 result = fBranchNames(index1, index2-index1);
705}