ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/HLTMod.cc
Revision: 1.11
Committed: Mon Jun 15 15:00:17 2009 UTC (15 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_009c, Mit_009b
Changes since 1.10: +3 -1 lines
Log Message:
Added proper fwd defs plus split up complilation of MitAna/DataTree LinkDefs.

File Contents

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