Forgot to increase class version
[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
d3106602 22
23class TClass;
c52c2132 24class TTree;
8d7d3b59 25class TFile;
cd11251e 26class TStopwatch;
8d7d3b59 27class AliAnalysisSelector;
d3106602 28class AliAnalysisDataContainer;
29class AliAnalysisTask;
d2f1d9ef 30class AliVEventHandler;
c2922515 31class AliVEventPool;
c57f56b7 32class AliAnalysisGrid;
8c9485b2 33
d3106602 34
c52c2132 35class AliAnalysisManager : public TNamed {
d3106602 36
37public:
38
39enum EAliAnalysisContType {
6cd44ee0 40 kExchangeContainer = 0, // use to exchange data between tasks
41 kInputContainer = 1, // use for the task private input data
42 kOutputContainer = 2, // use for the task private output data
43 kParamContainer = 3 // use for storing task private parameters/cuts per analysis session
d3106602 44};
c52c2132 45
46enum EAliAnalysisExecMode {
47 kLocalAnalysis = 0,
48 kProofAnalysis = 1,
aee5ee44 49 kGridAnalysis = 2,
50 kMixingAnalysis = 3
c52c2132 51};
52
efd53803 53enum EAliAnalysisFlags {
b1310ef5 54 kEventLoop = BIT(14),
d86ed856 55 kDisableBranches = BIT(15),
a0e2e8b1 56 kUseDataSet = BIT(16),
06a59280 57 kSaveCanvases = BIT(17),
90a4b3ee 58 kExternalLoop = BIT(18),
ff0d33e8 59 kSkipTerminate = BIT(19),
60 kUseProgressBar = BIT(20)
efd53803 61};
62
6e14aaa2 63 AliAnalysisManager(const char *name = "mgr", const char *title="");
d3106602 64 virtual ~AliAnalysisManager();
c52c2132 65
66 AliAnalysisManager(const AliAnalysisManager& other);
67 AliAnalysisManager& operator=(const AliAnalysisManager& other);
d3106602 68
06a59280 69 // Event loop control
70 virtual Int_t GetEntry(Long64_t entry, Int_t getall = 0);
2d626244 71 virtual Bool_t Init(TTree *tree);
327eaf46 72 virtual Bool_t Notify();
327eaf46 73 virtual Bool_t ProcessCut(Long64_t entry) {return Process(entry);}
d3106602 74 virtual Bool_t Process(Long64_t entry);
84fcd93f 75 TFile *OpenProofFile(AliAnalysisDataContainer *cont, const char *option);
76 static TFile *OpenFile(AliAnalysisDataContainer *cont, const char *option, Bool_t ignoreProof=kFALSE);
c52c2132 77 void PackOutput(TList *target);
06a59280 78 void RegisterExtraFile(const char *fname);
27734f0e 79 Long64_t StartAnalysis(const char *type, TTree * const tree, Long64_t nentries=1234567890, Long64_t firstentry=0);
1f87e9fb 80 Long64_t StartAnalysis(const char *type, const char *dataset, Long64_t nentries=1234567890, Long64_t firstentry=0);
27734f0e 81 Long64_t StartAnalysis(const char *type, Long64_t nentries=1234567890, Long64_t firstentry=0);
06a59280 82 virtual void SlaveBegin(TTree *tree);
d3106602 83 virtual void Terminate();
06a59280 84 void UnpackOutput(TList *source);
d3106602 85
c52c2132 86 // Getters/Setters
87 static AliAnalysisManager *GetAnalysisManager() {return fgAnalysisManager;}
c52c2132 88 EAliAnalysisExecMode
06a59280 89 GetAnalysisType() const {return fMode;}
d29168d6 90 void GetAnalysisTypeString(TString &type) const;
012e169c 91 Bool_t GetAutoBranchLoading() const {return fAutoBranchHandling;}
06a59280 92 static const char *GetCommonFileName() {return fgCommonFileName.Data();}
93 AliAnalysisDataContainer *
61505f8b 94 GetCommonInputContainer() const {return fCommonInput;}
06a59280 95 AliAnalysisDataContainer *
61505f8b 96 GetCommonOutputContainer() const {return fCommonOutput;}
06a59280 97 TObjArray *GetContainers() const {return fContainers;}
98 Long64_t GetCurrentEntry() const {return fCurrentEntry;}
99 UInt_t GetDebugLevel() const {return fDebug;}
100 TString GetExtraFiles() const {return fExtraFiles;}
61505f8b 101 AliVEventPool* GetEventPool() const {return fEventPool;}
102 Bool_t GetFileFromWrapper(const char *filename, const TList *source);
242accb2 103 static Int_t GetRunFromAlienPath(const char *path);
06a59280 104 AliAnalysisGrid* GetGridHandler() {return fGridHandler;}
105 TObjArray *GetInputs() const {return fInputs;}
61505f8b 106 AliVEventHandler* GetInputEventHandler() const {return fInputEventHandler;}
107 AliVEventHandler* GetMCtruthEventHandler() const {return fMCtruthEventHandler;}
108 AliVEventHandler* GetOutputEventHandler() const {return fOutputEventHandler;}
06a59280 109 TObjArray *GetOutputs() const {return fOutputs;}
ff07ec61 110 TObjArray *GetParamOutputs() const {return fParamCont;}
242accb2 111 Int_t GetRunFromPath() const {return fRunFromPath;}
06a59280 112 TObjArray *GetTasks() const {return fTasks;}
113 TObjArray *GetTopTasks() const {return fTopTasks;}
114 TTree *GetTree() const {return fTree;}
115 TObjArray *GetZombieTasks() const {return fZombies;}
d791fad6 116 Bool_t IsProofMode() const {return (fMode==kProofAnalysis)?kTRUE:kFALSE;}
8e1f0465 117 Bool_t IsRemote() const {return fIsRemote;}
06a59280 118 Bool_t IsUsingDataSet() const {return TObject::TestBit(kUseDataSet);}
012e169c 119 void LoadBranch(const char *n) { if(fAutoBranchHandling) return; DoLoadBranch(n); }
c52c2132 120 void SetAnalysisType(EAliAnalysisExecMode mode) {fMode = mode;}
012e169c 121 void SetAutoBranchLoading(Bool_t b) { fAutoBranchHandling = b; }
06a59280 122 void SetCurrentEntry(Long64_t entry) {fCurrentEntry = entry;}
123 void SetCollectSysInfoEach(Int_t nevents=0) {fNSysInfo = nevents;}
124 static void SetCommonFileName(const char *name) {fgCommonFileName = name;}
125 void SetDebugLevel(UInt_t level) {fDebug = level;}
126 void SetDisableBranches(Bool_t disable=kTRUE) {TObject::SetBit(kDisableBranches,disable);}
127 void SetExternalLoop(Bool_t flag) {TObject::SetBit(kExternalLoop,flag);}
61505f8b 128 void SetEventPool(AliVEventPool* const epool) {fEventPool = epool;}
129 void SetGridHandler(AliAnalysisGrid * const handler) {fGridHandler = handler;}
130 void SetInputEventHandler(AliVEventHandler* const handler);
131 void SetMCtruthEventHandler(AliVEventHandler* const handler) {fMCtruthEventHandler = handler;}
06a59280 132 void SetNSysInfo(Long64_t nevents) {fNSysInfo = nevents;}
61505f8b 133 void SetOutputEventHandler(AliVEventHandler* const handler);
242accb2 134 void SetRunFromPath(Int_t run) {fRunFromPath = run;}
61505f8b 135 void SetSelector(AliAnalysisSelector * const sel) {fSelector = sel;}
06a59280 136 void SetSaveCanvases(Bool_t flag=kTRUE) {TObject::SetBit(kSaveCanvases,flag);}
90a4b3ee 137 void SetSkipTerminate(Bool_t flag) {TObject::SetBit(kSkipTerminate,flag);}
ff0d33e8 138 void SetUseProgressBar(Bool_t flag) {TObject::SetBit(kUseProgressBar,flag);}
06a59280 139 void SetSpecialOutputLocation(const char *loc) {fSpecialOutputLocation = loc;}
d3106602 140
141 // Container handling
142 AliAnalysisDataContainer *CreateContainer(const char *name, TClass *datatype,
c52c2132 143 EAliAnalysisContType type = kExchangeContainer,
144 const char *filename = NULL);
d3106602 145
146 // Including tasks and getting them
147 void AddTask(AliAnalysisTask *task);
148 AliAnalysisTask *GetTask(const char *name) const;
149
150 // Connecting data containers to task inputs/outputs
151 Bool_t ConnectInput(AliAnalysisTask *task, Int_t islot,
152 AliAnalysisDataContainer *cont);
153 Bool_t ConnectOutput(AliAnalysisTask *task, Int_t islot,
154 AliAnalysisDataContainer *cont);
155 // Garbage collection
156 void CleanContainers();
157
158 // Analysis initialization and execution, status
159 Bool_t InitAnalysis();
160 Bool_t IsInitialized() const {return fInitOK;}
90a4b3ee 161 Bool_t IsExternalLoop() const {return TObject::TestBit(kExternalLoop);}
efd53803 162 Bool_t IsEventLoop() const {return TObject::TestBit(kEventLoop);}
90a4b3ee 163 Bool_t IsSkipTerminate() const {return TObject::TestBit(kSkipTerminate);}
d3106602 164 void ResetAnalysis();
165 void ExecAnalysis(Option_t *option="");
d3106602 166 void PrintStatus(Option_t *option="all") const;
096b5a2e 167 void ProfileTask(const char *name, const char *option="VM") const;
168 void ProfileTask(Int_t itop, const char *option="VM") const;
61505f8b 169 static void ProgressBar(const char *opname, Long64_t current, Long64_t size, TStopwatch * const watch=0, Bool_t last=kFALSE, Bool_t refresh=kFALSE);
923e2ca5 170 Bool_t ValidateOutputFiles() const;
d3106602 171
172protected:
981f2614 173 void ImportWrappers(TList *source);
efd53803 174 void SetEventLoop(Bool_t flag=kTRUE) {TObject::SetBit(kEventLoop,flag);}
012e169c 175 void DoLoadBranch(const char *name);
d3106602 176
5daf9fd2 177private:
6bb2b24f 178 TTree *fTree; //! Input tree in case of TSelector model
54cff064 179 AliVEventHandler *fInputEventHandler; // Optional common input event handler
d2f1d9ef 180 AliVEventHandler *fOutputEventHandler; // Optional common output event handler
181 AliVEventHandler *fMCtruthEventHandler; // Optional common MC Truth event handler
c2922515 182 AliVEventPool *fEventPool; // Event pool for mixing analysis
6bb2b24f 183 Long64_t fCurrentEntry; //! Current processed entry in the tree
8c0ab8e8 184 Long64_t fNSysInfo; // Event frequency for collecting system information
6bb2b24f 185 EAliAnalysisExecMode fMode; // Execution mode
186 Bool_t fInitOK; // Initialisation done
8e1f0465 187 Bool_t fIsRemote; //! Flag is set for remote analysis
6bb2b24f 188 UInt_t fDebug; // Debug level
13ef3bb0 189 TString fSpecialOutputLocation; // URL/path where the special outputs will be copied
6bb2b24f 190 TObjArray *fTasks; // List of analysis tasks
191 TObjArray *fTopTasks; // List of top tasks
192 TObjArray *fZombies; // List of zombie tasks
193 TObjArray *fContainers; // List of all containers
194 TObjArray *fInputs; // List of containers with input data
195 TObjArray *fOutputs; // List of containers with results
ff07ec61 196 TObjArray *fParamCont; // List of containers with results
60a04972 197 AliAnalysisDataContainer *fCommonInput; // Common input container
198 AliAnalysisDataContainer *fCommonOutput; // Common output container
8d7d3b59 199 AliAnalysisSelector *fSelector; //! Current selector
c57f56b7 200 AliAnalysisGrid *fGridHandler; //! Grid handler plugin
c9e39043 201 TString fExtraFiles; // List of extra files to be merged
012e169c 202 Bool_t fAutoBranchHandling; // def=kTRUE, turn off if you use LoadBranch
203 THashTable fTable; // keep branch ptrs in case of manual branch loading
242accb2 204 Int_t fRunFromPath; // Run number retrieved from path to input data
5daf9fd2 205
84fcd93f 206 static TString fgCommonFileName; //! Common output file name (not streamed)
c52c2132 207 static AliAnalysisManager *fgAnalysisManager; //! static pointer to object instance
11c09e87 208 ClassDef(AliAnalysisManager,9) // Analysis manager class
d3106602 209};
210#endif