Manager ignores now all Notify calls coming from the selector level before the first...
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisManager.h
CommitLineData
d3106602 1#ifndef ALIANALYSISMANAGER_H
2#define ALIANALYSISMANAGER_H
3/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * See cxx source for full Copyright notice */
5
6/* $Id$ */
7// Author: Andrei Gheata, 31/05/2006
8
9//==============================================================================
10// AliAnalysysManager - Manager analysis class. Allows creation of several
11// analysis tasks and data containers storing their input/output. Allows
12// connecting/chaining tasks via shared data containers. Serializes the current
13// event for all tasks depending only on initial input data.
14//==============================================================================
15
c52c2132 16#ifndef ROOT_TNamed
17#include <TNamed.h>
d3106602 18#endif
012e169c 19#ifndef ROOT_THashTable
20#include <THashTable.h>
21#endif
8ddad121 22#ifndef ROOT_Riostream
23#include <Riostream.h>
24#endif
d3106602 25
26class TClass;
c52c2132 27class TTree;
8d7d3b59 28class TFile;
cd11251e 29class TStopwatch;
8d7d3b59 30class AliAnalysisSelector;
d3106602 31class AliAnalysisDataContainer;
32class AliAnalysisTask;
d2f1d9ef 33class AliVEventHandler;
c2922515 34class AliVEventPool;
c57f56b7 35class AliAnalysisGrid;
f5cbe261 36class AliAnalysisStatistics;
8c9485b2 37
d3106602 38
c52c2132 39class AliAnalysisManager : public TNamed {
d3106602 40
41public:
42
43enum EAliAnalysisContType {
6cd44ee0 44 kExchangeContainer = 0, // use to exchange data between tasks
45 kInputContainer = 1, // use for the task private input data
46 kOutputContainer = 2, // use for the task private output data
47 kParamContainer = 3 // use for storing task private parameters/cuts per analysis session
d3106602 48};
c52c2132 49
50enum EAliAnalysisExecMode {
51 kLocalAnalysis = 0,
52 kProofAnalysis = 1,
aee5ee44 53 kGridAnalysis = 2,
54 kMixingAnalysis = 3
c52c2132 55};
56
efd53803 57enum EAliAnalysisFlags {
b1310ef5 58 kEventLoop = BIT(14),
d86ed856 59 kDisableBranches = BIT(15),
a0e2e8b1 60 kUseDataSet = BIT(16),
06a59280 61 kSaveCanvases = BIT(17),
90a4b3ee 62 kExternalLoop = BIT(18),
ff0d33e8 63 kSkipTerminate = BIT(19),
20b7268e 64 kUseProgressBar = BIT(20),
65 kTrueNotify = BIT(21)
efd53803 66};
67
6e14aaa2 68 AliAnalysisManager(const char *name = "mgr", const char *title="");
d3106602 69 virtual ~AliAnalysisManager();
c52c2132 70
71 AliAnalysisManager(const AliAnalysisManager& other);
72 AliAnalysisManager& operator=(const AliAnalysisManager& other);
d3106602 73
06a59280 74 // Event loop control
75 virtual Int_t GetEntry(Long64_t entry, Int_t getall = 0);
20b7268e 76 virtual Bool_t Init(TTree *tree);
327eaf46 77 virtual Bool_t Notify();
327eaf46 78 virtual Bool_t ProcessCut(Long64_t entry) {return Process(entry);}
d3106602 79 virtual Bool_t Process(Long64_t entry);
039e671e 80 TFile *OpenProofFile(AliAnalysisDataContainer *cont, const char *option, const char *extaod="");
84fcd93f 81 static TFile *OpenFile(AliAnalysisDataContainer *cont, const char *option, Bool_t ignoreProof=kFALSE);
c52c2132 82 void PackOutput(TList *target);
06a59280 83 void RegisterExtraFile(const char *fname);
27734f0e 84 Long64_t StartAnalysis(const char *type, TTree * const tree, Long64_t nentries=1234567890, Long64_t firstentry=0);
1f87e9fb 85 Long64_t StartAnalysis(const char *type, const char *dataset, Long64_t nentries=1234567890, Long64_t firstentry=0);
27734f0e 86 Long64_t StartAnalysis(const char *type, Long64_t nentries=1234567890, Long64_t firstentry=0);
06a59280 87 virtual void SlaveBegin(TTree *tree);
d3106602 88 virtual void Terminate();
06a59280 89 void UnpackOutput(TList *source);
d3106602 90
c52c2132 91 // Getters/Setters
92 static AliAnalysisManager *GetAnalysisManager() {return fgAnalysisManager;}
c52c2132 93 EAliAnalysisExecMode
06a59280 94 GetAnalysisType() const {return fMode;}
d29168d6 95 void GetAnalysisTypeString(TString &type) const;
012e169c 96 Bool_t GetAutoBranchLoading() const {return fAutoBranchHandling;}
06a59280 97 static const char *GetCommonFileName() {return fgCommonFileName.Data();}
98 AliAnalysisDataContainer *
61505f8b 99 GetCommonInputContainer() const {return fCommonInput;}
06a59280 100 AliAnalysisDataContainer *
61505f8b 101 GetCommonOutputContainer() const {return fCommonOutput;}
06a59280 102 TObjArray *GetContainers() const {return fContainers;}
103 Long64_t GetCurrentEntry() const {return fCurrentEntry;}
104 UInt_t GetDebugLevel() const {return fDebug;}
105 TString GetExtraFiles() const {return fExtraFiles;}
61505f8b 106 AliVEventPool* GetEventPool() const {return fEventPool;}
107 Bool_t GetFileFromWrapper(const char *filename, const TList *source);
242accb2 108 static Int_t GetRunFromAlienPath(const char *path);
06a59280 109 AliAnalysisGrid* GetGridHandler() {return fGridHandler;}
110 TObjArray *GetInputs() const {return fInputs;}
61505f8b 111 AliVEventHandler* GetInputEventHandler() const {return fInputEventHandler;}
112 AliVEventHandler* GetMCtruthEventHandler() const {return fMCtruthEventHandler;}
113 AliVEventHandler* GetOutputEventHandler() const {return fOutputEventHandler;}
06a59280 114 TObjArray *GetOutputs() const {return fOutputs;}
ff07ec61 115 TObjArray *GetParamOutputs() const {return fParamCont;}
242accb2 116 Int_t GetRunFromPath() const {return fRunFromPath;}
7acc5b9d 117 const char *GetRequestedBranches() const {return fRequestedBranches.Data();}
06a59280 118 TObjArray *GetTasks() const {return fTasks;}
119 TObjArray *GetTopTasks() const {return fTopTasks;}
120 TTree *GetTree() const {return fTree;}
121 TObjArray *GetZombieTasks() const {return fZombies;}
8ddad121 122 static Bool_t IsPipe(std::ostream &out);
d791fad6 123 Bool_t IsProofMode() const {return (fMode==kProofAnalysis)?kTRUE:kFALSE;}
8e1f0465 124 Bool_t IsRemote() const {return fIsRemote;}
06a59280 125 Bool_t IsUsingDataSet() const {return TObject::TestBit(kUseDataSet);}
012e169c 126 void LoadBranch(const char *n) { if(fAutoBranchHandling) return; DoLoadBranch(n); }
c52c2132 127 void SetAnalysisType(EAliAnalysisExecMode mode) {fMode = mode;}
012e169c 128 void SetAutoBranchLoading(Bool_t b) { fAutoBranchHandling = b; }
06a59280 129 void SetCurrentEntry(Long64_t entry) {fCurrentEntry = entry;}
130 void SetCollectSysInfoEach(Int_t nevents=0) {fNSysInfo = nevents;}
131 static void SetCommonFileName(const char *name) {fgCommonFileName = name;}
f03a8355 132 void SetDebugLevel(UInt_t level);
06a59280 133 void SetDisableBranches(Bool_t disable=kTRUE) {TObject::SetBit(kDisableBranches,disable);}
134 void SetExternalLoop(Bool_t flag) {TObject::SetBit(kExternalLoop,flag);}
61505f8b 135 void SetEventPool(AliVEventPool* const epool) {fEventPool = epool;}
136 void SetGridHandler(AliAnalysisGrid * const handler) {fGridHandler = handler;}
137 void SetInputEventHandler(AliVEventHandler* const handler);
138 void SetMCtruthEventHandler(AliVEventHandler* const handler) {fMCtruthEventHandler = handler;}
06a59280 139 void SetNSysInfo(Long64_t nevents) {fNSysInfo = nevents;}
61505f8b 140 void SetOutputEventHandler(AliVEventHandler* const handler);
242accb2 141 void SetRunFromPath(Int_t run) {fRunFromPath = run;}
61505f8b 142 void SetSelector(AliAnalysisSelector * const sel) {fSelector = sel;}
06a59280 143 void SetSaveCanvases(Bool_t flag=kTRUE) {TObject::SetBit(kSaveCanvases,flag);}
90a4b3ee 144 void SetSkipTerminate(Bool_t flag) {TObject::SetBit(kSkipTerminate,flag);}
f03a8355 145 void SetUseProgressBar(Bool_t flag, Int_t freq=1);
06a59280 146 void SetSpecialOutputLocation(const char *loc) {fSpecialOutputLocation = loc;}
d3106602 147
148 // Container handling
149 AliAnalysisDataContainer *CreateContainer(const char *name, TClass *datatype,
c52c2132 150 EAliAnalysisContType type = kExchangeContainer,
151 const char *filename = NULL);
d3106602 152
153 // Including tasks and getting them
154 void AddTask(AliAnalysisTask *task);
155 AliAnalysisTask *GetTask(const char *name) const;
156
157 // Connecting data containers to task inputs/outputs
158 Bool_t ConnectInput(AliAnalysisTask *task, Int_t islot,
159 AliAnalysisDataContainer *cont);
160 Bool_t ConnectOutput(AliAnalysisTask *task, Int_t islot,
161 AliAnalysisDataContainer *cont);
162 // Garbage collection
163 void CleanContainers();
164
165 // Analysis initialization and execution, status
7acc5b9d 166 void AddBranches(const char *branches);
c3732d79 167 void AddStatisticsTask(UInt_t offlineMask=0);
7acc5b9d 168 void CheckBranches(Bool_t load=kFALSE);
4747b4a7 169 Bool_t CheckTasks() const;
f5cbe261 170 void CountEvent(Int_t ninput, Int_t nprocessed, Int_t nfailed, Int_t naccepted);
d3106602 171 Bool_t InitAnalysis();
172 Bool_t IsInitialized() const {return fInitOK;}
90a4b3ee 173 Bool_t IsExternalLoop() const {return TObject::TestBit(kExternalLoop);}
efd53803 174 Bool_t IsEventLoop() const {return TObject::TestBit(kEventLoop);}
90a4b3ee 175 Bool_t IsSkipTerminate() const {return TObject::TestBit(kSkipTerminate);}
d3106602 176 void ResetAnalysis();
177 void ExecAnalysis(Option_t *option="");
d3106602 178 void PrintStatus(Option_t *option="all") const;
096b5a2e 179 void ProfileTask(const char *name, const char *option="VM") const;
180 void ProfileTask(Int_t itop, const char *option="VM") const;
61505f8b 181 static void ProgressBar(const char *opname, Long64_t current, Long64_t size, TStopwatch * const watch=0, Bool_t last=kFALSE, Bool_t refresh=kFALSE);
e9247450 182 void AddStatisticsMsg(const char *line);
183 const char *GetStatisticsMsg() const {return fStatisticsMsg.Data();}
f5cbe261 184 const AliAnalysisStatistics *GetStatistics() const {return fStatistics;}
c3732d79 185 void SetStatistics(AliAnalysisStatistics *stat) {fStatistics = stat;}
e9247450 186 void WriteStatisticsMsg(Int_t nevents);
187 Int_t GetNcalls() const {return fNcalls;}
923e2ca5 188 Bool_t ValidateOutputFiles() const;
37196805 189
190 static const char* GetOADBPath();
d3106602 191
192protected:
981f2614 193 void ImportWrappers(TList *source);
efd53803 194 void SetEventLoop(Bool_t flag=kTRUE) {TObject::SetBit(kEventLoop,flag);}
012e169c 195 void DoLoadBranch(const char *name);
d3106602 196
5daf9fd2 197private:
6bb2b24f 198 TTree *fTree; //! Input tree in case of TSelector model
54cff064 199 AliVEventHandler *fInputEventHandler; // Optional common input event handler
d2f1d9ef 200 AliVEventHandler *fOutputEventHandler; // Optional common output event handler
201 AliVEventHandler *fMCtruthEventHandler; // Optional common MC Truth event handler
c2922515 202 AliVEventPool *fEventPool; // Event pool for mixing analysis
6bb2b24f 203 Long64_t fCurrentEntry; //! Current processed entry in the tree
8c0ab8e8 204 Long64_t fNSysInfo; // Event frequency for collecting system information
6bb2b24f 205 EAliAnalysisExecMode fMode; // Execution mode
206 Bool_t fInitOK; // Initialisation done
8e1f0465 207 Bool_t fIsRemote; //! Flag is set for remote analysis
6bb2b24f 208 UInt_t fDebug; // Debug level
13ef3bb0 209 TString fSpecialOutputLocation; // URL/path where the special outputs will be copied
6bb2b24f 210 TObjArray *fTasks; // List of analysis tasks
211 TObjArray *fTopTasks; // List of top tasks
212 TObjArray *fZombies; // List of zombie tasks
213 TObjArray *fContainers; // List of all containers
214 TObjArray *fInputs; // List of containers with input data
215 TObjArray *fOutputs; // List of containers with results
ff07ec61 216 TObjArray *fParamCont; // List of containers with results
60a04972 217 AliAnalysisDataContainer *fCommonInput; // Common input container
218 AliAnalysisDataContainer *fCommonOutput; // Common output container
8d7d3b59 219 AliAnalysisSelector *fSelector; //! Current selector
c57f56b7 220 AliAnalysisGrid *fGridHandler; //! Grid handler plugin
c9e39043 221 TString fExtraFiles; // List of extra files to be merged
012e169c 222 Bool_t fAutoBranchHandling; // def=kTRUE, turn off if you use LoadBranch
223 THashTable fTable; // keep branch ptrs in case of manual branch loading
242accb2 224 Int_t fRunFromPath; // Run number retrieved from path to input data
e9247450 225 Int_t fNcalls; // Total number of calls (events) of ExecAnalysis
f03a8355 226 Long64_t fMaxEntries; // Maximum number of entries
227 static Int_t fPBUpdateFreq; // Progress bar update freq.
e9247450 228 TString fStatisticsMsg; // Statistics user message
7acc5b9d 229 TString fRequestedBranches; // Requested branch names
f5cbe261 230 AliAnalysisStatistics *fStatistics; // Statistics info about input events
84fcd93f 231 static TString fgCommonFileName; //! Common output file name (not streamed)
c52c2132 232 static AliAnalysisManager *fgAnalysisManager; //! static pointer to object instance
f03a8355 233 ClassDef(AliAnalysisManager,13) // Analysis manager class
d3106602 234};
235#endif