CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FFTJetLookupTableESProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: JetMETCorrections/FFTJetModules
4 // Class: FFTJetLookupTableESProducer
5 //
13 //
14 // Original Author: Igor Volobouev
15 // Created: Thu Aug 2 22:34:02 CDT 2012
16 //
17 //
18 
19 
20 // system include files
21 #include <sstream>
22 #include <utility>
23 
24 #include "boost/shared_ptr.hpp"
25 
26 #include "Alignment/Geners/interface/CompressedIO.hh"
27 #include "Alignment/Geners/interface/StringArchive.hh"
28 #include "Alignment/Geners/interface/Reference.hh"
29 
30 // user include files
34 
37 
40 
41 typedef boost::shared_ptr<npstat::StorableMultivariateFunctor> StorableFunctorPtr;
42 
44  StorableFunctorPtr fptr,
45  const std::string& name,
46  const std::string& category)
47 {
48  FFTJetLookupTableSequence::iterator it = seq.find(category);
49  if (it == seq.end())
50  it = seq.insert(std::make_pair(
52  it->second.insert(std::make_pair(name, fptr));
53 }
54 
55 static boost::shared_ptr<FFTJetLookupTableSequence>
57  const FFTJetCorrectorParameters& tablePars,
58  const std::vector<edm::ParameterSet>& tableDefs,
59  const bool isArchiveCompressed, const bool verbose)
60 {
61  // Load the archive stored in the FFTJetCorrectorParameters object
62  CPP11_auto_ptr<gs::StringArchive> ar;
63  {
64  std::istringstream is(tablePars.str());
65  if (isArchiveCompressed)
66  ar = gs::read_compressed_item<gs::StringArchive>(is);
67  else
68  ar = gs::read_item<gs::StringArchive>(is);
69  }
70 
71  boost::shared_ptr<FFTJetLookupTableSequence> ptr(
73 
74  // Avoid loading the same item more than once
75  std::set<unsigned long long> loadedSet;
76 
77  const unsigned nTables = tableDefs.size();
78  for (unsigned itab=0; itab<nTables; ++itab)
79  {
80  const edm::ParameterSet& ps(tableDefs[itab]);
81  gs::SearchSpecifier nameSearch(ps.getParameter<std::string>("name"),
82  ps.getParameter<bool>("nameIsRegex"));
83  gs::SearchSpecifier categorySearch(ps.getParameter<std::string>("category"),
84  ps.getParameter<bool>("categoryIsRegex"));
85  gs::Reference<npstat::StorableMultivariateFunctor> ref(
86  *ar, nameSearch, categorySearch);
87  const unsigned long nItems = ref.size();
88  for (unsigned long item=0; item<nItems; ++item)
89  {
90  const unsigned long long id = ref.id(item);
91  if (loadedSet.insert(id).second)
92  {
93  CPP11_auto_ptr<npstat::StorableMultivariateFunctor> p(ref.get(item));
94  StorableFunctorPtr fptr(p.release());
95  CPP11_shared_ptr<const gs::CatalogEntry> e = ar->catalogEntry(id);
96  insertLUTItem(*ptr, fptr, e->name(), e->category());
97  if (verbose)
98  std::cout << "In buildLookupTables: loaded table with name \""
99  << e->name() << "\" and category \""
100  << e->category() << '"' << std::endl;
101  }
102  }
103  }
104 
105  return ptr;
106 }
107 
108 //
109 // class declaration
110 //
111 template<typename CT>
113 {
114 public:
115  typedef boost::shared_ptr<FFTJetLookupTableSequence> ReturnType;
118 
121 
122  ReturnType produce(const MyRecord&);
123 
124 private:
125  inline void doWhenChanged(const ParentRecord&)
126  {remakeProduct = true;}
127 
128  // Module parameters
129  std::vector<edm::ParameterSet> tables;
131  bool verbose;
132 
133  // Other module variables
136 };
137 
138 //
139 // constructors and destructor
140 //
141 template<typename CT>
143  const edm::ParameterSet& psIn)
144  : tables(psIn.getParameter<std::vector<edm::ParameterSet> >("tables")),
145  isArchiveCompressed(psIn.getParameter<bool>("isArchiveCompressed")),
146  verbose(psIn.getUntrackedParameter<bool>("verbose")),
147  remakeProduct(true)
148 {
149  // The following line is needed to tell the framework what
150  // data is being produced
152 }
153 
154 // ------------ method called to produce the data ------------
155 template<typename CT>
158 {
159  if (remakeProduct)
160  {
161  // According to:
162  // https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideHowToGetDependentRecord
163  //
164  // If ARecord is dependent on BRecord then you can
165  // call the method getRecord of ARecord:
166  //
167  // const BRecord& b = aRecord.getRecord<BRecord>();
168  //
169  const ParentRecord& rec = iRecord.template getRecord<ParentRecord>();
171  rec.get(parHandle);
172  product = buildLookupTables(
173  *parHandle, tables, isArchiveCompressed, verbose);
174  remakeProduct = false;
175  }
176  return product;
177 }
178 
179 //
180 // define this as a plug-in
181 //
201 
202 // =========================================================
203 
void doWhenChanged(const ParentRecord &)
static boost::shared_ptr< FFTJetLookupTableSequence > buildLookupTables(const FFTJetCorrectorParameters &tablePars, const std::vector< edm::ParameterSet > &tableDefs, const bool isArchiveCompressed, const bool verbose)
T getParameter(std::string const &) const
depends_on::OneHolder< T, TDependsOnRecord > dependsOn(void(T::*iT)(const TDependsOnRecord &))
FFTJetLookupTableESProducer< fftluttypes::LUT3 > FFTLUT3TableESProducer
boost::shared_ptr< FFTJetLookupTableSequence > ReturnType
const std::string & str() const
FFTJetLookupTableESProducer< fftluttypes::LUT12 > FFTLUT12TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT15 > FFTLUT15TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT9 > FFTLUT9TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT2 > FFTLUT2TableESProducer
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
tuple tables
Definition: dataDML.py:2338
FFTJetLookupTableESProducer< fftluttypes::EtaFlatteningFactors > FFTEtaFlatteningFactorsTableESProducer
boost::shared_ptr< npstat::StorableMultivariateFunctor > StorableFunctorPtr
std::vector< edm::ParameterSet > tables
FFTJetLookupTableESProducer< fftluttypes::LUT4 > FFTLUT4TableESProducer
void get(HolderT &iHolder) const
FFTJetLookupTableESProducer< fftluttypes::LUT10 > FFTLUT10TableESProducer
ReturnType produce(const MyRecord &)
FFTJetLookupTableESProducer< fftluttypes::LUT1 > FFTLUT1TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT14 > FFTLUT14TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT13 > FFTLUT13TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT5 > FFTLUT5TableESProducer
FFTJetDict< std::string, FFTJetDict< std::string, boost::shared_ptr< npstat::StorableMultivariateFunctor > > > FFTJetLookupTableSequence
FFTJetLookupTableESProducer< fftluttypes::LUT6 > FFTLUT6TableESProducer
FFTJetLookupTableESProducer< fftluttypes::PileupRhoEtaDependence > FFTPileupRhoEtaDependenceTableESProducer
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
FFTJetCorrectorParametersRcd< CT > ParentRecord
static void insertLUTItem(FFTJetLookupTableSequence &seq, StorableFunctorPtr fptr, const std::string &name, const std::string &category)
FFTJetLookupTableESProducer< fftluttypes::LUT8 > FFTLUT8TableESProducer
FFTJetLookupTableESProducer< fftluttypes::PileupRhoCalibration > FFTPileupRhoCalibrationTableESProducer
tuple cout
Definition: gather_cfg.py:145
FFTJetLookupTableESProducer< fftluttypes::LUT7 > FFTLUT7TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT0 > FFTLUT0TableESProducer
FFTJetLookupTableESProducer(const edm::ParameterSet &)
FFTJetLookupTableESProducer< fftluttypes::LUT11 > FFTLUT11TableESProducer