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