]>
Commit | Line | Data |
---|---|---|
d3106602 | 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; | |
13ef3bb0 | 24 | class TFile; |
d3106602 | 25 | class AliAnalysisDataSlot; |
26 | class AliAnalysisDataContainer; | |
27 | ||
28 | class AliAnalysisTask : public TTask { | |
327eaf46 | 29 | public: |
30 | enum EAnalysisTaskFlags { | |
31 | kTaskUsed = BIT(14), | |
32 | kTaskZombie = BIT(15), | |
c5a87c56 | 33 | kTaskChecked = BIT(16), |
b1310ef5 | 34 | kTaskPostEventLoop = BIT(17) |
c5a87c56 | 35 | }; |
c52c2132 | 36 | |
37 | protected: | |
37153431 | 38 | Bool_t fReady; // Flag if the task is ready |
39 | Bool_t fInitialized; // True if Init() was called | |
40 | Int_t fNinputs; // Number of inputs | |
41 | Int_t fNoutputs; // Number of outputs | |
42 | Bool_t *fOutputReady; //[fNoutputs] Flags for output readyness | |
43 | TObject *fPublishedData; //! published data | |
44 | TObjArray *fInputs; // Array of input slots | |
45 | TObjArray *fOutputs; // Array of output slots | |
7acc5b9d | 46 | TString fBranchNames; // List of input branches that need to be loaded for this task |
c52c2132 | 47 | |
48 | // Define the input/output slots (called by user in the ctor of the derived class) | |
49 | //=== CALL IN THE CONSTRUCTOR OF DERIVED CLASS TO DEFINE INPUTS/OUTPUTS === | |
50 | void DefineInput(Int_t islot, TClass *type); | |
51 | void DefineOutput(Int_t islot, TClass *type); | |
c52c2132 | 52 | |
53 | //===================================================================== | |
54 | // === OVERLOAD THIS TO CONNECT TREE BRANCHES AT INPUT SLOTS. YOU | |
55 | // SHOULD DEFINE HERE ALSO THE OBJECTS TO BE CONNECTED TO YOUR OUTPUTS | |
56 | virtual void ConnectInputData(Option_t *option=""); | |
57 | //===================================================================== | |
58 | ||
59 | // Post output data (called by Exec() when data is ready) | |
60 | //=== CALL IN EXEC() FOR EACH OUTPUT WHEN READY === | |
61 | Bool_t PostData(Int_t iout, TObject *data, Option_t *option=""); | |
62 | //===================================================================== | |
327eaf46 | 63 | |
b1310ef5 | 64 | // === USE THIS FIRST IN YOUR ConnectInputData() TO CHECH IF A BRANCH IS ALREADY CONNECTED |
c52c2132 | 65 | // TO SOME ADDRESS. |
66 | char *GetBranchAddress(Int_t islot, const char *branch) const; | |
b1310ef5 | 67 | // === CALL THIS AFTERWARDS IN ConnectInputData() IF THE BRANCH ADDRESS IS NOT YET SET |
c52c2132 | 68 | Bool_t SetBranchAddress(Int_t islot, const char *branch, void *address) const; |
69 | //===================================================================== | |
b1310ef5 | 70 | //=== CALL IN ConnectInputData() TO ENABLE ONLY EXPLICIT BRANCHES NEEDED FOR THIS TASK EXECUTION |
71 | void EnableBranch(Int_t islot, const char *bname) const; | |
72 | //===================================================================== | |
c5a87c56 | 73 | // === CALL THIS IN CreateOutputObjects BEFORE CREATING THE OBJECT FOR EACH |
74 | // OUTPUT IOUT THAT HAS TO BE WRITTEN TO A FILE | |
13ef3bb0 | 75 | TFile *OpenFile(Int_t iout, Option_t *option="RECREATE") const; |
c52c2132 | 76 | |
77 | public: | |
327eaf46 | 78 | AliAnalysisTask(); |
79 | AliAnalysisTask(const char *name, const char *title); | |
80 | AliAnalysisTask(const AliAnalysisTask &task); | |
81 | virtual ~AliAnalysisTask(); | |
82 | ||
83 | // Assignment | |
84 | AliAnalysisTask& operator=(const AliAnalysisTask &task); | |
c52c2132 | 85 | //===================================================================== |
86 | // === OVERLOAD THIS AND CREATE YOUR OUTPUT OBJECTS (HISTOGRAMS,DATA) HERE | |
87 | virtual void CreateOutputObjects(); | |
9b33830a | 88 | // === OVERLOAD THIS IF YOU NEED TO INITIALIZE YOUR CLASS ON THE CLIENT |
89 | virtual void LocalInit(); | |
8508e09f | 90 | // === OVERLOAD THIS IF YOU NEED TO TREAT INPUT FILE/TREE CHANGE |
981f2614 | 91 | virtual Bool_t Notify(); |
aee5ee44 | 92 | // === OVERLOAD THIS IF YOU NEED TO TREAT BIN CHANGE IN EVENT MIXING |
93 | virtual Bool_t NotifyBinChange(); | |
8508e09f | 94 | //===================================================================== |
8d7d3b59 | 95 | // Optional method that will be called in SlaveTerminate phase for each task |
96 | // Warning: in PROOF mode this is called before merging so their cleanup is | |
97 | // not allowed - do output cleanup in class destructor. | |
98 | virtual void FinishTaskOutput(); | |
327eaf46 | 99 | // Conect inputs/outputs to data containers (by AliAnalysisModule) |
100 | Bool_t ConnectInput(Int_t islot, AliAnalysisDataContainer *cont); | |
101 | Bool_t ConnectOutput(Int_t islot, AliAnalysisDataContainer *cont); | |
102 | // Check connectivity | |
103 | Bool_t AreSlotsConnected(); | |
104 | // Check if data for all inputs is ready | |
105 | void CheckNotify(Bool_t init=kFALSE); | |
106 | // Check if there are illegal circular dependencies | |
107 | Bool_t CheckCircularDeps(); | |
4747b4a7 | 108 | virtual Bool_t CheckPostData() const; |
b2fce16b | 109 | virtual Bool_t CheckOwnership() const; |
327eaf46 | 110 | // Getters |
7acc5b9d | 111 | void GetBranches(const char *type, TString &result) const; |
327eaf46 | 112 | Int_t GetNinputs() const {return fNinputs;} |
113 | Int_t GetNoutputs() const {return fNoutputs;} | |
114 | TObject *GetPublishedData() const {return fPublishedData;} | |
115 | AliAnalysisDataSlot *GetInputSlot(Int_t islot) const {return (AliAnalysisDataSlot*)fInputs->At(islot);} | |
116 | AliAnalysisDataSlot *GetOutputSlot(Int_t islot) const {return (AliAnalysisDataSlot*)fOutputs->At(islot);} | |
117 | TClass *GetInputType(Int_t islot) const; | |
118 | TClass *GetOutputType(Int_t islot) const; | |
119 | // === USE THIS TO RETREIVE INPUT DATA AND STATICALLY CAST IT TO THE DECLARED TYPE | |
120 | TObject *GetInputData(Int_t islot) const; | |
c52c2132 | 121 | TObject *GetOutputData(Int_t islot) const; |
327eaf46 | 122 | Bool_t IsOutputReady(Int_t islot) const {return fOutputReady[islot];} |
123 | Bool_t IsChecked() const {return TObject::TestBit(kTaskChecked);} | |
b1310ef5 | 124 | Bool_t IsPostEventLoop() const {return TObject::TestBit(kTaskPostEventLoop);} |
327eaf46 | 125 | Bool_t IsInitialized() const {return fInitialized;} |
126 | Bool_t IsReady() const {return fReady;} | |
127 | Bool_t IsUsed() const {return TObject::TestBit(kTaskUsed);} | |
128 | Bool_t IsZombie() const {return TObject::TestBit(kTaskZombie);} | |
7acc5b9d | 129 | Bool_t HasBranches() const {return !fBranchNames.IsNull();} |
dcc1f876 | 130 | virtual void PrintTask(Option_t *option="all", Int_t indent=0) const; |
327eaf46 | 131 | void PrintContainers(Option_t *option="all", Int_t indent=0) const; |
7acc5b9d | 132 | void SetBranches(const char *names) {fBranchNames = names;} |
327eaf46 | 133 | void SetChecked(Bool_t flag=kTRUE) {TObject::SetBit(kTaskChecked,flag);} |
b1310ef5 | 134 | void SetPostEventLoop(Bool_t flag=kTRUE); |
327eaf46 | 135 | void SetUsed(Bool_t flag=kTRUE); |
136 | void SetZombie(Bool_t flag=kTRUE) {TObject::SetBit(kTaskZombie,flag);} | |
137 | // Main task execution | |
138 | //=== IMPLEMENT THIS !!! ============================================== | |
139 | virtual void Exec(Option_t *option) = 0; | |
140 | //===================================================================== | |
141 | Bool_t HasExecuted() const {return fHasExecuted;} | |
142 | //===================================================================== | |
143 | // === OVERLOAD THIS IF YOU WANT TO DO SOMETHING WITH THE OUTPUT | |
144 | virtual void Terminate(Option_t *option=""); | |
145 | //===================================================================== | |
c52c2132 | 146 | |
7acc5b9d | 147 | ClassDef(AliAnalysisTask,2) // Class describing an analysis task |
d3106602 | 148 | }; |
149 | #endif |