Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-31 23:14:01

0001 #include <string>
0002 #include <memory>
0003 #include <vector>
0004 #include <utility>
0005 
0006 #include "FWCore/Utilities/interface/EDGetToken.h"
0007 #include "FWCore/Framework/interface/global/EDProducer.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/Utilities/interface/InputTag.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 
0014 #include "DataFormats/Common/interface/Handle.h"
0015 #include "DataFormats/Common/interface/DetSetVector.h"
0016 #include "CondFormats/DataRecord/interface/SiStripFedCablingRcd.h"
0017 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0018 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
0019 
0020 #include "DQM/SiStripMonitorHardware/interface/SiStripSpyDigiConverter.h"
0021 #include "DQM/SiStripMonitorHardware/interface/SiStripSpyUtilities.h"
0022 
0023 /**
0024    @file DQM/SiStripMonitorHardware/interface/SiStripSpyDigiConverterModule.cc
0025    @class SiStripSpyDigiConverterModule 
0026    
0027    @brief A plug-in module that takes the spy channel scope mode digis as input
0028    from the Event and creates EDProducts containing intermediate and VirginRaw
0029    like SiStripRawDigis. 
0030 */
0031 
0032 namespace sistrip {
0033 
0034   class SpyDigiConverterModule : public edm::global::EDProducer<> {
0035   public:
0036     SpyDigiConverterModule(const edm::ParameterSet&);
0037     ~SpyDigiConverterModule() override;
0038     void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0039 
0040   private:
0041     const edm::InputTag productLabel_;
0042     edm::EDGetTokenT<sistrip::SpyDigiConverter::DSVRawDigis> productToken_;
0043     const bool storeAPVAddress_;  //!< True = store APVE address for each channel.
0044     const bool storePayloadDigis_, storeReorderedDigis_, storeModuleDigis_;
0045     sistrip::SpyUtilities::FrameQuality frameQuality_;
0046     const bool discardDigisWithAPVAddressError_;
0047     const uint32_t expectedHeaderBit_;
0048 
0049     //utilities for cabling etc...
0050     edm::ESGetToken<SiStripFedCabling, SiStripFedCablingRcd> fedCablingToken_;
0051   };
0052 
0053 }  // namespace sistrip
0054 
0055 namespace sistrip {
0056 
0057   SpyDigiConverterModule::SpyDigiConverterModule(const edm::ParameterSet& pset)
0058       : productLabel_(pset.getParameter<edm::InputTag>("InputProductLabel")),
0059         storeAPVAddress_(pset.getParameter<bool>("StoreAPVAddress")),
0060         storePayloadDigis_(pset.getParameter<bool>("StorePayloadDigis")),
0061         storeReorderedDigis_(pset.getParameter<bool>("StoreReorderedDigis")),
0062         storeModuleDigis_(pset.getParameter<bool>("StoreModuleDigis")),
0063         discardDigisWithAPVAddressError_(pset.getParameter<bool>("DiscardDigisWithWrongAPVAddress")),
0064         expectedHeaderBit_(pset.getParameter<uint32_t>("ExpectedPositionOfFirstHeaderBit")) {
0065     productToken_ = consumes<sistrip::SpyDigiConverter::DSVRawDigis>(productLabel_);
0066     if (edm::isDebugEnabled()) {
0067       LogTrace("SiStripSpyDigiConverter") << "[sistrip::SpyDigiConverterModule::" << __func__ << "]"
0068                                           << " Constructing object...";
0069     }
0070     if (storeModuleDigis_) {
0071       fedCablingToken_ = esConsumes<>();
0072     }
0073 
0074     if (storePayloadDigis_)
0075       produces<edm::DetSetVector<SiStripRawDigi> >("SpyPayload");
0076     if (storeReorderedDigis_)
0077       produces<edm::DetSetVector<SiStripRawDigi> >("SpyReordered");
0078     if (storeModuleDigis_)
0079       produces<edm::DetSetVector<SiStripRawDigi> >("SpyVirginRaw");
0080 
0081     if (storeAPVAddress_) {
0082       produces<std::vector<uint32_t> >("APVAddress");
0083       //produces<uint8_t>("APVAddress");
0084     }
0085 
0086     frameQuality_.minDigiRange = static_cast<uint16_t>(pset.getParameter<uint32_t>("MinDigiRange"));
0087     frameQuality_.maxDigiRange = static_cast<uint16_t>(pset.getParameter<uint32_t>("MaxDigiRange"));
0088     frameQuality_.minZeroLight = static_cast<uint16_t>(pset.getParameter<uint32_t>("MinZeroLight"));
0089     frameQuality_.maxZeroLight = static_cast<uint16_t>(pset.getParameter<uint32_t>("MaxZeroLight"));
0090     frameQuality_.minTickHeight = static_cast<uint16_t>(pset.getParameter<uint32_t>("MinTickHeight"));
0091     frameQuality_.maxTickHeight = static_cast<uint16_t>(pset.getParameter<uint32_t>("MaxTickHeight"));
0092 
0093   }  // end of constructor.
0094 
0095   SpyDigiConverterModule::~SpyDigiConverterModule() {
0096     if (edm::isDebugEnabled()) {
0097       LogTrace("SiStripSpyDigiConverter") << "[sistrip::SpyDigiConverterModule::" << __func__ << "]"
0098                                           << " Destructing object...";
0099     }
0100   }  // end of destructor.
0101 
0102   /** 
0103       Retrieves cabling map from EventSetup and spy channel scope mode digis
0104       from Event, creates DetSetVectors of SiStripRawDigis, at verious levels of
0105       processing, using the SiStripSpyDigiConverter class and
0106       attaches the containers to the Event.
0107   */
0108   void SpyDigiConverterModule::produce(edm::StreamID, edm::Event& event, const edm::EventSetup& setup) const {
0109     if (!(storePayloadDigis_ || storeReorderedDigis_ || storeModuleDigis_ || storeAPVAddress_))
0110       return;
0111 
0112     //retrieve the scope mode digis
0113     edm::Handle<sistrip::SpyDigiConverter::DSVRawDigis> scopeDigisHandle;
0114     event.getByToken(productToken_, scopeDigisHandle);
0115 
0116     //32-bit to accomodate known CMSSW container
0117     std::unique_ptr<std::vector<uint32_t> > pAPVAddresses(new std::vector<uint32_t>);
0118 
0119     std::unique_ptr<sistrip::SpyDigiConverter::DSVRawDigis> payloadDigis, reorderedDigis, moduleDigis;
0120 
0121     //get the majority value for expected position of first header bit
0122     //from first event, compare to expected one, else output warning.
0123     auto run_once = [this](auto digis) {
0124       uint16_t lFirstHeaderBit;
0125       sistrip::SpyUtilities::getMajorityHeader(digis, lFirstHeaderBit);
0126 
0127       if (lFirstHeaderBit != static_cast<uint16_t>(expectedHeaderBit_)) {
0128         edm::LogWarning("") << " -- Majority position for firstHeaderBit in first event (" << lFirstHeaderBit
0129                             << ") is not where expected: " << static_cast<uint16_t>(expectedHeaderBit_) << std::endl;
0130       }
0131       return false;
0132     };
0133 
0134     [[maybe_unused]] static const bool lFirstEvent = run_once(scopeDigisHandle.product());
0135 
0136     //extract frame digis and APV addresses
0137     payloadDigis = sistrip::SpyDigiConverter::extractPayloadDigis(scopeDigisHandle.product(),
0138                                                                   pAPVAddresses.get(),
0139                                                                   discardDigisWithAPVAddressError_,
0140                                                                   frameQuality_,
0141                                                                   static_cast<uint16_t>(expectedHeaderBit_));
0142 
0143     // Reorder
0144     if (storeReorderedDigis_ || storeModuleDigis_) {
0145       reorderedDigis = sistrip::SpyDigiConverter::reorderDigis(payloadDigis.get());
0146     }
0147 
0148     // Merge into modules
0149     if (storeModuleDigis_) {
0150       auto const& fedCabling = setup.getData(fedCablingToken_);
0151       moduleDigis = sistrip::SpyDigiConverter::mergeModuleChannels(reorderedDigis.get(), fedCabling);
0152     }
0153 
0154     //add to event
0155     if (storePayloadDigis_)
0156       event.put(std::move(payloadDigis), "SpyPayload");
0157     if (storeReorderedDigis_)
0158       event.put(std::move(reorderedDigis), "SpyReordered");
0159     if (storeModuleDigis_)
0160       event.put(std::move(moduleDigis), "SpyVirginRaw");
0161     if (storeAPVAddress_) {
0162       event.put(std::move(pAPVAddresses), "APVAddress");
0163     }
0164 
0165   }  // end of SpyDigiConverter::produce method.
0166 
0167 }  // namespace sistrip
0168 
0169 #include "FWCore/Framework/interface/MakerMacros.h"
0170 #include <cstdint>
0171 typedef sistrip::SpyDigiConverterModule SiStripSpyDigiConverterModule;
0172 DEFINE_FWK_MODULE(SiStripSpyDigiConverterModule);