Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*\ \file SiStripSpyUnpackerModule.cc
0002  * \brief Source code for the spy unpacking plugin module.
0003  */
0004 
0005 // CMSSW includes
0006 #include "FWCore/Utilities/interface/EDGetToken.h"
0007 #include "FWCore/Framework/interface/Frameworkfwd.h"
0008 #include "FWCore/Framework/interface/global/EDProducer.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/Utilities/interface/InputTag.h"
0013 #include "DataFormats/Common/interface/Handle.h"
0014 #include "FWCore/Framework/interface/ESWatcher.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "FWCore/Framework/interface/MakerMacros.h"
0017 
0018 // Needed for the FED cabling
0019 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0020 #include "CondFormats/DataRecord/interface/SiStripFedCablingRcd.h"
0021 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
0022 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0023 
0024 // Needed for the FED raw data collection
0025 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0026 
0027 // For the digi stuff.
0028 #include "DataFormats/Common/interface/DetSetVector.h"
0029 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
0030 
0031 // For the unpacking object.
0032 #include "DQM/SiStripMonitorHardware/interface/SiStripSpyUnpacker.h"
0033 #include "DQM/SiStripMonitorHardware/interface/SiStripSpyUtilities.h"
0034 
0035 // Standard includes
0036 #include <memory>
0037 #include <utility>
0038 #include <string>
0039 #include <cstdint>
0040 
0041 namespace sistrip {
0042   class SpyUnpacker;
0043 }  // namespace sistrip
0044 
0045 using edm::LogError;
0046 using edm::LogInfo;
0047 
0048 namespace sistrip {
0049 
0050   /*!
0051      * @file DQM/SiStripMonitorHardware/interface/SiStripSpyUnpackerModule.cc
0052      * @class SiStripSpyUnpackerModule 
0053      *
0054      * @brief A plug-in module that takes a FEDRawDataCollection as input
0055      * from the Event and creates EDProducts containing StripDigis from spy channel 
0056      * data.
0057      */
0058   class SpyUnpackerModule : public edm::global::EDProducer<> {
0059   public:
0060     SpyUnpackerModule(const edm::ParameterSet&);
0061     ~SpyUnpackerModule() override;
0062     void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0063 
0064   private:
0065     static const char* const msgLb_;
0066 
0067     // Data members
0068     //--------------
0069     // Configuration
0070     std::vector<uint32_t> fed_ids_;     //!< Vector of FED IDs to examine (FEDs).
0071     const edm::InputTag productLabel_;  //!< The product label of the FEDRawDataCollection input.
0072     edm::EDGetTokenT<FEDRawDataCollection> productToken_;
0073     const bool allowIncompleteEvents_;  //!< Allow inconsistent (by event count, APV address) event storage.
0074     const bool storeCounters_;          //!< True = store L1ID and TotalEventCount by FED key.
0075     const bool storeScopeRawDigis_;     //!< True = store the scope mode raw digis.
0076                                         // Unpacking
0077     const SpyUnpacker unpacker_;        //!<
0078 
0079     //utilities for cabling etc...
0080     const edm::ESGetToken<SiStripFedCabling, SiStripFedCablingRcd> fedCablingToken_;
0081   };  // end of SpyUnpackerModule class.
0082 
0083 }  // end of namespace sistrip.
0084 
0085 namespace sistrip {
0086 
0087   const char* const SpyUnpackerModule::msgLb_ = "SiStripSpyUnpackerModule";
0088 
0089   SpyUnpackerModule::SpyUnpackerModule(const edm::ParameterSet& pset)
0090       : fed_ids_(pset.getParameter<std::vector<uint32_t> >("FEDIDs")),
0091         productLabel_(pset.getParameter<edm::InputTag>("InputProductLabel")),
0092         allowIncompleteEvents_(pset.getParameter<bool>("AllowIncompleteEvents")),
0093         storeCounters_(pset.getParameter<bool>("StoreCounters")),
0094         storeScopeRawDigis_(pset.getParameter<bool>("StoreScopeRawDigis")),
0095         unpacker_(allowIncompleteEvents_),
0096         fedCablingToken_(esConsumes<>()) {
0097     productToken_ = consumes<FEDRawDataCollection>(productLabel_);
0098 
0099     if ((fed_ids_.empty())) {
0100       LogInfo(msgLb_) << "No FED IDs specified, so will try to unpack all FEDs with data" << std::endl;
0101       fed_ids_.reserve(FEDNumbering::MAXSiStripFEDID - FEDNumbering::MINSiStripFEDID + 1);
0102       for (uint32_t ifed = FEDNumbering::MINSiStripFEDID; ifed <= FEDNumbering::MAXSiStripFEDID; ifed++) {
0103         fed_ids_.push_back(ifed);
0104       }
0105     }  // end of FED ID specified check.
0106 
0107     if (edm::isDebugEnabled())
0108       LogTrace(msgLb_) << "[" << __func__ << "]:"
0109                        << " Constructing object...";
0110 
0111     if (storeScopeRawDigis_)
0112       produces<edm::DetSetVector<SiStripRawDigi> >("ScopeRawDigis");
0113 
0114     if (storeCounters_) {
0115       produces<std::vector<uint32_t> >("L1ACount");
0116       produces<std::vector<uint32_t> >("TotalEventCount");
0117     }
0118 
0119     produces<uint32_t>("GlobalRunNumber");
0120 
0121   }  // end of SpyUnpackerModule constructor.
0122 
0123   SpyUnpackerModule::~SpyUnpackerModule() {
0124     if (edm::isDebugEnabled()) {
0125       LogTrace("SiStripSpyUnpacker") << "[sistrip::SpyUnpackerModule::" << __func__ << "]"
0126                                      << " Destructing object...";
0127     }
0128   }
0129 
0130   /*! \brief Scope mode digis and event counter producer.
0131    *  Retrieves cabling map from EventSetup and FEDRawDataCollection
0132    *  from Event, creates a DetSetVector of SiStripRawDigis, uses the
0133    *  SiStripSpyUnpacker class to fill the DetSetVector, and
0134    *  attaches the container to the Event.
0135    */
0136   void SpyUnpackerModule::produce(edm::StreamID, edm::Event& event, const edm::EventSetup& setup) const {
0137     const SiStripFedCabling* fedCabling = &setup.getData(fedCablingToken_);
0138     //retrieve FED raw data (by label, which is "source" by default)
0139     edm::Handle<FEDRawDataCollection> buffers;
0140     event.getByToken(productToken_, buffers);
0141 
0142     //create container for digis
0143     std::unique_ptr<edm::DetSetVector<SiStripRawDigi> > digis(new edm::DetSetVector<SiStripRawDigi>);
0144 
0145     //if necessary, create container for event counters
0146     std::unique_ptr<std::vector<uint32_t> > pTotalCounts(new std::vector<uint32_t>);
0147     std::unique_ptr<std::vector<uint32_t> > pL1ACounts(new std::vector<uint32_t>);
0148     //and for run number
0149     std::unique_ptr<uint32_t> pGlobalRun(new uint32_t);
0150     //create digis
0151     // Using FED IDs...
0152     unpacker_.createDigis(
0153         *fedCabling, *buffers, digis.get(), fed_ids_, pTotalCounts.get(), pL1ACounts.get(), pGlobalRun.get());
0154 
0155     // Add digis to event
0156     if (storeScopeRawDigis_)
0157       event.put(std::move(digis), "ScopeRawDigis");
0158 
0159     //add counters to event
0160     if (storeCounters_) {
0161       event.put(std::move(pTotalCounts), "TotalEventCount");
0162       event.put(std::move(pL1ACounts), "L1ACount");
0163     }
0164 
0165     //add global run to the event
0166     event.put(std::move(pGlobalRun), "GlobalRunNumber");
0167 
0168   }  // end of SpyUnpackerModule::produce method.
0169 
0170 }  // namespace sistrip
0171 
0172 typedef sistrip::SpyUnpackerModule SiStripSpyUnpackerModule;
0173 DEFINE_FWK_MODULE(SiStripSpyUnpackerModule);