CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FFTJetCorrectorDBReader.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: JetMETCorrections/FFTJetModules
4 // Class: FFTJetCorrectorDBReader
5 //
13 //
14 // Original Author: Igor Volobouev
15 // Created: Wed Aug 1 20:59:12 CDT 2012
16 //
17 //
18 
19 #include <iostream>
20 #include <sstream>
21 #include <fstream>
22 
23 #include "Alignment/Geners/interface/StringArchive.hh"
24 #include "Alignment/Geners/interface/CompressedIO.hh"
25 
32 
34 
37 
39 
40 #define init_param(type, varname) varname (ps.getParameter< type >( #varname ))
41 
42 //
43 // class declaration
44 //
46 {
47 public:
50 
51 private:
55 
56  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
57 
63 };
64 
66  : init_param(std::string, record),
68  init_param(bool, printAsString),
69  init_param(bool, readArchive),
70  init_param(bool, isArchiveCompressed)
71 {
72 }
73 
75  const edm::EventSetup& iSetup)
76 {
79  iSetup, record, JetCorParams);
80 
82  std::cout << "++++ FFTJetCorrectorDBReader: info for record \""
83  << record << '"' << std::endl;
84 
85  if (printAsString)
86  std::cout << "++++ String rep: \""
87  << JetCorParams->str() << '"' << std::endl;
88  else if (readArchive)
89  {
90  CPP11_auto_ptr<gs::StringArchive> par;
91 
92  {
93  std::istringstream is(JetCorParams->str());
95  par = gs::read_compressed_item<gs::StringArchive>(is);
96  else
97  par = gs::read_item<gs::StringArchive>(is);
98  }
99 
100  const unsigned long long idSmall = par->smallestId();
101  if (!idSmall)
102  std::cout << "++++ No valid records in the archive" << std::endl;
103  else
104  {
105  std::cout << "++++ Archive metadata begins" << std::endl;
106  const unsigned long long idLarge = par->largestId();
107  unsigned long long count = 0;
108  for (unsigned long long id = idSmall; id <= idLarge; ++id)
109  if (par->itemExists(id))
110  {
111  CPP11_shared_ptr<const gs::CatalogEntry> e =
112  par->catalogEntry(id);
113  std::cout << '\n';
114  e->humanReadable(std::cout);
115  ++count;
116  }
117  std::cout << "\n++++ Archive metadata ends, "
118  << count << " items total" << std::endl;
119  }
120  }
121 
122  if (!outputFile.empty())
123  {
124  std::ofstream of(outputFile.c_str(), std::ios_base::binary);
125  if (!of.is_open())
126  throw cms::Exception("InvalidArgument")
127  << "Failed to open file \"" << outputFile << '"' << std::endl;
128  if (!JetCorParams->empty())
129  {
130  of.write(JetCorParams->getBuffer(), JetCorParams->length());
131  if (of.fail())
132  throw cms::Exception("SystemError")
133  << "Output stream failure while writing file \""
134  << outputFile << '"' << std::endl;
135  }
136  }
137 }
138 
JetCorrectorParameters::Record record
Definition: classes.h:7
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
FFTJetCorrectorDBReader & operator=(const FFTJetCorrectorDBReader &)
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:230
#define init_param(type, varname)
tuple cout
Definition: gather_cfg.py:121
static const Mapper & instance()