ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/interface/BaseMod.h
Revision: 1.20
Committed: Thu Jun 11 08:59:32 2009 UTC (15 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_009a
Changes since 1.19: +11 -1 lines
Log Message:
Provide trash for event loop.

File Contents

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