CMS 3D CMS Logo

FFTJetCorrectorDBWriter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: JetMETCorrections/FFTJetModules
4 // Class: FFTJetCorrectorDBWriter
5 //
13 //
14 // Original Author: Igor Volobouev
15 // Created: Wed Aug 1 20:59:12 CDT 2012
16 //
17 //
18 
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <unistd.h>
22 
23 #include <cassert>
24 #include <fstream>
25 
30 
33 
36 
37 #define init_param(type, varname) varname (ps.getParameter< type >( #varname ))
38 
39 //
40 // class declaration
41 //
43 {
44 public:
47 
48 private:
49  FFTJetCorrectorDBWriter() = delete;
52 
53  void analyze(const edm::Event&, const edm::EventSetup&) override;
54 
57 };
58 
62 {
63 }
64 
66  const edm::EventSetup& iSetup)
67 {
68  std::unique_ptr<FFTJetCorrectorParameters> fcp;
69 
70  {
71  std::ifstream input(inputFile.c_str(), std::ios_base::binary);
72  if (!input.is_open())
73  throw cms::Exception("InvalidArgument")
74  << "Failed to open file \"" << inputFile << '"' << std::endl;
75 
76  struct stat st;
77  if (stat(inputFile.c_str(), &st))
78  throw cms::Exception("SystemError")
79  << "Failed to stat file \"" << inputFile << '"' << std::endl;
80 
81  const std::size_t len = st.st_size;
82  fcp = std::make_unique<FFTJetCorrectorParameters>(len);
83  assert(fcp->length() == len);
84  if (len)
85  input.read(fcp->getBuffer(), len);
86  if (input.fail())
87  throw cms::Exception("SystemError")
88  << "Input stream failure while reading file \""
89  << inputFile << '"' << std::endl;
90  }
91 
93  if (poolDbService.isAvailable())
94  poolDbService->writeOne(fcp.release(),
95  poolDbService->currentTime(),
96  record);
97  else
98  throw cms::Exception("ConfigurationError")
99  << "PoolDBOutputService is not available, "
100  << "please configure it properly" << std::endl;
101 }
102 
#define init_param(type, varname)
static std::string const input
Definition: EdmProvDump.cc:48
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool isAvailable() const
Definition: Service.h:40
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
FFTJetCorrectorDBWriter & operator=(const FFTJetCorrectorDBWriter &)=delete
FFTJetCorrectorDBWriter()=delete
void analyze(const edm::Event &, const edm::EventSetup &) override