]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAnalysisTask.h
- Fix for a recently introduced bug
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTask.h
1 #ifndef ALIANALYSISTASK_H
2 #define ALIANALYSISTASK_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 //   AliAnalysysTask - Class representing a basic analysis task. Any
11 // user-defined task should derive from it and implement the Exec() virtual
12 // method.
13 //==============================================================================
14
15 #ifndef ROOT_TTask
16 #include "TTask.h"
17 #endif
18
19 #ifndef ROOT_TObjArray
20 #include "TObjArray.h"
21 #endif
22
23 class TClass;
24 class AliAnalysisDataSlot;
25 class AliAnalysisDataContainer;
26
27 class AliAnalysisTask : public TTask {
28  public:
29   enum EAnalysisTaskFlags {
30     kTaskUsed    = BIT(14),
31     kTaskZombie  = BIT(15),
32     kTaskChecked = BIT(16),
33     kTaskEvtByEvt = BIT(17)
34   };
35
36  protected:
37   Bool_t                    fReady;         // Flag if the task is ready
38   Bool_t                    fInitialized;   // True if Init() was called
39   Int_t                     fNinputs;       // Number of inputs
40   Int_t                     fNoutputs;      // Number of outputs
41   Bool_t                   *fOutputReady;   //[fNoutputs] Flags for output readyness
42   TObject                  *fPublishedData; //! published data
43   TObjArray                *fInputs;        // Array of input slots
44   TObjArray                *fOutputs;       // Array of output slots
45
46   // Define the input/output slots (called by user in the ctor of the derived class)
47   //=== CALL IN THE CONSTRUCTOR OF DERIVED CLASS TO DEFINE INPUTS/OUTPUTS ===
48   void                      DefineInput(Int_t islot, TClass *type);
49   void                      DefineOutput(Int_t islot, TClass *type);
50   //=====================================================================
51   
52   //=====================================================================
53   // === OVERLOAD THIS TO CONNECT TREE BRANCHES AT INPUT SLOTS. YOU
54   // SHOULD DEFINE HERE ALSO THE OBJECTS TO BE CONNECTED TO YOUR OUTPUTS
55   virtual void              ConnectInputData(Option_t *option="");
56   //=====================================================================
57   
58   // Post output data (called by Exec() when data is ready)
59   //=== CALL IN EXEC() FOR EACH OUTPUT WHEN READY ===
60   Bool_t                    PostData(Int_t iout, TObject *data, Option_t *option="");
61   //=====================================================================
62   
63   // === USE THIS FIRST IN YOUR Init() TO CHECH IF A BRANCH IS ALREADY CONNECTED
64   // TO SOME ADDRESS.
65   char                     *GetBranchAddress(Int_t islot, const char *branch) const;
66   // === CALL THIS AFTERWARDS IN Init() IF THE BRANCH ADDRESS IS NOT YET SET
67   Bool_t                    SetBranchAddress(Int_t islot, const char *branch, void *address) const;
68   //=====================================================================
69   // === CALL THIS IN CreateOutputObjects BEFORE CREATING THE OBJECT FOR EACH 
70   // OUTPUT IOUT THAT HAS TO BE WRITTEN TO A FILE
71   void                      OpenFile(Int_t iout, Option_t *option="RECREATE") const;
72   
73 public:  
74   AliAnalysisTask();
75   AliAnalysisTask(const char *name, const char *title);
76   AliAnalysisTask(const AliAnalysisTask &task); 
77   virtual ~AliAnalysisTask();
78   
79   // Assignment
80   AliAnalysisTask& operator=(const AliAnalysisTask &task);
81   //=====================================================================
82   // === OVERLOAD THIS AND CREATE YOUR OUTPUT OBJECTS (HISTOGRAMS,DATA) HERE
83   virtual void              CreateOutputObjects();
84   // === OVERLOAD THIS IF YOU NEED TO INITIALIZE YOUR CLASS ON THE CLIENT
85   virtual void              LocalInit();
86   // === OVERLOAD THIS IF YOU NEED TO TREAT INPUT FILE CHANGE
87   virtual Bool_t            Notify();
88   // Conect inputs/outputs to data containers (by AliAnalysisModule)
89   Bool_t                    ConnectInput(Int_t islot, AliAnalysisDataContainer *cont);
90   Bool_t                    ConnectOutput(Int_t islot, AliAnalysisDataContainer *cont);
91   // Check connectivity
92   Bool_t                    AreSlotsConnected();
93   // Check if data for all inputs is ready
94   void                      CheckNotify(Bool_t init=kFALSE);
95   // Check if there are illegal circular dependencies
96   Bool_t                    CheckCircularDeps();
97   // Getters
98   Int_t                     GetNinputs() const  {return fNinputs;}
99   Int_t                     GetNoutputs() const {return fNoutputs;}
100   TObject                  *GetPublishedData() const {return fPublishedData;}
101   AliAnalysisDataSlot      *GetInputSlot(Int_t islot) const  {return (AliAnalysisDataSlot*)fInputs->At(islot);}
102   AliAnalysisDataSlot      *GetOutputSlot(Int_t islot) const {return (AliAnalysisDataSlot*)fOutputs->At(islot);}
103   TClass                   *GetInputType(Int_t islot) const;
104   TClass                   *GetOutputType(Int_t islot) const;
105   // === USE THIS TO RETREIVE INPUT DATA AND STATICALLY CAST IT TO THE DECLARED TYPE
106   TObject                  *GetInputData(Int_t islot) const;
107   TObject                  *GetOutputData(Int_t islot) const;  
108   Bool_t                    IsOutputReady(Int_t islot) const {return fOutputReady[islot];}
109   Bool_t                    IsChecked() const  {return TObject::TestBit(kTaskChecked);}
110   Bool_t                    IsExecPerEvent() const {return TObject::TestBit(kTaskEvtByEvt);}
111   Bool_t                    IsInitialized() const  {return fInitialized;}
112   Bool_t                    IsReady() const  {return fReady;}
113   Bool_t                    IsUsed() const   {return TObject::TestBit(kTaskUsed);}
114   Bool_t                    IsZombie() const {return TObject::TestBit(kTaskZombie);}
115   void                      PrintTask(Option_t *option="all", Int_t indent=0) const;
116   void                      PrintContainers(Option_t *option="all", Int_t indent=0) const;
117   void                      SetChecked(Bool_t flag=kTRUE) {TObject::SetBit(kTaskChecked,flag);}
118   void                      SetExecPerEvent(Bool_t flag=kTRUE);
119   void                      SetUsed(Bool_t flag=kTRUE);
120   void                      SetZombie(Bool_t flag=kTRUE) {TObject::SetBit(kTaskZombie,flag);}
121   // Main task execution 
122   //=== IMPLEMENT THIS !!! ==============================================
123   virtual void              Exec(Option_t *option) = 0;
124   //=====================================================================
125   Bool_t                    HasExecuted() const {return fHasExecuted;}
126   //=====================================================================
127   // === OVERLOAD THIS IF YOU WANT TO DO SOMETHING WITH THE OUTPUT
128   virtual void              Terminate(Option_t *option="");
129   //=====================================================================
130     
131   ClassDef(AliAnalysisTask,1)  // Class describing an analysis task
132 };
133 #endif