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),
89 // Default constructor.
90 fgAnalysisManager = this;
91 fgCommonFileName = "AnalysisResults.root";
92 fTasks = new TObjArray();
93 fTopTasks = new TObjArray();
94 fZombies = new TObjArray();
95 fContainers = new TObjArray();
96 fInputs = new TObjArray();
97 fOutputs = new TObjArray();
98 fParamCont = new TObjArray();
100 TObject::SetObjectStat(kFALSE);
103 //______________________________________________________________________________
104 AliAnalysisManager::AliAnalysisManager(const AliAnalysisManager& other)
107 fInputEventHandler(NULL),
108 fOutputEventHandler(NULL),
109 fMCtruthEventHandler(NULL),
114 fInitOK(other.fInitOK),
115 fIsRemote(other.fIsRemote),
116 fDebug(other.fDebug),
117 fSpecialOutputLocation(""),
130 fAutoBranchHandling(other.fAutoBranchHandling),
135 fTasks = new TObjArray(*other.fTasks);
136 fTopTasks = new TObjArray(*other.fTopTasks);
137 fZombies = new TObjArray(*other.fZombies);
138 fContainers = new TObjArray(*other.fContainers);
139 fInputs = new TObjArray(*other.fInputs);
140 fOutputs = new TObjArray(*other.fOutputs);
141 fParamCont = new TObjArray(*other.fParamCont);
142 fgCommonFileName = "AnalysisResults.root";
143 fgAnalysisManager = this;
144 TObject::SetObjectStat(kFALSE);
147 //______________________________________________________________________________
148 AliAnalysisManager& AliAnalysisManager::operator=(const AliAnalysisManager& other)
151 if (&other != this) {
152 TNamed::operator=(other);
153 fInputEventHandler = other.fInputEventHandler;
154 fOutputEventHandler = other.fOutputEventHandler;
155 fMCtruthEventHandler = other.fMCtruthEventHandler;
156 fEventPool = other.fEventPool;
159 fNSysInfo = other.fNSysInfo;
161 fInitOK = other.fInitOK;
162 fIsRemote = other.fIsRemote;
163 fDebug = other.fDebug;
164 fTasks = new TObjArray(*other.fTasks);
165 fTopTasks = new TObjArray(*other.fTopTasks);
166 fZombies = new TObjArray(*other.fZombies);
167 fContainers = new TObjArray(*other.fContainers);
168 fInputs = new TObjArray(*other.fInputs);
169 fOutputs = new TObjArray(*other.fOutputs);
170 fParamCont = new TObjArray(*other.fParamCont);
172 fCommonOutput = NULL;
175 fExtraFiles = other.fExtraFiles;
176 fgCommonFileName = "AnalysisResults.root";
177 fgAnalysisManager = this;
178 fAutoBranchHandling = other.fAutoBranchHandling;
179 fTable.Clear("nodelete");
180 fRunFromPath = other.fRunFromPath;
185 //______________________________________________________________________________
186 AliAnalysisManager::~AliAnalysisManager()
189 if (fTasks) {fTasks->Delete(); delete fTasks;}
190 if (fTopTasks) delete fTopTasks;
191 if (fZombies) delete fZombies;
192 if (fContainers) {fContainers->Delete(); delete fContainers;}
193 if (fInputs) delete fInputs;
194 if (fOutputs) delete fOutputs;
195 if (fParamCont) delete fParamCont;
196 if (fGridHandler) delete fGridHandler;
197 if (fInputEventHandler) delete fInputEventHandler;
198 if (fOutputEventHandler) delete fOutputEventHandler;
199 if (fMCtruthEventHandler) delete fMCtruthEventHandler;
200 if (fEventPool) delete fEventPool;
201 if (fgAnalysisManager==this) fgAnalysisManager = NULL;
202 TObject::SetObjectStat(kTRUE);
205 //______________________________________________________________________________
206 Int_t AliAnalysisManager::GetEntry(Long64_t entry, Int_t getall)
208 // Read one entry of the tree or a whole branch.
209 fCurrentEntry = entry;
210 if (!fAutoBranchHandling)
212 return fTree ? fTree->GetTree()->GetEntry(entry, getall) : 0;
215 //______________________________________________________________________________
216 Int_t AliAnalysisManager::GetRunFromAlienPath(const char *path)
218 // Attempt to extract run number from input data path. Works only for paths to
219 // alice data in alien.
220 // sim: /alice/sim/<production>/run_no/...
221 // data: /alice/data/year/period/000run_no/... (ESD or AOD)
225 Int_t index = s.Index("/alice/sim");
227 for (Int_t i=0; i<3; i++) {
228 index = s.Index("/", index+1);
229 if (index<0) return 0;
234 index = s.Index("/alice/data");
236 for (Int_t i=0; i<4; i++) {
237 index = s.Index("/", index+1);
238 if (index<0) return 0;
246 //______________________________________________________________________________
247 Bool_t AliAnalysisManager::Init(TTree *tree)
249 // The Init() function is called when the selector needs to initialize
250 // a new tree or chain. Typically here the branch addresses of the tree
251 // will be set. It is normaly not necessary to make changes to the
252 // generated code, but the routine can be extended by the user if needed.
253 // Init() will be called many times when running with PROOF.
254 Bool_t init = kFALSE;
255 if (!tree) return kFALSE; // Should not happen - protected in selector caller
257 printf("->AliAnalysisManager::Init(%s)\n", tree->GetName());
259 // Call InitTree of EventHandler
260 if (fOutputEventHandler) {
261 if (fMode == kProofAnalysis) {
262 init = fOutputEventHandler->Init(0x0, "proof");
264 init = fOutputEventHandler->Init(0x0, "local");
267 Error("Init", "Output event handler failed to initialize");
272 if (fInputEventHandler) {
273 if (fMode == kProofAnalysis) {
274 init = fInputEventHandler->Init(tree, "proof");
276 init = fInputEventHandler->Init(tree, "local");
279 Error("Init", "Input event handler failed to initialize tree");
283 // If no input event handler we need to get the tree once
285 if(!tree->GetTree()) {
286 Long64_t readEntry = tree->LoadTree(0);
287 if (readEntry == -2) {
288 Error("Init", "Input tree has no entry. Exiting");
294 if (fMCtruthEventHandler) {
295 if (fMode == kProofAnalysis) {
296 init = fMCtruthEventHandler->Init(0x0, "proof");
298 init = fMCtruthEventHandler->Init(0x0, "local");
301 Error("Init", "MC event handler failed to initialize");
306 if (!fInitOK) InitAnalysis();
307 if (!fInitOK) return kFALSE;
310 AliAnalysisDataContainer *top = fCommonInput;
311 if (!top) top = (AliAnalysisDataContainer*)fInputs->At(0);
313 Error("Init","No top input container !");
318 printf("<-AliAnalysisManager::Init(%s)\n", tree->GetName());
323 //______________________________________________________________________________
324 void AliAnalysisManager::SlaveBegin(TTree *tree)
326 // The SlaveBegin() function is called after the Begin() function.
327 // When running with PROOF SlaveBegin() is called on each slave server.
328 // The tree argument is deprecated (on PROOF 0 is passed).
329 if (fDebug > 1) printf("->AliAnalysisManager::SlaveBegin()\n");
330 static Bool_t isCalled = kFALSE;
331 Bool_t init = kFALSE;
332 Bool_t initOK = kTRUE;
334 TDirectory *curdir = gDirectory;
335 // Call SlaveBegin only once in case of mixing
336 if (isCalled && fMode==kMixingAnalysis) return;
338 // Call Init of EventHandler
339 if (fOutputEventHandler) {
340 if (fMode == kProofAnalysis) {
341 // Merging AOD's in PROOF via TProofOutputFile
342 if (fDebug > 1) printf(" Initializing AOD output file %s...\n", fOutputEventHandler->GetOutputFileName());
343 init = fOutputEventHandler->Init("proof");
344 if (!init) msg = "Failed to initialize output handler on worker";
346 init = fOutputEventHandler->Init("local");
347 if (!init) msg = "Failed to initialize output handler";
350 if (!fSelector) Error("SlaveBegin", "Selector not set");
351 else if (!init) {fSelector->Abort(msg); fSelector->SetStatus(-1);}
354 if (fInputEventHandler) {
355 fInputEventHandler->SetInputTree(tree);
356 if (fMode == kProofAnalysis) {
357 init = fInputEventHandler->Init("proof");
358 if (!init) msg = "Failed to initialize input handler on worker";
360 init = fInputEventHandler->Init("local");
361 if (!init) msg = "Failed to initialize input handler";
364 if (!fSelector) Error("SlaveBegin", "Selector not set");
365 else if (!init) {fSelector->Abort(msg); fSelector->SetStatus(-1);}
368 if (fMCtruthEventHandler) {
369 if (fMode == kProofAnalysis) {
370 init = fMCtruthEventHandler->Init("proof");
371 if (!init) msg = "Failed to initialize MC handler on worker";
373 init = fMCtruthEventHandler->Init("local");
374 if (!init) msg = "Failed to initialize MC handler";
377 if (!fSelector) Error("SlaveBegin", "Selector not set");
378 else if (!init) {fSelector->Abort(msg); fSelector->SetStatus(-1);}
380 if (curdir) curdir->cd();
384 AliAnalysisTask *task;
385 // Call CreateOutputObjects for all tasks
386 Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
387 Bool_t dirStatus = TH1::AddDirectoryStatus();
389 while ((task=(AliAnalysisTask*)next())) {
391 // Start with memory as current dir and make sure by default histograms do not get attached to files.
392 TH1::AddDirectory(kFALSE);
393 task->CreateOutputObjects();
394 if (getsysInfo) AliSysInfo::AddStamp(Form("%s_CREATEOUTOBJ",task->ClassName()), 0, itask, 0);
397 TH1::AddDirectory(dirStatus);
398 if (curdir) curdir->cd();
399 if (fDebug > 1) printf("<-AliAnalysisManager::SlaveBegin()\n");
402 //______________________________________________________________________________
403 Bool_t AliAnalysisManager::Notify()
405 // The Notify() function is called when a new file is opened. This
406 // can be either for a new TTree in a TChain or when when a new TTree
407 // is started when using PROOF. It is normaly not necessary to make changes
408 // to the generated code, but the routine can be extended by the
409 // user if needed. The return value is currently not used.
410 if (!fTree) return kFALSE;
412 fTable.Clear("nodelete"); // clearing the hash table may not be needed -> C.L.
413 if (fMode == kProofAnalysis) fIsRemote = kTRUE;
415 TFile *curfile = fTree->GetCurrentFile();
417 Error("Notify","No current file");
421 if (fDebug > 1) printf("->AliAnalysisManager::Notify() file: %s\n", curfile->GetName());
422 Int_t run = AliAnalysisManager::GetRunFromAlienPath(curfile->GetName());
423 if (run) SetRunFromPath(run);
424 if (fDebug > 1) printf(" ### run found from path: %d\n", run);
426 AliAnalysisTask *task;
428 // Call Notify of the event handlers
429 if (fInputEventHandler) {
430 fInputEventHandler->Notify(curfile->GetName());
433 if (fOutputEventHandler) {
434 fOutputEventHandler->Notify(curfile->GetName());
437 if (fMCtruthEventHandler) {
438 fMCtruthEventHandler->Notify(curfile->GetName());
441 // Call Notify for all tasks
442 while ((task=(AliAnalysisTask*)next()))
445 if (fDebug > 1) printf("<-AliAnalysisManager::Notify()\n");
449 //______________________________________________________________________________
450 Bool_t AliAnalysisManager::Process(Long64_t entry)
452 // The Process() function is called for each entry in the tree (or possibly
453 // keyed object in the case of PROOF) to be processed. The entry argument
454 // specifies which entry in the currently loaded tree is to be processed.
455 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
456 // to read either all or the required parts of the data. When processing
457 // keyed objects with PROOF, the object is already loaded and is available
458 // via the fObject pointer.
460 // This function should contain the "body" of the analysis. It can contain
461 // simple or elaborate selection criteria, run algorithms on the data
462 // of the event and typically fill histograms.
464 // WARNING when a selector is used with a TChain, you must use
465 // the pointer to the current TTree to call GetEntry(entry).
466 // The entry is always the local entry number in the current tree.
467 // Assuming that fChain is the pointer to the TChain being processed,
468 // use fChain->GetTree()->GetEntry(entry).
469 if (fDebug > 1) printf("->AliAnalysisManager::Process(%lld)\n", entry);
471 if (fInputEventHandler) fInputEventHandler ->BeginEvent(entry);
472 if (fOutputEventHandler) fOutputEventHandler ->BeginEvent(entry);
473 if (fMCtruthEventHandler) fMCtruthEventHandler->BeginEvent(entry);
477 if (fInputEventHandler) fInputEventHandler ->GetEntry();
480 if (fDebug > 1) printf("<-AliAnalysisManager::Process()\n");
484 //______________________________________________________________________________
485 void AliAnalysisManager::PackOutput(TList *target)
487 // Pack all output data containers in the output list. Called at SlaveTerminate
488 // stage in PROOF case for each slave.
489 if (fDebug > 1) printf("->AliAnalysisManager::PackOutput()\n");
491 Error("PackOutput", "No target. Exiting.");
494 TDirectory *cdir = gDirectory;
496 if (fInputEventHandler) fInputEventHandler ->Terminate();
497 if (fOutputEventHandler) fOutputEventHandler ->Terminate();
498 if (fMCtruthEventHandler) fMCtruthEventHandler->Terminate();
501 // Call FinishTaskOutput() for each event loop task (not called for
502 // post-event loop tasks - use Terminate() fo those)
503 TIter nexttask(fTasks);
504 AliAnalysisTask *task;
505 while ((task=(AliAnalysisTask*)nexttask())) {
506 if (!task->IsPostEventLoop()) {
507 if (fDebug > 1) printf("->FinishTaskOutput: task %s\n", task->GetName());
508 task->FinishTaskOutput();
510 if (fDebug > 1) printf("<-FinishTaskOutput: task %s\n", task->GetName());
514 if (fMode == kProofAnalysis) {
515 TIter next(fOutputs);
516 AliAnalysisDataContainer *output;
517 Bool_t isManagedByHandler = kFALSE;
520 while ((output=(AliAnalysisDataContainer*)next())) {
521 // Do not consider outputs of post event loop tasks
522 isManagedByHandler = kFALSE;
523 if (output->GetProducer() && output->GetProducer()->IsPostEventLoop()) continue;
524 const char *filename = output->GetFileName();
525 if (!(strcmp(filename, "default")) && fOutputEventHandler) {
526 isManagedByHandler = kTRUE;
527 printf("#### Handler output. Extra: %s\n", fExtraFiles.Data());
528 filename = fOutputEventHandler->GetOutputFileName();
530 // Check if data was posted to this container. If not, issue an error.
531 if (!output->GetData() && !isManagedByHandler) {
532 Error("PackOutput", "No data for output container %s. Forgot to PostData ?", output->GetName());
535 if (!output->IsSpecialOutput()) {
537 if (strlen(filename) && !isManagedByHandler) {
538 // Backup current folder
539 TDirectory *opwd = gDirectory;
540 // File resident outputs.
541 // Check first if the file exists.
542 TString openoption = "RECREATE";
543 Bool_t firsttime = kTRUE;
544 if (filestmp.FindObject(output->GetFileName())) {
547 filestmp.Add(new TNamed(output->GetFileName(),""));
549 if (!gSystem->AccessPathName(output->GetFileName()) && !firsttime) openoption = "UPDATE";
550 // TFile *file = AliAnalysisManager::OpenFile(output, openoption, kTRUE);
551 // Save data to file, then close.
552 if (output->GetData()->InheritsFrom(TCollection::Class())) {
553 // If data is a collection, we set the name of the collection
554 // as the one of the container and we save as a single key.
555 TCollection *coll = (TCollection*)output->GetData();
556 coll->SetName(output->GetName());
557 // coll->Write(output->GetName(), TObject::kSingleKey);
559 if (output->GetData()->InheritsFrom(TTree::Class())) {
560 TFile *file = AliAnalysisManager::OpenFile(output, openoption, kTRUE);
561 // Save data to file, then close.
562 TTree *tree = (TTree*)output->GetData();
563 // Check if tree is in memory
564 if (tree->GetDirectory()==gROOT) tree->SetDirectory(gDirectory);
568 // output->GetData()->Write();
571 if (fDebug > 1) printf("PackOutput %s: memory merge, file resident output\n", output->GetName());
573 // printf(" file %s listing content:\n", filename);
576 // Clear file list to release object ownership to user.
579 output->SetFile(NULL);
580 // Restore current directory
581 if (opwd) opwd->cd();
583 // Memory-resident outputs
584 if (fDebug > 1) printf("PackOutput %s: memory merge memory resident output\n", filename);
586 AliAnalysisDataWrapper *wrap = 0;
587 if (isManagedByHandler) {
588 wrap = new AliAnalysisDataWrapper(fOutputEventHandler->GetTree());
589 wrap->SetName(output->GetName());
591 else wrap =output->ExportData();
592 // Output wrappers must NOT delete data after merging - the user owns them
593 wrap->SetDeleteData(kFALSE);
596 // Special outputs. The file must be opened and connected to the container.
597 TDirectory *opwd = gDirectory;
598 TFile *file = output->GetFile();
600 AliAnalysisTask *producer = output->GetProducer();
602 "File %s for special container %s was NOT opened in %s::CreateOutputObjects !!!",
603 output->GetFileName(), output->GetName(), producer->ClassName());
606 TString outFilename = file->GetName();
607 if (fDebug > 1) printf("PackOutput %s: special output\n", output->GetName());
608 if (isManagedByHandler) {
609 // Terminate IO for files managed by the output handler
610 // file->Write() moved to AOD handler (A.G. 11.01.10)
611 // if (file) file->Write();
612 if (file && fDebug > 2) {
613 printf(" handled file %s listing content:\n", file->GetName());
616 fOutputEventHandler->TerminateIO();
619 // Release object ownership to users after writing data to file
620 if (output->GetData()->InheritsFrom(TCollection::Class())) {
621 // If data is a collection, we set the name of the collection
622 // as the one of the container and we save as a single key.
623 TCollection *coll = (TCollection*)output->GetData();
624 coll->SetName(output->GetName());
625 coll->Write(output->GetName(), TObject::kSingleKey);
627 if (output->GetData()->InheritsFrom(TTree::Class())) {
628 TTree *tree = (TTree*)output->GetData();
629 tree->SetDirectory(file);
632 output->GetData()->Write();
636 printf(" file %s listing content:\n", output->GetFileName());
639 // Clear file list to release object ownership to user.
642 output->SetFile(NULL);
644 // Restore current directory
645 if (opwd) opwd->cd();
646 // Check if a special output location was provided or the output files have to be merged
647 if (strlen(fSpecialOutputLocation.Data())) {
648 TString remote = fSpecialOutputLocation;
650 Int_t gid = gROOT->ProcessLine("gProofServ->GetGroupId();");
651 if (remote.BeginsWith("alien:")) {
652 gROOT->ProcessLine("TGrid::Connect(\"alien:\", gProofServ->GetUser());");
653 remote += outFilename;
654 remote.ReplaceAll(".root", Form("_%d.root", gid));
656 remote += Form("%s_%d_", gSystem->HostName(), gid);
657 remote += outFilename;
660 Info("PackOutput", "Output file for container %s to be copied \n at: %s. No merging.",
661 output->GetName(), remote.Data());
662 TFile::Cp ( outFilename.Data(), remote.Data() );
663 // Copy extra outputs
664 if (fExtraFiles.Length() && isManagedByHandler) {
665 TObjArray *arr = fExtraFiles.Tokenize(" ");
667 TIter nextfilename(arr);
668 while ((os=(TObjString*)nextfilename())) {
669 outFilename = os->GetString();
670 remote = fSpecialOutputLocation;
672 if (remote.BeginsWith("alien://")) {
673 remote += outFilename;
674 remote.ReplaceAll(".root", Form("_%d.root", gid));
676 remote += Form("%s_%d_", gSystem->HostName(), gid);
677 remote += outFilename;
680 Info("PackOutput", "Extra AOD file %s to be copied \n at: %s. No merging.",
681 outFilename.Data(), remote.Data());
682 TFile::Cp ( outFilename.Data(), remote.Data() );
687 // No special location specified-> use TProofOutputFile as merging utility
688 // The file at this output slot must be opened in CreateOutputObjects
689 if (fDebug > 1) printf(" File for container %s to be merged via file merger...\n", output->GetName());
695 if (fDebug > 1) printf("<-AliAnalysisManager::PackOutput: output list contains %d containers\n", target->GetSize());
698 //______________________________________________________________________________
699 void AliAnalysisManager::ImportWrappers(TList *source)
701 // Import data in output containers from wrappers coming in source.
702 if (fDebug > 1) printf("->AliAnalysisManager::ImportWrappers()\n");
703 TIter next(fOutputs);
704 AliAnalysisDataContainer *cont;
705 AliAnalysisDataWrapper *wrap;
707 Bool_t inGrid = (fMode == kGridAnalysis)?kTRUE:kFALSE;
708 TDirectory *cdir = gDirectory;
709 while ((cont=(AliAnalysisDataContainer*)next())) {
711 if (cont->GetProducer() && cont->GetProducer()->IsPostEventLoop() && !inGrid) continue;
712 if (cont->IsRegisterDataset()) continue;
713 const char *filename = cont->GetFileName();
714 Bool_t isManagedByHandler = kFALSE;
715 if (!(strcmp(filename, "default")) && fOutputEventHandler) {
716 isManagedByHandler = kTRUE;
717 filename = fOutputEventHandler->GetOutputFileName();
719 if (cont->IsSpecialOutput() || inGrid) {
720 if (strlen(fSpecialOutputLocation.Data())) continue;
721 // Copy merged file from PROOF scratch space.
722 // In case of grid the files are already in the current directory.
724 if (isManagedByHandler && fExtraFiles.Length()) {
725 // Copy extra registered dAOD files.
726 TObjArray *arr = fExtraFiles.Tokenize(" ");
728 TIter nextfilename(arr);
729 while ((os=(TObjString*)nextfilename())) GetFileFromWrapper(os->GetString(), source);
732 if (!GetFileFromWrapper(filename, source)) continue;
734 // Normally we should connect data from the copied file to the
735 // corresponding output container, but it is not obvious how to do this
736 // automatically if several objects in file...
737 TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
738 if (!f) f = TFile::Open(filename, "READ");
740 Error("ImportWrappers", "Cannot open file %s in read-only mode", filename);
744 // Cd to the directory pointed by the container
745 TString folder = cont->GetFolderName();
746 if (!folder.IsNull()) f->cd(folder);
747 // Try to fetch first an object having the container name.
748 obj = gDirectory->Get(cont->GetName());
750 Warning("ImportWrappers", "Could not import object for container %s in file %s:%s.\n Object will not be available in Terminate()",
751 cont->GetName(), filename, cont->GetFolderName());
754 wrap = new AliAnalysisDataWrapper(obj);
755 wrap->SetDeleteData(kFALSE);
757 if (!wrap) wrap = (AliAnalysisDataWrapper*)source->FindObject(cont->GetName());
759 Error("ImportWrappers","Container %s not found in analysis output !", cont->GetName());
764 printf(" Importing data for container %s\n", cont->GetName());
765 if (strlen(filename)) printf(" -> file %s\n", filename);
768 cont->ImportData(wrap);
770 if (cdir) cdir->cd();
771 if (fDebug > 1) printf("<-AliAnalysisManager::ImportWrappers(): %d containers imported\n", icont);
774 //______________________________________________________________________________
775 void AliAnalysisManager::UnpackOutput(TList *source)
777 // Called by AliAnalysisSelector::Terminate only on the client.
778 if (fDebug > 1) printf("->AliAnalysisManager::UnpackOutput()\n");
780 Error("UnpackOutput", "No target. Exiting.");
783 if (fDebug > 1) printf(" Source list contains %d containers\n", source->GetSize());
785 if (fMode == kProofAnalysis) ImportWrappers(source);
787 TIter next(fOutputs);
788 AliAnalysisDataContainer *output;
789 while ((output=(AliAnalysisDataContainer*)next())) {
790 if (!output->GetData()) continue;
791 // Check if there are client tasks that run post event loop
792 if (output->HasConsumers()) {
793 // Disable event loop semaphore
794 output->SetPostEventLoop(kTRUE);
795 TObjArray *list = output->GetConsumers();
796 Int_t ncons = list->GetEntriesFast();
797 for (Int_t i=0; i<ncons; i++) {
798 AliAnalysisTask *task = (AliAnalysisTask*)list->At(i);
799 task->CheckNotify(kTRUE);
800 // If task is active, execute it
801 if (task->IsPostEventLoop() && task->IsActive()) {
802 if (fDebug > 1) printf("== Executing post event loop task %s\n", task->GetName());
808 if (fDebug > 1) printf("<-AliAnalysisManager::UnpackOutput()\n");
811 //______________________________________________________________________________
812 void AliAnalysisManager::Terminate()
814 // The Terminate() function is the last function to be called during
815 // a query. It always runs on the client, it can be used to present
816 // the results graphically.
817 if (fDebug > 1) printf("->AliAnalysisManager::Terminate()\n");
818 TDirectory *cdir = gDirectory;
820 AliAnalysisTask *task;
821 AliAnalysisDataContainer *output;
824 Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
825 // Call Terminate() for tasks
827 while (!IsSkipTerminate() && (task=(AliAnalysisTask*)next())) {
828 // Save all the canvases produced by the Terminate
829 TString pictname = Form("%s_%s", task->GetName(), task->ClassName());
833 AliSysInfo::AddStamp(Form("%s_TERMINATE",task->ClassName()),0, itask, 2);
835 if (TObject::TestBit(kSaveCanvases)) {
836 if (!gROOT->IsBatch()) {
837 if (fDebug>1) printf("Waiting 5 sec for %s::Terminate() to finish drawing ...\n", task->ClassName());
839 while (timer.CpuTime()<5) {
841 gSystem->ProcessEvents();
844 Int_t iend = gROOT->GetListOfCanvases()->GetEntries();
845 if (iend==0) continue;
847 for (Int_t ipict=0; ipict<iend; ipict++) {
848 canvas = (TCanvas*)gROOT->GetListOfCanvases()->At(ipict);
849 if (!canvas) continue;
850 canvas->SaveAs(Form("%s_%02d.gif", pictname.Data(),ipict));
852 gROOT->GetListOfCanvases()->Delete();
856 if (fInputEventHandler) fInputEventHandler ->TerminateIO();
857 if (fOutputEventHandler) fOutputEventHandler ->TerminateIO();
858 if (fMCtruthEventHandler) fMCtruthEventHandler->TerminateIO();
860 TObjArray *allOutputs = new TObjArray();
862 for (icont=0; icont<fOutputs->GetEntriesFast(); icont++) allOutputs->Add(fOutputs->At(icont));
863 if (!IsSkipTerminate())
864 for (icont=0; icont<fParamCont->GetEntriesFast(); icont++) allOutputs->Add(fParamCont->At(icont));
865 TIter next1(allOutputs);
866 TString handlerFile = "";
867 TString extraOutputs = "";
868 if (fOutputEventHandler) {
869 handlerFile = fOutputEventHandler->GetOutputFileName();
870 extraOutputs = fOutputEventHandler->GetExtraOutputs();
874 while ((output=(AliAnalysisDataContainer*)next1())) {
875 // Special outputs or grid files have the files already closed and written.
877 if (fMode == kGridAnalysis && icont<=fOutputs->GetEntriesFast()) continue;
878 if (fMode == kProofAnalysis) {
879 if (output->IsSpecialOutput() || output->IsRegisterDataset()) continue;
881 const char *filename = output->GetFileName();
882 TString openoption = "RECREATE";
883 if (!(strcmp(filename, "default"))) continue;
884 if (!strlen(filename)) continue;
885 if (!output->GetData()) continue;
886 TDirectory *opwd = gDirectory;
887 TFile *file = output->GetFile();
888 if (!file) file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
890 //if (handlerFile == filename && !gSystem->AccessPathName(filename)) openoption = "UPDATE";
891 Bool_t firsttime = kTRUE;
892 if (filestmp.FindObject(filename) || extraOutputs.Contains(filename)) {
895 filestmp.Add(new TNamed(filename,""));
897 if (!gSystem->AccessPathName(filename) && !firsttime) openoption = "UPDATE";
898 if (fDebug>1) printf("Opening file: %s option=%s\n",filename, openoption.Data());
899 file = new TFile(filename, openoption);
901 if (fDebug>1) printf("File <%s> already opened with option: <%s> \n", filename, file->GetOption());
902 openoption = file->GetOption();
903 if (openoption == "READ") {
904 if (fDebug>1) printf("...reopening in UPDATE mode\n");
905 file->ReOpen("UPDATE");
908 if (file->IsZombie()) {
909 Error("Terminate", "Cannot open output file %s", filename);
912 output->SetFile(file);
914 // Check for a folder request
915 TString dir = output->GetFolderName();
917 if (!file->GetDirectory(dir)) file->mkdir(dir);
920 if (fDebug > 1) printf("...writing container %s to file %s:%s\n", output->GetName(), file->GetName(), output->GetFolderName());
921 if (output->GetData()->InheritsFrom(TCollection::Class())) {
922 // If data is a collection, we set the name of the collection
923 // as the one of the container and we save as a single key.
924 TCollection *coll = (TCollection*)output->GetData();
925 coll->SetName(output->GetName());
926 coll->Write(output->GetName(), TObject::kSingleKey);
928 if (output->GetData()->InheritsFrom(TTree::Class())) {
929 TTree *tree = (TTree*)output->GetData();
930 tree->SetDirectory(gDirectory);
933 output->GetData()->Write();
936 if (opwd) opwd->cd();
940 while ((output=(AliAnalysisDataContainer*)next1())) {
941 // Close all files at output
942 TDirectory *opwd = gDirectory;
943 if (output->GetFile()) {
944 // Clear file list to release object ownership to user.
945 // output->GetFile()->Clear();
946 output->GetFile()->Close();
947 output->SetFile(NULL);
948 // Copy merged outputs in alien if requested
949 if (fSpecialOutputLocation.Length() &&
950 fSpecialOutputLocation.BeginsWith("alien://")) {
951 Info("Terminate", "Copy file %s to %s", output->GetFile()->GetName(),fSpecialOutputLocation.Data());
952 TFile::Cp(output->GetFile()->GetName(),
953 Form("%s/%s", fSpecialOutputLocation.Data(), output->GetFile()->GetName()));
956 if (opwd) opwd->cd();
961 TDirectory *crtdir = gDirectory;
962 TFile f("syswatch.root", "RECREATE");
966 TTree *tree = AliSysInfo::MakeTree("syswatch.log");
967 tree->SetName("syswatch");
968 tree->SetMarkerStyle(kCircle);
969 tree->SetMarkerColor(kBlue);
970 tree->SetMarkerSize(0.5);
971 if (!gROOT->IsBatch()) {
972 tree->SetAlias("event", "id0");
973 tree->SetAlias("task", "id1");
974 tree->SetAlias("stage", "id2");
975 // Already defined aliases
976 // tree->SetAlias("deltaT","stampSec-stampOldSec");
977 // tree->SetAlias("T","stampSec-first");
978 // tree->SetAlias("deltaVM","(pI.fMemVirtual-pIOld.fMemVirtual)");
979 // tree->SetAlias("VM","pI.fMemVirtual");
980 TCanvas *canvas = new TCanvas("SysInfo","SysInfo",10,10,1200,800);
981 Int_t npads = 1 /*COO plot for all tasks*/ +
982 fTopTasks->GetEntries() /*Exec plot per task*/ +
983 1 /*Terminate plot for all tasks*/ +
986 Int_t iopt = (Int_t)TMath::Sqrt((Double_t)npads);
987 if (npads<iopt*(iopt+1))
988 canvas->Divide(iopt, iopt+1, 0.01, 0.01);
990 canvas->Divide(iopt+1, iopt+1, 0.01, 0.01);
992 // draw the plot of deltaVM for Exec for each task
993 for (itask=0; itask<fTopTasks->GetEntriesFast(); itask++) {
994 task = (AliAnalysisTask*)fTopTasks->At(itask);
996 cut = Form("task==%d && stage==1", itask);
997 tree->Draw("deltaVM:event",cut,"", 1234567890, 0);
998 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1000 hist->SetTitle(Form("%s: Exec dVM[kB]/event", task->GetName()));
1001 hist->GetYaxis()->SetTitle("deltaVM [kB]");
1004 // Draw the plot of deltaVM for CreateOutputObjects for all tasks
1006 tree->SetMarkerStyle(kFullTriangleUp);
1007 tree->SetMarkerColor(kRed);
1008 tree->SetMarkerSize(0.8);
1009 cut = "task>=0 && task<1000 && stage==0";
1010 tree->Draw("deltaVM:sname",cut,"", 1234567890, 0);
1011 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1013 hist->SetTitle("Memory in CreateOutputObjects()");
1014 hist->GetYaxis()->SetTitle("deltaVM [kB]");
1015 hist->GetXaxis()->SetTitle("task");
1017 // draw the plot of deltaVM for Terminate for all tasks
1019 tree->SetMarkerStyle(kOpenSquare);
1020 tree->SetMarkerColor(kMagenta);
1021 cut = "task>=0 && task<1000 && stage==2";
1022 tree->Draw("deltaVM:sname",cut,"", 1234567890, 0);
1023 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1025 hist->SetTitle("Memory in Terminate()");
1026 hist->GetYaxis()->SetTitle("deltaVM [kB]");
1027 hist->GetXaxis()->SetTitle("task");
1031 tree->SetMarkerStyle(kFullCircle);
1032 tree->SetMarkerColor(kGreen);
1033 cut = Form("task==%d && stage==1",fTopTasks->GetEntriesFast()-1);
1034 tree->Draw("VM:event",cut,"", 1234567890, 0);
1035 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1037 hist->SetTitle("Virtual memory");
1038 hist->GetYaxis()->SetTitle("VM [kB]");
1042 tree->SetMarkerStyle(kCircle);
1043 tree->SetMarkerColor(kBlue);
1044 tree->SetMarkerSize(0.5);
1049 if (crtdir) crtdir->cd();
1051 // Validate the output files
1052 if (ValidateOutputFiles()) {
1054 out.open("outputs_valid", ios::out);
1058 if (fDebug > 1) printf("<-AliAnalysisManager::Terminate()\n");
1060 //______________________________________________________________________________
1061 void AliAnalysisManager::ProfileTask(Int_t itop, const char *option) const
1063 // Profiles the task having the itop index in the list of top (first level) tasks.
1064 AliAnalysisTask *task = (AliAnalysisTask*)fTopTasks->At(itop);
1066 Error("ProfileTask", "There are only %d top tasks in the manager", fTopTasks->GetEntries());
1069 ProfileTask(task->GetName(), option);
1072 //______________________________________________________________________________
1073 void AliAnalysisManager::ProfileTask(const char *name, const char */*option*/) const
1075 // Profile a managed task after the execution of the analysis in case NSysInfo
1077 if (gSystem->AccessPathName("syswatch.root")) {
1078 Error("ProfileTask", "No file syswatch.root found in the current directory");
1081 if (gROOT->IsBatch()) return;
1082 AliAnalysisTask *task = (AliAnalysisTask*)fTopTasks->FindObject(name);
1084 Error("ProfileTask", "No top task named %s known by the manager.", name);
1087 Int_t itop = fTopTasks->IndexOf(task);
1088 Int_t itask = fTasks->IndexOf(task);
1089 // Create canvas with 2 pads: first draw COO + Terminate, second Exec
1090 TDirectory *cdir = gDirectory;
1091 TFile f("syswatch.root");
1092 TTree *tree = (TTree*)f.Get("syswatch");
1094 Error("ProfileTask", "No tree named <syswatch> found in file syswatch.root");
1097 if (fDebug > 1) printf("=== Profiling task %s (class %s)\n", name, task->ClassName());
1098 TCanvas *canvas = new TCanvas(Form("profile_%d",itop),Form("Profile of task %s (class %s)",name,task->ClassName()),10,10,800,600);
1099 canvas->Divide(2, 2, 0.01, 0.01);
1103 // VM profile for COO and Terminate methods
1105 cut = Form("task==%d && (stage==0 || stage==2)",itask);
1106 tree->Draw("deltaVM:sname",cut,"", 1234567890, 0);
1107 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1109 hist->SetTitle("Alocated VM[kB] for COO and Terminate");
1110 hist->GetYaxis()->SetTitle("deltaVM [kB]");
1111 hist->GetXaxis()->SetTitle("method");
1113 // CPU profile per event
1115 cut = Form("task==%d && stage==1",itop);
1116 tree->Draw("deltaT:event",cut,"", 1234567890, 0);
1117 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1119 hist->SetTitle("Execution time per event");
1120 hist->GetYaxis()->SetTitle("CPU/event [s]");
1122 // VM profile for Exec
1124 cut = Form("task==%d && stage==1",itop);
1125 tree->Draw("deltaVM:event",cut,"", 1234567890, 0);
1126 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1128 hist->SetTitle("Alocated VM[kB] per event");
1129 hist->GetYaxis()->SetTitle("deltaVM [kB]");
1134 if (cdir) cdir->cd();
1137 //______________________________________________________________________________
1138 void AliAnalysisManager::AddTask(AliAnalysisTask *task)
1140 // Adds a user task to the global list of tasks.
1141 if (fTasks->FindObject(task)) {
1142 Warning("AddTask", "Task %s: the same object already added to the analysis manager. Not adding.", task->GetName());
1145 task->SetActive(kFALSE);
1149 //______________________________________________________________________________
1150 AliAnalysisTask *AliAnalysisManager::GetTask(const char *name) const
1152 // Retreive task by name.
1153 if (!fTasks) return NULL;
1154 return (AliAnalysisTask*)fTasks->FindObject(name);
1157 //______________________________________________________________________________
1158 AliAnalysisDataContainer *AliAnalysisManager::CreateContainer(const char *name,
1159 TClass *datatype, EAliAnalysisContType type, const char *filename)
1161 // Create a data container of a certain type. Types can be:
1162 // kExchangeContainer = 0, used to exchange data between tasks
1163 // kInputContainer = 1, used to store input data
1164 // kOutputContainer = 2, used for writing result to a file
1165 // filename: composed by file#folder (e.g. results.root#INCLUSIVE) - will write
1166 // the output object to a folder inside the output file
1167 if (fContainers->FindObject(name)) {
1168 Error("CreateContainer","A container named %s already defined !",name);
1171 AliAnalysisDataContainer *cont = new AliAnalysisDataContainer(name, datatype);
1172 fContainers->Add(cont);
1174 case kInputContainer:
1177 case kOutputContainer:
1178 fOutputs->Add(cont);
1179 if (filename && strlen(filename)) {
1180 cont->SetFileName(filename);
1181 cont->SetDataOwned(kFALSE); // data owned by the file
1184 case kParamContainer:
1185 fParamCont->Add(cont);
1186 if (filename && strlen(filename)) {
1187 cont->SetFileName(filename);
1188 cont->SetDataOwned(kFALSE); // data owned by the file
1191 case kExchangeContainer:
1197 //______________________________________________________________________________
1198 Bool_t AliAnalysisManager::ConnectInput(AliAnalysisTask *task, Int_t islot,
1199 AliAnalysisDataContainer *cont)
1201 // Connect input of an existing task to a data container.
1203 Error("ConnectInput", "Task pointer is NULL");
1206 if (!fTasks->FindObject(task)) {
1208 Info("ConnectInput", "Task %s was not registered. Now owned by analysis manager", task->GetName());
1210 Bool_t connected = task->ConnectInput(islot, cont);
1214 //______________________________________________________________________________
1215 Bool_t AliAnalysisManager::ConnectOutput(AliAnalysisTask *task, Int_t islot,
1216 AliAnalysisDataContainer *cont)
1218 // Connect output of an existing task to a data container.
1220 Error("ConnectOutput", "Task pointer is NULL");
1223 if (!fTasks->FindObject(task)) {
1225 Warning("ConnectOutput", "Task %s not registered. Now owned by analysis manager", task->GetName());
1227 Bool_t connected = task->ConnectOutput(islot, cont);
1231 //______________________________________________________________________________
1232 void AliAnalysisManager::CleanContainers()
1234 // Clean data from all containers that have already finished all client tasks.
1235 TIter next(fContainers);
1236 AliAnalysisDataContainer *cont;
1237 while ((cont=(AliAnalysisDataContainer *)next())) {
1238 if (cont->IsOwnedData() &&
1239 cont->IsDataReady() &&
1240 cont->ClientsExecuted()) cont->DeleteData();
1244 //______________________________________________________________________________
1245 Bool_t AliAnalysisManager::InitAnalysis()
1247 // Initialization of analysis chain of tasks. Should be called after all tasks
1248 // and data containers are properly connected
1249 // Reset flag and remove valid_outputs file if exists
1251 if (!gSystem->AccessPathName("outputs_valid"))
1252 gSystem->Unlink("outputs_valid");
1253 // Check for top tasks (depending only on input data containers)
1254 if (!fTasks->First()) {
1255 Error("InitAnalysis", "Analysis has no tasks !");
1259 AliAnalysisTask *task;
1260 AliAnalysisDataContainer *cont;
1263 Bool_t iszombie = kFALSE;
1264 Bool_t istop = kTRUE;
1266 while ((task=(AliAnalysisTask*)next())) {
1269 Int_t ninputs = task->GetNinputs();
1270 for (i=0; i<ninputs; i++) {
1271 cont = task->GetInputSlot(i)->GetContainer();
1275 fZombies->Add(task);
1279 Error("InitAnalysis", "Input slot %d of task %s has no container connected ! Declared zombie...",
1280 i, task->GetName());
1282 if (iszombie) continue;
1283 // Check if cont is an input container
1284 if (istop && !fInputs->FindObject(cont)) istop=kFALSE;
1285 // Connect to parent task
1289 fTopTasks->Add(task);
1293 Error("InitAnalysis", "No top task defined. At least one task should be connected only to input containers");
1296 // Check now if there are orphan tasks
1297 for (i=0; i<ntop; i++) {
1298 task = (AliAnalysisTask*)fTopTasks->At(i);
1303 while ((task=(AliAnalysisTask*)next())) {
1304 if (!task->IsUsed()) {
1306 Warning("InitAnalysis", "Task %s is orphan", task->GetName());
1309 // Check the task hierarchy (no parent task should depend on data provided
1310 // by a daughter task)
1311 for (i=0; i<ntop; i++) {
1312 task = (AliAnalysisTask*)fTopTasks->At(i);
1313 if (task->CheckCircularDeps()) {
1314 Error("InitAnalysis", "Found illegal circular dependencies between following tasks:");
1319 // Check that all containers feeding post-event loop tasks are in the outputs list
1320 TIter nextcont(fContainers); // loop over all containers
1321 while ((cont=(AliAnalysisDataContainer*)nextcont())) {
1322 if (!cont->IsPostEventLoop() && !fOutputs->FindObject(cont)) {
1323 if (cont->HasConsumers()) {
1324 // Check if one of the consumers is post event loop
1325 TIter nextconsumer(cont->GetConsumers());
1326 while ((task=(AliAnalysisTask*)nextconsumer())) {
1327 if (task->IsPostEventLoop()) {
1328 fOutputs->Add(cont);
1335 // Check if all special output containers have a file name provided
1336 TIter nextout(fOutputs);
1337 while ((cont=(AliAnalysisDataContainer*)nextout())) {
1338 if (cont->IsSpecialOutput() && !strlen(cont->GetFileName())) {
1339 Error("InitAnalysis", "Wrong container %s : a file name MUST be provided for special outputs", cont->GetName());
1347 //______________________________________________________________________________
1348 void AliAnalysisManager::PrintStatus(Option_t *option) const
1350 // Print task hierarchy.
1352 Info("PrintStatus", "Analysis manager %s not initialized : call InitAnalysis() first", GetName());
1355 Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
1357 Info("PrintStatus", "System information will be collected each %lld events", fNSysInfo);
1358 TIter next(fTopTasks);
1359 AliAnalysisTask *task;
1360 while ((task=(AliAnalysisTask*)next()))
1361 task->PrintTask(option);
1364 //______________________________________________________________________________
1365 void AliAnalysisManager::ResetAnalysis()
1367 // Reset all execution flags and clean containers.
1371 //______________________________________________________________________________
1372 Long64_t AliAnalysisManager::StartAnalysis(const char *type, Long64_t nentries, Long64_t firstentry)
1374 // Start analysis having a grid handler.
1375 if (!fGridHandler) {
1376 Error("StartAnalysis", "Cannot start analysis providing just the analysis type without a grid handler.");
1377 Info("===", "Add an AliAnalysisAlien object as plugin for this manager and configure it.");
1381 return StartAnalysis(type, tree, nentries, firstentry);
1384 //______________________________________________________________________________
1385 Long64_t AliAnalysisManager::StartAnalysis(const char *type, TTree * const tree, Long64_t nentries, Long64_t firstentry)
1387 // Start analysis for this manager. Analysis task can be: LOCAL, PROOF, GRID or
1388 // MIX. Process nentries starting from firstentry
1390 // Backup current directory and make sure gDirectory points to gROOT
1391 TDirectory *cdir = gDirectory;
1394 Error("StartAnalysis","Analysis manager was not initialized !");
1398 if (fDebug > 1) printf("StartAnalysis %s\n",GetName());
1400 TString anaType = type;
1402 fMode = kLocalAnalysis;
1403 Bool_t runlocalinit = kTRUE;
1404 if (anaType.Contains("file")) {
1405 runlocalinit = kFALSE;
1408 if (anaType.Contains("proof")) fMode = kProofAnalysis;
1409 else if (anaType.Contains("grid")) fMode = kGridAnalysis;
1410 else if (anaType.Contains("mix")) fMode = kMixingAnalysis;
1412 if (fMode == kGridAnalysis) {
1414 if (!anaType.Contains("terminate")) {
1415 if (!fGridHandler) {
1416 Error("StartAnalysis", "Cannot start grid analysis without a grid handler.");
1417 Info("===", "Add an AliAnalysisAlien object as plugin for this manager and configure it.");
1421 // Write analysis manager in the analysis file
1422 cout << "===== RUNNING GRID ANALYSIS: " << GetName() << endl;
1423 // run local task configuration
1424 TIter nextTask(fTasks);
1425 AliAnalysisTask *task;
1426 while ((task=(AliAnalysisTask*)nextTask())) {
1430 if (!fGridHandler->StartAnalysis(nentries, firstentry)) {
1431 Info("StartAnalysis", "Grid analysis was stopped and cannot be terminated");
1436 // Terminate grid analysis
1437 if (fSelector && fSelector->GetStatus() == -1) {cdir->cd(); return -1;}
1438 if (fGridHandler->GetRunMode() == AliAnalysisGrid::kOffline) {cdir->cd(); return 0;}
1439 cout << "===== MERGING OUTPUTS REGISTERED BY YOUR ANALYSIS JOB: " << GetName() << endl;
1440 if (!fGridHandler->MergeOutputs()) {
1441 // Return if outputs could not be merged or if it alien handler
1442 // was configured for offline mode or local testing.
1447 cout << "===== TERMINATING GRID ANALYSIS JOB: " << GetName() << endl;
1448 ImportWrappers(NULL);
1454 SetEventLoop(kFALSE);
1455 // Enable event loop mode if a tree was provided
1456 if (tree || fGridHandler || fMode==kMixingAnalysis) SetEventLoop(kTRUE);
1459 TString ttype = "TTree";
1460 if (tree && tree->IsA() == TChain::Class()) {
1461 chain = (TChain*)tree;
1462 if (!chain || !chain->GetListOfFiles()->First()) {
1463 Error("StartAnalysis", "Cannot process null or empty chain...");
1470 Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
1471 if (getsysInfo) AliSysInfo::AddStamp("Start", 0);
1472 // Initialize locally all tasks (happens for all modes)
1474 AliAnalysisTask *task;
1476 while ((task=(AliAnalysisTask*)next())) {
1480 if (getsysInfo) AliSysInfo::AddStamp("LocalInit_all", 0);
1484 case kLocalAnalysis:
1485 if (!tree && !fGridHandler) {
1486 TIter nextT(fTasks);
1487 // Call CreateOutputObjects for all tasks
1489 Bool_t dirStatus = TH1::AddDirectoryStatus();
1490 while ((task=(AliAnalysisTask*)nextT())) {
1491 TH1::AddDirectory(kFALSE);
1492 task->CreateOutputObjects();
1493 if (getsysInfo) AliSysInfo::AddStamp(Form("%s_CREATEOUTOBJ",task->ClassName()), 0, itask, 0);
1497 TH1::AddDirectory(dirStatus);
1498 if (IsExternalLoop()) {
1499 Info("StartAnalysis", "Initialization done. Event loop is controlled externally.\
1500 \nSetData for top container, call ExecAnalysis in a loop and then Terminate manually");
1507 fSelector = new AliAnalysisSelector(this);
1508 // Check if a plugin handler is used
1510 // Get the chain from the plugin
1511 TString dataType = "esdTree";
1512 if (fInputEventHandler) {
1513 dataType = fInputEventHandler->GetDataType();
1517 chain = fGridHandler->GetChainForTestMode(dataType);
1519 Error("StartAnalysis", "No chain for test mode. Aborting.");
1522 cout << "===== RUNNING LOCAL ANALYSIS" << GetName() << " ON CHAIN " << chain->GetName() << endl;
1523 retv = chain->Process(fSelector, "", nentries, firstentry);
1526 // Run tree-based analysis via AliAnalysisSelector
1527 cout << "===== RUNNING LOCAL ANALYSIS " << GetName() << " ON TREE " << tree->GetName() << endl;
1528 retv = tree->Process(fSelector, "", nentries, firstentry);
1530 case kProofAnalysis:
1532 // Check if the plugin is used
1534 return StartAnalysis(type, fGridHandler->GetProofDataSet(), nentries, firstentry);
1536 if (!gROOT->GetListOfProofs() || !gROOT->GetListOfProofs()->GetEntries()) {
1537 Error("StartAnalysis", "No PROOF!!! Exiting.");
1541 line = Form("gProof->AddInput((TObject*)0x%lx);", (ULong_t)this);
1542 gROOT->ProcessLine(line);
1545 cout << "===== RUNNING PROOF ANALYSIS " << GetName() << " ON CHAIN " << chain->GetName() << endl;
1546 retv = chain->Process("AliAnalysisSelector", "", nentries, firstentry);
1548 Error("StartAnalysis", "No chain!!! Exiting.");
1555 if (!anaType.Contains("terminate")) {
1556 if (!fGridHandler) {
1557 Error("StartAnalysis", "Cannot start grid analysis without a grid handler.");
1558 Info("===", "Add an AliAnalysisAlien object as plugin for this manager and configure it.");
1562 // Write analysis manager in the analysis file
1563 cout << "===== RUNNING GRID ANALYSIS: " << GetName() << endl;
1564 // Start the analysis via the handler
1565 if (!fGridHandler->StartAnalysis(nentries, firstentry)) {
1566 Info("StartAnalysis", "Grid analysis was stopped and cannot be terminated");
1571 // Terminate grid analysis
1572 if (fSelector && fSelector->GetStatus() == -1) {cdir->cd(); return -1;}
1573 if (fGridHandler->GetRunMode() == AliAnalysisGrid::kOffline) {cdir->cd(); return 0;}
1574 cout << "===== MERGING OUTPUTS REGISTERED BY YOUR ANALYSIS JOB: " << GetName() << endl;
1575 if (!fGridHandler->MergeOutputs()) {
1576 // Return if outputs could not be merged or if it alien handler
1577 // was configured for offline mode or local testing.
1582 cout << "===== TERMINATING GRID ANALYSIS JOB: " << GetName() << endl;
1583 ImportWrappers(NULL);
1587 case kMixingAnalysis:
1588 // Run event mixing analysis
1590 Error("StartAnalysis", "Cannot run event mixing without event pool");
1594 cout << "===== RUNNING EVENT MIXING ANALYSIS " << GetName() << endl;
1595 fSelector = new AliAnalysisSelector(this);
1596 while ((chain=fEventPool->GetNextChain())) {
1598 // Call NotifyBinChange for all tasks
1599 while ((task=(AliAnalysisTask*)next()))
1600 if (!task->IsPostEventLoop()) task->NotifyBinChange();
1601 retv = chain->Process(fSelector);
1603 Error("StartAnalysis", "Mixing analysis failed");
1608 PackOutput(fSelector->GetOutputList());
1615 //______________________________________________________________________________
1616 Long64_t AliAnalysisManager::StartAnalysis(const char *type, const char *dataset, Long64_t nentries, Long64_t firstentry)
1618 // Start analysis for this manager on a given dataset. Analysis task can be:
1619 // LOCAL, PROOF or GRID. Process nentries starting from firstentry.
1621 Error("StartAnalysis","Analysis manager was not initialized !");
1625 if (fDebug > 1) printf("StartAnalysis %s\n",GetName());
1626 TString anaType = type;
1628 if (!anaType.Contains("proof")) {
1629 Error("StartAnalysis", "Cannot process datasets in %s mode. Try PROOF.", type);
1632 fMode = kProofAnalysis;
1634 SetEventLoop(kTRUE);
1635 // Set the dataset flag
1636 TObject::SetBit(kUseDataSet);
1640 // Start proof analysis using the grid handler
1641 if (!fGridHandler->StartAnalysis(nentries, firstentry)) {
1642 Error("StartAnalysis", "The grid plugin could not start PROOF analysis");
1645 // Check if the plugin is in test mode
1646 if (fGridHandler->GetRunMode() == AliAnalysisGrid::kTest) {
1647 dataset = "test_collection";
1649 dataset = fGridHandler->GetProofDataSet();
1653 if (!gROOT->GetListOfProofs() || !gROOT->GetListOfProofs()->GetEntries()) {
1654 Error("StartAnalysis", "No PROOF!!! Exiting.");
1658 // Initialize locally all tasks
1660 AliAnalysisTask *task;
1661 while ((task=(AliAnalysisTask*)next())) {
1665 line = Form("gProof->AddInput((TObject*)0x%lx);", (ULong_t)this);
1666 gROOT->ProcessLine(line);
1669 // chain->SetProof();
1670 cout << "===== RUNNING PROOF ANALYSIS " << GetName() << " ON TEST CHAIN " << chain->GetName() << endl;
1671 retv = chain->Process("AliAnalysisSelector", "", nentries, firstentry);
1673 line = Form("gProof->Process(\"%s\", \"AliAnalysisSelector\", \"\", %lld, %lld);",
1674 dataset, nentries, firstentry);
1675 cout << "===== RUNNING PROOF ANALYSIS " << GetName() << " ON DATASET " << dataset << endl;
1676 retv = (Long_t)gROOT->ProcessLine(line);
1681 //______________________________________________________________________________
1682 TFile *AliAnalysisManager::OpenFile(AliAnalysisDataContainer *cont, const char *option, Bool_t ignoreProof)
1684 // Opens according the option the file specified by cont->GetFileName() and changes
1685 // current directory to cont->GetFolderName(). If the file was already opened, it
1686 // checks if the option UPDATE was preserved. File open via TProofOutputFile can
1687 // be optionally ignored.
1688 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1689 TString filename = cont->GetFileName();
1691 if (filename.IsNull()) {
1692 ::Error("AliAnalysisManager::OpenFile", "No file name specified for container %s", cont->GetName());
1695 if (mgr->GetAnalysisType()==AliAnalysisManager::kProofAnalysis && cont->IsSpecialOutput()
1697 f = mgr->OpenProofFile(cont,option);
1699 // Check first if the file is already opened
1700 f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
1702 // Check if option "UPDATE" was preserved
1703 TString opt(option);
1705 if ((opt=="UPDATE") && (opt!=f->GetOption()))
1706 ::Info("AliAnalysisManager::OpenFile", "File %s already opened in %s mode!", cont->GetFileName(), f->GetOption());
1708 f = TFile::Open(filename, option);
1711 if (f && !f->IsZombie() && !f->TestBit(TFile::kRecovered)) {
1715 // Check for a folder request
1716 TString dir = cont->GetFolderName();
1717 if (!dir.IsNull()) {
1718 if (!f->GetDirectory(dir)) f->mkdir(dir);
1723 ::Fatal("AliAnalysisManager::OpenFile", "File %s could not be opened", filename.Data());
1724 cont->SetFile(NULL);
1728 //______________________________________________________________________________
1729 TFile *AliAnalysisManager::OpenProofFile(AliAnalysisDataContainer *cont, const char *option)
1731 // Opens a special output file used in PROOF.
1733 TString filename = cont->GetFileName();
1734 if (cont == fCommonOutput) {
1735 if (fOutputEventHandler) filename = fOutputEventHandler->GetOutputFileName();
1736 else Fatal("OpenProofFile","No output container. Exiting.");
1739 if (fMode!=kProofAnalysis || !fSelector) {
1740 Fatal("OpenProofFile","Cannot open PROOF file %s: no PROOF or selector",filename.Data());
1743 if (fSpecialOutputLocation.Length()) {
1744 f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
1746 // Check if option "UPDATE" was preserved
1747 TString opt(option);
1749 if ((opt=="UPDATE") && (opt!=f->GetOption()))
1750 ::Info("OpenProofFile", "File %s already opened in %s mode!", cont->GetFileName(), f->GetOption());
1752 f = new TFile(filename, option);
1754 if (f && !f->IsZombie() && !f->TestBit(TFile::kRecovered)) {
1758 // Check for a folder request
1759 TString dir = cont->GetFolderName();
1761 if (!f->GetDirectory(dir)) f->mkdir(dir);
1766 Fatal("OpenProofFile", "File %s could not be opened", cont->GetFileName());
1767 cont->SetFile(NULL);
1770 // Check if there is already a proof output file in the output list
1771 TObject *pof = fSelector->GetOutputList()->FindObject(filename);
1773 // Get the actual file
1774 line = Form("((TProofOutputFile*)0x%lx)->GetFileName();", (ULong_t)pof);
1775 filename = (const char*)gROOT->ProcessLine(line);
1777 printf("File: %s already booked via TProofOutputFile\n", filename.Data());
1779 f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
1781 Fatal("OpenProofFile", "Proof output file found but no file opened for %s", filename.Data());
1784 // Check if option "UPDATE" was preserved
1785 TString opt(option);
1787 if ((opt=="UPDATE") && (opt!=f->GetOption()))
1788 Fatal("OpenProofFile", "File %s already opened, but not in UPDATE mode!", cont->GetFileName());
1790 if (cont->IsRegisterDataset()) {
1791 TString dsetName = filename;
1792 dsetName.ReplaceAll(".root", cont->GetTitle());
1793 dsetName.ReplaceAll(":","_");
1794 if (fDebug>1) printf("Booking dataset: %s\n", dsetName.Data());
1795 line = Form("TProofOutputFile *pf = new TProofOutputFile(\"%s\", \"DROV\", \"%s\");", filename.Data(), dsetName.Data());
1797 if (fDebug>1) printf("Booking TProofOutputFile: %s to be merged\n", filename.Data());
1798 line = Form("TProofOutputFile *pf = new TProofOutputFile(\"%s\");", filename.Data());
1800 if (fDebug > 1) printf("=== %s\n", line.Data());
1801 gROOT->ProcessLine(line);
1802 line = Form("pf->OpenFile(\"%s\");", option);
1803 gROOT->ProcessLine(line);
1806 gROOT->ProcessLine("pf->Print()");
1807 printf(" == proof file name: %s", f->GetName());
1809 // Add to proof output list
1810 line = Form("((TList*)0x%lx)->Add(pf);",(ULong_t)fSelector->GetOutputList());
1811 if (fDebug > 1) printf("=== %s\n", line.Data());
1812 gROOT->ProcessLine(line);
1814 if (f && !f->IsZombie() && !f->TestBit(TFile::kRecovered)) {
1818 // Check for a folder request
1819 TString dir = cont->GetFolderName();
1820 if (!dir.IsNull()) {
1821 if (!f->GetDirectory(dir)) f->mkdir(dir);
1826 Fatal("OpenProofFile", "File %s could not be opened", cont->GetFileName());
1827 cont->SetFile(NULL);
1831 //______________________________________________________________________________
1832 void AliAnalysisManager::ExecAnalysis(Option_t *option)
1834 // Execute analysis.
1835 static Long64_t ncalls = 0;
1836 static Long64_t nentries = 0;
1837 static TTree *lastTree = 0;
1838 static TStopwatch *timer = new TStopwatch();
1839 if (fDebug > 0) printf("MGR: Processing event #%lld\n", ncalls);
1841 if (fTree && (fTree != lastTree)) {
1842 nentries += fTree->GetEntries();
1845 if (!ncalls) timer->Start();
1846 if (!fIsRemote && TObject::TestBit(kUseProgressBar)) ProgressBar("Processing event", ncalls, nentries, timer, kFALSE);
1849 TDirectory *cdir = gDirectory;
1850 Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
1851 if (getsysInfo && ((ncalls%fNSysInfo)==0)) AliSysInfo::AddStamp("Exec_start", (Int_t)ncalls);
1854 Error("ExecAnalysis", "Analysis manager was not initialized !");
1858 AliAnalysisTask *task;
1859 // Check if the top tree is active.
1861 if (getsysInfo && ((ncalls%fNSysInfo)==0))
1862 AliSysInfo::AddStamp("Handlers_BeginEventGroup",(Int_t)ncalls, 1002, 0);
1864 // De-activate all tasks
1865 while ((task=(AliAnalysisTask*)next())) task->SetActive(kFALSE);
1866 AliAnalysisDataContainer *cont = fCommonInput;
1867 if (!cont) cont = (AliAnalysisDataContainer*)fInputs->At(0);
1869 Error("ExecAnalysis","Cannot execute analysis in TSelector mode without at least one top container");
1873 cont->SetData(fTree); // This will notify all consumers
1874 Long64_t entry = fTree->GetTree()->GetReadEntry();
1876 // Call BeginEvent() for optional input/output and MC services
1877 if (fInputEventHandler) fInputEventHandler ->BeginEvent(entry);
1878 if (fOutputEventHandler) fOutputEventHandler ->BeginEvent(entry);
1879 if (fMCtruthEventHandler) fMCtruthEventHandler->BeginEvent(entry);
1881 if (getsysInfo && ((ncalls%fNSysInfo)==0))
1882 AliSysInfo::AddStamp("Handlers_BeginEvent",(Int_t)ncalls, 1000, 0);
1884 // Execute the tasks
1885 // TIter next1(cont->GetConsumers());
1886 TIter next1(fTopTasks);
1888 while ((task=(AliAnalysisTask*)next1())) {
1890 cout << " Executing task " << task->GetName() << endl;
1892 task->ExecuteTask(option);
1894 if (getsysInfo && ((ncalls%fNSysInfo)==0))
1895 AliSysInfo::AddStamp(task->ClassName(),(Int_t)ncalls, itask, 1);
1899 // Call FinishEvent() for optional output and MC services
1900 if (fInputEventHandler) fInputEventHandler ->FinishEvent();
1901 if (fOutputEventHandler) fOutputEventHandler ->FinishEvent();
1902 if (fMCtruthEventHandler) fMCtruthEventHandler->FinishEvent();
1903 // Gather system information if requested
1904 if (getsysInfo && ((ncalls%fNSysInfo)==0))
1905 AliSysInfo::AddStamp("Handlers_FinishEvent",(Int_t)ncalls, 1001, 1);
1909 // The event loop is not controlled by TSelector
1911 // Call BeginEvent() for optional input/output and MC services
1912 if (fInputEventHandler) fInputEventHandler ->BeginEvent(-1);
1913 if (fOutputEventHandler) fOutputEventHandler ->BeginEvent(-1);
1914 if (fMCtruthEventHandler) fMCtruthEventHandler->BeginEvent(-1);
1916 if (getsysInfo && ((ncalls%fNSysInfo)==0))
1917 AliSysInfo::AddStamp("Handlers_BeginEvent",(Int_t)ncalls, 1000, 0);
1918 TIter next2(fTopTasks);
1919 while ((task=(AliAnalysisTask*)next2())) {
1920 task->SetActive(kTRUE);
1922 cout << " Executing task " << task->GetName() << endl;
1924 task->ExecuteTask(option);
1928 // Call FinishEvent() for optional output and MC services
1929 if (fInputEventHandler) fInputEventHandler ->FinishEvent();
1930 if (fOutputEventHandler) fOutputEventHandler ->FinishEvent();
1931 if (fMCtruthEventHandler) fMCtruthEventHandler->FinishEvent();
1932 if (getsysInfo && ((ncalls%fNSysInfo)==0))
1933 AliSysInfo::AddStamp("Handlers_FinishEvent",(Int_t)ncalls, 1000, 1);
1937 //______________________________________________________________________________
1938 void AliAnalysisManager::SetInputEventHandler(AliVEventHandler* const handler)
1940 // Set the input event handler and create a container for it.
1941 fInputEventHandler = handler;
1942 fCommonInput = CreateContainer("cAUTO_INPUT", TChain::Class(), AliAnalysisManager::kInputContainer);
1943 // Warning("SetInputEventHandler", " An automatic input container for the input chain was created.\nPlease use: mgr->GetCommonInputContainer() to access it.");
1946 //______________________________________________________________________________
1947 void AliAnalysisManager::SetOutputEventHandler(AliVEventHandler* const handler)
1949 // Set the input event handler and create a container for it.
1950 fOutputEventHandler = handler;
1951 fCommonOutput = CreateContainer("cAUTO_OUTPUT", TTree::Class(), AliAnalysisManager::kOutputContainer, "default");
1952 fCommonOutput->SetSpecialOutput();
1953 // Warning("SetOutputEventHandler", " An automatic output container for the output tree was created.\nPlease use: mgr->GetCommonOutputContainer() to access it.");
1956 //______________________________________________________________________________
1957 void AliAnalysisManager::RegisterExtraFile(const char *fname)
1959 // This method is used externally to register output files which are not
1960 // connected to any output container, so that the manager can properly register,
1961 // retrieve or merge them when running in distributed mode. The file names are
1962 // separated by blancs. The method has to be called in MyAnalysisTask::LocalInit().
1963 if (fExtraFiles.Contains(fname)) return;
1964 if (fExtraFiles.Length()) fExtraFiles += " ";
1965 fExtraFiles += fname;
1968 //______________________________________________________________________________
1969 Bool_t AliAnalysisManager::GetFileFromWrapper(const char *filename, const TList *source)
1971 // Copy a file from the location specified ina the wrapper with the same name from the source list.
1974 TObject *pof = source->FindObject(filename);
1975 if (!pof || !pof->InheritsFrom("TProofOutputFile")) {
1976 Error("GetFileFromWrapper", "TProofOutputFile object not found in output list for file %s", filename);
1979 gROOT->ProcessLine(Form("sprintf((char*)0x%lx, \"%%s\", ((TProofOutputFile*)0x%lx)->GetOutputFileName();)", (ULong_t)fullPath, (ULong_t)pof));
1980 gROOT->ProcessLine(Form("sprintf((char*)0x%lx, \"%%s\", gProof->GetUrl();)", (ULong_t)chUrl));
1981 TString clientUrl(chUrl);
1982 TString fullPath_str(fullPath);
1983 if (clientUrl.Contains("localhost")){
1984 TObjArray* array = fullPath_str.Tokenize ( "//" );
1985 TObjString *strobj = ( TObjString *)array->At(1);
1986 TObjArray* arrayPort = strobj->GetString().Tokenize ( ":" );
1987 TObjString *strobjPort = ( TObjString *) arrayPort->At(1);
1988 fullPath_str.ReplaceAll(strobj->GetString().Data(),"localhost:PORT");
1989 fullPath_str.ReplaceAll(":PORT",Form(":%s",strobjPort->GetString().Data()));
1990 if (fDebug > 1) Info("GetFileFromWrapper","Using tunnel from %s to %s",fullPath_str.Data(),filename);
1995 Info("GetFileFromWrapper","Copying file %s from PROOF scratch space", fullPath_str.Data());
1996 Bool_t gotit = TFile::Cp(fullPath_str.Data(), filename);
1998 Error("GetFileFromWrapper", "Could not get file %s from proof scratch space", filename);
2002 //______________________________________________________________________________
2003 void AliAnalysisManager::GetAnalysisTypeString(TString &type) const
2005 // Fill analysis type in the provided string.
2007 case kLocalAnalysis:
2010 case kProofAnalysis:
2016 case kMixingAnalysis:
2021 //______________________________________________________________________________
2022 Bool_t AliAnalysisManager::ValidateOutputFiles() const
2024 // Validate all output files.
2025 TIter next(fOutputs);
2026 AliAnalysisDataContainer *output;
2027 TDirectory *cdir = gDirectory;
2028 TString openedFiles;
2029 while ((output=(AliAnalysisDataContainer*)next())) {
2030 if (output->IsRegisterDataset()) continue;
2031 TString filename = output->GetFileName();
2032 if (filename == "default") {
2033 if (!fOutputEventHandler) continue;
2034 filename = fOutputEventHandler->GetOutputFileName();
2035 // Main AOD may not be there
2036 if (gSystem->AccessPathName(filename)) continue;
2038 // Check if the file is closed
2039 if (openedFiles.Contains(filename)) continue;;
2040 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
2042 Warning("ValidateOutputs", "File %s was not closed. Closing.", filename.Data());
2043 // Clear file list to release object ownership to user.
2047 file = TFile::Open(filename);
2048 if (!file || file->IsZombie() || file->TestBit(TFile::kRecovered)) {
2049 Error("ValidateOutputs", "Output file <%s> was not created or invalid", filename.Data());
2054 openedFiles += filename;
2061 //______________________________________________________________________________
2062 void AliAnalysisManager::ProgressBar(const char *opname, Long64_t current, Long64_t size, TStopwatch * const watch, Bool_t last, Bool_t refresh)
2064 // Implements a nice text mode progress bar.
2065 static Long64_t icount = 0;
2066 static TString oname;
2067 static TString nname;
2068 static Long64_t ocurrent = 0;
2069 static Long64_t osize = 0;
2070 static Int_t oseconds = 0;
2071 static TStopwatch *owatch = 0;
2072 static Bool_t oneoftwo = kFALSE;
2073 static Int_t nrefresh = 0;
2074 static Int_t nchecks = 0;
2075 const char symbol[4] = {'=','\\','|','/'};
2076 char progress[11] = " ";
2077 Int_t ichar = icount%4;
2084 ocurrent = TMath::Abs(current);
2085 osize = TMath::Abs(size);
2086 if (ocurrent > osize) ocurrent=osize;
2096 if (owatch && !last) {
2098 time = owatch->RealTime();
2099 hours = (Int_t)(time/3600.);
2101 minutes = (Int_t)(time/60.);
2103 seconds = (Int_t)time;
2105 if (oseconds==seconds) {
2109 oneoftwo = !oneoftwo;
2113 if (refresh && oneoftwo) {
2115 if (nchecks <= 0) nchecks = nrefresh+1;
2116 Int_t pctdone = (Int_t)(100.*nrefresh/nchecks);
2117 oname = Form(" == %d%% ==", pctdone);
2119 Double_t percent = 100.0*ocurrent/osize;
2120 Int_t nchar = Int_t(percent/10);
2121 if (nchar>10) nchar=10;
2123 for (i=0; i<nchar; i++) progress[i] = '=';
2124 progress[nchar] = symbol[ichar];
2125 for (i=nchar+1; i<10; i++) progress[i] = ' ';
2126 progress[10] = '\0';
2129 if(size<10000) fprintf(stderr, "%s [%10s] %4lld ", oname.Data(), progress, ocurrent);
2130 else if(size<100000) fprintf(stderr, "%s [%10s] %5lld ",oname.Data(), progress, ocurrent);
2131 else fprintf(stderr, "%s [%10s] %7lld ",oname.Data(), progress, ocurrent);
2132 if (time>0.) fprintf(stderr, "[%6.2f %%] TIME %.2d:%.2d:%.2d \r", percent, hours, minutes, seconds);
2133 else fprintf(stderr, "[%6.2f %%]\r", percent);
2134 if (refresh && oneoftwo) oname = nname;
2135 if (owatch) owatch->Continue();
2144 fprintf(stderr, "\n");
2148 //______________________________________________________________________________
2149 void AliAnalysisManager::DoLoadBranch(const char *name)
2151 // Get tree and load branch if needed.
2156 TBranch *br = dynamic_cast<TBranch*>(fTable.FindObject(name));
2158 br = fTree->GetBranch(name);
2160 Error("DoLoadBranch", "Could not find branch %s",name);
2165 if (br->GetReadEntry()==GetCurrentEntry())
2167 br->GetEntry(GetCurrentEntry());