CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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:
52 
53  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
54 
57 };
58 
60  : init_param(std::string, inputFile),
61  init_param(std::string, record)
62 {
63 }
64 
66  const edm::EventSetup& iSetup)
67 {
68  std::auto_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::auto_ptr<FFTJetCorrectorParameters>(
83  new FFTJetCorrectorParameters(len));
84  assert(fcp->length() == len);
85  if (len)
86  input.read(fcp->getBuffer(), len);
87  if (input.fail())
88  throw cms::Exception("SystemError")
89  << "Input stream failure while reading file \""
90  << inputFile << '"' << std::endl;
91  }
92 
94  if (poolDbService.isAvailable())
95  poolDbService->writeOne(fcp.release(),
96  poolDbService->currentTime(),
97  record);
98  else
99  throw cms::Exception("ConfigurationError")
100  << "PoolDBOutputService is not available, "
101  << "please configure it properly" << std::endl;
102 }
103 
#define init_param(type, varname)
JetCorrectorParameters::Record record
Definition: classes.h:7
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
assert(m_qm.get())
static std::string const input
Definition: EdmProvDump.cc:43
int iEvent
Definition: GenABIO.cc:230
FFTJetCorrectorDBWriter & operator=(const FFTJetCorrectorDBWriter &)
bool isAvailable() const
Definition: Service.h:46
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
virtual void analyze(const edm::Event &, const edm::EventSetup &) override