ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TAM/interface/TAModule.h
Revision: 1.3
Committed: Tue Jun 24 14:03:45 2008 UTC (16 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_006, Mit_005, Mit_004, MITHEP_2_0_x
Changes since 1.2: +2 -1 lines
Log Message:
Provide access to Selector.

File Contents

# User Rev Content
1 loizides 1.1 //
2 loizides 1.3 // $Id: TAModule.h,v 1.2 2008/06/23 10:53:00 loizides Exp $
3 loizides 1.1 //
4    
5     #ifndef ROOT_TAModule
6     #define ROOT_TAModule
7    
8     // keep this for compatibility
9     #define TAM_TAModule
10    
11    
12     // typeid include
13     #include <typeinfo>
14    
15    
16     #ifndef ROOT_TTask
17     #include "TTask.h"
18     #endif
19     #ifndef ROOT_Varargs
20     #include "Varargs.h"
21     #endif
22     #ifndef ROOT_TAMSelector
23     #include "TAMSelector.h"
24     #endif
25     #ifndef ROOT_TAMOutput
26     #include "TAMOutput.h"
27     #endif
28    
29     class TFile;
30     class TStopwatch;
31    
32    
33     class TAModule : public TTask {
34     public:
35     enum EModResult {
36     kWarning, //a problem requiring no action but just printing of a warning
37     kAbortModule, //a problem requiring this mod (and its submods) to stop
38     kAbortEvent, //a problem requiring the processing of this event to stop
39     kStopModule, //a problem requiring this mod (and its submods) to stop for the rest of the analysis
40     kAbortAnalysis //a problem requiring the processing of the analysis to stop
41     };
42    
43     private:
44     TAMSelector *fSelector; //!the selector for the tree this mod processes
45     TAMOutput *fOutput; //the list of output objects for this mod
46     Bool_t fDefActv; //!copy of fActive so that TAMSelector can temporarily change this mod's active-ness to abort the mod or the event
47     UInt_t fVerbose; //verbosity level
48     Bool_t fStopped; //!indicate if module (and its submodules) are aborted for the rest of the analysis
49    
50     static const Char_t kExecBegin; //!key to mark Begin
51     static const Char_t kExecSlaveBegin; //!key to mark SlaveBegin
52     static const Char_t kExecProcess; //!key to mark Process
53 loizides 1.2 static const Char_t kExecBeginRun; //!key to mark BeginRun
54     static const Char_t kExecEndRun; //!key to mark EndRun
55 loizides 1.1 static const Char_t kExecSlaveTerminate; //!key to mark SlaveTerminate
56     static const Char_t kExecTerminate; //!key to mark Terminate
57    
58     // to be called by friend class TAMSelector only
59     void AbortAnalysis();
60     void AbortEvent();
61     void AbortModule();
62     void DeactivateAll();
63     void NewOutputList(TList* list);
64     Bool_t NotifyAll();
65     void ResetAllActiveFlags();
66     void SetAllModOutput(TAMOutput* o);
67     void SetModOutput(TAMOutput* o);
68     void StopModule();
69    
70     protected:
71    
72     // utility functions to be used by derived classes
73     virtual Bool_t AddObjThisEvt(TObject* obj);
74     virtual Bool_t AddObjThisEvt(TObject* obj, const char *name);
75     template <class OC>
76     void AddOutput(OC* const & obj);
77 loizides 1.3 const TAMSelector *GetSelector() const { return fSelector; }
78 loizides 1.1 Bool_t IsEventAborted() const { return (fSelector==0) ? kFALSE : fSelector->IsEventAborted(); }
79     Bool_t IsAnalysisAborted() const { return (fSelector==0) ? kFALSE : fSelector->IsAnalysisAborted(); }
80     void LoadBranch(const Char_t* bname);
81     virtual TObject *FindObjThisEvt(const Char_t* name) const;
82     virtual Bool_t Notify() { return kTRUE; }
83     virtual TObject *RemoveObjThisEvt(const Char_t* name);
84     void RemoveOutput(TObject* obj);
85     template <typename T>
86     void ReqBranch(const Char_t* bname, T*& address);
87     void SendError(const EModResult errLevel,
88     const Char_t* location,
89     const Char_t* formattedMsg, ...);
90     void SkipEvent();
91    
92     // functions to be overloaded by specific TAModule
93     virtual void Begin() {}
94     virtual void SlaveBegin() {}
95     virtual void Process() {}
96 loizides 1.2 virtual void BeginRun() {}
97     virtual void EndRun() {}
98 loizides 1.1 virtual void SlaveTerminate() {}
99     virtual void Terminate() {}
100    
101     public:
102    
103     TAModule();
104     TAModule(const Char_t* name, const Char_t* title);
105     virtual ~TAModule();
106    
107     virtual void Browse(TBrowser* b);
108     // intentionally have no GetSelector as modules should never directly
109     // interact with the selector, the input list or the output list
110     Bool_t CheckSelectors(const TAMSelector* sel,
111     const Bool_t warn=kTRUE) const;
112     // TAMSelector is a friend to allow it to call Exec
113     // using the private variables such as kExecProcess
114     // and to prevent TAModules inheritting from this class
115     // from making such explicit calls.
116     friend class TAMSelector;
117     void Exec(Option_t* option);
118     TObject *FindPublicObj(const Char_t* name) const;
119     TFile *GetCurrentFile() const;
120     const TAMOutput *GetModOutput() const { return fOutput; }
121     TAMOutput *GetModOutput() { return fOutput; }
122     TList* GetSubModules() { return GetListOfTasks(); }
123     const TList *GetSubModules() const { return GetListOfTasks(); }
124     UInt_t GetVerbosity() const { return fVerbose; }
125     virtual void Print(Option_t *option="") const;
126     Bool_t PublishObj(TObject* obj);
127     TObject *RetractObj(const Char_t* name);
128     void SetDefActive(Bool_t active);
129     void SetSelector(TAMSelector* sel);
130     void SetVerbosity(UInt_t vb) { fVerbose = vb; }
131     void SetActive(Bool_t active = kTRUE) { SetDefActive(active); }
132    
133     static const char *Version();
134    
135     ClassDef(TAModule,3) // Abstract base class for modular processing a tree
136     };
137    
138    
139     //______________________________________________________________________________
140     template <class OC>
141     inline void TAModule::AddOutput(OC* const & obj)
142     {
143     // Add the object to the list of output objects of this module.
144     // The Proof facility can then merge this object from each worker
145     // computer.
146     // This version of the function will also store the address of the
147     // pointer, and if the pointer is a member of the module, the member
148     // will be made to point to the object in the output list on the
149     // client computer before Terminate is called.
150    
151     if (fOutput!=0) {
152     fOutput->AddOutput(obj);
153     } else {
154     SendError(kAbortAnalysis,
155     "AddOutput",
156     "fOutput is null in module [%s]",
157     GetName());
158     }
159     }
160    
161    
162     //______________________________________________________________________________
163     template <typename T>
164     inline void TAModule::ReqBranch(const Char_t* bname, T*& address)
165     {
166     // Requests that the branch with the specified name be made available
167     // during processing and that it be read in to the address specified.
168     // The TAMSelector will automatically change the value of the pointer
169     // pointed to ('*address') to the address of the branch entry when it
170     // is read in via LoadBranch.
171    
172     if (fSelector!=0) {
173     fSelector->ReqBranch(bname, address);
174     } else {
175     SendError(kAbortAnalysis,
176     "ReqBranch",
177     "fSelector is null in module [%s]",
178     GetName());
179     }
180     }
181    
182    
183     //______________________________________________________________________________
184     inline void TAModule::SetDefActive(Bool_t active)
185     {
186     // Set the activity and make it the default behavior.
187    
188     fDefActv = active;
189     TTask::SetActive(active);
190     }
191    
192     #endif //ROOT_TAModule