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