]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliAnalysisTask.cxx
Enable the outlier identification in ZDC vs V0 space (Alberica)
[u/mrichter/AliRoot.git] / 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.
263 AliAnalysisDataContainer *coutput;
b2fce16b 264 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
4747b4a7 265 for (Int_t islot=0; islot<fNoutputs; islot++) {
266 coutput = GetOutputSlot(islot)->GetContainer();
b2fce16b 267 if (!mgr->GetOutputs()->FindObject(coutput)) continue;
4747b4a7 268 if (!coutput->GetData()) return kFALSE;
269 }
b2fce16b 270 CheckOwnership();
4747b4a7 271 return kTRUE;
272}
273
b2fce16b 274//______________________________________________________________________________
275Bool_t AliAnalysisTask::CheckOwnership() const
276{
277// Check ownership of containers posted on output slots (1 level only)
278 TObject *outdata;
279 for (Int_t islot=0; islot<fNoutputs; islot++) {
280 outdata = GetOutputData(islot);
281 if (outdata && outdata->InheritsFrom(TCollection::Class())) {
282 TCollection *coll = (TCollection*)outdata;
283 if (!coll->IsOwner()) {
284 Error("CheckOwnership","####### IMPORTANT! ####### \n\n\n\
285 Task %s (%s) posts a container that is not owner at output #%d. This may apply for other embedded containers. \n\n\
286 ####### FIX YOUR CODE, THIS WILL PRODUCE A FATAL ERROR IN FUTURE! ##########", GetName(), ClassName(), islot);
287 return kFALSE;
288 }
289 }
290 }
291 return kTRUE;
292}
293
d3106602 294//______________________________________________________________________________
295Bool_t AliAnalysisTask::ConnectInput(Int_t islot, AliAnalysisDataContainer *cont)
296{
297// Connect an input slot to a data container.
298 AliAnalysisDataSlot *input = GetInputSlot(islot);
299 if (!input) {
c52c2132 300 Error("ConnectInput","Input slot %i not defined for analysis task %s", islot, GetName());
d3106602 301 return kFALSE;
302 }
303 // Check type matching
304 if (!input->GetType()->InheritsFrom(cont->GetType())) {
c52c2132 305 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 306 return kFALSE;
307 }
308 // Connect the slot to the container as input
309 if (!input->ConnectContainer(cont)) return kFALSE;
310 // Add this to the list of container consumers
311 cont->AddConsumer(this, islot);
312 AreSlotsConnected();
313 return kTRUE;
314}
315
316//______________________________________________________________________________
317Bool_t AliAnalysisTask::ConnectOutput(Int_t islot, AliAnalysisDataContainer *cont)
318{
319// Connect an output slot to a data container.
320 AliAnalysisDataSlot *output = GetOutputSlot(islot);
321 if (!output) {
c52c2132 322 Error("ConnectOutput","Output slot %i not defined for analysis task %s", islot, GetName());
d3106602 323 return kFALSE;
324 }
325 // Check type matching
326 if (!output->GetType()->InheritsFrom(cont->GetType())) {
c52c2132 327 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 328 return kFALSE;
329 }
330 // Connect the slot to the container as output
331 if (!output->ConnectContainer(cont)) return kFALSE;
b1310ef5 332 // Set event loop type the same as for the task
333 cont->SetPostEventLoop(IsPostEventLoop());
d3106602 334 // Declare this as the data producer
335 cont->SetProducer(this, islot);
336 AreSlotsConnected();
337 return kTRUE;
338}
339
340//______________________________________________________________________________
341void AliAnalysisTask::DefineInput(Int_t islot, TClass *type)
342{
343// Define an input slot and its type.
344 AliAnalysisDataSlot *input = new AliAnalysisDataSlot(type, this);
345 if (fNinputs<islot+1) fNinputs = islot+1;
6ae18197 346 fInputs->AddAtAndExpand(input, islot);
d3106602 347}
348
349//______________________________________________________________________________
350void AliAnalysisTask::DefineOutput(Int_t islot, TClass *type)
351{
352// Define an output slot and its type.
d3106602 353 AliAnalysisDataSlot *output = new AliAnalysisDataSlot(type, this);
354 if (fNoutputs<islot+1) {
355 fNoutputs = islot+1;
356 if (fOutputReady) delete [] fOutputReady;
357 fOutputReady = new Bool_t[fNoutputs];
358 memset(fOutputReady, 0, fNoutputs*sizeof(Bool_t));
359 }
6ae18197 360 fOutputs->AddAtAndExpand(output, islot);
d3106602 361}
362
363//______________________________________________________________________________
364TClass *AliAnalysisTask::GetInputType(Int_t islot) const
365{
366// Retreive type of a given input slot.
367 AliAnalysisDataSlot *input = GetInputSlot(islot);
368 if (!input) {
c52c2132 369 Error("GetInputType","Input slot %d not defined for analysis task %s", islot, GetName());
d3106602 370 return NULL;
371 }
372 return (input->GetType());
373}
374
375//______________________________________________________________________________
376TClass *AliAnalysisTask::GetOutputType(Int_t islot) const
377{
378// Retreive type of a given output slot.
379 AliAnalysisDataSlot *output = GetOutputSlot(islot);
380 if (!output) {
c52c2132 381 Error("GetOutputType","Output slot %d not defined for analysis task %s", islot, GetName());
d3106602 382 return NULL;
383 }
384 return (output->GetType());
385}
386
387//______________________________________________________________________________
388TObject *AliAnalysisTask::GetInputData(Int_t islot) const
389{
390// Retreive input data for a slot if ready. Normally called by Exec() and
391// the object has to be statically cast to the appropriate type.
392 AliAnalysisDataSlot *input = GetInputSlot(islot);
393 if (!input) {
c52c2132 394 Error("GetInputData","Input slot %d not defined for analysis task %s", islot, GetName());
d3106602 395 return NULL;
396 }
397 return (input->GetData());
398}
399
c52c2132 400//______________________________________________________________________________
401TObject *AliAnalysisTask::GetOutputData(Int_t islot) const
402{
403// Retreive output data for a slot. Normally called in UserTask::Terminate to
404// get a valid pointer to data even in case of Proof.
405 AliAnalysisDataSlot *output = GetOutputSlot(islot);
406 if (!output) {
407 Error("GetOutputData","Input slot %d not defined for analysis task %s", islot, GetName());
408 return NULL;
409 }
410 return (output->GetData());
411}
412
327eaf46 413//______________________________________________________________________________
414char *AliAnalysisTask::GetBranchAddress(Int_t islot, const char *branch) const
415{
416// Check if a branch with a given name from the specified input is connected
417// to some address. Call this in Init() before trying to call SetBranchAddress()
418// since the adress may be set by other task.
419 return (char *)GetInputSlot(islot)->GetBranchAddress(branch);
420}
421
422//______________________________________________________________________________
423Bool_t AliAnalysisTask::SetBranchAddress(Int_t islot, const char *branch, void *address) const
424{
425// Connect an object address to a branch of the specified input.
426 return GetInputSlot(islot)->SetBranchAddress(branch, address);
427}
428
b1310ef5 429//______________________________________________________________________________
430void AliAnalysisTask::EnableBranch(Int_t islot, const char *bname) const
431{
432// Call this in ConnectInputData() to enable only the branches needed by this
433// task. "*" will enable everything.
434 AliAnalysisDataSlot *input = GetInputSlot(islot);
435 if (!input || !input->GetType()->InheritsFrom(TTree::Class())) {
436 Error("EnableBranch", "Wrong slot type #%d for task %s: not TTree-derived type", islot, GetName());
437 return;
438 }
439 TTree *tree = (TTree*)input->GetData();
440 if (!strcmp(bname, "*")) {
441 tree->SetBranchStatus("*",1);
442 return;
443 }
444 AliAnalysisDataSlot::EnableBranch(bname, tree);
445}
8508e09f 446
447//______________________________________________________________________________
8d7d3b59 448void AliAnalysisTask::FinishTaskOutput()
8508e09f 449{
8d7d3b59 450// Optional method that is called in SlaveTerminate phase.
451// Used for calling aditional methods just after the last event was processed ON
452// THE WORKING NODE. The call is made also in local case.
453// Do NOT delete output objects here since they will have to be sent for
454// merging in PROOF mode - use class destructor for cleanup.
8508e09f 455}
b1310ef5 456
327eaf46 457//______________________________________________________________________________
c52c2132 458void AliAnalysisTask::ConnectInputData(Option_t *)
327eaf46 459{
c52c2132 460// Overload and connect your branches here.
327eaf46 461}
462
9b33830a 463//______________________________________________________________________________
464void AliAnalysisTask::LocalInit()
465{
466// The method LocalInit() may be implemented to call locally (on the client)
467// all initialization methods of the class. It is not mandatory and was created
468// in order to minimize the complexity and readability of the analysis macro.
469// DO NOT create in this method the histigrams or task output objects that will
470// go in the task output containers. Use CreateOutputObjects for that.
471}
472
327eaf46 473//______________________________________________________________________________
c52c2132 474void AliAnalysisTask::CreateOutputObjects()
327eaf46 475{
981f2614 476// Called once per task either in PROOF or local mode. Overload to put some
477// task initialization and/or create your output objects here.
478}
479
c5a87c56 480//______________________________________________________________________________
13ef3bb0 481TFile *AliAnalysisTask::OpenFile(Int_t iout, Option_t *option) const
c5a87c56 482{
483// This method has to be called INSIDE the user redefined CreateOutputObjects
484// method, before creating each object corresponding to the output containers
485// that are to be written to a file. This need to be done in general for the big output
486// objects that may not fit memory during processing.
487// - 'option' is the file opening option.
488//=========================================================================
489// NOTE !: The method call will be ignored in PROOF mode, in which case the
490// results have to be streamed back to the client and written just before Terminate()
491//=========================================================================
492//
493// Example:
494// void MyAnaTask::CreateOutputObjects() {
495// OpenFile(0); // Will open the file for the object to be written at output #0
496// fAOD = new TTree("AOD for D0toKPi");
497// OpenFile(1);
498// now some histos that should go in the file of the second output container
499// fHist1 = new TH1F("my quality check hist1",...);
500// fHist2 = new TH2F("my quality check hist2",...);
501// }
502
13ef3bb0 503 if (iout<0 || iout>=fNoutputs) {
504 Error("OpenFile", "No output slot for task %s with index %d", GetName(), iout);
505 return NULL;
506 }
84fcd93f 507 // Method delegated to the analysis manager (A.G. 02/11/09)
c5a87c56 508 AliAnalysisDataContainer *cont = GetOutputSlot(iout)->GetContainer();
84fcd93f 509 return AliAnalysisManager::OpenFile(cont, option);
c5a87c56 510}
511
981f2614 512//______________________________________________________________________________
513Bool_t AliAnalysisTask::Notify()
514{
515// Overload this IF you need to treat input file change.
516 return kTRUE;
327eaf46 517}
518
aee5ee44 519//______________________________________________________________________________
520Bool_t AliAnalysisTask::NotifyBinChange()
521{
522// Overload this IF you need to treat bin change in event mixing.
523 return kTRUE;
524}
525
327eaf46 526//______________________________________________________________________________
c52c2132 527void AliAnalysisTask::Terminate(Option_t *)
327eaf46 528{
c52c2132 529// Method called by the framework at the end of data processing.
530}
327eaf46 531
d3106602 532//______________________________________________________________________________
533Bool_t AliAnalysisTask::PostData(Int_t iout, TObject *data, Option_t *option)
534{
535// Post output data for a given ouput slot in the corresponding data container.
536// Published data becomes owned by the data container.
537// If option is specified, the container connected to the output slot must have
538// an associated file name defined. The option represents the method to open the file.
539 fPublishedData = 0;
540 AliAnalysisDataSlot *output = GetOutputSlot(iout);
541 if (!output) {
c52c2132 542 Error("PostData","Output slot %i not defined for analysis task %s", iout, GetName());
d3106602 543 return kFALSE;
544 }
545 if (!output->IsConnected()) {
c52c2132 546 Error("PostData","Output slot %i of analysis task %s not connected to any data container", iout, GetName());
d3106602 547 return kFALSE;
548 }
549 if (!fOutputReady) {
550 fOutputReady = new Bool_t[fNoutputs];
551 memset(fOutputReady, 0, fNoutputs*sizeof(Bool_t));
552 }
553 fOutputReady[iout] = kTRUE;
554 fPublishedData = data;
555 return (output->GetContainer()->SetData(data, option));
556}
557
558//______________________________________________________________________________
559void AliAnalysisTask::SetUsed(Bool_t flag)
560{
561// Set 'used' flag recursively to task and all daughter tasks.
562 if (TestBit(kTaskUsed)==flag) return;
563 TObject::SetBit(kTaskUsed,flag);
564 Int_t nd = fTasks->GetSize();
565 AliAnalysisTask *task;
566 for (Int_t i=0; i<nd; i++) {
567 task = (AliAnalysisTask*)fTasks->At(i);
568 task->SetUsed(flag);
569 }
570}
571
572//______________________________________________________________________________
573Bool_t AliAnalysisTask::CheckCircularDeps()
574{
575// Check for illegal circular dependencies, e.g. a daughter task should not have
576// a hierarchical parent as subtask.
577 if (IsChecked()) return kTRUE;
578 SetChecked();
579 TList *tasks = GetListOfTasks();
580 Int_t ntasks = tasks->GetSize();
581 AliAnalysisTask *task;
582 for (Int_t i=0; i<ntasks; i++) {
583 task = (AliAnalysisTask*)tasks->At(i);
584 if (task->CheckCircularDeps()) return kTRUE;
585 }
586 SetChecked(kFALSE);
587 return kFALSE;
588}
589
590//______________________________________________________________________________
591void AliAnalysisTask::PrintTask(Option_t *option, Int_t indent) const
592{
593// Print task info.
d3106602 594 TString opt(option);
595 opt.ToLower();
596 Bool_t dep = (opt.Contains("dep"))?kTRUE:kFALSE;
597 TString ind;
598 Int_t islot;
599 AliAnalysisDataContainer *cont;
600 for (Int_t i=0; i<indent; i++) ind += " ";
601 if (!dep || (dep && IsChecked())) {
7acc5b9d 602 printf("______________________________________________________________________________\n");
b1310ef5 603 printf("%s\n", Form("%stask: %s ACTIVE=%i POST_LOOP=%i", ind.Data(), GetName(),IsActive(),IsPostEventLoop()));
dcc1f876 604 if (dep) const_cast<AliAnalysisTask*>(this)->SetChecked(kFALSE);
d3106602 605 else {
606 for (islot=0; islot<fNinputs; islot++) {
607 printf("%s", Form("%s INPUT #%i: %s <- ",ind.Data(),islot, GetInputType(islot)->GetName()));
608 cont = GetInputSlot(islot)->GetContainer();
609 if (cont) printf(" [%s]\n", cont->GetName());
610 else printf(" [NO CONTAINER]\n");
611 }
612 for (islot=0; islot<fNoutputs; islot++) {
613 printf("%s", Form("%s OUTPUT #%i: %s -> ",ind.Data(),islot, GetOutputType(islot)->GetName()));
614 cont = GetOutputSlot(islot)->GetContainer();
615 if (cont) printf(" [%s]\n", cont->GetName());
616 else printf(" [NO CONTAINER]\n");
617 }
618 }
619 }
620 PrintContainers(option, indent+3);
7acc5b9d 621 if (!fBranchNames.IsNull()) printf("Requested branches: %s\n", fBranchNames.Data());
d3106602 622}
623
624//______________________________________________________________________________
625void AliAnalysisTask::PrintContainers(Option_t *option, Int_t indent) const
626{
627// Print containers info.
628 AliAnalysisDataContainer *cont;
629 TString ind;
630 for (Int_t i=0; i<indent; i++) ind += " ";
631 Int_t islot;
632 for (islot=0; islot<fNoutputs; islot++) {
633 cont = GetOutputSlot(islot)->GetContainer();
efd53803 634 if (cont) cont->PrintContainer(option, indent);
d3106602 635 }
636}
efd53803 637
638//______________________________________________________________________________
b1310ef5 639void AliAnalysisTask::SetPostEventLoop(Bool_t flag)
efd53803 640{
b1310ef5 641// Set the task execution mode - run after event loop or not. All output
efd53803 642// containers of this task will get the same type.
b1310ef5 643 TObject::SetBit(kTaskPostEventLoop,flag);
efd53803 644 AliAnalysisDataContainer *cont;
645 Int_t islot;
646 for (islot=0; islot<fNoutputs; islot++) {
647 cont = GetOutputSlot(islot)->GetContainer();
b1310ef5 648 if (cont) cont->SetPostEventLoop(flag);
efd53803 649 }
650}
651
7acc5b9d 652//______________________________________________________________________________
653void AliAnalysisTask::GetBranches(const char *type, TString &result) const
654{
655// Get the list of branches for a given type (ESD, AOD). The list of branches
656// requested by a task has to ve declared in the form:
657// SetBranches("ESD:branch1,branch2,...,branchN AOD:branch1,branch2,...,branchM")
658 result = "";
659 if (fBranchNames.IsNull()) return;
660 Int_t index1 = fBranchNames.Index(type);
661 if (index1<0) return;
662 index1 += 1+strlen(type);
663 Int_t index2 = fBranchNames.Index(" ", index1);
664 if (index2<0) index2 = fBranchNames.Length();
665 result = fBranchNames(index1, index2-index1);
666}