ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/HLTFwkMod.cc
Revision: 1.12
Committed: Tue Aug 11 15:24:39 2009 UTC (15 years, 8 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_011a, Mit_011, Mit_010a
Changes since 1.11: +4 -1 lines
Log Message:
Support different HLT menus

File Contents

# Content
1 // $Id: HLTFwkMod.cc,v 1.11 2009/07/13 13:45:30 loizides Exp $
2
3 #include "MitAna/TreeMod/interface/HLTFwkMod.h"
4 #include <TFile.h>
5 #include <TTree.h>
6 #include "MitAna/DataUtil/interface/Debug.h"
7 #include "MitAna/DataTree/interface/Names.h"
8 #include "MitAna/DataTree/interface/TriggerName.h"
9 #include "MitAna/DataTree/interface/TriggerTable.h"
10 #include "MitAna/DataTree/interface/TriggerObjectBaseCol.h"
11 #include "MitAna/DataTree/interface/TriggerObjectRelCol.h"
12 #include "MitAna/DataTree/interface/TriggerObjectCol.h"
13 #include "MitAna/DataTree/interface/TriggerObjectsTable.h"
14
15 using namespace mithep;
16
17 ClassImp(mithep::HLTFwkMod)
18
19
20 //--------------------------------------------------------------------------------------------------
21 HLTFwkMod::HLTFwkMod(const char *name, const char *title) :
22 BaseMod(name,title),
23 fHLTTreeName(Names::gkHltTreeName),
24 fHLTTabName(Names::gkHltTableBrn),
25 fHLTLabName(Names::gkHltLabelBrn),
26 fObjsName(Names::gkHltObjBrn),
27 fRelsName(Form("%sRelation",fObjsName.Data())),
28 fHLTTabNamePub(Form("%sFwk",fHLTTabName.Data())),
29 fHLTLabNamePub(Form("%sFwk",fHLTLabName.Data())),
30 fObjsNamePub(Form("%sFwk",fObjsName.Data())),
31 fNMaxTriggers(256),
32 fObjs(0),
33 fRels(0),
34 fReload(0),
35 fHLTTree(0),
36 fHLTTab(0),
37 fHLTLab(0),
38 fCurEnt(-2),
39 fTriggers(new TriggerTable(fNMaxTriggers)),
40 fLabels(new TriggerTable(fNMaxTriggers*16)),
41 fTrigObjs(new TriggerObjectsTable(fTriggers,fNMaxTriggers))
42 {
43 // Constructor.
44
45 fTriggers->SetName(fHLTTabNamePub);
46 fTriggers->SetOwner();
47 fLabels->SetName(fHLTLabNamePub);
48 fLabels->SetOwner();
49 fTrigObjs->SetName(fObjsNamePub);
50 fTrigObjs->SetOwner();
51 }
52
53 //--------------------------------------------------------------------------------------------------
54 HLTFwkMod::~HLTFwkMod()
55 {
56 // Destructor.
57
58 fReload = 0;
59 fHLTTree = 0;
60 fHLTTab = 0;
61 fHLTLab = 0;
62 fCurEnt = -2;
63 delete fTriggers;
64 fTriggers = 0;
65 delete fLabels;
66 fLabels = 0;
67 delete fTrigObjs;
68 fTrigObjs = 0;
69 }
70
71 //--------------------------------------------------------------------------------------------------
72 void HLTFwkMod::BeginRun()
73 {
74 // Get HLT tree and set branches if new file was opened. Read next entry in HLT key
75 // depending on entry in RunInfo.
76
77 if (fReload) {
78
79 // reset to be (re-)loaded variables
80 fReload = 0;
81 fHLTTree = 0;
82 fHLTTab = 0;
83 fHLTLab = 0;
84 fCurEnt = -2;
85
86 // get current file
87 TFile *file = GetCurrentFile();
88 if (!file)
89 return;
90
91 // get HLT tree
92 fHLTTree = dynamic_cast<TTree*>(file->Get(fHLTTreeName));
93 if (!fHLTTree) {
94 SendError(kAbortAnalysis, "BeginRun",
95 "Cannot find HLT tree with name %s.", fHLTTreeName.Data());
96 }
97
98 // get HLT trigger name branch
99 if (fHLTTree->GetBranch(fHLTTabName)) {
100 fHLTTree->SetBranchAddress(fHLTTabName, &fHLTTab);
101 } else {
102 SendError(kAbortAnalysis, "BeginRun",
103 "Cannot find HLT tree branch with name %s.", fHLTTabName.Data());
104 }
105
106 // get HLT module labels branch
107 if (fHLTTree->GetBranch(fHLTLabName)) {
108 fHLTTree->SetBranchAddress(fHLTLabName, &fHLTLab);
109 } else {
110 SendError(kAbortAnalysis, "BeginRun",
111 "Cannot find HLT tree branch with name %s.", fHLTLabName.Data());
112 }
113 }
114
115 // get entry for HLT info
116 const RunInfo *runinfo = GetRunInfo();
117 if (!runinfo) {
118 SendError(kAbortAnalysis, "BeginRun",
119 "Cannot obtain run info object from selector.");
120 return;
121 }
122
123 // load trigger table
124 if (runinfo->HltEntry()!=fCurEnt) {
125 MDB(kAnalysis, 1)
126 Info("BeginRun", "Loading trigger table for run %ld", runinfo->RunNum());
127
128 fCurEnt = runinfo->HltEntry();
129 Bool_t load = LoadTriggerTable();
130 if (!load) {
131 SendError(kAbortAnalysis, "BeginRun",
132 "Cannot load trigger table for next entry (%ld).", fCurEnt);
133 return;
134 }
135
136 MDB(kAnalysis, 2) {
137 Info("BeginRun", "Printing tables for run %ld", runinfo->RunNum());
138 cout << " --- Trigger table ---" << endl;
139 fTriggers->Print();
140 cout << " --- Module lables ---" << endl;
141 fLabels->Print();
142 }
143 }
144 }
145
146 //--------------------------------------------------------------------------------------------------
147 Bool_t HLTFwkMod::LoadTriggerTable()
148 {
149 // Load next trigger (and module) table from HLT tree.
150
151 if (fCurEnt<0)
152 return kFALSE;
153
154 // delete old tables
155 fTriggers->Delete();
156 fLabels->Delete();
157
158 // load next event in HLT tree
159 fHLTTab = 0;
160 fHLTLab = 0;
161 Int_t ret = fHLTTree->GetEvent(fCurEnt);
162 if (ret<0 || fHLTTab==0 || fHLTTab==0 ) {
163 SendError(kAbortAnalysis, "LoadTriggerTable",
164 "Could not get trigger data for next entry (%ld).", fCurEnt);
165 return kFALSE;
166 }
167
168 // check size of trigger table
169 if (fHLTTab->size()>fNMaxTriggers) {
170 SendError(kAbortAnalysis, "LoadTriggerTable",
171 "Size of trigger table (%ld) larger than maximum (%ld).",
172 fHLTTab->size(), fNMaxTriggers);
173 return kFALSE;
174 }
175
176 // add trigger names
177 for (UInt_t i=0; i<fHLTTab->size(); ++i) {
178 TriggerName *tname = new TriggerName(fHLTTab->at(i),i);
179 fTriggers->Add(tname);
180 }
181
182 // add module labels
183 for (UInt_t i=0; i<fHLTLab->size(); ++i) {
184 TriggerName *tname = new TriggerName(fHLTLab->at(i),i);
185 fLabels->Add(tname);
186 }
187
188 return kTRUE;
189 }
190
191 //--------------------------------------------------------------------------------------------------
192 Bool_t HLTFwkMod::Notify()
193 {
194 // Save notification of a new file, which will trigger the reloading of the tables and bitmasks.
195
196 fReload = kTRUE;
197 return kTRUE;
198 }
199
200 //--------------------------------------------------------------------------------------------------
201 void HLTFwkMod::Process()
202 {
203 // Read trigger objects and relation branch and fill our object table.
204
205 fTrigObjs->Delete();
206
207 LoadBranch(fObjsName);
208 LoadBranch(fRelsName);
209
210 for (UInt_t i=0; i<fRels->Entries(); ++i) {
211 const TriggerObjectRel *rel = fRels->At(i);
212 if (!rel) continue;
213
214 const TriggerObjectBase *ob = fObjs->At(rel->ObjInd());
215 if (!ob) continue;
216
217 TriggerObject *obj = new TriggerObject(rel->TrgId(), rel->Type(), ob->Id(),
218 ob->Pt(), ob->Eta(), ob->Phi(), ob->Mass());
219
220 obj->SetTrigName(fHLTTab->at(rel->TrgId()).c_str());
221 obj->SetModuleName(fHLTLab->at(rel->ModInd()).c_str());
222 obj->SetFilterName(fHLTLab->at(rel->FilterInd()).c_str());
223 if (obj->TagInd()>=0)
224 obj->SetTagName(fHLTLab->at(obj->TagInd()).c_str());
225 else
226 obj->SetTagName("Unknown");
227
228 fTrigObjs->Add(obj);
229 }
230 }
231
232 //--------------------------------------------------------------------------------------------------
233 void HLTFwkMod::SlaveBegin()
234 {
235 // Request branches for trigger objects and relation, and publish our tables.
236
237 if (fObjsName != Names::gkHltObjBrn)
238 fRelsName = Form("%sRelation",fObjsName.Data());
239
240 ReqBranch(fObjsName, fObjs);
241 ReqBranch(fRelsName, fRels);
242
243 if (!PublishObj(fTriggers)) {
244 SendError(kAbortAnalysis, "SlaveBegin",
245 "Could not publish HLT trigger table with name %s.", fTriggers->GetName());
246 return;
247 }
248 if (!PublishObj(fTrigObjs)) {
249 SendError(kAbortAnalysis, "SlaveBegin",
250 "Could not publish HLT trigger objects table with name %s.", fTrigObjs->GetName());
251 return;
252 }
253 if (!PublishObj(fLabels)) {
254 SendError(kAbortAnalysis, "SlaveBegin",
255 "Could not publish HLT labels with name %s.", fLabels->GetName());
256 return;
257 }
258 }
259
260 //--------------------------------------------------------------------------------------------------
261 void HLTFwkMod::SlaveTerminate()
262 {
263 // Retract our published objects.
264
265 RetractObj(fTriggers->GetName());
266 RetractObj(fLabels->GetName());
267 RetractObj(fTrigObjs->GetName());
268 }