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