AliRoot Core  3dc7879 (3dc7879)
AliAnalysisManager.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 
16 #include "AliAnalysisManager.h"
17 
18 #include <cerrno>
19 #include <Compression.h>
20 #include <Riostream.h>
21 #include <TError.h>
22 #include <TMap.h>
23 #include <TClass.h>
24 #include <TFile.h>
25 #include <TFileCollection.h>
26 #include <TTreeCache.h>
27 #include <TEnv.h>
28 #include <TMath.h>
29 #include <TH1.h>
30 #include <TMethodCall.h>
31 #include <TChain.h>
32 #include <TSystem.h>
33 #include <TROOT.h>
34 #include <TCanvas.h>
35 #include <TStopwatch.h>
36 
37 #include "AliLog.h"
38 #include "AliAnalysisSelector.h"
39 #include "AliAnalysisGrid.h"
40 #include "AliAnalysisTask.h"
42 #include "AliAnalysisDataSlot.h"
43 #include "AliVEventHandler.h"
44 #include "AliVEventPool.h"
45 #include "AliSysInfo.h"
46 #include "AliAnalysisStatistics.h"
47 #include "AliVEvent.h"
48 
49 using std::ofstream;
50 using std::ios;
51 using std::cout;
52 using std::endl;
53 ClassImp(AliAnalysisManager)
54 
55 AliAnalysisManager *AliAnalysisManager::fgAnalysisManager = NULL;
56 TString AliAnalysisManager::fgCommonFileName = "";
57 TString AliAnalysisManager::fgMacroNames = "";
58 Int_t AliAnalysisManager::fPBUpdateFreq = 1;
59 
60 //______________________________________________________________________________
61 AliAnalysisManager::AliAnalysisManager(const char *name, const char *title)
62  :TNamed(name,title),
63  fTree(0),
64  fInputEventHandler(0),
65  fOutputEventHandler(0),
66  fMCtruthEventHandler(0),
67  fEventPool(0),
68  fCurrentEntry(-1),
69  fNSysInfo(0),
70  fMode(kLocalAnalysis),
71  fInitOK(kFALSE),
72  fMustClean(kFALSE),
73  fIsRemote(kFALSE),
74  fLocked(kFALSE),
75  fMCLoop(kFALSE),
76  fDebug(0),
77  fSpecialOutputLocation(""),
78  fTasks(0),
79  fTopTasks(0),
80  fZombies(0),
81  fContainers(0),
82  fInputs(0),
83  fOutputs(0),
84  fParamCont(0),
85  fExchangeCont(0),
86  fDebugOptions(0),
87  fFileDescriptors(new TObjArray()),
88  fCurrentDescriptor(0),
89  fCommonInput(0),
90  fCommonOutput(0),
91  fSelector(0),
92  fGridHandler(0),
93  fExtraFiles(),
94  fFileInfoLog(),
95  fAutoBranchHandling(kTRUE),
96  fAsyncReading(kFALSE), // default prefetching on
97  fTable(),
98  fRunFromPath(0),
99  fNcalls(0),
100  fMaxEntries(0),
101  fCacheSize(100000000), // default 100 MB
102  fStatisticsMsg(),
103  fRequestedBranches(),
104  fStatistics(0),
105  fGlobals(0),
106  fIOTimer(0),
107  fCPUTimer(0),
108  fInitTimer(0),
109  fIOTime(0),
110  fCPUTime(0),
111  fInitTime(0)
112 {
114 
115  fgAnalysisManager = this;
116  fgCommonFileName = "AnalysisResults.root";
117  if (TClass::IsCallingNew() != TClass::kDummyNew) {
118  fTasks = new TObjArray();
119  fTopTasks = new TObjArray();
120  fZombies = new TObjArray();
121  fContainers = new TObjArray();
122  fInputs = new TObjArray();
123  fOutputs = new TObjArray();
124  fParamCont = new TObjArray();
125  fExchangeCont = new TObjArray();
126  fGlobals = new TMap();
127  }
128  fIOTimer = new TStopwatch();
129  fCPUTimer = new TStopwatch();
130  fInitTimer = new TStopwatch();
131  SetEventLoop(kTRUE);
132 }
133 
134 //______________________________________________________________________________
136  :TNamed(other),
137  fTree(NULL),
138  fInputEventHandler(NULL),
139  fOutputEventHandler(NULL),
140  fMCtruthEventHandler(NULL),
141  fEventPool(NULL),
142  fCurrentEntry(-1),
143  fNSysInfo(0),
144  fMode(other.fMode),
145  fInitOK(other.fInitOK),
146  fMustClean(other.fMustClean),
147  fIsRemote(other.fIsRemote),
148  fLocked(other.fLocked),
149  fMCLoop(other.fMCLoop),
150  fDebug(other.fDebug),
151  fSpecialOutputLocation(""),
152  fTasks(NULL),
153  fTopTasks(NULL),
154  fZombies(NULL),
155  fContainers(NULL),
156  fInputs(NULL),
157  fOutputs(NULL),
158  fParamCont(NULL),
159  fExchangeCont(NULL),
160  fDebugOptions(NULL),
161  fFileDescriptors(new TObjArray()),
162  fCurrentDescriptor(0),
163  fCommonInput(NULL),
164  fCommonOutput(NULL),
165  fSelector(NULL),
166  fGridHandler(NULL),
167  fExtraFiles(other.fExtraFiles),
168  fFileInfoLog(other.fFileInfoLog),
169  fAutoBranchHandling(other.fAutoBranchHandling),
170  fAsyncReading(other.fAsyncReading),
171  fTable(),
172  fRunFromPath(0),
173  fNcalls(other.fNcalls),
174  fMaxEntries(other.fMaxEntries),
175  fCacheSize(other.fCacheSize),
176  fStatisticsMsg(other.fStatisticsMsg),
177  fRequestedBranches(other.fRequestedBranches),
178  fStatistics(other.fStatistics),
179  fGlobals(other.fGlobals),
180  fIOTimer(new TStopwatch()),
181  fCPUTimer(new TStopwatch()),
182  fInitTimer(new TStopwatch()),
183  fIOTime(0),
184  fCPUTime(0),
185  fInitTime(0)
186 {
188 
189  fTasks = new TObjArray(*other.fTasks);
190  fTopTasks = new TObjArray(*other.fTopTasks);
191  fZombies = new TObjArray(*other.fZombies);
192  fContainers = new TObjArray(*other.fContainers);
193  fInputs = new TObjArray(*other.fInputs);
194  fOutputs = new TObjArray(*other.fOutputs);
195  fParamCont = new TObjArray(*other.fParamCont);
196  fExchangeCont = new TObjArray(*other.fExchangeCont);
197  fgCommonFileName = "AnalysisResults.root";
198  fgAnalysisManager = this;
199 }
200 
201 //______________________________________________________________________________
203 {
205 
206  if (&other != this) {
207  TNamed::operator=(other);
211  fEventPool = other.fEventPool;
212  fTree = NULL;
213  fCurrentEntry = -1;
214  fNSysInfo = other.fNSysInfo;
215  fMode = other.fMode;
216  fInitOK = other.fInitOK;
217  fIsRemote = other.fIsRemote;
218  fLocked = other.fLocked;
219  fMCLoop = other.fMCLoop;
220  fDebug = other.fDebug;
221  fTasks = new TObjArray(*other.fTasks);
222  fTopTasks = new TObjArray(*other.fTopTasks);
223  fZombies = new TObjArray(*other.fZombies);
224  fContainers = new TObjArray(*other.fContainers);
225  fInputs = new TObjArray(*other.fInputs);
226  fOutputs = new TObjArray(*other.fOutputs);
227  fParamCont = new TObjArray(*other.fParamCont);
228  fExchangeCont = new TObjArray(*other.fExchangeCont);
229  fDebugOptions = NULL;
230  fFileDescriptors = new TObjArray();
231  fCurrentDescriptor = 0;
232  fCommonInput = NULL;
233  fCommonOutput = NULL;
234  fSelector = NULL;
235  fGridHandler = NULL;
236  fExtraFiles = other.fExtraFiles;
237  fFileInfoLog = other.fFileInfoLog;
238  fgCommonFileName = "AnalysisResults.root";
239  fgAnalysisManager = this;
242  fTable.Clear("nodelete");
243  fRunFromPath = other.fRunFromPath;
244  fNcalls = other. fNcalls;
245  fMaxEntries = other.fMaxEntries;
246  fCacheSize = other.fCacheSize;
249  fStatistics = other.fStatistics;
250  fGlobals = new TMap();
251  fIOTimer = new TStopwatch();
252  fCPUTimer = new TStopwatch();
253  fInitTimer = new TStopwatch();
254  fIOTime = 0.;
255  fCPUTime = 0.;
256  fInitTime = 0.;
257  }
258  return *this;
259 }
260 
261 //______________________________________________________________________________
263 {
265 
266  if (fTasks) {fTasks->Delete(); delete fTasks;}
267  delete fTopTasks;
268  delete fZombies;
269  if (fContainers) {fContainers->Delete(); delete fContainers;}
270  delete fInputs;
271  delete fOutputs;
272  delete fParamCont;
273  delete fExchangeCont;
274  delete fDebugOptions;
275  delete fGridHandler;
276  delete fInputEventHandler;
277  delete fOutputEventHandler;
278  delete fMCtruthEventHandler;
279  delete fEventPool;
280  if (fgAnalysisManager==this) fgAnalysisManager = NULL;
281  if (fGlobals) {fGlobals->DeleteAll(); delete fGlobals;}
282  if (fFileDescriptors) {fFileDescriptors->Delete(); delete fFileDescriptors;}
283  delete fIOTimer;
284  delete fCPUTimer;
285  delete fInitTimer;
286 }
287 
288 //______________________________________________________________________________
290 {
292 
293  if (!fTree || !fTree->GetCurrentFile()) {
294  Error("CreateReadCache","Current tree or tree file not yet defined");
295  return;
296  }
297  if (!fCacheSize) {
298  if (fDebug) Info("CreateReadCache","=== Read caching disabled ===");
299  return;
300  }
301  gEnv->SetValue("TFile.AsyncPrefetching",(Int_t)fAsyncReading);
302 // if (fAsyncReading) gEnv->SetValue("Cache.Directory",Form("file://%s/cache", gSystem->WorkingDirectory()));
303 // if (fAsyncReading) gEnv->SetValue("TFile.AsyncReading",1);
304  fTree->SetCacheSize(fCacheSize);
305  TTreeCache::SetLearnEntries(1); //<<< we can take the decision after 1 entry
306  if (!fAutoBranchHandling && !fRequestedBranches.IsNull()) {
307  TObjArray *arr = fRequestedBranches.Tokenize(",");
308  TIter next(arr);
309  TObject *obj;
310  while ((obj=next()))
311  fTree->AddBranchToCache(obj->GetName(),kTRUE); //<<< add requested branches to cache
312  delete arr;
313  } else {
314  fTree->AddBranchToCache("*", kTRUE); //<<< add all branches to cache
315  }
316  if (fDebug) {
317  Info("CreateReadCache","Read cache enabled %lld bytes with async reading=%d",fCacheSize, (Int_t)fAsyncReading);
318  }
319  return;
320 }
321 
322 //______________________________________________________________________________
323 Bool_t AliAnalysisManager::EventLoop(Long64_t nevents)
324 {
330 
331  cout << "===== RUNNING IN EVENT LOOP MODE: " << GetName() << endl;
332  if (!fInputEventHandler) {
333  Error("EventLoop", "No input handler: exiting");
334  return kFALSE;
335  }
336  TTree *tree = new TTree("DummyTree", "Dummy tree for AliAnalysisManager::EventLoop");
337  SetExternalLoop(kTRUE);
338  if (!Init(tree)) return kFALSE;
339  SlaveBegin(tree);
340  for (Long64_t iev=0; iev<nevents; iev++)
341  ExecAnalysis();
342  TList dummyList;
343  PackOutput(&dummyList);
344  fIsRemote = kTRUE;
345  Terminate();
346  return kTRUE;
347 }
348 
349 //______________________________________________________________________________
350 Int_t AliAnalysisManager::GetEntry(Long64_t entry, Int_t getall)
351 {
353 
354  fCurrentEntry = entry;
355  if (!fAutoBranchHandling)
356  return 123456789;
357  if (!fTree || !fTree->GetTree()) return -1;
358  fIOTimer->Start(kTRUE);
359  Long64_t readbytes = fTree->GetTree()->GetEntry(entry, getall);
360  fIOTimer->Stop();
361  fIOTime += fIOTimer->RealTime();
362  return (Int_t)readbytes;
363 }
364 
365 //______________________________________________________________________________
367 {
377 
378  Int_t run;
379  TString spath(path);
380  TString tok;
381  Ssiz_t from = 0;
382  Int_t expect = 0; // 0:alice, 1:data|sim, 2:LHC*, 3:num>18000, 4:ok!
383  Bool_t isData;
384 
385  while ( spath.Tokenize(tok, from, "/") ) {
386  //::Info("AliAnalysisManager::GetRunFromAlienPath", "Token: {%s}", tok.Data());
387 
388  switch (expect) {
389 
390  case 0:
391  if (tok == "alice") expect = 1;
392  break;
393 
394  case 1:
395  if (tok == "sim") {
396  expect = 2;
397  isData = kFALSE;
398  }
399  else if (tok == "data") {
400  expect = 2;
401  isData = kTRUE;
402  }
403  break;
404 
405  case 2:
406  if (tok.BeginsWith("LHC")) expect = 3;
407  break;
408 
409  case 3:
410  run = tok.Atoi();
411  if (run >= 18000) expect = 4;
412  break;
413  }
414 
415  if (expect == 4) break;
416  }
417 
418  if (expect == 4) {
419  const char *type;
420  if (isData) type = "real";
421  else type = "simulated";
422  ::Info("AliAnalysisManager::GetRunFromAlienPath", "Run %d of %s data", run, type);
423  }
424  else {
425  ::Error("AliAnalysisManager::GetRunFromAlienPath", "Invalid AliEn path string");
426  run = -9999;
427  }
428 
429  return run;
430 }
431 
432 //______________________________________________________________________________
434 {
440 
441  Bool_t init = kFALSE;
442  if (!tree) return kFALSE; // Should not happen - protected in selector caller
443  if (fDebug > 1) {
444  printf("->AliAnalysisManager::Init(%s)\n", tree->GetName());
445  }
446  // Call InitTree of EventHandler
447  if (fOutputEventHandler) {
448  if (fMode == kProofAnalysis) {
449  init = fOutputEventHandler->Init(0x0, "proof");
450  } else {
451  init = fOutputEventHandler->Init(0x0, "local");
452  }
453  if (!init) {
454  Error("Init", "Output event handler failed to initialize");
455  return kFALSE;
456  }
457  }
458 
459  if (fInputEventHandler) {
460  if (fMode == kProofAnalysis) {
461  init = fInputEventHandler->Init(tree, "proof");
462  } else {
463  init = fInputEventHandler->Init(tree, "local");
464  }
465  if (!init) {
466  Error("Init", "Input event handler failed to initialize tree");
467  return kFALSE;
468  }
469  } else {
470  // If no input event handler we need to get the tree once
471  // for the chain
472  if(!tree->GetTree()) {
473  Long64_t readEntry = tree->LoadTree(0);
474  if (readEntry == -2) {
475  Error("Init", "Input tree has no entry. Exiting");
476  return kFALSE;
477  }
478  }
479  }
480 
481  if (fMCtruthEventHandler) {
482  if (fMode == kProofAnalysis) {
483  init = fMCtruthEventHandler->Init(0x0, "proof");
484  } else {
485  init = fMCtruthEventHandler->Init(0x0, "local");
486  }
487  if (!init) {
488  Error("Init", "MC event handler failed to initialize");
489  return kFALSE;
490  }
491  }
492 
493  if (!fInitOK) InitAnalysis();
494  if (!fInitOK) return kFALSE;
495  fTree = tree;
497  else {
498  // cholm - here we should re-add to the table or branches
499  fTable.Clear();
500  }
502  if (!top) top = (AliAnalysisDataContainer*)fInputs->At(0);
503  if (!top) {
504  Error("Init","No top input container !");
505  return kFALSE;
506  }
507  top->SetData(tree);
508  CheckBranches(kFALSE);
509  fTable.Rehash(100);
510  if (fDebug > 1) {
511  printf("<-AliAnalysisManager::Init(%s)\n", tree->GetName());
512  }
513  return kTRUE;
514 }
515 
516 //______________________________________________________________________________
518 {
522 
523  if (fDebug > 1) printf("->AliAnalysisManager::SlaveBegin()\n");
524  // Init timer should be already started
525  // Apply debug options
527  if (fCacheSize &&
530  if (!CheckTasks()) Fatal("SlaveBegin", "Not all needed libraries were loaded");
531  static Bool_t isCalled = kFALSE;
532  Bool_t init = kFALSE;
533  Bool_t initOK = kTRUE;
534  TString msg;
535  TDirectory *curdir = gDirectory;
536  // Call SlaveBegin only once in case of mixing
537  if (isCalled && fMode==kMixingAnalysis) return;
538  gROOT->cd();
539  // Call Init of EventHandler
540  if (fOutputEventHandler) {
541  if (fMode == kProofAnalysis) {
542  // Merging AOD's in PROOF via TProofOutputFile
543  if (fDebug > 1) printf(" Initializing AOD output file %s...\n", fOutputEventHandler->GetOutputFileName());
544  init = fOutputEventHandler->Init("proof");
545  if (!init) msg = "Failed to initialize output handler on worker";
546  } else {
547  init = fOutputEventHandler->Init("local");
548  if (!init) msg = "Failed to initialize output handler";
549  }
550  initOK &= init;
551  if (!fSelector) Error("SlaveBegin", "Selector not set");
552  else if (!init) {fSelector->Abort(msg); fSelector->SetStatus(-1);}
553  }
554  gROOT->cd();
555  if (fInputEventHandler) {
557  if (fMode == kProofAnalysis) {
558  init = fInputEventHandler->Init("proof");
559  if (!init) msg = "Failed to initialize input handler on worker";
560  } else {
561  init = fInputEventHandler->Init("local");
562  if (!init) msg = "Failed to initialize input handler";
563  }
564  initOK &= init;
565  if (!fSelector) Error("SlaveBegin", "Selector not set");
566  else if (!init) {fSelector->Abort(msg); fSelector->SetStatus(-1);}
567  }
568  gROOT->cd();
569  if (fMCtruthEventHandler) {
570  if (fMode == kProofAnalysis) {
571  init = fMCtruthEventHandler->Init("proof");
572  if (!init) msg = "Failed to initialize MC handler on worker";
573  } else {
574  init = fMCtruthEventHandler->Init("local");
575  if (!init) msg = "Failed to initialize MC handler";
576  }
577  initOK &= init;
578  if (!fSelector) Error("SlaveBegin", "Selector not set");
579  else if (!init) {fSelector->Abort(msg); fSelector->SetStatus(-1);}
580  }
581  if (curdir) curdir->cd();
582  isCalled = kTRUE;
583  if (!initOK) return;
584  TIter next(fTasks);
585  AliAnalysisTask *task;
586  // Call CreateOutputObjects for all tasks
587  Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
588  if (getsysInfo) AliSysInfo::SetVerbose(kTRUE);
589  Bool_t dirStatus = TH1::AddDirectoryStatus();
590  Int_t itask = 0;
591  while ((task=(AliAnalysisTask*)next())) {
592  gROOT->cd();
593  // Start with memory as current dir and make sure by default histograms do not get attached to files.
594  TH1::AddDirectory(kFALSE);
595  task->CreateOutputObjects();
596  if (!task->CheckPostData()) {
597  Error("SlaveBegin","####### IMPORTANT! ####### \n\n\n\
598  Task %s (%s) did not call PostData() for all its outputs in (User)CreateOutputObjects()\n\n\
599  ####### FIX YOUR CODE, THIS WILL PRODUCE A FATAL ERROR IN FUTURE! ##########", task->GetName(), task->ClassName());
600  }
601  if (getsysInfo) AliSysInfo::AddStamp(Form("%s_CREATEOUTOBJ",task->ClassName()), 0, itask, 0);
602  itask++;
603  }
604  TH1::AddDirectory(dirStatus);
605  if (curdir) curdir->cd();
606  fInitTimer->Stop();
607  fInitTime += fInitTimer->RealTime();
608  fInitTimer->Continue();
609  printf("Initialization time: %g [sec]\n", fInitTime);
610  if (fDebug > 1) printf("<-AliAnalysisManager::SlaveBegin()\n");
611 }
612 
613 //______________________________________________________________________________
615 {
621 
622  fIOTimer->Start(kTRUE);
623  if (!fTree) return kFALSE;
624  if (!TObject::TestBit(AliAnalysisManager::kTrueNotify)) return kFALSE;
625 
626  fTable.Clear("nodelete"); // clearing the hash table may not be needed -> C.L.
627  if (fMode == kProofAnalysis) fIsRemote = kTRUE;
628 
629  TFile *curfile = fTree->GetCurrentFile();
630  if (!curfile) {
631  Error("Notify","No current file");
632  return kFALSE;
633  }
634  if (IsCollectThroughput()) {
638  }
639 
640  if (fDebug > 1) printf("->AliAnalysisManager::Notify() file: %s\n", curfile->GetName());
641  Int_t run = AliAnalysisManager::GetRunFromAlienPath(curfile->GetName());
642  if (run && (run != fRunFromPath)) {
643  fRunFromPath = run;
644  if (fDebug > 1) printf(" ### run found from path: %d\n", run);
645  }
646  TIter next(fTasks);
647  AliAnalysisTask *task;
648 
649  // Call Notify of the event handlers
650  if (fInputEventHandler) {
651  fInputEventHandler->Notify(curfile->GetName());
652  }
653 
654  if (fOutputEventHandler) {
655  fOutputEventHandler->Notify(curfile->GetName());
656  }
657 
658  if (fMCtruthEventHandler) {
659  fMCtruthEventHandler->Notify(curfile->GetName());
660  }
661 
662  // Call Notify for all tasks
663  while ((task=(AliAnalysisTask*)next()))
664  task->Notify();
665 
666  if (fDebug > 1) printf("<-AliAnalysisManager::Notify()\n");
667  fIOTimer->Stop();
668  fIOTime += fIOTimer->RealTime();
669  return kTRUE;
670 }
671 
672 //______________________________________________________________________________
674 {
686 
687  // WARNING when a selector is used with a TChain, you must use
688  // the pointer to the current TTree to call GetEntry(entry).
689  // The entry is always the local entry number in the current tree.
690  // Assuming that fChain is the pointer to the TChain being processed,
691  // use fChain->GetTree()->GetEntry(entry).
692 
693  // This method is obsolete. ExecAnalysis is called instead.
694  return kTRUE;
695 }
696 
697 //______________________________________________________________________________
699 {
702 
703  if (fDebug > 1) printf("->AliAnalysisManager::PackOutput()\n");
704  fIOTimer->Start(kTRUE);
705  std::ofstream out;
706  if (IsCollectThroughput()) {
708  fFileDescriptors->Print();
709  if (fFileInfoLog.IsNull()) fFileInfoLog = "fileinfo.log";
710  out.open(fFileInfoLog, std::ios::app);
711  if (out.bad()) Error("SavePrimitive", "Bad file name: %s", fFileInfoLog.Data());
712  else {
713  TIter nextflog(fFileDescriptors);
714  TObject *log;
715  while ((log=nextflog())) log->SavePrimitive(out,"");
716  }
717  }
718  if (!target) {
719  Error("PackOutput", "No target. Exiting.");
720  return;
721  }
722  TDirectory *cdir = gDirectory;
723  gROOT->cd();
727  gROOT->cd();
728 
729  // Call FinishTaskOutput() for each event loop task (not called for
730  // post-event loop tasks - use Terminate() fo those)
731  TIter nexttask(fTasks);
732  AliAnalysisTask *task;
733  while ((task=(AliAnalysisTask*)nexttask())) {
734  if (!task->IsPostEventLoop()) {
735  if (fDebug > 1) printf("->FinishTaskOutput: task %s\n", task->GetName());
736  task->FinishTaskOutput();
737  gROOT->cd();
738  if (fDebug > 1) printf("<-FinishTaskOutput: task %s\n", task->GetName());
739  }
740  }
741  // Write statistics message on the workers.
743 
744  if (fMode == kProofAnalysis) {
745  TIter next(fOutputs);
746  AliAnalysisDataContainer *output;
747  Bool_t isManagedByHandler = kFALSE;
748  TList filestmp;
749  filestmp.SetOwner();
750  while ((output=(AliAnalysisDataContainer*)next())) {
751  // Do not consider outputs of post event loop tasks
752  isManagedByHandler = kFALSE;
753  if (output->GetProducer() && output->GetProducer()->IsPostEventLoop()) continue;
754  const char *filename = output->GetFileName();
755  if (!(strcmp(filename, "default")) && fOutputEventHandler) {
756  isManagedByHandler = kTRUE;
757  printf("#### Handler output. Extra: %s\n", fExtraFiles.Data());
759  }
760  // Check if data was posted to this container. If not, issue an error.
761  if (!output->GetData() && !isManagedByHandler) {
762  Error("PackOutput", "No data for output container %s. Forgot to PostData ?", output->GetName());
763  continue;
764  }
765  if (!output->IsSpecialOutput()) {
766  // Normal outputs
767  if (strlen(filename) && !isManagedByHandler) {
768  // Backup current folder
769  TDirectory *opwd = gDirectory;
770  // File resident outputs.
771  // Check first if the file exists.
772  TString openoption = "RECREATE";
773  Bool_t firsttime = kTRUE;
774  if (filestmp.FindObject(output->GetFileName())) {
775  firsttime = kFALSE;
776  } else {
777  filestmp.Add(new TNamed(output->GetFileName(),""));
778  }
779  if (!gSystem->AccessPathName(output->GetFileName()) && !firsttime) openoption = "UPDATE";
780 // TFile *file = AliAnalysisManager::OpenFile(output, openoption, kTRUE);
781  // Save data to file, then close.
782  if (output->GetData()->InheritsFrom(TCollection::Class())) {
783  // If data is a collection, we set the name of the collection
784  // as the one of the container and we save as a single key.
785  TCollection *coll = (TCollection*)output->GetData();
786  coll->SetName(output->GetName());
787 // coll->Write(output->GetName(), TObject::kSingleKey);
788  } else {
789  if (output->GetData()->InheritsFrom(TTree::Class())) {
790  TFile *file = AliAnalysisManager::OpenFile(output, openoption, kTRUE);
791  // Save data to file, then close.
792  TTree *tree = (TTree*)output->GetData();
793  // Check if tree is in memory
794  if (tree->GetDirectory()==gROOT) tree->SetDirectory(gDirectory);
795  tree->AutoSave();
796  file->Close();
797  } else {
798 // output->GetData()->Write();
799  }
800  }
801  if (fDebug > 1) printf("PackOutput %s: memory merge, file resident output\n", output->GetName());
802 // if (fDebug > 2) {
803 // printf(" file %s listing content:\n", filename);
804 // file->ls();
805 // }
806  // Clear file list to release object ownership to user.
807 // file->Clear();
808 // file->Close();
809  output->SetFile(NULL);
810  // Restore current directory
811  if (opwd) opwd->cd();
812  } else {
813  // Memory-resident outputs
814  if (fDebug > 1) printf("PackOutput %s: memory merge memory resident output\n", filename);
815  }
816  AliAnalysisDataWrapper *wrap = 0;
817  if (isManagedByHandler) {
819  wrap->SetName(output->GetName());
820  }
821  else wrap =output->ExportData();
822  // Output wrappers must NOT delete data after merging - the user owns them
823  wrap->SetDeleteData(kFALSE);
824  target->Add(wrap);
825  } else {
826  // Special outputs. The file must be opened and connected to the container.
827  TDirectory *opwd = gDirectory;
828  TFile *file = output->GetFile();
829  if (!file) {
830  AliAnalysisTask *producer = output->GetProducer();
831  Fatal("PackOutput",
832  "File %s for special container %s was NOT opened in %s::CreateOutputObjects !!!",
833  output->GetFileName(), output->GetName(), producer->ClassName());
834  continue;
835  }
836  TString outFilename = file->GetName();
837  if (fDebug > 1) printf("PackOutput %s: special output\n", output->GetName());
838  if (isManagedByHandler) {
839  // Terminate IO for files managed by the output handler
840  // file->Write() moved to AOD handler (A.G. 11.01.10)
841 // if (file) file->Write();
842  if (file && fDebug > 2) {
843  printf(" handled file %s listing content:\n", file->GetName());
844  file->ls();
845  }
847  } else {
848  file->cd();
849  // Release object ownership to users after writing data to file
850  if (output->GetData()->InheritsFrom(TCollection::Class())) {
851  // If data is a collection, we set the name of the collection
852  // as the one of the container and we save as a single key.
853  TCollection *coll = (TCollection*)output->GetData();
854  coll->SetName(output->GetName());
855  coll->Write(output->GetName(), TObject::kSingleKey);
856  } else {
857  if (output->GetData()->InheritsFrom(TTree::Class())) {
858  TTree *tree = (TTree*)output->GetData();
859  tree->SetDirectory(file);
860  tree->AutoSave();
861  } else {
862  output->GetData()->Write();
863  }
864  }
865  if (fDebug > 2) {
866  printf(" file %s listing content:\n", output->GetFileName());
867  file->ls();
868  }
869  // Clear file list to release object ownership to user.
870 // file->Clear();
871  file->Close();
872  output->SetFile(NULL);
873  }
874  // Restore current directory
875  if (opwd) opwd->cd();
876  // Check if a special output location was provided or the output files have to be merged
877  if (strlen(fSpecialOutputLocation.Data())) {
878  TString remote = fSpecialOutputLocation;
879  remote += "/";
880  Int_t gid = gROOT->ProcessLine("gProofServ->GetGroupId();");
881  if (remote.BeginsWith("alien:")) {
882  gROOT->ProcessLine("TGrid::Connect(\"alien:\", gProofServ->GetUser());");
883  remote += outFilename;
884  remote.ReplaceAll(".root", Form("_%d.root", gid));
885  } else {
886  remote += Form("%s_%d_", gSystem->HostName(), gid);
887  remote += outFilename;
888  }
889  if (fDebug > 1)
890  Info("PackOutput", "Output file for container %s to be copied \n at: %s. No merging.",
891  output->GetName(), remote.Data());
892  TFile::Cp ( outFilename.Data(), remote.Data() );
893  // Copy extra outputs
894  if (fExtraFiles.Length() && isManagedByHandler) {
895  TObjArray *arr = fExtraFiles.Tokenize(" ");
896  TObjString *os;
897  TIter nextfilename(arr);
898  while ((os=(TObjString*)nextfilename())) {
899  outFilename = os->GetString();
900  remote = fSpecialOutputLocation;
901  remote += "/";
902  if (remote.BeginsWith("alien://")) {
903  remote += outFilename;
904  remote.ReplaceAll(".root", Form("_%d.root", gid));
905  } else {
906  remote += Form("%s_%d_", gSystem->HostName(), gid);
907  remote += outFilename;
908  }
909  if (fDebug > 1)
910  Info("PackOutput", "Extra AOD file %s to be copied \n at: %s. No merging.",
911  outFilename.Data(), remote.Data());
912  TFile::Cp ( outFilename.Data(), remote.Data() );
913  }
914  delete arr;
915  }
916  } else {
917  // No special location specified-> use TProofOutputFile as merging utility
918  // The file at this output slot must be opened in CreateOutputObjects
919  if (fDebug > 1) printf(" File for container %s to be merged via file merger...\n", output->GetName());
920  }
921  }
922  }
923  }
924  fIOTime += fIOTimer->RealTime();
925  if ((fDebug || IsCollectThroughput())) {
926  fInitTimer->Stop();
927  fInitTime = fInitTimer->RealTime()-fIOTime-fCPUTime;
928  printf("=Analysis %s= init time: %g[sec]\
929  \n I/O & data mng.: %g [sec]\
930  \n task execution: %g [sec]\
931  \n total time: CPU=%g [sec] REAL=%g[sec]\n",
932  GetName(), fInitTime, fIOTime, fCPUTime, fInitTimer->CpuTime(), fInitTimer->RealTime());
933  if (IsCollectThroughput()) {
934  out << "#summary#########################################################" << endl;
935  out << "train_name " << GetName() << endl;
936  out << "root_time " << fInitTimer->RealTime() << endl;
937  out << "root_cpu " << fInitTimer->CpuTime() << endl;
938  out << "init_time " << fInitTime << endl;
939  out << "io_mng_time " << fIOTime << endl;
940  out << "exec_time " << fCPUTime << endl;
941  TString aliensite = gSystem->Getenv("ALIEN_SITE");
942  out << "alien_site " << aliensite << endl;
943  out << "host_name ";
944  TString hostname = gSystem->Getenv("ALIEN_HOSTNAME");
945  if (hostname.IsNull()) {
946  out.close();
947  gSystem->Exec(Form("hostname -f >> %s", fFileInfoLog.Data()));
948  } else {
949  out << hostname << endl;
950  }
951  }
952  }
953 
954  if (cdir) cdir->cd();
955  if (fDebug > 1) printf("<-AliAnalysisManager::PackOutput: output list contains %d containers\n", target->GetSize());
956 }
957 
958 //______________________________________________________________________________
960 {
962 
963  if (fDebug > 1) printf("->AliAnalysisManager::ImportWrappers()\n");
964  fIOTimer->Start(kTRUE);
965  TIter next(fOutputs);
968  Int_t icont = 0;
969  Bool_t inGrid = (fMode == kGridAnalysis)?kTRUE:kFALSE;
970  TDirectory *cdir = gDirectory;
971  while ((cont=(AliAnalysisDataContainer*)next())) {
972  wrap = 0;
973  if (cont->GetProducer() && cont->GetProducer()->IsPostEventLoop() && !inGrid) continue;
974  if (cont->IsRegisterDataset()) continue;
975  const char *filename = cont->GetFileName();
976  Bool_t isManagedByHandler = kFALSE;
977  if (!(strcmp(filename, "default")) && fOutputEventHandler) {
978  isManagedByHandler = kTRUE;
980  }
981  if (cont->IsSpecialOutput() || inGrid) {
982  if (strlen(fSpecialOutputLocation.Data())) continue;
983  // Copy merged file from PROOF scratch space.
984  // In case of grid the files are already in the current directory.
985  if (!inGrid) {
986  if (isManagedByHandler && fExtraFiles.Length()) {
987  // Copy extra registered dAOD files.
988  TObjArray *arr = fExtraFiles.Tokenize(" ");
989  TObjString *os;
990  TIter nextfilename(arr);
991  while ((os=(TObjString*)nextfilename())) GetFileFromWrapper(os->GetString(), source);
992  delete arr;
993  }
994  if (!GetFileFromWrapper(filename, source)) continue;
995  }
996  // Normally we should connect data from the copied file to the
997  // corresponding output container, but it is not obvious how to do this
998  // automatically if several objects in file...
999  TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
1000  if (!f) f = TFile::Open(filename, "READ");
1001  if (!f) {
1002  Error("ImportWrappers", "Cannot open file %s in read-only mode", filename);
1003  continue;
1004  }
1005  f->cd();
1006  TObject *obj = 0;
1007  // Cd to the directory pointed by the container
1008  TString folder = cont->GetFolderName();
1009  if (!folder.IsNull()) f->cd(folder);
1010  // Try to fetch first an object having the container name.
1011  obj = gDirectory->Get(cont->GetName());
1012  if (!obj) {
1013  Warning("ImportWrappers", "Could not import object of type:%s for container %s in file %s:%s.\n Object will not be available in Terminate(). Try if possible to name the output object as the container (%s) or to embed it in a TList",
1014  cont->GetType()->GetName(), cont->GetName(), filename, cont->GetFolderName(), cont->GetName());
1015  continue;
1016  }
1017  wrap = new AliAnalysisDataWrapper(obj);
1018  wrap->SetDeleteData(kFALSE);
1019  }
1020  if (!wrap) wrap = (AliAnalysisDataWrapper*)source->FindObject(cont->GetName());
1021  if (!wrap) {
1022  Error("ImportWrappers","Container %s not found in analysis output !", cont->GetName());
1023  continue;
1024  }
1025  icont++;
1026  if (fDebug > 1) {
1027  printf(" Importing data for container %s\n", cont->GetName());
1028  if (strlen(filename)) printf(" -> file %s\n", filename);
1029  else printf("\n");
1030  }
1031  cont->ImportData(wrap);
1032  }
1033  if (cdir) cdir->cd();
1034  fIOTimer->Stop();
1035  fIOTime += fIOTimer->RealTime();
1036  if (fDebug > 1) printf("<-AliAnalysisManager::ImportWrappers(): %d containers imported\n", icont);
1037 }
1038 
1039 //______________________________________________________________________________
1041 {
1043 
1044  fIOTimer->Start(kTRUE);
1045  if (fDebug > 1) printf("->AliAnalysisManager::UnpackOutput()\n");
1046  if (!source) {
1047  Error("UnpackOutput", "No target. Exiting.");
1048  return;
1049  }
1050  if (fDebug > 1) printf(" Source list contains %d containers\n", source->GetSize());
1051 
1052  if (fMode == kProofAnalysis) ImportWrappers(source);
1053 
1054  TIter next(fOutputs);
1055  AliAnalysisDataContainer *output;
1056  while ((output=(AliAnalysisDataContainer*)next())) {
1057  if (!output->GetData()) continue;
1058  // Check if there are client tasks that run post event loop
1059  if (output->HasConsumers()) {
1060  // Disable event loop semaphore
1061  output->SetPostEventLoop(kTRUE);
1062  TObjArray *list = output->GetConsumers();
1063  Int_t ncons = list->GetEntriesFast();
1064  for (Int_t i=0; i<ncons; i++) {
1065  AliAnalysisTask *task = (AliAnalysisTask*)list->At(i);
1066  task->CheckNotify(kTRUE);
1067  // If task is active, execute it
1068  if (task->IsPostEventLoop() && task->IsActive()) {
1069  if (fDebug > 1) printf("== Executing post event loop task %s\n", task->GetName());
1070  if (fStatistics) fStatistics->StartTimer(GetTaskIndex(task), task->GetName(), task->ClassName());
1071  task->ExecuteTask();
1072  }
1073  }
1075  }
1076  }
1077  fIOTimer->Stop();
1078  fIOTime += fIOTimer->RealTime();
1079  if (fDebug > 1) printf("<-AliAnalysisManager::UnpackOutput()\n");
1080 }
1081 
1082 //______________________________________________________________________________
1084 {
1088 
1089  if (fDebug > 1) printf("->AliAnalysisManager::Terminate()\n");
1090  fInitTimer->Start(kTRUE);
1091  TDirectory *cdir = gDirectory;
1092  gROOT->cd();
1093  AliAnalysisTask *task;
1094  AliAnalysisDataContainer *output;
1095  TIter next(fTasks);
1096  TStopwatch timer;
1097  Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
1098  if (getsysInfo) AliSysInfo::SetVerbose(kTRUE);
1099  // Call Terminate() for tasks
1100  Int_t itask = 0;
1101  while (!IsSkipTerminate() && (task=(AliAnalysisTask*)next())) {
1102  // Save all the canvases produced by the Terminate
1103  TString pictname = Form("%s_%s", task->GetName(), task->ClassName());
1104  task->Terminate();
1105  gROOT->cd();
1106  if (getsysInfo)
1107  AliSysInfo::AddStamp(Form("%s_TERMINATE",task->ClassName()),0, itask, 2);
1108  itask++;
1109  if (TObject::TestBit(kSaveCanvases)) {
1110  if (!gROOT->IsBatch()) {
1111  if (fDebug>1) printf("Waiting 5 sec for %s::Terminate() to finish drawing ...\n", task->ClassName());
1112  timer.Start(kTRUE);
1113  while (timer.RealTime()<5) {
1114  timer.Continue();
1115  gSystem->ProcessEvents();
1116  }
1117  }
1118  Int_t iend = gROOT->GetListOfCanvases()->GetEntries();
1119  if (iend==0) continue;
1120  TCanvas *canvas;
1121  for (Int_t ipict=0; ipict<iend; ipict++) {
1122  canvas = (TCanvas*)gROOT->GetListOfCanvases()->At(ipict);
1123  if (!canvas) continue;
1124  canvas->SaveAs(Form("%s_%02d.gif", pictname.Data(),ipict));
1125  }
1126  gROOT->GetListOfCanvases()->Delete();
1127  }
1128  }
1129  //
1133  gROOT->cd();
1134  TObjArray *allOutputs = new TObjArray();
1135  Int_t icont;
1136  for (icont=0; icont<fOutputs->GetEntriesFast(); icont++) allOutputs->Add(fOutputs->At(icont));
1137  if (!IsSkipTerminate())
1138  for (icont=0; icont<fParamCont->GetEntriesFast(); icont++) allOutputs->Add(fParamCont->At(icont));
1139  TIter next1(allOutputs);
1140  TString handlerFile = "";
1141  TString extraOutputs = "";
1142  if (fOutputEventHandler) {
1143  handlerFile = fOutputEventHandler->GetOutputFileName();
1144  extraOutputs = fOutputEventHandler->GetExtraOutputs();
1145  }
1146  icont = 0;
1147  TList filestmp;
1148  while ((output=(AliAnalysisDataContainer*)next1())) {
1149  // Special outputs or grid files have the files already closed and written.
1150  icont++;
1151  if (fMode == kGridAnalysis && icont<=fOutputs->GetEntriesFast()) continue;
1152  if (fMode == kProofAnalysis) {
1153  if (output->IsSpecialOutput() || output->IsRegisterDataset()) continue;
1154  }
1155  const char *filename = output->GetFileName();
1156  TString openoption = "RECREATE";
1157  if (!(strcmp(filename, "default"))) continue;
1158  if (!strlen(filename)) continue;
1159  if (!output->GetData()) continue;
1160  TDirectory *opwd = gDirectory;
1161  TFile *file = output->GetFile();
1162  if (!file) file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
1163  if (!file) {
1164  //if (handlerFile == filename && !gSystem->AccessPathName(filename)) openoption = "UPDATE";
1165  Bool_t firsttime = kTRUE;
1166  if (filestmp.FindObject(filename) || extraOutputs.Contains(filename)) {
1167  firsttime = kFALSE;
1168  } else {
1169  filestmp.Add(new TNamed(filename,""));
1170  }
1171  if (!gSystem->AccessPathName(filename) && !firsttime) openoption = "UPDATE";
1172  if (fDebug>1) printf("Opening file: %s option=%s\n",filename, openoption.Data());
1173  file = new TFile(filename, openoption);
1174  file->SetCompressionSettings(ROOT::CompressionSettings(ROOT::kZLIB, 1));
1175  } else {
1176  if (fDebug>1) printf("File <%s> already opened with option: <%s> \n", filename, file->GetOption());
1177  openoption = file->GetOption();
1178  if (openoption == "READ") {
1179  if (fDebug>1) printf("...reopening in UPDATE mode\n");
1180  file->ReOpen("UPDATE");
1181  }
1182  }
1183  if (file->IsZombie()) {
1184  Error("Terminate", "Cannot open output file %s", filename);
1185  continue;
1186  }
1187  output->SetFile(file);
1188  file->cd();
1189  // Check for a folder request
1190  TString dir = output->GetFolderName();
1191  if (!dir.IsNull()) {
1192  if (!file->GetDirectory(dir)) file->mkdir(dir);
1193  file->cd(dir);
1194  }
1195  if (fDebug > 1) printf("...writing container %s to file %s:%s\n", output->GetName(), file->GetName(), output->GetFolderName());
1196  if (output->GetData()->InheritsFrom(TCollection::Class())) {
1197  // If data is a collection, we set the name of the collection
1198  // as the one of the container and we save as a single key.
1199  TCollection *coll = (TCollection*)output->GetData();
1200  coll->SetName(output->GetName());
1201  coll->Write(output->GetName(), TObject::kSingleKey);
1202  } else {
1203  if (output->GetData()->InheritsFrom(TTree::Class())) {
1204  TTree *tree = (TTree*)output->GetData();
1205  tree->SetDirectory(gDirectory);
1206  tree->AutoSave();
1207  } else {
1208  output->GetData()->Write();
1209  }
1210  }
1211  if (opwd) opwd->cd();
1212  }
1213  gROOT->cd();
1214  next1.Reset();
1215  TString copiedFiles;
1216  while ((output=(AliAnalysisDataContainer*)next1())) {
1217  // Close all files at output
1218  TDirectory *opwd = gDirectory;
1219  if (output->GetFile()) {
1220  // Clear file list to release object ownership to user.
1221 // output->GetFile()->Clear();
1222  output->GetFile()->Close();
1223  // Copy merged outputs in alien if requested
1224  if (fSpecialOutputLocation.BeginsWith("alien://")) {
1225  if (copiedFiles.Contains(output->GetFile()->GetName())) {
1226  if (opwd) opwd->cd();
1227  output->SetFile(NULL);
1228  continue;
1229  }
1230  Info("Terminate", "Copy file %s to %s", output->GetFile()->GetName(),fSpecialOutputLocation.Data());
1231  gROOT->ProcessLine("if (!gGrid) TGrid::Connect(\"alien:\");");
1232  TFile::Cp(output->GetFile()->GetName(),
1233  Form("%s/%s", fSpecialOutputLocation.Data(), output->GetFile()->GetName()));
1234  copiedFiles += output->GetFile()->GetName();
1235  }
1236  output->SetFile(NULL);
1237  }
1238  if (opwd) opwd->cd();
1239  }
1240  delete allOutputs;
1241  //Write statistics information on the client
1243  if (getsysInfo) {
1244  TDirectory *crtdir = gDirectory;
1245  TFile f("syswatch.root", "RECREATE");
1246  TH1 *hist;
1247  TString cut;
1248  if (!f.IsZombie()) {
1249  TTree *tree = AliSysInfo::MakeTree("syswatch.log");
1250  tree->SetDirectory(&f);
1251  tree->SetName("syswatch");
1252  tree->SetMarkerStyle(kCircle);
1253  tree->SetMarkerColor(kBlue);
1254  tree->SetMarkerSize(0.5);
1255  if (!gROOT->IsBatch()) {
1256  tree->SetAlias("event", "id0");
1257  tree->SetAlias("task", "id1");
1258  tree->SetAlias("stage", "id2");
1259  // Already defined aliases
1260  // tree->SetAlias("deltaT","stampSec-stampOldSec");
1261  // tree->SetAlias("T","stampSec-first");
1262  // tree->SetAlias("deltaVM","(pI.fMemVirtual-pIOld.fMemVirtual)");
1263  // tree->SetAlias("VM","pI.fMemVirtual");
1264  TCanvas *canvas = new TCanvas("SysInfo","SysInfo",10,10,1200,800);
1265  Int_t npads = 1 /*COO plot for all tasks*/ +
1266  fTopTasks->GetEntries() /*Exec plot per task*/ +
1267  1 /*Terminate plot for all tasks*/ +
1268  1; /*vm plot*/
1269 
1270  Int_t iopt = (Int_t)TMath::Sqrt((Double_t)npads);
1271  if (npads<iopt*(iopt+1))
1272  canvas->Divide(iopt, iopt+1, 0.01, 0.01);
1273  else
1274  canvas->Divide(iopt+1, iopt+1, 0.01, 0.01);
1275  Int_t ipad = 1;
1276  // draw the plot of deltaVM for Exec for each task
1277  for (itask=0; itask<fTopTasks->GetEntriesFast(); itask++) {
1278  task = (AliAnalysisTask*)fTopTasks->At(itask);
1279  canvas->cd(ipad++);
1280  cut.Form("task==%d && stage==1", itask);
1281  tree->Draw("deltaVM:event",cut,"", 1234567890, 0);
1282  hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1283  if (hist) {
1284  hist->SetTitle(Form("%s: Exec dVM[MB]/event", task->GetName()));
1285  hist->GetYaxis()->SetTitle("deltaVM [MB]");
1286  }
1287  }
1288  // Draw the plot of deltaVM for CreateOutputObjects for all tasks
1289  canvas->cd(ipad++);
1290  tree->SetMarkerStyle(kFullTriangleUp);
1291  tree->SetMarkerColor(kRed);
1292  tree->SetMarkerSize(0.8);
1293  cut = "task>=0 && task<1000 && stage==0";
1294  tree->Draw("deltaVM:sname",cut,"", 1234567890, 0);
1295  hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1296  if (hist) {
1297  hist->SetTitle("Memory in CreateOutputObjects()");
1298  hist->GetYaxis()->SetTitle("deltaVM [MB]");
1299  hist->GetXaxis()->SetTitle("task");
1300  }
1301  // draw the plot of deltaVM for Terminate for all tasks
1302  canvas->cd(ipad++);
1303  tree->SetMarkerStyle(kOpenSquare);
1304  tree->SetMarkerColor(kMagenta);
1305  cut = "task>=0 && task<1000 && stage==2";
1306  tree->Draw("deltaVM:sname",cut,"", 1234567890, 0);
1307  hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1308  if (hist) {
1309  hist->SetTitle("Memory in Terminate()");
1310  hist->GetYaxis()->SetTitle("deltaVM [MB]");
1311  hist->GetXaxis()->SetTitle("task");
1312  }
1313  // Full VM profile
1314  canvas->cd(ipad++);
1315  tree->SetMarkerStyle(kFullCircle);
1316  tree->SetMarkerColor(kGreen);
1317  cut.Form("task==%d && stage==1",fTopTasks->GetEntriesFast()-1);
1318  tree->Draw("VM:event",cut,"", 1234567890, 0);
1319  hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1320  if (hist) {
1321  hist->SetTitle("Virtual memory");
1322  hist->GetYaxis()->SetTitle("VM [MB]");
1323  }
1324  canvas->Modified();
1325  }
1326  tree->SetMarkerStyle(kCircle);
1327  tree->SetMarkerColor(kBlue);
1328  tree->SetMarkerSize(0.5);
1329  tree->Write();
1330  f.Close();
1331  }
1332  if (crtdir) crtdir->cd();
1333  }
1334  // Validate the output files
1336  ofstream out;
1337  out.open("outputs_valid", ios::out);
1338  out.close();
1339  }
1340  if (cdir) cdir->cd();
1341  fInitTimer->Stop();
1342  if (fDebug || IsCollectThroughput()) {
1343  printf("=Analysis %s= Terminate time: %g[sec]\n", GetName(), fInitTimer->RealTime());
1344  }
1345  if (fDebug > 1) printf("<-AliAnalysisManager::Terminate()\n");
1346 }
1347 //______________________________________________________________________________
1348 void AliAnalysisManager::ProfileTask(Int_t itop, const char *option) const
1349 {
1351 
1352  AliAnalysisTask *task = (AliAnalysisTask*)fTopTasks->At(itop);
1353  if (!task) {
1354  Error("ProfileTask", "There are only %d top tasks in the manager", fTopTasks->GetEntries());
1355  return;
1356  }
1357  ProfileTask(task->GetName(), option);
1358 }
1359 
1360 //______________________________________________________________________________
1361 void AliAnalysisManager::ProfileTask(const char *name, const char */*option*/) const
1362 {
1365 
1366  if (gSystem->AccessPathName("syswatch.root")) {
1367  Error("ProfileTask", "No file syswatch.root found in the current directory");
1368  return;
1369  }
1370  if (gROOT->IsBatch()) return;
1371  AliAnalysisTask *task = (AliAnalysisTask*)fTopTasks->FindObject(name);
1372  if (!task) {
1373  Error("ProfileTask", "No top task named %s known by the manager.", name);
1374  return;
1375  }
1376  Int_t itop = fTopTasks->IndexOf(task);
1377  Int_t itask = fTasks->IndexOf(task);
1378  // Create canvas with 2 pads: first draw COO + Terminate, second Exec
1379  TDirectory *cdir = gDirectory;
1380  TFile f("syswatch.root");
1381  TTree *tree = (TTree*)f.Get("syswatch");
1382  if (!tree) {
1383  Error("ProfileTask", "No tree named <syswatch> found in file syswatch.root");
1384  return;
1385  }
1386  if (fDebug > 1) printf("=== Profiling task %s (class %s)\n", name, task->ClassName());
1387  TCanvas *canvas = new TCanvas(Form("profile_%d",itop),Form("Profile of task %s (class %s)",name,task->ClassName()),10,10,800,600);
1388  canvas->Divide(2, 2, 0.01, 0.01);
1389  Int_t ipad = 1;
1390  TString cut;
1391  TH1 *hist;
1392  // VM profile for COO and Terminate methods
1393  canvas->cd(ipad++);
1394  cut.Form("task==%d && (stage==0 || stage==2)",itask);
1395  tree->Draw("deltaVM:sname",cut,"", 1234567890, 0);
1396  hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1397  if (hist) {
1398  hist->SetTitle("Alocated VM[MB] for COO and Terminate");
1399  hist->GetYaxis()->SetTitle("deltaVM [MB]");
1400  hist->GetXaxis()->SetTitle("method");
1401  }
1402  // CPU profile per event
1403  canvas->cd(ipad++);
1404  cut.Form("task==%d && stage==1",itop);
1405  tree->Draw("deltaT:event",cut,"", 1234567890, 0);
1406  hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1407  if (hist) {
1408  hist->SetTitle("Execution time per event");
1409  hist->GetYaxis()->SetTitle("CPU/event [s]");
1410  }
1411  // VM profile for Exec
1412  canvas->cd(ipad++);
1413  cut.Form("task==%d && stage==1",itop);
1414  tree->Draw("deltaVM:event",cut,"", 1234567890, 0);
1415  hist = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
1416  if (hist) {
1417  hist->SetTitle("Alocated VM[MB] per event");
1418  hist->GetYaxis()->SetTitle("deltaVM [MB]");
1419  }
1420  canvas->Modified();
1421  delete tree;
1422  f.Close();
1423  if (cdir) cdir->cd();
1424 }
1425 
1426 //______________________________________________________________________________
1428 {
1430 
1431  if (fInitOK) {
1432  Error("AddTask", "Cannot add task %s since InitAnalysis was already called", task->GetName());
1433  return;
1434  }
1435 
1436  if (fTasks->FindObject(task)) {
1437  Warning("AddTask", "Task %s: the same object already added to the analysis manager. Not adding.", task->GetName());
1438  return;
1439  }
1440  task->SetActive(kFALSE);
1441  fTasks->Add(task);
1442 }
1443 
1444 //______________________________________________________________________________
1446 {
1448 
1449  if (!fTasks) return NULL;
1450  return (AliAnalysisTask*)fTasks->FindObject(name);
1451 }
1452 
1453 //______________________________________________________________________________
1455 {
1457 
1458  if (!fTasks) return -1;
1459  return fTasks->IndexOf(task);
1460 }
1461 
1462 //______________________________________________________________________________
1464  TClass *datatype, EAliAnalysisContType type, const char *filename)
1465 {
1472 
1473  if (fContainers->FindObject(name)) {
1474  Error("CreateContainer","A container named %s already defined !",name);
1475  return NULL;
1476  }
1477  AliAnalysisDataContainer *cont = new AliAnalysisDataContainer(name, datatype);
1478  fContainers->Add(cont);
1479  switch (type) {
1480  case kInputContainer:
1481  fInputs->Add(cont);
1482  break;
1483  case kOutputContainer:
1484  fOutputs->Add(cont);
1485  if (filename && strlen(filename)) {
1486  cont->SetFileName(filename);
1487  cont->SetDataOwned(kFALSE); // data owned by the file
1488  }
1489  break;
1490  case kParamContainer:
1491  fParamCont->Add(cont);
1492  if (filename && strlen(filename)) {
1493  cont->SetFileName(filename);
1494  cont->SetDataOwned(kFALSE); // data owned by the file
1495  }
1496  break;
1497  case kExchangeContainer:
1498  cont->SetExchange(kTRUE);
1499  fExchangeCont->Add(cont);
1500  cont->SetDataOwned(kFALSE); // data owned by the publisher
1501  break;
1502  }
1503  return cont;
1504 }
1505 
1506 //______________________________________________________________________________
1509 {
1511 
1512  if (!task) {
1513  Error("ConnectInput", "Task pointer is NULL");
1514  return kFALSE;
1515  }
1516  if (!fTasks->FindObject(task)) {
1517  AddTask(task);
1518  Info("ConnectInput", "Task %s was not registered. Now owned by analysis manager", task->GetName());
1519  }
1520  Bool_t connected = task->ConnectInput(islot, cont);
1521  return connected;
1522 }
1523 
1524 //______________________________________________________________________________
1527 {
1529 
1530  if (!task) {
1531  Error("ConnectOutput", "Task pointer is NULL");
1532  return kFALSE;
1533  }
1534  if (!fTasks->FindObject(task)) {
1535  AddTask(task);
1536  Warning("ConnectOutput", "Task %s not registered. Now owned by analysis manager", task->GetName());
1537  }
1538  Bool_t connected = task->ConnectOutput(islot, cont);
1539  return connected;
1540 }
1541 
1542 //______________________________________________________________________________
1544 {
1546 
1547  TIter next(fContainers);
1549  while ((cont=(AliAnalysisDataContainer *)next())) {
1550  if (cont->IsOwnedData() &&
1551  cont->IsDataReady() &&
1552  cont->ClientsExecuted()) cont->DeleteData();
1553  }
1554 }
1555 
1556 //______________________________________________________________________________
1558 {
1562 
1563  if (fInitOK) return kTRUE;
1564  if (!gSystem->AccessPathName("outputs_valid"))
1565  gSystem->Unlink("outputs_valid");
1566  // Check for top tasks (depending only on input data containers)
1567  if (!fTasks->First()) {
1568  Error("InitAnalysis", "Analysis has no tasks !");
1569  return kFALSE;
1570  }
1571  TIter next(fTasks);
1572  AliAnalysisTask *task;
1574  Int_t ntop = 0;
1575  Int_t nzombies = 0;
1576  Bool_t iszombie = kFALSE;
1577  Bool_t istop = kTRUE;
1578  Int_t i;
1579  while ((task=(AliAnalysisTask*)next())) {
1580  istop = kTRUE;
1581  iszombie = kFALSE;
1582  Int_t ninputs = task->GetNinputs();
1583  for (i=0; i<ninputs; i++) {
1584  cont = task->GetInputSlot(i)->GetContainer();
1585  if (!cont) {
1586  if (!iszombie) {
1587  task->SetZombie();
1588  fZombies->Add(task);
1589  nzombies++;
1590  iszombie = kTRUE;
1591  }
1592  Error("InitAnalysis", "Input slot %d of task %s has no container connected ! Declared zombie...",
1593  i, task->GetName());
1594  }
1595  if (iszombie) continue;
1596  // Check if cont is an input container
1597  if (istop && !fInputs->FindObject(cont)) istop=kFALSE;
1598  // Connect to parent task
1599  }
1600  if (istop) {
1601  ntop++;
1602  fTopTasks->Add(task);
1603  }
1604  }
1605  if (!ntop) {
1606  Error("InitAnalysis", "No top task defined. At least one task should be connected only to input containers");
1607  return kFALSE;
1608  }
1609  // Check now if there are orphan tasks
1610  for (i=0; i<ntop; i++) {
1611  task = (AliAnalysisTask*)fTopTasks->At(i);
1612  task->SetUsed();
1613  }
1614  Int_t norphans = 0;
1615  next.Reset();
1616  while ((task=(AliAnalysisTask*)next())) {
1617  if (!task->IsUsed()) {
1618  norphans++;
1619  Warning("InitAnalysis", "Task %s is orphan", task->GetName());
1620  }
1621  }
1622  // Check the task hierarchy (no parent task should depend on data provided
1623  // by a daughter task)
1624  for (i=0; i<ntop; i++) {
1625  task = (AliAnalysisTask*)fTopTasks->At(i);
1626  if (task->CheckCircularDeps()) {
1627  Error("InitAnalysis", "Found illegal circular dependencies between following tasks:");
1628  PrintStatus("dep");
1629  return kFALSE;
1630  }
1631  }
1632  // Check that all containers feeding post-event loop tasks are in the outputs list
1633  TIter nextcont(fContainers); // loop over all containers
1634  while ((cont=(AliAnalysisDataContainer*)nextcont())) {
1635  if (!cont->IsPostEventLoop() && !fOutputs->FindObject(cont)) {
1636  if (cont->HasConsumers()) {
1637  // Check if one of the consumers is post event loop
1638  TIter nextconsumer(cont->GetConsumers());
1639  while ((task=(AliAnalysisTask*)nextconsumer())) {
1640  if (task->IsPostEventLoop()) {
1641  fOutputs->Add(cont);
1642  break;
1643  }
1644  }
1645  }
1646  }
1647  }
1648  // Check if all special output containers have a file name provided
1649  TIter nextout(fOutputs);
1650  while ((cont=(AliAnalysisDataContainer*)nextout())) {
1651  if (cont->IsSpecialOutput() && !strlen(cont->GetFileName())) {
1652  Error("InitAnalysis", "Wrong container %s : a file name MUST be provided for special outputs", cont->GetName());
1653  return kFALSE;
1654  }
1655  }
1656  // Initialize requested branch list if needed
1657  if (!fAutoBranchHandling) {
1658  next.Reset();
1659  while ((task=(AliAnalysisTask*)next())) {
1660  if (!task->HasBranches()) {
1661  Error("InitAnalysis", "Manual branch loading requested but task %s of type %s does not define branches.\nUse: fBranchNames = \"ESD:br1,br2,...,brN AOD:bra1,bra2,...,braM\"",
1662  task->GetName(), task->ClassName());
1663  return kFALSE;
1664  }
1665  if (!fInputEventHandler || !strlen(fInputEventHandler->GetDataType())) {
1666  Error("InitAnalysis", "Manual branch loading requested but no input handler defined or handler does not define data type.");
1667  return kFALSE;
1668  }
1669  TString taskbranches;
1670  task->GetBranches(fInputEventHandler->GetDataType(), taskbranches);
1671  if (taskbranches.IsNull()) {
1672  Error("InitAnalysis", "Manual branch loading requested but task %s of type %s does not define branches of type %s:",
1673  task->GetName(), task->ClassName(), fInputEventHandler->GetDataType());
1674  return kFALSE;
1675  }
1676  AddBranches(taskbranches);
1677  }
1678  }
1679  fInitOK = kTRUE;
1680  return kTRUE;
1681 }
1682 
1683 //______________________________________________________________________________
1684 void AliAnalysisManager::AddBranches(const char *branches)
1685 {
1687 
1688  TString br(branches);
1689  TObjArray *arr = br.Tokenize(",");
1690  TIter next(arr);
1691  TObject *obj;
1692  while ((obj=next())) {
1693  if (!fRequestedBranches.Contains(obj->GetName())) {
1694  if (!fRequestedBranches.IsNull()) fRequestedBranches += ",";
1695  fRequestedBranches += obj->GetName();
1696  }
1697  }
1698  delete arr;
1699 }
1700 
1701 //______________________________________________________________________________
1703 {
1705 
1706  if (fAutoBranchHandling || fRequestedBranches.IsNull() || !fTree) return;
1707  TObjArray *arr = fRequestedBranches.Tokenize(",");
1708  TIter next(arr);
1709  TObject *obj;
1710  while ((obj=next())) {
1711  TBranch *br = dynamic_cast<TBranch*>(fTable.FindObject(obj->GetName()));
1712  if (!br) {
1713  br = fTree->GetBranch(obj->GetName());
1714  if (!br) {
1715  Error("CheckBranches", "Could not find branch %s",obj->GetName());
1716  continue;
1717  }
1718  fTable.Add(br);
1719  }
1720  if (load && br->GetReadEntry()!=GetCurrentEntry()) {
1721  br->GetEntry(GetCurrentEntry());
1722  }
1723  }
1724  delete arr;
1725 }
1726 
1727 //______________________________________________________________________________
1729 {
1731  Int_t ntasks = fTasks->GetEntries();
1732  if (!ntasks) {
1733  Error("CheckTasks", "No tasks connected to the manager. This may be due to forgetting to compile the task or to load their library.");
1734  return kFALSE;
1735  }
1736  // Loop all tasks to check if their corresponding library was loaded
1737  TIter next(fTasks);
1738  TObject *obj;
1739  while ((obj=next())) {
1740  if (strcmp(obj->ClassName(), "AliAnalysisTaskSE") == 0)
1741  {
1742  Error("CheckTasks", "##################\n \
1743  Class for task %s NOT loaded. You probably forgot to load the library for this task (or compile it dynamically).\n###########################\n",obj->GetName());
1744  return kFALSE;
1745  }
1746  }
1747  return kTRUE;
1748 }
1749 
1750 //______________________________________________________________________________
1751 void AliAnalysisManager::PrintStatus(Option_t *option) const
1752 {
1754 
1755  if (!fInitOK) {
1756  Info("PrintStatus", "Analysis manager %s not initialized : call InitAnalysis() first", GetName());
1757  return;
1758  }
1759  Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
1760  if (getsysInfo) {
1761  AliSysInfo::SetVerbose(kTRUE);
1762  Info("PrintStatus", "System information will be collected each %lld events", fNSysInfo);
1763  }
1765  if (!cont) cont = (AliAnalysisDataContainer*)fInputs->At(0);
1766  printf("=== TOP CONTAINER:\n");
1767  cont->PrintContainer(option,0);
1768  // Reset "touched" flag
1769  TIter next(fContainers);
1770  while ((cont = (AliAnalysisDataContainer*)next())) cont->SetTouched(kFALSE);
1771  TIter nextt(fTasks);
1772  AliAnalysisTask *task;
1773  while ((task=(AliAnalysisTask*)nextt()))
1774  task->SetActive(kFALSE);
1775 
1776  if (!fAutoBranchHandling && !fRequestedBranches.IsNull())
1777  printf("Requested input branches:\n%s\n", fRequestedBranches.Data());
1778 
1779  TString sopt(option);
1780  sopt.ToUpper();
1781 
1782  if (sopt.Contains("ALL"))
1783  {
1784  if ( fOutputEventHandler )
1785  {
1786  cout << TString('_',78) << endl;
1787  cout << "OutputEventHandler:" << endl;
1788  fOutputEventHandler->Print(" ");
1789  }
1790  }
1791 }
1792 
1793 //______________________________________________________________________________
1795 {
1797 
1798  TIter nextTask(fTasks);
1799  AliAnalysisTask *task;
1800  while ((task=(AliAnalysisTask*)nextTask())) {
1801  // Clean all tasks
1802  task->Reset();
1803  }
1804 // CleanContainers();
1805 }
1806 
1807 //______________________________________________________________________________
1809 {
1811 
1812  TDirectory *cdir = gDirectory;
1813  if (IsTrainInitialized()) return;
1814  TIter nextTask(fTasks);
1815  AliAnalysisTask *task;
1816  while ((task=(AliAnalysisTask*)nextTask())) {
1817  gROOT->cd();
1818  task->LocalInit();
1819  }
1820  if (cdir) cdir->cd();
1821  TObject::SetBit(kTasksInitialized, kTRUE);
1822 }
1823 
1824 //______________________________________________________________________________
1825 void AliAnalysisManager::InputFileFromTree(TTree * const tree, TString &fname)
1826 {
1828 
1829  fname = "";
1830  if (!tree) return;
1831  TFile *file = tree->GetCurrentFile();
1832  TString basename;
1833  if (!file) {
1834  TChain *chain = dynamic_cast<TChain*>(tree);
1835  if (!chain || !chain->GetNtrees()) return;
1836  basename = gSystem->BaseName(chain->GetListOfFiles()->First()->GetTitle());
1837  } else {
1838  basename = gSystem->BaseName(file->GetName());
1839  }
1840  Int_t index = basename.Index("#");
1841  fname = basename(index+1, basename.Length());
1842 }
1843 
1844 //______________________________________________________________________________
1845 Long64_t AliAnalysisManager::StartAnalysis(const char *type, Long64_t nentries, Long64_t firstentry)
1846 {
1848 
1849  if (!fGridHandler) {
1850  Error("StartAnalysis", "Cannot start analysis providing just the analysis type without a grid handler.");
1851  Info("===", "Add an AliAnalysisAlien object as plugin for this manager and configure it.");
1852  return -1;
1853  }
1854  TTree *tree = NULL;
1855  return StartAnalysis(type, tree, nentries, firstentry);
1856 }
1857 
1858 //______________________________________________________________________________
1859 Long64_t AliAnalysisManager::StartAnalysis(const char *type, TTree * const tree, Long64_t nentries, Long64_t firstentry)
1860 {
1863 
1864  Long64_t retv = 0;
1865  // Backup current directory and make sure gDirectory points to gROOT
1866  TDirectory *cdir = gDirectory;
1867  gROOT->cd();
1868  if (!fInitOK) {
1869  Error("StartAnalysis","Analysis manager was not initialized !");
1870  if (cdir) cdir->cd();
1871  return -1;
1872  }
1873  if (!CheckTasks()) Fatal("StartAnalysis", "Not all needed libraries were loaded");
1874  if (fDebug > 1) {
1875  printf("StartAnalysis %s\n",GetName());
1877  }
1878  fMaxEntries = nentries;
1879  fIsRemote = kFALSE;
1880  TString anaType = type;
1881  anaType.ToLower();
1883  if (anaType.Contains("file")) fIsRemote = kTRUE;
1884  if (anaType.Contains("proof")) fMode = kProofAnalysis;
1885  else if (anaType.Contains("grid")) fMode = kGridAnalysis;
1886  else if (anaType.Contains("mix")) fMode = kMixingAnalysis;
1887  if (fInputEventHandler) {
1888  TString fname;
1889  InputFileFromTree(tree, fname);
1890  if (fname.Length()) fInputEventHandler->SetInputFileName(fname);
1891  }
1892 
1893  if (fMode == kGridAnalysis) {
1894  fIsRemote = kTRUE;
1895  if (!anaType.Contains("terminate")) {
1896  if (!fGridHandler) {
1897  Error("StartAnalysis", "Cannot start grid analysis without a grid handler.");
1898  Info("===", "Add an AliAnalysisAlien object as plugin for this manager and configure it.");
1899  if (cdir) cdir->cd();
1900  return -1;
1901  }
1902  // Write analysis manager in the analysis file
1903  cout << "===== RUNNING GRID ANALYSIS: " << GetName() << endl;
1904  // run local task configuration
1905  RunLocalInit();
1906  if (!fGridHandler->StartAnalysis(nentries, firstentry)) {
1907  Info("StartAnalysis", "Grid analysis was stopped and cannot be terminated");
1908  if (cdir) cdir->cd();
1909  return -1;
1910  }
1911 
1912  // Terminate grid analysis
1913  if (fSelector && fSelector->GetStatus() == -1) {if (cdir) cdir->cd(); return -1;}
1914  if (fGridHandler->GetRunMode() == AliAnalysisGrid::kOffline) {if (cdir) cdir->cd(); return 0;}
1915  cout << "===== MERGING OUTPUTS REGISTERED BY YOUR ANALYSIS JOB: " << GetName() << endl;
1916  if (!fGridHandler->MergeOutputs()) {
1917  // Return if outputs could not be merged or if it alien handler
1918  // was configured for offline mode or local testing.
1919  if (cdir) cdir->cd();
1920  return 0;
1921  }
1922  }
1923  cout << "===== TERMINATING GRID ANALYSIS JOB: " << GetName() << endl;
1924  if (cdir) cdir->cd();
1925  ImportWrappers(NULL);
1926  Terminate();
1927  if (cdir) cdir->cd();
1928  return 0;
1929  }
1930  TString line;
1931  SetEventLoop(kFALSE);
1932  // Enable event loop mode if a tree was provided
1933  if (tree || fGridHandler || fMode==kMixingAnalysis) SetEventLoop(kTRUE);
1934 
1935  TChain *chain = 0;
1936  TString ttype = "TTree";
1937  if (tree && tree->IsA() == TChain::Class()) {
1938  chain = (TChain*)tree;
1939  if (!chain || !chain->GetListOfFiles()->First()) {
1940  Error("StartAnalysis", "Cannot process null or empty chain...");
1941  if (cdir) cdir->cd();
1942  return -1;
1943  }
1944  ttype = "TChain";
1945  }
1946 
1947  Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
1948  if (getsysInfo) {
1949  AliSysInfo::SetVerbose(kTRUE);
1950  AliSysInfo::AddStamp("Start", 0);
1951  }
1952  // Initialize locally all tasks (happens for all modes)
1953  TIter next(fTasks);
1954  AliAnalysisTask *task;
1955  RunLocalInit();
1956 
1957  switch (fMode) {
1958  case kLocalAnalysis:
1959  if (!tree && !fGridHandler) {
1960  TIter nextT(fTasks);
1961  // Call CreateOutputObjects for all tasks
1962  Int_t itask = 0;
1963  Bool_t dirStatus = TH1::AddDirectoryStatus();
1964  while ((task=(AliAnalysisTask*)nextT())) {
1965  TH1::AddDirectory(kFALSE);
1966  task->CreateOutputObjects();
1967  if (!task->CheckPostData()) {
1968  Error("SlaveBegin","####### IMPORTANT! ####### \n\n\n\
1969  Task %s (%s) did not call PostData() for all its outputs in (User)CreateOutputObjects()\n\n\
1970  ########### FIX YOUR CODE, THIS WILL PRODUCE A FATAL ERROR IN FUTURE! ###########", task->GetName(), task->ClassName());
1971  }
1972  if (getsysInfo) AliSysInfo::AddStamp(Form("%s_CREATEOUTOBJ",task->ClassName()), 0, itask, 0);
1973  gROOT->cd();
1974  itask++;
1975  }
1976  TH1::AddDirectory(dirStatus);
1977  if (IsExternalLoop()) {
1978  Info("StartAnalysis", "Initialization done. Event loop is controlled externally.\
1979  \nSetData for top container, call ExecAnalysis in a loop and then Terminate manually");
1980  return 0;
1981  }
1982  ExecAnalysis();
1983  Terminate();
1984  return 0;
1985  }
1986  fSelector = new AliAnalysisSelector(this);
1987  // Check if a plugin handler is used
1988  if (fGridHandler) {
1989  // Get the chain from the plugin
1990  TString dataType = "esdTree";
1991  if (fInputEventHandler) {
1992  dataType = fInputEventHandler->GetDataType();
1993  dataType.ToLower();
1994  dataType += "Tree";
1995  }
1996  chain = fGridHandler->GetChainForTestMode(dataType);
1997  if (!chain) {
1998  Error("StartAnalysis", "No chain for test mode. Aborting.");
1999  return -1;
2000  }
2001  cout << "===== RUNNING LOCAL ANALYSIS" << GetName() << " ON CHAIN " << chain->GetName() << endl;
2002  retv = chain->Process(fSelector, "", nentries, firstentry);
2003  break;
2004  }
2005  // Run tree-based analysis via AliAnalysisSelector
2006  cout << "===== RUNNING LOCAL ANALYSIS " << GetName() << " ON TREE " << tree->GetName() << endl;
2007  retv = tree->Process(fSelector, "", nentries, firstentry);
2008  break;
2009  case kProofAnalysis:
2010  fIsRemote = kTRUE;
2011  // Check if the plugin is used
2012  if (fGridHandler) {
2013  return StartAnalysis(type, fGridHandler->GetProofDataSet(), nentries, firstentry);
2014  }
2015  if (!gROOT->GetListOfProofs() || !gROOT->GetListOfProofs()->GetEntries()) {
2016  Error("StartAnalysis", "No PROOF!!! Exiting.");
2017  if (cdir) cdir->cd();
2018  return -1;
2019  }
2020  line = Form("gProof->AddInput((TObject*)%p);", this);
2021  gROOT->ProcessLine(line);
2022  if (chain) {
2023  chain->SetProof();
2024  cout << "===== RUNNING PROOF ANALYSIS " << GetName() << " ON CHAIN " << chain->GetName() << endl;
2025  retv = chain->Process("AliAnalysisSelector", "", nentries, firstentry);
2026  } else {
2027  Error("StartAnalysis", "No chain!!! Exiting.");
2028  if (cdir) cdir->cd();
2029  return -1;
2030  }
2031  break;
2032  case kGridAnalysis:
2033  fIsRemote = kTRUE;
2034  if (!anaType.Contains("terminate")) {
2035  if (!fGridHandler) {
2036  Error("StartAnalysis", "Cannot start grid analysis without a grid handler.");
2037  Info("===", "Add an AliAnalysisAlien object as plugin for this manager and configure it.");
2038  if (cdir) cdir->cd();
2039  return -1;
2040  }
2041  // Write analysis manager in the analysis file
2042  cout << "===== RUNNING GRID ANALYSIS: " << GetName() << endl;
2043  // Start the analysis via the handler
2044  if (!fGridHandler->StartAnalysis(nentries, firstentry)) {
2045  Info("StartAnalysis", "Grid analysis was stopped and cannot be terminated");
2046  if (cdir) cdir->cd();
2047  return -1;
2048  }
2049 
2050  // Terminate grid analysis
2051  if (fSelector && fSelector->GetStatus() == -1) {if (cdir) cdir->cd(); return -1;}
2052  if (fGridHandler->GetRunMode() == AliAnalysisGrid::kOffline) {if (cdir) cdir->cd(); return 0;}
2053  cout << "===== MERGING OUTPUTS REGISTERED BY YOUR ANALYSIS JOB: " << GetName() << endl;
2054  if (!fGridHandler->MergeOutputs()) {
2055  // Return if outputs could not be merged or if it alien handler
2056  // was configured for offline mode or local testing.
2057  if (cdir) cdir->cd();
2058  return 0;
2059  }
2060  }
2061  cout << "===== TERMINATING GRID ANALYSIS JOB: " << GetName() << endl;
2062  ImportWrappers(NULL);
2063  Terminate();
2064  if (cdir) cdir->cd();
2065  return 0;
2066  case kMixingAnalysis:
2067  // Run event mixing analysis
2068  if (!fEventPool) {
2069  Error("StartAnalysis", "Cannot run event mixing without event pool");
2070  if (cdir) cdir->cd();
2071  return -1;
2072  }
2073  cout << "===== RUNNING EVENT MIXING ANALYSIS " << GetName() << endl;
2074  fSelector = new AliAnalysisSelector(this);
2075  while ((chain=fEventPool->GetNextChain())) {
2076  next.Reset();
2077  // Call NotifyBinChange for all tasks
2078  while ((task=(AliAnalysisTask*)next()))
2079  if (!task->IsPostEventLoop()) task->NotifyBinChange();
2080  retv = chain->Process(fSelector);
2081  if (retv < 0) {
2082  Error("StartAnalysis", "Mixing analysis failed");
2083  if (cdir) cdir->cd();
2084  return retv;
2085  }
2086  }
2087  PackOutput(fSelector->GetOutputList());
2088  Terminate();
2089  }
2090  if (cdir) cdir->cd();
2091  return retv;
2092 }
2093 
2094 //______________________________________________________________________________
2095 Long64_t AliAnalysisManager::StartAnalysis(const char *type, const char *dataset, Long64_t nentries, Long64_t firstentry)
2096 {
2099 
2100  if (!fInitOK) {
2101  Error("StartAnalysis","Analysis manager was not initialized !");
2102  return -1;
2103  }
2104  fIsRemote = kTRUE;
2105  if (fDebug > 1) printf("StartAnalysis %s\n",GetName());
2106  TString anaType = type;
2107  anaType.ToLower();
2108  if (!anaType.Contains("proof")) {
2109  Error("StartAnalysis", "Cannot process datasets in %s mode. Try PROOF.", type);
2110  return -1;
2111  }
2113  TString line;
2114  TString proofProcessOpt;
2115  SetEventLoop(kTRUE);
2116  // Set the dataset flag
2117  TObject::SetBit(kUseDataSet);
2118  fTree = 0;
2119  if (fGridHandler) {
2120  // Start proof analysis using the grid handler
2121  if (!fGridHandler->StartAnalysis(nentries, firstentry)) {
2122  Error("StartAnalysis", "The grid plugin could not start PROOF analysis");
2123  return -1;
2124  }
2125  // Check if the plugin is in test mode
2127  dataset = "test_collection";
2128  } else {
2129  dataset = fGridHandler->GetProofDataSet();
2130  }
2131 
2132  proofProcessOpt = fGridHandler->GetProofProcessOpt();
2133  }
2134 
2135  if (!gROOT->GetListOfProofs() || !gROOT->GetListOfProofs()->GetEntries()) {
2136  Error("StartAnalysis", "No PROOF!!! Exiting.");
2137  return -1;
2138  }
2139 
2140  // Initialize locally all tasks
2141  RunLocalInit();
2142 
2143  line.Form("gProof->AddInput((TObject*)%p);", this);
2144  gROOT->ProcessLine(line);
2145  Long_t retv;
2146  line.Form("gProof->Process((const char *)%p, \"AliAnalysisSelector\", \"%s\", %lld, %lld);",
2147  dataset, proofProcessOpt.Data(), nentries, firstentry);
2148  char *dispDataset = new char[101];
2149  strncpy(dispDataset, dataset, 100);
2150  strncpy(&dispDataset[97], "...", 3);
2151  dispDataset[100] = '\0';
2152  cout << "===== RUNNING PROOF ANALYSIS " << GetName() << " ON DATASET " << dispDataset << endl;
2153  delete [] dispDataset;
2154  retv = (Long_t)gROOT->ProcessLine(line);
2155  return retv;
2156 }
2157 
2158 //______________________________________________________________________________
2159 Long64_t AliAnalysisManager::StartAnalysis(const char *type, TFileCollection* dataset, Long64_t nentries, Long64_t firstentry)
2160 {
2163 
2164  AliInfo("Using the new direct TFileCollection interface !!!!");
2165 
2166  if (!fInitOK) {
2167  Error("StartAnalysis","Analysis manager was not initialized !");
2168  return -1;
2169  }
2170  if (!dataset) {
2171  Error("StartAnalysis","Can not work with a NULL TFileCollection !");
2172  return -1;
2173  }
2174  fIsRemote = kTRUE;
2175  if (fDebug > 1) printf("StartAnalysis %s\n",GetName());
2176  TString anaType = type;
2177  anaType.ToLower();
2178  if (!anaType.Contains("proof")) {
2179  Error("StartAnalysis", "Cannot process datasets in %s mode. Try PROOF.", type);
2180  return -1;
2181  }
2183  TString line;
2184  TString proofProcessOpt;
2185  SetEventLoop(kTRUE);
2186  // Set the dataset flag
2187  TObject::SetBit(kUseDataSet);
2188  fTree = 0;
2189 
2190  if (!gROOT->GetListOfProofs() || !gROOT->GetListOfProofs()->GetEntries()) {
2191  Error("StartAnalysis", "No PROOF!!! Exiting.");
2192  return -1;
2193  }
2194 
2195  // Initialize locally all tasks
2196  RunLocalInit();
2197 
2198  line.Form("gProof->AddInput((TObject*)%p);", this);
2199  gROOT->ProcessLine(line);
2200  Long_t retv;
2201  line.Form("gProof->Process((TFileCollection *)%p, \"AliAnalysisSelector\", \"%s\", %lld, %lld);",
2202  dataset, proofProcessOpt.Data(), nentries, firstentry);
2203  char *dispDataset = new char[101];
2204  strncpy(dispDataset, dataset->GetName(), 100);
2205  strncpy(&dispDataset[97], "...", 3);
2206  dispDataset[100] = '\0';
2207  cout << "===== RUNNING PROOF ANALYSIS " << GetName() << " ON DATASET " << dispDataset << endl;
2208  delete [] dispDataset;
2209  retv = (Long_t)gROOT->ProcessLine(line);
2210  return retv;
2211 }
2212 
2213 //______________________________________________________________________________
2214 TFile *AliAnalysisManager::OpenFile(AliAnalysisDataContainer *cont, const char *option, Bool_t ignoreProof)
2215 {
2220 
2222  TString filename = cont->GetFileName();
2223  TFile *f = NULL;
2224  if (filename.IsNull()) {
2225  ::Error("AliAnalysisManager::OpenFile", "No file name specified for container %s", cont->GetName());
2226  return NULL;
2227  }
2229  && !ignoreProof)
2230  f = mgr->OpenProofFile(cont,option);
2231  else {
2232  // Check first if the file is already opened
2233  f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
2234  if (f) {
2235  // Check if option "UPDATE" was preserved
2236  TString opt(option);
2237  opt.ToUpper();
2238  if ((opt=="UPDATE") && (opt!=f->GetOption()))
2239  ::Info("AliAnalysisManager::OpenFile", "File %s already opened in %s mode!", cont->GetFileName(), f->GetOption());
2240  } else {
2241  f = TFile::Open(filename, option);
2242  }
2243  }
2244  if (f && !f->IsZombie() && !f->TestBit(TFile::kRecovered)) {
2245  cont->SetFile(f);
2246  // Cd to file
2247  f->cd();
2248  // Check for a folder request
2249  TString dir = cont->GetFolderName();
2250  if (!dir.IsNull()) {
2251  if (!f->GetDirectory(dir)) f->mkdir(dir);
2252  f->cd(dir);
2253  }
2254  return f;
2255  }
2256  ::Fatal("AliAnalysisManager::OpenFile", "File %s could not be opened", filename.Data());
2257  cont->SetFile(NULL);
2258  return NULL;
2259 }
2260 
2261 //______________________________________________________________________________
2262 TFile *AliAnalysisManager::OpenProofFile(AliAnalysisDataContainer *cont, const char *option, const char *extaod)
2263 {
2265 
2266  TString line;
2267  TString filename = cont->GetFileName();
2268  if (cont == fCommonOutput) {
2269  if (fOutputEventHandler) {
2270  if (strlen(extaod)) filename = extaod;
2271  filename = fOutputEventHandler->GetOutputFileName();
2272  }
2273  else Fatal("OpenProofFile","No output container. Exiting.");
2274  }
2275  TFile *f = NULL;
2276  if (fMode!=kProofAnalysis || !fSelector) {
2277  Fatal("OpenProofFile","Cannot open PROOF file %s: no PROOF or selector",filename.Data());
2278  return NULL;
2279  }
2280  if (fSpecialOutputLocation.Length()) {
2281  f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
2282  if (f) {
2283  // Check if option "UPDATE" was preserved
2284  TString opt(option);
2285  opt.ToUpper();
2286  if ((opt=="UPDATE") && (opt!=f->GetOption()))
2287  ::Info("OpenProofFile", "File %s already opened in %s mode!", cont->GetFileName(), f->GetOption());
2288  } else {
2289  f = new TFile(filename, option);
2290  }
2291  if (f && !f->IsZombie() && !f->TestBit(TFile::kRecovered)) {
2292  cont->SetFile(f);
2293  // Cd to file
2294  f->cd();
2295  // Check for a folder request
2296  TString dir = cont->GetFolderName();
2297  if (dir.Length()) {
2298  if (!f->GetDirectory(dir)) f->mkdir(dir);
2299  f->cd(dir);
2300  }
2301  return f;
2302  }
2303  Fatal("OpenProofFile", "File %s could not be opened", cont->GetFileName());
2304  cont->SetFile(NULL);
2305  return NULL;
2306  }
2307  // Check if there is already a proof output file in the output list
2308  TObject *pof = fSelector->GetOutputList()->FindObject(filename);
2309  if (pof) {
2310  // Get the actual file
2311  line.Form("((TProofOutputFile*)%p)->GetFileName();", pof);
2312  filename = (const char*)gROOT->ProcessLine(line);
2313  if (fDebug>1) {
2314  printf("File: %s already booked via TProofOutputFile\n", filename.Data());
2315  }
2316  f = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
2317  if (!f) {
2318  Fatal("OpenProofFile", "Proof output file found but no file opened for %s", filename.Data());
2319  return NULL;
2320  }
2321  // Check if option "UPDATE" was preserved
2322  TString opt(option);
2323  opt.ToUpper();
2324  if ((opt=="UPDATE") && (opt!=f->GetOption()))
2325  Fatal("OpenProofFile", "File %s already opened, but not in UPDATE mode!", cont->GetFileName());
2326  } else {
2327  if (cont->IsRegisterDataset()) {
2328  TString dsetName = filename;
2329  dsetName.ReplaceAll(".root", cont->GetTitle());
2330  dsetName.ReplaceAll(":","_");
2331  if (fDebug>1) printf("Booking dataset: %s\n", dsetName.Data());
2332  line.Form("TProofOutputFile *pf = new TProofOutputFile(\"%s\", \"DROV\", \"%s\");", filename.Data(), dsetName.Data());
2333  } else {
2334  if (fDebug>1) printf("Booking TProofOutputFile: %s to be merged\n", filename.Data());
2335  line.Form("TProofOutputFile *pf = new TProofOutputFile(\"%s\");", filename.Data());
2336  }
2337  if (fDebug > 1) printf("=== %s\n", line.Data());
2338  gROOT->ProcessLine(line);
2339  line.Form("pf->OpenFile(\"%s\");", option);
2340  gROOT->ProcessLine(line);
2341  f = gFile;
2342  if (fDebug > 1) {
2343  gROOT->ProcessLine("pf->Print()");
2344  printf(" == proof file name: %s", f->GetName());
2345  }
2346  // Add to proof output list
2347  line.Form("((TList*)%p)->Add(pf);",fSelector->GetOutputList());
2348  if (fDebug > 1) printf("=== %s\n", line.Data());
2349  gROOT->ProcessLine(line);
2350  }
2351  if (f && !f->IsZombie() && !f->TestBit(TFile::kRecovered)) {
2352  cont->SetFile(f);
2353  // Cd to file
2354  f->cd();
2355  // Check for a folder request
2356  TString dir = cont->GetFolderName();
2357  if (!dir.IsNull()) {
2358  if (!f->GetDirectory(dir)) f->mkdir(dir);
2359  f->cd(dir);
2360  }
2361  return f;
2362  }
2363  Fatal("OpenProofFile", "File %s could not be opened", cont->GetFileName());
2364  cont->SetFile(NULL);
2365  return NULL;
2366 }
2367 
2368 //______________________________________________________________________________
2369 void AliAnalysisManager::ExecAnalysis(Option_t *option)
2370 {
2372 
2373  static Long64_t nentries = 0;
2374  static TTree *lastTree = 0;
2375  static TStopwatch *timer = new TStopwatch();
2376  // Only the first call to Process will trigger a true Notify. Other Notify
2377  // coming before is ignored.
2378  if (!TObject::TestBit(AliAnalysisManager::kTrueNotify)) {
2379  TObject::SetBit(AliAnalysisManager::kTrueNotify);
2380  Notify();
2381  }
2382  if (fDebug > 0) printf("MGR: Processing event #%d\n", fNcalls);
2383  else {
2384  if (fTree && (fTree != lastTree)) {
2385  nentries += fTree->GetEntries();
2386  lastTree = fTree;
2387  }
2388  if (!fNcalls) timer->Start();
2389  if (!fIsRemote && TObject::TestBit(kUseProgressBar)) ProgressBar("Processing event", fNcalls, TMath::Min(fMaxEntries,nentries), timer, kFALSE);
2390  }
2391  fIOTimer->Start(kTRUE);
2392  gROOT->cd();
2393  TDirectory *cdir = gDirectory;
2394  Bool_t getsysInfo = ((fNSysInfo>0) && (fMode==kLocalAnalysis))?kTRUE:kFALSE;
2395  if (getsysInfo && ((fNcalls%fNSysInfo)==0)) AliSysInfo::AddStamp("Exec_start", (Int_t)fNcalls);
2396  if (!fInitOK) {
2397  Error("ExecAnalysis", "Analysis manager was not initialized !");
2398  if (cdir) cdir->cd();
2399  return;
2400  }
2401  fNcalls++;
2402  AliAnalysisTask *task;
2403  // Reset the analysis
2404  ResetAnalysis();
2405  // Check if the top tree is active.
2406  if (fTree) {
2407  if (getsysInfo && ((fNcalls%fNSysInfo)==0))
2408  AliSysInfo::AddStamp("Handlers_BeginEventGroup",fNcalls, 1002, 0);
2409  TIter next(fTasks);
2410  // De-activate all tasks (not needed anymore after ResetAnalysis
2411 // while ((task=(AliAnalysisTask*)next())) task->SetActive(kFALSE);
2413  if (!cont) cont = (AliAnalysisDataContainer*)fInputs->At(0);
2414  if (!cont) {
2415  Error("ExecAnalysis","Cannot execute analysis in TSelector mode without at least one top container");
2416  if (cdir) cdir->cd();
2417  return;
2418  }
2419  cont->SetData(fTree); // This set activity for all tasks reading only from the top container
2420  Long64_t entry = fTree->GetTree()->GetReadEntry();
2421 //
2422 // Call BeginEvent() for optional input/output and MC services
2425  if (fMCtruthEventHandler) {
2427  if (fInputEventHandler) {
2429  if (inpEv) inpEv->AdjustMCLabels(fMCtruthEventHandler->GetEvent());
2430  }
2431  }
2432  gROOT->cd();
2433  if (getsysInfo && ((fNcalls%fNSysInfo)==0))
2434  AliSysInfo::AddStamp("Handlers_BeginEvent",fNcalls, 1000, 0);
2435 //
2436 // Execute the tasks
2437 // TIter next1(cont->GetConsumers());
2438  fIOTimer->Stop();
2439  fIOTime += fIOTimer->RealTime();
2440  fCPUTimer->Start(kTRUE);
2441  TIter next1(fTopTasks);
2442  Int_t itask = 0;
2443  while ((task=(AliAnalysisTask*)next1())) {
2444  task->SetActive(kTRUE);
2445  if (fDebug >1) {
2446  cout << " Executing task " << task->GetName() << endl;
2447  }
2448  if (fStatistics) fStatistics->StartTimer(GetTaskIndex(task), task->GetName(), task->ClassName());
2449  task->ExecuteTask(option);
2451  gROOT->cd();
2452  if (getsysInfo && ((fNcalls%fNSysInfo)==0))
2453  AliSysInfo::AddStamp(task->ClassName(), fNcalls, itask, 1);
2454  itask++;
2455  }
2456  fCPUTimer->Stop();
2457  fCPUTime += fCPUTimer->RealTime();
2458  fIOTimer->Start(kTRUE);
2459 //
2460 // Call FinishEvent() for optional output and MC services
2464  // Gather system information if requested
2465  if (getsysInfo && ((fNcalls%fNSysInfo)==0))
2466  AliSysInfo::AddStamp("Handlers_FinishEvent",fNcalls, 1001, 1);
2467  if (cdir) cdir->cd();
2468  fIOTimer->Stop();
2469  fIOTime += fIOTimer->RealTime();
2470  return;
2471  }
2472  // The event loop is not controlled by TSelector
2473 //
2474 // Call BeginEvent() for optional input/output and MC services
2475  fIOTimer->Start(kTRUE);
2478  if (fMCtruthEventHandler) {
2480  if (fInputEventHandler) {
2482  if (inpEv) inpEv->AdjustMCLabels(fMCtruthEventHandler->GetEvent());
2483  }
2484  }
2485  fIOTimer->Stop();
2486  fIOTime += fIOTimer->RealTime();
2487  gROOT->cd();
2488  if (getsysInfo && ((fNcalls%fNSysInfo)==0))
2489  AliSysInfo::AddStamp("Handlers_BeginEvent",fNcalls, 1000, 0);
2490  fCPUTimer->Start(kTRUE);
2491  TIter next2(fTopTasks);
2492  while ((task=(AliAnalysisTask*)next2())) {
2493  task->SetActive(kTRUE);
2494  if (fDebug > 1) {
2495  cout << " Executing task " << task->GetName() << endl;
2496  }
2497  if (fStatistics) fStatistics->StartTimer(GetTaskIndex(task), task->GetName(), task->ClassName());
2498  task->ExecuteTask(option);
2500  gROOT->cd();
2501  }
2502  fCPUTimer->Stop();
2503  fCPUTime += fCPUTimer->RealTime();
2504 //
2505 // Call FinishEvent() for optional output and MC services
2506  fIOTimer->Start(kTRUE);
2510  if (getsysInfo && ((fNcalls%fNSysInfo)==0))
2511  AliSysInfo::AddStamp("Handlers_FinishEvent",fNcalls, 1000, 1);
2512  if (cdir) cdir->cd();
2513  fIOTimer->Stop();
2514  fIOTime += fIOTimer->RealTime();
2515 }
2516 
2517 //______________________________________________________________________________
2518 Bool_t AliAnalysisManager::IsPipe(std::ostream &out)
2519 {
2521 
2522  Bool_t ispipe = kFALSE;
2523  out.seekp(0, std::ios_base::cur);
2524  if (out.fail()) {
2525  out.clear();
2526  if (errno == ESPIPE) ispipe = kTRUE;
2527  }
2528  return ispipe;
2529 }
2530 
2531 //______________________________________________________________________________
2533 {
2535 
2536  Changed();
2537  fInputEventHandler = handler;
2538  if (!fCommonInput) fCommonInput = CreateContainer("cAUTO_INPUT", TChain::Class(), AliAnalysisManager::kInputContainer);
2539 }
2540 
2541 //______________________________________________________________________________
2543 {
2545 
2546  Changed();
2547  fOutputEventHandler = handler;
2548  if (!fCommonOutput) fCommonOutput = CreateContainer("cAUTO_OUTPUT", TTree::Class(), AliAnalysisManager::kOutputContainer, "default");
2550 }
2551 
2552 //______________________________________________________________________________
2554 {
2556 
2557  if (TObject::TestBit(kUseProgressBar)) {
2558  Info("SetDebugLevel","Ignored. Disable the progress bar first.");
2559  return;
2560  }
2561  fDebug = level;
2562 }
2563 
2564 //______________________________________________________________________________
2565 void AliAnalysisManager::SetUseProgressBar(Bool_t flag, Int_t freq)
2566 {
2568 
2569  Info("SetUseProgressBar", "Progress bar enabled, updated every %d events.\n ### NOTE: Debug level reset to 0 ###", freq);
2570  TObject::SetBit(kUseProgressBar,flag);
2571  fPBUpdateFreq = freq;
2572  fDebug = 0;
2573 }
2574 
2575 //______________________________________________________________________________
2577 {
2582 
2583  if (fExtraFiles.Contains(fname)) return;
2584  if (fExtraFiles.Length()) fExtraFiles += " ";
2585  fExtraFiles += fname;
2586 }
2587 
2588 //______________________________________________________________________________
2589 Bool_t AliAnalysisManager::GetFileFromWrapper(const char *filename, const TList *source)
2590 {
2592 
2593  char fullPath[512];
2594  char chUrl[512];
2595  char tmp[1024];
2596  TObject *pof = source->FindObject(filename);
2597  if (!pof || !pof->InheritsFrom("TProofOutputFile")) {
2598  Error("GetFileFromWrapper", "TProofOutputFile object not found in output list for file %s", filename);
2599  return kFALSE;
2600  }
2601  gROOT->ProcessLine(Form("sprintf((char*)%p, \"%%s\", ((TProofOutputFile*)%p)->GetOutputFileName());", fullPath, pof));
2602  gROOT->ProcessLine(Form("sprintf((char*)%p, \"%%s\", gProof->GetUrl());",chUrl));
2603  TString clientUrl(chUrl);
2604  TString fullPath_str(fullPath);
2605  if (clientUrl.Contains("localhost")){
2606  TObjArray* array = fullPath_str.Tokenize ( "//" );
2607  TObjString *strobj = ( TObjString *)array->At(1);
2608  TObjArray* arrayPort = strobj->GetString().Tokenize ( ":" );
2609  TObjString *strobjPort = ( TObjString *) arrayPort->At(1);
2610  fullPath_str.ReplaceAll(strobj->GetString().Data(),"localhost:PORT");
2611  fullPath_str.ReplaceAll(":PORT",Form(":%s",strobjPort->GetString().Data()));
2612  if (fDebug > 1) Info("GetFileFromWrapper","Using tunnel from %s to %s",fullPath_str.Data(),filename);
2613  delete arrayPort;
2614  delete array;
2615  }
2616  else if (clientUrl.Contains("__lite__")) {
2617  // Special case for ProofLite environement - get file info and copy.
2618  gROOT->ProcessLine(Form("sprintf((char*)%p,\"%%s\",((TProofOutputFile*)%p)->GetDir());", tmp, pof));
2619  fullPath_str.Form("%s/%s", tmp, fullPath);
2620  }
2621  if (fDebug > 1)
2622  Info("GetFileFromWrapper","Copying file %s from PROOF scratch space to %s", fullPath_str.Data(),filename);
2623  Bool_t gotit = TFile::Cp(fullPath_str.Data(), filename);
2624  if (!gotit)
2625  Error("GetFileFromWrapper", "Could not get file %s from proof scratch space", filename);
2626  return gotit;
2627 }
2628 
2629 //______________________________________________________________________________
2631 {
2633 
2634  switch (fMode) {
2635  case kLocalAnalysis:
2636  type = "local";
2637  return;
2638  case kProofAnalysis:
2639  type = "proof";
2640  return;
2641  case kGridAnalysis:
2642  type = "grid";
2643  return;
2644  case kMixingAnalysis:
2645  type = "mix";
2646  }
2647 }
2648 
2649 //______________________________________________________________________________
2651 {
2653 
2654  TIter next(fOutputs);
2655  AliAnalysisDataContainer *output;
2656  TDirectory *cdir = gDirectory;
2657  TString openedFiles;
2658  while ((output=(AliAnalysisDataContainer*)next())) {
2659  if (output->IsRegisterDataset()) continue;
2660  TString filename = output->GetFileName();
2661  if (filename == "default") {
2662  if (!fOutputEventHandler) continue;
2663  filename = fOutputEventHandler->GetOutputFileName();
2664  // Main AOD may not be there
2665  if (gSystem->AccessPathName(filename)) continue;
2666  }
2667  // Check if the file is closed
2668  if (openedFiles.Contains(filename)) continue;;
2669  TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
2670  if (file) {
2671  Warning("ValidateOutputs", "File %s was not closed. Closing.", filename.Data());
2672  // Clear file list to release object ownership to user.
2673 // file->Clear();
2674  file->Close();
2675  }
2676  file = TFile::Open(filename);
2677  if (!file || file->IsZombie() || file->TestBit(TFile::kRecovered)) {
2678  Error("ValidateOutputs", "Output file <%s> was not created or invalid", filename.Data());
2679  if (cdir) cdir->cd();
2680  return kFALSE;
2681  }
2682  file->Close();
2683  openedFiles += filename;
2684  openedFiles += " ";
2685  }
2686  if (cdir) cdir->cd();
2687  return kTRUE;
2688 }
2689 
2690 //______________________________________________________________________________
2691 void AliAnalysisManager::ProgressBar(const char *opname, Long64_t current, Long64_t size, TStopwatch * const watch, Bool_t last, Bool_t refresh)
2692 {
2694 
2695  static Long64_t icount = 0;
2696  static TString oname;
2697  static TString nname;
2698  static Long64_t ocurrent = 0;
2699  static Long64_t osize = 0;
2700  static Int_t oseconds = 0;
2701  static TStopwatch *owatch = 0;
2702  static Bool_t oneoftwo = kFALSE;
2703  static Int_t nrefresh = 0;
2704  static Int_t nchecks = 0;
2705  static char lastChar = 0;
2706  const char symbol[4] = {'-','\\','|','/'};
2707 
2708  if (!lastChar) lastChar = (IsPipe(std::cerr))?'\r':'\n';
2709  if (!refresh) {
2710  nrefresh = 0;
2711  if (!size) return;
2712  owatch = watch;
2713  oname = opname;
2714  ocurrent = TMath::Abs(current);
2715  osize = TMath::Abs(size);
2716  if (ocurrent > osize) ocurrent=osize;
2717  } else {
2718  nrefresh++;
2719  if (!osize) return;
2720  }
2721  if ((current % fPBUpdateFreq) != 0) return;
2722  icount++;
2723  char progress[11] = " ";
2724  Int_t ichar = icount%4;
2725  Double_t time = 0.;
2726  Int_t hours = 0;
2727  Int_t minutes = 0;
2728  Int_t seconds = 0;
2729  if (owatch && !last) {
2730  owatch->Stop();
2731  time = owatch->RealTime();
2732  seconds = int(time) % 60;
2733  minutes = (int(time) / 60) % 60;
2734  hours = (int(time) / 60 / 60);
2735  if (refresh) {
2736  if (oseconds==seconds) {
2737  owatch->Continue();
2738  return;
2739  }
2740  oneoftwo = !oneoftwo;
2741  }
2742  oseconds = seconds;
2743  }
2744  if (refresh && oneoftwo) {
2745  nname = oname;
2746  if (nchecks <= 0) nchecks = nrefresh+1;
2747  Int_t pctdone = (Int_t)(100.*nrefresh/nchecks);
2748  oname.Form(" == %d%% ==", pctdone);
2749  }
2750  Double_t percent = 100.0*ocurrent/osize;
2751  Int_t nchar = Int_t(percent/10);
2752  if (nchar>10) nchar=10;
2753  Int_t i;
2754  for (i=0; i<nchar; i++) progress[i] = '=';
2755  progress[nchar] = symbol[ichar];
2756  for (i=nchar+1; i<10; i++) progress[i] = ' ';
2757  progress[10] = '\0';
2758  oname += " ";
2759  oname.Remove(20);
2760  if(size<10000) fprintf(stderr, "%s [%10s] %4lld ", oname.Data(), progress, ocurrent);
2761  else if(size<100000) fprintf(stderr, "%s [%10s] %5lld ",oname.Data(), progress, ocurrent);
2762  else fprintf(stderr, "%s [%10s] %7lld ",oname.Data(), progress, ocurrent);
2763  if (time>0.) {
2764  Int_t full = Int_t(ocurrent > 0 ?
2765  time * (float(osize)/ocurrent) + .5 :
2766  99*3600+59*60+59);
2767  Int_t remain = Int_t(full - time);
2768  Int_t rsec = remain % 60;
2769  Int_t rmin = (remain / 60) % 60;
2770  Int_t rhour = (remain / 60 / 60);
2771  fprintf(stderr, "[%6.2f %%] TIME %.2d:%.2d:%.2d ETA %.2d:%.2d:%.2d%c",
2772  percent, hours, minutes, seconds, rhour, rmin, rsec, lastChar);
2773  }
2774  else fprintf(stderr, "[%6.2f %%]%c", percent, lastChar);
2775  if (refresh && oneoftwo) oname = nname;
2776  if (owatch) owatch->Continue();
2777  if (last) {
2778  icount = 0;
2779  owatch = 0;
2780  ocurrent = 0;
2781  osize = 0;
2782  oseconds = 0;
2783  oneoftwo = kFALSE;
2784  nrefresh = 0;
2785  fprintf(stderr, "\n");
2786  }
2787 }
2788 
2789 //______________________________________________________________________________
2790 void AliAnalysisManager::DoLoadBranch(const char *name)
2791 {
2793 
2794  static Long64_t crtEntry = -100;
2795 
2796  if (fAutoBranchHandling || !fTree)
2797  return;
2798 
2799  TBranch *br = dynamic_cast<TBranch*>(fTable.FindObject(name));
2800  if (!br) {
2801  br = fTree->GetBranch(name);
2802  if (!br) {
2803  Error("DoLoadBranch", "Could not find branch %s",name);
2804  return;
2805  }
2806  fTable.Add(br);
2807  }
2808  if (br->GetReadEntry()==fCurrentEntry) return;
2809  Long64_t readbytes = br->GetEntry(GetCurrentEntry());
2810  if (readbytes<0) {
2811  Error("DoLoadBranch", "Could not load entry %lld from branch %s",GetCurrentEntry(), name);
2812  if (crtEntry != fCurrentEntry) {
2813  CountEvent(1,0,1,0);
2814  crtEntry = fCurrentEntry;
2815  }
2816  } else {
2817  if (crtEntry != fCurrentEntry) {
2818  CountEvent(1,1,0,0);
2819  crtEntry = fCurrentEntry;
2820  }
2821  }
2822 }
2823 
2824 //______________________________________________________________________________
2826 {
2828 
2829  if (fStatistics) {
2830  Info("AddStatisticsTask", "Already added");
2831  return;
2832  }
2833  TString line;
2834  line.Form("AliAnalysisTaskStat::AddToManager(%u);", offlineMask);
2835  gROOT->ProcessLine(line);
2836 }
2837 
2838 //______________________________________________________________________________
2839 void AliAnalysisManager::CountEvent(Int_t ninput, Int_t nprocessed, Int_t nfailed, Int_t naccepted)
2840 {
2842 
2843  if (!fStatistics) return;
2844  fStatistics->AddInput(ninput);
2845  fStatistics->AddProcessed(nprocessed);
2846  fStatistics->AddFailed(nfailed);
2847  fStatistics->AddAccepted(naccepted);
2848 }
2849 
2850 //______________________________________________________________________________
2852 {
2856 
2857  if (!strlen(line)) return;
2858  if (!fStatisticsMsg.IsNull()) fStatisticsMsg += "\n";
2859  fStatisticsMsg += line;
2860 }
2861 
2862 //______________________________________________________________________________
2864 {
2866 
2867  static Bool_t done = kFALSE;
2868  if (done) return;
2869  done = kTRUE;
2870  if (!fStatistics) return;
2871  ofstream out;
2872  AddStatisticsMsg(Form("Number of input events: %lld",fStatistics->GetNinput()));
2873  AddStatisticsMsg(Form("Number of processed events: %lld",fStatistics->GetNprocessed()));
2874  AddStatisticsMsg(Form("Number of failed events (I/O): %lld",fStatistics->GetNfailed()));
2875  AddStatisticsMsg(Form("Number of accepted events for mask %s: %lld", AliAnalysisStatistics::GetMaskAsString(fStatistics->GetOfflineMask()), fStatistics->GetNaccepted()));
2876  out.open(Form("%lld_%lld_%lld_%lld.stat",fStatistics->GetNinput(),
2878  fStatistics->GetNaccepted()), ios::out);
2879  out << fStatisticsMsg << endl;
2880  out.close();
2881 }
2882 
2883 //______________________________________________________________________________
2885 {
2888 
2889  static TString oadbPath;
2890 
2891  if (gSystem->Getenv("OADB_PATH"))
2892  oadbPath = gSystem->Getenv("OADB_PATH");
2893  else if (gSystem->Getenv("ALICE_PHYSICS"))
2894  oadbPath.Form("%s/OADB", gSystem->Getenv("ALICE_PHYSICS"));
2895  else
2896  ::Fatal("AliAnalysisManager::GetOADBPath", "Cannot figure out AODB path. Define ALICE_PHYSICS or OADB_PATH!");
2897 
2898  return oadbPath;
2899 }
2900 
2901 //______________________________________________________________________________
2902 void AliAnalysisManager::SetGlobalStr(const char *key, const char *value)
2903 {
2906 
2908  if (!mgr) {
2909  AliErrorClass("No analysis manager defined");
2910  return;
2911  }
2912  Bool_t valid = kFALSE;
2913  TString existing = AliAnalysisManager::GetGlobalStr(key, valid);
2914  if (valid) {
2915  ::Error("AliAnalysisManager::SetGlobalStr", "Global %s = %s already defined.", key, existing.Data());
2916  return;
2917  }
2918  mgr->GetGlobals()->Add(new TObjString(key), new TObjString(value));
2919 }
2920 
2921 //______________________________________________________________________________
2922 const char *AliAnalysisManager::GetGlobalStr(const char *key, Bool_t &valid)
2923 {
2925 
2926  valid = kFALSE;
2928  if (!mgr) return 0;
2929  TObject *value = mgr->GetGlobals()->GetValue(key);
2930  if (!value) return 0;
2931  valid = kTRUE;
2932  return value->GetName();
2933 }
2934 
2935 //______________________________________________________________________________
2936 void AliAnalysisManager::SetGlobalInt(const char *key, Int_t value)
2937 {
2940 
2942  if (!mgr) {
2943  AliErrorClass("No analysis manager defined");
2944  return;
2945  }
2946  Bool_t valid = kFALSE;
2947  Int_t existing = AliAnalysisManager::GetGlobalInt(key, valid);
2948  if (valid) {
2949  ::Error("AliAnalysisManager::SetGlobalInt", "Global %s = %i already defined.", key, existing);
2950  return;
2951  }
2952  mgr->GetGlobals()->Add(new TObjString(key), new TObjString(TString::Format("%i",value)));
2953 }
2954 
2955 //______________________________________________________________________________
2956 Int_t AliAnalysisManager::GetGlobalInt(const char *key, Bool_t &valid)
2957 {
2959 
2960  valid = kFALSE;
2962  if (!mgr) return 0;
2963  TObject *value = mgr->GetGlobals()->GetValue(key);
2964  if (!value) return 0;
2965  valid = kTRUE;
2966  TString s = value->GetName();
2967  return s.Atoi();
2968 }
2969 
2970 //______________________________________________________________________________
2971 void AliAnalysisManager::SetGlobalDbl(const char *key, Double_t value)
2972 {
2975 
2977  if (!mgr) {
2978  AliErrorClass("No analysis manager defined");
2979  return;
2980  }
2981  Bool_t valid = kFALSE;
2982  Double_t existing = AliAnalysisManager::GetGlobalDbl(key, valid);
2983  if (valid) {
2984  ::Error("AliAnalysisManager::SetGlobalInt", "Global %s = %g already defined.", key, existing);
2985  return;
2986  }
2987  mgr->GetGlobals()->Add(new TObjString(key), new TObjString(TString::Format("%f.16",value)));
2988 }
2989 
2990 //______________________________________________________________________________
2991 Double_t AliAnalysisManager::GetGlobalDbl(const char *key, Bool_t &valid)
2992 {
2994 
2995  valid = kFALSE;
2997  if (!mgr) return 0;
2998  TObject *value = mgr->GetGlobals()->GetValue(key);
2999  if (!value) return 0;
3000  valid = kTRUE;
3001  TString s = value->GetName();
3002  return s.Atof();
3003 }
3004 
3005 //______________________________________________________________________________
3006 void AliAnalysisManager::AddClassDebug(const char *className, Int_t debugLevel)
3007 {
3009 
3010  if (!fDebugOptions) {
3011  fDebugOptions = new TObjArray();
3012  fDebugOptions->SetOwner(kTRUE);
3013  }
3014 
3015  TNamed *debugOpt = (TNamed*)fDebugOptions->FindObject(className);
3016  if (!debugOpt) {
3017  AliInfo(TString::Format("Adding debug level %d for class %s",debugLevel,className).Data());
3018  fDebugOptions->Add(new TNamed(className,TString::Format("%d",debugLevel).Data()));
3019  } else {
3020  TString oldDebugStr = debugOpt->GetTitle();
3021  Int_t oldDebug = oldDebugStr.Atoi();
3022  if (debugLevel > oldDebug) {
3023  AliWarning(TString::Format("Overwriting debug level to %d class %s, because it is higher then previously set (%d).",debugLevel,className,oldDebug).Data());
3024  debugOpt->SetTitle(TString::Format("%d",debugLevel).Data());
3025  } else {
3026  AliWarning(TString::Format("Ignoring debug level to %d class %s, because it is smaller then previously set (%d).",debugLevel,className,oldDebug).Data());
3027  }
3028  }
3029 }
3030 
3031 //______________________________________________________________________________
3033 {
3035 
3036  if (!fDebugOptions) return;
3037 
3038  TIter next(fDebugOptions);
3039  TNamed *debug;
3040  TString debugLevel;
3041  while ((debug=dynamic_cast<TNamed*>(next()))) {
3042  debugLevel = debug->GetTitle();
3043  AliInfo(TString::Format("Class=%s debulLevel=%d",debug->GetName(),debugLevel.Atoi()).Data());
3044  AliLog::SetClassDebugLevel(debug->GetName(), debugLevel.Atoi());
3045  }
3046 }
3047 
3048 //______________________________________________________________________________
3049 Bool_t AliAnalysisManager::IsMacroLoaded(const char * filename)
3050 {
3052 
3053  return fgMacroNames.Contains(filename);
3054 }
3055 
3056 //______________________________________________________________________________
3057 Int_t AliAnalysisManager::LoadMacro(const char *filename, Int_t *error, Bool_t check)
3058 {
3061 
3062  TString macroName = gSystem->BaseName(filename);
3063  // Strip appended +, ++, +g, +O
3064  Int_t index = macroName.Index("+");
3065  if (index>0) macroName.Remove(index);
3066  if (fgMacroNames.Contains(macroName)) {
3067  // Macro with the same name loaded already in this root session, do
3068  // nothing
3069  error = 0;
3070  return 0;
3071  }
3072  Int_t ret = gROOT->LoadMacro(filename,error,check);
3073  // In case of error return the error code
3074  if (ret) return ret;
3075  // Append the macro name to the loaded macros list
3076  fgMacroNames += macroName;
3077  fgMacroNames += " ";
3078  return ret;
3079 }
3080 
3081 //______________________________________________________________________________
3083 {
3086 
3087  if (fLocked) return;
3088  fLocked = kTRUE;
3092  Info("Lock","====== ANALYSIS MANAGER LOCKED ======");
3093 }
3094 
3095 //______________________________________________________________________________
3097 {
3099 
3100  if (!fLocked) return;
3101  fLocked = kFALSE;
3105  Info("UnLock", "====== ANALYSIS MANAGER UNLOCKED ======");
3106 }
3107 
3108 //______________________________________________________________________________
3110 {
3113 
3114  if (fLocked) Fatal("Changed","Critical setter called in locked mode");
3115 }
3116 
3117 //______________________________________________________________________________
3119 {
3120 
3124 
3125  if (fInputEventHandler) {
3126  TString classInputHandler = fInputEventHandler->ClassName();
3127  if (classInputHandler.Contains("HLT")){
3128  TObjArray* arrTasks = GetTasks();
3129  //connect the friend to the event
3130  esdEvent->SetFriendEvent(esdFriend);
3131  //let all tasks know about the new event
3132  fInputEventHandler->InitTaskInputData(esdEvent, esdFriend, arrTasks);
3133  }
3134  else {
3135  Fatal("PropagateHLTEvent", "Input Handler not of type HLT, we cannot use this method!");
3136  }
3137  }
3138  else {
3139  Fatal("PropagateHLTEvent", "Input Handler not found, we cannot use this method!");
3140  }
3141 }
Bool_t ConnectOutput(AliAnalysisTask *task, Int_t islot, AliAnalysisDataContainer *cont)
AliAnalysysTask - Class representing a basic analysis task. Any user-defined task should derive from...
Bool_t GetFileFromWrapper(const char *filename, const TList *source)
TObjArray * fContainers
List of all containers.
AliAnalysisFileDescriptor * fCurrentDescriptor
! Current file descriptor
void InputFileFromTree(TTree *const tree, TString &fname)
AliAnalysisDataWrapper * ExportData() const
Wrapping.
TFile * OpenProofFile(AliAnalysisDataContainer *cont, const char *option, const char *extaod="")
virtual void Terminate(Option_t *option="")
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
virtual Bool_t StartAnalysis(Long64_t nentries=123456789, Long64_t firstentry=0)=0
TFile * Open(const char *filename, Long64_t &nevents)
virtual Bool_t Process(Long64_t entry)
void CheckNotify(Bool_t init=kFALSE)
TTree * fTree
Definition: MakeTreeStat.C:55
static Int_t GetRunFromAlienPath(const char *path)
Bool_t HasBranches() const
void SetEventLoop(Bool_t flag=kTRUE)
void PrintStatus(Option_t *option="all") const
Bool_t CheckCircularDeps()
void WriteStatisticsMsg(Int_t nevents)
virtual void FinishTaskOutput()
AliAnalysisTask * GetTask(const char *name) const
static Int_t LoadMacro(const char *filename, Int_t *error=0, Bool_t check=kFALSE)
static TFile * OpenFile(AliAnalysisDataContainer *cont, const char *option, Bool_t ignoreProof=kFALSE)
static void SetGlobalLogLevel(EType_t type)
Definition: AliLog.cxx:447
static TString fgMacroNames
! Loaded macro names
#define TObjArray
Bool_t fIsRemote
! Flag is set for remote analysis
void AddStatisticsTask(UInt_t offlineMask=0)
virtual TChain * GetNextChain()=0
void GetAnalysisTypeString(TString &type) const
virtual EPluginRunMode GetRunMode() const
Int_t fNcalls
Total number of calls (events) of ExecAnalysis.
static AliAnalysisManager * GetAnalysisManager()
static void SetClassDebugLevel(const char *className, Int_t level)
Definition: AliLog.cxx:513
EAliAnalysisExecMode fMode
Execution mode.
TObject * GetData() const
Getters.
AliAnalysysManager Manager analysis class. Allows creation of several analysis tasks and data contain...
TStopwatch timer
Definition: kNNSpeed.C:15
const char * path
TString fStatisticsMsg
Statistics user message.
void DoLoadBranch(const char *name)
void SetSpecialOutput(Bool_t flag=kTRUE)
AliAnalysisTask * GetProducer() const
AliVEventHandler * fInputEventHandler
Optional common input event handler.
THashTable fTable
keep branch ptrs in case of manual branch loading
void PrintContainer(Option_t *option="all", Int_t indent=0) const
Print connected tasks/status.
virtual Bool_t Init(TTree *tree)
static void SetGlobalDbl(const char *key, Double_t value)
TROOT * gROOT
Long64_t GetNaccepted() const
TObjArray * GetConsumers() const
static const char * GetGlobalStr(const char *key, Bool_t &valid)
TObjArray * fTasks
List of analysis tasks.
void UnpackOutput(TList *source)
virtual Bool_t NotifyBinChange()
Long64_t GetNprocessed() const
static const char * GetMaskAsString(UInt_t mask)
TChain * chain
virtual Bool_t TerminateIO()=0
UInt_t fDebug
Debug level.
static TTree * MakeTree(const char *lname, const char *fout=0)
Definition: AliSysInfo.cxx:263
virtual Bool_t FinishEvent()=0
AliAnalysysDataContainer AliAnalysysDataContainer - Container of data of arbitrary type deriving from...
Int_t GetNinputs() const
void AddAccepted(Int_t nevents=1)
void SetZombie(Bool_t flag=kTRUE)
virtual Bool_t Notify()
TMap * fGlobals
Map with global variables.
TStopwatch * fCPUTimer
! Timer for useful processing
TString fRequestedBranches
Requested branch names.
void AddFailed(Int_t nevents=1)
EAliAnalysisExecMode GetAnalysisType() const
#define AliWarning(message)
Definition: AliLog.h:541
virtual TChain * GetChainForTestMode(const char *treeName) const =0
static TString fgCommonFileName
! Common output file name (not streamed)
TObjArray * GetTasks() const
bool init
Definition: XSection.C:263
TObjArray * array
Definition: AnalyzeLaser.C:12
virtual void CreateOutputObjects()
AliAnalysisDataContainer * fCommonOutput
Common output container.
AliVEventPool * fEventPool
Event pool for mixing analysis.
Long64_t StartAnalysis(const char *type, TTree *const tree, Long64_t nentries=1234567890, Long64_t firstentry=0)
void RegisterExtraFile(const char *fname)
virtual Option_t * GetDataType() const
virtual void SetFriendEvent(AliVfriendEvent *)
Definition: AliVEvent.h:238
Bool_t ConnectOutput(Int_t islot, AliAnalysisDataContainer *cont)
void SetDebugLevel(UInt_t level)
Int_t GetTaskIndex(const AliAnalysisTask *task) const
AliAnalysisSelector * fSelector
! Current selector
#define AliErrorClass(message)
Definition: AliLog.h:596
virtual void SetInputTree(TTree *tree)=0
Double_t fInitTime
! Cumulated time in initialization
TTree * fTree
! Input tree in case of TSelector model
virtual Bool_t BeginEvent(Long64_t entry)=0
TTree * tree
void AddBranches(const char *branches)
AliAnalysisManager & operator=(const AliAnalysisManager &other)
AliAnalysisManager(const char *name="mgr", const char *title="")
virtual void SlaveBegin(TTree *tree)
void ImportData(AliAnalysisDataWrapper *pack)
Bool_t IsDataReady() const
Container status checking.
virtual TTree * GetTree() const
static void SetGlobalStr(const char *key, const char *value)
Long64_t GetNfailed() const
virtual TString GetProofProcessOpt()=0
Bool_t ValidateOutputFiles() const
#define AliInfo(message)
Definition: AliLog.h:484
TStopwatch * fInitTimer
! Timer for initialization
Bool_t IsExternalLoop() const
virtual void Reset()
void SetOutputEventHandler(AliVEventHandler *const handler)
void AddInput(Int_t nevents=1)
void PackOutput(TList *target)
virtual const char * GetExtraOutputs(Bool_t merge=kFALSE) const
void SetUseProgressBar(Bool_t flag, Int_t freq=1)
TObjArray * fZombies
List of zombie tasks.
TObjArray * fOutputs
List of containers with results.
virtual Bool_t Notify()
AliAnalysisSelector Transparent selector class instantiated by an analysis manager object...
void SetInputEventHandler(AliVEventHandler *const handler)
void ExecAnalysis(Option_t *option="")
char * oname
virtual void LocalInit()
Bool_t ConnectInput(Int_t islot, AliAnalysisDataContainer *cont)
Long64_t fNSysInfo
Event frequency for collecting system information.
Double_t fIOTime
! Cumulated time in IO
Bool_t fInitOK
Initialisation done.
void StartTimer(Int_t itask, const char *name, const char *classname="")
static Bool_t IsMacroLoaded(const char *filename)
static void SetVerbose(Bool_t v=kFALSE)
Definition: AliSysInfo.h:30
static AliAnalysisManager * fgAnalysisManager
! static pointer to object instance
Bool_t IsPostEventLoop() const
static Int_t fPBUpdateFreq
Progress bar update freq.
static void SetGlobalInt(const char *key, Int_t value)
TString fSpecialOutputLocation
URL/path where the special outputs will be copied.
TObjArray * fTopTasks
List of top tasks.
TStopwatch * fIOTimer
! Timer for I/O + deserialization
AliVEventHandler * fMCtruthEventHandler
Optional common MC Truth event handler.
AliAnalysisStatistics * fStatistics
Statistics info about input events.
void AddProcessed(Int_t nevents=1)
void AddClassDebug(const char *className, Int_t debugLevel)
void ProfileTask(const char *name, const char *option="VM") const
AliAnalysisDataContainer * fCommonInput
Common input container.
TF1 * f
Definition: interpolTest.C:21
void SetDeleteData(Bool_t flag=kTRUE)
Bool_t fLocked
! Lock for the manager and handlers
AliAnalysisDataSlot * GetInputSlot(Int_t islot) const
static const char * GetOADBPath()
Bool_t ConnectInput(AliAnalysisTask *task, Int_t islot, AliAnalysisDataContainer *cont)
static Double_t GetGlobalDbl(const char *key, Bool_t &valid)
const char * GetFolderName() const
AliAnalysisGrid * fGridHandler
! Grid handler plugin
void GetBranches(const char *type, TString &result) const
mgr
Definition: runKineProof.C:24
virtual void SetInputFileName(const char *)
void SetPostEventLoop(Bool_t flag=kTRUE)
Bool_t IsSkipTerminate() const
virtual Bool_t Terminate()=0
virtual Bool_t MergeOutputs()=0
TObjArray * fFileDescriptors
! List of file descriptors
void AddTask(AliAnalysisTask *task)
TString fExtraFiles
List of extra files to be merged.
void AddStatisticsMsg(const char *line)
void SetUsed(Bool_t flag=kTRUE)
Bool_t fAsyncReading
Enable async reading.
TObjArray * fExchangeCont
List of exchange containers.
virtual Bool_t Notify(const char *path)=0
virtual Bool_t InitTaskInputData(AliVEvent *, AliVfriendEvent *, TObjArray *)
virtual Bool_t CheckPostData() const
virtual Bool_t Init(Option_t *opt)=0
const char * GetFileName() const
virtual const char * GetOutputFileName() const =0
TObjArray * fParamCont
List of containers with parameters.
void ImportWrappers(TList *source)
Bool_t fAutoBranchHandling
def=kTRUE, turn off if you use LoadBranch
void SetFileName(const char *filename)
Long64_t GetCurrentEntry() const
static void ProgressBar(const char *opname, Long64_t current, Long64_t size, TStopwatch *const watch=0, Bool_t last=kFALSE, Bool_t refresh=kFALSE)
void SetExternalLoop(Bool_t flag)
Bool_t IsUsed() const
AliAnalysisDataContainer * GetContainer() const
TObjArray * fDebugOptions
List of debug options.
Long64_t fMaxEntries
Maximum number of entries.
virtual Bool_t SetData(TObject *data, Option_t *option="")
static void AddStamp(const char *sname, Int_t id0=-1, Int_t id1=-1, Int_t id2=-1, Int_t id3=-1)
Definition: AliSysInfo.cxx:179
Int_t debugLevel
Long64_t GetNinput() const
AliVEventHandler * fOutputEventHandler
Optional common output event handler.
Bool_t IsTrainInitialized() const
TObjArray * fInputs
List of containers with input data.
TCut cut
Definition: MakeGlobalFit.C:75
Long64_t fCacheSize
Cache size in bytes.
Double_t fCPUTime
! Cumulated time in Exec
virtual AliVEvent * GetEvent() const
virtual void SetCacheSize(Long64_t)
TString fFileInfoLog
File name for fileinfo logs.
virtual void AdjustMCLabels(const AliVEvent *)
Definition: AliVEvent.h:267
char * fname
Bool_t EventLoop(Long64_t nevents)
Long64_t fCurrentEntry
! Current processed entry in the tree
Int_t debug
UInt_t GetOfflineMask() const
virtual const char * GetProofDataSet() const =0
void InitInputData(AliVEvent *esdEvent, AliVfriendEvent *esdFriend)
Bool_t fMCLoop
External MC generator loop.
void SetTouched(Bool_t flag=kTRUE)
static Bool_t IsPipe(std::ostream &out)
Int_t fRunFromPath
Run number retrieved from path to input data.
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
static Int_t GetGlobalInt(const char *key, Bool_t &valid)
Bool_t CheckTasks() const
AliAnalysisDataContainer * CreateContainer(const char *name, TClass *datatype, EAliAnalysisContType type=kExchangeContainer, const char *filename=NULL)
void CheckBranches(Bool_t load=kFALSE)
void CountEvent(Int_t ninput, Int_t nprocessed, Int_t nfailed, Int_t naccepted)