]>
Commit | Line | Data |
---|---|---|
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 | // AliAnalysysManager - Manager analysis class. Allows creation of several | |
37153431 | 21 | // analysis tasks and data containers storing their input/output. Allows |
d3106602 | 22 | // connecting/chaining tasks via shared data containers. Serializes the current |
23 | // event for all tasks depending only on initial input data. | |
24 | //============================================================================== | |
25 | // | |
26 | //============================================================================== | |
27 | ||
c52c2132 | 28 | #include <Riostream.h> |
11026a80 | 29 | |
c52c2132 | 30 | #include <TClass.h> |
31 | #include <TFile.h> | |
32 | #include <TMethodCall.h> | |
33 | #include <TChain.h> | |
34 | #include <TSystem.h> | |
35 | #include <TROOT.h> | |
8c0ab8e8 | 36 | #include <TCanvas.h> |
d3106602 | 37 | |
8d7d3b59 | 38 | #include "AliAnalysisSelector.h" |
d3106602 | 39 | #include "AliAnalysisTask.h" |
40 | #include "AliAnalysisDataContainer.h" | |
41 | #include "AliAnalysisDataSlot.h" | |
d2f1d9ef | 42 | #include "AliVEventHandler.h" |
c2922515 | 43 | #include "AliVEventPool.h" |
8c0ab8e8 | 44 | #include "AliSysInfo.h" |
c52c2132 | 45 | #include "AliAnalysisManager.h" |
d3106602 | 46 | |
47 | ClassImp(AliAnalysisManager) | |
48 | ||
c52c2132 | 49 | AliAnalysisManager *AliAnalysisManager::fgAnalysisManager = NULL; |
50 | ||
c52c2132 | 51 | //______________________________________________________________________________ |
52 | AliAnalysisManager::AliAnalysisManager(const char *name, const char *title) | |
53 | :TNamed(name,title), | |
54 | fTree(NULL), | |
8c0ab8e8 | 55 | fInputEventHandler(NULL), |
56 | fOutputEventHandler(NULL), | |
57 | fMCtruthEventHandler(NULL), | |
c2922515 | 58 | fEventPool(NULL), |
c52c2132 | 59 | fCurrentEntry(-1), |
8c0ab8e8 | 60 | fNSysInfo(0), |
c52c2132 | 61 | fMode(kLocalAnalysis), |
62 | fInitOK(kFALSE), | |
63 | fDebug(0), | |
26f071d8 | 64 | fSpecialOutputLocation(""), |
37a26056 | 65 | fTasks(NULL), |
66 | fTopTasks(NULL), | |
c52c2132 | 67 | fZombies(NULL), |
68 | fContainers(NULL), | |
69 | fInputs(NULL), | |
8d7d3b59 | 70 | fOutputs(NULL), |
71 | fSelector(NULL) | |
d3106602 | 72 | { |
73 | // Default constructor. | |
c52c2132 | 74 | fgAnalysisManager = this; |
75 | fTasks = new TObjArray(); | |
76 | fTopTasks = new TObjArray(); | |
77 | fZombies = new TObjArray(); | |
78 | fContainers = new TObjArray(); | |
79 | fInputs = new TObjArray(); | |
37153431 | 80 | fOutputs = new TObjArray(); |
b1310ef5 | 81 | SetEventLoop(kTRUE); |
d3106602 | 82 | } |
83 | ||
84 | //______________________________________________________________________________ | |
85 | AliAnalysisManager::AliAnalysisManager(const AliAnalysisManager& other) | |
c52c2132 | 86 | :TNamed(other), |
327eaf46 | 87 | fTree(NULL), |
8c0ab8e8 | 88 | fInputEventHandler(NULL), |
89 | fOutputEventHandler(NULL), | |
90 | fMCtruthEventHandler(NULL), | |
c2922515 | 91 | fEventPool(NULL), |
c52c2132 | 92 | fCurrentEntry(-1), |
8c0ab8e8 | 93 | fNSysInfo(0), |
c52c2132 | 94 | fMode(other.fMode), |
95 | fInitOK(other.fInitOK), | |
96 | fDebug(other.fDebug), | |
26f071d8 | 97 | fSpecialOutputLocation(""), |
37a26056 | 98 | fTasks(NULL), |
99 | fTopTasks(NULL), | |
c52c2132 | 100 | fZombies(NULL), |
101 | fContainers(NULL), | |
102 | fInputs(NULL), | |
8d7d3b59 | 103 | fOutputs(NULL), |
104 | fSelector(NULL) | |
d3106602 | 105 | { |
106 | // Copy constructor. | |
37a26056 | 107 | fTasks = new TObjArray(*other.fTasks); |
108 | fTopTasks = new TObjArray(*other.fTopTasks); | |
109 | fZombies = new TObjArray(*other.fZombies); | |
c52c2132 | 110 | fContainers = new TObjArray(*other.fContainers); |
111 | fInputs = new TObjArray(*other.fInputs); | |
112 | fOutputs = new TObjArray(*other.fOutputs); | |
113 | fgAnalysisManager = this; | |
d3106602 | 114 | } |
115 | ||
116 | //______________________________________________________________________________ | |
117 | AliAnalysisManager& AliAnalysisManager::operator=(const AliAnalysisManager& other) | |
118 | { | |
119 | // Assignment | |
120 | if (&other != this) { | |
c52c2132 | 121 | TNamed::operator=(other); |
54cff064 | 122 | fInputEventHandler = other.fInputEventHandler; |
6bb2b24f | 123 | fOutputEventHandler = other.fOutputEventHandler; |
124 | fMCtruthEventHandler = other.fMCtruthEventHandler; | |
c2922515 | 125 | fEventPool = other.fEventPool; |
c52c2132 | 126 | fTree = NULL; |
127 | fCurrentEntry = -1; | |
8c0ab8e8 | 128 | fNSysInfo = other.fNSysInfo; |
c52c2132 | 129 | fMode = other.fMode; |
37a26056 | 130 | fInitOK = other.fInitOK; |
c52c2132 | 131 | fDebug = other.fDebug; |
37a26056 | 132 | fTasks = new TObjArray(*other.fTasks); |
133 | fTopTasks = new TObjArray(*other.fTopTasks); | |
134 | fZombies = new TObjArray(*other.fZombies); | |
c52c2132 | 135 | fContainers = new TObjArray(*other.fContainers); |
136 | fInputs = new TObjArray(*other.fInputs); | |
137 | fOutputs = new TObjArray(*other.fOutputs); | |
8d7d3b59 | 138 | fSelector = NULL; |
c52c2132 | 139 | fgAnalysisManager = this; |
d3106602 | 140 | } |
141 | return *this; | |
142 | } | |
143 | ||
144 | //______________________________________________________________________________ | |
145 | AliAnalysisManager::~AliAnalysisManager() | |
146 | { | |
147 | // Destructor. | |
d3106602 | 148 | if (fTasks) {fTasks->Delete(); delete fTasks;} |
149 | if (fTopTasks) delete fTopTasks; | |
150 | if (fZombies) delete fZombies; | |
c52c2132 | 151 | if (fContainers) {fContainers->Delete(); delete fContainers;} |
152 | if (fInputs) delete fInputs; | |
153 | if (fOutputs) delete fOutputs; | |
154 | if (fgAnalysisManager==this) fgAnalysisManager = NULL; | |
d3106602 | 155 | } |
c52c2132 | 156 | |
d3106602 | 157 | //______________________________________________________________________________ |
327eaf46 | 158 | Int_t AliAnalysisManager::GetEntry(Long64_t entry, Int_t getall) |
159 | { | |
160 | // Read one entry of the tree or a whole branch. | |
8d7d3b59 | 161 | if (fDebug > 0) printf("== AliAnalysisManager::GetEntry(%lld)\n", entry); |
c52c2132 | 162 | fCurrentEntry = entry; |
327eaf46 | 163 | return fTree ? fTree->GetTree()->GetEntry(entry, getall) : 0; |
164 | } | |
165 | ||
166 | //______________________________________________________________________________ | |
167 | void AliAnalysisManager::Init(TTree *tree) | |
d3106602 | 168 | { |
169 | // The Init() function is called when the selector needs to initialize | |
170 | // a new tree or chain. Typically here the branch addresses of the tree | |
171 | // will be set. It is normaly not necessary to make changes to the | |
172 | // generated code, but the routine can be extended by the user if needed. | |
173 | // Init() will be called many times when running with PROOF. | |
327eaf46 | 174 | if (!tree) return; |
8d7d3b59 | 175 | if (fDebug > 0) { |
176 | printf("->AliAnalysisManager::Init(%s)\n", tree->GetName()); | |
c52c2132 | 177 | } |
fdb458ec | 178 | |
f3d59a0d | 179 | // Call InitTree of EventHandler |
36e82a52 | 180 | if (fOutputEventHandler) { |
181 | if (fMode == kProofAnalysis) { | |
f3d59a0d | 182 | fOutputEventHandler->Init(0x0, "proof"); |
36e82a52 | 183 | } else { |
f3d59a0d | 184 | fOutputEventHandler->Init(0x0, "local"); |
36e82a52 | 185 | } |
186 | } | |
187 | ||
fdb458ec | 188 | if (fInputEventHandler) { |
36e82a52 | 189 | if (fMode == kProofAnalysis) { |
f3d59a0d | 190 | fInputEventHandler->Init(tree, "proof"); |
36e82a52 | 191 | } else { |
f3d59a0d | 192 | fInputEventHandler->Init(tree, "local"); |
36e82a52 | 193 | } |
e7ae3836 | 194 | } else { |
195 | // If no input event handler we need to get the tree once | |
196 | // for the chain | |
197 | if(!tree->GetTree()) tree->LoadTree(0); | |
36e82a52 | 198 | } |
e7ae3836 | 199 | |
36e82a52 | 200 | |
201 | if (fMCtruthEventHandler) { | |
202 | if (fMode == kProofAnalysis) { | |
f3d59a0d | 203 | fMCtruthEventHandler->Init(0x0, "proof"); |
36e82a52 | 204 | } else { |
f3d59a0d | 205 | fMCtruthEventHandler->Init(0x0, "local"); |
36e82a52 | 206 | } |
fdb458ec | 207 | } |
208 | ||
c52c2132 | 209 | if (!fInitOK) InitAnalysis(); |
210 | if (!fInitOK) return; | |
327eaf46 | 211 | fTree = tree; |
212 | AliAnalysisDataContainer *top = (AliAnalysisDataContainer*)fInputs->At(0); | |
c52c2132 | 213 | if (!top) { |
8d7d3b59 | 214 | Error("Init","No top input container !"); |
c52c2132 | 215 | return; |
37153431 | 216 | } |
327eaf46 | 217 | top->SetData(tree); |
8d7d3b59 | 218 | if (fDebug > 0) { |
981f2614 | 219 | printf("<-AliAnalysisManager::Init(%s)\n", tree->GetName()); |
220 | } | |
d3106602 | 221 | } |
222 | ||
d3106602 | 223 | //______________________________________________________________________________ |
327eaf46 | 224 | void AliAnalysisManager::SlaveBegin(TTree *tree) |
d3106602 | 225 | { |
226 | // The SlaveBegin() function is called after the Begin() function. | |
227 | // When running with PROOF SlaveBegin() is called on each slave server. | |
228 | // The tree argument is deprecated (on PROOF 0 is passed). | |
8d7d3b59 | 229 | if (fDebug > 0) printf("->AliAnalysisManager::SlaveBegin()\n"); |
aee5ee44 | 230 | static Bool_t isCalled = kFALSE; |
231 | // Call SlaveBegin only once in case of mixing | |
232 | if (isCalled && fMode==kMixingAnalysis) return; | |
f3d59a0d | 233 | // Call Init of EventHandler |
234 | if (fOutputEventHandler) { | |
235 | if (fMode == kProofAnalysis) { | |
236 | fOutputEventHandler->Init("proof"); | |
237 | } else { | |
238 | fOutputEventHandler->Init("local"); | |
239 | } | |
240 | } | |
241 | ||
242 | if (fInputEventHandler) { | |
243 | fInputEventHandler->SetInputTree(tree); | |
244 | if (fMode == kProofAnalysis) { | |
245 | fInputEventHandler->Init("proof"); | |
246 | } else { | |
247 | fInputEventHandler->Init("local"); | |
248 | } | |
249 | } | |
250 | ||
251 | if (fMCtruthEventHandler) { | |
252 | if (fMode == kProofAnalysis) { | |
253 | fMCtruthEventHandler->Init("proof"); | |
254 | } else { | |
255 | fMCtruthEventHandler->Init("local"); | |
256 | } | |
257 | } | |
258 | ||
c52c2132 | 259 | TIter next(fTasks); |
260 | AliAnalysisTask *task; | |
261 | // Call CreateOutputObjects for all tasks | |
c5a87c56 | 262 | while ((task=(AliAnalysisTask*)next())) { |
263 | TDirectory *curdir = gDirectory; | |
c52c2132 | 264 | task->CreateOutputObjects(); |
c5a87c56 | 265 | if (curdir) curdir->cd(); |
36e82a52 | 266 | } |
aee5ee44 | 267 | isCalled = kTRUE; |
36e82a52 | 268 | |
8d7d3b59 | 269 | if (fDebug > 0) printf("<-AliAnalysisManager::SlaveBegin()\n"); |
d3106602 | 270 | } |
271 | ||
272 | //______________________________________________________________________________ | |
327eaf46 | 273 | Bool_t AliAnalysisManager::Notify() |
274 | { | |
275 | // The Notify() function is called when a new file is opened. This | |
276 | // can be either for a new TTree in a TChain or when when a new TTree | |
277 | // is started when using PROOF. It is normaly not necessary to make changes | |
278 | // to the generated code, but the routine can be extended by the | |
279 | // user if needed. The return value is currently not used. | |
8d7d3b59 | 280 | if (!fTree) { |
281 | Error("Notify","No current tree."); | |
282 | return kFALSE; | |
283 | } | |
284 | TFile *curfile = fTree->GetCurrentFile(); | |
285 | if (!curfile) { | |
286 | Error("Notify","No current file"); | |
287 | return kFALSE; | |
288 | } | |
289 | ||
290 | if (fDebug > 0) printf("->AliAnalysisManager::Notify() file: %s\n", curfile->GetName()); | |
291 | TIter next(fTasks); | |
292 | AliAnalysisTask *task; | |
293 | // Call Notify for all tasks | |
294 | while ((task=(AliAnalysisTask*)next())) | |
295 | task->Notify(); | |
fdb458ec | 296 | |
8d7d3b59 | 297 | // Call Notify of the event handlers |
298 | if (fInputEventHandler) { | |
299 | fInputEventHandler->Notify(curfile->GetName()); | |
300 | } | |
6073f8c9 | 301 | |
8d7d3b59 | 302 | if (fOutputEventHandler) { |
303 | fOutputEventHandler->Notify(curfile->GetName()); | |
304 | } | |
890126ab | 305 | |
8d7d3b59 | 306 | if (fMCtruthEventHandler) { |
307 | fMCtruthEventHandler->Notify(curfile->GetName()); | |
308 | } | |
309 | if (fDebug > 0) printf("<-AliAnalysisManager::Notify()\n"); | |
310 | return kTRUE; | |
327eaf46 | 311 | } |
312 | ||
313 | //______________________________________________________________________________ | |
314 | Bool_t AliAnalysisManager::Process(Long64_t entry) | |
d3106602 | 315 | { |
316 | // The Process() function is called for each entry in the tree (or possibly | |
317 | // keyed object in the case of PROOF) to be processed. The entry argument | |
318 | // specifies which entry in the currently loaded tree is to be processed. | |
319 | // It can be passed to either TTree::GetEntry() or TBranch::GetEntry() | |
320 | // to read either all or the required parts of the data. When processing | |
321 | // keyed objects with PROOF, the object is already loaded and is available | |
322 | // via the fObject pointer. | |
323 | // | |
324 | // This function should contain the "body" of the analysis. It can contain | |
325 | // simple or elaborate selection criteria, run algorithms on the data | |
326 | // of the event and typically fill histograms. | |
327 | ||
328 | // WARNING when a selector is used with a TChain, you must use | |
329 | // the pointer to the current TTree to call GetEntry(entry). | |
330 | // The entry is always the local entry number in the current tree. | |
331 | // Assuming that fChain is the pointer to the TChain being processed, | |
332 | // use fChain->GetTree()->GetEntry(entry). | |
8d7d3b59 | 333 | if (fDebug > 0) printf("->AliAnalysisManager::Process(%lld)\n", entry); |
334 | ||
ed97dc98 | 335 | if (fInputEventHandler) fInputEventHandler ->BeginEvent(entry); |
336 | if (fOutputEventHandler) fOutputEventHandler ->BeginEvent(entry); | |
337 | if (fMCtruthEventHandler) fMCtruthEventHandler->BeginEvent(entry); | |
6bb2b24f | 338 | |
327eaf46 | 339 | GetEntry(entry); |
340 | ExecAnalysis(); | |
8d7d3b59 | 341 | if (fDebug > 0) printf("<-AliAnalysisManager::Process()\n"); |
327eaf46 | 342 | return kTRUE; |
d3106602 | 343 | } |
344 | ||
345 | //______________________________________________________________________________ | |
c52c2132 | 346 | void AliAnalysisManager::PackOutput(TList *target) |
d3106602 | 347 | { |
981f2614 | 348 | // Pack all output data containers in the output list. Called at SlaveTerminate |
349 | // stage in PROOF case for each slave. | |
8d7d3b59 | 350 | if (fDebug > 0) printf("->AliAnalysisManager::PackOutput()\n"); |
c52c2132 | 351 | if (!target) { |
352 | Error("PackOutput", "No target. Aborting."); | |
353 | return; | |
37153431 | 354 | } |
6073f8c9 | 355 | if (fInputEventHandler) fInputEventHandler ->Terminate(); |
6bb2b24f | 356 | if (fOutputEventHandler) fOutputEventHandler ->Terminate(); |
357 | if (fMCtruthEventHandler) fMCtruthEventHandler->Terminate(); | |
8d7d3b59 | 358 | |
359 | // Call FinishTaskOutput() for each event loop task (not called for | |
360 | // post-event loop tasks - use Terminate() fo those) | |
361 | TIter nexttask(fTasks); | |
362 | AliAnalysisTask *task; | |
363 | while ((task=(AliAnalysisTask*)nexttask())) { | |
364 | if (!task->IsPostEventLoop()) { | |
365 | if (fDebug > 0) printf("->FinishTaskOutput: task %s\n", task->GetName()); | |
366 | task->FinishTaskOutput(); | |
367 | if (fDebug > 0) printf("<-FinishTaskOutput: task %s\n", task->GetName()); | |
368 | } | |
369 | } | |
8c9485b2 | 370 | |
c52c2132 | 371 | if (fMode == kProofAnalysis) { |
372 | TIter next(fOutputs); | |
373 | AliAnalysisDataContainer *output; | |
374 | while ((output=(AliAnalysisDataContainer*)next())) { | |
8d7d3b59 | 375 | // Do not consider outputs of post event loop tasks |
376 | if (output->GetProducer()->IsPostEventLoop()) continue; | |
377 | // Check if data was posted to this container. If not, issue an error. | |
378 | if (!output->GetData() ) { | |
379 | Error("PackOutput", "No data for output container %s. Forgot to PostData ?\n", output->GetName()); | |
380 | continue; | |
381 | } | |
382 | if (!output->IsSpecialOutput()) { | |
383 | // Normal outputs | |
ca78991b | 384 | const char *filename = output->GetFileName(); |
385 | if (!(strcmp(filename, "default"))) { | |
386 | if (fOutputEventHandler) filename = fOutputEventHandler->GetOutputFileName(); | |
387 | } | |
388 | if (strlen(filename)) { | |
8d7d3b59 | 389 | // File resident outputs |
390 | TFile *file = output->GetFile(); | |
391 | // Backup current folder | |
ca78991b | 392 | TDirectory *opwd = gDirectory; |
8d7d3b59 | 393 | // Create file if not existing and register to container. |
ca78991b | 394 | if (file) file->cd(); |
8d7d3b59 | 395 | else file = new TFile(filename, "RECREATE"); |
396 | if (file->IsZombie()) { | |
397 | Fatal("PackOutput", "Could not recreate file %s\n", filename); | |
398 | return; | |
399 | } | |
400 | output->SetFile(file); | |
ca78991b | 401 | // Clear file list to release object ownership to user. |
ca78991b | 402 | file->Clear(); |
8d7d3b59 | 403 | // Save data to file, then close. |
1be433fc | 404 | if (output->GetData()->InheritsFrom(TCollection::Class())) { |
405 | // If data is a collection, we set the name of the collection | |
406 | // as the one of the container and we save as a single key. | |
407 | TCollection *coll = (TCollection*)output->GetData(); | |
408 | coll->SetName(output->GetName()); | |
409 | coll->Write(output->GetName(), TObject::kSingleKey); | |
410 | } else { | |
411 | output->GetData()->Write(); | |
412 | } | |
8d7d3b59 | 413 | if (fDebug > 1) printf("PackOutput %s: memory merge, file resident output\n", output->GetName()); |
414 | if (fDebug > 2) { | |
415 | printf(" file %s listing content:\n", filename); | |
416 | file->ls(); | |
417 | } | |
ca78991b | 418 | file->Close(); |
ca78991b | 419 | // Restore current directory |
420 | if (opwd) opwd->cd(); | |
8d7d3b59 | 421 | } else { |
422 | // Memory-resident outputs | |
423 | if (fDebug > 1) printf("PackOutput %s: memory merge memory resident output\n", output->GetName()); | |
ca78991b | 424 | } |
8167b1d0 | 425 | AliAnalysisDataWrapper *wrap = output->ExportData(); |
426 | // Output wrappers must delete data after merging (AG 13/11/07) | |
427 | wrap->SetDeleteData(kTRUE); | |
8167b1d0 | 428 | target->Add(wrap); |
429 | } | |
8d7d3b59 | 430 | // Special outputs |
431 | if (output->IsSpecialOutput()) { | |
d0864eb4 | 432 | TDirectory *opwd = gDirectory; |
8d7d3b59 | 433 | TFile *file = output->GetFile(); |
434 | if (!file) { | |
435 | AliAnalysisTask *producer = output->GetProducer(); | |
436 | Error("PackOutput", | |
437 | "File %s for special container %s was NOT opened in %s::CreateOutputObjects !!!", | |
438 | output->GetFileName(), output->GetName(), producer->ClassName()); | |
439 | continue; | |
440 | } | |
ef788aee | 441 | file->cd(); |
8d7d3b59 | 442 | // Release object ownership to users after writing data to file |
1be433fc | 443 | if (output->GetData()->InheritsFrom(TCollection::Class())) { |
444 | // If data is a collection, we set the name of the collection | |
445 | // as the one of the container and we save as a single key. | |
446 | TCollection *coll = (TCollection*)output->GetData(); | |
447 | coll->SetName(output->GetName()); | |
448 | coll->Write(output->GetName(), TObject::kSingleKey); | |
449 | } else { | |
450 | output->GetData()->Write(); | |
451 | } | |
8d7d3b59 | 452 | file->Clear(); |
453 | if (fDebug > 2) { | |
454 | printf(" file %s listing content:\n", output->GetFileName()); | |
455 | file->ls(); | |
456 | } | |
13ef3bb0 | 457 | file->Close(); |
8d7d3b59 | 458 | // Restore current directory |
d0864eb4 | 459 | if (opwd) opwd->cd(); |
8d7d3b59 | 460 | // Check if a special output location was provided or the output files have to be merged |
13ef3bb0 | 461 | if (strlen(fSpecialOutputLocation.Data())) { |
462 | TString remote = fSpecialOutputLocation; | |
463 | remote += "/"; | |
ef788aee | 464 | Int_t gid = gROOT->ProcessLine("gProofServ->GetGroupId();"); |
d0864eb4 | 465 | remote += Form("%s_%d_", gSystem->HostName(), gid); |
13ef3bb0 | 466 | remote += output->GetFileName(); |
467 | TFile::Cp(output->GetFileName(), remote.Data()); | |
ca78991b | 468 | } else { |
8d7d3b59 | 469 | // No special location specified-> use TProofOutputFile as merging utility |
470 | // The file at this output slot must be opened in CreateOutputObjects | |
471 | if (fDebug > 1) printf(" File %s to be merged...\n", output->GetFileName()); | |
13ef3bb0 | 472 | } |
473 | } | |
c52c2132 | 474 | } |
475 | } | |
8d7d3b59 | 476 | if (fDebug > 0) printf("<-AliAnalysisManager::PackOutput: output list contains %d containers\n", target->GetSize()); |
c52c2132 | 477 | } |
478 | ||
479 | //______________________________________________________________________________ | |
981f2614 | 480 | void AliAnalysisManager::ImportWrappers(TList *source) |
c52c2132 | 481 | { |
981f2614 | 482 | // Import data in output containers from wrappers coming in source. |
8d7d3b59 | 483 | if (fDebug > 0) printf("->AliAnalysisManager::ImportWrappers()\n"); |
327eaf46 | 484 | TIter next(fOutputs); |
981f2614 | 485 | AliAnalysisDataContainer *cont; |
486 | AliAnalysisDataWrapper *wrap; | |
487 | Int_t icont = 0; | |
c52c2132 | 488 | while ((cont=(AliAnalysisDataContainer*)next())) { |
8d7d3b59 | 489 | if (cont->GetProducer()->IsPostEventLoop()) continue; |
490 | if (cont->IsSpecialOutput()) { | |
491 | if (strlen(fSpecialOutputLocation.Data())) continue; | |
492 | // Copy merged file from PROOF scratch space | |
493 | if (fDebug > 1) | |
494 | printf(" Copying file %s from PROOF scratch space\n", cont->GetFileName()); | |
495 | Bool_t gotit = TFile::Cp(Form("root://lxb6045.cern.ch:11094//pool/scratch/%s",cont->GetFileName()), | |
496 | cont->GetFileName()); | |
497 | if (!gotit) { | |
498 | Error("ImportWrappers", "Could not get file %s from proof scratch space", cont->GetFileName()); | |
499 | } | |
500 | // Normally we should connect data from the copied file to the | |
501 | // corresponding output container, but it is not obvious how to do this | |
502 | // automatically if several objects in file... | |
503 | continue; | |
504 | } | |
981f2614 | 505 | wrap = (AliAnalysisDataWrapper*)source->FindObject(cont->GetName()); |
8d7d3b59 | 506 | if (!wrap) { |
507 | Error("ImportWrappers","Container %s not found in analysis output !", cont->GetName()); | |
c52c2132 | 508 | continue; |
509 | } | |
981f2614 | 510 | icont++; |
8d7d3b59 | 511 | if (fDebug > 1) { |
512 | printf(" Importing data for container %s", cont->GetName()); | |
513 | if (strlen(cont->GetFileName())) printf(" -> file %s\n", cont->GetFileName()); | |
514 | else printf("\n"); | |
515 | } | |
981f2614 | 516 | cont->ImportData(wrap); |
c52c2132 | 517 | } |
8d7d3b59 | 518 | if (fDebug > 0) printf("<-AliAnalysisManager::ImportWrappers(): %d containers imported\n", icont); |
c52c2132 | 519 | } |
520 | ||
521 | //______________________________________________________________________________ | |
522 | void AliAnalysisManager::UnpackOutput(TList *source) | |
523 | { | |
ca78991b | 524 | // Called by AliAnalysisSelector::Terminate only on the client. |
8d7d3b59 | 525 | if (fDebug > 0) printf("->AliAnalysisManager::UnpackOutput()\n"); |
c52c2132 | 526 | if (!source) { |
981f2614 | 527 | Error("UnpackOutput", "No target. Aborting."); |
c52c2132 | 528 | return; |
529 | } | |
8d7d3b59 | 530 | if (fDebug > 1) printf(" Source list contains %d containers\n", source->GetSize()); |
c52c2132 | 531 | |
981f2614 | 532 | if (fMode == kProofAnalysis) ImportWrappers(source); |
37153431 | 533 | |
981f2614 | 534 | TIter next(fOutputs); |
c52c2132 | 535 | AliAnalysisDataContainer *output; |
536 | while ((output=(AliAnalysisDataContainer*)next())) { | |
c52c2132 | 537 | if (!output->GetData()) continue; |
b1310ef5 | 538 | // Check if there are client tasks that run post event loop |
539 | if (output->HasConsumers()) { | |
540 | // Disable event loop semaphore | |
541 | output->SetPostEventLoop(kTRUE); | |
542 | TObjArray *list = output->GetConsumers(); | |
543 | Int_t ncons = list->GetEntriesFast(); | |
544 | for (Int_t i=0; i<ncons; i++) { | |
545 | AliAnalysisTask *task = (AliAnalysisTask*)list->At(i); | |
546 | task->CheckNotify(kTRUE); | |
547 | // If task is active, execute it | |
548 | if (task->IsPostEventLoop() && task->IsActive()) { | |
8d7d3b59 | 549 | if (fDebug > 0) printf("== Executing post event loop task %s\n", task->GetName()); |
b1310ef5 | 550 | task->ExecuteTask(); |
551 | } | |
552 | } | |
553 | } | |
c52c2132 | 554 | } |
8d7d3b59 | 555 | if (fDebug > 0) printf("<-AliAnalysisManager::UnpackOutput()\n"); |
d3106602 | 556 | } |
557 | ||
558 | //______________________________________________________________________________ | |
559 | void AliAnalysisManager::Terminate() | |
560 | { | |
561 | // The Terminate() function is the last function to be called during | |
562 | // a query. It always runs on the client, it can be used to present | |
c52c2132 | 563 | // the results graphically. |
8d7d3b59 | 564 | if (fDebug > 0) printf("->AliAnalysisManager::Terminate()\n"); |
327eaf46 | 565 | AliAnalysisTask *task; |
c52c2132 | 566 | TIter next(fTasks); |
327eaf46 | 567 | // Call Terminate() for tasks |
c52c2132 | 568 | while ((task=(AliAnalysisTask*)next())) task->Terminate(); |
8c9485b2 | 569 | // |
8c0ab8e8 | 570 | TIter next1(fOutputs); |
571 | AliAnalysisDataContainer *output; | |
572 | while ((output=(AliAnalysisDataContainer*)next1())) { | |
573 | // Close all files at output | |
1be433fc | 574 | // Special outputs have the files already closed and written. |
575 | if (output->IsSpecialOutput()) continue; | |
8c0ab8e8 | 576 | const char *filename = output->GetFileName(); |
577 | if (!(strcmp(filename, "default"))) { | |
578 | if (fOutputEventHandler) filename = fOutputEventHandler->GetOutputFileName(); | |
1be433fc | 579 | TFile *aodfile = (TFile*)gROOT->GetListOfFiles()->FindObject(filename); |
580 | if (aodfile) { | |
581 | if (fDebug > 1) printf("Writing output handler file: %s\n", filename); | |
582 | aodfile->Write(); | |
583 | continue; | |
584 | } | |
8d7d3b59 | 585 | } |
586 | if (!strlen(filename)) continue; | |
1be433fc | 587 | if (!output->GetData()) continue; |
8d7d3b59 | 588 | TFile *file = output->GetFile(); |
589 | TDirectory *opwd = gDirectory; | |
590 | if (file) { | |
591 | file->cd(); | |
592 | } else { | |
593 | file = new TFile(filename, "RECREATE"); | |
594 | if (file->IsZombie()) continue; | |
595 | output->SetFile(file); | |
596 | } | |
597 | if (fDebug > 1) printf(" writing output data %s to file %s\n", output->GetData()->GetName(), file->GetName()); | |
1be433fc | 598 | if (output->GetData()->InheritsFrom(TCollection::Class())) { |
599 | // If data is a collection, we set the name of the collection | |
600 | // as the one of the container and we save as a single key. | |
601 | TCollection *coll = (TCollection*)output->GetData(); | |
602 | coll->SetName(output->GetName()); | |
603 | coll->Write(output->GetName(), TObject::kSingleKey); | |
604 | } else { | |
605 | output->GetData()->Write(); | |
606 | } | |
8c0ab8e8 | 607 | file->Close(); |
8d7d3b59 | 608 | if (opwd) opwd->cd(); |
8c0ab8e8 | 609 | } |
610 | ||
1be433fc | 611 | if (fInputEventHandler) fInputEventHandler ->TerminateIO(); |
612 | if (fOutputEventHandler) fOutputEventHandler ->TerminateIO(); | |
613 | if (fMCtruthEventHandler) fMCtruthEventHandler->TerminateIO(); | |
614 | ||
8c0ab8e8 | 615 | Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE; |
616 | if (getsysInfo) { | |
617 | TDirectory *cdir = gDirectory; | |
618 | TFile f("syswatch.root", "RECREATE"); | |
619 | if (!f.IsZombie()) { | |
620 | TTree *tree = AliSysInfo::MakeTree("syswatch.log"); | |
621 | tree->SetMarkerStyle(kCircle); | |
622 | tree->SetMarkerColor(kBlue); | |
623 | tree->SetMarkerSize(0.5); | |
624 | if (!gROOT->IsBatch()) { | |
625 | tree->SetAlias("event", "id0"); | |
29cbcef8 | 626 | tree->SetAlias("memUSED", "pI.fMemVirtual"); |
8c0ab8e8 | 627 | tree->SetAlias("userCPU", "pI.fCpuUser"); |
628 | TCanvas *c = new TCanvas("SysInfo","SysInfo",10,10,800,600); | |
629 | c->Divide(2,1,0.01,0.01); | |
630 | c->cd(1); | |
631 | tree->Draw("memUSED:event","","", 1234567890, 0); | |
632 | c->cd(2); | |
633 | tree->Draw("userCPU:event","","", 1234567890, 0); | |
634 | } | |
635 | tree->Write(); | |
636 | f.Close(); | |
637 | delete tree; | |
638 | } | |
639 | if (cdir) cdir->cd(); | |
640 | } | |
8d7d3b59 | 641 | if (fDebug > 0) printf("<-AliAnalysisManager::Terminate()\n"); |
d3106602 | 642 | } |
643 | ||
644 | //______________________________________________________________________________ | |
645 | void AliAnalysisManager::AddTask(AliAnalysisTask *task) | |
646 | { | |
647 | // Adds a user task to the global list of tasks. | |
8d7d3b59 | 648 | if (fTasks->FindObject(task)) { |
649 | Warning("AddTask", "Task %s: the same object already added to the analysis manager. Not adding.", task->GetName()); | |
650 | return; | |
651 | } | |
d3106602 | 652 | task->SetActive(kFALSE); |
653 | fTasks->Add(task); | |
654 | } | |
655 | ||
656 | //______________________________________________________________________________ | |
657 | AliAnalysisTask *AliAnalysisManager::GetTask(const char *name) const | |
658 | { | |
659 | // Retreive task by name. | |
660 | if (!fTasks) return NULL; | |
661 | return (AliAnalysisTask*)fTasks->FindObject(name); | |
662 | } | |
663 | ||
664 | //______________________________________________________________________________ | |
665 | AliAnalysisDataContainer *AliAnalysisManager::CreateContainer(const char *name, | |
c52c2132 | 666 | TClass *datatype, EAliAnalysisContType type, const char *filename) |
d3106602 | 667 | { |
668 | // Create a data container of a certain type. Types can be: | |
c52c2132 | 669 | // kExchangeContainer = 0, used to exchange date between tasks |
d3106602 | 670 | // kInputContainer = 1, used to store input data |
671 | // kOutputContainer = 2, used for posting results | |
b1310ef5 | 672 | if (fContainers->FindObject(name)) { |
673 | Error("CreateContainer","A container named %s already defined !\n",name); | |
674 | return NULL; | |
675 | } | |
d3106602 | 676 | AliAnalysisDataContainer *cont = new AliAnalysisDataContainer(name, datatype); |
677 | fContainers->Add(cont); | |
678 | switch (type) { | |
679 | case kInputContainer: | |
680 | fInputs->Add(cont); | |
681 | break; | |
682 | case kOutputContainer: | |
683 | fOutputs->Add(cont); | |
8c0ab8e8 | 684 | if (filename && strlen(filename)) { |
685 | cont->SetFileName(filename); | |
686 | cont->SetDataOwned(kFALSE); // data owned by the file | |
687 | } | |
d3106602 | 688 | break; |
c52c2132 | 689 | case kExchangeContainer: |
d3106602 | 690 | break; |
691 | } | |
692 | return cont; | |
693 | } | |
694 | ||
695 | //______________________________________________________________________________ | |
696 | Bool_t AliAnalysisManager::ConnectInput(AliAnalysisTask *task, Int_t islot, | |
697 | AliAnalysisDataContainer *cont) | |
698 | { | |
699 | // Connect input of an existing task to a data container. | |
700 | if (!fTasks->FindObject(task)) { | |
701 | AddTask(task); | |
8d7d3b59 | 702 | Info("ConnectInput", "Task %s was not registered. Now owned by analysis manager", task->GetName()); |
d3106602 | 703 | } |
704 | Bool_t connected = task->ConnectInput(islot, cont); | |
705 | return connected; | |
706 | } | |
707 | ||
708 | //______________________________________________________________________________ | |
709 | Bool_t AliAnalysisManager::ConnectOutput(AliAnalysisTask *task, Int_t islot, | |
710 | AliAnalysisDataContainer *cont) | |
711 | { | |
712 | // Connect output of an existing task to a data container. | |
713 | if (!fTasks->FindObject(task)) { | |
714 | AddTask(task); | |
c52c2132 | 715 | Warning("ConnectOutput", "Task %s not registered. Now owned by analysis manager", task->GetName()); |
d3106602 | 716 | } |
717 | Bool_t connected = task->ConnectOutput(islot, cont); | |
718 | return connected; | |
719 | } | |
720 | ||
721 | //______________________________________________________________________________ | |
722 | void AliAnalysisManager::CleanContainers() | |
723 | { | |
724 | // Clean data from all containers that have already finished all client tasks. | |
725 | TIter next(fContainers); | |
726 | AliAnalysisDataContainer *cont; | |
727 | while ((cont=(AliAnalysisDataContainer *)next())) { | |
728 | if (cont->IsOwnedData() && | |
729 | cont->IsDataReady() && | |
730 | cont->ClientsExecuted()) cont->DeleteData(); | |
731 | } | |
732 | } | |
733 | ||
734 | //______________________________________________________________________________ | |
735 | Bool_t AliAnalysisManager::InitAnalysis() | |
736 | { | |
737 | // Initialization of analysis chain of tasks. Should be called after all tasks | |
738 | // and data containers are properly connected | |
739 | // Check for input/output containers | |
740 | fInitOK = kFALSE; | |
d3106602 | 741 | // Check for top tasks (depending only on input data containers) |
742 | if (!fTasks->First()) { | |
c52c2132 | 743 | Error("InitAnalysis", "Analysis has no tasks !"); |
d3106602 | 744 | return kFALSE; |
745 | } | |
746 | TIter next(fTasks); | |
747 | AliAnalysisTask *task; | |
748 | AliAnalysisDataContainer *cont; | |
749 | Int_t ntop = 0; | |
750 | Int_t nzombies = 0; | |
327eaf46 | 751 | Bool_t iszombie = kFALSE; |
752 | Bool_t istop = kTRUE; | |
d3106602 | 753 | Int_t i; |
754 | while ((task=(AliAnalysisTask*)next())) { | |
327eaf46 | 755 | istop = kTRUE; |
756 | iszombie = kFALSE; | |
d3106602 | 757 | Int_t ninputs = task->GetNinputs(); |
d3106602 | 758 | for (i=0; i<ninputs; i++) { |
759 | cont = task->GetInputSlot(i)->GetContainer(); | |
760 | if (!cont) { | |
327eaf46 | 761 | if (!iszombie) { |
d3106602 | 762 | task->SetZombie(); |
763 | fZombies->Add(task); | |
764 | nzombies++; | |
327eaf46 | 765 | iszombie = kTRUE; |
d3106602 | 766 | } |
c52c2132 | 767 | Error("InitAnalysis", "Input slot %d of task %s has no container connected ! Declared zombie...", |
768 | i, task->GetName()); | |
d3106602 | 769 | } |
327eaf46 | 770 | if (iszombie) continue; |
d3106602 | 771 | // Check if cont is an input container |
327eaf46 | 772 | if (istop && !fInputs->FindObject(cont)) istop=kFALSE; |
d3106602 | 773 | // Connect to parent task |
774 | } | |
327eaf46 | 775 | if (istop) { |
d3106602 | 776 | ntop++; |
777 | fTopTasks->Add(task); | |
778 | } | |
779 | } | |
780 | if (!ntop) { | |
c52c2132 | 781 | Error("InitAnalysis", "No top task defined. At least one task should be connected only to input containers"); |
d3106602 | 782 | return kFALSE; |
783 | } | |
784 | // Check now if there are orphan tasks | |
785 | for (i=0; i<ntop; i++) { | |
786 | task = (AliAnalysisTask*)fTopTasks->At(i); | |
787 | task->SetUsed(); | |
788 | } | |
789 | Int_t norphans = 0; | |
790 | next.Reset(); | |
791 | while ((task=(AliAnalysisTask*)next())) { | |
792 | if (!task->IsUsed()) { | |
793 | norphans++; | |
c52c2132 | 794 | Warning("InitAnalysis", "Task %s is orphan", task->GetName()); |
d3106602 | 795 | } |
796 | } | |
797 | // Check the task hierarchy (no parent task should depend on data provided | |
798 | // by a daughter task) | |
799 | for (i=0; i<ntop; i++) { | |
800 | task = (AliAnalysisTask*)fTopTasks->At(i); | |
801 | if (task->CheckCircularDeps()) { | |
c52c2132 | 802 | Error("InitAnalysis", "Found illegal circular dependencies between following tasks:"); |
d3106602 | 803 | PrintStatus("dep"); |
804 | return kFALSE; | |
805 | } | |
806 | } | |
b1310ef5 | 807 | // Check that all containers feeding post-event loop tasks are in the outputs list |
808 | TIter nextcont(fContainers); // loop over all containers | |
809 | while ((cont=(AliAnalysisDataContainer*)nextcont())) { | |
810 | if (!cont->IsPostEventLoop() && !fOutputs->FindObject(cont)) { | |
811 | if (cont->HasConsumers()) { | |
812 | // Check if one of the consumers is post event loop | |
813 | TIter nextconsumer(cont->GetConsumers()); | |
814 | while ((task=(AliAnalysisTask*)nextconsumer())) { | |
815 | if (task->IsPostEventLoop()) { | |
816 | fOutputs->Add(cont); | |
817 | break; | |
818 | } | |
819 | } | |
820 | } | |
821 | } | |
822 | } | |
8d7d3b59 | 823 | // Check if all special output containers have a file name provided |
824 | TIter nextout(fOutputs); | |
825 | while ((cont=(AliAnalysisDataContainer*)nextout())) { | |
826 | if (cont->IsSpecialOutput() && !strlen(cont->GetFileName())) { | |
827 | Error("InitAnalysis", "Wrong container %s : a file name MUST be provided for special outputs", cont->GetName()); | |
828 | return kFALSE; | |
829 | } | |
830 | } | |
327eaf46 | 831 | fInitOK = kTRUE; |
d3106602 | 832 | return kTRUE; |
833 | } | |
834 | ||
835 | //______________________________________________________________________________ | |
836 | void AliAnalysisManager::PrintStatus(Option_t *option) const | |
837 | { | |
838 | // Print task hierarchy. | |
8c0ab8e8 | 839 | if (!fInitOK) { |
840 | Info("PrintStatus", "Analysis manager %s not initialized : call InitAnalysis() first", GetName()); | |
841 | return; | |
842 | } | |
843 | Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE; | |
844 | if (getsysInfo) | |
845 | Info("PrintStatus", "System information will be collected each %lld events", fNSysInfo); | |
d3106602 | 846 | TIter next(fTopTasks); |
847 | AliAnalysisTask *task; | |
848 | while ((task=(AliAnalysisTask*)next())) | |
849 | task->PrintTask(option); | |
850 | } | |
851 | ||
852 | //______________________________________________________________________________ | |
853 | void AliAnalysisManager::ResetAnalysis() | |
854 | { | |
855 | // Reset all execution flags and clean containers. | |
856 | CleanContainers(); | |
857 | } | |
858 | ||
c52c2132 | 859 | //______________________________________________________________________________ |
8c0ab8e8 | 860 | void AliAnalysisManager::StartAnalysis(const char *type, TTree *tree, Long64_t nentries, Long64_t firstentry) |
c52c2132 | 861 | { |
aee5ee44 | 862 | // Start analysis for this manager. Analysis task can be: LOCAL, PROOF, GRID or |
863 | // MIX. Process nentries starting from firstentry | |
c52c2132 | 864 | if (!fInitOK) { |
865 | Error("StartAnalysis","Analysis manager was not initialized !"); | |
866 | return; | |
867 | } | |
8d7d3b59 | 868 | if (fDebug > 0) printf("StartAnalysis %s\n",GetName()); |
c52c2132 | 869 | TString anaType = type; |
870 | anaType.ToLower(); | |
871 | fMode = kLocalAnalysis; | |
872 | if (tree) { | |
873 | if (anaType.Contains("proof")) fMode = kProofAnalysis; | |
874 | else if (anaType.Contains("grid")) fMode = kGridAnalysis; | |
aee5ee44 | 875 | else if (anaType.Contains("mix")) fMode = kMixingAnalysis; |
c52c2132 | 876 | } |
877 | if (fMode == kGridAnalysis) { | |
878 | Warning("StartAnalysis", "GRID analysis mode not implemented. Running local."); | |
981f2614 | 879 | fMode = kLocalAnalysis; |
880 | } | |
d86ed856 | 881 | char line[256]; |
efd53803 | 882 | SetEventLoop(kFALSE); |
8d7d3b59 | 883 | // Enable event loop mode if a tree was provided |
aee5ee44 | 884 | if (tree || fMode==kMixingAnalysis) SetEventLoop(kTRUE); |
efd53803 | 885 | |
8c0ab8e8 | 886 | TChain *chain = 0; |
887 | TString ttype = "TTree"; | |
888 | if (tree->IsA() == TChain::Class()) { | |
889 | chain = (TChain*)tree; | |
6b742510 | 890 | if (!chain || !chain->GetListOfFiles()->First()) { |
891 | Error("StartAnalysis", "Cannot process null or empty chain..."); | |
892 | return; | |
893 | } | |
8c0ab8e8 | 894 | ttype = "TChain"; |
895 | } | |
9b33830a | 896 | |
aee5ee44 | 897 | // Initialize locally all tasks (happens for all modes) |
9b33830a | 898 | TIter next(fTasks); |
899 | AliAnalysisTask *task; | |
efd53803 | 900 | while ((task=(AliAnalysisTask*)next())) { |
efd53803 | 901 | task->LocalInit(); |
902 | } | |
903 | ||
c52c2132 | 904 | switch (fMode) { |
905 | case kLocalAnalysis: | |
906 | if (!tree) { | |
03a5cc9f | 907 | TIter nextT(fTasks); |
981f2614 | 908 | // Call CreateOutputObjects for all tasks |
03a5cc9f | 909 | while ((task=(AliAnalysisTask*)nextT())) { |
c5a87c56 | 910 | TDirectory *curdir = gDirectory; |
911 | task->CreateOutputObjects(); | |
912 | if (curdir) curdir->cd(); | |
913 | } | |
c52c2132 | 914 | ExecAnalysis(); |
981f2614 | 915 | Terminate(); |
c52c2132 | 916 | return; |
917 | } | |
918 | // Run tree-based analysis via AliAnalysisSelector | |
c52c2132 | 919 | cout << "===== RUNNING LOCAL ANALYSIS " << GetName() << " ON TREE " << tree->GetName() << endl; |
aee5ee44 | 920 | fSelector = new AliAnalysisSelector(this); |
921 | tree->Process(fSelector, "", nentries, firstentry); | |
c52c2132 | 922 | break; |
923 | case kProofAnalysis: | |
924 | if (!gROOT->GetListOfProofs() || !gROOT->GetListOfProofs()->GetEntries()) { | |
925 | printf("StartAnalysis: no PROOF!!!\n"); | |
926 | return; | |
927 | } | |
928 | sprintf(line, "gProof->AddInput((TObject*)0x%lx);", (ULong_t)this); | |
929 | gROOT->ProcessLine(line); | |
930 | if (chain) { | |
931 | chain->SetProof(); | |
932 | cout << "===== RUNNING PROOF ANALYSIS " << GetName() << " ON CHAIN " << chain->GetName() << endl; | |
8c0ab8e8 | 933 | chain->Process("AliAnalysisSelector", "", nentries, firstentry); |
c52c2132 | 934 | } else { |
935 | printf("StartAnalysis: no chain\n"); | |
936 | return; | |
937 | } | |
938 | break; | |
939 | case kGridAnalysis: | |
940 | Warning("StartAnalysis", "GRID analysis mode not implemented. Running local."); | |
aee5ee44 | 941 | break; |
942 | case kMixingAnalysis: | |
943 | // Run event mixing analysis | |
944 | if (!fEventPool) { | |
945 | Error("StartAnalysis", "Cannot run event mixing without event pool"); | |
946 | return; | |
947 | } | |
948 | cout << "===== RUNNING EVENT MIXING ANALYSIS " << GetName() << endl; | |
949 | fSelector = new AliAnalysisSelector(this); | |
950 | TChain *chain; | |
951 | while ((chain=fEventPool->GetNextChain())) { | |
952 | TIter next(fTasks); | |
953 | AliAnalysisTask *task; | |
954 | // Call NotifyBinChange for all tasks | |
955 | while ((task=(AliAnalysisTask*)next())) | |
956 | if (!task->IsPostEventLoop()) task->NotifyBinChange(); | |
957 | chain->Process(fSelector); | |
958 | } | |
959 | PackOutput(fSelector->GetOutputList()); | |
960 | Terminate(); | |
c52c2132 | 961 | } |
962 | } | |
963 | ||
d86ed856 | 964 | //______________________________________________________________________________ |
965 | void AliAnalysisManager::StartAnalysis(const char *type, const char *dataset, Long64_t nentries, Long64_t firstentry) | |
966 | { | |
967 | // Start analysis for this manager on a given dataset. Analysis task can be: | |
968 | // LOCAL, PROOF or GRID. Process nentries starting from firstentry. | |
969 | if (!fInitOK) { | |
970 | Error("StartAnalysis","Analysis manager was not initialized !"); | |
971 | return; | |
972 | } | |
8d7d3b59 | 973 | if (fDebug > 0) printf("StartAnalysis %s\n",GetName()); |
d86ed856 | 974 | TString anaType = type; |
975 | anaType.ToLower(); | |
976 | if (!anaType.Contains("proof")) { | |
977 | Error("Cannot process datasets in %s mode. Try PROOF.", type); | |
978 | return; | |
979 | } | |
980 | fMode = kProofAnalysis; | |
981 | char line[256]; | |
982 | SetEventLoop(kTRUE); | |
983 | // Set the dataset flag | |
984 | TObject::SetBit(kUseDataSet); | |
985 | fTree = 0; | |
986 | ||
987 | // Initialize locally all tasks | |
988 | TIter next(fTasks); | |
989 | AliAnalysisTask *task; | |
990 | while ((task=(AliAnalysisTask*)next())) { | |
991 | task->LocalInit(); | |
992 | } | |
993 | ||
994 | if (!gROOT->GetListOfProofs() || !gROOT->GetListOfProofs()->GetEntries()) { | |
995 | printf("StartAnalysis: no PROOF!!!\n"); | |
996 | return; | |
997 | } | |
998 | sprintf(line, "gProof->AddInput((TObject*)0x%lx);", (ULong_t)this); | |
999 | gROOT->ProcessLine(line); | |
1000 | sprintf(line, "gProof->GetDataSet(\"%s\");", dataset); | |
1001 | if (!gROOT->ProcessLine(line)) { | |
1002 | Error("StartAnalysis", "Dataset %s not found", dataset); | |
1003 | return; | |
1004 | } | |
1005 | sprintf(line, "gProof->Process(\"%s\", \"AliAnalysisSelector\", \"\", %lld, %lld);", | |
1006 | dataset, nentries, firstentry); | |
1007 | cout << "===== RUNNING PROOF ANALYSIS " << GetName() << " ON DATASET " << dataset << endl; | |
1008 | gROOT->ProcessLine(line); | |
1009 | } | |
1010 | ||
d3106602 | 1011 | //______________________________________________________________________________ |
8d7d3b59 | 1012 | TFile *AliAnalysisManager::OpenProofFile(const char *filename, const char *option) |
1013 | { | |
1014 | // Opens a special output file used in PROOF. | |
1015 | char line[256]; | |
1016 | if (fMode!=kProofAnalysis || !fSelector) { | |
1017 | Error("OpenProofFile","Cannot open PROOF file %s",filename); | |
1018 | return NULL; | |
1019 | } | |
1020 | sprintf(line, "TProofOutputFile *pf = new TProofOutputFile(\"%s\");", filename); | |
1021 | if (fDebug > 1) printf("=== %s\n", line); | |
1022 | gROOT->ProcessLine(line); | |
1023 | sprintf(line, "pf->OpenFile(\"%s\");", option); | |
1024 | gROOT->ProcessLine(line); | |
1025 | if (fDebug > 1) { | |
1026 | gROOT->ProcessLine("pf->Print()"); | |
1027 | printf(" == proof file name: %s\n", gFile->GetName()); | |
1028 | } | |
1029 | sprintf(line, "((TList*)0x%lx)->Add(pf);",(ULong_t)fSelector->GetOutputList()); | |
1030 | if (fDebug > 1) printf("=== %s\n", line); | |
1031 | gROOT->ProcessLine(line); | |
1032 | return gFile; | |
1033 | } | |
1034 | ||
1035 | //______________________________________________________________________________ | |
d3106602 | 1036 | void AliAnalysisManager::ExecAnalysis(Option_t *option) |
1037 | { | |
1038 | // Execute analysis. | |
8c0ab8e8 | 1039 | static Long64_t ncalls = 0; |
1040 | Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE; | |
1041 | if (getsysInfo && ncalls==0) AliSysInfo::AddStamp("Start", (Int_t)ncalls); | |
1042 | ncalls++; | |
327eaf46 | 1043 | if (!fInitOK) { |
c52c2132 | 1044 | Error("ExecAnalysis", "Analysis manager was not initialized !"); |
327eaf46 | 1045 | return; |
1046 | } | |
d3106602 | 1047 | AliAnalysisTask *task; |
327eaf46 | 1048 | // Check if the top tree is active. |
1049 | if (fTree) { | |
1050 | TIter next(fTasks); | |
1051 | // De-activate all tasks | |
1052 | while ((task=(AliAnalysisTask*)next())) task->SetActive(kFALSE); | |
1053 | AliAnalysisDataContainer *cont = (AliAnalysisDataContainer*)fInputs->At(0); | |
1054 | if (!cont) { | |
c52c2132 | 1055 | Error("ExecAnalysis","Cannot execute analysis in TSelector mode without at least one top container"); |
327eaf46 | 1056 | return; |
1057 | } | |
1058 | cont->SetData(fTree); // This will notify all consumers | |
ed97dc98 | 1059 | Long64_t entry = fTree->GetTree()->GetReadEntry(); |
1060 | ||
6bb2b24f | 1061 | // |
c3701689 | 1062 | // Call BeginEvent() for optional input/output and MC services |
ed97dc98 | 1063 | if (fInputEventHandler) fInputEventHandler ->BeginEvent(entry); |
1064 | if (fOutputEventHandler) fOutputEventHandler ->BeginEvent(entry); | |
1065 | if (fMCtruthEventHandler) fMCtruthEventHandler->BeginEvent(entry); | |
6bb2b24f | 1066 | // |
1067 | // Execute the tasks | |
276941c8 | 1068 | // TIter next1(cont->GetConsumers()); |
1069 | TIter next1(fTopTasks); | |
327eaf46 | 1070 | while ((task=(AliAnalysisTask*)next1())) { |
c52c2132 | 1071 | if (fDebug >1) { |
1072 | cout << " Executing task " << task->GetName() << endl; | |
1073 | } | |
6bb2b24f | 1074 | |
327eaf46 | 1075 | task->ExecuteTask(option); |
1076 | } | |
6bb2b24f | 1077 | // |
1078 | // Call FinishEvent() for optional output and MC services | |
6073f8c9 | 1079 | if (fInputEventHandler) fInputEventHandler ->FinishEvent(); |
6bb2b24f | 1080 | if (fOutputEventHandler) fOutputEventHandler ->FinishEvent(); |
1081 | if (fMCtruthEventHandler) fMCtruthEventHandler->FinishEvent(); | |
8c0ab8e8 | 1082 | // Gather system information if requested |
1083 | if (getsysInfo && ((ncalls%fNSysInfo)==0)) | |
1084 | AliSysInfo::AddStamp(Form("Event#%lld",ncalls),(Int_t)ncalls); | |
327eaf46 | 1085 | return; |
1086 | } | |
1087 | // The event loop is not controlled by TSelector | |
6bb2b24f | 1088 | // |
c3701689 | 1089 | // Call BeginEvent() for optional input/output and MC services |
ed97dc98 | 1090 | if (fInputEventHandler) fInputEventHandler ->BeginEvent(-1); |
1091 | if (fOutputEventHandler) fOutputEventHandler ->BeginEvent(-1); | |
1092 | if (fMCtruthEventHandler) fMCtruthEventHandler->BeginEvent(-1); | |
327eaf46 | 1093 | TIter next2(fTopTasks); |
1094 | while ((task=(AliAnalysisTask*)next2())) { | |
1095 | task->SetActive(kTRUE); | |
c52c2132 | 1096 | if (fDebug > 1) { |
1097 | cout << " Executing task " << task->GetName() << endl; | |
1098 | } | |
d3106602 | 1099 | task->ExecuteTask(option); |
327eaf46 | 1100 | } |
6bb2b24f | 1101 | // |
1102 | // Call FinishEvent() for optional output and MC services | |
6073f8c9 | 1103 | if (fInputEventHandler) fInputEventHandler ->FinishEvent(); |
1104 | if (fOutputEventHandler) fOutputEventHandler ->FinishEvent(); | |
6bb2b24f | 1105 | if (fMCtruthEventHandler) fMCtruthEventHandler->FinishEvent(); |
d3106602 | 1106 | } |
1107 | ||
1108 | //______________________________________________________________________________ | |
1109 | void AliAnalysisManager::FinishAnalysis() | |
1110 | { | |
1111 | // Finish analysis. | |
1112 | } |