ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/HLTFwkMod.cc
Revision: 1.9
Committed: Mon Jun 15 15:00:17 2009 UTC (15 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_009c, Mit_009b
Changes since 1.8: +2 -1 lines
Log Message:
Added proper fwd defs plus split up complilation of MitAna/DataTree LinkDefs.

File Contents

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