ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/interface/BaseMod.h
Revision: 1.30
Committed: Wed Nov 25 15:13:16 2009 UTC (15 years, 5 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_025c_branch2, Mit_025c_branch1, Mit_025c_branch0, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013, Mit_013pre1, Mit_012i, Mit_012h, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c
Branch point for: Mit_025c_branch
Changes since 1.29: +7 -3 lines
Log Message:
Added GetTriggerTable

File Contents

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