ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/HLTMod.cc
Revision: 1.18
Committed: Tue Dec 1 15:14:11 2009 UTC (15 years, 5 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013, Mit_013pre1, Mit_012i, Mit_012h, Mit_012g, Mit_012f, Mit_012e, Mit_012d
Changes since 1.17: +4 -2 lines
Log Message:
Printout

File Contents

# User Rev Content
1 loizides 1.18 // $Id: HLTMod.cc,v 1.17 2009/10/01 12:43:53 loizides Exp $
2 loizides 1.1
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 loizides 1.11 #include "MitAna/DataTree/interface/TriggerMask.h"
9 loizides 1.1 #include "MitAna/DataTree/interface/TriggerObject.h"
10 loizides 1.11 #include "MitAna/DataTree/interface/TriggerObjectCol.h"
11 loizides 1.12 #include "MitAna/DataTree/interface/TriggerObjectsTable.h"
12 loizides 1.1
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 loizides 1.8 fPrintTable(kFALSE),
22 loizides 1.13 fIgnoreBits(kFALSE),
23     fObjMode(kHlt),
24 loizides 1.1 fBitsName(Names::gkHltBitBrn),
25 loizides 1.8 fMyObjsNamePub(Form("%sTrigObjs", name)),
26 loizides 1.1 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 loizides 1.5 fTrigNames.push_back(tname);
53 loizides 1.1 }
54    
55     //--------------------------------------------------------------------------------------------------
56     void HLTMod::AddTrigObjs(UInt_t tid)
57     {
58     // Add trigger objects corresponding to trigger id.
59    
60 loizides 1.6 const BitMask256 &ba = fTrigBitsAnd.at(tid);
61     const BitMask256 &bm = fTrigBitsCmp.at(tid);
62 loizides 1.1 for (UInt_t i=0; i<bm.Size(); ++i) {
63 loizides 1.13 if (ba.TestBit(i)==0 && !fIgnoreBits)
64 loizides 1.1 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 loizides 1.15 if (list) {
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 loizides 1.13 }
82 loizides 1.1 fBitsDone.SetBit(i);
83     }
84     }
85    
86     //--------------------------------------------------------------------------------------------------
87     void HLTMod::BeginRun()
88     {
89     // Get HLT tree and set branches. Compute bitmasks to be used when comparing to the HLT bits.
90    
91 loizides 1.6 fTrigBitsAnd.clear();
92     fTrigBitsCmp.clear();
93 loizides 1.1
94 loizides 1.18 if (fPrintTable) {
95     Info("BeginRun", "Get trigger table for run %d", GetEventHeader()->RunNum());
96 loizides 1.2 fTriggers->Print();
97 loizides 1.18 }
98 loizides 1.2
99 loizides 1.5 for (UInt_t i=0; i<fTrigNames.size(); ++i) {
100 loizides 1.1 BitMask256 tmask; //trigger mask
101     BitMask256 amask; //bitand mask
102 loizides 1.5 TString names(fTrigNames.at(i).c_str());
103 loizides 1.7
104 loizides 1.1 TObjArray *arr = names.Tokenize("&");
105     if (arr) {
106     for(Int_t j=0; j<arr->GetEntries(); j++){
107     TObjString *s = dynamic_cast<TObjString*>(arr->At(j));
108     if (!s)
109     continue;
110     const char *sptr = s->GetString().Data();
111     Bool_t invert = kFALSE;
112     if (sptr[0] == '!') {
113     invert = kTRUE; //inverted bit set
114     ++sptr;
115     }
116     const TriggerName *tn = fTriggers->Get(sptr);
117     if (!tn) {
118 loizides 1.7 Warning("BeginRun", "Trigger %s not found.", sptr);
119 loizides 1.1 continue;
120     }
121 loizides 1.16
122 loizides 1.1 UShort_t bit = tn->Id();
123 loizides 1.16 if (amask.TestBit(bit)) {
124     if (tmask.TestBit(bit)==invert) {
125     amask.ClearBit(bit);
126     tmask.ClearBit(bit);
127 loizides 1.17 Warning("BeginRun", "Trigger expression %s always false.", names.Data());
128 loizides 1.16 break;
129     }
130     } else { //always set and-mask bit
131     amask.SetBit(bit);
132     if (!invert)
133     tmask.SetBit(bit); //set trigger bit
134     }
135 loizides 1.1 }
136     delete arr;
137     }
138 loizides 1.16 if (amask.NBitsSet()) {
139 loizides 1.14 fTrigBitsAnd.push_back(amask);
140     fTrigBitsCmp.push_back(tmask);
141     }
142 loizides 1.1 }
143     }
144    
145     //--------------------------------------------------------------------------------------------------
146     void HLTMod::Process()
147     {
148     // Process trigger bits for this event. If trigger bits pass the given bit mask, then obtain
149     // and publish the corresponding trigger objects. If OnAccepted or OnFailed is implemented
150     // in a derived class, call it. Do not stop processing this event, if fAbort is kFALSE.
151    
152     ++fNEvents;
153 loizides 1.4 LoadBranch(fBitsName);
154 loizides 1.1
155     // match trigger bits to trigger mask and obtain trigger objects
156     fMyTrgObjs = new TriggerObjectOArr(0,fMyObjsNamePub);
157     fMyTrgObjs->SetOwner(kFALSE); // the objects are owned by the object table
158     fBitsDone.Clear();
159     Bool_t accept = kFALSE;
160 loizides 1.6 for (UInt_t i = 0; i<fTrigBitsAnd.size(); ++i) {
161     BitMask256 bitmask(fBits->Get());
162     bitmask &= fTrigBitsAnd.at(i);
163     if (bitmask==fTrigBitsCmp.at(i)) {
164 loizides 1.1 accept = kTRUE;
165     AddTrigObjs(i);
166     }
167     }
168    
169     // take action if failed
170     if (!accept) {
171     ++fNFailed;
172     OnFailed();
173     delete fMyTrgObjs;
174     if (fAbort) {
175     SkipEvent(); // abort processing of this event by sub-modules
176     }
177     return;
178     }
179    
180     // take action if accepted
181     ++fNAcceped;
182 loizides 1.9 IncNEventsProcessed();
183 loizides 1.1 OnAccepted();
184     if (!AddObjThisEvt(fMyTrgObjs)) {
185     SendError(kAbortAnalysis, "Process",
186     "Could not add my trigger objects with name %s to event.",
187     fMyTrgObjs->GetName());
188     return;
189     }
190     fMyTrgObjs = 0;
191     }
192    
193     //--------------------------------------------------------------------------------------------------
194     void HLTMod::SlaveBegin()
195     {
196     // Request trigger bit branch and obtain trigger table and objects.
197    
198 loizides 1.4 ReqBranch(fBitsName, fBits);
199 loizides 1.1
200     fTriggers = GetHLTTable();
201     if (!fTriggers) {
202     SendError(kAbortAnalysis, "SlaveBegin", "Could not get HLT trigger table.");
203     return;
204     }
205     fTrigObjs = GetHLTObjectsTable();
206     if (!fTrigObjs) {
207     SendError(kAbortAnalysis, "SlaveBegin", "Could not get HLT trigger objects table.");
208     return;
209     }
210     }
211 loizides 1.9
212     //--------------------------------------------------------------------------------------------------
213     void HLTMod::SlaveTerminate()
214     {
215     // Save number of accepted events.
216    
217 ceballos 1.10 SaveNEventsProcessed("hDHLTEvents");
218 loizides 1.9 }