Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef CommonTools_UtilAlgos_ObjectCountEventSelector_h
0002 #define CommonTools_UtilAlgos_ObjectCountEventSelector_h
0003 
0004 /** \class ObjectCountEventSelector
0005  *
0006  * Selects an event if a collection has at least N entries
0007  *
0008  * \author Luca Lista, INFN
0009  *
0010  * \version $Revision: 1.2 $
0011  *
0012  * $Id: ObjectCountEventSelector.h,v 1.2 2010/02/20 20:55:24 wmtan Exp $
0013  *
0014  */
0015 
0016 #include "FWCore/Framework/interface/Event.h"
0017 #include "FWCore/Framework/interface/ConsumesCollector.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0020 #include "FWCore/Utilities/interface/InputTag.h"
0021 #include "CommonTools/UtilAlgos/interface/ParameterAdapter.h"
0022 #include "CommonTools/UtilAlgos/interface/CollectionFilterTrait.h"
0023 #include "CommonTools/UtilAlgos/interface/EventSelectorBase.h"
0024 
0025 template <typename C,
0026           typename S = AnySelector,
0027           typename N = MinNumberSelector,
0028           typename CS = typename helper::CollectionFilterTrait<C, S, N>::type>
0029 class ObjectCountEventSelector : public EventSelectorBase {
0030 public:
0031   /// constructor
0032   explicit ObjectCountEventSelector(const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC)
0033       : srcToken_(iC.consumes<C>(cfg.template getParameter<edm::InputTag>("src"))),
0034         select_(reco::modules::make<S>(cfg, iC)),
0035         sizeSelect_(reco::modules::make<N>(cfg, iC)) {}
0036 
0037   static void fillPSetDescription(edm::ParameterSetDescription& desc) {
0038     desc.add<edm::InputTag>("src", edm::InputTag());
0039     reco::modules::fillPSetDescription<S>(desc);
0040     reco::modules::fillPSetDescription<N>(desc);
0041   }
0042 
0043   bool operator()(edm::Event& evt, const edm::EventSetup&) const override {
0044     edm::Handle<C> source;
0045     evt.getByToken(srcToken_, source);
0046     return CS::filter(*source, select_, sizeSelect_);
0047   }
0048 
0049 private:
0050   /// source collection label
0051   edm::EDGetTokenT<C> srcToken_;
0052 
0053   /// object filter
0054   S select_;
0055 
0056   /// minimum number of entries in a collection
0057   N sizeSelect_;
0058 };
0059 
0060 #endif