ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/HLTMod.cc
Revision: 1.3
Committed: Thu Oct 23 18:25:27 2008 UTC (16 years, 6 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_006
Changes since 1.2: +2 -11 lines
Log Message:
use objarray::add

File Contents

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