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 */
7 // Author: Andrei Gheata, 31/05/2006
9 //==============================================================================
10 // AliAnalysysTask - Class representing a basic analysis task. Any
11 // user-defined task should derive from it and implement the Exec() virtual
13 //==============================================================================
19 #ifndef ROOT_TObjArray
20 #include "TObjArray.h"
24 class AliAnalysisDataSlot;
25 class AliAnalysisDataContainer;
27 class AliAnalysisTask : public TTask {
29 enum EAnalysisTaskFlags {
31 kTaskZombie = BIT(15),
32 kTaskChecked = BIT(16)
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
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 //=====================================================================
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 //=====================================================================
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 //=====================================================================
62 // === USE THIS FIRST IN YOUR Init() TO CHECH IF A BRANCH IS ALREADY CONNECTED
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;
73 AliAnalysisTask(const char *name, const char *title);
74 AliAnalysisTask(const AliAnalysisTask &task);
75 virtual ~AliAnalysisTask();
78 AliAnalysisTask& operator=(const AliAnalysisTask &task);
79 //=====================================================================
80 // === OVERLOAD THIS AND CREATE YOUR OUTPUT OBJECTS (HISTOGRAMS,DATA) HERE
81 virtual void CreateOutputObjects();
82 // Conect inputs/outputs to data containers (by AliAnalysisModule)
83 Bool_t ConnectInput(Int_t islot, AliAnalysisDataContainer *cont);
84 Bool_t ConnectOutput(Int_t islot, AliAnalysisDataContainer *cont);
86 Bool_t AreSlotsConnected();
87 // Check if data for all inputs is ready
88 void CheckNotify(Bool_t init=kFALSE);
89 // Check if there are illegal circular dependencies
90 Bool_t CheckCircularDeps();
92 Int_t GetNinputs() const {return fNinputs;}
93 Int_t GetNoutputs() const {return fNoutputs;}
94 TObject *GetPublishedData() const {return fPublishedData;}
95 AliAnalysisDataSlot *GetInputSlot(Int_t islot) const {return (AliAnalysisDataSlot*)fInputs->At(islot);}
96 AliAnalysisDataSlot *GetOutputSlot(Int_t islot) const {return (AliAnalysisDataSlot*)fOutputs->At(islot);}
97 TClass *GetInputType(Int_t islot) const;
98 TClass *GetOutputType(Int_t islot) const;
99 // === USE THIS TO RETREIVE INPUT DATA AND STATICALLY CAST IT TO THE DECLARED TYPE
100 TObject *GetInputData(Int_t islot) const;
101 TObject *GetOutputData(Int_t islot) const;
102 Bool_t IsOutputReady(Int_t islot) const {return fOutputReady[islot];}
103 Bool_t IsChecked() const {return TObject::TestBit(kTaskChecked);}
104 Bool_t IsInitialized() const {return fInitialized;}
105 Bool_t IsReady() const {return fReady;}
106 Bool_t IsUsed() const {return TObject::TestBit(kTaskUsed);}
107 Bool_t IsZombie() const {return TObject::TestBit(kTaskZombie);}
108 void PrintTask(Option_t *option="all", Int_t indent=0) const;
109 void PrintContainers(Option_t *option="all", Int_t indent=0) const;
110 void SetChecked(Bool_t flag=kTRUE) {TObject::SetBit(kTaskChecked,flag);}
111 void SetUsed(Bool_t flag=kTRUE);
112 void SetZombie(Bool_t flag=kTRUE) {TObject::SetBit(kTaskZombie,flag);}
113 // Main task execution
114 //=== IMPLEMENT THIS !!! ==============================================
115 virtual void Exec(Option_t *option) = 0;
116 //=====================================================================
117 Bool_t HasExecuted() const {return fHasExecuted;}
118 //=====================================================================
119 // === OVERLOAD THIS IF YOU WANT TO DO SOMETHING WITH THE OUTPUT
120 virtual void Terminate(Option_t *option="");
121 //=====================================================================
123 ClassDef(AliAnalysisTask,1) // Class describing an analysis task