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