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 */
7 // Author: Andrei Gheata, 31/05/2006
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 //==============================================================================
19 #ifndef ROOT_THashTable
20 #include <THashTable.h>
22 #ifndef ROOT_Riostream
23 #include <Riostream.h>
30 class AliAnalysisSelector;
31 class AliAnalysisDataContainer;
32 class AliAnalysisTask;
33 class AliVEventHandler;
35 class AliAnalysisGrid;
36 class AliAnalysisStatistics;
39 class AliAnalysisManager : public TNamed {
43 enum EAliAnalysisContType {
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
50 enum EAliAnalysisExecMode {
57 enum EAliAnalysisFlags {
59 kDisableBranches = BIT(15),
60 kUseDataSet = BIT(16),
61 kSaveCanvases = BIT(17),
62 kExternalLoop = BIT(18),
63 kSkipTerminate = BIT(19),
64 kUseProgressBar = BIT(20)
67 AliAnalysisManager(const char *name = "mgr", const char *title="");
68 virtual ~AliAnalysisManager();
70 AliAnalysisManager(const AliAnalysisManager& other);
71 AliAnalysisManager& operator=(const AliAnalysisManager& other);
74 virtual Int_t GetEntry(Long64_t entry, Int_t getall = 0);
75 virtual Bool_t Init(TTree *tree);
76 virtual Bool_t Notify();
77 virtual Bool_t ProcessCut(Long64_t entry) {return Process(entry);}
78 virtual Bool_t Process(Long64_t entry);
79 TFile *OpenProofFile(AliAnalysisDataContainer *cont, const char *option, const char *extaod="");
80 static TFile *OpenFile(AliAnalysisDataContainer *cont, const char *option, Bool_t ignoreProof=kFALSE);
81 void PackOutput(TList *target);
82 void RegisterExtraFile(const char *fname);
83 Long64_t StartAnalysis(const char *type, TTree * const tree, Long64_t nentries=1234567890, Long64_t firstentry=0);
84 Long64_t StartAnalysis(const char *type, const char *dataset, Long64_t nentries=1234567890, Long64_t firstentry=0);
85 Long64_t StartAnalysis(const char *type, Long64_t nentries=1234567890, Long64_t firstentry=0);
86 virtual void SlaveBegin(TTree *tree);
87 virtual void Terminate();
88 void UnpackOutput(TList *source);
91 static AliAnalysisManager *GetAnalysisManager() {return fgAnalysisManager;}
93 GetAnalysisType() const {return fMode;}
94 void GetAnalysisTypeString(TString &type) const;
95 Bool_t GetAutoBranchLoading() const {return fAutoBranchHandling;}
96 static const char *GetCommonFileName() {return fgCommonFileName.Data();}
97 AliAnalysisDataContainer *
98 GetCommonInputContainer() const {return fCommonInput;}
99 AliAnalysisDataContainer *
100 GetCommonOutputContainer() const {return fCommonOutput;}
101 TObjArray *GetContainers() const {return fContainers;}
102 Long64_t GetCurrentEntry() const {return fCurrentEntry;}
103 UInt_t GetDebugLevel() const {return fDebug;}
104 TString GetExtraFiles() const {return fExtraFiles;}
105 AliVEventPool* GetEventPool() const {return fEventPool;}
106 Bool_t GetFileFromWrapper(const char *filename, const TList *source);
107 static Int_t GetRunFromAlienPath(const char *path);
108 AliAnalysisGrid* GetGridHandler() {return fGridHandler;}
109 TObjArray *GetInputs() const {return fInputs;}
110 AliVEventHandler* GetInputEventHandler() const {return fInputEventHandler;}
111 AliVEventHandler* GetMCtruthEventHandler() const {return fMCtruthEventHandler;}
112 AliVEventHandler* GetOutputEventHandler() const {return fOutputEventHandler;}
113 TObjArray *GetOutputs() const {return fOutputs;}
114 TObjArray *GetParamOutputs() const {return fParamCont;}
115 Int_t GetRunFromPath() const {return fRunFromPath;}
116 const char *GetRequestedBranches() const {return fRequestedBranches.Data();}
117 TObjArray *GetTasks() const {return fTasks;}
118 TObjArray *GetTopTasks() const {return fTopTasks;}
119 TTree *GetTree() const {return fTree;}
120 TObjArray *GetZombieTasks() const {return fZombies;}
121 static Bool_t IsPipe(std::ostream &out);
122 Bool_t IsProofMode() const {return (fMode==kProofAnalysis)?kTRUE:kFALSE;}
123 Bool_t IsRemote() const {return fIsRemote;}
124 Bool_t IsUsingDataSet() const {return TObject::TestBit(kUseDataSet);}
125 void LoadBranch(const char *n) { if(fAutoBranchHandling) return; DoLoadBranch(n); }
126 void SetAnalysisType(EAliAnalysisExecMode mode) {fMode = mode;}
127 void SetAutoBranchLoading(Bool_t b) { fAutoBranchHandling = b; }
128 void SetCurrentEntry(Long64_t entry) {fCurrentEntry = entry;}
129 void SetCollectSysInfoEach(Int_t nevents=0) {fNSysInfo = nevents;}
130 static void SetCommonFileName(const char *name) {fgCommonFileName = name;}
131 void SetDebugLevel(UInt_t level);
132 void SetDisableBranches(Bool_t disable=kTRUE) {TObject::SetBit(kDisableBranches,disable);}
133 void SetExternalLoop(Bool_t flag) {TObject::SetBit(kExternalLoop,flag);}
134 void SetEventPool(AliVEventPool* const epool) {fEventPool = epool;}
135 void SetGridHandler(AliAnalysisGrid * const handler) {fGridHandler = handler;}
136 void SetInputEventHandler(AliVEventHandler* const handler);
137 void SetMCtruthEventHandler(AliVEventHandler* const handler) {fMCtruthEventHandler = handler;}
138 void SetNSysInfo(Long64_t nevents) {fNSysInfo = nevents;}
139 void SetOutputEventHandler(AliVEventHandler* const handler);
140 void SetRunFromPath(Int_t run) {fRunFromPath = run;}
141 void SetSelector(AliAnalysisSelector * const sel) {fSelector = sel;}
142 void SetSaveCanvases(Bool_t flag=kTRUE) {TObject::SetBit(kSaveCanvases,flag);}
143 void SetSkipTerminate(Bool_t flag) {TObject::SetBit(kSkipTerminate,flag);}
144 void SetUseProgressBar(Bool_t flag, Int_t freq=1);
145 void SetSpecialOutputLocation(const char *loc) {fSpecialOutputLocation = loc;}
147 // Container handling
148 AliAnalysisDataContainer *CreateContainer(const char *name, TClass *datatype,
149 EAliAnalysisContType type = kExchangeContainer,
150 const char *filename = NULL);
152 // Including tasks and getting them
153 void AddTask(AliAnalysisTask *task);
154 AliAnalysisTask *GetTask(const char *name) const;
156 // Connecting data containers to task inputs/outputs
157 Bool_t ConnectInput(AliAnalysisTask *task, Int_t islot,
158 AliAnalysisDataContainer *cont);
159 Bool_t ConnectOutput(AliAnalysisTask *task, Int_t islot,
160 AliAnalysisDataContainer *cont);
161 // Garbage collection
162 void CleanContainers();
164 // Analysis initialization and execution, status
165 void AddBranches(const char *branches);
166 void AddStatisticsTask(UInt_t offlineMask=0);
167 void CheckBranches(Bool_t load=kFALSE);
168 Bool_t CheckTasks() const;
169 void CountEvent(Int_t ninput, Int_t nprocessed, Int_t nfailed, Int_t naccepted);
170 Bool_t InitAnalysis();
171 Bool_t IsInitialized() const {return fInitOK;}
172 Bool_t IsExternalLoop() const {return TObject::TestBit(kExternalLoop);}
173 Bool_t IsEventLoop() const {return TObject::TestBit(kEventLoop);}
174 Bool_t IsSkipTerminate() const {return TObject::TestBit(kSkipTerminate);}
175 void ResetAnalysis();
176 void ExecAnalysis(Option_t *option="");
177 void PrintStatus(Option_t *option="all") const;
178 void ProfileTask(const char *name, const char *option="VM") const;
179 void ProfileTask(Int_t itop, const char *option="VM") const;
180 static void ProgressBar(const char *opname, Long64_t current, Long64_t size, TStopwatch * const watch=0, Bool_t last=kFALSE, Bool_t refresh=kFALSE);
181 void AddStatisticsMsg(const char *line);
182 const char *GetStatisticsMsg() const {return fStatisticsMsg.Data();}
183 const AliAnalysisStatistics *GetStatistics() const {return fStatistics;}
184 void SetStatistics(AliAnalysisStatistics *stat) {fStatistics = stat;}
185 void WriteStatisticsMsg(Int_t nevents);
186 Int_t GetNcalls() const {return fNcalls;}
187 Bool_t ValidateOutputFiles() const;
189 static const char* GetOADBPath();
192 void ImportWrappers(TList *source);
193 void SetEventLoop(Bool_t flag=kTRUE) {TObject::SetBit(kEventLoop,flag);}
194 void DoLoadBranch(const char *name);
197 TTree *fTree; //! Input tree in case of TSelector model
198 AliVEventHandler *fInputEventHandler; // Optional common input event handler
199 AliVEventHandler *fOutputEventHandler; // Optional common output event handler
200 AliVEventHandler *fMCtruthEventHandler; // Optional common MC Truth event handler
201 AliVEventPool *fEventPool; // Event pool for mixing analysis
202 Long64_t fCurrentEntry; //! Current processed entry in the tree
203 Long64_t fNSysInfo; // Event frequency for collecting system information
204 EAliAnalysisExecMode fMode; // Execution mode
205 Bool_t fInitOK; // Initialisation done
206 Bool_t fIsRemote; //! Flag is set for remote analysis
207 UInt_t fDebug; // Debug level
208 TString fSpecialOutputLocation; // URL/path where the special outputs will be copied
209 TObjArray *fTasks; // List of analysis tasks
210 TObjArray *fTopTasks; // List of top tasks
211 TObjArray *fZombies; // List of zombie tasks
212 TObjArray *fContainers; // List of all containers
213 TObjArray *fInputs; // List of containers with input data
214 TObjArray *fOutputs; // List of containers with results
215 TObjArray *fParamCont; // List of containers with results
216 AliAnalysisDataContainer *fCommonInput; // Common input container
217 AliAnalysisDataContainer *fCommonOutput; // Common output container
218 AliAnalysisSelector *fSelector; //! Current selector
219 AliAnalysisGrid *fGridHandler; //! Grid handler plugin
220 TString fExtraFiles; // List of extra files to be merged
221 Bool_t fAutoBranchHandling; // def=kTRUE, turn off if you use LoadBranch
222 THashTable fTable; // keep branch ptrs in case of manual branch loading
223 Int_t fRunFromPath; // Run number retrieved from path to input data
224 Int_t fNcalls; // Total number of calls (events) of ExecAnalysis
225 Long64_t fMaxEntries; // Maximum number of entries
226 static Int_t fPBUpdateFreq; // Progress bar update freq.
227 TString fStatisticsMsg; // Statistics user message
228 TString fRequestedBranches; // Requested branch names
229 AliAnalysisStatistics *fStatistics; // Statistics info about input events
230 static TString fgCommonFileName; //! Common output file name (not streamed)
231 static AliAnalysisManager *fgAnalysisManager; //! static pointer to object instance
232 ClassDef(AliAnalysisManager,13) // Analysis manager class