1 |
loizides |
1.14 |
// $Id: HLTFwkMod.cc,v 1.13 2009/10/26 11:04:56 loizides Exp $
|
2 |
loizides |
1.1 |
|
3 |
|
|
#include "MitAna/TreeMod/interface/HLTFwkMod.h"
|
4 |
|
|
#include <TFile.h>
|
5 |
|
|
#include <TTree.h>
|
6 |
loizides |
1.6 |
#include "MitAna/DataUtil/interface/Debug.h"
|
7 |
loizides |
1.1 |
#include "MitAna/DataTree/interface/Names.h"
|
8 |
|
|
#include "MitAna/DataTree/interface/TriggerName.h"
|
9 |
loizides |
1.10 |
#include "MitAna/DataTree/interface/TriggerTable.h"
|
10 |
|
|
#include "MitAna/DataTree/interface/TriggerObjectBaseCol.h"
|
11 |
|
|
#include "MitAna/DataTree/interface/TriggerObjectRelCol.h"
|
12 |
loizides |
1.9 |
#include "MitAna/DataTree/interface/TriggerObjectCol.h"
|
13 |
loizides |
1.10 |
#include "MitAna/DataTree/interface/TriggerObjectsTable.h"
|
14 |
loizides |
1.1 |
|
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 |
loizides |
1.14 |
fL1ATabNamePub("L1AlgoTableFwk"),
|
32 |
|
|
fL1TTabNamePub("L1TechTableFwk"),
|
33 |
loizides |
1.1 |
fNMaxTriggers(256),
|
34 |
|
|
fObjs(0),
|
35 |
|
|
fRels(0),
|
36 |
|
|
fReload(0),
|
37 |
|
|
fHLTTree(0),
|
38 |
|
|
fHLTTab(0),
|
39 |
|
|
fHLTLab(0),
|
40 |
|
|
fCurEnt(-2),
|
41 |
|
|
fTriggers(new TriggerTable(fNMaxTriggers)),
|
42 |
|
|
fLabels(new TriggerTable(fNMaxTriggers*16)),
|
43 |
loizides |
1.14 |
fTrigObjs(new TriggerObjectsTable(fTriggers,fNMaxTriggers)),
|
44 |
|
|
fL1Algos(new TriggerTable(fNMaxTriggers)),
|
45 |
|
|
fL1Techs(new TriggerTable(fNMaxTriggers))
|
46 |
loizides |
1.1 |
{
|
47 |
|
|
// Constructor.
|
48 |
|
|
|
49 |
|
|
fTriggers->SetName(fHLTTabNamePub);
|
50 |
|
|
fTriggers->SetOwner();
|
51 |
|
|
fLabels->SetName(fHLTLabNamePub);
|
52 |
|
|
fLabels->SetOwner();
|
53 |
|
|
fTrigObjs->SetName(fObjsNamePub);
|
54 |
|
|
fTrigObjs->SetOwner();
|
55 |
loizides |
1.14 |
fL1Algos->SetName(fL1ATabNamePub);
|
56 |
|
|
fL1Algos->SetOwner();
|
57 |
|
|
fL1Techs->SetName(fL1TTabNamePub);
|
58 |
|
|
fL1Techs->SetOwner();
|
59 |
loizides |
1.1 |
}
|
60 |
|
|
|
61 |
|
|
//--------------------------------------------------------------------------------------------------
|
62 |
|
|
HLTFwkMod::~HLTFwkMod()
|
63 |
|
|
{
|
64 |
|
|
// Destructor.
|
65 |
|
|
|
66 |
|
|
fReload = 0;
|
67 |
|
|
fHLTTree = 0;
|
68 |
|
|
fHLTTab = 0;
|
69 |
|
|
fHLTLab = 0;
|
70 |
|
|
fCurEnt = -2;
|
71 |
|
|
delete fTriggers;
|
72 |
|
|
fTriggers = 0;
|
73 |
|
|
delete fLabels;
|
74 |
|
|
fLabels = 0;
|
75 |
|
|
delete fTrigObjs;
|
76 |
|
|
fTrigObjs = 0;
|
77 |
loizides |
1.14 |
delete fL1Algos;
|
78 |
|
|
|
79 |
loizides |
1.1 |
}
|
80 |
|
|
|
81 |
|
|
//--------------------------------------------------------------------------------------------------
|
82 |
|
|
void HLTFwkMod::BeginRun()
|
83 |
|
|
{
|
84 |
|
|
// Get HLT tree and set branches if new file was opened. Read next entry in HLT key
|
85 |
|
|
// depending on entry in RunInfo.
|
86 |
|
|
|
87 |
|
|
if (fReload) {
|
88 |
|
|
|
89 |
|
|
// reset to be (re-)loaded variables
|
90 |
|
|
fReload = 0;
|
91 |
|
|
fHLTTree = 0;
|
92 |
|
|
fHLTTab = 0;
|
93 |
|
|
fHLTLab = 0;
|
94 |
|
|
fCurEnt = -2;
|
95 |
|
|
|
96 |
|
|
// get current file
|
97 |
|
|
TFile *file = GetCurrentFile();
|
98 |
|
|
if (!file)
|
99 |
|
|
return;
|
100 |
|
|
|
101 |
|
|
// get HLT tree
|
102 |
|
|
fHLTTree = dynamic_cast<TTree*>(file->Get(fHLTTreeName));
|
103 |
|
|
if (!fHLTTree) {
|
104 |
|
|
SendError(kAbortAnalysis, "BeginRun",
|
105 |
loizides |
1.6 |
"Cannot find HLT tree with name %s.", fHLTTreeName.Data());
|
106 |
loizides |
1.1 |
}
|
107 |
|
|
|
108 |
|
|
// get HLT trigger name branch
|
109 |
|
|
if (fHLTTree->GetBranch(fHLTTabName)) {
|
110 |
|
|
fHLTTree->SetBranchAddress(fHLTTabName, &fHLTTab);
|
111 |
|
|
} else {
|
112 |
|
|
SendError(kAbortAnalysis, "BeginRun",
|
113 |
loizides |
1.6 |
"Cannot find HLT tree branch with name %s.", fHLTTabName.Data());
|
114 |
loizides |
1.1 |
}
|
115 |
|
|
|
116 |
|
|
// get HLT module labels branch
|
117 |
|
|
if (fHLTTree->GetBranch(fHLTLabName)) {
|
118 |
|
|
fHLTTree->SetBranchAddress(fHLTLabName, &fHLTLab);
|
119 |
|
|
} else {
|
120 |
|
|
SendError(kAbortAnalysis, "BeginRun",
|
121 |
loizides |
1.6 |
"Cannot find HLT tree branch with name %s.", fHLTLabName.Data());
|
122 |
loizides |
1.1 |
}
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
// get entry for HLT info
|
126 |
|
|
const RunInfo *runinfo = GetRunInfo();
|
127 |
|
|
if (!runinfo) {
|
128 |
|
|
SendError(kAbortAnalysis, "BeginRun",
|
129 |
loizides |
1.6 |
"Cannot obtain run info object from selector.");
|
130 |
loizides |
1.1 |
return;
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
// load trigger table
|
134 |
|
|
if (runinfo->HltEntry()!=fCurEnt) {
|
135 |
loizides |
1.7 |
MDB(kAnalysis, 1)
|
136 |
loizides |
1.6 |
Info("BeginRun", "Loading trigger table for run %ld", runinfo->RunNum());
|
137 |
|
|
|
138 |
loizides |
1.1 |
fCurEnt = runinfo->HltEntry();
|
139 |
|
|
Bool_t load = LoadTriggerTable();
|
140 |
|
|
if (!load) {
|
141 |
|
|
SendError(kAbortAnalysis, "BeginRun",
|
142 |
loizides |
1.6 |
"Cannot load trigger table for next entry (%ld).", fCurEnt);
|
143 |
loizides |
1.1 |
return;
|
144 |
|
|
}
|
145 |
loizides |
1.6 |
|
146 |
loizides |
1.7 |
MDB(kAnalysis, 2) {
|
147 |
loizides |
1.6 |
Info("BeginRun", "Printing tables for run %ld", runinfo->RunNum());
|
148 |
|
|
cout << " --- Trigger table ---" << endl;
|
149 |
|
|
fTriggers->Print();
|
150 |
|
|
cout << " --- Module lables ---" << endl;
|
151 |
|
|
fLabels->Print();
|
152 |
loizides |
1.14 |
if (fL1Algos->GetEntries()) {
|
153 |
|
|
cout << " --- L1 Algos ---" << endl;
|
154 |
|
|
fL1Algos->Print();
|
155 |
|
|
}
|
156 |
|
|
if (fL1Techs->GetEntries()) {
|
157 |
|
|
cout << " --- L1 Techs ---" << endl;
|
158 |
|
|
fL1Techs->Print();
|
159 |
|
|
}
|
160 |
loizides |
1.6 |
}
|
161 |
loizides |
1.1 |
}
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
//--------------------------------------------------------------------------------------------------
|
165 |
|
|
Bool_t HLTFwkMod::LoadTriggerTable()
|
166 |
|
|
{
|
167 |
|
|
// Load next trigger (and module) table from HLT tree.
|
168 |
|
|
|
169 |
|
|
if (fCurEnt<0)
|
170 |
|
|
return kFALSE;
|
171 |
|
|
|
172 |
|
|
// delete old tables
|
173 |
|
|
fTriggers->Delete();
|
174 |
|
|
fLabels->Delete();
|
175 |
loizides |
1.14 |
fL1Algos->Delete();
|
176 |
|
|
fL1Techs->Delete();
|
177 |
loizides |
1.1 |
|
178 |
|
|
// load next event in HLT tree
|
179 |
|
|
fHLTTab = 0;
|
180 |
|
|
fHLTLab = 0;
|
181 |
|
|
Int_t ret = fHLTTree->GetEvent(fCurEnt);
|
182 |
|
|
if (ret<0 || fHLTTab==0 || fHLTTab==0 ) {
|
183 |
loizides |
1.8 |
SendError(kAbortAnalysis, "LoadTriggerTable",
|
184 |
|
|
"Could not get trigger data for next entry (%ld).", fCurEnt);
|
185 |
loizides |
1.1 |
return kFALSE;
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
// check size of trigger table
|
189 |
loizides |
1.5 |
if (fHLTTab->size()>fNMaxTriggers) {
|
190 |
loizides |
1.1 |
SendError(kAbortAnalysis, "LoadTriggerTable",
|
191 |
loizides |
1.6 |
"Size of trigger table (%ld) larger than maximum (%ld).",
|
192 |
loizides |
1.7 |
fHLTTab->size(), fNMaxTriggers);
|
193 |
loizides |
1.1 |
return kFALSE;
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
// add trigger names
|
197 |
loizides |
1.5 |
for (UInt_t i=0; i<fHLTTab->size(); ++i) {
|
198 |
|
|
TriggerName *tname = new TriggerName(fHLTTab->at(i),i);
|
199 |
loizides |
1.1 |
fTriggers->Add(tname);
|
200 |
|
|
}
|
201 |
|
|
|
202 |
|
|
// add module labels
|
203 |
loizides |
1.14 |
UInt_t counter = 0;
|
204 |
|
|
UInt_t bitnum = 0;
|
205 |
|
|
UInt_t which = 0;
|
206 |
|
|
while (counter<fHLTLab->size()) {
|
207 |
|
|
TString tmpn(fHLTLab->at(counter));
|
208 |
|
|
++counter;
|
209 |
|
|
if (tmpn.CompareTo("xxx-L1AlgoNames-xxx",TString::kIgnoreCase)==0) {
|
210 |
|
|
bitnum = 0;
|
211 |
|
|
which = 1;
|
212 |
|
|
continue;
|
213 |
|
|
} else if (tmpn.CompareTo("xxx-L1TechNames-xxx",TString::kIgnoreCase)==0) {
|
214 |
|
|
bitnum = 0;
|
215 |
|
|
which = 2;
|
216 |
|
|
continue;
|
217 |
|
|
}
|
218 |
|
|
TriggerName *tname = new TriggerName(tmpn,bitnum);
|
219 |
|
|
if (which==0)
|
220 |
|
|
fLabels->Add(tname);
|
221 |
|
|
else if (which==1)
|
222 |
|
|
fL1Algos->Add(tname);
|
223 |
|
|
else
|
224 |
|
|
fL1Techs->Add(tname);
|
225 |
|
|
++bitnum;
|
226 |
loizides |
1.1 |
}
|
227 |
|
|
|
228 |
|
|
return kTRUE;
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
//--------------------------------------------------------------------------------------------------
|
232 |
|
|
Bool_t HLTFwkMod::Notify()
|
233 |
|
|
{
|
234 |
|
|
// Save notification of a new file, which will trigger the reloading of the tables and bitmasks.
|
235 |
|
|
|
236 |
|
|
fReload = kTRUE;
|
237 |
|
|
return kTRUE;
|
238 |
|
|
}
|
239 |
|
|
|
240 |
|
|
//--------------------------------------------------------------------------------------------------
|
241 |
|
|
void HLTFwkMod::Process()
|
242 |
|
|
{
|
243 |
|
|
// Read trigger objects and relation branch and fill our object table.
|
244 |
|
|
|
245 |
|
|
fTrigObjs->Delete();
|
246 |
|
|
|
247 |
loizides |
1.2 |
LoadBranch(fObjsName);
|
248 |
|
|
LoadBranch(fRelsName);
|
249 |
loizides |
1.1 |
|
250 |
loizides |
1.13 |
const UInt_t n = fRels->GetEntries();
|
251 |
|
|
for (UInt_t i=0; i<n; ++i) {
|
252 |
loizides |
1.1 |
const TriggerObjectRel *rel = fRels->At(i);
|
253 |
loizides |
1.3 |
if (!rel) continue;
|
254 |
loizides |
1.1 |
|
255 |
|
|
const TriggerObjectBase *ob = fObjs->At(rel->ObjInd());
|
256 |
loizides |
1.3 |
if (!ob) continue;
|
257 |
loizides |
1.1 |
|
258 |
|
|
TriggerObject *obj = new TriggerObject(rel->TrgId(), rel->Type(), ob->Id(),
|
259 |
|
|
ob->Pt(), ob->Eta(), ob->Phi(), ob->Mass());
|
260 |
|
|
|
261 |
loizides |
1.5 |
obj->SetTrigName(fHLTTab->at(rel->TrgId()).c_str());
|
262 |
|
|
obj->SetModuleName(fHLTLab->at(rel->ModInd()).c_str());
|
263 |
|
|
obj->SetFilterName(fHLTLab->at(rel->FilterInd()).c_str());
|
264 |
loizides |
1.11 |
if (obj->TagInd()>=0)
|
265 |
|
|
obj->SetTagName(fHLTLab->at(obj->TagInd()).c_str());
|
266 |
|
|
else
|
267 |
|
|
obj->SetTagName("Unknown");
|
268 |
|
|
|
269 |
loizides |
1.1 |
fTrigObjs->Add(obj);
|
270 |
|
|
}
|
271 |
|
|
}
|
272 |
|
|
|
273 |
|
|
//--------------------------------------------------------------------------------------------------
|
274 |
|
|
void HLTFwkMod::SlaveBegin()
|
275 |
|
|
{
|
276 |
|
|
// Request branches for trigger objects and relation, and publish our tables.
|
277 |
|
|
|
278 |
loizides |
1.12 |
if (fObjsName != Names::gkHltObjBrn)
|
279 |
|
|
fRelsName = Form("%sRelation",fObjsName.Data());
|
280 |
|
|
|
281 |
loizides |
1.2 |
ReqBranch(fObjsName, fObjs);
|
282 |
|
|
ReqBranch(fRelsName, fRels);
|
283 |
loizides |
1.1 |
|
284 |
|
|
if (!PublishObj(fTriggers)) {
|
285 |
|
|
SendError(kAbortAnalysis, "SlaveBegin",
|
286 |
|
|
"Could not publish HLT trigger table with name %s.", fTriggers->GetName());
|
287 |
|
|
return;
|
288 |
|
|
}
|
289 |
|
|
if (!PublishObj(fTrigObjs)) {
|
290 |
|
|
SendError(kAbortAnalysis, "SlaveBegin",
|
291 |
|
|
"Could not publish HLT trigger objects table with name %s.", fTrigObjs->GetName());
|
292 |
|
|
return;
|
293 |
|
|
}
|
294 |
|
|
if (!PublishObj(fLabels)) {
|
295 |
|
|
SendError(kAbortAnalysis, "SlaveBegin",
|
296 |
|
|
"Could not publish HLT labels with name %s.", fLabels->GetName());
|
297 |
|
|
return;
|
298 |
|
|
}
|
299 |
loizides |
1.14 |
if (!PublishObj(fL1Algos)) {
|
300 |
|
|
SendError(kAbortAnalysis, "SlaveBegin",
|
301 |
|
|
"Could not publish L1 algo table with name %s.", fL1Algos->GetName());
|
302 |
|
|
return;
|
303 |
|
|
}
|
304 |
|
|
if (!PublishObj(fL1Techs)) {
|
305 |
|
|
SendError(kAbortAnalysis, "SlaveBegin",
|
306 |
|
|
"Could not publish L1 tech table with name %s.", fL1Techs->GetName());
|
307 |
|
|
return;
|
308 |
|
|
}
|
309 |
loizides |
1.1 |
}
|
310 |
|
|
|
311 |
|
|
//--------------------------------------------------------------------------------------------------
|
312 |
|
|
void HLTFwkMod::SlaveTerminate()
|
313 |
|
|
{
|
314 |
|
|
// Retract our published objects.
|
315 |
|
|
|
316 |
|
|
RetractObj(fTriggers->GetName());
|
317 |
|
|
RetractObj(fLabels->GetName());
|
318 |
|
|
RetractObj(fTrigObjs->GetName());
|
319 |
loizides |
1.14 |
RetractObj(fL1Algos->GetName());
|
320 |
|
|
RetractObj(fL1Techs->GetName());
|
321 |
loizides |
1.1 |
}
|