test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  virtual ~Prescaler();
14 
15  static void fillDescriptions(ConfigurationDescriptions& descriptions);
16  virtual bool filter(StreamID, Event& e, EventSetup const& c) const override 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_(),
26  n_(ps.getParameter<int>("prescaleFactor")),
27  offset_(ps.getParameter<int>("prescaleOffset")) {
28  }
29 
31  }
32 
33  bool Prescaler::filter(StreamID, Event&, EventSetup const&) const {
34  //have to capture the value here since it could change by the time we do the comparision
35  int count = ++count_;
36  return count % n_ == offset_ ? true : false;
37  }
38 
39  void
42  desc.add<int>("prescaleFactor")->setComment("Accept one event every N events");
43  desc.add<int>("prescaleOffset")->setComment("The first event to accept should be the Mth one. Choose 'prescaleFactor'=1 to accept the first event from the source.");
44  descriptions.add("preScaler", desc);
45  }
46 }
47 
48 using edm::Prescaler;
Prescaler(ParameterSet const &)
Definition: Prescaler.cc:24
static void fillDescriptions(ConfigurationDescriptions &descriptions)
Definition: Prescaler.cc:40
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual ~Prescaler()
Definition: Prescaler.cc:30
std::atomic< int > count_
Definition: Prescaler.cc:19
ParameterDescriptionBase * add(U const &iLabel, T const &value)
virtual bool filter(StreamID, Event &e, EventSetup const &c) const overridefinal
Definition: Prescaler.cc:33
void add(std::string const &label, ParameterSetDescription const &psetDescription)