]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisManager.h
Added support for retrieving and merging dAOD's. The producer task has to call AliAna...
[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 methods called by the framework
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                RegisterExtraFile(const char *fname);
91    void                SetAnalysisType(EAliAnalysisExecMode mode) {fMode = mode;}
92    void                SetCurrentEntry(Long64_t entry) {fCurrentEntry = entry;}
93    void                SetDebugLevel(UInt_t level) {fDebug = level;}
94    void                SetSpecialOutputLocation(const char *location) {fSpecialOutputLocation = location;}
95    void                SetDisableBranches(Bool_t disable=kTRUE) {TObject::SetBit(kDisableBranches,disable);}
96    void                SetCollectSysInfoEach(Int_t nevents=0) {fNSysInfo = nevents;}
97    void                SetInputEventHandler(AliVEventHandler*  handler);
98    void                SetOutputEventHandler(AliVEventHandler*  handler);
99    void                SetMCtruthEventHandler(AliVEventHandler* handler) {fMCtruthEventHandler = handler;}
100    void                SetGridHandler(AliAnalysisGrid *handler) {fGridHandler = handler;}
101    void                SetEventPool(AliVEventPool* epool) {fEventPool = epool;}
102    void                SetNSysInfo(Long64_t nevents) {fNSysInfo = nevents;}
103    void                SetSelector(AliAnalysisSelector *sel) {fSelector = sel;}
104    AliVEventHandler*   GetInputEventHandler()   {return fInputEventHandler;}
105    AliVEventHandler*   GetOutputEventHandler()  {return fOutputEventHandler;}
106    AliVEventHandler*   GetMCtruthEventHandler() {return fMCtruthEventHandler;}
107    AliAnalysisDataContainer *GetCommonInputContainer() {return fCommonInput;}
108    AliAnalysisDataContainer *GetCommonOutputContainer() {return fCommonOutput;}
109    AliAnalysisGrid*    GetGridHandler()         {return fGridHandler;}
110    AliVEventPool*      GetEventPool()           {return fEventPool;}
111    Bool_t              GetFileFromWrapper(const char *filename, TList *source);
112    TString             GetExtraFiles() const {return fExtraFiles;}
113
114    // Container handling
115    AliAnalysisDataContainer *CreateContainer(const char *name, TClass *datatype, 
116                        EAliAnalysisContType type     = kExchangeContainer, 
117                        const char          *filename = NULL);
118    
119    // Including tasks and getting them
120    void                 AddTask(AliAnalysisTask *task);
121    AliAnalysisTask     *GetTask(const char *name) const;
122    
123    // Connecting data containers to task inputs/outputs
124    Bool_t               ConnectInput(AliAnalysisTask *task, Int_t islot,
125                                      AliAnalysisDataContainer *cont);
126    Bool_t               ConnectOutput(AliAnalysisTask *task, Int_t islot,
127                                      AliAnalysisDataContainer *cont);
128    // Garbage collection
129    void                 CleanContainers();
130    
131    // Analysis initialization and execution, status
132    Bool_t               InitAnalysis();
133    Bool_t               IsInitialized() const {return fInitOK;}
134    Bool_t               IsEventLoop() const {return TObject::TestBit(kEventLoop);}
135    void                 ResetAnalysis();
136    void                 ExecAnalysis(Option_t *option="");
137    void                 FinishAnalysis();
138    void                 PrintStatus(Option_t *option="all") const;
139
140 protected:
141    void                 ImportWrappers(TList *source);
142    void                 SetEventLoop(Bool_t flag=kTRUE) {TObject::SetBit(kEventLoop,flag);}
143
144 private:
145    TTree                  *fTree;                //! Input tree in case of TSelector model
146    AliVEventHandler       *fInputEventHandler;   //  Optional common input  event handler
147    AliVEventHandler       *fOutputEventHandler;  //  Optional common output event handler
148    AliVEventHandler       *fMCtruthEventHandler; //  Optional common MC Truth event handler
149    AliVEventPool          *fEventPool;           //  Event pool for mixing analysis
150    Long64_t                fCurrentEntry;        //! Current processed entry in the tree
151    Long64_t                fNSysInfo;            // Event frequency for collecting system information
152    EAliAnalysisExecMode    fMode;                // Execution mode
153    Bool_t                  fInitOK;              // Initialisation done
154    UInt_t                  fDebug;               // Debug level
155    TString                 fSpecialOutputLocation; // URL/path where the special outputs will be copied
156    TObjArray              *fTasks;               // List of analysis tasks
157    TObjArray              *fTopTasks;            // List of top tasks
158    TObjArray              *fZombies;             // List of zombie tasks
159    TObjArray              *fContainers;          // List of all containers
160    TObjArray              *fInputs;              // List of containers with input data
161    TObjArray              *fOutputs;             // List of containers with results
162    AliAnalysisDataContainer *fCommonInput;       // Common input container
163    AliAnalysisDataContainer *fCommonOutput;      // Common output container
164    AliAnalysisSelector    *fSelector;            //! Current selector
165    AliAnalysisGrid        *fGridHandler;         //! Grid handler plugin
166    TString                 fExtraFiles;          //! List of extra files to be merged
167
168    static AliAnalysisManager *fgAnalysisManager; //! static pointer to object instance
169    ClassDef(AliAnalysisManager,4)  // Analysis manager class
170 };   
171 #endif