Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-11 04:33:32

0001 #ifndef CalibTracker_SiStripESProducer_DummyCondDBWriter_h
0002 #define CalibTracker_SiStripESProducer_DummyCondDBWriter_h
0003 
0004 // user include files
0005 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0006 #include "FWCore/Framework/interface/ESWatcher.h"
0007 #include "FWCore/Framework/interface/Run.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/ServiceRegistry/interface/Service.h"
0012 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0013 
0014 #include "FWCore/Utilities/interface/Exception.h"
0015 
0016 #include <string>
0017 
0018 template <typename TObject, typename TObjectO, typename TRecord>
0019 class DummyCondDBWriter : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0020 public:
0021   explicit DummyCondDBWriter(const edm::ParameterSet& iConfig);
0022   ~DummyCondDBWriter() override;
0023   void analyze(const edm::Event& e, const edm::EventSetup& es) override{};
0024   void beginRun(const edm::Run& run, const edm::EventSetup& es) override{};
0025   void endRun(const edm::Run& run, const edm::EventSetup& es) override;
0026 
0027 private:
0028   edm::ParameterSet iConfig_;
0029   edm::ESWatcher<TRecord> watcher_;
0030   edm::ESGetToken<TObject, TRecord> token_;
0031 };
0032 
0033 template <typename TObject, typename TObjectO, typename TRecord>
0034 DummyCondDBWriter<TObject, TObjectO, TRecord>::DummyCondDBWriter(const edm::ParameterSet& iConfig)
0035     : iConfig_(iConfig),
0036       token_(esConsumes<edm::Transition::EndRun>(
0037           edm::ESInputTag{"", iConfig.getUntrackedParameter<std::string>("label", "")})) {
0038   edm::LogInfo("DummyCondDBWriter") << "DummyCondDBWriter constructor for typename " << typeid(TObject).name()
0039                                     << " and record " << typeid(TRecord).name() << std::endl;
0040 }
0041 
0042 template <typename TObject, typename TObjectO, typename TRecord>
0043 DummyCondDBWriter<TObject, TObjectO, TRecord>::~DummyCondDBWriter() {
0044   edm::LogInfo("DummyCondDBWriter") << "DummyCondDBWriter::~DummyCondDBWriter()" << std::endl;
0045 }
0046 
0047 template <typename TObject, typename TObjectO, typename TRecord>
0048 void DummyCondDBWriter<TObject, TObjectO, TRecord>::endRun(const edm::Run& run, const edm::EventSetup& es) {
0049   std::string rcdName = iConfig_.getParameter<std::string>("record");
0050 
0051   if (!watcher_.check(es)) {
0052     edm::LogInfo("DummyCondDBWriter") << "not needed to store objects with Record " << rcdName << " at run "
0053                                       << run.run() << std::endl;
0054     return;
0055   }
0056 
0057   auto obj = std::make_unique<TObjectO>(es.getData(token_));
0058   cond::Time_t Time_;
0059 
0060   //And now write  data in DB
0061   edm::Service<cond::service::PoolDBOutputService> dbservice;
0062   if (dbservice.isAvailable()) {
0063     std::string openIovAt = iConfig_.getUntrackedParameter<std::string>("OpenIovAt", "beginOfTime");
0064     if (openIovAt == "beginOfTime")
0065       Time_ = dbservice->beginOfTime();
0066     else if (openIovAt == "currentTime")
0067       Time_ = dbservice->currentTime();
0068     else
0069       Time_ = iConfig_.getUntrackedParameter<uint32_t>("OpenIovAtTime", 1);
0070 
0071     dbservice->writeOneIOV(*obj, Time_, rcdName);
0072   } else {
0073     edm::LogError("SiStripFedCablingBuilder") << "Service is unavailable" << std::endl;
0074   }
0075 }
0076 
0077 #endif