Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:14:51

0001 // -*- C++ -*-
0002 //
0003 // Package:    CalibTracker/SiStripESProducers
0004 // Class:      SiStripConfObjectFakeESSource
0005 //
0006 /**\class SiStripConfObjectFakeESSource SiStripConfObjectFakeESSource.h CalibTracker/SiStripESProducers/plugins/SiStripConfObjectFakeESSource.cc
0007 
0008  Description: "fake" SiStripConfObject ESProducer - fixed value from configuration for conf object
0009 
0010  Implementation:
0011      Port of SiStripConfObjectGenerator 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/SiStripConfObject.h"
0022 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 
0025 class SiStripConfObjectFakeESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0026 public:
0027   SiStripConfObjectFakeESSource(const edm::ParameterSet&);
0028   ~SiStripConfObjectFakeESSource() override;
0029 
0030   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0031                       const edm::IOVSyncValue& iov,
0032                       edm::ValidityInterval& iValidity) override;
0033 
0034   typedef std::unique_ptr<SiStripConfObject> ReturnType;
0035   ReturnType produce(const SiStripConfObjectRcd&);
0036 
0037 private:
0038   std::vector<edm::ParameterSet> m_parameters;
0039 };
0040 
0041 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0042 
0043 SiStripConfObjectFakeESSource::SiStripConfObjectFakeESSource(const edm::ParameterSet& iConfig) {
0044   setWhatProduced(this);
0045   findingRecord<SiStripConfObjectRcd>();
0046 
0047   m_parameters = iConfig.getParameter<std::vector<edm::ParameterSet>>("Parameters");
0048 }
0049 
0050 SiStripConfObjectFakeESSource::~SiStripConfObjectFakeESSource() {}
0051 
0052 void SiStripConfObjectFakeESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0053                                                    const edm::IOVSyncValue& iov,
0054                                                    edm::ValidityInterval& iValidity) {
0055   iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
0056 }
0057 
0058 // ------------ method called to produce the data  ------------
0059 SiStripConfObjectFakeESSource::ReturnType SiStripConfObjectFakeESSource::produce(const SiStripConfObjectRcd& iRecord) {
0060   using namespace edm::es;
0061 
0062   auto confObject = std::make_unique<SiStripConfObject>();
0063 
0064   for (const auto& param : m_parameters) {
0065     const std::string paramType{param.getParameter<std::string>("ParameterType")};
0066     const std::string paramName{param.getParameter<std::string>("ParameterName")};
0067     if (paramType == "int") {
0068       confObject->put(paramName, param.getParameter<int32_t>("ParameterValue"));
0069     } else if (paramType == "double") {
0070       confObject->put(paramName, param.getParameter<double>("ParameterValue"));
0071     } else if (paramType == "string") {
0072       confObject->put(paramName, param.getParameter<std::string>("ParameterValue"));
0073     } else if (paramType == "bool") {
0074       confObject->put(paramName, param.getParameter<bool>("ParameterValue"));
0075     } else if (paramType == "vint32") {
0076       confObject->put(paramName, param.getParameter<std::vector<int>>("ParameterValue"));
0077     } else if (paramType == "vstring") {
0078       confObject->put(paramName, param.getParameter<std::vector<std::string>>("ParameterValue"));
0079     }
0080   }
0081 
0082   return confObject;
0083 }
0084 
0085 //define this as a plug-in
0086 #include "FWCore/Framework/interface/SourceFactory.h"
0087 DEFINE_FWK_EVENTSETUP_SOURCE(SiStripConfObjectFakeESSource);