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

File Contents

# Content
1 // $Id: HLTMod.cc,v 1.10 2009/05/24 19:10:43 ceballos 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
12 using namespace mithep;
13
14 ClassImp(mithep::HLTMod)
15
16 //--------------------------------------------------------------------------------------------------
17 HLTMod::HLTMod(const char *name, const char *title) :
18 BaseMod(name,title),
19 fAbort(kTRUE),
20 fPrintTable(kFALSE),
21 fBitsName(Names::gkHltBitBrn),
22 fMyObjsNamePub(Form("%sTrigObjs", name)),
23 fBits(0),
24 fMyTrgObjs(0),
25 fTriggers(0),
26 fTrigObjs(0),
27 fNEvents(0),
28 fNAcceped(0),
29 fNFailed(0)
30 {
31 // Constructor.
32 }
33
34 //--------------------------------------------------------------------------------------------------
35 HLTMod::~HLTMod()
36 {
37 // Destructor.
38 }
39
40 //--------------------------------------------------------------------------------------------------
41 void HLTMod::AddTrigger(const char *expr)
42 {
43 // Add trigger search pattern to the list of patters. Each element of the list is logically
44 // "ored". The given expression can contain several trigger names logically "anded" (using "&").
45 // A "!" infront of a trigger name negates the bit. For example, valid expressions are:
46 // "A", "!A", "A&B", "A&!B" or "A&B&C"
47
48 string tname(expr);
49 fTrigNames.push_back(tname);
50 }
51
52 //--------------------------------------------------------------------------------------------------
53 void HLTMod::AddTrigObjs(UInt_t tid)
54 {
55 // Add trigger objects corresponding to trigger id.
56
57 const BitMask256 &ba = fTrigBitsAnd.at(tid);
58 const BitMask256 &bm = fTrigBitsCmp.at(tid);
59 for (UInt_t i=0; i<bm.Size(); ++i) {
60 if (ba.TestBit(i)==0)
61 continue; // not an active trigger bit
62 if (fBitsDone.TestBit(i))
63 continue; // objects for this bit are already obtained
64 if (bm.TestBit(i)==0)
65 continue; // excluded trigger bit (ie a !trgname)
66
67 const TList *list = fTrigObjs->GetList(i);
68 fMyTrgObjs->Add(list);
69 fBitsDone.SetBit(i);
70 }
71 }
72
73 //--------------------------------------------------------------------------------------------------
74 void HLTMod::BeginRun()
75 {
76 // Get HLT tree and set branches. Compute bitmasks to be used when comparing to the HLT bits.
77
78 fTrigBitsAnd.clear();
79 fTrigBitsCmp.clear();
80
81 if (fPrintTable)
82 fTriggers->Print();
83
84 for (UInt_t i=0; i<fTrigNames.size(); ++i) {
85 BitMask256 tmask; //trigger mask
86 BitMask256 amask; //bitand mask
87 TString names(fTrigNames.at(i).c_str());
88
89 TObjArray *arr = names.Tokenize("&");
90 if (arr) {
91 for(Int_t j=0; j<arr->GetEntries(); j++){
92 TObjString *s = dynamic_cast<TObjString*>(arr->At(j));
93 if (!s)
94 continue;
95 const char *sptr = s->GetString().Data();
96 Bool_t invert = kFALSE;
97 if (sptr[0] == '!') {
98 invert = kTRUE; //inverted bit set
99 ++sptr;
100 }
101 const TriggerName *tn = fTriggers->Get(sptr);
102 if (!tn) {
103 Warning("BeginRun", "Trigger %s not found.", sptr);
104 continue;
105 }
106 UShort_t bit = tn->Id();
107 amask.SetBit(bit); //always set and-mask bit
108 if (!invert)
109 tmask.SetBit(bit); //set trigger bit
110 }
111 delete arr;
112 }
113 fTrigBitsAnd.push_back(amask);
114 fTrigBitsCmp.push_back(tmask);
115 }
116 }
117
118 //--------------------------------------------------------------------------------------------------
119 void HLTMod::Process()
120 {
121 // Process trigger bits for this event. If trigger bits pass the given bit mask, then obtain
122 // and publish the corresponding trigger objects. If OnAccepted or OnFailed is implemented
123 // in a derived class, call it. Do not stop processing this event, if fAbort is kFALSE.
124
125 ++fNEvents;
126 LoadBranch(fBitsName);
127
128 // match trigger bits to trigger mask and obtain trigger objects
129 fMyTrgObjs = new TriggerObjectOArr(0,fMyObjsNamePub);
130 fMyTrgObjs->SetOwner(kFALSE); // the objects are owned by the object table
131 fBitsDone.Clear();
132 Bool_t accept = kFALSE;
133 for (UInt_t i = 0; i<fTrigBitsAnd.size(); ++i) {
134 BitMask256 bitmask(fBits->Get());
135 bitmask &= fTrigBitsAnd.at(i);
136 if (bitmask==fTrigBitsCmp.at(i)) {
137 accept = kTRUE;
138 AddTrigObjs(i);
139 }
140 }
141
142 // take action if failed
143 if (!accept) {
144 ++fNFailed;
145 OnFailed();
146 delete fMyTrgObjs;
147 if (fAbort) {
148 SkipEvent(); // abort processing of this event by sub-modules
149 }
150 return;
151 }
152
153 // take action if accepted
154 ++fNAcceped;
155 IncNEventsProcessed();
156 OnAccepted();
157 if (!AddObjThisEvt(fMyTrgObjs)) {
158 SendError(kAbortAnalysis, "Process",
159 "Could not add my trigger objects with name %s to event.",
160 fMyTrgObjs->GetName());
161 return;
162 }
163 fMyTrgObjs = 0;
164 }
165
166 //--------------------------------------------------------------------------------------------------
167 void HLTMod::SlaveBegin()
168 {
169 // Request trigger bit branch and obtain trigger table and objects.
170
171 ReqBranch(fBitsName, fBits);
172
173 fTriggers = GetHLTTable();
174 if (!fTriggers) {
175 SendError(kAbortAnalysis, "SlaveBegin", "Could not get HLT trigger table.");
176 return;
177 }
178 fTrigObjs = GetHLTObjectsTable();
179 if (!fTrigObjs) {
180 SendError(kAbortAnalysis, "SlaveBegin", "Could not get HLT trigger objects table.");
181 return;
182 }
183 }
184
185 //--------------------------------------------------------------------------------------------------
186 void HLTMod::SlaveTerminate()
187 {
188 // Save number of accepted events.
189
190 SaveNEventsProcessed("hDHLTEvents");
191 }