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 (fDebug > 1) printf("<-AliAnalysisManager::Process()\n");
481 //______________________________________________________________________________
482 void AliAnalysisManager::PackOutput(TList *target)
484 // Pack all output data containers in the output list. Called at SlaveTerminate
485 // stage in PROOF case for each slave.
486 if (fDebug > 1) printf("->AliAnalysisManager::PackOutput()\n");
488 Error("PackOutput", "No target. Exiting.");
491 TDirectory *cdir = gDirectory;
493 if (fInputEventHandler) fInputEventHandler ->Terminate();
494 if (fOutputEventHandler) fOutputEventHandler ->Terminate();
495 if (fMCtruthEventHandler) fMCtruthEventHandler->Terminate();
498 // Call FinishTaskOutput() for each event loop task (not called for
499 // post-event loop tasks - use Terminate() fo those)
500 TIter nexttask(fTasks);
501 AliAnalysisTask *task;
502 while ((task=(AliAnalysisTask*)nexttask())) {
503 if (!task->IsPostEventLoop()) {
504 if (fDebug > 1) printf("->FinishTaskOutput: task %s\n", task->GetName());
505 task->FinishTaskOutput();
507 if (fDebug > 1) printf("<-FinishTaskOutput: task %s\n", task->GetName());
511 if (fMode == kProofAnalysis) {
512 TIter next(fOutputs);
513 AliAnalysisDataContainer *output;
514 Bool_t isManagedByHandler = kFALSE;
517 while ((output=(AliAnalysisDataContainer*)next())) {
518 // Do not consider outputs of post event loop tasks
519 isManagedByHandler = kFALSE;
520 if (output->GetProducer() && output->GetProducer()->IsPostEventLoop()) continue;
521 const char *filename = output->GetFileName();
522 if (!(strcmp(filename, "default")) && fOutputEventHandler) {
523 isManagedByHandler = kTRUE;
524 printf("#### Handler output. Extra: %s\n", fExtraFiles.Data());
525 filename = fOutputEventHandler->GetOutputFileName();
527 // Check if data was posted to this container. If not, issue an error.
528 if (!output->GetData() && !isManagedByHandler) {
529 Error("PackOutput", "No data for output container %s. Forgot to PostData ?", output->GetName());
532 if (!output->IsSpecialOutput()) {
534 if (strlen(filename) && !isManagedByHandler) {
535 // Backup current folder
536 TDirectory *opwd = gDirectory;
537 // File resident outputs.
538 // Check first if the file exists.
539 TString openoption = "RECREATE";
540 Bool_t firsttime = kTRUE;
541 if (filestmp.FindObject(output->GetFileName())) {
544 filestmp.Add(new TNamed(output->GetFileName(),""));
546 if (!gSystem->AccessPathName(output->GetFileName()) && !firsttime) openoption = "UPDATE";
547 // TFile *file = AliAnalysisManager::OpenFile(output, openoption, kTRUE);
548 // Save data to file, then close.
549 if (output->GetData()->InheritsFrom(TCollection::Class())) {
550 // If data is a collection, we set the name of the collection
551 // as the one of the container and we save as a single key.
552 TCollection *coll = (TCollection*)output->GetData();
553 coll->SetName(output->GetName());
554 // coll->Write(output->GetName(), TObject::kSingleKey);
556 if (output->GetData()->InheritsFrom(TTree::Class())) {
557 TFile *file = AliAnalysisManager::OpenFile(output, openoption, kTRUE);
558 // Save data to file, then close.
559 TTree *tree = (TTree*)output->GetData();
560 // Check if tree is in memory
561 if (tree->GetDirectory()==gROOT) tree->SetDirectory(gDirectory);
565 // output->GetData()->Write();
568 if (fDebug > 1) printf("PackOutput %s: memory merge, file resident output\n", output->GetName());
570 // printf(" file %s listing content:\n", filename);
573 // Clear file list to release object ownership to user.
576 output->SetFile(NULL);
577 // Restore current directory
578 if (opwd) opwd->cd();
580 // Memory-resident outputs
581 if (fDebug > 1) printf("PackOutput %s: memory merge memory resident output\n", filename);
583 AliAnalysisDataWrapper *wrap = 0;
584 if (isManagedByHandler) {
585 wrap = new AliAnalysisDataWrapper(fOutputEventHandler->GetTree());
586 wrap->SetName(output->GetName());
588 else wrap =output->ExportData();
589 // Output wrappers must NOT delete data after merging - the user owns them
590 wrap->SetDeleteData(kFALSE);
593 // Special outputs. The file must be opened and connected to the container.
594 TDirectory *opwd = gDirectory;
595 TFile *file = output->GetFile();
597 AliAnalysisTask *producer = output->GetProducer();
599 "File %s for special container %s was NOT opened in %s::CreateOutputObjects !!!",
600 output->GetFileName(), output->GetName(), producer->ClassName());
603 TString outFilename = file->GetName();
604 if (fDebug > 1) printf("PackOutput %s: special output\n", output->GetName());
605 if (isManagedByHandler) {
606 // Terminate IO for files managed by the output handler
607 // file->Write() moved to AOD handler (A.G. 11.01.10)
608 // if (file) file->Write();
609 if (file && fDebug > 2) {
610 printf(" handled file %s listing content:\n", file->GetName());
613 fOutputEventHandler->TerminateIO();
616 // Release object ownership to users after writing data to file
617 if (output->GetData()->InheritsFrom(TCollection::Class())) {
618 // If data is a collection, we set the name of the collection
619 // as the one of the container and we save as a single key.
620 TCollection *coll = (TCollection*)output->GetData();
621 coll->SetName(output->GetName());
622 coll->Write(output->GetName(), TObject::kSingleKey);
624 if (output->GetData()->InheritsFrom(TTree::Class())) {
625 TTree *tree = (TTree*)output->GetData();
626 tree->SetDirectory(file);
629 output->GetData()->Write();
633 printf(" file %s listing content:\n", output->GetFileName());
636 // Clear file list to release object ownership to user.
639 output->SetFile(NULL);
641 // Restore current directory
642 if (opwd) opwd->cd();
643 // Check if a special output location was provided or the output files have to be merged
644 if (strlen(fSpecialOutputLocation.Data())) {
645 TString remote = fSpecialOutputLocation;
647 Int_t gid = gROOT->ProcessLine("gProofServ->GetGroupId();");
648 if (remote.BeginsWith("alien:")) {
649 gROOT->ProcessLine("TGrid::Connect(\"alien:\", gProofServ->GetUser());");
650 remote += outFilename;
651 remote.ReplaceAll(".root", Form("_%d.root", gid));
653 remote += Form("%s_%d_", gSystem->HostName(), gid);
654 remote += outFilename;
657 Info("PackOutput", "Output file for container %s to be copied \n at: %s. No merging.",
658 output->GetName(), remote.Data());
659 TFile::Cp ( outFilename.Data(), remote.Data() );
660 // Copy extra outputs
661 if (fExtraFiles.Length() && isManagedByHandler) {
662 TObjArray *arr = fExtraFiles.Tokenize(" ");
664 TIter nextfilename(arr);
665 while ((os=(TObjString*)nextfilename())) {
666 outFilename = os->GetString();
667 remote = fSpecialOutputLocation;
669 if (remote.BeginsWith("alien://")) {
670 remote += outFilename;
671 remote.ReplaceAll(".root", Form("_%d.root", gid));
673 remote += Form("%s_%d_", gSystem->HostName(), gid);
674 remote += outFilename;
677 Info("PackOutput", "Extra AOD file %s to be copied \n at: %s. No merging.",
678 outFilename.Data(), remote.Data());
679 TFile::Cp ( outFilename.Data(), remote.Data() );
684 // No special location specified-> use TProofOutputFile as merging utility
685 // The file at this output slot must be opened in CreateOutputObjects
686 if (fDebug > 1) printf(" File for container %s to be merged via file merger...\n", output->GetName());
692 if (fDebug > 1) printf("<-AliAnalysisManager::PackOutput: output list contains %d containers\n", target->GetSize());
695 //______________________________________________________________________________
696 void AliAnalysisManager::ImportWrappers(TList *source)
698 // Import data in output containers from wrappers coming in source.
699 if (fDebug > 1) printf("->AliAnalysisManager::ImportWrappers()\n");
700 TIter next(fOutputs);
701 AliAnalysisDataContainer *cont;
702 AliAnalysisDataWrapper *wrap;
704 Bool_t inGrid = (fMode == kGridAnalysis)?kTRUE:kFALSE;
705 TDirectory *cdir = gDirectory;
706 while ((cont=(AliAnalysisDataContainer*)next())) {
708 if (cont->GetProducer() && cont->GetProducer()->IsPostEventLoop() && !inGrid) continue;
709 if (cont->IsRegisterDataset()) continue;
710 const char *filename = cont->GetFileName();
711 Bool_t isManagedByHandler = kFALSE;
712 if (!(strcmp(filename, "default")) && fOutputEventHandler) {
713 isManagedByHandler = kTRUE;
714 filename = fOutputEventHandler->GetOutputFileName();
716 if (cont->IsSpecialOutput() || inGrid) {
717 if (strlen(fSpecialOutputLocation.Data())) continue;
718 // Copy merged file from PROOF scratch space.
719 // In case of grid the files are already in the current directory.
721 if (isManagedByHandler && fExtraFiles.Length()) {
722 // Copy extra registered dAOD files.
723 TObjArray *arr = fExtraFiles.Tokenize(" ");
725 TIter nextfilename(arr);
726 while ((os=(TObjString*)nextfilename())) GetFileFromWrapper(os->GetString(), source);
729 if (!GetFileFromWrapper(filename, source)) continue;
731 // Normally we should connect data from the copied file to the
732 // corresponding output container, but it is not obvious how to do this
733 // automatically if several objects in file...
734 TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
735 if (!f) f = TFile::Open(filename, "READ");
737 Error("ImportWrappers", "Cannot open file %s in read-only mode", filename);
741 // Cd to the directory pointed by the container
742 TString folder = cont->GetFolderName();
743 if (!folder.IsNull()) f->cd(folder);
744 // Try to fetch first an object having the container name.
745 obj = gDirectory->Get(cont->GetName());
747 Warning("ImportWrappers", "Could not import object for container %s in file %s:%s.\n Object will not be available in Terminate()",
748 cont->GetName(), filename, cont->GetFolderName());
751 wrap = new AliAnalysisDataWrapper(obj);
752 wrap->SetDeleteData(kFALSE);
754 if (!wrap) wrap = (AliAnalysisDataWrapper*)source->FindObject(cont->GetName());
756 Error("ImportWrappers","Container %s not found in analysis output !", cont->GetName());
761 printf(" Importing data for container %s\n", cont->GetName());
762 if (strlen(filename)) printf(" -> file %s\n", filename);
765 cont->ImportData(wrap);
767 if (cdir) cdir->cd();
768 if (fDebug > 1) printf("<-AliAnalysisManager::ImportWrappers(): %d containers imported\n", icont);
771 //______________________________________________________________________________
772 void AliAnalysisManager::UnpackOutput(TList *source)
774 // Called by AliAnalysisSelector::Terminate only on the client.
775 if (fDebug > 1) printf("->AliAnalysisManager::UnpackOutput()\n");
777 Error("UnpackOutput", "No target. Exiting.");
780 if (fDebug > 1) printf(" Source list contains %d containers\n", source->GetSize());
782 if (fMode == kProofAnalysis) ImportWrappers(source);
784 TIter next(fOutputs);
785 AliAnalysisDataContainer *output;
786 while ((output=(AliAnalysisDataContainer*)next())) {
787 if (!output->GetData()) continue;
788 // Check if there are client tasks that run post event loop
789 if (output->HasConsumers()) {
790 // Disable event loop semaphore
791 output->SetPostEventLoop(kTRUE);
792 TObjArray *list = output->GetConsumers();
793 Int_t ncons = list->GetEntriesFast();
794 for (Int_t i=0; i<ncons; i++) {
795 AliAnalysisTask *task = (AliAnalysisTask*)list->At(i);
796 task->CheckNotify(kTRUE);
797 // If task is active, execute it
798 if (task->IsPostEventLoop() && task->IsActive()) {
799 if (fDebug > 1) printf("== Executing post event loop task %s\n", task->GetName());
805 if (fDebug > 1) printf("<-AliAnalysisManager::UnpackOutput()\n");
808 //______________________________________________________________________________
809 void AliAnalysisManager::Terminate()
811 // The Terminate() function is the last function to be called during
812 // a query. It always runs on the client, it can be used to present
813 // the results graphically.
814 if (fDebug > 1) printf("->AliAnalysisManager::Terminate()\n");
815 TDirectory *cdir = gDirectory;
817 AliAnalysisTask *task;
818 AliAnalysisDataContainer *output;
821 Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
822 // Call Terminate() for tasks
824 while (!IsSkipTerminate() && (task=(AliAnalysisTask*)next())) {
825 // Save all the canvases produced by the Terminate
826 TString pictname = Form("%s_%s", task->GetName(), task->ClassName());
830 AliSysInfo::AddStamp(Form("%s_TERMINATE",task->ClassName()),0, itask, 2);
832 if (TObject::TestBit(kSaveCanvases)) {
833 if (!gROOT->IsBatch()) {
834 if (fDebug>1) printf("Waiting 5 sec for %s::Terminate() to finish drawing ...\n", task->ClassName());
836 while (timer.CpuTime()<5) {
838 gSystem->ProcessEvents();
841 Int_t iend = gROOT->GetListOfCanvases()->GetEntries();
842 if (iend==0) continue;
844 for (Int_t ipict=0; ipict<iend; ipict++) {
845 canvas = (TCanvas*)gROOT->GetListOfCanvases()->At(ipict);
846 if (!canvas) continue;
847 canvas->SaveAs(Form("%s_%02d.gif", pictname.Data(),ipict));
849 gROOT->GetListOfCanvases()->Delete();
853 if (fInputEventHandler) fInputEventHandler ->TerminateIO();
854 if (fOutputEventHandler) fOutputEventHandler ->TerminateIO();
855 if (fMCtruthEventHandler) fMCtruthEventHandler->TerminateIO();
857 TObjArray *allOutputs = new TObjArray();
859 for (icont=0; icont<fOutputs->GetEntriesFast(); icont++) allOutputs->Add(fOutputs->At(icont));
860 if (!IsSkipTerminate())
861 for (icont=0; icont<fParamCont->GetEntriesFast(); icont++) allOutputs->Add(fParamCont->At(icont));
862 TIter next1(allOutputs);
863 TString handlerFile = "";
864 TString extraOutputs = "";
865 if (fOutputEventHandler) {
866 handlerFile = fOutputEventHandler->GetOutputFileName();
867 extraOutputs = fOutputEventHandler->GetExtraOutputs();
871 while ((output=(AliAnalysisDataContainer*)next1())) {
872 // Special outputs or grid files have the files already closed and written.
874 if (fMode == kGridAnalysis && icont<=fOutputs->GetEntriesFast()) continue;
875 if (fMode == kProofAnalysis) {
876 if (output->IsSpecialOutput() || output->IsRegisterDataset()) continue;
878 const char *filename = output->GetFileName();
879 TString openoption = "RECREATE";
880 if (!(strcmp(filename, "default"))) continue;
881 if (!strlen(filename)) continue;
882 if (!output->GetData()) continue;
883 TDirectory *opwd = gDirectory;
884 TFile *file = output->GetFile();
885 if (!file) file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
887 //if (handlerFile == filename && !gSystem->AccessPathName(filename)) openoption = "UPDATE";
888 Bool_t firsttime = kTRUE;
889 if (filestmp.FindObject(filename) || extraOutputs.Contains(filename)) {
892 filestmp.Add(new TNamed(filename,""));
894 if (!gSystem->AccessPathName(filename) && !firsttime) openoption = "UPDATE";
895 if (fDebug>1) printf("Opening file: %s option=%s\n",filename, openoption.Data());
896 file = new TFile(filename, openoption);
898 if (fDebug>1) printf("File <%s> already opened with option: <%s> \n", filename, file->GetOption());
899 openoption = file->GetOption();
900 if (openoption == "READ") {
901 if (fDebug>1) printf("...reopening in UPDATE mode\n");
902 file->ReOpen("UPDATE");
905 if (file->IsZombie()) {
906 Error("Terminate", "Cannot open output file %s", filename);
909 output->SetFile(file);
911 // Check for a folder request
912 TString dir = output->GetFolderName();
914 if (!file->GetDirectory(dir)) file->mkdir(dir);
917 if (fDebug > 1) printf("...writing container %s to file %s:%s\n", output->GetName(), file->GetName(), output->GetFolderName());
918 if (output->GetData()->InheritsFrom(TCollection::Class())) {
919 // If data is a collection, we set the name of the collection
920 // as the one of the container and we save as a single key.
921 TCollection *coll = (TCollection*)output->GetData();
922 coll->SetName(output->GetName());
923 coll->Write(output->GetName(), TObject::kSingleKey);
925 if (output->GetData()->InheritsFrom(TTree::Class())) {
926 TTree *tree = (TTree*)output->GetData();
927 tree->SetDirectory(gDirectory);
930 output->GetData()->Write();
933 if (opwd) opwd->cd();
937 while ((output=(AliAnalysisDataContainer*)next1())) {
938 // Close all files at output
939 TDirectory *opwd = gDirectory;
940 if (output->GetFile()) {
941 // Clear file list to release object ownership to user.
942 // output->GetFile()->Clear();
943 output->GetFile()->Close();
944 output->SetFile(NULL);
945 // Copy merged outputs in alien if requested
946 if (fSpecialOutputLocation.Length() &&
947 fSpecialOutputLocation.BeginsWith("alien://")) {
948 Info("Terminate", "Copy file %s to %s", output->GetFile()->GetName(),fSpecialOutputLocation.Data());
949 TFile::Cp(output->GetFile()->GetName(),
950 Form("%s/%s", fSpecialOutputLocation.Data(), output->GetFile()->GetName()));
953 if (opwd) opwd->cd();
958 TDirectory *crtdir = gDirectory;
959 TFile f("syswatch.root", "RECREATE");
963 TTree *tree = AliSysInfo::MakeTree("syswatch.log");
964 tree->SetName("syswatch");
965 tree->SetMarkerStyle(kCircle);
966 tree->SetMarkerColor(kBlue);
967 tree->SetMarkerSize(0.5);
968 if (!gROOT->IsBatch()) {
969 tree->SetAlias("event", "id0");
970 tree->SetAlias("task", "id1");
971 tree->SetAlias("stage", "id2");
972 // Already defined aliases
973 // tree->SetAlias("deltaT","stampSec-stampOldSec");
974 // tree->SetAlias("T","stampSec-first");
975 // tree->SetAlias("deltaVM","(pI.fMemVirtual-pIOld.fMemVirtual)");
976 // tree->SetAlias("VM","pI.fMemVirtual");
977 TCanvas *canvas = new TCanvas("SysInfo","SysInfo",10,10,1200,800);
978 Int_t npads = 1 /*COO plot for all tasks*/ +
979 fTopTasks->GetEntries() /*Exec plot per task*/ +
980 1 /*Terminate plot for all tasks*/ +
983 Int_t iopt = (Int_t)TMath::Sqrt((Double_t)npads);
984 if (npads<iopt*(iopt+1))
985 canvas->Divide(iopt, iopt+1, 0.01, 0.01);
987 canvas->Divide(iopt+1, iopt+1, 0.01, 0.01);
989 // draw the plot of deltaVM for Exec for each task
990 for (itask=0; itask<fTopTasks->GetEntriesFast(); itask++) {
991 task = (AliAnalysisTask*)fTopTasks->At(itask);
993 cut = Form("task==%d && stage==1", itask);
994 tree->Draw("deltaVM:event",cut,"", 1234567890, 0);
995 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
997 hist->SetTitle(Form("%s: Exec dVM[kB]/event", task->GetName()));
998 hist->GetYaxis()->SetTitle("deltaVM [kB]");
1001 // Draw the plot of deltaVM for CreateOutputObjects for all tasks
1003 tree->SetMarkerStyle(kFullTriangleUp);
1004 tree->SetMarkerColor(kRed);
1005 tree->SetMarkerSize(0.8);
1006 cut = "task>=0 && task<1000 && stage==0";
1007 tree->Draw("deltaVM:sname",cut,"", 1234567890, 0);
1008 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1010 hist->SetTitle("Memory in CreateOutputObjects()");
1011 hist->GetYaxis()->SetTitle("deltaVM [kB]");
1012 hist->GetXaxis()->SetTitle("task");
1014 // draw the plot of deltaVM for Terminate for all tasks
1016 tree->SetMarkerStyle(kOpenSquare);
1017 tree->SetMarkerColor(kMagenta);
1018 cut = "task>=0 && task<1000 && stage==2";
1019 tree->Draw("deltaVM:sname",cut,"", 1234567890, 0);
1020 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1022 hist->SetTitle("Memory in Terminate()");
1023 hist->GetYaxis()->SetTitle("deltaVM [kB]");
1024 hist->GetXaxis()->SetTitle("task");
1028 tree->SetMarkerStyle(kFullCircle);
1029 tree->SetMarkerColor(kGreen);
1030 cut = Form("task==%d && stage==1",fTopTasks->GetEntriesFast()-1);
1031 tree->Draw("VM:event",cut,"", 1234567890, 0);
1032 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1034 hist->SetTitle("Virtual memory");
1035 hist->GetYaxis()->SetTitle("VM [kB]");
1039 tree->SetMarkerStyle(kCircle);
1040 tree->SetMarkerColor(kBlue);
1041 tree->SetMarkerSize(0.5);
1046 if (crtdir) crtdir->cd();
1048 // Validate the output files
1049 if (ValidateOutputFiles()) {
1051 out.open("outputs_valid", ios::out);
1055 if (fDebug > 1) printf("<-AliAnalysisManager::Terminate()\n");
1057 //______________________________________________________________________________
1058 void AliAnalysisManager::ProfileTask(Int_t itop, const char *option) const
1060 // Profiles the task having the itop index in the list of top (first level) tasks.
1061 AliAnalysisTask *task = (AliAnalysisTask*)fTopTasks->At(itop);
1063 Error("ProfileTask", "There are only %d top tasks in the manager", fTopTasks->GetEntries());
1066 ProfileTask(task->GetName(), option);
1069 //______________________________________________________________________________
1070 void AliAnalysisManager::ProfileTask(const char *name, const char */*option*/) const
1072 // Profile a managed task after the execution of the analysis in case NSysInfo
1074 if (gSystem->AccessPathName("syswatch.root")) {
1075 Error("ProfileTask", "No file syswatch.root found in the current directory");
1078 if (gROOT->IsBatch()) return;
1079 AliAnalysisTask *task = (AliAnalysisTask*)fTopTasks->FindObject(name);
1081 Error("ProfileTask", "No top task named %s known by the manager.", name);
1084 Int_t itop = fTopTasks->IndexOf(task);
1085 Int_t itask = fTasks->IndexOf(task);
1086 // Create canvas with 2 pads: first draw COO + Terminate, second Exec
1087 TDirectory *cdir = gDirectory;
1088 TFile f("syswatch.root");
1089 TTree *tree = (TTree*)f.Get("syswatch");
1091 Error("ProfileTask", "No tree named <syswatch> found in file syswatch.root");
1094 if (fDebug > 1) printf("=== Profiling task %s (class %s)\n", name, task->ClassName());
1095 TCanvas *canvas = new TCanvas(Form("profile_%d",itop),Form("Profile of task %s (class %s)",name,task->ClassName()),10,10,800,600);
1096 canvas->Divide(2, 2, 0.01, 0.01);
1100 // VM profile for COO and Terminate methods
1102 cut = Form("task==%d && (stage==0 || stage==2)",itask);
1103 tree->Draw("deltaVM:sname",cut,"", 1234567890, 0);
1104 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1106 hist->SetTitle("Alocated VM[kB] for COO and Terminate");
1107 hist->GetYaxis()->SetTitle("deltaVM [kB]");
1108 hist->GetXaxis()->SetTitle("method");
1110 // CPU profile per event
1112 cut = Form("task==%d && stage==1",itop);
1113 tree->Draw("deltaT:event",cut,"", 1234567890, 0);
1114 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1116 hist->SetTitle("Execution time per event");
1117 hist->GetYaxis()->SetTitle("CPU/event [s]");
1119 // VM profile for Exec
1121 cut = Form("task==%d && stage==1",itop);
1122 tree->Draw("deltaVM:event",cut,"", 1234567890, 0);
1123 hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1125 hist->SetTitle("Alocated VM[kB] per event");
1126 hist->GetYaxis()->SetTitle("deltaVM [kB]");
1131 if (cdir) cdir->cd();
1134 //______________________________________________________________________________
1135 void AliAnalysisManager::AddTask(AliAnalysisTask *task)
1137 // Adds a user task to the global list of tasks.
1138 if (fTasks->FindObject(task)) {
1139 Warning("AddTask", "Task %s: the same object already added to the analysis manager. Not adding.", task->GetName());
1142 task->SetActive(kFALSE);
1146 //______________________________________________________________________________
1147 AliAnalysisTask *AliAnalysisManager::GetTask(const char *name) const
1149 // Retreive task by name.
1150 if (!fTasks) return NULL;
1151 return (AliAnalysisTask*)fTasks->FindObject(name);
1154 //______________________________________________________________________________
1155 AliAnalysisDataContainer *AliAnalysisManager::CreateContainer(const char *name,
1156 TClass *datatype, EAliAnalysisContType type, const char *filename)
1158 // Create a data container of a certain type. Types can be:
1159 // kExchangeContainer = 0, used to exchange data between tasks
1160 // kInputContainer = 1, used to store input data
1161 // kOutputContainer = 2, used for writing result to a file
1162 // filename: composed by file#folder (e.g. results.root#INCLUSIVE) - will write
1163 // the output object to a folder inside the output file
1164 if (fContainers->FindObject(name)) {
1165 Error("CreateContainer","A container named %s already defined !",name);
1168 AliAnalysisDataContainer *cont = new AliAnalysisDataContainer(name, datatype);
1169 fContainers->Add(cont);
1171 case kInputContainer:
1174 case kOutputContainer:
1175 fOutputs->Add(cont);
1176 if (filename && strlen(filename)) {
1177 cont->SetFileName(filename);
1178 cont->SetDataOwned(kFALSE); // data owned by the file
1181 case kParamContainer:
1182 fParamCont->Add(cont);
1183 if (filename && strlen(filename)) {
1184 cont->SetFileName(filename);
1185 cont->SetDataOwned(kFALSE); // data owned by the file
1188 case kExchangeContainer:
1194 //______________________________________________________________________________
1195 Bool_t AliAnalysisManager::ConnectInput(AliAnalysisTask *task, Int_t islot,
1196 AliAnalysisDataContainer *cont)
1198 // Connect input of an existing task to a data container.
1200 Error("ConnectInput", "Task pointer is NULL");
1203 if (!fTasks->FindObject(task)) {
1205 Info("ConnectInput", "Task %s was not registered. Now owned by analysis manager", task->GetName());
1207 Bool_t connected = task->ConnectInput(islot, cont);
1211 //______________________________________________________________________________
1212 Bool_t AliAnalysisManager::ConnectOutput(AliAnalysisTask *task, Int_t islot,
1213 AliAnalysisDataContainer *cont)
1215 // Connect output of an existing task to a data container.
1217 Error("ConnectOutput", "Task pointer is NULL");
1220 if (!fTasks->FindObject(task)) {
1222 Warning("ConnectOutput", "Task %s not registered. Now owned by analysis manager", task->GetName());
1224 Bool_t connected = task->ConnectOutput(islot, cont);
1228 //______________________________________________________________________________
1229 void AliAnalysisManager::CleanContainers()
1231 // Clean data from all containers that have already finished all client tasks.
1232 TIter next(fContainers);
1233 AliAnalysisDataContainer *cont;
1234 while ((cont=(AliAnalysisDataContainer *)next())) {
1235 if (cont->IsOwnedData() &&
1236 cont->IsDataReady() &&
1237 cont->ClientsExecuted()) cont->DeleteData();
1241 //______________________________________________________________________________
1242 Bool_t AliAnalysisManager::InitAnalysis()
1244 // Initialization of analysis chain of tasks. Should be called after all tasks
1245 // and data containers are properly connected
1246 // Reset flag and remove valid_outputs file if exists
1248 if (!gSystem->AccessPathName("outputs_valid"))
1249 gSystem->Unlink("outputs_valid");
1250 // Check for top tasks (depending only on input data containers)
1251 if (!fTasks->First()) {
1252 Error("InitAnalysis", "Analysis has no tasks !");
1256 AliAnalysisTask *task;
1257 AliAnalysisDataContainer *cont;
1260 Bool_t iszombie = kFALSE;
1261 Bool_t istop = kTRUE;
1263 while ((task=(AliAnalysisTask*)next())) {
1266 Int_t ninputs = task->GetNinputs();
1267 for (i=0; i<ninputs; i++) {
1268 cont = task->GetInputSlot(i)->GetContainer();
1272 fZombies->Add(task);
1276 Error("InitAnalysis", "Input slot %d of task %s has no container connected ! Declared zombie...",
1277 i, task->GetName());
1279 if (iszombie) continue;
1280 // Check if cont is an input container
1281 if (istop && !fInputs->FindObject(cont)) istop=kFALSE;
1282 // Connect to parent task
1286 fTopTasks->Add(task);
1290 Error("InitAnalysis", "No top task defined. At least one task should be connected only to input containers");
1293 // Check now if there are orphan tasks
1294 for (i=0; i<ntop; i++) {
1295 task = (AliAnalysisTask*)fTopTasks->At(i);
1300 while ((task=(AliAnalysisTask*)next())) {
1301 if (!task->IsUsed()) {
1303 Warning("InitAnalysis", "Task %s is orphan", task->GetName());
1306 // Check the task hierarchy (no parent task should depend on data provided
1307 // by a daughter task)
1308 for (i=0; i<ntop; i++) {
1309 task = (AliAnalysisTask*)fTopTasks->At(i);
1310 if (task->CheckCircularDeps()) {
1311 Error("InitAnalysis", "Found illegal circular dependencies between following tasks:");
1316 // Check that all containers feeding post-event loop tasks are in the outputs list
1317 TIter nextcont(fContainers); // loop over all containers
1318 while ((cont=(AliAnalysisDataContainer*)nextcont())) {
1319 if (!cont->IsPostEventLoop() && !fOutputs->FindObject(cont)) {
1320 if (cont->HasConsumers()) {
1321 // Check if one of the consumers is post event loop
1322 TIter nextconsumer(cont->GetConsumers());
1323 while ((task=(AliAnalysisTask*)nextconsumer())) {
1324 if (task->IsPostEventLoop()) {
1325 fOutputs->Add(cont);
1332 // Check if all special output containers have a file name provided
1333 TIter nextout(fOutputs);
1334 while ((cont=(AliAnalysisDataContainer*)nextout())) {
1335 if (cont->IsSpecialOutput() && !strlen(cont->GetFileName())) {
1336 Error("InitAnalysis", "Wrong container %s : a file name MUST be provided for special outputs", cont->GetName());
1344 //______________________________________________________________________________
1345 void AliAnalysisManager::PrintStatus(Option_t *option) const
1347 // Print task hierarchy.
1349 Info("PrintStatus", "Analysis manager %s not initialized : call InitAnalysis() first", GetName());
1352 Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
1354 Info("PrintStatus", "System information will be collected each %lld events", fNSysInfo);
1355 TIter next(fTopTasks);
1356 AliAnalysisTask *task;
1357 while ((task=(AliAnalysisTask*)next()))
1358 task->PrintTask(option);
1361 //______________________________________________________________________________
1362 void AliAnalysisManager::ResetAnalysis()
1364 // Reset all execution flags and clean containers.
1368 //______________________________________________________________________________
1369 Long64_t AliAnalysisManager::StartAnalysis(const char *type, Long64_t nentries, Long64_t firstentry)
1371 // Start analysis having a grid handler.
1372 if (!fGridHandler) {
1373 Error("StartAnalysis", "Cannot start analysis providing just the analysis type without a grid handler.");
1374 Info("===", "Add an AliAnalysisAlien object as plugin for this manager and configure it.");
1378 return StartAnalysis(type, tree, nentries, firstentry);
1381 //______________________________________________________________________________
1382 Long64_t AliAnalysisManager::StartAnalysis(const char *type, TTree * const tree, Long64_t nentries, Long64_t firstentry)
1384 // Start analysis for this manager. Analysis task can be: LOCAL, PROOF, GRID or
1385 // MIX. Process nentries starting from firstentry
1387 // Backup current directory and make sure gDirectory points to gROOT
1388 TDirectory *cdir = gDirectory;
1391 Error("StartAnalysis","Analysis manager was not initialized !");
1395 if (fDebug > 1) printf("StartAnalysis %s\n",GetName());
1397 TString anaType = type;
1399 fMode = kLocalAnalysis;
1400 Bool_t runlocalinit = kTRUE;
1401 if (anaType.Contains("file")) {
1402 runlocalinit = kFALSE;
1405 if (anaType.Contains("proof")) fMode = kProofAnalysis;
1406 else if (anaType.Contains("grid")) fMode = kGridAnalysis;
1407 else if (anaType.Contains("mix")) fMode = kMixingAnalysis;
1409 if (fMode == kGridAnalysis) {
1411 if (!anaType.Contains("terminate")) {
1412 if (!fGridHandler) {
1413 Error("StartAnalysis", "Cannot start grid analysis without a grid handler.");
1414 Info("===", "Add an AliAnalysisAlien object as plugin for this manager and configure it.");
1418 // Write analysis manager in the analysis file
1419 cout << "===== RUNNING GRID ANALYSIS: " << GetName() << endl;
1420 // run local task configuration
1421 TIter nextTask(fTasks);
1422 AliAnalysisTask *task;
1423 while ((task=(AliAnalysisTask*)nextTask())) {
1427 if (!fGridHandler->StartAnalysis(nentries, firstentry)) {
1428 Info("StartAnalysis", "Grid analysis was stopped and cannot be terminated");
1433 // Terminate grid analysis
1434 if (fSelector && fSelector->GetStatus() == -1) {cdir->cd(); return -1;}
1435 if (fGridHandler->GetRunMode() == AliAnalysisGrid::kOffline) {cdir->cd(); return 0;}
1436 cout << "===== MERGING OUTPUTS REGISTERED BY YOUR ANALYSIS JOB: " << GetName() << endl;
1437 if (!fGridHandler->MergeOutputs()) {
1438 // Return if outputs could not be merged or if it alien handler
1439 // was configured for offline mode or local testing.
1444 cout << "===== TERMINATING GRID ANALYSIS JOB: " << GetName() << endl;
1445 ImportWrappers(NULL);
1451 SetEventLoop(kFALSE);
1452 // Enable event loop mode if a tree was provided
1453 if (tree || fGridHandler || fMode==kMixingAnalysis) SetEventLoop(kTRUE);
1456 TString ttype = "TTree";
1457 if (tree && tree->IsA() == TChain::Class()) {
1458 chain = (TChain*)tree;
1459 if (!chain || !chain->GetListOfFiles()->First()) {
1460 Error("StartAnalysis", "Cannot process null or empty chain...");
1467 Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
1468 if (getsysInfo) AliSysInfo::AddStamp("Start", 0);
1469 // Initialize locally all tasks (happens for all modes)
1471 AliAnalysisTask *task;
1473 while ((task=(AliAnalysisTask*)next())) {
1477 if (getsysInfo) AliSysInfo::AddStamp("LocalInit_all", 0);
1481 case kLocalAnalysis:
1482 if (!tree && !fGridHandler) {
1483 TIter nextT(fTasks);
1484 // Call CreateOutputObjects for all tasks
1486 Bool_t dirStatus = TH1::AddDirectoryStatus();
1487 while ((task=(AliAnalysisTask*)nextT())) {
1488 TH1::AddDirectory(kFALSE);
1489 task->CreateOutputObjects();
1490 if (getsysInfo) AliSysInfo::AddStamp(Form("%s_CREATEOUTOBJ",task->ClassName()), 0, itask, 0);
1494 TH1::AddDirectory(dirStatus);
1495 if (IsExternalLoop()) {
1496 Info("StartAnalysis", "Initialization done. Event loop is controlled externally.\
1497 \nSetData for top container, call ExecAnalysis in a loop and then Terminate manually");
1504 fSelector = new AliAnalysisSelector(this);
1505 // Check if a plugin handler is used
1507 // Get the chain from the plugin
1508 TString dataType = "esdTree";
1509 if (fInputEventHandler) {
1510 dataType = fInputEventHandler->GetDataType();
1514 chain = fGridHandler->GetChainForTestMode(dataType);
1516 Error("StartAnalysis", "No chain for test mode. Aborting.");
1519 cout << "===== RUNNING LOCAL ANALYSIS" << GetName() << " ON CHAIN " << chain->GetName() << endl;
1520 retv = chain->Process(fSelector, "", nentries, firstentry);
1523 // Run tree-based analysis via AliAnalysisSelector
1524 cout << "===== RUNNING LOCAL ANALYSIS " << GetName() << " ON TREE " << tree->GetName() << endl;
1525 retv = tree->Process(fSelector, "", nentries, firstentry);
1527 case kProofAnalysis:
1529 // Check if the plugin is used
1531 return StartAnalysis(type, fGridHandler->GetProofDataSet(), nentries, firstentry);
1533 if (!gROOT->GetListOfProofs() || !gROOT->GetListOfProofs()->GetEntries()) {
1534 Error("StartAnalysis", "No PROOF!!! Exiting.");
1538 line = Form("gProof->AddInput((TObject*)0x%lx);", (ULong_t)this);
1539 gROOT->ProcessLine(line);
1542 cout << "===== RUNNING PROOF ANALYSIS " << GetName() << " ON CHAIN " << chain->GetName() << endl;
1543 retv = chain->Process("AliAnalysisSelector", "", nentries, firstentry);
1545 Error("StartAnalysis", "No chain!!! Exiting.");
1552 if (!anaType.Contains("terminate")) {
1553 if (!fGridHandler) {
1554 Error("StartAnalysis", "Cannot start grid analysis without a grid handler.");
1555 Info("===", "Add an AliAnalysisAlien object as plugin for this manager and configure it.");
1559 // Write analysis manager in the analysis file
1560 cout << "===== RUNNING GRID ANALYSIS: " << GetName() << endl;
1561 // Start the analysis via the handler
1562 if (!fGridHandler->StartAnalysis(nentries, firstentry)) {
1563 Info("StartAnalysis", "Grid analysis was stopped and cannot be terminated");
1568 // Terminate grid analysis
1569 if (fSelector && fSelector->GetStatus() == -1) {cdir->cd(); return -1;}
1570 if (fGridHandler->GetRunMode() == AliAnalysisGrid::kOffline) {cdir->cd(); return 0;}
1571 cout << "===== MERGING OUTPUTS REGISTERED BY YOUR ANALYSIS JOB: " << GetName() << endl;
1572 if (!fGridHandler->MergeOutputs()) {
1573 // Return if outputs could not be merged or if it alien handler
1574 // was configured for offline mode or local testing.
1579 cout << "===== TERMINATING GRID ANALYSIS JOB: " << GetName() << endl;
1580 ImportWrappers(NULL);
1584 case kMixingAnalysis:
1585 // Run event mixing analysis
1587 Error("StartAnalysis", "Cannot run event mixing without event pool");
1591 cout << "===== RUNNING EVENT MIXING ANALYSIS " << GetName() << endl;
1592 fSelector = new AliAnalysisSelector(this);
1593 while ((chain=fEventPool->GetNextChain())) {
1595 // Call NotifyBinChange for all tasks
1596 while ((task=(AliAnalysisTask*)next()))
1597 if (!task->IsPostEventLoop()) task->NotifyBinChange();
1598 retv = chain->Process(fSelector);
1600 Error("StartAnalysis", "Mixing analysis failed");
1605 PackOutput(fSelector->GetOutputList());
1612 //______________________________________________________________________________
1613 Long64_t AliAnalysisManager::StartAnalysis(const char *type, const char *dataset, Long64_t nentries, Long64_t firstentry)
1615 // Start analysis for this manager on a given dataset. Analysis task can be:
1616 // LOCAL, PROOF or GRID. Process nentries starting from firstentry.
1618 Error("StartAnalysis","Analysis manager was not initialized !");
1622 if (fDebug > 1) printf("StartAnalysis %s\n",GetName());
1623 TString anaType = type;
1625 if (!anaType.Contains("proof")) {
1626 Error("StartAnalysis", "Cannot process datasets in %s mode. Try PROOF.", type);
1629 fMode = kProofAnalysis;
1631 SetEventLoop(kTRUE);
1632 // Set the dataset flag
1633 TObject::SetBit(kUseDataSet);
1637 // Start proof analysis using the grid handler
1638 if (!fGridHandler->StartAnalysis(nentries, firstentry)) {
1639 Error("StartAnalysis", "The grid plugin could not start PROOF analysis");
1642 // Check if the plugin is in test mode
1643 if (fGridHandler->GetRunMode() == AliAnalysisGrid::kTest) {
1644 dataset = "test_collection";
1646 dataset = fGridHandler->GetProofDataSet();
1650 if (!gROOT->GetListOfProofs() || !gROOT->GetListOfProofs()->GetEntries()) {
1651 Error("StartAnalysis", "No PROOF!!! Exiting.");
1655 // Initialize locally all tasks
1657 AliAnalysisTask *task;
1658 while ((task=(AliAnalysisTask*)next())) {
1662 line = Form("gProof->AddInput((TObject*)0x%lx);", (ULong_t)this);
1663 gROOT->ProcessLine(line);
1666 // chain->SetProof();
1667 cout << "===== RUNNING PROOF ANALYSIS " << GetName() << " ON TEST CHAIN " << chain->GetName() << endl;
1668 retv = chain->Process("AliAnalysisSelector", "", nentries, firstentry);
1670 line = Form("gProof->Process(\"%s\", \"AliAnalysisSelector\", \"\", %lld, %lld);",
1671 dataset, nentries, firstentry);
1672 cout << "===== RUNNING PROOF ANALYSIS " << GetName() << " ON DATASET " << dataset << endl;
1673 retv = (Long_t)gROOT->ProcessLine(line);
1678 //______________________________________________________________________________
1679 TFile *AliAnalysisManager::OpenFile(AliAnalysisDataContainer *cont, const char *option, Bool_t ignoreProof)
1681 // Opens according the option the file specified by cont->GetFileName() and changes
1682 // current directory to cont->GetFolderName(). If the file was already opened, it
1683 // checks if the option UPDATE was preserved. File open via TProofOutputFile can
1684 // be optionally ignored.
1685 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
1686 TString filename = cont->GetFileName();
1688 if (filename.IsNull()) {
1689 ::Error("AliAnalysisManager::OpenFile", "No file name specified for container %s", cont->GetName());
1692 if (mgr->GetAnalysisType()==AliAnalysisManager::kProofAnalysis && cont->IsSpecialOutput()
1694 f = mgr->OpenProofFile(cont,option);
1696 // Check first if the file is already opened
1697 f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
1699 // Check if option "UPDATE" was preserved
1700 TString opt(option);
1702 if ((opt=="UPDATE") && (opt!=f->GetOption()))
1703 ::Info("AliAnalysisManager::OpenFile", "File %s already opened in %s mode!", cont->GetFileName(), f->GetOption());
1705 f = TFile::Open(filename, option);
1708 if (f && !f->IsZombie() && !f->TestBit(TFile::kRecovered)) {
1712 // Check for a folder request
1713 TString dir = cont->GetFolderName();
1714 if (!dir.IsNull()) {
1715 if (!f->GetDirectory(dir)) f->mkdir(dir);
1720 ::Fatal("AliAnalysisManager::OpenFile", "File %s could not be opened", filename.Data());
1721 cont->SetFile(NULL);
1725 //______________________________________________________________________________
1726 TFile *AliAnalysisManager::OpenProofFile(AliAnalysisDataContainer *cont, const char *option)
1728 // Opens a special output file used in PROOF.
1730 TString filename = cont->GetFileName();
1731 if (cont == fCommonOutput) {
1732 if (fOutputEventHandler) filename = fOutputEventHandler->GetOutputFileName();
1733 else Fatal("OpenProofFile","No output container. Exiting.");
1736 if (fMode!=kProofAnalysis || !fSelector) {
1737 Fatal("OpenProofFile","Cannot open PROOF file %s: no PROOF or selector",filename.Data());
1740 if (fSpecialOutputLocation.Length()) {
1741 f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
1743 // Check if option "UPDATE" was preserved
1744 TString opt(option);
1746 if ((opt=="UPDATE") && (opt!=f->GetOption()))
1747 ::Info("OpenProofFile", "File %s already opened in %s mode!", cont->GetFileName(), f->GetOption());
1749 f = new TFile(filename, option);
1751 if (f && !f->IsZombie() && !f->TestBit(TFile::kRecovered)) {
1755 // Check for a folder request
1756 TString dir = cont->GetFolderName();
1758 if (!f->GetDirectory(dir)) f->mkdir(dir);
1763 Fatal("OpenProofFile", "File %s could not be opened", cont->GetFileName());
1764 cont->SetFile(NULL);
1767 // Check if there is already a proof output file in the output list
1768 TObject *pof = fSelector->GetOutputList()->FindObject(filename);
1770 // Get the actual file
1771 line = Form("((TProofOutputFile*)0x%lx)->GetFileName();", (ULong_t)pof);
1772 filename = (const char*)gROOT->ProcessLine(line);
1774 printf("File: %s already booked via TProofOutputFile\n", filename.Data());
1776 f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
1778 Fatal("OpenProofFile", "Proof output file found but no file opened for %s", filename.Data());
1781 // Check if option "UPDATE" was preserved
1782 TString opt(option);
1784 if ((opt=="UPDATE") && (opt!=f->GetOption()))
1785 Fatal("OpenProofFile", "File %s already opened, but not in UPDATE mode!", cont->GetFileName());
1787 if (cont->IsRegisterDataset()) {
1788 TString dsetName = filename;
1789 dsetName.ReplaceAll(".root", cont->GetTitle());
1790 dsetName.ReplaceAll(":","_");
1791 if (fDebug>1) printf("Booking dataset: %s\n", dsetName.Data());
1792 line = Form("TProofOutputFile *pf = new TProofOutputFile(\"%s\", \"DROV\", \"%s\");", filename.Data(), dsetName.Data());
1794 if (fDebug>1) printf("Booking TProofOutputFile: %s to be merged\n", filename.Data());
1795 line = Form("TProofOutputFile *pf = new TProofOutputFile(\"%s\");", filename.Data());
1797 if (fDebug > 1) printf("=== %s\n", line.Data());
1798 gROOT->ProcessLine(line);
1799 line = Form("pf->OpenFile(\"%s\");", option);
1800 gROOT->ProcessLine(line);
1803 gROOT->ProcessLine("pf->Print()");
1804 printf(" == proof file name: %s", f->GetName());
1806 // Add to proof output list
1807 line = Form("((TList*)0x%lx)->Add(pf);",(ULong_t)fSelector->GetOutputList());
1808 if (fDebug > 1) printf("=== %s\n", line.Data());
1809 gROOT->ProcessLine(line);
1811 if (f && !f->IsZombie() && !f->TestBit(TFile::kRecovered)) {
1815 // Check for a folder request
1816 TString dir = cont->GetFolderName();
1817 if (!dir.IsNull()) {
1818 if (!f->GetDirectory(dir)) f->mkdir(dir);
1823 Fatal("OpenProofFile", "File %s could not be opened", cont->GetFileName());
1824 cont->SetFile(NULL);
1828 //______________________________________________________________________________
1829 void AliAnalysisManager::ExecAnalysis(Option_t *option)
1831 // Execute analysis.
1832 static Long64_t ncalls = 0;
1833 static Long64_t nentries = 0;
1834 static TTree *lastTree = 0;
1835 static TStopwatch *timer = new TStopwatch();
1836 if (fDebug > 0) printf("MGR: Processing event #%lld\n", ncalls);
1838 if (fTree && (fTree != lastTree)) {
1839 nentries += fTree->GetEntries();
1842 if (!ncalls) timer->Start();
1843 if (!fIsRemote && TObject::TestBit(kUseProgressBar)) ProgressBar("Processing event", ncalls, nentries, timer, kFALSE);
1846 TDirectory *cdir = gDirectory;
1847 Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
1848 if (getsysInfo && ((ncalls%fNSysInfo)==0)) AliSysInfo::AddStamp("Exec_start", (Int_t)ncalls);
1851 Error("ExecAnalysis", "Analysis manager was not initialized !");
1855 AliAnalysisTask *task;
1856 // Check if the top tree is active.
1858 if (getsysInfo && ((ncalls%fNSysInfo)==0))
1859 AliSysInfo::AddStamp("Handlers_BeginEventGroup",(Int_t)ncalls, 1002, 0);
1861 // De-activate all tasks
1862 while ((task=(AliAnalysisTask*)next())) task->SetActive(kFALSE);
1863 AliAnalysisDataContainer *cont = fCommonInput;
1864 if (!cont) cont = (AliAnalysisDataContainer*)fInputs->At(0);
1866 Error("ExecAnalysis","Cannot execute analysis in TSelector mode without at least one top container");
1870 cont->SetData(fTree); // This will notify all consumers
1871 Long64_t entry = fTree->GetTree()->GetReadEntry();
1873 // Call BeginEvent() for optional input/output and MC services
1874 if (fInputEventHandler) fInputEventHandler ->BeginEvent(entry);
1875 if (fOutputEventHandler) fOutputEventHandler ->BeginEvent(entry);
1876 if (fMCtruthEventHandler) fMCtruthEventHandler->BeginEvent(entry);
1878 if (getsysInfo && ((ncalls%fNSysInfo)==0))
1879 AliSysInfo::AddStamp("Handlers_BeginEvent",(Int_t)ncalls, 1000, 0);
1881 // Execute the tasks
1882 // TIter next1(cont->GetConsumers());
1883 TIter next1(fTopTasks);
1885 while ((task=(AliAnalysisTask*)next1())) {
1887 cout << " Executing task " << task->GetName() << endl;
1889 task->ExecuteTask(option);
1891 if (getsysInfo && ((ncalls%fNSysInfo)==0))
1892 AliSysInfo::AddStamp(task->ClassName(),(Int_t)ncalls, itask, 1);
1896 // Call FinishEvent() for optional output and MC services
1897 if (fInputEventHandler) fInputEventHandler ->FinishEvent();
1898 if (fOutputEventHandler) fOutputEventHandler ->FinishEvent();
1899 if (fMCtruthEventHandler) fMCtruthEventHandler->FinishEvent();
1900 // Gather system information if requested
1901 if (getsysInfo && ((ncalls%fNSysInfo)==0))
1902 AliSysInfo::AddStamp("Handlers_FinishEvent",(Int_t)ncalls, 1001, 1);
1906 // The event loop is not controlled by TSelector
1908 // Call BeginEvent() for optional input/output and MC services
1909 if (fInputEventHandler) fInputEventHandler ->BeginEvent(-1);
1910 if (fOutputEventHandler) fOutputEventHandler ->BeginEvent(-1);
1911 if (fMCtruthEventHandler) fMCtruthEventHandler->BeginEvent(-1);
1913 if (getsysInfo && ((ncalls%fNSysInfo)==0))
1914 AliSysInfo::AddStamp("Handlers_BeginEvent",(Int_t)ncalls, 1000, 0);
1915 TIter next2(fTopTasks);
1916 while ((task=(AliAnalysisTask*)next2())) {
1917 task->SetActive(kTRUE);
1919 cout << " Executing task " << task->GetName() << endl;
1921 task->ExecuteTask(option);
1925 // Call FinishEvent() for optional output and MC services
1926 if (fInputEventHandler) fInputEventHandler ->FinishEvent();
1927 if (fOutputEventHandler) fOutputEventHandler ->FinishEvent();
1928 if (fMCtruthEventHandler) fMCtruthEventHandler->FinishEvent();
1929 if (getsysInfo && ((ncalls%fNSysInfo)==0))
1930 AliSysInfo::AddStamp("Handlers_FinishEvent",(Int_t)ncalls, 1000, 1);
1934 //______________________________________________________________________________
1935 void AliAnalysisManager::SetInputEventHandler(AliVEventHandler* const handler)
1937 // Set the input event handler and create a container for it.
1938 fInputEventHandler = handler;
1939 fCommonInput = CreateContainer("cAUTO_INPUT", TChain::Class(), AliAnalysisManager::kInputContainer);
1940 // Warning("SetInputEventHandler", " An automatic input container for the input chain was created.\nPlease use: mgr->GetCommonInputContainer() to access it.");
1943 //______________________________________________________________________________
1944 void AliAnalysisManager::SetOutputEventHandler(AliVEventHandler* const handler)
1946 // Set the input event handler and create a container for it.
1947 fOutputEventHandler = handler;
1948 fCommonOutput = CreateContainer("cAUTO_OUTPUT", TTree::Class(), AliAnalysisManager::kOutputContainer, "default");
1949 fCommonOutput->SetSpecialOutput();
1950 // Warning("SetOutputEventHandler", " An automatic output container for the output tree was created.\nPlease use: mgr->GetCommonOutputContainer() to access it.");
1953 //______________________________________________________________________________
1954 void AliAnalysisManager::RegisterExtraFile(const char *fname)
1956 // This method is used externally to register output files which are not
1957 // connected to any output container, so that the manager can properly register,
1958 // retrieve or merge them when running in distributed mode. The file names are
1959 // separated by blancs. The method has to be called in MyAnalysisTask::LocalInit().
1960 if (fExtraFiles.Contains(fname)) return;
1961 if (fExtraFiles.Length()) fExtraFiles += " ";
1962 fExtraFiles += fname;
1965 //______________________________________________________________________________
1966 Bool_t AliAnalysisManager::GetFileFromWrapper(const char *filename, const TList *source)
1968 // Copy a file from the location specified ina the wrapper with the same name from the source list.
1971 TObject *pof = source->FindObject(filename);
1972 if (!pof || !pof->InheritsFrom("TProofOutputFile")) {
1973 Error("GetFileFromWrapper", "TProofOutputFile object not found in output list for file %s", filename);
1976 gROOT->ProcessLine(Form("sprintf((char*)0x%lx, \"%%s\", ((TProofOutputFile*)0x%lx)->GetOutputFileName();)", (ULong_t)fullPath, (ULong_t)pof));
1977 gROOT->ProcessLine(Form("sprintf((char*)0x%lx, \"%%s\", gProof->GetUrl();)", (ULong_t)chUrl));
1978 TString clientUrl(chUrl);
1979 TString fullPath_str(fullPath);
1980 if (clientUrl.Contains("localhost")){
1981 TObjArray* array = fullPath_str.Tokenize ( "//" );
1982 TObjString *strobj = ( TObjString *)array->At(1);
1983 TObjArray* arrayPort = strobj->GetString().Tokenize ( ":" );
1984 TObjString *strobjPort = ( TObjString *) arrayPort->At(1);
1985 fullPath_str.ReplaceAll(strobj->GetString().Data(),"localhost:PORT");
1986 fullPath_str.ReplaceAll(":PORT",Form(":%s",strobjPort->GetString().Data()));
1987 if (fDebug > 1) Info("GetFileFromWrapper","Using tunnel from %s to %s",fullPath_str.Data(),filename);
1992 Info("GetFileFromWrapper","Copying file %s from PROOF scratch space", fullPath_str.Data());
1993 Bool_t gotit = TFile::Cp(fullPath_str.Data(), filename);
1995 Error("GetFileFromWrapper", "Could not get file %s from proof scratch space", filename);
1999 //______________________________________________________________________________
2000 void AliAnalysisManager::GetAnalysisTypeString(TString &type) const
2002 // Fill analysis type in the provided string.
2004 case kLocalAnalysis:
2007 case kProofAnalysis:
2013 case kMixingAnalysis:
2018 //______________________________________________________________________________
2019 Bool_t AliAnalysisManager::ValidateOutputFiles() const
2021 // Validate all output files.
2022 TIter next(fOutputs);
2023 AliAnalysisDataContainer *output;
2024 TDirectory *cdir = gDirectory;
2025 TString openedFiles;
2026 while ((output=(AliAnalysisDataContainer*)next())) {
2027 if (output->IsRegisterDataset()) continue;
2028 TString filename = output->GetFileName();
2029 if (filename == "default") {
2030 if (!fOutputEventHandler) continue;
2031 filename = fOutputEventHandler->GetOutputFileName();
2032 // Main AOD may not be there
2033 if (gSystem->AccessPathName(filename)) continue;
2035 // Check if the file is closed
2036 if (openedFiles.Contains(filename)) continue;;
2037 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
2039 Warning("ValidateOutputs", "File %s was not closed. Closing.", filename.Data());
2040 // Clear file list to release object ownership to user.
2044 file = TFile::Open(filename);
2045 if (!file || file->IsZombie() || file->TestBit(TFile::kRecovered)) {
2046 Error("ValidateOutputs", "Output file <%s> was not created or invalid", filename.Data());
2051 openedFiles += filename;
2058 //______________________________________________________________________________
2059 void AliAnalysisManager::ProgressBar(const char *opname, Long64_t current, Long64_t size, TStopwatch * const watch, Bool_t last, Bool_t refresh)
2061 // Implements a nice text mode progress bar.
2062 static Long64_t icount = 0;
2063 static TString oname;
2064 static TString nname;
2065 static Long64_t ocurrent = 0;
2066 static Long64_t osize = 0;
2067 static Int_t oseconds = 0;
2068 static TStopwatch *owatch = 0;
2069 static Bool_t oneoftwo = kFALSE;
2070 static Int_t nrefresh = 0;
2071 static Int_t nchecks = 0;
2072 const char symbol[4] = {'=','\\','|','/'};
2073 char progress[11] = " ";
2074 Int_t ichar = icount%4;
2081 ocurrent = TMath::Abs(current);
2082 osize = TMath::Abs(size);
2083 if (ocurrent > osize) ocurrent=osize;
2093 if (owatch && !last) {
2095 time = owatch->RealTime();
2096 hours = (Int_t)(time/3600.);
2098 minutes = (Int_t)(time/60.);
2100 seconds = (Int_t)time;
2102 if (oseconds==seconds) {
2106 oneoftwo = !oneoftwo;
2110 if (refresh && oneoftwo) {
2112 if (nchecks <= 0) nchecks = nrefresh+1;
2113 Int_t pctdone = (Int_t)(100.*nrefresh/nchecks);
2114 oname = Form(" == %d%% ==", pctdone);
2116 Double_t percent = 100.0*ocurrent/osize;
2117 Int_t nchar = Int_t(percent/10);
2118 if (nchar>10) nchar=10;
2120 for (i=0; i<nchar; i++) progress[i] = '=';
2121 progress[nchar] = symbol[ichar];
2122 for (i=nchar+1; i<10; i++) progress[i] = ' ';
2123 progress[10] = '\0';
2126 if(size<10000) fprintf(stderr, "%s [%10s] %4lld ", oname.Data(), progress, ocurrent);
2127 else if(size<100000) fprintf(stderr, "%s [%10s] %5lld ",oname.Data(), progress, ocurrent);
2128 else fprintf(stderr, "%s [%10s] %7lld ",oname.Data(), progress, ocurrent);
2129 if (time>0.) fprintf(stderr, "[%6.2f %%] TIME %.2d:%.2d:%.2d \r", percent, hours, minutes, seconds);
2130 else fprintf(stderr, "[%6.2f %%]\r", percent);
2131 if (refresh && oneoftwo) oname = nname;
2132 if (owatch) owatch->Continue();
2141 fprintf(stderr, "\n");
2145 //______________________________________________________________________________
2146 void AliAnalysisManager::DoLoadBranch(const char *name)
2148 // Get tree and load branch if needed.
2153 TBranch *br = dynamic_cast<TBranch*>(fTable.FindObject(name));
2155 br = fTree->GetBranch(name);
2157 Error("DoLoadBranch", "Could not find branch %s",name);
2162 if (br->GetReadEntry()==GetCurrentEntry())
2164 br->GetEntry(GetCurrentEntry());