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 // system include files
20 #include <sstream>
21 #include <utility>
22 
23 #include <memory>
24 
25 #include "Alignment/Geners/interface/CompressedIO.hh"
26 #include "Alignment/Geners/interface/StringArchive.hh"
27 #include "Alignment/Geners/interface/Reference.hh"
28 
29 // user include files
35 
38 
41 
42 typedef std::shared_ptr<npstat::StorableMultivariateFunctor> StorableFunctorPtr;
43 
45  StorableFunctorPtr fptr,
46  const std::string& name,
47  const std::string& category) {
48  FFTJetLookupTableSequence::iterator it = seq.find(category);
49  if (it == seq.end())
50  it = seq.insert(std::make_pair(category, FFTJetDict<std::string, StorableFunctorPtr>())).first;
51  it->second.insert(std::make_pair(name, fptr));
52 }
53 
54 static void buildLookupTables(const FFTJetCorrectorParameters& tablePars,
55  const std::vector<edm::ParameterSet>& tableDefs,
56  const bool isArchiveCompressed,
57  const bool verbose,
59  // Load the archive stored in the FFTJetCorrectorParameters object
60  CPP11_auto_ptr<gs::StringArchive> ar;
61  {
62  std::istringstream is(tablePars.str());
63  if (isArchiveCompressed)
64  ar = gs::read_compressed_item<gs::StringArchive>(is);
65  else
66  ar = gs::read_item<gs::StringArchive>(is);
67  }
68 
69  ptr->clear();
70 
71  // Avoid loading the same item more than once
72  std::set<unsigned long long> loadedSet;
73 
74  const unsigned nTables = tableDefs.size();
75  for (unsigned itab = 0; itab < nTables; ++itab) {
76  const edm::ParameterSet& ps(tableDefs[itab]);
77  gs::SearchSpecifier nameSearch(ps.getParameter<std::string>("name"), ps.getParameter<bool>("nameIsRegex"));
78  gs::SearchSpecifier categorySearch(ps.getParameter<std::string>("category"),
79  ps.getParameter<bool>("categoryIsRegex"));
80  gs::Reference<npstat::StorableMultivariateFunctor> ref(*ar, nameSearch, categorySearch);
81  const unsigned long nItems = ref.size();
82  for (unsigned long item = 0; item < nItems; ++item) {
83  const unsigned long long id = ref.id(item);
84  if (loadedSet.insert(id).second) {
85  CPP11_auto_ptr<npstat::StorableMultivariateFunctor> p(ref.get(item));
86  StorableFunctorPtr fptr(p.release());
87  std::shared_ptr<const gs::CatalogEntry> e = ar->catalogEntry(id);
88  insertLUTItem(*ptr, fptr, e->name(), e->category());
89  if (verbose)
90  std::cout << "In buildLookupTables: loaded table with name \"" << e->name() << "\" and category \""
91  << e->category() << '"' << std::endl;
92  }
93  }
94  }
95 }
96 
97 //
98 // class declaration
99 //
100 template <typename CT>
102 public:
103  typedef std::shared_ptr<FFTJetLookupTableSequence> ReturnType;
106 
109 
110  ReturnType produce(const MyRecord&);
111 
112 private:
113  // Module parameters
114  std::vector<edm::ParameterSet> tables;
116  bool verbose;
117 
120 
122 };
123 
124 //
125 // constructors and destructor
126 //
127 template <typename CT>
129  : tables(psIn.getParameter<std::vector<edm::ParameterSet> >("tables")),
130  isArchiveCompressed(psIn.getParameter<bool>("isArchiveCompressed")),
131  verbose(psIn.getUntrackedParameter<bool>("verbose")) {
132  // The following line is needed to tell the framework what
133  // data is being produced
134  auto cc = setWhatProduced(this);
135  token_ = cc.consumes();
136 }
137 
138 // ------------ method called to produce the data ------------
139 template <typename CT>
141  auto host = holder_.makeOrGet([]() { return new HostType; });
142 
143  host->template ifRecordChanges<ParentRecord>(iRecord, [this, product = host.get()](auto const& rec) {
144  edm::ESTransientHandle<FFTJetCorrectorParameters> parHandle = rec.getTransientHandle(token_);
145  buildLookupTables(*parHandle, tables, isArchiveCompressed, verbose, product);
146  });
147 
148  return host;
149 }
150 
151 //
152 // define this as a plug-in
153 //
173 
174 // =========================================================
175 
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
edm::ESGetToken< FFTJetCorrectorParameters, ParentRecord > token_
FFTJetLookupTableESProducer< fftluttypes::LUT3 > FFTLUT3TableESProducer
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
string host
Definition: query.py:115
bool verbose
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
FFTJetLookupTableESProducer< fftluttypes::LUT12 > FFTLUT12TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT15 > FFTLUT15TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT9 > FFTLUT9TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT2 > FFTLUT2TableESProducer
std::shared_ptr< FFTJetLookupTableSequence > ReturnType
FFTJetLookupTableESProducer< fftluttypes::EtaFlatteningFactors > FFTEtaFlatteningFactorsTableESProducer
std::vector< edm::ParameterSet > tables
edm::ReusableObjectHolder< HostType > holder_
std::shared_ptr< npstat::StorableMultivariateFunctor > StorableFunctorPtr
FFTJetLookupTableESProducer< fftluttypes::LUT4 > FFTLUT4TableESProducer
const std::string & str() const
FFTJetLookupTableESProducer< fftluttypes::LUT10 > FFTLUT10TableESProducer
ReturnType produce(const MyRecord &)
FFTJetLookupTableESProducer< fftluttypes::LUT1 > FFTLUT1TableESProducer
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:61
FFTJetLookupTableESProducer< fftluttypes::LUT14 > FFTLUT14TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT13 > FFTLUT13TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT5 > FFTLUT5TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT6 > FFTLUT6TableESProducer
FFTJetLookupTableESProducer< fftluttypes::PileupRhoEtaDependence > FFTPileupRhoEtaDependenceTableESProducer
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
FFTJetLookupTableESProducer< fftluttypes::LUT0 > FFTLUT0TableESProducer
FFTJetLookupTableESProducer(const edm::ParameterSet &)
FFTJetLookupTableESProducer< fftluttypes::LUT11 > FFTLUT11TableESProducer