Revision: | 1.8 |
Committed: | Tue Oct 4 16:23:16 2011 UTC (13 years, 6 months ago) by arizzi |
Content type: | text/plain |
Branch: | MAIN |
CVS Tags: | EDMV42_Step2_V8, EDMV42_Step2_V7, EDMV42_Step2_V6, EDMV42_Step2_V5a, EDMV42_Step2_V5, tauCandV42, hbbsubstructDev_11, hbbsubstructDev_10, hbbsubstructDev_9, hbbsubstructDev_8, hbbsubstructDev_7, hbbsubstructDev_6, hbbsubstructDev_5, hbbsubstructDev_4, hbbsubstructDev_3, hbbsubstructDev_2, hbbsubstructDev_1, hbbsubstructDev, V21TauCand_0, EDMV42_Step2_V4a, EDMV42_Step2_V4, EDMV42_Step2_V3, EDMV42_Step2_V2, EDMV42_Step2_V1, EdmV42, EdmV41alpha1, EdmV40alpha1, EdmV40alpha, V21emuCand, EdmV33Jun12v2_consistent, Step2ForV33_v2, Step2ForV33_v1, EdmV33Jun12v2, EdmV33Jun12v1, EdmV33Jun12v0, Step2ForV32_v2, Step2ForV32_v1, Step2ForV32_v0, Step2ForV31_v0, EdmV32May24v0, EdmV31May21v1, EdmV31May17v0, May14thStep2, EdmV30Apr10, EdmV21Apr10v2, EdmV22May9, EdmV21Apr06, EdmV21Apr10, EdmV21Apr04, EdmV21Apr03, EdmV21Apr2, EdmV21Mar30, EdmV20Mar12, AR_Nov10Ntuple, AR_step2_Oct25, AR_step2_oct19, EdmV11Oct2011, AR_Step2_Oct13, AR_Oct9Ntuple, AR_Oct7_step2ntuple, AR_Oct5Ntuple, EdmV10Oct2011, HEAD |
Branch point for: | V42TauCandidate, hbbsubstructDevPostHCP, V21TauCand, V21emuCandidate |
Changes since 1.7: | +1 -0 lines |
Error occurred while calculating annotation data. | |
Log Message: | fix crash in triggerreader |
# | Content |
---|---|
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 | TriggerReader(bool passAllEvents=false) : passAll(passAllEvents) {} |
17 | |
18 | void setEvent( fwlite::Event * e,const char * process ="HLT") { |
19 | ev=e; |
20 | if(!passAll) { |
21 | hTriggerResults.getByLabel(*ev,"TriggerResults","",process); |
22 | run = ev->eventAuxiliary().id().run(); |
23 | } |
24 | } |
25 | |
26 | bool accept(const std::string & triggername) |
27 | { |
28 | if(passAll) return true; |
29 | |
30 | |
31 | regex_t regex; |
32 | int reti; |
33 | |
34 | |
35 | |
36 | |
37 | std::map<std::string,size_t>::iterator nit; |
38 | if(run != cacheRun[triggername] || nameMap.find(triggername) == nameMap.end()) |
39 | { |
40 | |
41 | reti = regcomp(®ex, triggername.c_str(), 0); |
42 | // reti = regcomp(®ex, "HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v.*", 0); |
43 | if( reti ){ std::cerr << "Could not compile regex" << std::endl;} |
44 | |
45 | std::cout << "new run" << run << std::endl; |
46 | // cacheRun[triggername]=ev->getRun().run(); |
47 | cacheRun[triggername]=run; |
48 | 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(®ex, oldiname.c_str(), 0, NULL, 0) << std::endl; |
57 | if(nit==nameMap.end() || ( regexec(®ex, oldiname.c_str(), 0, NULL, 0) != 0 )) //; ! oldiname.Contains( TRegexp(triggername)) ) // changed, search it |
58 | { |
59 | std::cout << "searching " << triggername << std::endl; |
60 | nameMap[triggername]=100000000; |
61 | for (unsigned i = 0; i < triggerNames.size(); ++i) { |
62 | std::string iname(triggerNames.triggerName(i)); |
63 | |
64 | if( regexec(®ex, iname.c_str(), 0, NULL, 0) == 0 ) //iname.Contains(TRegexp(triggername)) ) |
65 | { |
66 | nameMap[triggername]= i; |
67 | std::cout << "FOUND: " << triggerNames.triggerName(i) << " is bit " << i << std::endl; |
68 | } |
69 | } |
70 | |
71 | } |
72 | regfree(®ex); |
73 | } |
74 | nit=nameMap.find(triggername); |
75 | if(nit==nameMap.end()) |
76 | { |
77 | std::cout << "ERROR: trigger name not found" << std::endl; |
78 | // edm::TriggerNames const& triggerNames = ev->triggerNames(*hTriggerResults); |
79 | // for (unsigned i = 0; i < triggerNames.size(); ++i) std::cout << triggerNames.triggerName(i) << " is bit " << i << "looking for: "<< triggername << std::endl; |
80 | nameMap[triggername]=100000000; // meaning not found in this run |
81 | |
82 | return false; |
83 | } |
84 | if(nit->second==100000000) return false; |
85 | return hTriggerResults->accept(nit->second); |
86 | } |
87 | |
88 | private: |
89 | fwlite::Handle<edm::TriggerResults> hTriggerResults; |
90 | std::map<std::string,size_t> nameMap; |
91 | std::map<std::string,size_t> cacheRun; |
92 | // unsigned int cacheRun; |
93 | fwlite::Event * ev; |
94 | bool passAll; |
95 | unsigned int run; |
96 | |
97 | }; |
98 | |
99 | #endif |