CMS 3D CMS Logo

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 <memory>
25 #include "boost/shared_ptr.hpp"
26 
27 #include "Alignment/Geners/interface/CompressedIO.hh"
28 #include "Alignment/Geners/interface/StringArchive.hh"
29 #include "Alignment/Geners/interface/Reference.hh"
30 
31 // user include files
37 
40 
43 
44 typedef boost::shared_ptr<npstat::StorableMultivariateFunctor> StorableFunctorPtr;
45 
47  StorableFunctorPtr fptr,
48  const std::string& name,
49  const std::string& category)
50 {
51  FFTJetLookupTableSequence::iterator it = seq.find(category);
52  if (it == seq.end())
53  it = seq.insert(std::make_pair(
55  it->second.insert(std::make_pair(name, fptr));
56 }
57 
58 static void
60  const FFTJetCorrectorParameters& tablePars,
61  const std::vector<edm::ParameterSet>& tableDefs,
62  const bool isArchiveCompressed, const bool verbose,
64 {
65  // Load the archive stored in the FFTJetCorrectorParameters object
66  CPP11_auto_ptr<gs::StringArchive> ar;
67  {
68  std::istringstream is(tablePars.str());
69  if (isArchiveCompressed)
70  ar = gs::read_compressed_item<gs::StringArchive>(is);
71  else
72  ar = gs::read_item<gs::StringArchive>(is);
73  }
74 
75  ptr->clear();
76 
77  // Avoid loading the same item more than once
78  std::set<unsigned long long> loadedSet;
79 
80  const unsigned nTables = tableDefs.size();
81  for (unsigned itab=0; itab<nTables; ++itab)
82  {
83  const edm::ParameterSet& ps(tableDefs[itab]);
84  gs::SearchSpecifier nameSearch(ps.getParameter<std::string>("name"),
85  ps.getParameter<bool>("nameIsRegex"));
86  gs::SearchSpecifier categorySearch(ps.getParameter<std::string>("category"),
87  ps.getParameter<bool>("categoryIsRegex"));
88  gs::Reference<npstat::StorableMultivariateFunctor> ref(
89  *ar, nameSearch, categorySearch);
90  const unsigned long nItems = ref.size();
91  for (unsigned long item=0; item<nItems; ++item)
92  {
93  const unsigned long long id = ref.id(item);
94  if (loadedSet.insert(id).second)
95  {
96  CPP11_auto_ptr<npstat::StorableMultivariateFunctor> p(ref.get(item));
97  StorableFunctorPtr fptr(p.release());
98  CPP11_shared_ptr<const gs::CatalogEntry> e = ar->catalogEntry(id);
99  insertLUTItem(*ptr, fptr, e->name(), e->category());
100  if (verbose)
101  std::cout << "In buildLookupTables: loaded table with name \""
102  << e->name() << "\" and category \""
103  << e->category() << '"' << std::endl;
104  }
105  }
106  }
107 }
108 
109 //
110 // class declaration
111 //
112 template<typename CT>
114 {
115 public:
116  typedef std::shared_ptr<FFTJetLookupTableSequence> ReturnType;
119 
122 
123  ReturnType produce(const MyRecord&);
124 
125 private:
126 
127  // Module parameters
128  std::vector<edm::ParameterSet> tables;
130  bool verbose;
131 
133  ParentRecord>;
135 };
136 
137 //
138 // constructors and destructor
139 //
140 template<typename CT>
142  const edm::ParameterSet& psIn)
143  : tables(psIn.getParameter<std::vector<edm::ParameterSet> >("tables")),
144  isArchiveCompressed(psIn.getParameter<bool>("isArchiveCompressed")),
145  verbose(psIn.getUntrackedParameter<bool>("verbose"))
146 {
147  // The following line is needed to tell the framework what
148  // data is being produced
149  setWhatProduced(this);
150 }
151 
152 // ------------ method called to produce the data ------------
153 template<typename CT>
156 {
157  auto host = holder_.makeOrGet([]() {
158  return new HostType;
159  });
160 
161  host->template ifRecordChanges<ParentRecord>(iRecord,
162  [this,product=host.get()](auto const& rec) {
164  rec.get(parHandle);
165  buildLookupTables(*parHandle, tables, isArchiveCompressed, verbose, product);
166  });
167 
168  return host;
169 }
170 
171 //
172 // define this as a plug-in
173 //
193 
194 // =========================================================
195 
T getParameter(std::string const &) const
host
Definition: query.py:115
FFTJetLookupTableESProducer< fftluttypes::LUT3 > FFTLUT3TableESProducer
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
std::shared_ptr< FFTJetLookupTableSequence > ReturnType
FFTJetLookupTableESProducer< fftluttypes::EtaFlatteningFactors > FFTEtaFlatteningFactorsTableESProducer
boost::shared_ptr< npstat::StorableMultivariateFunctor > StorableFunctorPtr
std::vector< edm::ParameterSet > tables
edm::ReusableObjectHolder< HostType > holder_
FFTJetLookupTableESProducer< fftluttypes::LUT4 > FFTLUT4TableESProducer
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 buildLookupTables(const FFTJetCorrectorParameters &tablePars, const std::vector< edm::ParameterSet > &tableDefs, const bool isArchiveCompressed, const bool verbose, FFTJetLookupTableSequence *ptr)
static void insertLUTItem(FFTJetLookupTableSequence &seq, StorableFunctorPtr fptr, const std::string &name, const std::string &category)
FFTJetLookupTableESProducer< fftluttypes::LUT8 > FFTLUT8TableESProducer
HLT enums.
FFTJetLookupTableESProducer< fftluttypes::PileupRhoCalibration > FFTPileupRhoCalibrationTableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT7 > FFTLUT7TableESProducer
edm::ESProductHost< FFTJetLookupTableSequence, ParentRecord > HostType
FFTJetLookupTableESProducer< fftluttypes::LUT0 > FFTLUT0TableESProducer
FFTJetLookupTableESProducer(const edm::ParameterSet &)
FFTJetLookupTableESProducer< fftluttypes::LUT11 > FFTLUT11TableESProducer