Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-31 23:51:03

0001 #ifndef CondTools_Hcal_BoostIODBWriter_h
0002 #define CondTools_Hcal_BoostIODBWriter_h
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:    CondTools/Hcal
0007 // Class:      BoostIODBWriter
0008 //
0009 /**\class BoostIODBWriter BoostIODBWriter.h CondTools/Hcal/interface/BoostIODBWriter.h
0010 
0011  Description: writes a boost I/O blob from a file into a database
0012 
0013  Implementation:
0014      [Notes on implementation]
0015 */
0016 //
0017 // Original Author:  Igor Volobouev
0018 //         Created:  Fri Apr 25 17:58:33 CDT 2014
0019 //
0020 //
0021 
0022 #include <string>
0023 #include <fstream>
0024 #include <memory>
0025 #include <cassert>
0026 
0027 #include "CondFormats/Serialization/interface/eos/portable_iarchive.hpp"
0028 
0029 #include "FWCore/Framework/interface/Frameworkfwd.h"
0030 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0031 #include "FWCore/Framework/interface/Event.h"
0032 
0033 #include "FWCore/Utilities/interface/Exception.h"
0034 
0035 #include "FWCore/ServiceRegistry/interface/Service.h"
0036 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0037 
0038 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0039 
0040 //
0041 // class declaration
0042 //
0043 template <class DataType>
0044 class BoostIODBWriter : public edm::one::EDAnalyzer<> {
0045 public:
0046   typedef DataType data_type;
0047 
0048   explicit BoostIODBWriter(const edm::ParameterSet&);
0049   inline ~BoostIODBWriter() override {}
0050 
0051 private:
0052   void analyze(const edm::Event&, const edm::EventSetup&) override;
0053 
0054   std::string inputFile_;
0055   std::string record_;
0056 };
0057 
0058 template <class DataType>
0059 BoostIODBWriter<DataType>::BoostIODBWriter(const edm::ParameterSet& ps)
0060     : inputFile_(ps.getParameter<std::string>("inputFile")), record_(ps.getParameter<std::string>("record")) {}
0061 
0062 template <class DataType>
0063 void BoostIODBWriter<DataType>::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0064   std::ifstream is(inputFile_.c_str(), std::ios_base::binary);
0065   if (!is.is_open())
0066     throw cms::Exception("InvalidArgument") << "Failed to open file \"" << inputFile_ << '"' << std::endl;
0067 
0068   std::unique_ptr<DataType> datum(new DataType());
0069   eos::portable_iarchive ar(is);
0070   ar&* datum;
0071 
0072   edm::Service<cond::service::PoolDBOutputService> poolDbService;
0073   if (poolDbService.isAvailable())
0074     poolDbService->writeOneIOV(*datum, poolDbService->currentTime(), record_);
0075   else
0076     throw cms::Exception("ConfigurationError") << "PoolDBOutputService is not available, "
0077                                                << "please configure it properly" << std::endl;
0078 }
0079 
0080 #endif  // CondTools_Hcal_BoostIODBWriter_h