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