CMS 3D CMS Logo

BoostIODBWriter.h
Go to the documentation of this file.
1 #ifndef CondTools_Hcal_BoostIODBWriter_h
2 #define CondTools_Hcal_BoostIODBWriter_h
3 
4 // -*- C++ -*-
5 //
6 // Package: CondTools/Hcal
7 // Class: BoostIODBWriter
8 //
16 //
17 // Original Author: Igor Volobouev
18 // Created: Fri Apr 25 17:58:33 CDT 2014
19 //
20 //
21 
22 #include <string>
23 #include <fstream>
24 #include <memory>
25 #include <cassert>
26 
28 #include "CondFormats/Serialization/interface/eos/portable_iarchive.hpp"
35 
36 //
37 // class declaration
38 //
39 template <class DataType>
40 class BoostIODBWriter : public edm::one::EDAnalyzer<edm::one::SharedResources> {
41 public:
43 
44  explicit BoostIODBWriter(const edm::ParameterSet&);
45  inline ~BoostIODBWriter() override {}
46 
47 private:
48  void analyze(const edm::Event&, const edm::EventSetup&) override;
49 
52 };
53 
54 template <class DataType>
56  : inputFile_(ps.getParameter<std::string>("inputFile")), record_(ps.getParameter<std::string>("record")) {
58 }
59 
60 template <class DataType>
62  std::ifstream is(inputFile_.c_str(), std::ios_base::binary);
63  if (!is.is_open())
64  throw cms::Exception("InvalidArgument") << "Failed to open file \"" << inputFile_ << '"' << std::endl;
65 
66  std::unique_ptr<DataType> datum(new DataType());
67  eos::portable_iarchive ar(is);
68  ar&* datum;
69 
71  if (poolDbService.isAvailable())
72  poolDbService->writeOneIOV(*datum, poolDbService->currentTime(), record_);
73  else
74  throw cms::Exception("ConfigurationError") << "PoolDBOutputService is not available, "
75  << "please configure it properly" << std::endl;
76 }
77 
78 #endif // CondTools_Hcal_BoostIODBWriter_h
void analyze(const edm::Event &, const edm::EventSetup &) override
std::string inputFile_
int iEvent
Definition: GenABIO.cc:224
std::string record_
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
BoostIODBWriter(const edm::ParameterSet &)
~BoostIODBWriter() override
static const std::string kSharedResource
bool isAvailable() const
Definition: Service.h:40