ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/HLTMod.cc
Revision: 1.6
Committed: Sun Mar 8 12:11:49 2009 UTC (16 years, 2 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_008pre2
Changes since 1.5: +11 -11 lines
Log Message:
Use TriggerMask

File Contents

# User Rev Content
1 loizides 1.6 // $Id: HLTMod.cc,v 1.5 2009/03/02 13:26:45 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     #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 loizides 1.5 fTrigNames.push_back(tname);
47 loizides 1.1 }
48    
49     //--------------------------------------------------------------------------------------------------
50     void HLTMod::AddTrigObjs(UInt_t tid)
51     {
52     // Add trigger objects corresponding to trigger id.
53    
54 loizides 1.6 const BitMask256 &ba = fTrigBitsAnd.at(tid);
55     const BitMask256 &bm = fTrigBitsCmp.at(tid);
56 loizides 1.1 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 loizides 1.3 fMyTrgObjs->Add(list);
66 loizides 1.1 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 loizides 1.6 fTrigBitsAnd.clear();
76     fTrigBitsCmp.clear();
77 loizides 1.1
78 loizides 1.2 if (fPrintTable)
79     fTriggers->Print();
80    
81 loizides 1.5 for (UInt_t i=0; i<fTrigNames.size(); ++i) {
82 loizides 1.1 BitMask256 tmask; //trigger mask
83     BitMask256 amask; //bitand mask
84 loizides 1.5 TString names(fTrigNames.at(i).c_str());
85 loizides 1.1 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 loizides 1.6 fTrigBitsAnd.push_back(amask);
110     fTrigBitsCmp.push_back(tmask);
111 loizides 1.1 }
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 loizides 1.4 LoadBranch(fBitsName);
123 loizides 1.1
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 loizides 1.6 for (UInt_t i = 0; i<fTrigBitsAnd.size(); ++i) {
130     BitMask256 bitmask(fBits->Get());
131     bitmask &= fTrigBitsAnd.at(i);
132     if (bitmask==fTrigBitsCmp.at(i)) {
133 loizides 1.1 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 loizides 1.4 ReqBranch(fBitsName, fBits);
167 loizides 1.1
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     }