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