Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:57

0001 //
0002 // Toyoko Orimoto (Caltech), 10 July 2007
0003 // Andrea Massironi, 3 Aug 2019
0004 //
0005 
0006 // system include files
0007 #include <iostream>
0008 #include <fstream>
0009 #include <memory>
0010 
0011 #include "FWCore/Framework/interface/ModuleFactory.h"
0012 #include "FWCore/Framework/interface/ESProducer.h"
0013 #include "FWCore/Framework/interface/ESProductHost.h"
0014 #include "FWCore/Utilities/interface/ReusableObjectHolder.h"
0015 #include "FWCore/Framework/interface/ESHandle.h"
0016 
0017 #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbService.h"
0018 #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbRecordMC.h"
0019 
0020 #include "CondFormats/DataRecord/interface/EcalLaserAlphasRcd.h"
0021 #include "CondFormats/DataRecord/interface/EcalLaserAPDPNRatiosRefRcd.h"
0022 #include "CondFormats/DataRecord/interface/EcalLaserAPDPNRatiosMCRcd.h"
0023 #include "CondFormats/DataRecord/interface/EcalLinearCorrectionsRcd.h"
0024 
0025 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0027 
0028 class EcalLaserCorrectionServiceMC : public edm::ESProducer {
0029 public:
0030   EcalLaserCorrectionServiceMC(const edm::ParameterSet&);
0031   ~EcalLaserCorrectionServiceMC() override;
0032 
0033   std::shared_ptr<EcalLaserDbService> produce(const EcalLaserDbRecordMC&);
0034   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0035 
0036 private:
0037   using HostType = edm::ESProductHost<EcalLaserDbService,
0038                                       EcalLaserAlphasRcd,
0039                                       EcalLaserAPDPNRatiosRefRcd,
0040                                       EcalLaserAPDPNRatiosMCRcd,
0041                                       EcalLinearCorrectionsRcd>;
0042 
0043   // ----------member data ---------------------------
0044   edm::ReusableObjectHolder<HostType> holder_;
0045 
0046   edm::ESGetToken<EcalLaserAlphas, EcalLaserAlphasRcd> alphaToken_;
0047   edm::ESGetToken<EcalLaserAPDPNRatiosRef, EcalLaserAPDPNRatiosRefRcd> apdpnRefToken_;
0048   edm::ESGetToken<EcalLaserAPDPNRatios, EcalLaserAPDPNRatiosMCRcd> apdpnToken_;
0049   edm::ESGetToken<EcalLinearCorrections, EcalLinearCorrectionsRcd> linearToken_;
0050 };
0051 
0052 EcalLaserCorrectionServiceMC::EcalLaserCorrectionServiceMC(const edm::ParameterSet& fConfig) : ESProducer() {
0053   // the following line is needed to tell the framework what
0054   // data is being produced
0055   // setWhatProduced (this, (dependsOn (&EcalLaserCorrectionServiceMC::apdpnCallback)));
0056 
0057   auto cc = setWhatProduced(this);
0058   alphaToken_ = cc.consumes();
0059   apdpnRefToken_ = cc.consumes();
0060   apdpnToken_ = cc.consumes();
0061   linearToken_ = cc.consumes();
0062 
0063   //now do what ever other initialization is needed
0064 }
0065 
0066 EcalLaserCorrectionServiceMC::~EcalLaserCorrectionServiceMC() {}
0067 
0068 //
0069 // member functions
0070 //
0071 void EcalLaserCorrectionServiceMC::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0072   edm::ParameterSetDescription desc;
0073   descriptions.add("EcalLaserCorrectionServiceMC", desc);
0074 }
0075 
0076 // ------------ method called to produce the data  ------------
0077 std::shared_ptr<EcalLaserDbService> EcalLaserCorrectionServiceMC::produce(const EcalLaserDbRecordMC& record) {
0078   auto host = holder_.makeOrGet([]() { return new HostType; });
0079 
0080   host->ifRecordChanges<EcalLinearCorrectionsRcd>(
0081       record, [this, h = host.get()](auto const& rec) { h->setLinearCorrectionsData(&rec.get(linearToken_)); });
0082 
0083   host->ifRecordChanges<EcalLaserAPDPNRatiosMCRcd>(
0084       record, [this, h = host.get()](auto const& rec) { h->setAPDPNData(&rec.get(apdpnToken_)); });
0085 
0086   host->ifRecordChanges<EcalLaserAPDPNRatiosRefRcd>(
0087       record, [this, h = host.get()](auto const& rec) { h->setAPDPNRefData(&rec.get(apdpnRefToken_)); });
0088 
0089   host->ifRecordChanges<EcalLaserAlphasRcd>(
0090       record, [this, h = host.get()](auto const& rec) { h->setAlphaData(&rec.get(alphaToken_)); });
0091 
0092   return host;  // automatically converts to std::shared_ptr<EcalLaserDbService>
0093 }
0094 
0095 DEFINE_FWK_EVENTSETUP_MODULE(EcalLaserCorrectionServiceMC);