ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/HLTMod.cc
Revision: 1.2
Committed: Thu Oct 23 17:02:16 2008 UTC (16 years, 6 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.1: +4 -1 lines
Log Message:
If wanted print HLTtable.

File Contents

# Content
1 // $Id: HLTMod.cc,v 1.1 2008/09/28 02:40:09 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.AddCopy(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.Ref(tid);
55 const BitMask256 &bm = fTrigBitsCmp.Ref(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 if (list) {
66 TIterator *iter = list->MakeIterator();
67 if (iter) {
68 TriggerObject *to = dynamic_cast<TriggerObject *>(iter->Next());
69 while (to) {
70 fMyTrgObjs->Add(to);
71 to = dynamic_cast<TriggerObject *>(iter->Next());
72 }
73 }
74 }
75 fBitsDone.SetBit(i);
76 }
77 }
78
79 //--------------------------------------------------------------------------------------------------
80 void HLTMod::BeginRun()
81 {
82 // Get HLT tree and set branches. Compute bitmasks to be used when comparing to the HLT bits.
83
84 fTrigBitsAnd.Reset();
85 fTrigBitsCmp.Reset();
86
87 if (fPrintTable)
88 fTriggers->Print();
89
90 for (UInt_t i=0; i<fTrigNames.Entries(); ++i) {
91 BitMask256 tmask; //trigger mask
92 BitMask256 amask; //bitand mask
93 TString names(fTrigNames.At(i)->c_str());
94 TObjArray *arr = names.Tokenize("&");
95 if (arr) {
96 for(Int_t j=0; j<arr->GetEntries(); j++){
97 TObjString *s = dynamic_cast<TObjString*>(arr->At(j));
98 if (!s)
99 continue;
100 const char *sptr = s->GetString().Data();
101 Bool_t invert = kFALSE;
102 if (sptr[0] == '!') {
103 invert = kTRUE; //inverted bit set
104 ++sptr;
105 }
106 const TriggerName *tn = fTriggers->Get(sptr);
107 if (!tn) {
108 Warning("BeginRun", "Trigger %s not found.", tn->Name());
109 continue;
110 }
111 UShort_t bit = tn->Id();
112 amask.SetBit(bit); //always set and-mask bit
113 if (!invert)
114 tmask.SetBit(bit); //set trigger bit
115 }
116 delete arr;
117 }
118 fTrigBitsAnd.AddCopy(amask);
119 fTrigBitsCmp.AddCopy(tmask);
120 }
121 }
122
123 //--------------------------------------------------------------------------------------------------
124 void HLTMod::Process()
125 {
126 // Process trigger bits for this event. If trigger bits pass the given bit mask, then obtain
127 // and publish the corresponding trigger objects. If OnAccepted or OnFailed is implemented
128 // in a derived class, call it. Do not stop processing this event, if fAbort is kFALSE.
129
130 ++fNEvents;
131 LoadBranch(fBitsName.Data());
132
133 // match trigger bits to trigger mask and obtain trigger objects
134 fMyTrgObjs = new TriggerObjectOArr(0,fMyObjsNamePub);
135 fMyTrgObjs->SetOwner(kFALSE); // the objects are owned by the object table
136 fBitsDone.Clear();
137 Bool_t accept = kFALSE;
138 for (UInt_t i = 0; i<fTrigBitsAnd.Entries(); ++i) {
139 BitMask256 bitmask(*fBits);
140 bitmask &= fTrigBitsAnd.Ref(i);
141 if (bitmask==fTrigBitsCmp.Ref(i)) {
142 accept = kTRUE;
143 AddTrigObjs(i);
144 }
145 }
146
147 // take action if failed
148 if (!accept) {
149 ++fNFailed;
150 OnFailed();
151 delete fMyTrgObjs;
152 if (fAbort) {
153 SkipEvent(); // abort processing of this event by sub-modules
154 }
155 return;
156 }
157
158 // take action if accepted
159 ++fNAcceped;
160 OnAccepted();
161 if (!AddObjThisEvt(fMyTrgObjs)) {
162 SendError(kAbortAnalysis, "Process",
163 "Could not add my trigger objects with name %s to event.",
164 fMyTrgObjs->GetName());
165 return;
166 }
167 fMyTrgObjs = 0;
168 }
169
170 //--------------------------------------------------------------------------------------------------
171 void HLTMod::SlaveBegin()
172 {
173 // Request trigger bit branch and obtain trigger table and objects.
174
175 ReqBranch(fBitsName.Data(), fBits);
176
177 fTriggers = GetHLTTable();
178 if (!fTriggers) {
179 SendError(kAbortAnalysis, "SlaveBegin", "Could not get HLT trigger table.");
180 return;
181 }
182 fTrigObjs = GetHLTObjectsTable();
183 if (!fTrigObjs) {
184 SendError(kAbortAnalysis, "SlaveBegin", "Could not get HLT trigger objects table.");
185 return;
186 }
187 }