File indexing completed on 2024-04-06 12:12:49
0001
0002 #include "FWCore/Framework/interface/global/EDFilter.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0007
0008 namespace edm {
0009 class ModuloStreamIDFilter : public global::EDFilter<> {
0010 public:
0011 explicit ModuloStreamIDFilter(ParameterSet const&);
0012 ~ModuloStreamIDFilter() override;
0013
0014 static void fillDescriptions(ConfigurationDescriptions& descriptions);
0015 bool filter(StreamID, Event& e, EventSetup const& c) const final;
0016
0017 private:
0018 const unsigned int n_;
0019 const unsigned int offset_;
0020 };
0021
0022 ModuloStreamIDFilter::ModuloStreamIDFilter(ParameterSet const& ps)
0023 : n_(ps.getParameter<unsigned int>("modulo")), offset_(ps.getParameter<unsigned int>("offset")) {}
0024
0025 ModuloStreamIDFilter::~ModuloStreamIDFilter() {}
0026
0027 bool ModuloStreamIDFilter::filter(StreamID iStreamID, Event&, EventSetup const&) const {
0028 return (iStreamID.value() % n_ == offset_);
0029 }
0030
0031 void ModuloStreamIDFilter::fillDescriptions(ConfigurationDescriptions& descriptions) {
0032 ParameterSetDescription desc;
0033 desc.add<unsigned int>("modulo")->setComment("Accept event if (streamID % modulo) == offset.");
0034 desc.add<unsigned int>("offset")->setComment("Used to shift which value of modulo to accept.");
0035 descriptions.add("streamIDFilter", desc);
0036 }
0037 }
0038
0039 using edm::ModuloStreamIDFilter;
0040 DEFINE_FWK_MODULE(ModuloStreamIDFilter);