ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TAM/interface/TAModule.h
Revision: 1.5
Committed: Mon Mar 23 08:36:30 2009 UTC (16 years, 1 month ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_009, Mit_008
Changes since 1.4: +9 -8 lines
Log Message:
Allow calls to AbortAnalysis, AbortEvent and AbortModule from derived modules. Previously this was only possible when SendError was used.

File Contents

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