ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TAM/interface/TAModule.h
Revision: 1.4
Committed: Thu Dec 4 13:50:56 2008 UTC (16 years, 5 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_008pre2, Mit_008pre1, Mit_006b, Mit_006a
Changes since 1.3: +5 -5 lines
Log Message:
Have TAModule::ls

File Contents

# Content
1 //
2 // $Id: TAModule.h,v 1.3 2008/06/24 14:03:45 loizides Exp $
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 kExecBeginRun; //!key to mark BeginRun
54 static const Char_t kExecEndRun; //!key to mark EndRun
55 static const Char_t kExecSlaveTerminate; //!key to mark SlaveTerminate
56 static const Char_t kExecTerminate; //!key to mark Terminate
57
58 void AbortAnalysis();
59 void AbortEvent();
60 void AbortModule();
61 void DeactivateAll();
62 void NewOutputList(TList* list);
63 Bool_t NotifyAll();
64 void ResetAllActiveFlags();
65 void SetAllModOutput(TAMOutput* o);
66 void SetModOutput(TAMOutput* o);
67 void StopModule();
68
69 protected:
70
71 // utility functions to be used by derived classes
72 virtual Bool_t AddObjThisEvt(TObject* obj);
73 virtual Bool_t AddObjThisEvt(TObject* obj, const char *name);
74 template <class OC>
75 void AddOutput(OC* const & obj);
76 const TAMSelector *GetSelector() const { return fSelector; }
77 Bool_t IsEventAborted() const { return (fSelector==0) ? kFALSE : fSelector->IsEventAborted(); }
78 Bool_t IsAnalysisAborted() const { return (fSelector==0) ? kFALSE : fSelector->IsAnalysisAborted(); }
79 void ls(Option_t *option) const;
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 virtual void BeginRun() {}
97 virtual void EndRun() {}
98 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