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 // $Id: FFTJetLookupTableESProducer.cc,v 1.1 2012/11/14 22:34:57 igv Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <sstream>
23 #include <utility>
24 
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 boost::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  boost::shared_ptr<FFTJetLookupTableSequence> ptr(
74 
75  // Avoid loading the same item more than once
76  std::set<unsigned long long> loadedSet;
77 
78  const unsigned nTables = tableDefs.size();
79  for (unsigned itab=0; itab<nTables; ++itab)
80  {
81  const edm::ParameterSet& ps(tableDefs[itab]);
82  gs::SearchSpecifier nameSearch(ps.getParameter<std::string>("name"),
83  ps.getParameter<bool>("nameIsRegex"));
84  gs::SearchSpecifier categorySearch(ps.getParameter<std::string>("category"),
85  ps.getParameter<bool>("categoryIsRegex"));
86  gs::Reference<npstat::StorableMultivariateFunctor> ref(
87  *ar, nameSearch, categorySearch);
88  const unsigned long nItems = ref.size();
89  for (unsigned long item=0; item<nItems; ++item)
90  {
91  const unsigned long long id = ref.id(item);
92  if (loadedSet.insert(id).second)
93  {
94  CPP11_auto_ptr<npstat::StorableMultivariateFunctor> p(ref.get(item));
95  StorableFunctorPtr fptr(p.release());
96  CPP11_shared_ptr<const gs::CatalogEntry> e = ar->catalogEntry(id);
97  insertLUTItem(*ptr, fptr, e->name(), e->category());
98  if (verbose)
99  std::cout << "In buildLookupTables: loaded table with name \""
100  << e->name() << "\" and category \""
101  << e->category() << '"' << std::endl;
102  }
103  }
104  }
105 
106  return ptr;
107 }
108 
109 //
110 // class declaration
111 //
112 template<typename CT>
114 {
115 public:
116  typedef boost::shared_ptr<FFTJetLookupTableSequence> ReturnType;
119 
122 
123  ReturnType produce(const MyRecord&);
124 
125 private:
126  inline void doWhenChanged(const ParentRecord&)
127  {remakeProduct = true;}
128 
129  // Module parameters
130  std::vector<edm::ParameterSet> tables;
132  bool verbose;
133 
134  // Other module variables
137 };
138 
139 //
140 // constructors and destructor
141 //
142 template<typename CT>
144  const edm::ParameterSet& psIn)
145  : tables(psIn.getParameter<std::vector<edm::ParameterSet> >("tables")),
146  isArchiveCompressed(psIn.getParameter<bool>("isArchiveCompressed")),
147  verbose(psIn.getUntrackedParameter<bool>("verbose")),
148  remakeProduct(true)
149 {
150  // The following line is needed to tell the framework what
151  // data is being produced
153 }
154 
155 // ------------ method called to produce the data ------------
156 template<typename CT>
159 {
160  if (remakeProduct)
161  {
162  // According to:
163  // https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideHowToGetDependentRecord
164  //
165  // If ARecord is dependent on BRecord then you can
166  // call the method getRecord of ARecord:
167  //
168  // const BRecord& b = aRecord.getRecord<BRecord>();
169  //
170  const ParentRecord& rec = iRecord.template getRecord<ParentRecord>();
172  rec.get(parHandle);
173  product = buildLookupTables(
174  *parHandle, tables, isArchiveCompressed, verbose);
175  remakeProduct = false;
176  }
177  return product;
178 }
179 
180 //
181 // define this as a plug-in
182 //
202 
203 // =========================================================
204 
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:2329
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:121
FFTJetLookupTableESProducer< fftluttypes::LUT7 > FFTLUT7TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT0 > FFTLUT0TableESProducer
FFTJetLookupTableESProducer(const edm::ParameterSet &)
FFTJetLookupTableESProducer< fftluttypes::LUT11 > FFTLUT11TableESProducer