- New class AliAnalysisDataWrapper used for streaming output results from PROOF to
[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 AliAnalysisDataContainer;
23 class AliAnalysisTask;
24
25 class AliAnalysisManager : public TNamed {
26
27 public:
28
29 enum EAliAnalysisContType {
30    kExchangeContainer  = 0,
31    kInputContainer   = 1,
32    kOutputContainer  = 2
33 };   
34
35 enum EAliAnalysisExecMode {
36    kLocalAnalysis    = 0,
37    kProofAnalysis    = 1,
38    kGridAnalysis     = 2
39 };
40
41    AliAnalysisManager();
42    AliAnalysisManager(const char *name, const char *title="");
43    virtual            ~AliAnalysisManager();
44
45    AliAnalysisManager(const AliAnalysisManager& other);
46    AliAnalysisManager& operator=(const AliAnalysisManager& other);
47    
48    void                StartAnalysis(const char *type="local", TTree *tree=0);
49
50    virtual void        Init(TTree *tree);   
51    virtual void        Begin(TTree *tree);
52    virtual Bool_t      Notify();
53    virtual void        SlaveBegin(TTree *tree);
54    virtual Bool_t      ProcessCut(Long64_t entry) {return Process(entry);}
55    virtual Bool_t      Process(Long64_t entry);
56    virtual Int_t       GetEntry(Long64_t entry, Int_t getall = 0);
57    void                PackOutput(TList *target);
58    void                UnpackOutput(TList *source);
59    virtual void        Terminate();
60
61    // Getters/Setters
62    static AliAnalysisManager *GetAnalysisManager() {return fgAnalysisManager;}
63    TObjArray          *GetContainers() const {return fContainers;}
64    UInt_t              GetDebugLevel() const {return fDebug;}
65    TObjArray          *GetInputs() const     {return fInputs;}
66    TObjArray          *GetOutputs() const    {return fOutputs;}
67    TObjArray          *GetTasks() const      {return fTasks;}
68    TObjArray          *GetTopTasks() const   {return fTopTasks;}
69    TTree              *GetTree() const       {return fTree;}
70    TObjArray          *GetZombieTasks() const {return fZombies;}
71    Long64_t            GetCurrentEntry() const {return fCurrentEntry;}
72    EAliAnalysisExecMode 
73                        GetAnalysisType() const {return fMode;}
74
75    void                SetAnalysisType(EAliAnalysisExecMode mode) {fMode = mode;}
76    void                SetCurrentEntry(Long64_t entry) {fCurrentEntry = entry;}
77    void                SetDebugLevel(UInt_t level) {fDebug = level;}
78
79    // Container handling
80    AliAnalysisDataContainer *CreateContainer(const char *name, TClass *datatype, 
81                        EAliAnalysisContType type     = kExchangeContainer, 
82                        const char          *filename = NULL);
83    
84    // Including tasks and getting them
85    void                 AddTask(AliAnalysisTask *task);
86    AliAnalysisTask     *GetTask(const char *name) const;
87    
88    // Connecting data containers to task inputs/outputs
89    Bool_t               ConnectInput(AliAnalysisTask *task, Int_t islot,
90                                      AliAnalysisDataContainer *cont);
91    Bool_t               ConnectOutput(AliAnalysisTask *task, Int_t islot,
92                                      AliAnalysisDataContainer *cont);
93    // Garbage collection
94    void                 CleanContainers();
95    
96    // Analysis initialization and execution, status
97    Bool_t               InitAnalysis();
98    Bool_t               IsInitialized() const {return fInitOK;}
99    void                 ResetAnalysis();
100    void                 ExecAnalysis(Option_t *option="");
101    void                 FinishAnalysis();
102    void                 PrintStatus(Option_t *option="all") const;
103
104 protected:
105    void                 ImportWrappers(TList *source);
106
107 private:
108    TTree               *fTree;         //! Input tree in case of TSelector model
109    Long64_t             fCurrentEntry; //! Current processed entry in the tree
110    EAliAnalysisExecMode fMode;         // Execution mode
111    Bool_t               fInitOK;       // Initialisation done
112    UInt_t               fDebug;        // Debug level
113    TObjArray           *fTasks;        // List of analysis tasks
114    TObjArray           *fTopTasks;     // List of top tasks
115    TObjArray           *fZombies;      // List of zombie tasks
116    TObjArray           *fContainers;   // List of all containers
117    TObjArray           *fInputs;       // List of containers with input data
118    TObjArray           *fOutputs;      // List of containers with results
119
120    static AliAnalysisManager *fgAnalysisManager; //! static pointer to object instance
121    ClassDef(AliAnalysisManager,1)  // Analysis manager class
122 };   
123 #endif