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 
27 #include "CondFormats/Serialization/interface/eos/portable_iarchive.hpp"
28 
32 
34 
37 
39 
40 //
41 // class declaration
42 //
43 template<class DataType>
45 {
46 public:
48 
49  explicit BoostIODBWriter(const edm::ParameterSet&);
50  inline virtual ~BoostIODBWriter() {}
51 
52 private:
53  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
54 
57 };
58 
59 template<class DataType>
61  : inputFile_(ps.getParameter<std::string>("inputFile")),
62  record_(ps.getParameter<std::string>("record"))
63 {
64 }
65 
66 template<class DataType>
68  const edm::EventSetup& iSetup)
69 {
70  std::ifstream is(inputFile_.c_str(), std::ios_base::binary);
71  if (!is.is_open())
72  throw cms::Exception("InvalidArgument")
73  << "Failed to open file \"" << inputFile_ << '"' << std::endl;
74 
75  std::unique_ptr<DataType> datum(new DataType());
76  eos::portable_iarchive ar(is);
77  ar & *datum;
78 
80  if (poolDbService.isAvailable())
81  poolDbService->writeOne(datum.release(),
82  poolDbService->currentTime(),
83  record_);
84  else
85  throw cms::Exception("ConfigurationError")
86  << "PoolDBOutputService is not available, "
87  << "please configure it properly" << std::endl;
88 }
89 
90 #endif // CondTools_Hcal_BoostIODBWriter_h
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
std::string inputFile_
int iEvent
Definition: GenABIO.cc:230
std::string record_
bool isAvailable() const
Definition: Service.h:46
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
BoostIODBWriter(const edm::ParameterSet &)
virtual ~BoostIODBWriter()