ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/HLTMod.cc
Revision: 1.14
Committed: Tue Sep 15 14:48:36 2009 UTC (15 years, 7 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.13: +7 -3 lines
Log Message:
Only add mask if trigger name was found

File Contents

# Content
1 // $Id: HLTMod.cc,v 1.13 2009/07/13 13:45:30 loizides 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 fNAcceped(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)
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 fTrigNames.push_back(tname);
53 }
54
55 //--------------------------------------------------------------------------------------------------
56 void HLTMod::AddTrigObjs(UInt_t tid)
57 {
58 // Add trigger objects corresponding to trigger id.
59
60 const BitMask256 &ba = fTrigBitsAnd.at(tid);
61 const BitMask256 &bm = fTrigBitsCmp.at(tid);
62 for (UInt_t i=0; i<bm.Size(); ++i) {
63 if (ba.TestBit(i)==0 && !fIgnoreBits)
64 continue; // not an active trigger bit
65 if (fBitsDone.TestBit(i))
66 continue; // objects for this bit are already obtained
67 if (bm.TestBit(i)==0)
68 continue; // excluded trigger bit (ie a !trgname)
69
70 const TList *list = fTrigObjs->GetList(i);
71
72 TIter iter(list->MakeIterator());
73 const TriggerObject *to = dynamic_cast<const TriggerObject*>(iter.Next());
74 while (to) {
75 if ( (fObjMode == kAll) ||
76 ((fObjMode==kHlt) && (to->IsHLT())) ||
77 ((fObjMode==kL1) && (to->IsL1())) )
78 fMyTrgObjs->Add(to);
79 to = dynamic_cast<const TriggerObject*>(iter.Next());
80 }
81 fBitsDone.SetBit(i);
82 }
83 }
84
85 //--------------------------------------------------------------------------------------------------
86 void HLTMod::BeginRun()
87 {
88 // Get HLT tree and set branches. Compute bitmasks to be used when comparing to the HLT bits.
89
90 fTrigBitsAnd.clear();
91 fTrigBitsCmp.clear();
92
93 if (fPrintTable)
94 fTriggers->Print();
95
96 for (UInt_t i=0; i<fTrigNames.size(); ++i) {
97 BitMask256 tmask; //trigger mask
98 BitMask256 amask; //bitand mask
99 Bool_t gotamask = 0;
100 TString names(fTrigNames.at(i).c_str());
101
102 TObjArray *arr = names.Tokenize("&");
103 if (arr) {
104 for(Int_t j=0; j<arr->GetEntries(); j++){
105 TObjString *s = dynamic_cast<TObjString*>(arr->At(j));
106 if (!s)
107 continue;
108 const char *sptr = s->GetString().Data();
109 Bool_t invert = kFALSE;
110 if (sptr[0] == '!') {
111 invert = kTRUE; //inverted bit set
112 ++sptr;
113 }
114 const TriggerName *tn = fTriggers->Get(sptr);
115 if (!tn) {
116 Warning("BeginRun", "Trigger %s not found.", sptr);
117 continue;
118 }
119 gotamask = 1;
120 UShort_t bit = tn->Id();
121 amask.SetBit(bit); //always set and-mask bit
122 if (!invert)
123 tmask.SetBit(bit); //set trigger bit
124 }
125 delete arr;
126 }
127 if (gotamask) {
128 fTrigBitsAnd.push_back(amask);
129 fTrigBitsCmp.push_back(tmask);
130 }
131 }
132 }
133
134 //--------------------------------------------------------------------------------------------------
135 void HLTMod::Process()
136 {
137 // Process trigger bits for this event. If trigger bits pass the given bit mask, then obtain
138 // and publish the corresponding trigger objects. If OnAccepted or OnFailed is implemented
139 // in a derived class, call it. Do not stop processing this event, if fAbort is kFALSE.
140
141 ++fNEvents;
142 LoadBranch(fBitsName);
143
144 // match trigger bits to trigger mask and obtain trigger objects
145 fMyTrgObjs = new TriggerObjectOArr(0,fMyObjsNamePub);
146 fMyTrgObjs->SetOwner(kFALSE); // the objects are owned by the object table
147 fBitsDone.Clear();
148 Bool_t accept = kFALSE;
149 for (UInt_t i = 0; i<fTrigBitsAnd.size(); ++i) {
150 BitMask256 bitmask(fBits->Get());
151 bitmask &= fTrigBitsAnd.at(i);
152 if (bitmask==fTrigBitsCmp.at(i)) {
153 accept = kTRUE;
154 AddTrigObjs(i);
155 }
156 }
157
158 // take action if failed
159 if (!accept) {
160 ++fNFailed;
161 OnFailed();
162 delete fMyTrgObjs;
163 if (fAbort) {
164 SkipEvent(); // abort processing of this event by sub-modules
165 }
166 return;
167 }
168
169 // take action if accepted
170 ++fNAcceped;
171 IncNEventsProcessed();
172 OnAccepted();
173 if (!AddObjThisEvt(fMyTrgObjs)) {
174 SendError(kAbortAnalysis, "Process",
175 "Could not add my trigger objects with name %s to event.",
176 fMyTrgObjs->GetName());
177 return;
178 }
179 fMyTrgObjs = 0;
180 }
181
182 //--------------------------------------------------------------------------------------------------
183 void HLTMod::SlaveBegin()
184 {
185 // Request trigger bit branch and obtain trigger table and objects.
186
187 ReqBranch(fBitsName, fBits);
188
189 fTriggers = GetHLTTable();
190 if (!fTriggers) {
191 SendError(kAbortAnalysis, "SlaveBegin", "Could not get HLT trigger table.");
192 return;
193 }
194 fTrigObjs = GetHLTObjectsTable();
195 if (!fTrigObjs) {
196 SendError(kAbortAnalysis, "SlaveBegin", "Could not get HLT trigger objects table.");
197 return;
198 }
199 }
200
201 //--------------------------------------------------------------------------------------------------
202 void HLTMod::SlaveTerminate()
203 {
204 // Save number of accepted events.
205
206 SaveNEventsProcessed("hDHLTEvents");
207 }