Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-05 04:09:22

0001 // -*- C++ -*-
0002 //
0003 // Package:    CalibTracker/SiStripESProducers
0004 // Class:      SiStripLatencyFakeESSource
0005 //
0006 /**\class SiStripLatencyFakeESSource SiStripLatencyFakeESSource.h CalibTracker/SiStripESProducers/plugins/SiStripLatencyFakeESSource.cc
0007 
0008  Description: "fake" SiStripLatency ESProducer - fixed value from configuration for the latency and mode
0009 
0010  Implementation:
0011      Port of SiStripLatencyGenerator and templated fake ESSource to an edm::ESProducer
0012 */
0013 
0014 // system include files
0015 #include <memory>
0016 
0017 // user include files
0018 #include "FWCore/Framework/interface/ESProducer.h"
0019 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0020 
0021 #include "CondFormats/SiStripObjects/interface/SiStripLatency.h"
0022 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0025 
0026 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0027 
0028 class SiStripLatencyFakeESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0029 public:
0030   SiStripLatencyFakeESSource(const edm::ParameterSet&);
0031   ~SiStripLatencyFakeESSource() override;
0032 
0033   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0034                       const edm::IOVSyncValue& iov,
0035                       edm::ValidityInterval& iValidity) override;
0036 
0037   typedef std::unique_ptr<SiStripLatency> ReturnType;
0038   ReturnType produce(const SiStripLatencyRcd&);
0039 
0040 private:
0041   uint32_t m_latency;
0042   uint32_t m_mode;
0043   SiStripDetInfo m_detInfo;
0044 };
0045 
0046 SiStripLatencyFakeESSource::SiStripLatencyFakeESSource(const edm::ParameterSet& iConfig) {
0047   setWhatProduced(this);
0048   findingRecord<SiStripLatencyRcd>();
0049 
0050   m_latency = iConfig.getParameter<uint32_t>("latency");
0051   m_mode = iConfig.getParameter<uint32_t>("mode");
0052   m_detInfo = SiStripDetInfoFileReader::read(iConfig.getParameter<edm::FileInPath>("SiStripDetInfoFile").fullPath());
0053 }
0054 
0055 SiStripLatencyFakeESSource::~SiStripLatencyFakeESSource() {}
0056 
0057 void SiStripLatencyFakeESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0058                                                 const edm::IOVSyncValue& iov,
0059                                                 edm::ValidityInterval& iValidity) {
0060   iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
0061 }
0062 
0063 // ------------ method called to produce the data  ------------
0064 SiStripLatencyFakeESSource::ReturnType SiStripLatencyFakeESSource::produce(const SiStripLatencyRcd& iRecord) {
0065   using namespace edm::es;
0066 
0067   auto latency = std::make_unique<SiStripLatency>();
0068 
0069   const auto& detInfos = m_detInfo.getAllData();
0070   // Take the last detId. Since the map is sorted it will be the biggest value
0071   if (!detInfos.empty()) {
0072     // Set the apv number as 6, the highest possible
0073     edm::LogInfo("SiStripLatencyGenerator") << "detId = " << detInfos.rbegin()->first << " apv = " << 6
0074                                             << " latency = " << m_latency << " mode = " << m_mode;
0075     latency->put(detInfos.rbegin()->first, 6, m_latency, m_mode);
0076 
0077     // Call this method to collapse all consecutive detIdAndApvs with the same latency and mode to a single entry
0078     latency->compress();
0079   } else {
0080     edm::LogError("SiStripLatencyGenerator") << "Error: detInfo map is empty. Cannot get the last detId.";
0081   }
0082 
0083   return latency;
0084 }
0085 
0086 //define this as a plug-in
0087 #include "FWCore/Framework/interface/SourceFactory.h"
0088 DEFINE_FWK_EVENTSETUP_SOURCE(SiStripLatencyFakeESSource);