Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:09

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 
0039 private:
0040   bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0041 
0042   // ----------member data ---------------------------
0043   edm::EDGetTokenT<bool> inputToken_;
0044   bool reverse_;
0045 };
0046 
0047 //
0048 // constants, enums and typedefs
0049 //
0050 
0051 //
0052 // static data member definitions
0053 //
0054 
0055 //
0056 // constructors and destructor
0057 //
0058 BooleanFlagFilter::BooleanFlagFilter(const edm::ParameterSet& iConfig) {
0059   //now do what ever initialization is needed
0060   inputToken_ = consumes<bool>(iConfig.getParameter<edm::InputTag>("inputLabel"));
0061   reverse_ = iConfig.getParameter<bool>("reverseDecision");
0062 }
0063 
0064 //
0065 // member functions
0066 //
0067 
0068 // ------------ method called on each new Event  ------------
0069 bool BooleanFlagFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0070   using namespace edm;
0071 
0072   Handle<bool> pIn;
0073   iEvent.getByToken(inputToken_, pIn);
0074   if (!pIn.isValid()) {
0075     throw edm::Exception(edm::errors::ProductNotFound) << " could not find requested flag\n";
0076     return true;
0077   }
0078 
0079   bool result = *pIn;
0080   if (reverse_)
0081     result = !result;
0082 
0083   return result;
0084 }
0085 
0086 //define this as a plug-in
0087 DEFINE_FWK_MODULE(BooleanFlagFilter);