CMS 3D CMS Logo

Prescaler.cc
Go to the documentation of this file.
1 
2 #include <atomic>
8 
9 namespace edm {
10  class Prescaler : public global::EDFilter<> {
11  public:
12  explicit Prescaler(ParameterSet const&);
13  ~Prescaler() override;
14 
15  static void fillDescriptions(ConfigurationDescriptions& descriptions);
16  bool filter(StreamID, Event& e, EventSetup const& c) const final;
17 
18  private:
19  mutable std::atomic<int> count_;
20  int n_; // accept one in n
21  int offset_; // with offset, ie. sequence of events does not have to start at first event
22  };
23 
25  : count_(), n_(ps.getParameter<int>("prescaleFactor")), offset_(ps.getParameter<int>("prescaleOffset")) {}
26 
28 
29  bool Prescaler::filter(StreamID, Event&, EventSetup const&) const {
30  //have to capture the value here since it could change by the time we do the comparision
31  int count = ++count_;
32  return count % n_ == offset_ ? true : false;
33  }
34 
37  desc.add<int>("prescaleFactor")->setComment("Accept one event every N events");
38  desc.add<int>("prescaleOffset")
39  ->setComment(
40  "The first event to accept should be the Mth one. Choose 'prescaleFactor'=1 to accept the first event from "
41  "the source.");
42  descriptions.add("preScaler", desc);
43  }
44 } // namespace edm
45 
46 using edm::Prescaler;
Prescaler(ParameterSet const &)
Definition: Prescaler.cc:24
static void fillDescriptions(ConfigurationDescriptions &descriptions)
Definition: Prescaler.cc:35
std::atomic< int > count_
Definition: Prescaler.cc:19
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool filter(StreamID, Event &e, EventSetup const &c) const final
Definition: Prescaler.cc:29
~Prescaler() override
Definition: Prescaler.cc:27
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.