Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:48

0001 
0002 #include "FWCore/Framework/interface/global/EDFilter.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0008 
0009 namespace {
0010 
0011   template <typename T>
0012   std::vector<T> sorted(std::vector<T> v) {
0013     std::sort(v.begin(), v.end());
0014     return v;
0015   }
0016 
0017 }  // namespace
0018 
0019 namespace edm {
0020 
0021   class BunchCrossingFilter : public global::EDFilter<> {
0022   public:
0023     explicit BunchCrossingFilter(ParameterSet const& config);
0024 
0025     static void fillDescriptions(ConfigurationDescriptions& descriptions);
0026     bool filter(StreamID, Event& event, EventSetup const&) const final;
0027 
0028   private:
0029     const std::vector<unsigned int> bunches_;
0030   };
0031 
0032   BunchCrossingFilter::BunchCrossingFilter(ParameterSet const& config)
0033       : bunches_(sorted(config.getParameter<std::vector<unsigned int>>("bunches"))) {}
0034 
0035   bool BunchCrossingFilter::filter(StreamID, Event& event, EventSetup const&) const {
0036     return std::binary_search(bunches_.begin(), bunches_.end(), event.bunchCrossing());
0037   }
0038 
0039   void BunchCrossingFilter::fillDescriptions(ConfigurationDescriptions& descriptions) {
0040     ParameterSetDescription desc;
0041     desc.add<std::vector<unsigned int>>("bunches", {})
0042         ->setComment("List of bunch crossings for which events should be accepted [1-3564].");
0043     descriptions.add("bunchCrossingFilter", desc);
0044   }
0045 
0046 }  // namespace edm
0047 
0048 using edm::BunchCrossingFilter;
0049 DEFINE_FWK_MODULE(BunchCrossingFilter);