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