test
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 <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
35 
38 
41 
42 typedef boost::shared_ptr<npstat::StorableMultivariateFunctor> StorableFunctorPtr;
43 
45  StorableFunctorPtr fptr,
46  const std::string& name,
47  const std::string& category)
48 {
49  FFTJetLookupTableSequence::iterator it = seq.find(category);
50  if (it == seq.end())
51  it = seq.insert(std::make_pair(
53  it->second.insert(std::make_pair(name, fptr));
54 }
55 
56 static std::shared_ptr<FFTJetLookupTableSequence>
58  const FFTJetCorrectorParameters& tablePars,
59  const std::vector<edm::ParameterSet>& tableDefs,
60  const bool isArchiveCompressed, const bool verbose)
61 {
62  // Load the archive stored in the FFTJetCorrectorParameters object
63  CPP11_auto_ptr<gs::StringArchive> ar;
64  {
65  std::istringstream is(tablePars.str());
66  if (isArchiveCompressed)
67  ar = gs::read_compressed_item<gs::StringArchive>(is);
68  else
69  ar = gs::read_item<gs::StringArchive>(is);
70  }
71 
72  auto ptr = std::make_shared<FFTJetLookupTableSequence>();
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 std::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 &)
T getParameter(std::string const &) const
depends_on::OneHolder< T, TDependsOnRecord > dependsOn(void(T::*iT)(const TDependsOnRecord &))
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
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
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
static std::shared_ptr< FFTJetLookupTableSequence > buildLookupTables(const FFTJetCorrectorParameters &tablePars, const std::vector< edm::ParameterSet > &tableDefs, const bool isArchiveCompressed, const bool verbose)
FFTJetLookupTableESProducer(const edm::ParameterSet &)
FFTJetLookupTableESProducer< fftluttypes::LUT11 > FFTLUT11TableESProducer