Protected cases when the user forgot to load the library. Error poster if user forget...
[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>
b1310ef5 103#include <TTree.h>
8e6e6fe8 104#include <TROOT.h>
d3106602 105
d3106602 106#include "AliAnalysisTask.h"
107#include "AliAnalysisDataSlot.h"
108#include "AliAnalysisDataContainer.h"
c5a87c56 109#include "AliAnalysisManager.h"
d3106602 110
111ClassImp(AliAnalysisTask)
112
113//______________________________________________________________________________
114AliAnalysisTask::AliAnalysisTask()
37a26056 115 :fReady(kFALSE),
327eaf46 116 fInitialized(kFALSE),
37a26056 117 fNinputs(0),
118 fNoutputs(0),
119 fOutputReady(NULL),
120 fPublishedData(NULL),
121 fInputs(NULL),
7acc5b9d 122 fOutputs(NULL),
123 fBranchNames()
d3106602 124{
125// Default constructor.
d3106602 126}
127
128//______________________________________________________________________________
129AliAnalysisTask::AliAnalysisTask(const char *name, const char *title)
37a26056 130 :TTask(name,title),
131 fReady(kFALSE),
327eaf46 132 fInitialized(kFALSE),
37a26056 133 fNinputs(0),
134 fNoutputs(0),
135 fOutputReady(NULL),
136 fPublishedData(NULL),
137 fInputs(NULL),
7acc5b9d 138 fOutputs(NULL),
139 fBranchNames()
d3106602 140{
37a26056 141// Constructor.
d3106602 142 fInputs = new TObjArray(2);
143 fOutputs = new TObjArray(2);
144}
145
146//______________________________________________________________________________
147AliAnalysisTask::AliAnalysisTask(const AliAnalysisTask &task)
37a26056 148 :TTask(task),
149 fReady(task.fReady),
327eaf46 150 fInitialized(task.fInitialized),
37a26056 151 fNinputs(task.fNinputs),
152 fNoutputs(task.fNoutputs),
153 fOutputReady(NULL),
154 fPublishedData(NULL),
155 fInputs(NULL),
7acc5b9d 156 fOutputs(NULL),
157 fBranchNames(task.fBranchNames)
d3106602 158{
159// Copy ctor.
d3106602 160 fInputs = new TObjArray((fNinputs)?fNinputs:2);
161 fOutputs = new TObjArray((fNoutputs)?fNoutputs:2);
162 fPublishedData = 0;
163 Int_t i;
164 for (i=0; i<fNinputs; i++) fInputs->AddAt(task.GetInputSlot(i),i);
165 fOutputReady = new Bool_t[(fNoutputs)?fNoutputs:2];
166 for (i=0; i<fNoutputs; i++) {
167 fOutputReady[i] = IsOutputReady(i);
168 fOutputs->AddAt(task.GetOutputSlot(i),i);
169 }
170}
171
172//______________________________________________________________________________
173AliAnalysisTask::~AliAnalysisTask()
174{
175// Dtor.
c52c2132 176 if (fTasks) fTasks->Clear();
d3106602 177 if (fInputs) {fInputs->Delete(); delete fInputs;}
178 if (fOutputs) {fOutputs->Delete(); delete fOutputs;}
179}
180
181//______________________________________________________________________________
182AliAnalysisTask& AliAnalysisTask::operator=(const AliAnalysisTask& task)
183{
184// Assignment
37a26056 185 if (&task == this) return *this;
186 TTask::operator=(task);
187 fReady = task.IsReady();
327eaf46 188 fInitialized = task.IsInitialized();
37a26056 189 fNinputs = task.GetNinputs();
190 fNoutputs = task.GetNoutputs();
191 fInputs = new TObjArray((fNinputs)?fNinputs:2);
192 fOutputs = new TObjArray((fNoutputs)?fNoutputs:2);
193 fPublishedData = 0;
194 Int_t i;
195 for (i=0; i<fNinputs; i++) fInputs->AddAt(new AliAnalysisDataSlot(*task.GetInputSlot(i)),i);
196 fOutputReady = new Bool_t[(fNoutputs)?fNoutputs:2];
197 for (i=0; i<fNoutputs; i++) {
198 fOutputReady[i] = IsOutputReady(i);
199 fOutputs->AddAt(new AliAnalysisDataSlot(*task.GetOutputSlot(i)),i);
200 }
7acc5b9d 201 fBranchNames = task.fBranchNames;
d3106602 202 return *this;
203}
204
205//______________________________________________________________________________
206Bool_t AliAnalysisTask::AreSlotsConnected()
207{
208// Check if all input/output slots are connected. If this is the case fReady=true
209 fReady = kFALSE;
210 if (!fNinputs || !fNoutputs) return kFALSE;
211 Int_t i;
212 AliAnalysisDataSlot *slot;
213 for (i=0; i<fNinputs; i++) {
214 slot = (AliAnalysisDataSlot*)fInputs->At(i);
215 if (!slot) {
c52c2132 216 Error("AreSlotsConnected", "Input slot %d of task %s not defined !",i,GetName());
d3106602 217 return kFALSE;
218 }
219 if (!slot->IsConnected()) return kFALSE;
220 }
221 for (i=0; i<fNoutputs; i++) {
222 slot = (AliAnalysisDataSlot*)fOutputs->At(i);
223 if (!slot) {
c52c2132 224 Error("AreSlotsConnected", "Output slot %d of task %s not defined !",i,GetName());
d3106602 225 return kFALSE;
226 }
227 if (!slot->IsConnected()) return kFALSE;
228 }
229 fReady = kTRUE;
230 return kTRUE;
231}
232
233//______________________________________________________________________________
327eaf46 234void AliAnalysisTask::CheckNotify(Bool_t init)
d3106602 235{
236// Check if data is available from all inputs. Change the status of the task
237// accordingly. This method is called automatically for all tasks connected
238// to a container where the data was published.
327eaf46 239 if (init) fInitialized = kFALSE;
b1310ef5 240 Bool_t single_shot = IsPostEventLoop();
efd53803 241 AliAnalysisDataContainer *cinput;
d3106602 242 for (Int_t islot=0; islot<fNinputs; islot++) {
efd53803 243 cinput = GetInputSlot(islot)->GetContainer();
b1310ef5 244 if (!cinput->GetData() || (single_shot && !cinput->IsPostEventLoop())) {
d3106602 245 SetActive(kFALSE);
246 return;
247 }
248 }
249 SetActive(kTRUE);
327eaf46 250 if (fInitialized) return;
251 TDirectory *cursav = gDirectory;
c52c2132 252 ConnectInputData();
327eaf46 253 if (cursav) cursav->cd();
254 fInitialized = kTRUE;
d3106602 255}
256
4747b4a7 257//______________________________________________________________________________
258Bool_t AliAnalysisTask::CheckPostData() const
259{
260// Checks if data was posted to all outputs defined by the task. If task does
261// not have output slots this returns always kTRUE.
262 AliAnalysisDataContainer *coutput;
263 for (Int_t islot=0; islot<fNoutputs; islot++) {
264 coutput = GetOutputSlot(islot)->GetContainer();
265 if (!coutput->GetData()) return kFALSE;
266 }
267 return kTRUE;
268}
269
d3106602 270//______________________________________________________________________________
271Bool_t AliAnalysisTask::ConnectInput(Int_t islot, AliAnalysisDataContainer *cont)
272{
273// Connect an input slot to a data container.
274 AliAnalysisDataSlot *input = GetInputSlot(islot);
275 if (!input) {
c52c2132 276 Error("ConnectInput","Input slot %i not defined for analysis task %s", islot, GetName());
d3106602 277 return kFALSE;
278 }
279 // Check type matching
280 if (!input->GetType()->InheritsFrom(cont->GetType())) {
c52c2132 281 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 282 return kFALSE;
283 }
284 // Connect the slot to the container as input
285 if (!input->ConnectContainer(cont)) return kFALSE;
286 // Add this to the list of container consumers
287 cont->AddConsumer(this, islot);
288 AreSlotsConnected();
289 return kTRUE;
290}
291
292//______________________________________________________________________________
293Bool_t AliAnalysisTask::ConnectOutput(Int_t islot, AliAnalysisDataContainer *cont)
294{
295// Connect an output slot to a data container.
296 AliAnalysisDataSlot *output = GetOutputSlot(islot);
297 if (!output) {
c52c2132 298 Error("ConnectOutput","Output slot %i not defined for analysis task %s", islot, GetName());
d3106602 299 return kFALSE;
300 }
301 // Check type matching
302 if (!output->GetType()->InheritsFrom(cont->GetType())) {
c52c2132 303 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 304 return kFALSE;
305 }
306 // Connect the slot to the container as output
307 if (!output->ConnectContainer(cont)) return kFALSE;
b1310ef5 308 // Set event loop type the same as for the task
309 cont->SetPostEventLoop(IsPostEventLoop());
d3106602 310 // Declare this as the data producer
311 cont->SetProducer(this, islot);
312 AreSlotsConnected();
313 return kTRUE;
314}
315
316//______________________________________________________________________________
317void AliAnalysisTask::DefineInput(Int_t islot, TClass *type)
318{
319// Define an input slot and its type.
320 AliAnalysisDataSlot *input = new AliAnalysisDataSlot(type, this);
321 if (fNinputs<islot+1) fNinputs = islot+1;
6ae18197 322 fInputs->AddAtAndExpand(input, islot);
d3106602 323}
324
325//______________________________________________________________________________
326void AliAnalysisTask::DefineOutput(Int_t islot, TClass *type)
327{
328// Define an output slot and its type.
d3106602 329 AliAnalysisDataSlot *output = new AliAnalysisDataSlot(type, this);
330 if (fNoutputs<islot+1) {
331 fNoutputs = islot+1;
332 if (fOutputReady) delete [] fOutputReady;
333 fOutputReady = new Bool_t[fNoutputs];
334 memset(fOutputReady, 0, fNoutputs*sizeof(Bool_t));
335 }
6ae18197 336 fOutputs->AddAtAndExpand(output, islot);
d3106602 337}
338
339//______________________________________________________________________________
340TClass *AliAnalysisTask::GetInputType(Int_t islot) const
341{
342// Retreive type of a given input slot.
343 AliAnalysisDataSlot *input = GetInputSlot(islot);
344 if (!input) {
c52c2132 345 Error("GetInputType","Input slot %d not defined for analysis task %s", islot, GetName());
d3106602 346 return NULL;
347 }
348 return (input->GetType());
349}
350
351//______________________________________________________________________________
352TClass *AliAnalysisTask::GetOutputType(Int_t islot) const
353{
354// Retreive type of a given output slot.
355 AliAnalysisDataSlot *output = GetOutputSlot(islot);
356 if (!output) {
c52c2132 357 Error("GetOutputType","Output slot %d not defined for analysis task %s", islot, GetName());
d3106602 358 return NULL;
359 }
360 return (output->GetType());
361}
362
363//______________________________________________________________________________
364TObject *AliAnalysisTask::GetInputData(Int_t islot) const
365{
366// Retreive input data for a slot if ready. Normally called by Exec() and
367// the object has to be statically cast to the appropriate type.
368 AliAnalysisDataSlot *input = GetInputSlot(islot);
369 if (!input) {
c52c2132 370 Error("GetInputData","Input slot %d not defined for analysis task %s", islot, GetName());
d3106602 371 return NULL;
372 }
373 return (input->GetData());
374}
375
c52c2132 376//______________________________________________________________________________
377TObject *AliAnalysisTask::GetOutputData(Int_t islot) const
378{
379// Retreive output data for a slot. Normally called in UserTask::Terminate to
380// get a valid pointer to data even in case of Proof.
381 AliAnalysisDataSlot *output = GetOutputSlot(islot);
382 if (!output) {
383 Error("GetOutputData","Input slot %d not defined for analysis task %s", islot, GetName());
384 return NULL;
385 }
386 return (output->GetData());
387}
388
327eaf46 389//______________________________________________________________________________
390char *AliAnalysisTask::GetBranchAddress(Int_t islot, const char *branch) const
391{
392// Check if a branch with a given name from the specified input is connected
393// to some address. Call this in Init() before trying to call SetBranchAddress()
394// since the adress may be set by other task.
395 return (char *)GetInputSlot(islot)->GetBranchAddress(branch);
396}
397
398//______________________________________________________________________________
399Bool_t AliAnalysisTask::SetBranchAddress(Int_t islot, const char *branch, void *address) const
400{
401// Connect an object address to a branch of the specified input.
402 return GetInputSlot(islot)->SetBranchAddress(branch, address);
403}
404
b1310ef5 405//______________________________________________________________________________
406void AliAnalysisTask::EnableBranch(Int_t islot, const char *bname) const
407{
408// Call this in ConnectInputData() to enable only the branches needed by this
409// task. "*" will enable everything.
410 AliAnalysisDataSlot *input = GetInputSlot(islot);
411 if (!input || !input->GetType()->InheritsFrom(TTree::Class())) {
412 Error("EnableBranch", "Wrong slot type #%d for task %s: not TTree-derived type", islot, GetName());
413 return;
414 }
415 TTree *tree = (TTree*)input->GetData();
416 if (!strcmp(bname, "*")) {
417 tree->SetBranchStatus("*",1);
418 return;
419 }
420 AliAnalysisDataSlot::EnableBranch(bname, tree);
421}
8508e09f 422
423//______________________________________________________________________________
8d7d3b59 424void AliAnalysisTask::FinishTaskOutput()
8508e09f 425{
8d7d3b59 426// Optional method that is called in SlaveTerminate phase.
427// Used for calling aditional methods just after the last event was processed ON
428// THE WORKING NODE. The call is made also in local case.
429// Do NOT delete output objects here since they will have to be sent for
430// merging in PROOF mode - use class destructor for cleanup.
8508e09f 431}
b1310ef5 432
327eaf46 433//______________________________________________________________________________
c52c2132 434void AliAnalysisTask::ConnectInputData(Option_t *)
327eaf46 435{
c52c2132 436// Overload and connect your branches here.
327eaf46 437}
438
9b33830a 439//______________________________________________________________________________
440void AliAnalysisTask::LocalInit()
441{
442// The method LocalInit() may be implemented to call locally (on the client)
443// all initialization methods of the class. It is not mandatory and was created
444// in order to minimize the complexity and readability of the analysis macro.
445// DO NOT create in this method the histigrams or task output objects that will
446// go in the task output containers. Use CreateOutputObjects for that.
447}
448
327eaf46 449//______________________________________________________________________________
c52c2132 450void AliAnalysisTask::CreateOutputObjects()
327eaf46 451{
981f2614 452// Called once per task either in PROOF or local mode. Overload to put some
453// task initialization and/or create your output objects here.
454}
455
c5a87c56 456//______________________________________________________________________________
13ef3bb0 457TFile *AliAnalysisTask::OpenFile(Int_t iout, Option_t *option) const
c5a87c56 458{
459// This method has to be called INSIDE the user redefined CreateOutputObjects
460// method, before creating each object corresponding to the output containers
461// that are to be written to a file. This need to be done in general for the big output
462// objects that may not fit memory during processing.
463// - 'option' is the file opening option.
464//=========================================================================
465// NOTE !: The method call will be ignored in PROOF mode, in which case the
466// results have to be streamed back to the client and written just before Terminate()
467//=========================================================================
468//
469// Example:
470// void MyAnaTask::CreateOutputObjects() {
471// OpenFile(0); // Will open the file for the object to be written at output #0
472// fAOD = new TTree("AOD for D0toKPi");
473// OpenFile(1);
474// now some histos that should go in the file of the second output container
475// fHist1 = new TH1F("my quality check hist1",...);
476// fHist2 = new TH2F("my quality check hist2",...);
477// }
478
13ef3bb0 479 if (iout<0 || iout>=fNoutputs) {
480 Error("OpenFile", "No output slot for task %s with index %d", GetName(), iout);
481 return NULL;
482 }
84fcd93f 483 // Method delegated to the analysis manager (A.G. 02/11/09)
c5a87c56 484 AliAnalysisDataContainer *cont = GetOutputSlot(iout)->GetContainer();
84fcd93f 485 return AliAnalysisManager::OpenFile(cont, option);
c5a87c56 486}
487
981f2614 488//______________________________________________________________________________
489Bool_t AliAnalysisTask::Notify()
490{
491// Overload this IF you need to treat input file change.
492 return kTRUE;
327eaf46 493}
494
aee5ee44 495//______________________________________________________________________________
496Bool_t AliAnalysisTask::NotifyBinChange()
497{
498// Overload this IF you need to treat bin change in event mixing.
499 return kTRUE;
500}
501
327eaf46 502//______________________________________________________________________________
c52c2132 503void AliAnalysisTask::Terminate(Option_t *)
327eaf46 504{
c52c2132 505// Method called by the framework at the end of data processing.
506}
327eaf46 507
d3106602 508//______________________________________________________________________________
509Bool_t AliAnalysisTask::PostData(Int_t iout, TObject *data, Option_t *option)
510{
511// Post output data for a given ouput slot in the corresponding data container.
512// Published data becomes owned by the data container.
513// If option is specified, the container connected to the output slot must have
514// an associated file name defined. The option represents the method to open the file.
515 fPublishedData = 0;
516 AliAnalysisDataSlot *output = GetOutputSlot(iout);
517 if (!output) {
c52c2132 518 Error("PostData","Output slot %i not defined for analysis task %s", iout, GetName());
d3106602 519 return kFALSE;
520 }
521 if (!output->IsConnected()) {
c52c2132 522 Error("PostData","Output slot %i of analysis task %s not connected to any data container", iout, GetName());
d3106602 523 return kFALSE;
524 }
525 if (!fOutputReady) {
526 fOutputReady = new Bool_t[fNoutputs];
527 memset(fOutputReady, 0, fNoutputs*sizeof(Bool_t));
528 }
529 fOutputReady[iout] = kTRUE;
530 fPublishedData = data;
531 return (output->GetContainer()->SetData(data, option));
532}
533
534//______________________________________________________________________________
535void AliAnalysisTask::SetUsed(Bool_t flag)
536{
537// Set 'used' flag recursively to task and all daughter tasks.
538 if (TestBit(kTaskUsed)==flag) return;
539 TObject::SetBit(kTaskUsed,flag);
540 Int_t nd = fTasks->GetSize();
541 AliAnalysisTask *task;
542 for (Int_t i=0; i<nd; i++) {
543 task = (AliAnalysisTask*)fTasks->At(i);
544 task->SetUsed(flag);
545 }
546}
547
548//______________________________________________________________________________
549Bool_t AliAnalysisTask::CheckCircularDeps()
550{
551// Check for illegal circular dependencies, e.g. a daughter task should not have
552// a hierarchical parent as subtask.
553 if (IsChecked()) return kTRUE;
554 SetChecked();
555 TList *tasks = GetListOfTasks();
556 Int_t ntasks = tasks->GetSize();
557 AliAnalysisTask *task;
558 for (Int_t i=0; i<ntasks; i++) {
559 task = (AliAnalysisTask*)tasks->At(i);
560 if (task->CheckCircularDeps()) return kTRUE;
561 }
562 SetChecked(kFALSE);
563 return kFALSE;
564}
565
566//______________________________________________________________________________
567void AliAnalysisTask::PrintTask(Option_t *option, Int_t indent) const
568{
569// Print task info.
d3106602 570 TString opt(option);
571 opt.ToLower();
572 Bool_t dep = (opt.Contains("dep"))?kTRUE:kFALSE;
573 TString ind;
574 Int_t islot;
575 AliAnalysisDataContainer *cont;
576 for (Int_t i=0; i<indent; i++) ind += " ";
577 if (!dep || (dep && IsChecked())) {
7acc5b9d 578 printf("______________________________________________________________________________\n");
b1310ef5 579 printf("%s\n", Form("%stask: %s ACTIVE=%i POST_LOOP=%i", ind.Data(), GetName(),IsActive(),IsPostEventLoop()));
dcc1f876 580 if (dep) const_cast<AliAnalysisTask*>(this)->SetChecked(kFALSE);
d3106602 581 else {
582 for (islot=0; islot<fNinputs; islot++) {
583 printf("%s", Form("%s INPUT #%i: %s <- ",ind.Data(),islot, GetInputType(islot)->GetName()));
584 cont = GetInputSlot(islot)->GetContainer();
585 if (cont) printf(" [%s]\n", cont->GetName());
586 else printf(" [NO CONTAINER]\n");
587 }
588 for (islot=0; islot<fNoutputs; islot++) {
589 printf("%s", Form("%s OUTPUT #%i: %s -> ",ind.Data(),islot, GetOutputType(islot)->GetName()));
590 cont = GetOutputSlot(islot)->GetContainer();
591 if (cont) printf(" [%s]\n", cont->GetName());
592 else printf(" [NO CONTAINER]\n");
593 }
594 }
595 }
596 PrintContainers(option, indent+3);
7acc5b9d 597 if (!fBranchNames.IsNull()) printf("Requested branches: %s\n", fBranchNames.Data());
d3106602 598}
599
600//______________________________________________________________________________
601void AliAnalysisTask::PrintContainers(Option_t *option, Int_t indent) const
602{
603// Print containers info.
604 AliAnalysisDataContainer *cont;
605 TString ind;
606 for (Int_t i=0; i<indent; i++) ind += " ";
607 Int_t islot;
608 for (islot=0; islot<fNoutputs; islot++) {
609 cont = GetOutputSlot(islot)->GetContainer();
efd53803 610 if (cont) cont->PrintContainer(option, indent);
d3106602 611 }
612}
efd53803 613
614//______________________________________________________________________________
b1310ef5 615void AliAnalysisTask::SetPostEventLoop(Bool_t flag)
efd53803 616{
b1310ef5 617// Set the task execution mode - run after event loop or not. All output
efd53803 618// containers of this task will get the same type.
b1310ef5 619 TObject::SetBit(kTaskPostEventLoop,flag);
efd53803 620 AliAnalysisDataContainer *cont;
621 Int_t islot;
622 for (islot=0; islot<fNoutputs; islot++) {
623 cont = GetOutputSlot(islot)->GetContainer();
b1310ef5 624 if (cont) cont->SetPostEventLoop(flag);
efd53803 625 }
626}
627
7acc5b9d 628//______________________________________________________________________________
629void AliAnalysisTask::GetBranches(const char *type, TString &result) const
630{
631// Get the list of branches for a given type (ESD, AOD). The list of branches
632// requested by a task has to ve declared in the form:
633// SetBranches("ESD:branch1,branch2,...,branchN AOD:branch1,branch2,...,branchM")
634 result = "";
635 if (fBranchNames.IsNull()) return;
636 Int_t index1 = fBranchNames.Index(type);
637 if (index1<0) return;
638 index1 += 1+strlen(type);
639 Int_t index2 = fBranchNames.Index(" ", index1);
640 if (index2<0) index2 = fBranchNames.Length();
641 result = fBranchNames(index1, index2-index1);
642}