Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:44:34

0001 // -*- C++ -*-
0002 //
0003 // Package:    Alignment/CommonAlignment
0004 // Class:      APVModeFilter
0005 //
0006 /**\class APVModeFilter APVModeFilter.cc Alignment/CommonAlignment/plugins/APVModeFilter.cc
0007 
0008  Description: Plugin to filter events based on the APV mode
0009 
0010  Implementation:
0011      The filter checks the bit configuration used for a given run and selects
0012      only events according to the configured APV mode.
0013 
0014      General reference:
0015      https://twiki.cern.ch/twiki/bin/view/CMS/SiStripConditionObjects#SiStripLatency
0016 
0017      Document describing the bit configuration (section 5.5):
0018      https://cds.cern.ch/record/1069892/files/cer-002725643.pdf
0019 
0020      Summary given here:
0021      https://hypernews.cern.ch/HyperNews/CMS/get/recoTracking/1590/1/1/1.html
0022 
0023      bit 1: 0 = 3-sample,      1 = 1-sample
0024      bit 3: 0 = deconvolution, 1 = peak
0025 
0026      if both bits are zero: deco
0027      if both bits are one: peak
0028      if 1 is zero and bit 3 is one: multi (not used in actual data taking)
0029 
0030 */
0031 //
0032 // Original Author:  Gregor Mittag
0033 //         Created:  Thu, 03 Dec 2015 16:51:33 GMT
0034 //
0035 //
0036 
0037 // system include files
0038 #include <bitset>
0039 #include <array>
0040 
0041 // user include files
0042 #include "FWCore/Framework/interface/Frameworkfwd.h"
0043 #include "FWCore/Framework/interface/MakerMacros.h"
0044 #include "FWCore/Framework/interface/EventSetup.h"
0045 #include "FWCore/Framework/interface/stream/EDFilter.h"
0046 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0047 #include "FWCore/Utilities/interface/Exception.h"
0048 #include "CondFormats/SiStripObjects/interface/SiStripLatency.h"
0049 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
0050 
0051 //
0052 // class declaration
0053 //
0054 
0055 class APVModeFilter : public edm::stream::EDFilter<> {
0056 public:
0057   explicit APVModeFilter(const edm::ParameterSet&);
0058   ~APVModeFilter() override = default;
0059 
0060   static void fillDescriptions(edm::ConfigurationDescriptions&);
0061 
0062 private:
0063   bool filter(edm::Event&, const edm::EventSetup&) override;
0064   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0065 
0066   using BitMask = std::bitset<16>;  /// APV mode is encoded in uin16_t
0067 
0068   /// converts configuration parameter into type used for APV mode filtering
0069   BitMask convertMode(const std::string& mode) const;
0070 
0071   /// converts latency record content into type used for APV mode filtering
0072   BitMask convertMode(const uint16_t& mode) const;
0073 
0074   // ----------member data ---------------------------
0075 
0076   // esConsumes
0077   const edm::ESGetToken<SiStripLatency, SiStripLatencyRcd> latencyToken_;
0078 
0079   /// bits of interest for the APV mode
0080   static constexpr std::array<size_t, 2> bits_ = {{1, 3}};
0081   static constexpr BitMask deco_ = BitMask(0);   /// deco mode bit mask (0000)
0082   static constexpr BitMask peak_ = BitMask(10);  /// peak mode bit mask (1010)
0083   static constexpr BitMask multi_ = BitMask(8);  /// multi mode bit mask (1000)
0084 
0085   const BitMask mode_;      /// APV mode that is filtered
0086   BitMask modeCurrentRun_;  /// APV mode of the current run
0087 };
0088 
0089 //
0090 // static data member definitions
0091 //
0092 constexpr std::array<size_t, 2> APVModeFilter::bits_;
0093 constexpr APVModeFilter::BitMask APVModeFilter::deco_;
0094 constexpr APVModeFilter::BitMask APVModeFilter::peak_;
0095 constexpr APVModeFilter::BitMask APVModeFilter::multi_;
0096 
0097 //
0098 // constructors and destructor
0099 //
0100 APVModeFilter::APVModeFilter(const edm::ParameterSet& iConfig)
0101     : latencyToken_(esConsumes<edm::Transition::BeginRun>()),
0102       mode_(convertMode(iConfig.getUntrackedParameter<std::string>("apvMode"))) {
0103   edm::LogInfo("Alignment") << "@SUB=APVModeFilter::APVModeFilter"
0104                             << "Selecting events with APV mode '"
0105                             << iConfig.getUntrackedParameter<std::string>("apvMode") << "'.";
0106 }
0107 
0108 //
0109 // member functions
0110 //
0111 
0112 // ------------ method called on each new Event  ------------
0113 bool APVModeFilter::filter(edm::Event&, const edm::EventSetup&) { return mode_ == modeCurrentRun_; }
0114 
0115 // ------------ method called when starting to processes a run  ------------
0116 void APVModeFilter::beginRun(const edm::Run&, const edm::EventSetup& iSetup) {
0117   const auto& siStripLatency = &iSetup.getData(latencyToken_);
0118   modeCurrentRun_ = convertMode(siStripLatency->singleMode());
0119 }
0120 
0121 APVModeFilter::BitMask APVModeFilter::convertMode(const std::string& mode) const {
0122   if (mode == "deco") {
0123     return deco_;
0124   } else if (mode == "peak") {
0125     return peak_;
0126   } else if (mode == "multi") {
0127     return multi_;
0128   } else {
0129     throw cms::Exception("BadConfig") << "Your choice for the APV mode ('" << mode
0130                                       << "') is invalid.\nValid APV modes: deco, peak, multi" << std::endl;
0131   }
0132 }
0133 
0134 APVModeFilter::BitMask APVModeFilter::convertMode(const uint16_t& mode) const {
0135   BitMask input(mode);
0136   BitMask result;
0137   for (const auto& bit : bits_)
0138     result.set(bit, input[bit]);
0139   return result;
0140 }
0141 
0142 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0143 void APVModeFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0144   edm::ParameterSetDescription desc;
0145   desc.setComment("Filters events with the APV mode 'apvMode' (deco/peak/multi).");
0146   desc.addUntracked<std::string>("apvMode", "deco");
0147   descriptions.add("apvModeFilter", desc);
0148 }
0149 
0150 //define this as a plug-in
0151 DEFINE_FWK_MODULE(APVModeFilter);