Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:52

0001 // -*- C++ -*-
0002 //
0003 // Package:    CalibTracker/SiStripESProducers
0004 // Class:      SiStripThresholdFakeESSource
0005 //
0006 /**\class SiStripThresholdFakeESSource SiStripThresholdFakeESSource.h CalibTracker/SiStripESProducers/plugins/SiStripThresholdFakeESSource.cc
0007 
0008  Description: "fake" SiStripThreshold ESProducer - fixed values from configuration for all thresholds (low, high and cluster)
0009 
0010  Implementation:
0011      Port of SiStripThresholdGenerator 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/SiStripThreshold.h"
0022 #include "CondFormats/DataRecord/interface/SiStripThresholdRcd.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 SiStripThresholdFakeESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0029 public:
0030   SiStripThresholdFakeESSource(const edm::ParameterSet&);
0031   ~SiStripThresholdFakeESSource() 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<SiStripThreshold> ReturnType;
0038   ReturnType produce(const SiStripThresholdRcd&);
0039 
0040 private:
0041   float m_lTh;
0042   float m_hTh;
0043   float m_cTh;
0044   SiStripDetInfo m_detInfo;
0045 };
0046 
0047 SiStripThresholdFakeESSource::SiStripThresholdFakeESSource(const edm::ParameterSet& iConfig) {
0048   setWhatProduced(this);
0049   findingRecord<SiStripThresholdRcd>();
0050 
0051   m_lTh = iConfig.getParameter<double>("LowTh");
0052   m_hTh = iConfig.getParameter<double>("HighTh");
0053   m_cTh = iConfig.getParameter<double>("ClusTh");
0054   m_detInfo = SiStripDetInfoFileReader::read(iConfig.getParameter<edm::FileInPath>("SiStripDetInfoFile").fullPath());
0055 }
0056 
0057 SiStripThresholdFakeESSource::~SiStripThresholdFakeESSource() {}
0058 
0059 void SiStripThresholdFakeESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0060                                                   const edm::IOVSyncValue& iov,
0061                                                   edm::ValidityInterval& iValidity) {
0062   iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
0063 }
0064 
0065 // ------------ method called to produce the data  ------------
0066 SiStripThresholdFakeESSource::ReturnType SiStripThresholdFakeESSource::produce(const SiStripThresholdRcd& iRecord) {
0067   using namespace edm::es;
0068 
0069   auto threshold = std::make_unique<SiStripThreshold>();
0070 
0071   for (const auto& elm : m_detInfo.getAllData()) {
0072     //Generate Thresholds for det detid
0073     SiStripThreshold::Container theSiStripVector;
0074     uint16_t strip = 0;
0075 
0076     threshold->setData(strip, m_lTh, m_hTh, m_cTh, theSiStripVector);
0077     LogDebug("SiStripThresholdFakeESSource::produce")
0078         << "detid: " << elm.first << " \t"
0079         << "firstStrip: " << strip << " \t" << theSiStripVector.back().getFirstStrip() << " \t"
0080         << "lTh: " << m_lTh << " \t" << theSiStripVector.back().getLth() << " \t"
0081         << "hTh: " << m_hTh << " \t" << theSiStripVector.back().getHth() << " \t"
0082         << "FirstStrip_and_Hth: " << theSiStripVector.back().FirstStrip_and_Hth << " \t";
0083 
0084     if (!threshold->put(elm.first, theSiStripVector)) {
0085       edm::LogError("SiStripThresholdFakeESSource::produce ") << " detid already exists";
0086     }
0087   }
0088 
0089   return threshold;
0090 }
0091 
0092 //define this as a plug-in
0093 #include "FWCore/Framework/interface/SourceFactory.h"
0094 DEFINE_FWK_EVENTSETUP_SOURCE(SiStripThresholdFakeESSource);