Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef CommonTools_UtilAlgos_OverlapExclusionSelector_h
0002 #define CommonTools_UtilAlgos_OverlapExclusionSelector_h
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/Utilities/interface/InputTag.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/ConsumesCollector.h"
0007 #include "DataFormats/Common/interface/Handle.h"
0008 
0009 namespace edm {
0010   class EventSetup;
0011 }
0012 
0013 template <typename C, typename T, typename O>
0014 class OverlapExclusionSelector {
0015 public:
0016   OverlapExclusionSelector(const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC)
0017       : OverlapExclusionSelector(cfg, iC){};
0018   OverlapExclusionSelector(const edm::ParameterSet& cfg, edm::ConsumesCollector& iC);
0019   void newEvent(const edm::Event&, const edm::EventSetup&) const;
0020   bool operator()(const T&) const;
0021 
0022 private:
0023   edm::EDGetTokenT<C> srcToken_;
0024   mutable typename C::const_iterator begin_, end_;
0025   O overlap_;
0026 };
0027 
0028 template <typename C, typename T, typename O>
0029 OverlapExclusionSelector<C, T, O>::OverlapExclusionSelector(const edm::ParameterSet& cfg, edm::ConsumesCollector& iC)
0030     : srcToken_(iC.consumes<C>(cfg.template getParameter<edm::InputTag>("overlap"))), overlap_(cfg) {}
0031 
0032 template <typename C, typename T, typename O>
0033 void OverlapExclusionSelector<C, T, O>::newEvent(const edm::Event& evt, const edm::EventSetup&) const {
0034   edm::Handle<C> h;
0035   evt.getByToken(srcToken_, h);
0036   begin_ = h->begin();
0037   end_ = h->end();
0038 }
0039 
0040 template <typename C, typename T, typename O>
0041 bool OverlapExclusionSelector<C, T, O>::operator()(const T& t) const {
0042   bool noOverlap = true;
0043   for (typename C::const_iterator i = begin_; i != end_; ++i) {
0044     if (overlap_(*i, t)) {
0045       noOverlap = false;
0046       break;
0047     }
0048   }
0049   return noOverlap;
0050 }
0051 
0052 #include "CommonTools/UtilAlgos/interface/EventSetupInitTrait.h"
0053 
0054 EVENTSETUP_STD_INIT_T3(OverlapExclusionSelector);
0055 
0056 #endif