ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/HLTMod.cc
Revision: 1.23
Committed: Wed Mar 28 12:15:38 2012 UTC (13 years, 1 month ago) by paus
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, HEAD
Changes since 1.22: +7 -5 lines
Log Message:
Enable skimming.

File Contents

# Content
1 // $Id: HLTMod.cc,v 1.22 2011/11/18 00:02:02 bendavid Exp $
2
3 #include "MitAna/TreeMod/interface/HLTMod.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/TriggerMask.h"
9 #include "MitAna/DataTree/interface/TriggerObject.h"
10 #include "MitAna/DataTree/interface/TriggerObjectCol.h"
11 #include "MitAna/DataTree/interface/TriggerObjectsTable.h"
12
13 using namespace mithep;
14
15 ClassImp(mithep::HLTMod)
16
17 //--------------------------------------------------------------------------------------------------
18 HLTMod::HLTMod(const char *name, const char *title) :
19 BaseMod(name,title),
20 fAbort(kTRUE),
21 fPrintTable(kFALSE),
22 fIgnoreBits(kFALSE),
23 fObjMode(kHlt),
24 fBitsName(Names::gkHltBitBrn),
25 fMyObjsNamePub(Form("%sTrigObjs", name)),
26 fBits(0),
27 fMyTrgObjs(0),
28 fTriggers(0),
29 fTrigObjs(0),
30 fNEvents(0),
31 fNAccepted(0),
32 fNFailed(0)
33 {
34 // Constructor.
35 }
36
37 //--------------------------------------------------------------------------------------------------
38 HLTMod::~HLTMod()
39 {
40 // Destructor.
41 }
42
43 //--------------------------------------------------------------------------------------------------
44 void HLTMod::AddTrigger(const char *expr, UInt_t firstRun, UInt_t lastRun)
45 {
46 // Add trigger search pattern to the list of patters. Each element of the list is logically
47 // "ored". The given expression can contain several trigger names logically "anded" (using "&").
48 // A "!" infront of a trigger name negates the bit. For example, valid expressions are:
49 // "A", "!A", "A&B", "A&!B" or "A&B&C"
50
51 string tname(expr);
52 std::pair<std::string,std::pair<UInt_t,UInt_t> >
53 element(tname,std::pair<UInt_t,UInt_t>(firstRun,lastRun));
54 fTrigNames.push_back(element);
55 }
56
57 //--------------------------------------------------------------------------------------------------
58 void HLTMod::AddTrigObjs(UInt_t tid)
59 {
60 // Add trigger objects corresponding to trigger id.
61
62 const BitMask1024 &ba = fTrigBitsAnd.at(tid);
63 const BitMask1024 &bm = fTrigBitsCmp.at(tid);
64 for (UInt_t i=0; i<bm.Size(); ++i) {
65 if (ba.TestBit(i)==0 && !fIgnoreBits)
66 continue; // not an active trigger bit
67 if (fBitsDone.TestBit(i))
68 continue; // objects for this bit are already obtained
69 if (bm.TestBit(i)==0)
70 continue; // excluded trigger bit (ie a !trgname)
71
72 const TList *list = fTrigObjs->GetList(i);
73 if (list) {
74 TIter iter(list->MakeIterator());
75 const TriggerObject *to = dynamic_cast<const TriggerObject*>(iter.Next());
76 while (to) {
77 if ( (fObjMode == kAll) ||
78 ((fObjMode == kHlt) && (to->IsHLT())) ||
79 ((fObjMode == kL1) && (to->IsL1())) )
80 fMyTrgObjs->Add(to);
81 to = dynamic_cast<const TriggerObject*>(iter.Next());
82 }
83 }
84 fBitsDone.SetBit(i);
85 }
86 }
87
88 //--------------------------------------------------------------------------------------------------
89 void HLTMod::BeginRun()
90 {
91 // Get HLT tree and set branches. Compute bitmasks to be used when comparing to the HLT bits.
92
93 fTrigBitsAnd.clear();
94 fTrigBitsCmp.clear();
95
96 if (fPrintTable) {
97 Info("BeginRun", "Get trigger table for run %d", GetEventHeader()->RunNum());
98 printf(" Trigger table for run %d:\n",GetEventHeader()->RunNum());
99 fTriggers->Print();
100 }
101
102 UInt_t runNumber = GetEventHeader()->RunNum();
103
104 for (UInt_t i=0; i<fTrigNames.size(); ++i) {
105
106 UInt_t firstRun = fTrigNames.at(i).second.first;
107 UInt_t lastRun = fTrigNames.at(i).second.second;
108
109 // implement run dependence of the triggers
110 if ( (!(firstRun==0 && lastRun==0)) &&
111 ( runNumber<firstRun || runNumber>lastRun ) )
112 continue;
113
114 BitMask1024 tmask; //trigger mask
115 BitMask1024 amask; //bitand mask
116 TString names(fTrigNames.at(i).first.c_str());
117
118 TObjArray *arr = names.Tokenize("&");
119 if (arr) {
120 for(Int_t j=0; j<arr->GetEntries(); j++){
121 TObjString *s = dynamic_cast<TObjString*>(arr->At(j));
122 if (!s)
123 continue;
124 TString st = s->GetString();
125 bool wildcard = false;
126 if (st.EndsWith("*")) {
127 st.ReplaceAll("*","");
128 wildcard = true;
129 }
130 const char *sptr = st.Data();
131 Bool_t invert = kFALSE;
132 if (sptr[0] == '!') {
133 invert = kTRUE; //inverted bit set
134 ++sptr;
135 }
136 const TriggerName *tn = 0;
137 if (wildcard) {
138 tn = fTriggers->GetWildcard(sptr);
139 }
140 else {
141 tn = fTriggers->Get(sptr);
142 }
143 if (!tn) {
144 Warning("BeginRun", "Trigger %s not found.", sptr);
145 continue;
146 }
147
148 UShort_t bit = tn->Id();
149 if (amask.TestBit(bit)) {
150 if (tmask.TestBit(bit)==invert) {
151 amask.ClearBit(bit);
152 tmask.ClearBit(bit);
153 Warning("BeginRun", "Trigger expression %s always false.", names.Data());
154 break;
155 }
156 } else { //always set and-mask bit
157 amask.SetBit(bit);
158 if (!invert)
159 tmask.SetBit(bit); //set trigger bit
160 }
161 }
162 delete arr;
163 }
164 if (amask.NBitsSet()) {
165 fTrigBitsAnd.push_back(amask);
166 fTrigBitsCmp.push_back(tmask);
167 }
168 }
169 }
170
171 //--------------------------------------------------------------------------------------------------
172 void HLTMod::Process()
173 {
174 // Process trigger bits for this event. If trigger bits pass the given bit mask, then obtain
175 // and publish the corresponding trigger objects. If OnAccepted or OnFailed is implemented
176 // in a derived class, call it. Do not stop processing this event, if fAbort is kFALSE.
177
178 ++fNEvents;
179 LoadBranch(fBitsName);
180
181 // match trigger bits to trigger mask and obtain trigger objects
182 fMyTrgObjs = new TriggerObjectOArr(0,fMyObjsNamePub);
183 fMyTrgObjs->SetOwner(kFALSE); // the objects are owned by the object table
184 fBitsDone.Clear();
185 Bool_t accept = kFALSE;
186 for (UInt_t i = 0; i<fTrigBitsAnd.size(); ++i) {
187 BitMask1024 bitmask(fBits->Get());
188 bitmask &= fTrigBitsAnd.at(i);
189 if (bitmask==fTrigBitsCmp.at(i)) {
190 accept = kTRUE;
191 AddTrigObjs(i);
192 }
193 }
194
195 // take action if failed
196 if (!accept) {
197 ++fNFailed;
198 OnFailed();
199 delete fMyTrgObjs;
200 if (fAbort) {
201 SkipEvent(); // abort processing of this event by sub-modules
202 }
203 return;
204 }
205
206 // take action if accepted
207 ++fNAccepted;
208 IncNEventsProcessed();
209 OnAccepted();
210 if (!AddObjThisEvt(fMyTrgObjs)) {
211 SendError(kAbortAnalysis, "Process",
212 "Could not add my trigger objects with name %s to event.",
213 fMyTrgObjs->GetName());
214 return;
215 }
216 fMyTrgObjs = 0;
217 }
218
219 //--------------------------------------------------------------------------------------------------
220 void HLTMod::SlaveBegin()
221 {
222 // Request trigger bit branch and obtain trigger table and objects.
223
224 ReqBranch(fBitsName, fBits);
225
226 fTriggers = GetHLTTable();
227 if (!fTriggers) {
228 SendError(kAbortAnalysis, "SlaveBegin", "Could not get HLT trigger table.");
229 return;
230 }
231 fTrigObjs = GetHLTObjectsTable();
232 if (!fTrigObjs) {
233 SendError(kAbortAnalysis, "SlaveBegin", "Could not get HLT trigger objects table.");
234 return;
235 }
236 }
237
238 //--------------------------------------------------------------------------------------------------
239 void HLTMod::SlaveTerminate()
240 {
241 // Save number of accepted events.
242
243 printf(" %s - Accepted events: %d (/%d)\n",GetName(),fNAccepted,fNEvents);
244 SaveNEventsProcessed("hDHLTEvents");
245 }