1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // Author: Andrei Gheata, 31/05/2006
19 //==============================================================================
20 // AliAnalysysManager - Manager analysis class. Allows creation of several
21 // analysis tasks and data containers storing their input/output. Allows
22 // connecting/chaining tasks via shared data containers. Serializes the current
23 // event for all tasks depending only on initial input data.
24 //==============================================================================
26 //==============================================================================
28 #include <Riostream.h>
36 #include <TMethodCall.h>
41 #include <TStopwatch.h>
43 #include "AliAnalysisSelector.h"
44 #include "AliAnalysisGrid.h"
45 #include "AliAnalysisTask.h"
46 #include "AliAnalysisDataContainer.h"
47 #include "AliAnalysisDataSlot.h"
48 #include "AliVEventHandler.h"
49 #include "AliVEventPool.h"
50 #include "AliSysInfo.h"
51 #include "AliAnalysisManager.h"
53 ClassImp(AliAnalysisManager)
55 AliAnalysisManager *AliAnalysisManager::fgAnalysisManager = NULL;
56 TString AliAnalysisManager::fgCommonFileName = "";
58 //______________________________________________________________________________
59 AliAnalysisManager::AliAnalysisManager(const char *name, const char *title)
62 fInputEventHandler(NULL),
63 fOutputEventHandler(NULL),
64 fMCtruthEventHandler(NULL),
68 fMode(kLocalAnalysis),
72 fSpecialOutputLocation(""),
85 fAutoBranchHandling(kTRUE),
91 // Default constructor.
92 fgAnalysisManager = this;
93 fgCommonFileName = "AnalysisResults.root";
94 fTasks = new TObjArray();
95 fTopTasks = new TObjArray();
96 fZombies = new TObjArray();
97 fContainers = new TObjArray();
98 fInputs = new TObjArray();
99 fOutputs = new TObjArray();
100 fParamCont = new TObjArray();
102 TObject::SetObjectStat(kFALSE);
105 //______________________________________________________________________________
106 AliAnalysisManager::AliAnalysisManager(const AliAnalysisManager& other)
109 fInputEventHandler(NULL),
110 fOutputEventHandler(NULL),
111 fMCtruthEventHandler(NULL),
116 fInitOK(other.fInitOK),
117 fIsRemote(other.fIsRemote),
118 fDebug(other.fDebug),
119 fSpecialOutputLocation(""),
132 fAutoBranchHandling(other.fAutoBranchHandling),
135 fNcalls(other.fNcalls),
136 fStatisticsMsg(other.fStatisticsMsg)
139 fTasks = new TObjArray(*other.fTasks);
140 fTopTasks = new TObjArray(*other.fTopTasks);
141 fZombies = new TObjArray(*other.fZombies);
142 fContainers = new TObjArray(*other.fContainers);
143 fInputs = new TObjArray(*other.fInputs);
144 fOutputs = new TObjArray(*other.fOutputs);
145 fParamCont = new TObjArray(*other.fParamCont);
146 fgCommonFileName = "AnalysisResults.root";
147 fgAnalysisManager = this;
148 TObject::SetObjectStat(kFALSE);
151 //______________________________________________________________________________
152 AliAnalysisManager& AliAnalysisManager::operator=(const AliAnalysisManager& other)
155 if (&other != this) {
156 TNamed::operator=(other);
157 fInputEventHandler = other.fInputEventHandler;
158 fOutputEventHandler = other.fOutputEventHandler;
159 fMCtruthEventHandler = other.fMCtruthEventHandler;
160 fEventPool = other.fEventPool;
163 fNSysInfo = other.fNSysInfo;
165 fInitOK = other.fInitOK;
166 fIsRemote = other.fIsRemote;
167 fDebug = other.fDebug;
168 fTasks = new TObjArray(*other.fTasks);
169 fTopTasks = new TObjArray(*other.fTopTasks);
170 fZombies = new TObjArray(*other.fZombies);
171 fContainers = new TObjArray(*other.fContainers);
172 fInputs = new TObjArray(*other.fInputs);
173 fOutputs = new TObjArray(*other.fOutputs);
174 fParamCont = new TObjArray(*other.fParamCont);
176 fCommonOutput = NULL;
179 fExtraFiles = other.fExtraFiles;
180 fgCommonFileName = "AnalysisResults.root";
181 fgAnalysisManager = this;
182 fAutoBranchHandling = other.fAutoBranchHandling;
183 fTable.Clear("nodelete");
184 fRunFromPath = other.fRunFromPath;
185 fNcalls = other. fNcalls;
186 fStatisticsMsg = other.fStatisticsMsg;
191 //______________________________________________________________________________
192 AliAnalysisManager::~AliAnalysisManager()
195 if (fTasks) {fTasks->Delete(); delete fTasks;}
196 if (fTopTasks) delete fTopTasks;
197 if (fZombies) delete fZombies;
198 if (fContainers) {fContainers->Delete(); delete fContainers;}
199 if (fInputs) delete fInputs;
200 if (fOutputs) delete fOutputs;
201 if (fParamCont) delete fParamCont;
202 if (fGridHandler) delete fGridHandler;
203 if (fInputEventHandler) delete fInputEventHandler;
204 if (fOutputEventHandler) delete fOutputEventHandler;
205 if (fMCtruthEventHandler) delete fMCtruthEventHandler;
206 if (fEventPool) delete fEventPool;
207 if (fgAnalysisManager==this) fgAnalysisManager = NULL;
208 TObject::SetObjectStat(kTRUE);
211 //______________________________________________________________________________
212 Int_t AliAnalysisManager::GetEntry(Long64_t entry, Int_t getall)
214 // Read one entry of the tree or a whole branch.
215 fCurrentEntry = entry;
216 if (!fAutoBranchHandling)
218 return fTree ? fTree->GetTree()->GetEntry(entry, getall) : 0;
221 //______________________________________________________________________________
222 Int_t AliAnalysisManager::GetRunFromAlienPath(const char *path)
224 // Attempt to extract run number from input data path. Works only for paths to
225 // alice data in alien.
226 // sim: /alice/sim/<production>/run_no/...
227 // data: /alice/data/year/period/000run_no/... (ESD or AOD)
231 Int_t index = s.Index("/alice/sim");
233 for (Int_t i=0; i<3; i++) {
234 index = s.Index("/", index+1);
235 if (index<0) return 0;
240 index = s.Index("/alice/data");
242 for (Int_t i=0; i<4; i++) {
243 index = s.Index("/", index+1);
244 if (index<0) return 0;
252 //______________________________________________________________________________
253 Bool_t AliAnalysisManager::Init(TTree *tree)
255 // The Init() function is called when the selector needs to initialize
256 // a new tree or chain. Typically here the branch addresses of the tree
257 // will be set. It is normaly not necessary to make changes to the
258 // generated code, but the routine can be extended by the user if needed.
259 // Init() will be called many times when running with PROOF.
260 Bool_t init = kFALSE;
261 if (!tree) return kFALSE; // Should not happen - protected in selector caller
263 printf("->AliAnalysisManager::Init(%s)\n", tree->GetName());
265 // Call InitTree of EventHandler
266 if (fOutputEventHandler) {
267 if (fMode == kProofAnalysis) {
268 init = fOutputEventHandler->Init(0x0, "proof");
270 init = fOutputEventHandler->Init(0x0, "local");
273 Error("Init", "Output event handler failed to initialize");
278 if (fInputEventHandler) {
279 if (fMode == kProofAnalysis) {
280 init = fInputEventHandler->Init(tree, "proof");
282 init = fInputEventHandler->Init(tree, "local");
285 Error("Init", "Input event handler failed to initialize tree");
289 // If no input event handler we need to get the tree once
291 if(!tree->GetTree()) {
292 Long64_t readEntry = tree->LoadTree(0);
293 if (readEntry == -2) {
294 Error("Init", "Input tree has no entry. Exiting");
300 if (fMCtruthEventHandler) {
301 if (fMode == kProofAnalysis) {
302 init = fMCtruthEventHandler->Init(0x0, "proof");
304 init = fMCtruthEventHandler->Init(0x0, "local");
307 Error("Init", "MC event handler failed to initialize");
312 if (!fInitOK) InitAnalysis();
313 if (!fInitOK) return kFALSE;
316 AliAnalysisDataContainer *top = fCommonInput;
317 if (!top) top = (AliAnalysisDataContainer*)fInputs->At(0);
319 Error("Init","No top input container !");
324 printf("<-AliAnalysisManager::Init(%s)\n", tree->GetName());
329 //______________________________________________________________________________
330 void AliAnalysisManager::SlaveBegin(TTree *tree)
332 // The SlaveBegin() function is called after the Begin() function.
333 // When running with PROOF SlaveBegin() is called on each slave server.
334 // The tree argument is deprecated (on PROOF 0 is passed).
335 if (fDebug > 1) printf("->AliAnalysisManager::SlaveBegin()\n");
336 static Bool_t isCalled = kFALSE;
337 Bool_t init = kFALSE;
338 Bool_t initOK = kTRUE;
340 TDirectory *curdir = gDirectory;
341 // Call SlaveBegin only once in case of mixing
342 if (isCalled && fMode==kMixingAnalysis) return;
344 // Call Init of EventHandler
345 if (fOutputEventHandler) {
346 if (fMode == kProofAnalysis) {
347 // Merging AOD's in PROOF via TProofOutputFile
348 if (fDebug > 1) printf(" Initializing AOD output file %s...\n", fOutputEventHandler->GetOutputFileName());
349 init = fOutputEventHandler->Init("proof");
350 if (!init) msg = "Failed to initialize output handler on worker";
352 init = fOutputEventHandler->Init("local");
353 if (!init) msg = "Failed to initialize output handler";
356 if (!fSelector) Error("SlaveBegin", "Selector not set");
357 else if (!init) {fSelector->Abort(msg); fSelector->SetStatus(-1);}
360 if (fInputEventHandler) {
361 fInputEventHandler->SetInputTree(tree);
362 if (fMode == kProofAnalysis) {
363 init = fInputEventHandler->Init("proof");
364 if (!init) msg = "Failed to initialize input handler on worker";
366 init = fInputEventHandler->Init("local");
367 if (!init) msg = "Failed to initialize input handler";
370 if (!fSelector) Error("SlaveBegin", "Selector not set");
371 else if (!init) {fSelector->Abort(msg); fSelector->SetStatus(-1);}
374 if (fMCtruthEventHandler) {
375 if (fMode == kProofAnalysis) {
376 init = fMCtruthEventHandler->Init("proof");
377 if (!init) msg = "Failed to initialize MC handler on worker";
379 init = fMCtruthEventHandler->Init("local");
380 if (!init) msg = "Failed to initialize MC handler";
383 if (!fSelector) Error("SlaveBegin", "Selector not set");
384 else if (!init) {fSelector->Abort(msg); fSelector->SetStatus(-1);}
386 if (curdir) curdir->cd();
390 AliAnalysisTask *task;
391 // Call CreateOutputObjects for all tasks
392 Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
393 Bool_t dirStatus = TH1::AddDirectoryStatus();
395 while ((task=(AliAnalysisTask*)next())) {
397 // Start with memory as current dir and make sure by default histograms do not get attached to files.
398 TH1::AddDirectory(kFALSE);
399 task->CreateOutputObjects();
400 if (getsysInfo) AliSysInfo::AddStamp(Form("%s_CREATEOUTOBJ",task->ClassName()), 0, itask, 0);
403 TH1::AddDirectory(dirStatus);
404 if (curdir) curdir->cd();
405 if (fDebug > 1) printf("<-AliAnalysisManager::SlaveBegin()\n");
408 //______________________________________________________________________________
409 Bool_t AliAnalysisManager::Notify()
411 // The Notify() function is called when a new file is opened. This
412 // can be either for a new TTree in a TChain or when when a new TTree
413 // is started when using PROOF. It is normaly not necessary to make changes
414 // to the generated code, but the routine can be extended by the
415 // user if needed. The return value is currently not used.
416 if (!fTree) return kFALSE;
418 fTable.Clear("nodelete"); // clearing the hash table may not be needed -> C.L.
419 if (fMode == kProofAnalysis) fIsRemote = kTRUE;
421 TFile *curfile = fTree->GetCurrentFile();
423 Error("Notify","No current file");
427 if (fDebug > 1) printf("->AliAnalysisManager::Notify() file: %s\n", curfile->GetName());
428 Int_t run = AliAnalysisManager::GetRunFromAlienPath(curfile->GetName());
429 if (run) SetRunFromPath(run);
430 if (fDebug > 1) printf(" ### run found from path: %d\n", run);
432 AliAnalysisTask *task;
434 // Call Notify of the event handlers
435 if (fInputEventHandler) {
436 fInputEventHandler->Notify(curfile->GetName());
439 if (fOutputEventHandler) {
440 fOutputEventHandler->Notify(curfile->GetName());
443 if (fMCtruthEventHandler) {
444 fMCtruthEventHandler->Notify(curfile->GetName());
447 // Call Notify for all tasks
448 while ((task=(AliAnalysisTask*)next()))
451 if (fDebug > 1) printf("<-AliAnalysisManager::Notify()\n");
455 //______________________________________________________________________________
456 Bool_t AliAnalysisManager::Process(Long64_t entry)
458 // The Process() function is called for each entry in the tree (or possibly
459 // keyed object in the case of PROOF) to be processed. The entry argument
460 // specifies which entry in the currently loaded tree is to be processed.
461 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
462 // to read either all or the required parts of the data. When processing
463 // keyed objects with PROOF, the object is already loaded and is available
464 // via the fObject pointer.
466 // This function should contain the "body" of the analysis. It can contain
467 // simple or elaborate selection criteria, run algorithms on the data
468 // of the event and typically fill histograms.
470 // WARNING when a selector is used with a TChain, you must use
471 // the pointer to the current TTree to call GetEntry(entry).
472 // The entry is always the local entry number in the current tree.
473 // Assuming that fChain is the pointer to the TChain being processed,
474 // use fChain->GetTree()->GetEntry(entry).
475 if (fDebug > 1) printf("->AliAnalysisManager::Process(%lld)\n", entry);
477 if (fInputEventHandler) fInputEventHandler ->BeginEvent(entry);
478 if (fOutputEventHandler) fOutputEventHandler ->BeginEvent(entry);
479 if (fMCtruthEventHandler) fMCtruthEventHandler->BeginEvent(entry);
483 if (fInputEventHandler) fInputEventHandler ->GetEntry();
486 if (fDebug > 1) printf("<-AliAnalysisManager::Process()\n");
490 //______________________________________________________________________________
491 void AliAnalysisManager::PackOutput(TList *target)
493 // Pack all output data containers in the output list. Called at SlaveTerminate
494 // stage in PROOF case for each slave.
495 if (fDebug > 1) printf("->AliAnalysisManager::PackOutput()\n");
497 Error("PackOutput", "No target. Exiting.");
500 TDirectory *cdir = gDirectory;
502 if (fInputEventHandler) fInputEventHandler ->Terminate();
503 if (fOutputEventHandler) fOutputEventHandler ->Terminate();
504 if (fMCtruthEventHandler) fMCtruthEventHandler->Terminate();
507 // Call FinishTaskOutput() for each event loop task (not called for
508 // post-event loop tasks - use Terminate() fo those)
509 TIter nexttask(fTasks);
510 AliAnalysisTask *task;
511 while ((task=(AliAnalysisTask*)nexttask())) {
512 if (!task->IsPostEventLoop()) {
513 if (fDebug > 1) printf("->FinishTaskOutput: task %s\n", task->GetName());
514 task->FinishTaskOutput();
516 if (fDebug > 1) printf("<-FinishTaskOutput: task %s\n", task->GetName());
519 // Write statistics message on the workers.
520 WriteStatisticsMsg(fNcalls);
522 if (fMode == kProofAnalysis) {
523 TIter next(fOutputs);
524 AliAnalysisDataContainer *output;
525 Bool_t isManagedByHandler = kFALSE;
528 while ((output=(AliAnalysisDataContainer*)next())) {
529 // Do not consider outputs of post event loop tasks
530 isManagedByHandler = kFALSE;
531 if (output->GetProducer() && output->GetProducer()->IsPostEventLoop()) continue;
532 const char *filename = output->GetFileName();
533 if (!(strcmp(filename, "default")) && fOutputEventHandler) {
534 isManagedByHandler = kTRUE;
535 printf("#### Handler output. Extra: %s\n", fExtraFiles.Data());
536 filename = fOutputEventHandler->GetOutputFileName();
538 // Check if data was posted to this container. If not, issue an error.
539 if (!output->GetData() && !isManagedByHandler) {
540 Error("PackOutput", "No data for output container %s. Forgot to PostData ?", output->GetName());
543 if (!output->IsSpecialOutput()) {
545 if (strlen(filename) && !isManagedByHandler) {
546 // Backup current folder
547 TDirectory *opwd = gDirectory;
548 // File resident outputs.
549 // Check first if the file exists.
550 TString openoption = "RECREATE";
551 Bool_t firsttime = kTRUE;
552 if (filestmp.FindObject(output->GetFileName())) {
555 filestmp.Add(new TNamed(output->GetFileName(),""));
557 if (!gSystem->AccessPathName(output->GetFileName()) && !firsttime) openoption = "UPDATE";
558 // TFile *file = AliAnalysisManager::OpenFile(output, openoption, kTRUE);
559 // Save data to file, then close.
560 if (output->GetData()->InheritsFrom(TCollection::Class())) {
561 // If data is a collection, we set the name of the collection
562 // as the one of the container and we save as a single key.
563 TCollection *coll = (TCollection*)output->GetData();
564 coll->SetName(output->GetName());
565 // coll->Write(output->GetName(), TObject::kSingleKey);
567 if (output->GetData()->InheritsFrom(TTree::Class())) {
568 TFile *file = AliAnalysisManager::OpenFile(output, openoption, kTRUE);
569 // Save data to file, then close.
570 TTree *tree = (TTree*)output->GetData();
571 // Check if tree is in memory
572 if (tree->GetDirectory()==gROOT) tree->SetDirectory(gDirectory);
576 // output->GetData()->Write();
579 if (fDebug > 1) printf("PackOutput %s: memory merge, file resident output\n", output->GetName());
581 // printf(" file %s listing content:\n", filename);
584 // Clear file list to release object ownership to user.
587 output->SetFile(NULL);
588 // Restore current directory
589 if (opwd) opwd->cd();
591 // Memory-resident outputs
592 if (fDebug > 1) printf("PackOutput %s: memory merge memory resident output\n", filename);
594 AliAnalysisDataWrapper *wrap = 0;
595 if (isManagedByHandler) {
596 wrap = new AliAnalysisDataWrapper(fOutputEventHandler->GetTree());
597 wrap->SetName(output->GetName());
599 else wrap =output->ExportData();
600 // Output wrappers must NOT delete data after merging - the user owns them
601 wrap->SetDeleteData(kFALSE);
604 // Special outputs. The file must be opened and connected to the container.
605 TDirectory *opwd = gDirectory;
606 TFile *file = output->GetFile();
608 AliAnalysisTask *producer = output->GetProducer();
610 "File %s for special container %s was NOT opened in %s::CreateOutputObjects !!!",
611 output->GetFileName(), output->GetName(), producer->ClassName());
614 TString outFilename = file->GetName();
615 if (fDebug > 1) printf("PackOutput %s: special output\n", output->GetName());
616 if (isManagedByHandler) {
617 // Terminate IO for files managed by the output handler
618 // file->Write() moved to AOD handler (A.G. 11.01.10)
619 // if (file) file->Write();
620 if (file && fDebug > 2) {
621 printf(" handled file %s listing content:\n", file->GetName());
624 fOutputEventHandler->TerminateIO();
627 // Release object ownership to users after writing data to file
628 if (output->GetData()->InheritsFrom(TCollection::Class())) {
629 // If data is a collection, we set the name of the collection
630 // as the one of the container and we save as a single key.
631 TCollection *coll = (TCollection*)output->GetData();
632 coll->SetName(output->GetName());
633 coll->Write(output->GetName(), TObject::kSingleKey);
635 if (output->GetData()->InheritsFrom(TTree::Class())) {
636 TTree *tree = (TTree*)output->GetData();
637 tree->SetDirectory(file);
640 output->GetData()->Write();
644 printf(" file %s listing content:\n", output->GetFileName());
647 // Clear file list to release object ownership to user.
650 output->SetFile(NULL);
652 // Restore current directory
653 if (opwd) opwd->cd();
654 // Check if a special output location was provided or the output files have to be merged
655 if (strlen(fSpecialOutputLocation.Data())) {
656 TString remote = fSpecialOutputLocation;
658 Int_t gid = gROOT->ProcessLine("gProofServ->GetGroupId();");
659 if (remote.BeginsWith("alien:")) {
660 gROOT->ProcessLine("TGrid::Connect(\"alien:\", gProofServ->GetUser());");
661 remote += outFilename;
662 remote.ReplaceAll(".root", Form("_%d.root", gid));
664 remote += Form("%s_%d_", gSystem->HostName(), gid);
665 remote += outFilename;
668 Info("PackOutput", "Output file for container %s to be copied \n at: %s. No merging.",
669 output->GetName(), remote.Data());
670 TFile::Cp ( outFilename.Data(), remote.Data() );
671 // Copy extra outputs
672 if (fExtraFiles.Length() && isManagedByHandler) {
673 TObjArray *arr = fExtraFiles.Tokenize(" ");
675 TIter nextfilename(arr);
676 while ((os=(TObjString*)nextfilename())) {
677 outFilename = os->GetString();
678 remote = fSpecialOutputLocation;
680 if (remote.BeginsWith("alien://")) {
681 remote += outFilename;
682 remote.ReplaceAll(".root", Form("_%d.root", gid));
684 remote += Form("%s_%d_", gSystem->HostName(), gid);
685 remote += outFilename;
688 Info("PackOutput", "Extra AOD file %s to be copied \n at: %s. No merging.",
689 outFilename.Data(), remote.Data());
690 TFile::Cp ( outFilename.Data(), remote.Data() );
695 // No special location specified-> use TProofOutputFile as merging utility
696 // The file at this output slot must be opened in CreateOutputObjects
697 if (fDebug > 1) printf(" File for container %s to be merged via file merger...\n", output->GetName());
703 if (fDebug > 1) printf("<-AliAnalysisManager::PackOutput: output list contains %d containers\n", target->GetSize());
706 //______________________________________________________________________________
707 void AliAnalysisManager::ImportWrappers(TList *source)
709 // Import data in output containers from wrappers coming in source.
710 if (fDebug > 1) printf("->AliAnalysisManager::ImportWrappers()\n");
711 TIter next(fOutputs);
712 AliAnalysisDataContainer *cont;
713 AliAnalysisDataWrapper *wrap;
715 Bool_t inGrid = (fMode == kGridAnalysis)?kTRUE:kFALSE;
716 TDirectory *cdir = gDirectory;
717 while ((cont=(AliAnalysisDataContainer*)next())) {
719 if (cont->GetProducer() && cont->GetProducer()->IsPostEventLoop() && !inGrid) continue;
720 if (cont->IsRegisterDataset()) continue;
721 const char *filename = cont->GetFileName();
722 Bool_t isManagedByHandler = kFALSE;
723 if (!(strcmp(filename, "default")) && fOutputEventHandler) {
724 isManagedByHandler = kTRUE;
725 filename = fOutputEventHandler->GetOutputFileName();
727 if (cont->IsSpecialOutput() || inGrid) {
728 if (strlen(fSpecialOutputLocation.Data())) continue;
729 // Copy merged file from PROOF scratch space.
730 // In case of grid the files are already in the current directory.
732 if (isManagedByHandler && fExtraFiles.Length()) {
733 // Copy extra registered dAOD files.
734 TObjArray *arr = fExtraFiles.Tokenize(" ");
736 TIter nextfilename(arr);
737 while ((os=(TObjString*)nextfilename())) GetFileFromWrapper(os->GetString(), source);
740 if (!GetFileFromWrapper(filename, source)) continue;
742 // Normally we should connect data from the copied file to the
743 // corresponding output container, but it is not obvious how to do this
744 // automatically if several objects in file...
745 TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
746 if (!f) f = TFile::Open(filename, "READ");
748 Error("ImportWrappers", "Cannot open file %s in read-only mode", filename);
752 // Cd to the directory pointed by the container
753 TString folder = cont->GetFolderName();
754 if (!folder.IsNull()) f->cd(folder);
755 // Try to fetch first an object having the container name.
756 obj = gDirectory->Get(cont->GetName());
758 Warning("ImportWrappers", "Could not import object for container %s in file %s:%s.\n Object will not be available in Terminate()",
759 cont->GetName(), filename, cont->GetFolderName());
762 wrap = new AliAnalysisDataWrapper(obj);
763 wrap->SetDeleteData(kFALSE);
765 if (!wrap) wrap = (AliAnalysisDataWrapper*)source->FindObject(cont->GetName());
767 Error("ImportWrappers","Container %s not found in analysis output !", cont->GetName());
772 printf(" Importing data for container %s\n", cont->GetName());
773 if (strlen(filename)) printf(" -> file %s\n", filename);
776 cont->ImportData(wrap);
778 if (cdir) cdir->cd();
779 if (fDebug > 1) printf("<-AliAnalysisManager::ImportWrappers(): %d containers imported\n", icont);
782 //______________________________________________________________________________
783 void AliAnalysisManager::UnpackOutput(TList *source)
785 // Called by AliAnalysisSelector::Terminate only on the client.
786 if (fDebug > 1) printf("->AliAnalysisManager::UnpackOutput()\n");
788 Error("UnpackOutput", "No target. Exiting.");
791 if (fDebug > 1) printf(" Source list contains %d containers\n", source->GetSize());
793 if (fMode == kProofAnalysis) ImportWrappers(source);
795 TIter next(fOutputs);
796 AliAnalysisDataContainer *output;
797 while ((output=(AliAnalysisDataContainer*)next())) {
798 if (!output->GetData()) continue;
799 // Check if there are client tasks that run post event loop
800 if (output->HasConsumers()) {
801 // Disable event loop semaphore
802 output->SetPostEventLoop(kTRUE);
803 TObjArray *list = output->GetConsumers();
804 Int_t ncons = list->GetEntriesFast();
805 for (Int_t i=0; i<ncons; i++) {
806 AliAnalysisTask *task = (AliAnalysisTask*)list->At(i);
807 task->CheckNotify(kTRUE);
808 // If task is active, execute it
809 if (task->IsPostEventLoop() && task->IsActive()) {
810 if (fDebug > 1) printf("== Executing post event loop task %s\n", task->GetName());
816 if (fDebug > 1) printf("<-AliAnalysisManager::UnpackOutput()\n");
819 //______________________________________________________________________________
820 void AliAnalysisManager::Terminate()
822 // The Terminate() function is the last function to be called during
823 // a query. It always runs on the client, it can be used to present
824 // the results graphically.
825 if (fDebug > 1) printf("->AliAnalysisManager::Terminate()\n");
826 TDirectory *cdir = gDirectory;
828 AliAnalysisTask *task;
829 AliAnalysisDataContainer *output;
832 Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
833 // Call Terminate() for tasks
835 while (!IsSkipTerminate() && (task=(AliAnalysisTask*)next())) {
836 // Save all the canvases produced by the Terminate
837 TString pictname = Form("%s_%s", task->GetName(), task->ClassName());
841 AliSysInfo::AddStamp(Form("%s_TERMINATE",task->ClassName()),0, itask, 2);
843 if (TObject::TestBit(kSaveCanvases)) {
844 if (!gROOT->IsBatch()) {
845 if (fDebug>1) printf("Waiting 5 sec for %s::Terminate() to finish drawing ...\n", task->ClassName());
847 while (timer.CpuTime()<5) {
849 gSystem->ProcessEvents();
852 Int_t iend = gROOT->GetListOfCanvases()->GetEntries();
853 if (iend==0) continue;
855 for (Int_t ipict=0; ipict<iend; ipict++) {
856 canvas = (TCanvas*)gROOT->GetListOfCanvases()->At(ipict);
857 if (!canvas) continue;
858 canvas->SaveAs(Form("%s_%02d.gif", pictname.Data(),ipict));
860 gROOT->GetListOfCanvases()->Delete();
864 if (fInputEventHandler) fInputEventHandler ->TerminateIO();
865 if (fOutputEventHandler) fOutputEventHandler ->TerminateIO();
866 if (fMCtruthEventHandler) fMCtruthEventHandler->TerminateIO();
868 TObjArray *allOutputs = new TObjArray();
870 for (icont=0; icont<fOutputs->GetEntriesFast(); icont++) allOutputs->Add(fOutputs->At(icont));
871 if (!IsSkipTerminate())
872 for (icont=0; icont<fParamCont->GetEntriesFast(); icont++) allOutputs->Add(fParamCont->At(icont));
873 TIter next1(allOutputs);
874 TString handlerFile = "";
875 TString extraOutputs = "";
876 if (fOutputEventHandler) {
877 handlerFile = fOutputEventHandler->GetOutputFileName();
878 extraOutputs = fOutputEventHandler->GetExtraOutputs();
882 while ((output=(AliAnalysisDataContainer*)next1())) {
883 // Special outputs or grid files have the files already closed and written.
885 if (fMode == kGridAnalysis && icont<=fOutputs->GetEntriesFast()) continue;
886 if (fMode == kProofAnalysis) {
887 if (output->IsSpecialOutput() || output->IsRegisterDataset()) continue;
889 const char *filename = output->GetFileName();
890 TString openoption = "RECREATE";
891 if (!(strcmp(filename, "default"))) continue;
892 if (!strlen(filename)) continue;
893 if (!output->GetData()) continue;
894 TDirectory *opwd = gDirectory;
895 TFile *file = output->GetFile();
896 if (!file) file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
898 //if (handlerFile == filename && !gSystem->AccessPathName(filename)) openoption = "UPDATE";
899 Bool_t firsttime = kTRUE;
900 if (filestmp.FindObject(filename) || extraOutputs.Contains(filename)) {
903 filestmp.Add(new TNamed(filename,""));
905 if (!gSystem->AccessPathName(filename) && !firsttime) openoption = "UPDATE";
906 if (fDebug>1) printf("Opening file: %s option=%s\n",filename, openoption.Data());
907 file = new TFile(filename, openoption);
909 if (fDebug>1) printf("File <%s> already opened with option: <%s> \n", filename, file->GetOption());
910 openoption = file->GetOption();
911 if (openoption == "READ") {
912 if (fDebug>1) printf("...reopening in UPDATE mode\n");
913 file->ReOpen("UPDATE");
916 if (file->IsZombie()) {
917 Error("Terminate", "Cannot open output file %s", filename);
920 output->SetFile(file);
922 // Check for a folder request
923 TString dir = output->GetFolderName();
925 if (!file->GetDirectory(dir)) file->mkdir(dir);
928 if (fDebug > 1) printf("...writing container %s to file %s:%s\n", output->GetName(), file->GetName(), output->GetFolderName());
929 if (output->GetData()->InheritsFrom(TCollection::Class())) {
930 // If data is a collection, we set the name of the collection
931 // as the one of the container and we save as a single key.
932 TCollection *coll = (TCollection*)output->GetData();
933 coll->SetName(output->GetName());
934 coll->Write(output->GetName(), TObject::kSingleKey);
936 if (output->GetData()->InheritsFrom(TTree::Class())) {
937 TTree *tree = (TTree*)output->GetData();
938 tree->SetDirectory(gDirectory);
941 output->GetData()->Write();
944 if (opwd) opwd->cd();
948 while ((output=(AliAnalysisDataContainer*)next1())) {
949 // Close all files at output
950 TDirectory *opwd = gDirectory;
951 if (output->GetFile()) {
952 // Clear file list to release object ownership to user.
953 // output->GetFile()->Clear();
954 output->GetFile()->Close();
955 output->SetFile(NULL);
956 // Copy merged outputs in alien if requested
957 if (fSpecialOutputLocation.Length() &&
958 fSpecialOutputLocation.BeginsWith("alien://")) {
959 Info("Terminate", "Copy file %s to %s", output->GetFile()->GetName(),fSpecialOutputLocation.Data());
960 TFile::Cp(output->GetFile()->GetName(),
961 Form("%s/%s", fSpecialOutputLocation.Data(), output->GetFile()->GetName()));
964 if (opwd) opwd->cd();
967 //Write statistics information on the client
968 WriteStatisticsMsg(fNcalls);
970 TDirectory *crtdir = gDirectory;
971 TFile f("syswatch.root", "RECREATE");
975 TTree *tree = AliSysInfo::MakeTree("syswatch.log");
976 tree->SetName("syswatch");
977 tree->SetMarkerStyle(kCircle);
978 tree->SetMarkerColor(kBlue);
979 tree->SetMarkerSize(0.5);
980 if (!gROOT->IsBatch()) {
981 tree->SetAlias("event", "id0");
982 tree->SetAlias("task", "id1");
983 tree->SetAlias("stage", "id2");
984 // Already defined aliases
985 // tree->SetAlias("deltaT","stampSec-stampOldSec");
986 // tree->SetAlias("T","stampSec-first");
987 // tree->SetAlias("deltaVM","(pI.fMemVirtual-pIOld.fMemVirtual)");
988 // tree->SetAlias("VM","pI.fMemVirtual");
989 TCanvas *canvas = new TCanvas("SysInfo","SysInfo",10,10,1200,800);
990 Int_t npads = 1 /*COO plot for all tasks*/ +
991 fTopTasks->GetEntries() /*Exec plot per task*/ +
992 1 /*Terminate plot for all tasks*/ +
995 Int_t iopt = (Int_t)TMath::Sqrt((Double_t)npads);
996 if (npads<iopt*(iopt+1))
997 canvas->Divide(iopt, iopt+1, 0.01, 0.01);
999 canvas->Divide(iopt+1, iopt+1, 0.01, 0.01);
1001 // draw the plot of deltaVM for Exec for each task
1002 for (itask=0; itask<fTopTasks->GetEntriesFast(); itask++) {
1003 task = (AliAnalysisTask*)fTopTasks->At(itask);
1005 cut = Form("task==%d && stage==1", itask);
1006 tree->Draw("deltaVM:event",cut,"", 1234567890, 0);
1007 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1009 hist->SetTitle(Form("%s: Exec dVM[kB]/event", task->GetName()));
1010 hist->GetYaxis()->SetTitle("deltaVM [kB]");
1013 // Draw the plot of deltaVM for CreateOutputObjects for all tasks
1015 tree->SetMarkerStyle(kFullTriangleUp);
1016 tree->SetMarkerColor(kRed);
1017 tree->SetMarkerSize(0.8);
1018 cut = "task>=0 && task<1000 && stage==0";
1019 tree->Draw("deltaVM:sname",cut,"", 1234567890, 0);
1020 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1022 hist->SetTitle("Memory in CreateOutputObjects()");
1023 hist->GetYaxis()->SetTitle("deltaVM [kB]");
1024 hist->GetXaxis()->SetTitle("task");
1026 // draw the plot of deltaVM for Terminate for all tasks
1028 tree->SetMarkerStyle(kOpenSquare);
1029 tree->SetMarkerColor(kMagenta);
1030 cut = "task>=0 && task<1000 && stage==2";
1031 tree->Draw("deltaVM:sname",cut,"", 1234567890, 0);
1032 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1034 hist->SetTitle("Memory in Terminate()");
1035 hist->GetYaxis()->SetTitle("deltaVM [kB]");
1036 hist->GetXaxis()->SetTitle("task");
1040 tree->SetMarkerStyle(kFullCircle);
1041 tree->SetMarkerColor(kGreen);
1042 cut = Form("task==%d && stage==1",fTopTasks->GetEntriesFast()-1);
1043 tree->Draw("VM:event",cut,"", 1234567890, 0);
1044 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1046 hist->SetTitle("Virtual memory");
1047 hist->GetYaxis()->SetTitle("VM [kB]");
1051 tree->SetMarkerStyle(kCircle);
1052 tree->SetMarkerColor(kBlue);
1053 tree->SetMarkerSize(0.5);
1058 if (crtdir) crtdir->cd();
1060 // Validate the output files
1061 if (ValidateOutputFiles()) {
1063 out.open("outputs_valid", ios::out);
1067 if (fDebug > 1) printf("<-AliAnalysisManager::Terminate()\n");
1069 //______________________________________________________________________________
1070 void AliAnalysisManager::ProfileTask(Int_t itop, const char *option) const
1072 // Profiles the task having the itop index in the list of top (first level) tasks.
1073 AliAnalysisTask *task = (AliAnalysisTask*)fTopTasks->At(itop);
1075 Error("ProfileTask", "There are only %d top tasks in the manager", fTopTasks->GetEntries());
1078 ProfileTask(task->GetName(), option);
1081 //______________________________________________________________________________
1082 void AliAnalysisManager::ProfileTask(const char *name, const char */*option*/) const
1084 // Profile a managed task after the execution of the analysis in case NSysInfo
1086 if (gSystem->AccessPathName("syswatch.root")) {
1087 Error("ProfileTask", "No file syswatch.root found in the current directory");
1090 if (gROOT->IsBatch()) return;
1091 AliAnalysisTask *task = (AliAnalysisTask*)fTopTasks->FindObject(name);
1093 Error("ProfileTask", "No top task named %s known by the manager.", name);
1096 Int_t itop = fTopTasks->IndexOf(task);
1097 Int_t itask = fTasks->IndexOf(task);
1098 // Create canvas with 2 pads: first draw COO + Terminate, second Exec
1099 TDirectory *cdir = gDirectory;
1100 TFile f("syswatch.root");
1101 TTree *tree = (TTree*)f.Get("syswatch");
1103 Error("ProfileTask", "No tree named <syswatch> found in file syswatch.root");
1106 if (fDebug > 1) printf("=== Profiling task %s (class %s)\n", name, task->ClassName());
1107 TCanvas *canvas = new TCanvas(Form("profile_%d",itop),Form("Profile of task %s (class %s)",name,task->ClassName()),10,10,800,600);
1108 canvas->Divide(2, 2, 0.01, 0.01);
1112 // VM profile for COO and Terminate methods
1114 cut = Form("task==%d && (stage==0 || stage==2)",itask);
1115 tree->Draw("deltaVM:sname",cut,"", 1234567890, 0);
1116 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1118 hist->SetTitle("Alocated VM[kB] for COO and Terminate");
1119 hist->GetYaxis()->SetTitle("deltaVM [kB]");
1120 hist->GetXaxis()->SetTitle("method");
1122 // CPU profile per event
1124 cut = Form("task==%d && stage==1",itop);
1125 tree->Draw("deltaT:event",cut,"", 1234567890, 0);
1126 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1128 hist->SetTitle("Execution time per event");
1129 hist->GetYaxis()->SetTitle("CPU/event [s]");
1131 // VM profile for Exec
1133 cut = Form("task==%d && stage==1",itop);
1134 tree->Draw("deltaVM:event",cut,"", 1234567890, 0);
1135 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1137 hist->SetTitle("Alocated VM[kB] per event");
1138 hist->GetYaxis()->SetTitle("deltaVM [kB]");
1143 if (cdir) cdir->cd();
1146 //______________________________________________________________________________
1147 void AliAnalysisManager::AddTask(AliAnalysisTask *task)
1149 // Adds a user task to the global list of tasks.
1150 if (fTasks->FindObject(task)) {
1151 Warning("AddTask", "Task %s: the same object already added to the analysis manager. Not adding.", task->GetName());
1154 task->SetActive(kFALSE);
1158 //______________________________________________________________________________
1159 AliAnalysisTask *AliAnalysisManager::GetTask(const char *name) const
1161 // Retreive task by name.
1162 if (!fTasks) return NULL;
1163 return (AliAnalysisTask*)fTasks->FindObject(name);
1166 //______________________________________________________________________________
1167 AliAnalysisDataContainer *AliAnalysisManager::CreateContainer(const char *name,
1168 TClass *datatype, EAliAnalysisContType type, const char *filename)
1170 // Create a data container of a certain type. Types can be:
1171 // kExchangeContainer = 0, used to exchange data between tasks
1172 // kInputContainer = 1, used to store input data
1173 // kOutputContainer = 2, used for writing result to a file
1174 // filename: composed by file#folder (e.g. results.root#INCLUSIVE) - will write
1175 // the output object to a folder inside the output file
1176 if (fContainers->FindObject(name)) {
1177 Error("CreateContainer","A container named %s already defined !",name);
1180 AliAnalysisDataContainer *cont = new AliAnalysisDataContainer(name, datatype);
1181 fContainers->Add(cont);
1183 case kInputContainer:
1186 case kOutputContainer:
1187 fOutputs->Add(cont);
1188 if (filename && strlen(filename)) {
1189 cont->SetFileName(filename);
1190 cont->SetDataOwned(kFALSE); // data owned by the file
1193 case kParamContainer:
1194 fParamCont->Add(cont);
1195 if (filename && strlen(filename)) {
1196 cont->SetFileName(filename);
1197 cont->SetDataOwned(kFALSE); // data owned by the file
1200 case kExchangeContainer:
1206 //______________________________________________________________________________
1207 Bool_t AliAnalysisManager::ConnectInput(AliAnalysisTask *task, Int_t islot,
1208 AliAnalysisDataContainer *cont)
1210 // Connect input of an existing task to a data container.
1212 Error("ConnectInput", "Task pointer is NULL");
1215 if (!fTasks->FindObject(task)) {
1217 Info("ConnectInput", "Task %s was not registered. Now owned by analysis manager", task->GetName());
1219 Bool_t connected = task->ConnectInput(islot, cont);
1223 //______________________________________________________________________________
1224 Bool_t AliAnalysisManager::ConnectOutput(AliAnalysisTask *task, Int_t islot,
1225 AliAnalysisDataContainer *cont)
1227 // Connect output of an existing task to a data container.
1229 Error("ConnectOutput", "Task pointer is NULL");
1232 if (!fTasks->FindObject(task)) {
1234 Warning("ConnectOutput", "Task %s not registered. Now owned by analysis manager", task->GetName());
1236 Bool_t connected = task->ConnectOutput(islot, cont);
1240 //______________________________________________________________________________
1241 void AliAnalysisManager::CleanContainers()
1243 // Clean data from all containers that have already finished all client tasks.
1244 TIter next(fContainers);
1245 AliAnalysisDataContainer *cont;
1246 while ((cont=(AliAnalysisDataContainer *)next())) {
1247 if (cont->IsOwnedData() &&
1248 cont->IsDataReady() &&
1249 cont->ClientsExecuted()) cont->DeleteData();
1253 //______________________________________________________________________________
1254 Bool_t AliAnalysisManager::InitAnalysis()
1256 // Initialization of analysis chain of tasks. Should be called after all tasks
1257 // and data containers are properly connected
1258 // Reset flag and remove valid_outputs file if exists
1260 if (!gSystem->AccessPathName("outputs_valid"))
1261 gSystem->Unlink("outputs_valid");
1262 // Check for top tasks (depending only on input data containers)
1263 if (!fTasks->First()) {
1264 Error("InitAnalysis", "Analysis has no tasks !");
1268 AliAnalysisTask *task;
1269 AliAnalysisDataContainer *cont;
1272 Bool_t iszombie = kFALSE;
1273 Bool_t istop = kTRUE;
1275 while ((task=(AliAnalysisTask*)next())) {
1278 Int_t ninputs = task->GetNinputs();
1279 for (i=0; i<ninputs; i++) {
1280 cont = task->GetInputSlot(i)->GetContainer();
1284 fZombies->Add(task);
1288 Error("InitAnalysis", "Input slot %d of task %s has no container connected ! Declared zombie...",
1289 i, task->GetName());
1291 if (iszombie) continue;
1292 // Check if cont is an input container
1293 if (istop && !fInputs->FindObject(cont)) istop=kFALSE;
1294 // Connect to parent task
1298 fTopTasks->Add(task);
1302 Error("InitAnalysis", "No top task defined. At least one task should be connected only to input containers");
1305 // Check now if there are orphan tasks
1306 for (i=0; i<ntop; i++) {
1307 task = (AliAnalysisTask*)fTopTasks->At(i);
1312 while ((task=(AliAnalysisTask*)next())) {
1313 if (!task->IsUsed()) {
1315 Warning("InitAnalysis", "Task %s is orphan", task->GetName());
1318 // Check the task hierarchy (no parent task should depend on data provided
1319 // by a daughter task)
1320 for (i=0; i<ntop; i++) {
1321 task = (AliAnalysisTask*)fTopTasks->At(i);
1322 if (task->CheckCircularDeps()) {
1323 Error("InitAnalysis", "Found illegal circular dependencies between following tasks:");
1328 // Check that all containers feeding post-event loop tasks are in the outputs list
1329 TIter nextcont(fContainers); // loop over all containers
1330 while ((cont=(AliAnalysisDataContainer*)nextcont())) {
1331 if (!cont->IsPostEventLoop() && !fOutputs->FindObject(cont)) {
1332 if (cont->HasConsumers()) {
1333 // Check if one of the consumers is post event loop
1334 TIter nextconsumer(cont->GetConsumers());
1335 while ((task=(AliAnalysisTask*)nextconsumer())) {
1336 if (task->IsPostEventLoop()) {
1337 fOutputs->Add(cont);
1344 // Check if all special output containers have a file name provided
1345 TIter nextout(fOutputs);
1346 while ((cont=(AliAnalysisDataContainer*)nextout())) {
1347 if (cont->IsSpecialOutput() && !strlen(cont->GetFileName())) {
1348 Error("InitAnalysis", "Wrong container %s : a file name MUST be provided for special outputs", cont->GetName());
1356 //______________________________________________________________________________
1357 void AliAnalysisManager::PrintStatus(Option_t *option) const
1359 // Print task hierarchy.
1361 Info("PrintStatus", "Analysis manager %s not initialized : call InitAnalysis() first", GetName());
1364 Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
1366 Info("PrintStatus", "System information will be collected each %lld events", fNSysInfo);
1367 TIter next(fTopTasks);
1368 AliAnalysisTask *task;
1369 while ((task=(AliAnalysisTask*)next()))
1370 task->PrintTask(option);
1373 //______________________________________________________________________________
1374 void AliAnalysisManager::ResetAnalysis()
1376 // Reset all execution flags and clean containers.
1380 //______________________________________________________________________________
1381 Long64_t AliAnalysisManager::StartAnalysis(const char *type, Long64_t nentries, Long64_t firstentry)
1383 // Start analysis having a grid handler.
1384 if (!fGridHandler) {
1385 Error("StartAnalysis", "Cannot start analysis providing just the analysis type without a grid handler.");
1386 Info("===", "Add an AliAnalysisAlien object as plugin for this manager and configure it.");
1390 return StartAnalysis(type, tree, nentries, firstentry);
1393 //______________________________________________________________________________
1394 Long64_t AliAnalysisManager::StartAnalysis(const char *type, TTree * const tree, Long64_t nentries, Long64_t firstentry)
1396 // Start analysis for this manager. Analysis task can be: LOCAL, PROOF, GRID or
1397 // MIX. Process nentries starting from firstentry
1399 // Backup current directory and make sure gDirectory points to gROOT
1400 TDirectory *cdir = gDirectory;
1403 Error("StartAnalysis","Analysis manager was not initialized !");
1407 if (fDebug > 1) printf("StartAnalysis %s\n",GetName());
1409 TString anaType = type;
1411 fMode = kLocalAnalysis;
1412 Bool_t runlocalinit = kTRUE;
1413 if (anaType.Contains("file")) {
1414 runlocalinit = kFALSE;
1417 if (anaType.Contains("proof")) fMode = kProofAnalysis;
1418 else if (anaType.Contains("grid")) fMode = kGridAnalysis;
1419 else if (anaType.Contains("mix")) fMode = kMixingAnalysis;
1421 if (fMode == kGridAnalysis) {
1423 if (!anaType.Contains("terminate")) {
1424 if (!fGridHandler) {
1425 Error("StartAnalysis", "Cannot start grid analysis without a grid handler.");
1426 Info("===", "Add an AliAnalysisAlien object as plugin for this manager and configure it.");
1430 // Write analysis manager in the analysis file
1431 cout << "===== RUNNING GRID ANALYSIS: " << GetName() << endl;
1432 // run local task configuration
1433 TIter nextTask(fTasks);
1434 AliAnalysisTask *task;
1435 while ((task=(AliAnalysisTask*)nextTask())) {
1439 if (!fGridHandler->StartAnalysis(nentries, firstentry)) {
1440 Info("StartAnalysis", "Grid analysis was stopped and cannot be terminated");
1445 // Terminate grid analysis
1446 if (fSelector && fSelector->GetStatus() == -1) {cdir->cd(); return -1;}
1447 if (fGridHandler->GetRunMode() == AliAnalysisGrid::kOffline) {cdir->cd(); return 0;}
1448 cout << "===== MERGING OUTPUTS REGISTERED BY YOUR ANALYSIS JOB: " << GetName() << endl;
1449 if (!fGridHandler->MergeOutputs()) {
1450 // Return if outputs could not be merged or if it alien handler
1451 // was configured for offline mode or local testing.
1456 cout << "===== TERMINATING GRID ANALYSIS JOB: " << GetName() << endl;
1457 ImportWrappers(NULL);
1463 SetEventLoop(kFALSE);
1464 // Enable event loop mode if a tree was provided
1465 if (tree || fGridHandler || fMode==kMixingAnalysis) SetEventLoop(kTRUE);
1468 TString ttype = "TTree";
1469 if (tree && tree->IsA() == TChain::Class()) {
1470 chain = (TChain*)tree;
1471 if (!chain || !chain->GetListOfFiles()->First()) {
1472 Error("StartAnalysis", "Cannot process null or empty chain...");
1479 Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
1480 if (getsysInfo) AliSysInfo::AddStamp("Start", 0);
1481 // Initialize locally all tasks (happens for all modes)
1483 AliAnalysisTask *task;
1485 while ((task=(AliAnalysisTask*)next())) {
1489 if (getsysInfo) AliSysInfo::AddStamp("LocalInit_all", 0);
1493 case kLocalAnalysis:
1494 if (!tree && !fGridHandler) {
1495 TIter nextT(fTasks);
1496 // Call CreateOutputObjects for all tasks
1498 Bool_t dirStatus = TH1::AddDirectoryStatus();
1499 while ((task=(AliAnalysisTask*)nextT())) {
1500 TH1::AddDirectory(kFALSE);
1501 task->CreateOutputObjects();
1502 if (getsysInfo) AliSysInfo::AddStamp(Form("%s_CREATEOUTOBJ",task->ClassName()), 0, itask, 0);
1506 TH1::AddDirectory(dirStatus);
1507 if (IsExternalLoop()) {
1508 Info("StartAnalysis", "Initialization done. Event loop is controlled externally.\
1509 \nSetData for top container, call ExecAnalysis in a loop and then Terminate manually");
1516 fSelector = new AliAnalysisSelector(this);
1517 // Check if a plugin handler is used
1519 // Get the chain from the plugin
1520 TString dataType = "esdTree";
1521 if (fInputEventHandler) {
1522 dataType = fInputEventHandler->GetDataType();
1526 chain = fGridHandler->GetChainForTestMode(dataType);
1528 Error("StartAnalysis", "No chain for test mode. Aborting.");
1531 cout << "===== RUNNING LOCAL ANALYSIS" << GetName() << " ON CHAIN " << chain->GetName() << endl;
1532 retv = chain->Process(fSelector, "", nentries, firstentry);
1535 // Run tree-based analysis via AliAnalysisSelector
1536 cout << "===== RUNNING LOCAL ANALYSIS " << GetName() << " ON TREE " << tree->GetName() << endl;
1537 retv = tree->Process(fSelector, "", nentries, firstentry);
1539 case kProofAnalysis:
1541 // Check if the plugin is used
1543 return StartAnalysis(type, fGridHandler->GetProofDataSet(), nentries, firstentry);
1545 if (!gROOT->GetListOfProofs() || !gROOT->GetListOfProofs()->GetEntries()) {
1546 Error("StartAnalysis", "No PROOF!!! Exiting.");
1550 line = Form("gProof->AddInput((TObject*)0x%lx);", (ULong_t)this);
1551 gROOT->ProcessLine(line);
1554 cout << "===== RUNNING PROOF ANALYSIS " << GetName() << " ON CHAIN " << chain->GetName() << endl;
1555 retv = chain->Process("AliAnalysisSelector", "", nentries, firstentry);
1557 Error("StartAnalysis", "No chain!!! Exiting.");
1564 if (!anaType.Contains("terminate")) {
1565 if (!fGridHandler) {
1566 Error("StartAnalysis", "Cannot start grid analysis without a grid handler.");
1567 Info("===", "Add an AliAnalysisAlien object as plugin for this manager and configure it.");
1571 // Write analysis manager in the analysis file
1572 cout << "===== RUNNING GRID ANALYSIS: " << GetName() << endl;
1573 // Start the analysis via the handler
1574 if (!fGridHandler->StartAnalysis(nentries, firstentry)) {
1575 Info("StartAnalysis", "Grid analysis was stopped and cannot be terminated");
1580 // Terminate grid analysis
1581 if (fSelector && fSelector->GetStatus() == -1) {cdir->cd(); return -1;}
1582 if (fGridHandler->GetRunMode() == AliAnalysisGrid::kOffline) {cdir->cd(); return 0;}
1583 cout << "===== MERGING OUTPUTS REGISTERED BY YOUR ANALYSIS JOB: " << GetName() << endl;
1584 if (!fGridHandler->MergeOutputs()) {
1585 // Return if outputs could not be merged or if it alien handler
1586 // was configured for offline mode or local testing.
1591 cout << "===== TERMINATING GRID ANALYSIS JOB: " << GetName() << endl;
1592 ImportWrappers(NULL);
1596 case kMixingAnalysis:
1597 // Run event mixing analysis
1599 Error("StartAnalysis", "Cannot run event mixing without event pool");
1603 cout << "===== RUNNING EVENT MIXING ANALYSIS " << GetName() << endl;
1604 fSelector = new AliAnalysisSelector(this);
1605 while ((chain=fEventPool->GetNextChain())) {
1607 // Call NotifyBinChange for all tasks
1608 while ((task=(AliAnalysisTask*)next()))
1609 if (!task->IsPostEventLoop()) task->NotifyBinChange();
1610 retv = chain->Process(fSelector);
1612 Error("StartAnalysis", "Mixing analysis failed");
1617 PackOutput(fSelector->GetOutputList());
1624 //______________________________________________________________________________
1625 Long64_t AliAnalysisManager::StartAnalysis(const char *type, const char *dataset, Long64_t nentries, Long64_t firstentry)
1627 // Start analysis for this manager on a given dataset. Analysis task can be:
1628 // LOCAL, PROOF or GRID. Process nentries starting from firstentry.
1630 Error("StartAnalysis","Analysis manager was not initialized !");
1634 if (fDebug > 1) printf("StartAnalysis %s\n",GetName());
1635 TString anaType = type;
1637 if (!anaType.Contains("proof")) {
1638 Error("StartAnalysis", "Cannot process datasets in %s mode. Try PROOF.", type);
1641 fMode = kProofAnalysis;
1643 SetEventLoop(kTRUE);
1644 // Set the dataset flag
1645 TObject::SetBit(kUseDataSet);
1649 // Start proof analysis using the grid handler
1650 if (!fGridHandler->StartAnalysis(nentries, firstentry)) {
1651 Error("StartAnalysis", "The grid plugin could not start PROOF analysis");
1654 // Check if the plugin is in test mode
1655 if (fGridHandler->GetRunMode() == AliAnalysisGrid::kTest) {
1656 dataset = "test_collection";
1658 dataset = fGridHandler->GetProofDataSet();
1662 if (!gROOT->GetListOfProofs() || !gROOT->GetListOfProofs()->GetEntries()) {
1663 Error("StartAnalysis", "No PROOF!!! Exiting.");
1667 // Initialize locally all tasks
1669 AliAnalysisTask *task;
1670 while ((task=(AliAnalysisTask*)next())) {
1674 line = Form("gProof->AddInput((TObject*)0x%lx);", (ULong_t)this);
1675 gROOT->ProcessLine(line);
1678 // chain->SetProof();
1679 cout << "===== RUNNING PROOF ANALYSIS " << GetName() << " ON TEST CHAIN " << chain->GetName() << endl;
1680 retv = chain->Process("AliAnalysisSelector", "", nentries, firstentry);
1682 line = Form("gProof->Process(\"%s\", \"AliAnalysisSelector\", \"\", %lld, %lld);",
1683 dataset, nentries, firstentry);
1684 cout << "===== RUNNING PROOF ANALYSIS " << GetName() << " ON DATASET " << dataset << endl;
1685 retv = (Long_t)gROOT->ProcessLine(line);
1690 //______________________________________________________________________________
1691 TFile *AliAnalysisManager::OpenFile(AliAnalysisDataContainer *cont, const char *option, Bool_t ignoreProof)
1693 // Opens according the option the file specified by cont->GetFileName() and changes
1694 // current directory to cont->GetFolderName(). If the file was already opened, it
1695 // checks if the option UPDATE was preserved. File open via TProofOutputFile can
1696 // be optionally ignored.
1697 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1698 TString filename = cont->GetFileName();
1700 if (filename.IsNull()) {
1701 ::Error("AliAnalysisManager::OpenFile", "No file name specified for container %s", cont->GetName());
1704 if (mgr->GetAnalysisType()==AliAnalysisManager::kProofAnalysis && cont->IsSpecialOutput()
1706 f = mgr->OpenProofFile(cont,option);
1708 // Check first if the file is already opened
1709 f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
1711 // Check if option "UPDATE" was preserved
1712 TString opt(option);
1714 if ((opt=="UPDATE") && (opt!=f->GetOption()))
1715 ::Info("AliAnalysisManager::OpenFile", "File %s already opened in %s mode!", cont->GetFileName(), f->GetOption());
1717 f = TFile::Open(filename, option);
1720 if (f && !f->IsZombie() && !f->TestBit(TFile::kRecovered)) {
1724 // Check for a folder request
1725 TString dir = cont->GetFolderName();
1726 if (!dir.IsNull()) {
1727 if (!f->GetDirectory(dir)) f->mkdir(dir);
1732 ::Fatal("AliAnalysisManager::OpenFile", "File %s could not be opened", filename.Data());
1733 cont->SetFile(NULL);
1737 //______________________________________________________________________________
1738 TFile *AliAnalysisManager::OpenProofFile(AliAnalysisDataContainer *cont, const char *option, const char *extaod)
1740 // Opens a special output file used in PROOF.
1742 TString filename = cont->GetFileName();
1743 if (cont == fCommonOutput) {
1744 if (fOutputEventHandler) {
1745 if (strlen(extaod)) filename = extaod;
1746 filename = fOutputEventHandler->GetOutputFileName();
1748 else Fatal("OpenProofFile","No output container. Exiting.");
1751 if (fMode!=kProofAnalysis || !fSelector) {
1752 Fatal("OpenProofFile","Cannot open PROOF file %s: no PROOF or selector",filename.Data());
1755 if (fSpecialOutputLocation.Length()) {
1756 f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
1758 // Check if option "UPDATE" was preserved
1759 TString opt(option);
1761 if ((opt=="UPDATE") && (opt!=f->GetOption()))
1762 ::Info("OpenProofFile", "File %s already opened in %s mode!", cont->GetFileName(), f->GetOption());
1764 f = new TFile(filename, option);
1766 if (f && !f->IsZombie() && !f->TestBit(TFile::kRecovered)) {
1770 // Check for a folder request
1771 TString dir = cont->GetFolderName();
1773 if (!f->GetDirectory(dir)) f->mkdir(dir);
1778 Fatal("OpenProofFile", "File %s could not be opened", cont->GetFileName());
1779 cont->SetFile(NULL);
1782 // Check if there is already a proof output file in the output list
1783 TObject *pof = fSelector->GetOutputList()->FindObject(filename);
1785 // Get the actual file
1786 line = Form("((TProofOutputFile*)0x%lx)->GetFileName();", (ULong_t)pof);
1787 filename = (const char*)gROOT->ProcessLine(line);
1789 printf("File: %s already booked via TProofOutputFile\n", filename.Data());
1791 f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
1793 Fatal("OpenProofFile", "Proof output file found but no file opened for %s", filename.Data());
1796 // Check if option "UPDATE" was preserved
1797 TString opt(option);
1799 if ((opt=="UPDATE") && (opt!=f->GetOption()))
1800 Fatal("OpenProofFile", "File %s already opened, but not in UPDATE mode!", cont->GetFileName());
1802 if (cont->IsRegisterDataset()) {
1803 TString dsetName = filename;
1804 dsetName.ReplaceAll(".root", cont->GetTitle());
1805 dsetName.ReplaceAll(":","_");
1806 if (fDebug>1) printf("Booking dataset: %s\n", dsetName.Data());
1807 line = Form("TProofOutputFile *pf = new TProofOutputFile(\"%s\", \"DROV\", \"%s\");", filename.Data(), dsetName.Data());
1809 if (fDebug>1) printf("Booking TProofOutputFile: %s to be merged\n", filename.Data());
1810 line = Form("TProofOutputFile *pf = new TProofOutputFile(\"%s\");", filename.Data());
1812 if (fDebug > 1) printf("=== %s\n", line.Data());
1813 gROOT->ProcessLine(line);
1814 line = Form("pf->OpenFile(\"%s\");", option);
1815 gROOT->ProcessLine(line);
1818 gROOT->ProcessLine("pf->Print()");
1819 printf(" == proof file name: %s", f->GetName());
1821 // Add to proof output list
1822 line = Form("((TList*)0x%lx)->Add(pf);",(ULong_t)fSelector->GetOutputList());
1823 if (fDebug > 1) printf("=== %s\n", line.Data());
1824 gROOT->ProcessLine(line);
1826 if (f && !f->IsZombie() && !f->TestBit(TFile::kRecovered)) {
1830 // Check for a folder request
1831 TString dir = cont->GetFolderName();
1832 if (!dir.IsNull()) {
1833 if (!f->GetDirectory(dir)) f->mkdir(dir);
1838 Fatal("OpenProofFile", "File %s could not be opened", cont->GetFileName());
1839 cont->SetFile(NULL);
1843 //______________________________________________________________________________
1844 void AliAnalysisManager::ExecAnalysis(Option_t *option)
1846 // Execute analysis.
1847 static Long64_t nentries = 0;
1848 static TTree *lastTree = 0;
1849 static TStopwatch *timer = new TStopwatch();
1850 if (fDebug > 0) printf("MGR: Processing event #%d\n", fNcalls);
1852 if (fTree && (fTree != lastTree)) {
1853 nentries += fTree->GetEntries();
1856 if (!fNcalls) timer->Start();
1857 if (!fIsRemote && TObject::TestBit(kUseProgressBar)) ProgressBar("Processing event", fNcalls, nentries, timer, kFALSE);
1860 TDirectory *cdir = gDirectory;
1861 Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
1862 if (getsysInfo && ((fNcalls%fNSysInfo)==0)) AliSysInfo::AddStamp("Exec_start", (Int_t)fNcalls);
1864 Error("ExecAnalysis", "Analysis manager was not initialized !");
1869 AliAnalysisTask *task;
1870 // Check if the top tree is active.
1872 if (getsysInfo && ((fNcalls%fNSysInfo)==0))
1873 AliSysInfo::AddStamp("Handlers_BeginEventGroup",fNcalls, 1002, 0);
1875 // De-activate all tasks
1876 while ((task=(AliAnalysisTask*)next())) task->SetActive(kFALSE);
1877 AliAnalysisDataContainer *cont = fCommonInput;
1878 if (!cont) cont = (AliAnalysisDataContainer*)fInputs->At(0);
1880 Error("ExecAnalysis","Cannot execute analysis in TSelector mode without at least one top container");
1884 cont->SetData(fTree); // This will notify all consumers
1885 Long64_t entry = fTree->GetTree()->GetReadEntry();
1887 // Call BeginEvent() for optional input/output and MC services
1888 if (fInputEventHandler) fInputEventHandler ->BeginEvent(entry);
1889 if (fOutputEventHandler) fOutputEventHandler ->BeginEvent(entry);
1890 if (fMCtruthEventHandler) fMCtruthEventHandler->BeginEvent(entry);
1892 if (getsysInfo && ((fNcalls%fNSysInfo)==0))
1893 AliSysInfo::AddStamp("Handlers_BeginEvent",fNcalls, 1000, 0);
1895 // Execute the tasks
1896 // TIter next1(cont->GetConsumers());
1897 TIter next1(fTopTasks);
1899 while ((task=(AliAnalysisTask*)next1())) {
1901 cout << " Executing task " << task->GetName() << endl;
1903 task->ExecuteTask(option);
1905 if (getsysInfo && ((fNcalls%fNSysInfo)==0))
1906 AliSysInfo::AddStamp(task->ClassName(), fNcalls, itask, 1);
1910 // Call FinishEvent() for optional output and MC services
1911 if (fInputEventHandler) fInputEventHandler ->FinishEvent();
1912 if (fOutputEventHandler) fOutputEventHandler ->FinishEvent();
1913 if (fMCtruthEventHandler) fMCtruthEventHandler->FinishEvent();
1914 // Gather system information if requested
1915 if (getsysInfo && ((fNcalls%fNSysInfo)==0))
1916 AliSysInfo::AddStamp("Handlers_FinishEvent",fNcalls, 1001, 1);
1920 // The event loop is not controlled by TSelector
1922 // Call BeginEvent() for optional input/output and MC services
1923 if (fInputEventHandler) fInputEventHandler ->BeginEvent(-1);
1924 if (fOutputEventHandler) fOutputEventHandler ->BeginEvent(-1);
1925 if (fMCtruthEventHandler) fMCtruthEventHandler->BeginEvent(-1);
1927 if (getsysInfo && ((fNcalls%fNSysInfo)==0))
1928 AliSysInfo::AddStamp("Handlers_BeginEvent",fNcalls, 1000, 0);
1929 TIter next2(fTopTasks);
1930 while ((task=(AliAnalysisTask*)next2())) {
1931 task->SetActive(kTRUE);
1933 cout << " Executing task " << task->GetName() << endl;
1935 task->ExecuteTask(option);
1939 // Call FinishEvent() for optional output and MC services
1940 if (fInputEventHandler) fInputEventHandler ->FinishEvent();
1941 if (fOutputEventHandler) fOutputEventHandler ->FinishEvent();
1942 if (fMCtruthEventHandler) fMCtruthEventHandler->FinishEvent();
1943 if (getsysInfo && ((fNcalls%fNSysInfo)==0))
1944 AliSysInfo::AddStamp("Handlers_FinishEvent",fNcalls, 1000, 1);
1948 //______________________________________________________________________________
1949 void AliAnalysisManager::SetInputEventHandler(AliVEventHandler* const handler)
1951 // Set the input event handler and create a container for it.
1952 fInputEventHandler = handler;
1953 fCommonInput = CreateContainer("cAUTO_INPUT", TChain::Class(), AliAnalysisManager::kInputContainer);
1954 // Warning("SetInputEventHandler", " An automatic input container for the input chain was created.\nPlease use: mgr->GetCommonInputContainer() to access it.");
1957 //______________________________________________________________________________
1958 void AliAnalysisManager::SetOutputEventHandler(AliVEventHandler* const handler)
1960 // Set the input event handler and create a container for it.
1961 fOutputEventHandler = handler;
1962 fCommonOutput = CreateContainer("cAUTO_OUTPUT", TTree::Class(), AliAnalysisManager::kOutputContainer, "default");
1963 fCommonOutput->SetSpecialOutput();
1964 // Warning("SetOutputEventHandler", " An automatic output container for the output tree was created.\nPlease use: mgr->GetCommonOutputContainer() to access it.");
1967 //______________________________________________________________________________
1968 void AliAnalysisManager::RegisterExtraFile(const char *fname)
1970 // This method is used externally to register output files which are not
1971 // connected to any output container, so that the manager can properly register,
1972 // retrieve or merge them when running in distributed mode. The file names are
1973 // separated by blancs. The method has to be called in MyAnalysisTask::LocalInit().
1974 if (fExtraFiles.Contains(fname)) return;
1975 if (fExtraFiles.Length()) fExtraFiles += " ";
1976 fExtraFiles += fname;
1979 //______________________________________________________________________________
1980 Bool_t AliAnalysisManager::GetFileFromWrapper(const char *filename, const TList *source)
1982 // Copy a file from the location specified ina the wrapper with the same name from the source list.
1985 TObject *pof = source->FindObject(filename);
1986 if (!pof || !pof->InheritsFrom("TProofOutputFile")) {
1987 Error("GetFileFromWrapper", "TProofOutputFile object not found in output list for file %s", filename);
1990 gROOT->ProcessLine(Form("sprintf((char*)0x%lx, \"%%s\", ((TProofOutputFile*)0x%lx)->GetOutputFileName();)", (ULong_t)fullPath, (ULong_t)pof));
1991 gROOT->ProcessLine(Form("sprintf((char*)0x%lx, \"%%s\", gProof->GetUrl();)", (ULong_t)chUrl));
1992 TString clientUrl(chUrl);
1993 TString fullPath_str(fullPath);
1994 if (clientUrl.Contains("localhost")){
1995 TObjArray* array = fullPath_str.Tokenize ( "//" );
1996 TObjString *strobj = ( TObjString *)array->At(1);
1997 TObjArray* arrayPort = strobj->GetString().Tokenize ( ":" );
1998 TObjString *strobjPort = ( TObjString *) arrayPort->At(1);
1999 fullPath_str.ReplaceAll(strobj->GetString().Data(),"localhost:PORT");
2000 fullPath_str.ReplaceAll(":PORT",Form(":%s",strobjPort->GetString().Data()));
2001 if (fDebug > 1) Info("GetFileFromWrapper","Using tunnel from %s to %s",fullPath_str.Data(),filename);
2006 Info("GetFileFromWrapper","Copying file %s from PROOF scratch space", fullPath_str.Data());
2007 Bool_t gotit = TFile::Cp(fullPath_str.Data(), filename);
2009 Error("GetFileFromWrapper", "Could not get file %s from proof scratch space", filename);
2013 //______________________________________________________________________________
2014 void AliAnalysisManager::GetAnalysisTypeString(TString &type) const
2016 // Fill analysis type in the provided string.
2018 case kLocalAnalysis:
2021 case kProofAnalysis:
2027 case kMixingAnalysis:
2032 //______________________________________________________________________________
2033 Bool_t AliAnalysisManager::ValidateOutputFiles() const
2035 // Validate all output files.
2036 TIter next(fOutputs);
2037 AliAnalysisDataContainer *output;
2038 TDirectory *cdir = gDirectory;
2039 TString openedFiles;
2040 while ((output=(AliAnalysisDataContainer*)next())) {
2041 if (output->IsRegisterDataset()) continue;
2042 TString filename = output->GetFileName();
2043 if (filename == "default") {
2044 if (!fOutputEventHandler) continue;
2045 filename = fOutputEventHandler->GetOutputFileName();
2046 // Main AOD may not be there
2047 if (gSystem->AccessPathName(filename)) continue;
2049 // Check if the file is closed
2050 if (openedFiles.Contains(filename)) continue;;
2051 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
2053 Warning("ValidateOutputs", "File %s was not closed. Closing.", filename.Data());
2054 // Clear file list to release object ownership to user.
2058 file = TFile::Open(filename);
2059 if (!file || file->IsZombie() || file->TestBit(TFile::kRecovered)) {
2060 Error("ValidateOutputs", "Output file <%s> was not created or invalid", filename.Data());
2065 openedFiles += filename;
2072 //______________________________________________________________________________
2073 void AliAnalysisManager::ProgressBar(const char *opname, Long64_t current, Long64_t size, TStopwatch * const watch, Bool_t last, Bool_t refresh)
2075 // Implements a nice text mode progress bar.
2076 static Long64_t icount = 0;
2077 static TString oname;
2078 static TString nname;
2079 static Long64_t ocurrent = 0;
2080 static Long64_t osize = 0;
2081 static Int_t oseconds = 0;
2082 static TStopwatch *owatch = 0;
2083 static Bool_t oneoftwo = kFALSE;
2084 static Int_t nrefresh = 0;
2085 static Int_t nchecks = 0;
2086 const char symbol[4] = {'=','\\','|','/'};
2087 char progress[11] = " ";
2088 Int_t ichar = icount%4;
2095 ocurrent = TMath::Abs(current);
2096 osize = TMath::Abs(size);
2097 if (ocurrent > osize) ocurrent=osize;
2107 if (owatch && !last) {
2109 time = owatch->RealTime();
2110 hours = (Int_t)(time/3600.);
2112 minutes = (Int_t)(time/60.);
2114 seconds = (Int_t)time;
2116 if (oseconds==seconds) {
2120 oneoftwo = !oneoftwo;
2124 if (refresh && oneoftwo) {
2126 if (nchecks <= 0) nchecks = nrefresh+1;
2127 Int_t pctdone = (Int_t)(100.*nrefresh/nchecks);
2128 oname = Form(" == %d%% ==", pctdone);
2130 Double_t percent = 100.0*ocurrent/osize;
2131 Int_t nchar = Int_t(percent/10);
2132 if (nchar>10) nchar=10;
2134 for (i=0; i<nchar; i++) progress[i] = '=';
2135 progress[nchar] = symbol[ichar];
2136 for (i=nchar+1; i<10; i++) progress[i] = ' ';
2137 progress[10] = '\0';
2140 if(size<10000) fprintf(stderr, "%s [%10s] %4lld ", oname.Data(), progress, ocurrent);
2141 else if(size<100000) fprintf(stderr, "%s [%10s] %5lld ",oname.Data(), progress, ocurrent);
2142 else fprintf(stderr, "%s [%10s] %7lld ",oname.Data(), progress, ocurrent);
2143 if (time>0.) fprintf(stderr, "[%6.2f %%] TIME %.2d:%.2d:%.2d \r", percent, hours, minutes, seconds);
2144 else fprintf(stderr, "[%6.2f %%]\r", percent);
2145 if (refresh && oneoftwo) oname = nname;
2146 if (owatch) owatch->Continue();
2155 fprintf(stderr, "\n");
2159 //______________________________________________________________________________
2160 void AliAnalysisManager::DoLoadBranch(const char *name)
2162 // Get tree and load branch if needed.
2167 TBranch *br = dynamic_cast<TBranch*>(fTable.FindObject(name));
2169 br = fTree->GetBranch(name);
2171 Error("DoLoadBranch", "Could not find branch %s",name);
2176 if (br->GetReadEntry()==GetCurrentEntry())
2178 br->GetEntry(GetCurrentEntry());
2181 //______________________________________________________________________________
2182 void AliAnalysisManager::AddStatisticsMsg(const char *line)
2184 // Add a line in the statistics message. If available, the statistics message is written
2185 // at the end of the SlaveTerminate phase on workers AND at the end of Terminate
2187 if (!strlen(line)) return;
2188 if (!fStatisticsMsg.IsNull()) fStatisticsMsg += "\n";
2189 fStatisticsMsg += line;
2192 //______________________________________________________________________________
2193 void AliAnalysisManager::WriteStatisticsMsg(Int_t nevents)
2195 // Write the statistics message in a file named <nevents.stat>
2196 if (!nevents) return;
2198 out.open(Form("%09d.stat", nevents), ios::out);
2199 if (!fStatisticsMsg.IsNull()) out << fStatisticsMsg << endl;