Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:03

0001 // -*- C++ -*-
0002 //
0003 // Package:    CommonTools/RecoAlgos
0004 // Class:      BooleanFlagFilter
0005 //
0006 /**\class BooleanFlagFilter BooleanFlagFilter.cc CommonTools/RecoAlgos/plugins/BooleanFlagFilter.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Igor Volobouev
0015 //         Created:  Fri, 20 Mar 2015 08:05:20 GMT
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/global/EDFilter.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 
0031 //
0032 // class declaration
0033 //
0034 
0035 class BooleanFlagFilter : public edm::global::EDFilter<> {
0036 public:
0037   explicit BooleanFlagFilter(const edm::ParameterSet&);
0038   ~BooleanFlagFilter() override;
0039 
0040 private:
0041   //virtual void beginJob() override;
0042   bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0043   //virtual void endJob() override;
0044 
0045   //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
0046   //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
0047   //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0048   //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0049 
0050   // ----------member data ---------------------------
0051   edm::EDGetTokenT<bool> inputToken_;
0052   bool reverse_;
0053 };
0054 
0055 //
0056 // constants, enums and typedefs
0057 //
0058 
0059 //
0060 // static data member definitions
0061 //
0062 
0063 //
0064 // constructors and destructor
0065 //
0066 BooleanFlagFilter::BooleanFlagFilter(const edm::ParameterSet& iConfig) {
0067   //now do what ever initialization is needed
0068   inputToken_ = consumes<bool>(iConfig.getParameter<edm::InputTag>("inputLabel"));
0069   reverse_ = iConfig.getParameter<bool>("reverseDecision");
0070 }
0071 
0072 BooleanFlagFilter::~BooleanFlagFilter() {
0073   // do anything here that needs to be done at desctruction time
0074   // (e.g. close files, deallocate resources etc.)
0075 }
0076 
0077 //
0078 // member functions
0079 //
0080 
0081 // ------------ method called on each new Event  ------------
0082 bool BooleanFlagFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0083   using namespace edm;
0084 
0085   Handle<bool> pIn;
0086   iEvent.getByToken(inputToken_, pIn);
0087   if (!pIn.isValid()) {
0088     throw edm::Exception(edm::errors::ProductNotFound) << " could not find requested flag\n";
0089     return true;
0090   }
0091 
0092   bool result = *pIn;
0093   if (reverse_)
0094     result = !result;
0095 
0096   return result;
0097 }
0098 
0099 // ------------ method called once each job just before starting event loop  ------------
0100 /*
0101 void 
0102 BooleanFlagFilter::beginJob()
0103 {
0104 }
0105 */
0106 
0107 // ------------ method called once each job just after ending the event loop  ------------
0108 /*
0109 void 
0110 BooleanFlagFilter::endJob() {
0111 }
0112 */
0113 
0114 // ------------ method called when starting to processes a run  ------------
0115 /*
0116 void
0117 BooleanFlagFilter::beginRun(edm::Run const&, edm::EventSetup const&)
0118 { 
0119 }
0120 */
0121 
0122 // ------------ method called when ending the processing of a run  ------------
0123 /*
0124 void
0125 BooleanFlagFilter::endRun(edm::Run const&, edm::EventSetup const&)
0126 {
0127 }
0128 */
0129 
0130 // ------------ method called when starting to processes a luminosity block  ------------
0131 /*
0132 void
0133 BooleanFlagFilter::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0134 {
0135 }
0136 */
0137 
0138 // ------------ method called when ending the processing of a luminosity block  ------------
0139 /*
0140 void
0141 BooleanFlagFilter::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0142 {
0143 }
0144 */
0145 
0146 //define this as a plug-in
0147 DEFINE_FWK_MODULE(BooleanFlagFilter);