CMS 3D CMS Logo

BooleanFlagFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CommonTools/RecoAlgos
4 // Class: BooleanFlagFilter
5 //
13 //
14 // Original Author: Igor Volobouev
15 // Created: Fri, 20 Mar 2015 08:05:20 GMT
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
31 
32 //
33 // class declaration
34 //
35 
37  public:
38  explicit BooleanFlagFilter(const edm::ParameterSet&);
39  ~BooleanFlagFilter() override;
40 
41  private:
42  //virtual void beginJob() override;
43  bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
44  //virtual void endJob() override;
45 
46  //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
47  //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
48  //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
49  //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
50 
51  // ----------member data ---------------------------
53  bool reverse_;
54 };
55 
56 //
57 // constants, enums and typedefs
58 //
59 
60 //
61 // static data member definitions
62 //
63 
64 //
65 // constructors and destructor
66 //
68 {
69  //now do what ever initialization is needed
70  inputToken_ = consumes<bool>(iConfig.getParameter<edm::InputTag>("inputLabel"));
71  reverse_ = iConfig.getParameter<bool>("reverseDecision");
72 }
73 
74 
76 {
77 
78  // do anything here that needs to be done at desctruction time
79  // (e.g. close files, deallocate resources etc.)
80 
81 }
82 
83 
84 //
85 // member functions
86 //
87 
88 // ------------ method called on each new Event ------------
89 bool
91 {
92  using namespace edm;
93 
94  Handle<bool> pIn;
95  iEvent.getByToken(inputToken_, pIn);
96  if (!pIn.isValid())
97  {
98  throw edm::Exception(edm::errors::ProductNotFound) << " could not find requested flag\n";
99  return true;
100  }
101 
102  bool result = *pIn;
103  if (reverse_)
104  result = !result;
105 
106  return result;
107 }
108 
109 // ------------ method called once each job just before starting event loop ------------
110 /*
111 void
112 BooleanFlagFilter::beginJob()
113 {
114 }
115 */
116 
117 // ------------ method called once each job just after ending the event loop ------------
118 /*
119 void
120 BooleanFlagFilter::endJob() {
121 }
122 */
123 
124 // ------------ method called when starting to processes a run ------------
125 /*
126 void
127 BooleanFlagFilter::beginRun(edm::Run const&, edm::EventSetup const&)
128 {
129 }
130 */
131 
132 // ------------ method called when ending the processing of a run ------------
133 /*
134 void
135 BooleanFlagFilter::endRun(edm::Run const&, edm::EventSetup const&)
136 {
137 }
138 */
139 
140 // ------------ method called when starting to processes a luminosity block ------------
141 /*
142 void
143 BooleanFlagFilter::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
144 {
145 }
146 */
147 
148 // ------------ method called when ending the processing of a luminosity block ------------
149 /*
150 void
151 BooleanFlagFilter::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
152 {
153 }
154 */
155 
156 //define this as a plug-in
T getParameter(std::string const &) const
~BooleanFlagFilter() override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BooleanFlagFilter(const edm::ParameterSet &)
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< bool > inputToken_
HLT enums.
bool filter(edm::StreamID, edm::Event &, const edm::EventSetup &) const override