ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TAM/interface/TAModule.h
Revision: 1.1
Committed: Tue May 27 19:13:21 2008 UTC (16 years, 11 months ago) by loizides
Content type: text/plain
Branch: MAIN
Log Message:
TAM trunk 5120

File Contents

# User Rev Content
1 loizides 1.1 //
2     // $Id: TAModule.h 3594 2007-01-05 22:52:44Z loizides $
3     //
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     static const Char_t kExecSlaveTerminate; //!key to mark SlaveTerminate
54     static const Char_t kExecTerminate; //!key to mark Terminate
55    
56     // to be called by friend class TAMSelector only
57     void AbortAnalysis();
58     void AbortEvent();
59     void AbortModule();
60     void DeactivateAll();
61     void NewOutputList(TList* list);
62     Bool_t NotifyAll();
63     void ResetAllActiveFlags();
64     void SetAllModOutput(TAMOutput* o);
65     void SetModOutput(TAMOutput* o);
66     void StopModule();
67    
68     protected:
69    
70     // utility functions to be used by derived classes
71     virtual Bool_t AddObjThisEvt(TObject* obj);
72     virtual Bool_t AddObjThisEvt(TObject* obj, const char *name);
73     template <class OC>
74     void AddOutput(OC* const & obj);
75     Bool_t IsEventAborted() const { return (fSelector==0) ? kFALSE : fSelector->IsEventAborted(); }
76     Bool_t IsAnalysisAborted() const { return (fSelector==0) ? kFALSE : fSelector->IsAnalysisAborted(); }
77     void LoadBranch(const Char_t* bname);
78     virtual TObject *FindObjThisEvt(const Char_t* name) const;
79     virtual Bool_t Notify() { return kTRUE; }
80     virtual TObject *RemoveObjThisEvt(const Char_t* name);
81     void RemoveOutput(TObject* obj);
82     template <typename T>
83     void ReqBranch(const Char_t* bname, T*& address);
84     void SendError(const EModResult errLevel,
85     const Char_t* location,
86     const Char_t* formattedMsg, ...);
87     void SkipEvent();
88    
89     // functions to be overloaded by specific TAModule
90     virtual void Begin() {}
91     virtual void SlaveBegin() {}
92     virtual void Process() {}
93     virtual void SlaveTerminate() {}
94     virtual void Terminate() {}
95    
96     public:
97    
98     TAModule();
99     TAModule(const Char_t* name, const Char_t* title);
100     virtual ~TAModule();
101    
102     virtual void Browse(TBrowser* b);
103     // intentionally have no GetSelector as modules should never directly
104     // interact with the selector, the input list or the output list
105     Bool_t CheckSelectors(const TAMSelector* sel,
106     const Bool_t warn=kTRUE) const;
107     // TAMSelector is a friend to allow it to call Exec
108     // using the private variables such as kExecProcess
109     // and to prevent TAModules inheritting from this class
110     // from making such explicit calls.
111     friend class TAMSelector;
112     void Exec(Option_t* option);
113     TObject *FindPublicObj(const Char_t* name) const;
114     TFile *GetCurrentFile() const;
115     const TAMOutput *GetModOutput() const { return fOutput; }
116     TAMOutput *GetModOutput() { return fOutput; }
117     TList* GetSubModules() { return GetListOfTasks(); }
118     const TList *GetSubModules() const { return GetListOfTasks(); }
119     UInt_t GetVerbosity() const { return fVerbose; }
120     virtual void Print(Option_t *option="") const;
121     Bool_t PublishObj(TObject* obj);
122     TObject *RetractObj(const Char_t* name);
123     void SetDefActive(Bool_t active);
124     void SetSelector(TAMSelector* sel);
125     void SetVerbosity(UInt_t vb) { fVerbose = vb; }
126     void SetActive(Bool_t active = kTRUE) { SetDefActive(active); }
127    
128     static const char *Version();
129    
130     ClassDef(TAModule,3) // Abstract base class for modular processing a tree
131     };
132    
133    
134     //______________________________________________________________________________
135     template <class OC>
136     inline void TAModule::AddOutput(OC* const & obj)
137     {
138     // Add the object to the list of output objects of this module.
139     // The Proof facility can then merge this object from each worker
140     // computer.
141     // This version of the function will also store the address of the
142     // pointer, and if the pointer is a member of the module, the member
143     // will be made to point to the object in the output list on the
144     // client computer before Terminate is called.
145    
146     if (fOutput!=0) {
147     fOutput->AddOutput(obj);
148     } else {
149     SendError(kAbortAnalysis,
150     "AddOutput",
151     "fOutput is null in module [%s]",
152     GetName());
153     }
154     }
155    
156    
157     //______________________________________________________________________________
158     template <typename T>
159     inline void TAModule::ReqBranch(const Char_t* bname, T*& address)
160     {
161     // Requests that the branch with the specified name be made available
162     // during processing and that it be read in to the address specified.
163     // The TAMSelector will automatically change the value of the pointer
164     // pointed to ('*address') to the address of the branch entry when it
165     // is read in via LoadBranch.
166    
167     if (fSelector!=0) {
168     fSelector->ReqBranch(bname, address);
169     } else {
170     SendError(kAbortAnalysis,
171     "ReqBranch",
172     "fSelector is null in module [%s]",
173     GetName());
174     }
175     }
176    
177    
178     //______________________________________________________________________________
179     inline void TAModule::SetDefActive(Bool_t active)
180     {
181     // Set the activity and make it the default behavior.
182    
183     fDefActv = active;
184     TTask::SetActive(active);
185     }
186    
187     #endif //ROOT_TAModule