ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/interface/TriggerReader.h
Revision: 1.7
Committed: Mon Sep 12 22:33:56 2011 UTC (13 years, 7 months ago) by arizzi
Content type: text/plain
Branch: MAIN
CVS Tags: EdmV9Sept2011, Sept19th2011_2, Sept19th2011, Sept19th, VHNtupleV9_AR1, VHSept15_AR1, Sept14th2011_2, Sept14th2011_AR1, Sept14th2011, Sept13th2011
Changes since 1.6: +3 -2 lines
Log Message:
hbhe flag

File Contents

# User Rev Content
1 arizzi 1.1 #ifndef TRIGGERREADER_H
2     #define TRIGGERREADER_H
3     #include "DataFormats/FWLite/interface/Event.h"
4     #include "DataFormats/FWLite/interface/Handle.h"
5     #include "DataFormats/Common/interface/TriggerResults.h"
6     #include "FWCore/Common/interface/TriggerNames.h"
7     #include <string>
8     #include <map>
9     #include <TString.h>
10     #include <TRegexp.h>
11     #include <regex.h>
12     #include <stdio.h>
13    
14     class TriggerReader {
15     public:
16 arizzi 1.3 TriggerReader(bool passAllEvents=false) : passAll(passAllEvents) {}
17 arizzi 1.1
18 arizzi 1.7 void setEvent( fwlite::Event * e,const char * process ="HLT") {
19     ev=e;
20 arizzi 1.6 if(!passAll) {
21 arizzi 1.7 hTriggerResults.getByLabel(*ev,"TriggerResults","",process);
22 arizzi 1.6 run = ev->eventAuxiliary().id().run();
23     }
24     }
25 arizzi 1.1
26     bool accept(const std::string & triggername)
27     {
28 arizzi 1.2 if(passAll) return true;
29 arizzi 1.1
30    
31     regex_t regex;
32     int reti;
33    
34    
35    
36    
37     std::map<std::string,size_t>::iterator nit;
38 arizzi 1.6 if(run != cacheRun[triggername] || nameMap.find(triggername) == nameMap.end())
39 arizzi 1.1 {
40 arizzi 1.5
41     reti = regcomp(&regex, triggername.c_str(), 0);
42     // reti = regcomp(&regex, "HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v.*", 0);
43     if( reti ){ std::cerr << "Could not compile regex" << std::endl;}
44    
45 arizzi 1.6 std::cout << "new run" << run << std::endl;
46     // cacheRun[triggername]=ev->getRun().run();
47     cacheRun[triggername]=run;
48 arizzi 1.1 edm::TriggerNames const& triggerNames = ev->triggerNames(*hTriggerResults);
49     std::string oldiname="whatever";
50     nit=nameMap.find(triggername);
51     if(nit!=nameMap.end() && nit->second < triggerNames.size())
52     {
53     oldiname=triggerNames.triggerName(nit->second);
54     }
55     // std::cout << "whatever3" << std::endl;
56     // std::cout << "reg1 " << regexec(&regex, oldiname.c_str(), 0, NULL, 0) << std::endl;
57     if(nit==nameMap.end() || ( regexec(&regex, oldiname.c_str(), 0, NULL, 0) != 0 )) //; ! oldiname.Contains( TRegexp(triggername)) ) // changed, search it
58     {
59     std::cout << "searching " << triggername << std::endl;
60     for (unsigned i = 0; i < triggerNames.size(); ++i) {
61     std::string iname(triggerNames.triggerName(i));
62    
63     if( regexec(&regex, iname.c_str(), 0, NULL, 0) == 0 ) //iname.Contains(TRegexp(triggername)) )
64     {
65     nameMap[triggername]= i;
66     std::cout << "FOUND: " << triggerNames.triggerName(i) << " is bit " << i << std::endl;
67     }
68     }
69    
70     }
71 arizzi 1.5 regfree(&regex);
72 arizzi 1.1 }
73     nit=nameMap.find(triggername);
74     if(nit==nameMap.end())
75     {
76     std::cout << "ERROR: trigger name not found" << std::endl;
77 arizzi 1.6 // edm::TriggerNames const& triggerNames = ev->triggerNames(*hTriggerResults);
78 arizzi 1.3 // for (unsigned i = 0; i < triggerNames.size(); ++i) std::cout << triggerNames.triggerName(i) << " is bit " << i << "looking for: "<< triggername << std::endl;
79     nameMap[triggername]=100000000; // meaning not found in this run
80 arizzi 1.1
81     return false;
82     }
83 arizzi 1.3 if(nit->second==100000000) return false;
84 arizzi 1.1 return hTriggerResults->accept(nit->second);
85     }
86    
87     private:
88 arizzi 1.6 fwlite::Handle<edm::TriggerResults> hTriggerResults;
89 arizzi 1.1 std::map<std::string,size_t> nameMap;
90 arizzi 1.3 std::map<std::string,size_t> cacheRun;
91     // unsigned int cacheRun;
92 arizzi 1.1 fwlite::Event * ev;
93 arizzi 1.2 bool passAll;
94 arizzi 1.6 unsigned int run;
95 arizzi 1.1
96     };
97    
98     #endif