File indexing completed on 2024-04-06 12:03:06
0001 #ifndef CondTools_Hcal_BoostIODBWriter_h
0002 #define CondTools_Hcal_BoostIODBWriter_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <string>
0023 #include <fstream>
0024 #include <memory>
0025 #include <cassert>
0026
0027 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0028 #include "CondFormats/Serialization/interface/eos/portable_iarchive.hpp"
0029 #include "FWCore/Framework/interface/Event.h"
0030 #include "FWCore/Framework/interface/Frameworkfwd.h"
0031 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "FWCore/ServiceRegistry/interface/Service.h"
0034 #include "FWCore/Utilities/interface/Exception.h"
0035
0036
0037
0038
0039 template <class DataType>
0040 class BoostIODBWriter : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0041 public:
0042 typedef DataType data_type;
0043
0044 explicit BoostIODBWriter(const edm::ParameterSet&);
0045 inline ~BoostIODBWriter() override {}
0046
0047 private:
0048 void analyze(const edm::Event&, const edm::EventSetup&) override;
0049
0050 std::string inputFile_;
0051 std::string record_;
0052 };
0053
0054 template <class DataType>
0055 BoostIODBWriter<DataType>::BoostIODBWriter(const edm::ParameterSet& ps)
0056 : inputFile_(ps.getParameter<std::string>("inputFile")), record_(ps.getParameter<std::string>("record")) {
0057 usesResource(cond::service::PoolDBOutputService::kSharedResource);
0058 }
0059
0060 template <class DataType>
0061 void BoostIODBWriter<DataType>::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0062 std::ifstream is(inputFile_.c_str(), std::ios_base::binary);
0063 if (!is.is_open())
0064 throw cms::Exception("InvalidArgument") << "Failed to open file \"" << inputFile_ << '"' << std::endl;
0065
0066 std::unique_ptr<DataType> datum(new DataType());
0067 eos::portable_iarchive ar(is);
0068 ar&* datum;
0069
0070 edm::Service<cond::service::PoolDBOutputService> poolDbService;
0071 if (poolDbService.isAvailable())
0072 poolDbService->writeOneIOV(*datum, poolDbService->currentTime(), record_);
0073 else
0074 throw cms::Exception("ConfigurationError") << "PoolDBOutputService is not available, "
0075 << "please configure it properly" << std::endl;
0076 }
0077
0078 #endif