ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/HLTMod.cc
Revision: 1.12
Committed: Mon Jul 13 10:39:20 2009 UTC (15 years, 9 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.11: +2 -1 lines
Log Message:
Updated for changes in trigger classes

File Contents

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