1 |
loizides |
1.6 |
//--------------------------------------------------------------------------------------------------
|
2 |
bendavid |
1.25 |
// $Id: BaseMod.h,v 1.24 2009/07/13 11:08:10 loizides Exp $
|
3 |
loizides |
1.2 |
//
|
4 |
|
|
// BaseMod
|
5 |
|
|
//
|
6 |
loizides |
1.8 |
// This TAM module is the base module for all our TAM modules. It defines a couple of useful
|
7 |
|
|
// getters to retrieve information from the underlying framework code, such as the EventHeader,
|
8 |
|
|
// RunInfo or Trigger information.
|
9 |
loizides |
1.2 |
//
|
10 |
|
|
// Authors: C.Loizides
|
11 |
loizides |
1.6 |
//--------------------------------------------------------------------------------------------------
|
12 |
loizides |
1.2 |
|
13 |
loizides |
1.7 |
#ifndef MITANA_TREEMOD_BASEMOD_H
|
14 |
|
|
#define MITANA_TREEMOD_BASEMOD_H
|
15 |
loizides |
1.1 |
|
16 |
loizides |
1.19 |
#include <TObjString.h>
|
17 |
loizides |
1.1 |
#include "MitAna/TAM/interface/TAModule.h"
|
18 |
loizides |
1.8 |
#include "MitAna/TreeMod/interface/Selector.h"
|
19 |
loizides |
1.24 |
#include "MitAna/DataTree/interface/TriggerObjectCol.h"
|
20 |
bendavid |
1.25 |
#include "MitAna/DataCont/interface/ObjArray.h"
|
21 |
loizides |
1.1 |
|
22 |
|
|
namespace mithep
|
23 |
|
|
{
|
24 |
loizides |
1.12 |
class HLTFwkMod;
|
25 |
loizides |
1.21 |
class TriggerObjectsTable;
|
26 |
|
|
class TriggerTable;
|
27 |
loizides |
1.5 |
|
28 |
loizides |
1.1 |
class BaseMod : public TAModule {
|
29 |
|
|
public:
|
30 |
loizides |
1.12 |
BaseMod(const char *name="BaseMod", const char *title="Base analysis module");
|
31 |
loizides |
1.4 |
|
32 |
loizides |
1.19 |
private:
|
33 |
|
|
class ObjType : public TObjString {
|
34 |
|
|
public:
|
35 |
|
|
ObjType(const char *name="", Bool_t br=kTRUE) : TObjString(name), fBr(br) {}
|
36 |
|
|
~ObjType() {}
|
37 |
|
|
Bool_t IsBranch() const { return fBr; }
|
38 |
|
|
protected:
|
39 |
|
|
Bool_t fBr; //=true then object is from branch
|
40 |
|
|
};
|
41 |
|
|
|
42 |
loizides |
1.4 |
protected:
|
43 |
loizides |
1.19 |
void AddEventObject(const char *name, Bool_t fromBr=kTRUE);
|
44 |
loizides |
1.14 |
template <class T> void AddTH1(T *&ptr, const char *name, const char *title,
|
45 |
|
|
Int_t nbins, Double_t xmin, Double_t xmax);
|
46 |
|
|
template <class T> void AddTH2(T *&ptr, const char *name, const char *title,
|
47 |
|
|
Int_t nbinsx, Double_t xmin, Double_t xmax,
|
48 |
|
|
Int_t nbinsy, Double_t ymin, Double_t ymax);
|
49 |
phedex |
1.17 |
template <class T> void AddTH3(T *&ptr, const char *name, const char *title,
|
50 |
|
|
Int_t nbinsx, Double_t xmin, Double_t xmax,
|
51 |
|
|
Int_t nbinsy, Double_t ymin, Double_t ymax,
|
52 |
|
|
Int_t nbinsz, Double_t zmin, Double_t zmax);
|
53 |
loizides |
1.20 |
void AddToTrash(TObject *obj);
|
54 |
loizides |
1.9 |
const EventHeader *GetEventHeader() const { return GetSel()->GetEventHeader(); }
|
55 |
loizides |
1.19 |
Bool_t GetFillHist() const { return fFillHist; }
|
56 |
|
|
const HLTFwkMod *GetHltFwkMod() const { return fHltFwkMod; }
|
57 |
loizides |
1.12 |
const TriggerObjectCol *GetHLTObjects(const char *name) const;
|
58 |
|
|
const TriggerObjectsTable *GetHLTObjectsTable() const;
|
59 |
|
|
const TriggerTable *GetHLTTable() const;
|
60 |
loizides |
1.19 |
Int_t GetNEventsProcessed() const { return fNEventsProc; }
|
61 |
bendavid |
1.25 |
template <class T> const T *GetColThisEvt(const char *name, Bool_t warn=1);
|
62 |
loizides |
1.18 |
template <class T> const T *GetObjThisEvt(const char *name, Bool_t warn=1) const;
|
63 |
|
|
template <class T> T *GetObjThisEvt(const char *name, Bool_t warn=1);
|
64 |
|
|
template <class T> const T *GetPublicObj(const char *name, Bool_t warn=1) const;
|
65 |
|
|
template <class T> T *GetPublicObj(const char *name, Bool_t warn=1);
|
66 |
loizides |
1.19 |
const RunInfo *GetRunInfo() const { return GetSel()->GetRunInfo(); }
|
67 |
loizides |
1.9 |
const Selector *GetSel() const;
|
68 |
loizides |
1.12 |
Bool_t HasHLTInfo() const;
|
69 |
loizides |
1.19 |
void IncNEventsProcessed() { ++fNEventsProc; }
|
70 |
|
|
template <class T> Bool_t LoadEventObject(const char *name, const T *&addr, Bool_t warn=1);
|
71 |
|
|
template <class T> void ReqBranch(const char *bname, const T *&addr);
|
72 |
|
|
template <class T> void ReqEventObject(const char *name, const T *&addr);
|
73 |
|
|
template <class T> void ReqEventObject(const char *name, const T *&addr, Bool_t fromBr);
|
74 |
loizides |
1.9 |
void SaveNEventsProcessed(const char *name="hDEvents");
|
75 |
loizides |
1.19 |
void SetFillHist(Bool_t b) { fFillHist = b; }
|
76 |
loizides |
1.22 |
Bool_t ValidRunInfo() const { return GetSel()->ValidRunInfo(); }
|
77 |
loizides |
1.9 |
|
78 |
|
|
private:
|
79 |
loizides |
1.14 |
Bool_t fFillHist; //=true then fill histos (def=0)
|
80 |
loizides |
1.19 |
THashTable fEvtObjBrNames; //names of per-event objects
|
81 |
loizides |
1.12 |
mutable const HLTFwkMod *fHltFwkMod; //!pointer to HLTFwdMod
|
82 |
|
|
const TString fHltFwkModName; //!name of HLTFwkMod
|
83 |
loizides |
1.14 |
Int_t fNEventsProc; //!number of events
|
84 |
loizides |
1.1 |
|
85 |
loizides |
1.15 |
ClassDef(BaseMod, 1) // Base TAM module
|
86 |
loizides |
1.1 |
};
|
87 |
loizides |
1.6 |
}
|
88 |
loizides |
1.4 |
|
89 |
loizides |
1.6 |
//--------------------------------------------------------------------------------------------------
|
90 |
loizides |
1.19 |
inline void mithep::BaseMod::AddEventObject(const char *name, Bool_t fromBr)
|
91 |
|
|
{
|
92 |
|
|
// Add event object to list of objects that should be retrieved from a branch rather
|
93 |
|
|
// than from a pointer given by the event.
|
94 |
|
|
|
95 |
|
|
if (fEvtObjBrNames.FindObject(name)) {
|
96 |
loizides |
1.23 |
SendError(kWarning, Form("AddEventObject (\"%s\")",GetName()),
|
97 |
|
|
"Can not add event object with name \"\"%s\"\" and type %d",
|
98 |
loizides |
1.19 |
name, fromBr);
|
99 |
|
|
return;
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
fEvtObjBrNames.Add(new ObjType(name,fromBr));
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
//--------------------------------------------------------------------------------------------------
|
106 |
loizides |
1.14 |
template <class T>
|
107 |
|
|
inline void mithep::BaseMod::AddTH1(T *&ptr, const char *name, const char *title,
|
108 |
|
|
Int_t nbins, Double_t xmin, Double_t xmax)
|
109 |
|
|
{
|
110 |
|
|
// Create ROOT histogram and add it to the output list.
|
111 |
|
|
|
112 |
|
|
ptr = new T(name, title, nbins, xmin, xmax);
|
113 |
|
|
ptr->Sumw2();
|
114 |
|
|
AddOutput(ptr);
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
//--------------------------------------------------------------------------------------------------
|
118 |
|
|
template <class T>
|
119 |
|
|
inline void mithep::BaseMod::AddTH2(T *&ptr, const char *name, const char *title,
|
120 |
|
|
Int_t nbinsx, Double_t xmin, Double_t xmax,
|
121 |
|
|
Int_t nbinsy, Double_t ymin, Double_t ymax)
|
122 |
|
|
{
|
123 |
|
|
// Create ROOT histogram and add it to the output list.
|
124 |
|
|
|
125 |
|
|
ptr = new T(name, title, nbinsx, xmin, xmax, nbinsy, ymin, ymax);
|
126 |
|
|
ptr->Sumw2();
|
127 |
|
|
AddOutput(ptr);
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
//--------------------------------------------------------------------------------------------------
|
131 |
phedex |
1.17 |
template <class T>
|
132 |
|
|
inline void mithep::BaseMod::AddTH3(T *&ptr, const char *name, const char *title,
|
133 |
|
|
Int_t nbinsx, Double_t xmin, Double_t xmax,
|
134 |
|
|
Int_t nbinsy, Double_t ymin, Double_t ymax,
|
135 |
|
|
Int_t nbinsz, Double_t zmin, Double_t zmax)
|
136 |
|
|
{
|
137 |
|
|
// Create ROOT histogram and add it to the output list.
|
138 |
|
|
|
139 |
|
|
ptr = new T(name, title, nbinsx, xmin, xmax, nbinsy, ymin, ymax, nbinsz, zmin, zmax);
|
140 |
|
|
ptr->Sumw2();
|
141 |
|
|
AddOutput(ptr);
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
//--------------------------------------------------------------------------------------------------
|
145 |
loizides |
1.20 |
inline void mithep::BaseMod::AddToTrash(TObject *obj)
|
146 |
|
|
{
|
147 |
|
|
// Add object to trash. Trash will be emptied after an entry of the tree was processed.
|
148 |
|
|
|
149 |
|
|
Selector *sel = const_cast<Selector*>(GetSel());
|
150 |
|
|
sel->AddToTrash(obj);
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
//--------------------------------------------------------------------------------------------------
|
154 |
loizides |
1.8 |
inline const mithep::TriggerObjectCol *mithep::BaseMod::GetHLTObjects(const char *name) const
|
155 |
|
|
{
|
156 |
|
|
// Get pointer to HLT TriggerObjects collection with given name for the current event.
|
157 |
|
|
|
158 |
|
|
return (dynamic_cast<const TriggerObjectCol *>(FindObjThisEvt(name)));
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
//--------------------------------------------------------------------------------------------------
|
162 |
loizides |
1.10 |
template <class T>
|
163 |
bendavid |
1.25 |
const T *mithep::BaseMod::GetColThisEvt(const char *name, Bool_t warn)
|
164 |
|
|
{
|
165 |
|
|
|
166 |
|
|
// Get published object for the current event.
|
167 |
|
|
TObject *inObj = FindObjThisEvt(name);
|
168 |
|
|
T *ret = dynamic_cast<T*>(inObj);
|
169 |
|
|
|
170 |
|
|
if (ret)
|
171 |
|
|
return ret;
|
172 |
|
|
|
173 |
|
|
TString outName(name);
|
174 |
|
|
outName.Append("_GetColThisEvt_");
|
175 |
|
|
outName.Append(T::Class_Name());
|
176 |
|
|
|
177 |
|
|
ret = dynamic_cast<T*>(FindObjThisEvt(outName));
|
178 |
|
|
if (ret)
|
179 |
|
|
return ret;
|
180 |
|
|
|
181 |
|
|
mithep::BaseCollection *inCol = dynamic_cast<mithep::BaseCollection*>(inObj);
|
182 |
|
|
|
183 |
|
|
if (!inCol && warn) {
|
184 |
|
|
SendError(kWarning, Form("GetColThisEvt (\"%s\")",GetName()),
|
185 |
|
|
"Could not obtain collection with name \"%s\" and type \"%s\" for current event!",
|
186 |
|
|
name, T::Class_Name());
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
mithep::ObjArray<typename T::element_type> *newRet = new mithep::ObjArray<typename T::element_type>;
|
190 |
|
|
newRet->SetName(outName);
|
191 |
|
|
for (UInt_t i=0; i<inCol->GetEntries(); ++i) {
|
192 |
|
|
const typename T::element_type *outElement = dynamic_cast<typename T::element_type*>(inCol->ObjAt(i));
|
193 |
|
|
if (outElement)
|
194 |
|
|
newRet->Add(outElement);
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
AddObjThisEvt(newRet);
|
198 |
|
|
return newRet;
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
//--------------------------------------------------------------------------------------------------
|
202 |
|
|
template <class T>
|
203 |
loizides |
1.18 |
inline const T *mithep::BaseMod::GetObjThisEvt(const char *name, Bool_t warn) const
|
204 |
loizides |
1.13 |
{
|
205 |
|
|
// Get published object for the current event.
|
206 |
|
|
|
207 |
|
|
T *ret = dynamic_cast<T*>(FindObjThisEvt(name));
|
208 |
loizides |
1.18 |
if (!ret && warn) {
|
209 |
loizides |
1.23 |
SendError(kWarning, Form("GetObjThisEvt (\"%s\")",GetName()),
|
210 |
|
|
"Could not obtain object with name \"%s\" and type \"%s\" for current event!",
|
211 |
loizides |
1.13 |
name, T::Class_Name());
|
212 |
|
|
}
|
213 |
|
|
return ret;
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
//--------------------------------------------------------------------------------------------------
|
217 |
|
|
template <class T>
|
218 |
loizides |
1.18 |
inline T *mithep::BaseMod::GetObjThisEvt(const char *name, Bool_t warn)
|
219 |
loizides |
1.10 |
{
|
220 |
|
|
// Get published object for the current event.
|
221 |
|
|
|
222 |
|
|
T *ret = dynamic_cast<T*>(FindObjThisEvt(name));
|
223 |
loizides |
1.18 |
if (!ret && warn) {
|
224 |
loizides |
1.23 |
SendError(kWarning, Form("GetObjThisEvt (\"%s\")",GetName()),
|
225 |
|
|
"Could not obtain object with name \"%s\" and type \"%s\" for current event!",
|
226 |
loizides |
1.10 |
name, T::Class_Name());
|
227 |
|
|
}
|
228 |
|
|
return ret;
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
//--------------------------------------------------------------------------------------------------
|
232 |
|
|
template <class T>
|
233 |
loizides |
1.18 |
inline const T *mithep::BaseMod::GetPublicObj(const char *name, Bool_t warn) const
|
234 |
loizides |
1.13 |
{
|
235 |
|
|
// Get public object.
|
236 |
|
|
|
237 |
|
|
|
238 |
|
|
T *ret = dynamic_cast<T*>(FindPublicObj(name));
|
239 |
loizides |
1.18 |
if (!ret && warn) {
|
240 |
loizides |
1.23 |
SendError(kWarning, Form("GetPublicObject (\"%s\")",GetName()),
|
241 |
|
|
"Could not obtain public object with name \"%s\" and type \"%s\"!",
|
242 |
loizides |
1.13 |
name, T::Class_Name());
|
243 |
|
|
}
|
244 |
|
|
return ret;
|
245 |
|
|
}
|
246 |
|
|
|
247 |
|
|
//--------------------------------------------------------------------------------------------------
|
248 |
|
|
template <class T>
|
249 |
loizides |
1.18 |
inline T *mithep::BaseMod::GetPublicObj(const char *name, Bool_t warn)
|
250 |
loizides |
1.10 |
{
|
251 |
|
|
// Get public object.
|
252 |
|
|
|
253 |
|
|
T *ret = dynamic_cast<T*>(FindPublicObj(name));
|
254 |
loizides |
1.18 |
if (!ret && warn) {
|
255 |
loizides |
1.23 |
SendError(kWarning, Form("GetPublicObject (\"%s\")",GetName()),
|
256 |
|
|
"Could not obtain public object with name \"%s\" and type \"%s\"!",
|
257 |
loizides |
1.10 |
name, T::Class_Name());
|
258 |
|
|
}
|
259 |
|
|
return ret;
|
260 |
|
|
}
|
261 |
|
|
|
262 |
|
|
//--------------------------------------------------------------------------------------------------
|
263 |
loizides |
1.6 |
inline const mithep::Selector *mithep::BaseMod::GetSel() const
|
264 |
|
|
{
|
265 |
loizides |
1.8 |
// Get pointer to selector.
|
266 |
|
|
|
267 |
loizides |
1.6 |
return static_cast<const Selector*>(GetSelector());
|
268 |
loizides |
1.1 |
}
|
269 |
loizides |
1.13 |
|
270 |
|
|
//--------------------------------------------------------------------------------------------------
|
271 |
|
|
template <class T>
|
272 |
loizides |
1.19 |
inline Bool_t mithep::BaseMod::LoadEventObject(const char *name, const T *&addr, Bool_t warn)
|
273 |
loizides |
1.13 |
{
|
274 |
loizides |
1.19 |
// Obtain the object with the specified name that has been requested during processing.
|
275 |
|
|
// In case name is found in fEvtObjBrNames it will be read from a branch to the
|
276 |
|
|
// address specified in ReqEventObject.
|
277 |
|
|
|
278 |
|
|
TString type("event");
|
279 |
|
|
ObjType *o = static_cast<ObjType*>(fEvtObjBrNames.FindObject(name));
|
280 |
|
|
if (o && o->IsBranch()) {
|
281 |
|
|
type = "branch";
|
282 |
|
|
LoadBranch(name);
|
283 |
|
|
} else {
|
284 |
|
|
addr = GetObjThisEvt<T>(name);
|
285 |
|
|
}
|
286 |
|
|
|
287 |
|
|
Bool_t ret = (addr!=0);
|
288 |
|
|
if (!ret && warn) {
|
289 |
loizides |
1.23 |
SendError(kWarning, Form("LoadEventObject (\"%s\")",GetName()),
|
290 |
|
|
"Could not obtain object with name \"%s\" and type \"%s\" from \"%s\"!",
|
291 |
loizides |
1.19 |
name, T::Class_Name(), type.Data());
|
292 |
|
|
}
|
293 |
|
|
|
294 |
|
|
return ret;
|
295 |
|
|
}
|
296 |
|
|
|
297 |
|
|
//--------------------------------------------------------------------------------------------------
|
298 |
|
|
template <class T>
|
299 |
|
|
inline void mithep::BaseMod::ReqBranch(const char *bname, const T *&addr)
|
300 |
|
|
{
|
301 |
|
|
// Requests that the branch with the specified name is made available
|
302 |
loizides |
1.13 |
// during processing and that it be read in to the address specified.
|
303 |
|
|
|
304 |
loizides |
1.19 |
TAModule::ReqBranch(bname, const_cast<T*&>(addr));
|
305 |
|
|
}
|
306 |
|
|
|
307 |
|
|
//--------------------------------------------------------------------------------------------------
|
308 |
|
|
template <class T>
|
309 |
|
|
inline void mithep::BaseMod::ReqEventObject(const char *name, const T *&addr)
|
310 |
|
|
{
|
311 |
|
|
// Requests that the object with the specified name is made available
|
312 |
|
|
// during processing. In case name is found in fEvtObjBrNames it
|
313 |
|
|
// will be read from a branch to the address specified.
|
314 |
|
|
|
315 |
|
|
ObjType *o = static_cast<ObjType*>(fEvtObjBrNames.FindObject(name));
|
316 |
|
|
if (!o || !o->IsBranch())
|
317 |
|
|
return;
|
318 |
|
|
|
319 |
|
|
ReqBranch(name, addr);
|
320 |
|
|
}
|
321 |
|
|
|
322 |
|
|
//--------------------------------------------------------------------------------------------------
|
323 |
|
|
template <class T>
|
324 |
|
|
inline void mithep::BaseMod::ReqEventObject(const char *name, const T *&addr, Bool_t fromBr)
|
325 |
|
|
{
|
326 |
|
|
// Requests that the object with the specified name is made available
|
327 |
|
|
// during processing. In case name is found in fEvtObjBrNames it
|
328 |
|
|
// will be read from a branch to the address specified.
|
329 |
|
|
|
330 |
|
|
ObjType *o = static_cast<ObjType*>(fEvtObjBrNames.FindObject(name));
|
331 |
|
|
if (!o && fromBr)
|
332 |
|
|
AddEventObject(name, fromBr);
|
333 |
|
|
|
334 |
|
|
ReqEventObject(name, addr);
|
335 |
loizides |
1.13 |
}
|
336 |
loizides |
1.1 |
#endif
|