]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisManager.h
3c95aa4c214b1e1f82fbc3be0220a794ff2dcb9b
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisManager.h
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
16 #ifndef ROOT_TNamed
17 #include <TNamed.h>
18 #endif
19
20 class TClass;
21 class TTree;
22 class TFile;
23 class AliAnalysisSelector;
24 class AliAnalysisDataContainer;
25 class AliAnalysisTask;
26 class AliVEventHandler;
27 class AliVEventPool;
28 class AliAnalysisGrid;
29
30
31 class AliAnalysisManager : public TNamed {
32
33 public:
34
35 enum EAliAnalysisContType {
36    kExchangeContainer  = 0,
37    kInputContainer   = 1,
38    kOutputContainer  = 2
39 };   
40
41 enum EAliAnalysisExecMode {
42    kLocalAnalysis    = 0,
43    kProofAnalysis    = 1,
44    kGridAnalysis     = 2,
45    kMixingAnalysis   = 3
46 };
47
48 enum EAliAnalysisFlags {
49    kEventLoop        = BIT(14),
50    kDisableBranches  = BIT(15),
51    kUseDataSet       = BIT(16)
52 };   
53
54    AliAnalysisManager(const char *name = "mgr", const char *title="");
55    virtual            ~AliAnalysisManager();
56
57    AliAnalysisManager(const AliAnalysisManager& other);
58    AliAnalysisManager& operator=(const AliAnalysisManager& other);
59    
60    // Management
61    void                StartAnalysis(const char *type="local", TTree *tree=0, Long64_t nentries=1234567890, Long64_t firstentry=0);
62    void                StartAnalysis(const char *type, const char *dataset, Long64_t nentries=1234567890, Long64_t firstentry=0);
63
64    virtual Bool_t      Init(TTree *tree);   
65    virtual Bool_t      Notify();
66    virtual void        SlaveBegin(TTree *tree);
67    virtual Bool_t      ProcessCut(Long64_t entry) {return Process(entry);}
68    virtual Bool_t      Process(Long64_t entry);
69    virtual Int_t       GetEntry(Long64_t entry, Int_t getall = 0);
70    TFile              *OpenProofFile(const char *name, const char *option);
71    void                PackOutput(TList *target);
72    void                UnpackOutput(TList *source);
73    virtual void        Terminate();
74
75    // Getters/Setters
76    static AliAnalysisManager *GetAnalysisManager() {return fgAnalysisManager;}
77    TObjArray          *GetContainers() const {return fContainers;}
78    UInt_t              GetDebugLevel() const {return fDebug;}
79    TObjArray          *GetInputs() const     {return fInputs;}
80    TObjArray          *GetOutputs() const    {return fOutputs;}
81    TObjArray          *GetTasks() const      {return fTasks;}
82    TObjArray          *GetTopTasks() const   {return fTopTasks;}
83    TTree              *GetTree() const       {return fTree;}
84    TObjArray          *GetZombieTasks() const {return fZombies;}
85    Long64_t            GetCurrentEntry() const {return fCurrentEntry;}
86    EAliAnalysisExecMode 
87                        GetAnalysisType() const {return fMode;}
88    Bool_t              IsUsingDataSet() const  {return TObject::TestBit(kUseDataSet);}
89
90    void                SetAnalysisType(EAliAnalysisExecMode mode) {fMode = mode;}
91    void                SetCurrentEntry(Long64_t entry) {fCurrentEntry = entry;}
92    void                SetDebugLevel(UInt_t level) {fDebug = level;}
93    void                SetSpecialOutputLocation(const char *location) {fSpecialOutputLocation = location;}
94    void                SetDisableBranches(Bool_t disable=kTRUE) {TObject::SetBit(kDisableBranches,disable);}
95    void                SetCollectSysInfoEach(Int_t nevents=0) {fNSysInfo = nevents;}
96    void                SetInputEventHandler(AliVEventHandler*  handler)  {fInputEventHandler   = handler;}
97    void                SetOutputEventHandler(AliVEventHandler*  handler) {fOutputEventHandler  = handler;}
98    void                SetMCtruthEventHandler(AliVEventHandler* handler) {fMCtruthEventHandler = handler;}
99    void                SetGridHandler(AliAnalysisGrid *handler) {fGridHandler = handler;}
100    void                SetEventPool(AliVEventPool* epool) {fEventPool = epool;}
101    void                SetNSysInfo(Long64_t nevents) {fNSysInfo = nevents;}
102    void                SetSelector(AliAnalysisSelector *sel) {fSelector = sel;}
103    AliVEventHandler*   GetInputEventHandler()   {return fInputEventHandler;}
104    AliVEventHandler*   GetOutputEventHandler()  {return fOutputEventHandler;}
105    AliVEventHandler*   GetMCtruthEventHandler() {return fMCtruthEventHandler;}
106    AliAnalysisGrid*    GetGridHandler()         {return fGridHandler;}
107    AliVEventPool*      GetEventPool()           {return fEventPool;}
108
109    // Container handling
110    AliAnalysisDataContainer *CreateContainer(const char *name, TClass *datatype, 
111                        EAliAnalysisContType type     = kExchangeContainer, 
112                        const char          *filename = NULL);
113    
114    // Including tasks and getting them
115    void                 AddTask(AliAnalysisTask *task);
116    AliAnalysisTask     *GetTask(const char *name) const;
117    
118    // Connecting data containers to task inputs/outputs
119    Bool_t               ConnectInput(AliAnalysisTask *task, Int_t islot,
120                                      AliAnalysisDataContainer *cont);
121    Bool_t               ConnectOutput(AliAnalysisTask *task, Int_t islot,
122                                      AliAnalysisDataContainer *cont);
123    // Garbage collection
124    void                 CleanContainers();
125    
126    // Analysis initialization and execution, status
127    Bool_t               InitAnalysis();
128    Bool_t               IsInitialized() const {return fInitOK;}
129    Bool_t               IsEventLoop() const {return TObject::TestBit(kEventLoop);}
130    void                 ResetAnalysis();
131    void                 ExecAnalysis(Option_t *option="");
132    void                 FinishAnalysis();
133    void                 PrintStatus(Option_t *option="all") const;
134
135 protected:
136    void                 ImportWrappers(TList *source);
137    void                 SetEventLoop(Bool_t flag=kTRUE) {TObject::SetBit(kEventLoop,flag);}
138
139 private:
140    TTree                  *fTree;                //! Input tree in case of TSelector model
141    AliVEventHandler       *fInputEventHandler;   //  Optional common input  event handler
142    AliVEventHandler       *fOutputEventHandler;  //  Optional common output event handler
143    AliVEventHandler       *fMCtruthEventHandler; //  Optional common MC Truth event handler
144    AliVEventPool          *fEventPool;           //  Event pool for mixing analysis
145    Long64_t                fCurrentEntry;        //! Current processed entry in the tree
146    Long64_t                fNSysInfo;            // Event frequency for collecting system information
147    EAliAnalysisExecMode    fMode;                // Execution mode
148    Bool_t                  fInitOK;              // Initialisation done
149    UInt_t                  fDebug;               // Debug level
150    TString                 fSpecialOutputLocation; // URL/path where the special outputs will be copied
151    TObjArray              *fTasks;               // List of analysis tasks
152    TObjArray              *fTopTasks;            // List of top tasks
153    TObjArray              *fZombies;             // List of zombie tasks
154    TObjArray              *fContainers;          // List of all containers
155    TObjArray              *fInputs;              // List of containers with input data
156    TObjArray              *fOutputs;             // List of containers with results
157    AliAnalysisSelector    *fSelector;            //! Current selector
158    AliAnalysisGrid        *fGridHandler;         //! Grid handler plugin
159
160    static AliAnalysisManager *fgAnalysisManager; //! static pointer to object instance
161    ClassDef(AliAnalysisManager,3)  // Analysis manager class
162 };   
163 #endif