Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:21

0001 
0002 #include "SiStripRawToDigiModule.h"
0003 #include "SiStripRawToDigiUnpacker.h"
0004 
0005 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0006 #include "DataFormats/Common/interface/DetSetVector.h"
0007 #include "DataFormats/Common/interface/Handle.h"
0008 #include "DataFormats/DetId/interface/DetIdCollection.h"
0009 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0010 #include "DataFormats/SiStripCommon/interface/SiStripEventSummary.h"
0011 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
0012 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include <cstdlib>
0015 
0016 namespace sistrip {
0017 
0018   RawToDigiModule::RawToDigiModule(const edm::ParameterSet& pset)
0019       : rawToDigi_(nullptr),
0020         cabling_(nullptr),
0021         extractCm_(false),
0022         doFullCorruptBufferChecks_(false),
0023         doAPVEmulatorCheck_(true),
0024         tTopoToken_(esConsumes()),
0025         fedCablingToken_(esConsumes()) {
0026     if (edm::isDebugEnabled()) {
0027       LogTrace("SiStripRawToDigi") << "[sistrip::RawToDigiModule::" << __func__ << "]"
0028                                    << " Constructing object...";
0029     }
0030 
0031     token_ = consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("ProductLabel"));
0032     int16_t appended_bytes = pset.getParameter<int>("AppendedBytes");
0033     int16_t trigger_fed_id = pset.getParameter<int>("TriggerFedId");
0034     bool legacy_unpacker = pset.getParameter<bool>("LegacyUnpacker");
0035     bool use_daq_register = pset.getParameter<bool>("UseDaqRegister");
0036     bool using_fed_key = pset.getParameter<bool>("UseFedKey");
0037     bool unpack_bad_channels = pset.getParameter<bool>("UnpackBadChannels");
0038     bool mark_missing_feds = pset.getParameter<bool>("MarkModulesOnMissingFeds");
0039 
0040     int16_t fed_buffer_dump_freq = pset.getUntrackedParameter<int>("FedBufferDumpFreq", 0);
0041     int16_t fed_event_dump_freq = pset.getUntrackedParameter<int>("FedEventDumpFreq", 0);
0042     bool quiet = pset.getUntrackedParameter<bool>("Quiet", true);
0043     extractCm_ = pset.getParameter<bool>("UnpackCommonModeValues");
0044     doFullCorruptBufferChecks_ = pset.getParameter<bool>("DoAllCorruptBufferChecks");
0045     doAPVEmulatorCheck_ = pset.getParameter<bool>("DoAPVEmulatorCheck");
0046 
0047     uint32_t errorThreshold = pset.getParameter<unsigned int>("ErrorThreshold");
0048 
0049     rawToDigi_ = new sistrip::RawToDigiUnpacker(appended_bytes,
0050                                                 fed_buffer_dump_freq,
0051                                                 fed_event_dump_freq,
0052                                                 trigger_fed_id,
0053                                                 using_fed_key,
0054                                                 unpack_bad_channels,
0055                                                 mark_missing_feds,
0056                                                 errorThreshold);
0057     rawToDigi_->legacy(legacy_unpacker);
0058     rawToDigi_->quiet(quiet);
0059     rawToDigi_->useDaqRegister(use_daq_register);
0060     rawToDigi_->extractCm(extractCm_);
0061     rawToDigi_->doFullCorruptBufferChecks(doFullCorruptBufferChecks_);
0062     rawToDigi_->doAPVEmulatorCheck(doAPVEmulatorCheck_);
0063 
0064     produces<SiStripEventSummary>();
0065     produces<edm::DetSetVector<SiStripRawDigi> >("ScopeMode");
0066     produces<edm::DetSetVector<SiStripRawDigi> >("VirginRaw");
0067     produces<edm::DetSetVector<SiStripRawDigi> >("ProcessedRaw");
0068     produces<edm::DetSetVector<SiStripDigi> >("ZeroSuppressed");
0069     produces<DetIdCollection>();
0070     if (extractCm_)
0071       produces<edm::DetSetVector<SiStripRawDigi> >("CommonMode");
0072   }
0073 
0074   RawToDigiModule::~RawToDigiModule() {
0075     if (rawToDigi_) {
0076       delete rawToDigi_;
0077     }
0078     if (cabling_) {
0079       cabling_ = nullptr;
0080     }
0081     if (edm::isDebugEnabled()) {
0082       LogTrace("SiStripRawToDigi") << "[sistrip::RawToDigiModule::" << __func__ << "]"
0083                                    << " Destructing object...";
0084     }
0085   }
0086 
0087   /** 
0088       Retrieves cabling map from EventSetup and FEDRawDataCollection
0089       from Event, creates a DetSetVector of SiStrip(Raw)Digis, uses the
0090       SiStripRawToDigiUnpacker class to fill the DetSetVector, and
0091       attaches the container to the Event.
0092   */
0093   void RawToDigiModule::produce(edm::Event& event, const edm::EventSetup& setup) {
0094     updateCabling(setup);
0095 
0096     // Retrieve FED raw data (by label, which is "source" by default)
0097     edm::Handle<FEDRawDataCollection> buffers;
0098     event.getByToken(token_, buffers);
0099 
0100     // Populate SiStripEventSummary object with "trigger FED" info
0101     auto summary = std::make_unique<SiStripEventSummary>();
0102     rawToDigi_->triggerFed(*buffers, *summary, event.id().event());
0103 
0104     // Create containers for digis
0105     edm::DetSetVector<SiStripRawDigi>* sm = new edm::DetSetVector<SiStripRawDigi>();
0106     edm::DetSetVector<SiStripRawDigi>* vr = new edm::DetSetVector<SiStripRawDigi>();
0107     edm::DetSetVector<SiStripRawDigi>* pr = new edm::DetSetVector<SiStripRawDigi>();
0108     edm::DetSetVector<SiStripDigi>* zs = new edm::DetSetVector<SiStripDigi>();
0109     DetIdCollection* ids = new DetIdCollection();
0110     edm::DetSetVector<SiStripRawDigi>* cm = new edm::DetSetVector<SiStripRawDigi>();
0111 
0112     // Create digis
0113     if (rawToDigi_) {
0114       rawToDigi_->createDigis(*cabling_, *buffers, *summary, *sm, *vr, *pr, *zs, *ids, *cm);
0115     }
0116 
0117     // Create unique_ptr's of digi products
0118     std::unique_ptr<edm::DetSetVector<SiStripRawDigi> > sm_dsv(sm);
0119     std::unique_ptr<edm::DetSetVector<SiStripRawDigi> > vr_dsv(vr);
0120     std::unique_ptr<edm::DetSetVector<SiStripRawDigi> > pr_dsv(pr);
0121     std::unique_ptr<edm::DetSetVector<SiStripDigi> > zs_dsv(zs);
0122     std::unique_ptr<DetIdCollection> det_ids(ids);
0123     std::unique_ptr<edm::DetSetVector<SiStripRawDigi> > cm_dsv(cm);
0124 
0125     // Add to event
0126     event.put(std::move(summary));
0127     event.put(std::move(sm_dsv), "ScopeMode");
0128     event.put(std::move(vr_dsv), "VirginRaw");
0129     event.put(std::move(pr_dsv), "ProcessedRaw");
0130     event.put(std::move(zs_dsv), "ZeroSuppressed");
0131     event.put(std::move(det_ids));
0132     if (extractCm_)
0133       event.put(std::move(cm_dsv), "CommonMode");
0134   }
0135 
0136   void RawToDigiModule::updateCabling(const edm::EventSetup& setup) {
0137     if (fedCablingWatcher_.check(setup)) {
0138       const bool isFirst = cabling_ != nullptr;
0139       cabling_ = &setup.getData(fedCablingToken_);
0140 
0141       if (edm::isDebugEnabled()) {
0142         if (isFirst) {
0143           std::stringstream ss;
0144           ss << "[sistrip::RawToDigiModule::" << __func__ << "]"
0145              << " Updating cabling for first time..." << std::endl
0146              << " Terse print out of FED cabling:" << std::endl;
0147           cabling_->terse(ss);
0148           LogTrace("SiStripRawToDigi") << ss.str();
0149         }
0150       }
0151 
0152       if (edm::isDebugEnabled()) {
0153         std::stringstream sss;
0154         sss << "[sistrip::RawToDigiModule::" << __func__ << "]"
0155             << " Summary of FED cabling:" << std::endl;
0156         cabling_->summary(sss, &setup.getData(tTopoToken_));
0157         LogTrace("SiStripRawToDigi") << sss.str();
0158       }
0159     }
0160   }
0161 
0162   void RawToDigiModule::endStream() { rawToDigi_->printWarningSummary(); }
0163 }  // namespace sistrip