ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/HLTMod.cc
Revision: 1.7
Committed: Tue Mar 24 16:11:16 2009 UTC (16 years, 1 month ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_009, Mit_008
Changes since 1.6: +3 -2 lines
Log Message:
Bugfix.

File Contents

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