Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-06 04:00:40

0001 // Author: S├ębastien Brochet
0002 
0003 #include <memory>
0004 #include <string>
0005 #include <fstream>
0006 #include <iostream>
0007 #include "FWCore/Framework/interface/Frameworkfwd.h"
0008 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/ServiceRegistry/interface/Service.h"
0013 #include "FWCore/Utilities/interface/EDMException.h"
0014 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0015 #include "CondFormats/JetMETObjects/interface/JetResolutionObject.h"
0016 
0017 class JetResolutionDBWriter : public edm::one::EDAnalyzer<> {
0018 public:
0019   JetResolutionDBWriter(const edm::ParameterSet&);
0020   void beginJob() override;
0021   void analyze(const edm::Event&, const edm::EventSetup&) override {}
0022   void endJob() override {}
0023   ~JetResolutionDBWriter() override {}
0024 
0025 private:
0026   std::string m_record;
0027   std::string m_path;
0028 };
0029 
0030 // Constructor
0031 JetResolutionDBWriter::JetResolutionDBWriter(const edm::ParameterSet& pSet) {
0032   m_record = pSet.getUntrackedParameter<std::string>("record");
0033   m_path = pSet.getUntrackedParameter<edm::FileInPath>("file").fullPath();
0034 }
0035 
0036 // Begin Job
0037 void JetResolutionDBWriter::beginJob() {
0038   std::cout << "Loading data from '" << m_path << "'" << std::endl;
0039 
0040   const JME::JetResolutionObject jerObject(m_path);
0041 
0042   std::cout << "Opening PoolDBOutputService" << std::endl;
0043 
0044   // now write it into the DB
0045   edm::Service<cond::service::PoolDBOutputService> s;
0046   if (s.isAvailable()) {
0047     std::cout << "Setting up payload record " << m_record << std::endl;
0048     cond::Time_t sinceTime = s->isNewTagRequest(m_record) ? s->beginOfTime() : s->currentTime();
0049     s->writeOneIOV(jerObject, sinceTime, m_record);
0050 
0051     std::cout << "Object saved into the database with the record: " << m_record << std::endl;
0052   }
0053 }
0054 
0055 DEFINE_FWK_MODULE(JetResolutionDBWriter);