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