ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/HLTMod.cc
Revision: 1.1
Committed: Sun Sep 28 02:40:09 2008 UTC (16 years, 7 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_005, Mit_004
Log Message:
HLT trigger module to select on certain trigger bits. For every accepted event all corresponding trigger objects are exported to the sub-modules.

File Contents

# User Rev Content
1 loizides 1.1 // $Id: BaseMod.cc,v 1.1 2008/06/12 08:47:57 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     if (list) {
66     TIterator *iter = list->MakeIterator();
67     if (iter) {
68     TriggerObject *to = dynamic_cast<TriggerObject *>(iter->Next());
69     while (to) {
70     fMyTrgObjs->Add(to);
71     to = dynamic_cast<TriggerObject *>(iter->Next());
72     }
73     }
74     }
75     fBitsDone.SetBit(i);
76     }
77     }
78    
79     //--------------------------------------------------------------------------------------------------
80     void HLTMod::BeginRun()
81     {
82     // Get HLT tree and set branches. Compute bitmasks to be used when comparing to the HLT bits.
83    
84     fTrigBitsAnd.Reset();
85     fTrigBitsCmp.Reset();
86    
87     for (UInt_t i=0; i<fTrigNames.Entries(); ++i) {
88     BitMask256 tmask; //trigger mask
89     BitMask256 amask; //bitand mask
90     TString names(fTrigNames.At(i)->c_str());
91     TObjArray *arr = names.Tokenize("&");
92     if (arr) {
93     for(Int_t j=0; j<arr->GetEntries(); j++){
94     TObjString *s = dynamic_cast<TObjString*>(arr->At(j));
95     if (!s)
96     continue;
97     const char *sptr = s->GetString().Data();
98     Bool_t invert = kFALSE;
99     if (sptr[0] == '!') {
100     invert = kTRUE; //inverted bit set
101     ++sptr;
102     }
103     const TriggerName *tn = fTriggers->Get(sptr);
104     if (!tn) {
105     Warning("BeginRun", "Trigger %s not found.", tn->Name());
106     continue;
107     }
108     UShort_t bit = tn->Id();
109     amask.SetBit(bit); //always set and-mask bit
110     if (!invert)
111     tmask.SetBit(bit); //set trigger bit
112     }
113     delete arr;
114     }
115     fTrigBitsAnd.AddCopy(amask);
116     fTrigBitsCmp.AddCopy(tmask);
117     }
118     }
119    
120     //--------------------------------------------------------------------------------------------------
121     void HLTMod::Process()
122     {
123     // Process trigger bits for this event. If trigger bits pass the given bit mask, then obtain
124     // and publish the corresponding trigger objects. If OnAccepted or OnFailed is implemented
125     // in a derived class, call it. Do not stop processing this event, if fAbort is kFALSE.
126    
127     ++fNEvents;
128     LoadBranch(fBitsName.Data());
129    
130     // match trigger bits to trigger mask and obtain trigger objects
131     fMyTrgObjs = new TriggerObjectOArr(0,fMyObjsNamePub);
132     fMyTrgObjs->SetOwner(kFALSE); // the objects are owned by the object table
133     fBitsDone.Clear();
134     Bool_t accept = kFALSE;
135     for (UInt_t i = 0; i<fTrigBitsAnd.Entries(); ++i) {
136     BitMask256 bitmask(*fBits);
137     bitmask &= fTrigBitsAnd.Ref(i);
138     if (bitmask==fTrigBitsCmp.Ref(i)) {
139     accept = kTRUE;
140     AddTrigObjs(i);
141     }
142     }
143    
144     // take action if failed
145     if (!accept) {
146     ++fNFailed;
147     OnFailed();
148     delete fMyTrgObjs;
149     if (fAbort) {
150     SkipEvent(); // abort processing of this event by sub-modules
151     }
152     return;
153     }
154    
155     // take action if accepted
156     ++fNAcceped;
157     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     ReqBranch(fBitsName.Data(), fBits);
173    
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     }