Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:00

0001 //
0002 // Toyoko Orimoto (Caltech), 10 July 2007
0003 // Fabrice Couderc, 16 March 2020 (add protection for extrapolation if t > t3 + delta t : t = t3 + delta t
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/EcalLaserDbRecord.h"
0019 
0020 #include "CondFormats/DataRecord/interface/EcalLaserAlphasRcd.h"
0021 #include "CondFormats/DataRecord/interface/EcalLaserAPDPNRatiosRefRcd.h"
0022 #include "CondFormats/DataRecord/interface/EcalLaserAPDPNRatiosRcd.h"
0023 #include "CondFormats/DataRecord/interface/EcalLinearCorrectionsRcd.h"
0024 
0025 class EcalLaserCorrectionService : public edm::ESProducer {
0026 public:
0027   EcalLaserCorrectionService(const edm::ParameterSet&);
0028   ~EcalLaserCorrectionService() override;
0029 
0030   std::shared_ptr<EcalLaserDbService> produce(const EcalLaserDbRecord&);
0031   static void fillDescriptions(edm::ConfigurationDescriptions&);
0032 
0033 private:
0034   using HostType = edm::ESProductHost<EcalLaserDbService,
0035                                       EcalLaserAlphasRcd,
0036                                       EcalLaserAPDPNRatiosRefRcd,
0037                                       EcalLaserAPDPNRatiosRcd,
0038                                       EcalLinearCorrectionsRcd>;
0039 
0040   // ----------member data ---------------------------
0041   edm::ReusableObjectHolder<HostType> holder_;
0042 
0043   edm::ESGetToken<EcalLaserAlphas, EcalLaserAlphasRcd> alphaToken_;
0044   edm::ESGetToken<EcalLaserAPDPNRatiosRef, EcalLaserAPDPNRatiosRefRcd> apdpnRefToken_;
0045   edm::ESGetToken<EcalLaserAPDPNRatios, EcalLaserAPDPNRatiosRcd> apdpnToken_;
0046   edm::ESGetToken<EcalLinearCorrections, EcalLinearCorrectionsRcd> linearToken_;
0047 
0048   int maxExtrapolationTimeInSec_;
0049 
0050   //  std::vector<std::string> mDumpRequest;
0051   //  std::ostream* mDumpStream;
0052 };
0053 
0054 EcalLaserCorrectionService::EcalLaserCorrectionService(const edm::ParameterSet& fConfig)
0055     : ESProducer()
0056 //    mDumpRequest (),
0057 //    mDumpStream(0)
0058 {
0059   //the following line is needed to tell the framework what
0060   // data is being produced
0061   //  setWhatProduced (this, (dependsOn (&EcalLaserCorrectionService::apdpnCallback)));
0062 
0063   auto cc = setWhatProduced(this);
0064   alphaToken_ = cc.consumes();
0065   apdpnRefToken_ = cc.consumes();
0066   apdpnToken_ = cc.consumes();
0067   linearToken_ = cc.consumes();
0068 
0069   maxExtrapolationTimeInSec_ = fConfig.getParameter<unsigned int>("maxExtrapolationTimeInSec");
0070 
0071   //now do what ever other initialization is needed
0072 
0073   //  mDumpRequest = fConfig.getUntrackedParameter <std::vector <std::string> > ("dump", std::vector<std::string>());
0074   //  if (!mDumpRequest.empty()) {
0075   //    std::string otputFile = fConfig.getUntrackedParameter <std::string> ("file", "");
0076   //    mDumpStream = otputFile.empty () ? &std::cout : new std::ofstream (otputFile.c_str());
0077   //  }
0078 }
0079 
0080 EcalLaserCorrectionService::~EcalLaserCorrectionService() {
0081   // do anything here that needs to be done at desctruction time
0082   // (e.g. close files, deallocate resources etc.)
0083   //  if (mDumpStream != &std::cout) delete mDumpStream;
0084 }
0085 
0086 //
0087 // member functions
0088 //
0089 
0090 // ------------ method called to produce the data  ------------
0091 std::shared_ptr<EcalLaserDbService> EcalLaserCorrectionService::produce(const EcalLaserDbRecord& record) {
0092   auto host = holder_.makeOrGet([]() { return new HostType; });
0093 
0094   host.get()->setMaxExtrapolationTimeInSec(maxExtrapolationTimeInSec_);
0095 
0096   host->ifRecordChanges<EcalLinearCorrectionsRcd>(
0097       record, [this, h = host.get()](auto const& rec) { h->setLinearCorrectionsData(&rec.get(linearToken_)); });
0098 
0099   host->ifRecordChanges<EcalLaserAPDPNRatiosRcd>(
0100       record, [this, h = host.get()](auto const& rec) { h->setAPDPNData(&rec.get(apdpnToken_)); });
0101 
0102   host->ifRecordChanges<EcalLaserAPDPNRatiosRefRcd>(
0103       record, [this, h = host.get()](auto const& rec) { h->setAPDPNRefData(&rec.get(apdpnRefToken_)); });
0104 
0105   host->ifRecordChanges<EcalLaserAlphasRcd>(
0106       record, [this, h = host.get()](auto const& rec) { h->setAlphaData(&rec.get(alphaToken_)); });
0107 
0108   return host;  // automatically converts to std::shared_ptr<EcalLaserDbService>
0109 }
0110 
0111 void EcalLaserCorrectionService::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0112   edm::ParameterSetDescription desc;
0113   desc.add<unsigned int>("maxExtrapolationTimeInSec", 0);
0114   descriptions.add("EcalLaserCorrectionService", desc);
0115 }
0116 
0117 DEFINE_FWK_EVENTSETUP_MODULE(EcalLaserCorrectionService);