CMS 3D CMS Logo

APVModeFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Alignment/CommonAlignment
4 // Class: APVModeFilter
5 //
31 //
32 // Original Author: Gregor Mittag
33 // Created: Thu, 03 Dec 2015 16:51:33 GMT
34 //
35 //
36 
37 
38 // system include files
39 #include <bitset>
40 #include <array>
41 
42 // user include files
52 
53 //
54 // class declaration
55 //
56 
58 public:
59  explicit APVModeFilter(const edm::ParameterSet&);
60  ~APVModeFilter() override = default;
61 
63 
64 private:
65  bool filter(edm::Event&, const edm::EventSetup&) override;
66  void beginRun(const edm::Run&, const edm::EventSetup&) override;
67 
68  using BitMask = std::bitset<16>;
69 
71  BitMask convertMode(const std::string& mode) const;
72 
74  BitMask convertMode(const uint16_t& mode) const;
75 
76 
77  // ----------member data ---------------------------
78 
80  static constexpr std::array<size_t, 2> bits_ = {{1, 3}};
82  static constexpr BitMask peak_ = BitMask(10);
84 
85  const BitMask mode_;
87 };
88 
89 
90 //
91 // static data member definitions
92 //
93 constexpr std::array<size_t, 2> APVModeFilter::bits_;
97 
98 
99 //
100 // constructors and destructor
101 //
103  mode_(convertMode(iConfig.getUntrackedParameter<std::string>("apvMode"))) {
104  edm::LogInfo("Alignment")
105  << "@SUB=APVModeFilter::APVModeFilter"
106  << "Selecting events with APV mode '"
107  << iConfig.getUntrackedParameter<std::string>("apvMode") << "'.";
108 }
109 
110 
111 //
112 // member functions
113 //
114 
115 // ------------ method called on each new Event ------------
116 bool
118  return mode_ == modeCurrentRun_;
119 }
120 
121 // ------------ method called when starting to processes a run ------------
122 void
124  edm::ESHandle<SiStripLatency> siStripLatency;
125  iSetup.get<SiStripLatencyRcd>().get(siStripLatency);
126  auto product = siStripLatency.product();
127  modeCurrentRun_ = convertMode(product->singleMode());
128 }
129 
132  if (mode == "deco") {
133  return deco_;
134  } else if (mode == "peak") {
135  return peak_;
136  } else if (mode == "multi") {
137  return multi_;
138  } else {
139  throw cms::Exception("BadConfig")
140  << "Your choice for the APV mode ('" << mode
141  << "') is invalid.\nValid APV modes: deco, peak, multi" << std::endl;
142  }
143 }
144 
146 APVModeFilter::convertMode(const uint16_t& mode) const {
147  BitMask input(mode);
148  BitMask result;
149  for (const auto& bit: bits_) result.set(bit, input[bit]);
150  return result;
151 }
152 
153 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
154 void
157  desc.setComment("Filters events with the APV mode 'apvMode' (deco/peak/multi).");
158  desc.addUntracked<std::string>("apvMode", "deco");
159  descriptions.add("apvModeFilter", desc);
160 }
161 
162 //define this as a plug-in
static BitMask multi_
peak mode bit mask (1010)
T getUntrackedParameter(std::string const &, T const &) const
static std::array< size_t, 2 > bits_
bits of interest for the APV mode
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
bool filter(edm::Event &, const edm::EventSetup &) override
~APVModeFilter() override=default
void beginRun(const edm::Run &, const edm::EventSetup &) override
const BitMask mode_
multi mode bit mask (1000)
static BitMask deco_
static std::string const input
Definition: EdmProvDump.cc:48
APVModeFilter(const edm::ParameterSet &)
void setComment(std::string const &value)
static BitMask peak_
deco mode bit mask (0000)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BitMask convertMode(const std::string &mode) const
APV mode is encoded in uin16_t.
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &)
T get() const
Definition: EventSetup.h:71
BitMask modeCurrentRun_
APV mode that is filtered.
T const * product() const
Definition: ESHandle.h:86
#define constexpr
Definition: Run.h:45
std::bitset< 16 > BitMask