ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/HLTFwkMod.cc
Revision: 1.5
Committed: Mon Mar 2 13:26:45 2009 UTC (16 years, 2 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_008pre2, Mit_008pre1
Changes since 1.4: +10 -10 lines
Log Message:
Removed Vector<std:string>

File Contents

# User Rev Content
1 loizides 1.5 // $Id: HLTFwkMod.cc,v 1.4 2009/02/13 14:45:29 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 loizides 1.4 if ((fCurEnt==1) && (fHLTTree->GetEntries()==1)) {
139     if (1)
140     SendError(kWarning, "LoadTriggerTable",
141     "Loading trigger table omitted due to a bug fix for Mit_006.");
142     return kTRUE;
143     }
144    
145 loizides 1.1 // delete old tables
146     fTriggers->Delete();
147     fLabels->Delete();
148    
149     // load next event in HLT tree
150     fHLTTab = 0;
151     fHLTLab = 0;
152     Int_t ret = fHLTTree->GetEvent(fCurEnt);
153     if (ret<0 || fHLTTab==0 || fHLTTab==0 ) {
154     ::Error("LoadTriggerTable", "Could not get entries for next event %ud", fCurEnt);
155     return kFALSE;
156     }
157    
158     // check size of trigger table
159 loizides 1.5 if (fHLTTab->size()>fNMaxTriggers) {
160 loizides 1.1 SendError(kAbortAnalysis, "LoadTriggerTable",
161     "Size of trigger table (%d) larger than maximum (%d)",
162 loizides 1.5 fHLTTab->size(), fNMaxTriggers);
163 loizides 1.1 return kFALSE;
164     }
165    
166     // add trigger names
167 loizides 1.5 for (UInt_t i=0; i<fHLTTab->size(); ++i) {
168     TriggerName *tname = new TriggerName(fHLTTab->at(i),i);
169 loizides 1.1 fTriggers->Add(tname);
170     }
171    
172     // add module labels
173 loizides 1.5 for (UInt_t i=0; i<fHLTLab->size(); ++i) {
174     TriggerName *tname = new TriggerName(fHLTLab->at(i),i);
175 loizides 1.1 fLabels->Add(tname);
176     }
177    
178     return kTRUE;
179     }
180    
181     //--------------------------------------------------------------------------------------------------
182     Bool_t HLTFwkMod::Notify()
183     {
184     // Save notification of a new file, which will trigger the reloading of the tables and bitmasks.
185    
186     fReload = kTRUE;
187     return kTRUE;
188     }
189    
190     //--------------------------------------------------------------------------------------------------
191     void HLTFwkMod::Process()
192     {
193     // Read trigger objects and relation branch and fill our object table.
194    
195     fTrigObjs->Delete();
196    
197 loizides 1.2 LoadBranch(fObjsName);
198     LoadBranch(fRelsName);
199 loizides 1.1
200     for (UInt_t i=0; i<fRels->Entries(); ++i) {
201     const TriggerObjectRel *rel = fRels->At(i);
202 loizides 1.3 if (!rel) continue;
203 loizides 1.1
204     const TriggerObjectBase *ob = fObjs->At(rel->ObjInd());
205 loizides 1.3 if (!ob) continue;
206 loizides 1.1
207     TriggerObject *obj = new TriggerObject(rel->TrgId(), rel->Type(), ob->Id(),
208     ob->Pt(), ob->Eta(), ob->Phi(), ob->Mass());
209    
210 loizides 1.5 obj->SetTrigName(fHLTTab->at(rel->TrgId()).c_str());
211     obj->SetModuleName(fHLTLab->at(rel->ModInd()).c_str());
212     obj->SetFilterName(fHLTLab->at(rel->FilterInd()).c_str());
213 loizides 1.1 fTrigObjs->Add(obj);
214     }
215     }
216    
217     //--------------------------------------------------------------------------------------------------
218     void HLTFwkMod::SlaveBegin()
219     {
220     // Request branches for trigger objects and relation, and publish our tables.
221    
222 loizides 1.2 ReqBranch(fObjsName, fObjs);
223     ReqBranch(fRelsName, fRels);
224 loizides 1.1
225     if (!PublishObj(fTriggers)) {
226     SendError(kAbortAnalysis, "SlaveBegin",
227     "Could not publish HLT trigger table with name %s.", fTriggers->GetName());
228     return;
229     }
230     if (!PublishObj(fTrigObjs)) {
231     SendError(kAbortAnalysis, "SlaveBegin",
232     "Could not publish HLT trigger objects table with name %s.", fTrigObjs->GetName());
233     return;
234     }
235     if (!PublishObj(fLabels)) {
236     SendError(kAbortAnalysis, "SlaveBegin",
237     "Could not publish HLT labels with name %s.", fLabels->GetName());
238     return;
239     }
240     }
241    
242     //--------------------------------------------------------------------------------------------------
243     void HLTFwkMod::SlaveTerminate()
244     {
245     // Retract our published objects.
246    
247     RetractObj(fTriggers->GetName());
248     RetractObj(fLabels->GetName());
249     RetractObj(fTrigObjs->GetName());
250     }