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