CMS 3D CMS Logo

BufferedBoostIODBWriter.cc
Go to the documentation of this file.
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <unistd.h>
4 
5 #include <cassert>
6 #include <fstream>
7 
12 
15 
18 
19 //
20 // class declaration
21 //
23 {
24 public:
27 
28 private:
29  BufferedBoostIODBWriter() = delete;
32 
33  void analyze(const edm::Event&, const edm::EventSetup&) override;
34 
37 };
38 
40  : inputFile(ps.getParameter<std::string>("inputFile")),
41  record(ps.getParameter<std::string>("record"))
42 {
43 }
44 
46  const edm::EventSetup& iSetup)
47 {
48  std::auto_ptr<OOTPileupCorrectionBuffer> fcp;
49 
50  {
51  std::ifstream input(inputFile.c_str(), std::ios_base::binary);
52  if (!input.is_open())
53  throw cms::Exception("InvalidArgument")
54  << "Failed to open file \"" << inputFile << '"' << std::endl;
55 
56  struct stat st;
57  if (stat(inputFile.c_str(), &st))
58  throw cms::Exception("SystemError")
59  << "Failed to stat file \"" << inputFile << '"' << std::endl;
60 
61  const std::size_t len = st.st_size;
62  fcp = std::auto_ptr<OOTPileupCorrectionBuffer>(
63  new OOTPileupCorrectionBuffer(len));
64  assert(fcp->length() == len);
65  if (len)
66  input.read(fcp->getBuffer(), len);
67  if (input.fail())
68  throw cms::Exception("SystemError")
69  << "Input stream failure while reading file \""
70  << inputFile << '"' << std::endl;
71  }
72 
74  if (poolDbService.isAvailable())
75  poolDbService->writeOne(fcp.release(),
76  poolDbService->currentTime(),
77  record);
78  else
79  throw cms::Exception("ConfigurationError")
80  << "PoolDBOutputService is not available, "
81  << "please configure it properly" << std::endl;
82 }
83 
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static std::string const input
Definition: EdmProvDump.cc:44
int iEvent
Definition: GenABIO.cc:230
bool isAvailable() const
Definition: Service.h:46
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
BufferedBoostIODBWriter & operator=(const BufferedBoostIODBWriter &)=delete
BufferedBoostIODBWriter()=delete
void analyze(const edm::Event &, const edm::EventSetup &) override