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 };
121 
122 //
123 // constructors and destructor
124 //
125 template <typename CT>
127  : tables(psIn.getParameter<std::vector<edm::ParameterSet> >("tables")),
128  isArchiveCompressed(psIn.getParameter<bool>("isArchiveCompressed")),
129  verbose(psIn.getUntrackedParameter<bool>("verbose")) {
130  // The following line is needed to tell the framework what
131  // data is being produced
132  setWhatProduced(this);
133 }
134 
135 // ------------ method called to produce the data ------------
136 template <typename CT>
138  auto host = holder_.makeOrGet([]() { return new HostType; });
139 
140  host->template ifRecordChanges<ParentRecord>(iRecord, [this, product = host.get()](auto const& rec) {
142  rec.get(parHandle);
143  buildLookupTables(*parHandle, tables, isArchiveCompressed, verbose, product);
144  });
145 
146  return host;
147 }
148 
149 //
150 // define this as a plug-in
151 //
171 
172 // =========================================================
173 
FFTJetCorrectorParameters
Definition: FFTJetCorrectorParameters.h:14
FFTLUT12TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT12 > FFTLUT12TableESProducer
Definition: FFTJetLookupTableESProducer.cc:167
taus_updatedMVAIds_cff.category
category
Definition: taus_updatedMVAIds_cff.py:31
FFTJetLookupTableESProducer::tables
std::vector< edm::ParameterSet > tables
Definition: FFTJetLookupTableESProducer.cc:114
electrons_cff.bool
bool
Definition: electrons_cff.py:393
StorableFunctorPtr
std::shared_ptr< npstat::StorableMultivariateFunctor > StorableFunctorPtr
Definition: FFTJetLookupTableESProducer.cc:42
ESTransientHandle.h
FFTJetLookupTableESProducer::ReturnType
std::shared_ptr< FFTJetLookupTableSequence > ReturnType
Definition: FFTJetLookupTableESProducer.cc:103
cmsswSequenceInfo.seq
seq
Definition: cmsswSequenceInfo.py:539
FFTJetLookupTableESProducer::~FFTJetLookupTableESProducer
~FFTJetLookupTableESProducer() override
Definition: FFTJetLookupTableESProducer.cc:108
FFTLUT3TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT3 > FFTLUT3TableESProducer
Definition: FFTJetLookupTableESProducer.cc:158
edm
HLT enums.
Definition: AlignableModifier.h:19
FFTJetLookupTableESProducer::isArchiveCompressed
bool isArchiveCompressed
Definition: FFTJetLookupTableESProducer.cc:115
FFTLUT2TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT2 > FFTLUT2TableESProducer
Definition: FFTJetLookupTableESProducer.cc:157
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
FFTLUT15TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT15 > FFTLUT15TableESProducer
Definition: FFTJetLookupTableESProducer.cc:170
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
ESProducer.h
FFTEtaFlatteningFactorsTableESProducer
FFTJetLookupTableESProducer< fftluttypes::EtaFlatteningFactors > FFTEtaFlatteningFactorsTableESProducer
Definition: FFTJetLookupTableESProducer.cc:152
FFTJetLookupTableRcd
Definition: FFTJetLookupTableRcd.h:27
FFTJetLookupTableESProducer::MyRecord
FFTJetLookupTableRcd< CT > MyRecord
Definition: FFTJetLookupTableESProducer.cc:104
postprocess-scan-build.tables
tables
Definition: postprocess-scan-build.py:10
query.host
string host
Definition: query.py:115
FFTLUT1TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT1 > FFTLUT1TableESProducer
Definition: FFTJetLookupTableESProducer.cc:156
FFTPileupRhoEtaDependenceTableESProducer
FFTJetLookupTableESProducer< fftluttypes::PileupRhoEtaDependence > FFTPileupRhoEtaDependenceTableESProducer
Definition: FFTJetLookupTableESProducer.cc:154
FFTJetLookupTableSequence.h
edm::ReusableObjectHolder< HostType >
ReusableObjectHolder.h
FFTJetDict
Definition: FFTJetDict.h:16
FFTLUT10TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT10 > FFTLUT10TableESProducer
Definition: FFTJetLookupTableESProducer.cc:165
buildLookupTables
static void buildLookupTables(const FFTJetCorrectorParameters &tablePars, const std::vector< edm::ParameterSet > &tableDefs, const bool isArchiveCompressed, const bool verbose, FFTJetLookupTableSequence *ptr)
Definition: FFTJetLookupTableESProducer.cc:54
verbose
static constexpr int verbose
Definition: HLTExoticaSubAnalysis.cc:25
FFTJetLookupTableESProducer::verbose
bool verbose
Definition: FFTJetLookupTableESProducer.cc:116
FFTLUT9TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT9 > FFTLUT9TableESProducer
Definition: FFTJetLookupTableESProducer.cc:164
FFTLUT6TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT6 > FFTLUT6TableESProducer
Definition: FFTJetLookupTableESProducer.cc:161
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FFTJetCorrectorParameters.h
FFTLUT13TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT13 > FFTLUT13TableESProducer
Definition: FFTJetLookupTableESProducer.cc:168
edm::ParameterSet
Definition: ParameterSet.h:47
ParameterSet
Definition: Functions.h:16
FFTPileupRhoCalibrationTableESProducer
FFTJetLookupTableESProducer< fftluttypes::PileupRhoCalibration > FFTPileupRhoCalibrationTableESProducer
Definition: FFTJetLookupTableESProducer.cc:153
FFTJetLookupTableESProducer::holder_
edm::ReusableObjectHolder< HostType > holder_
Definition: FFTJetLookupTableESProducer.cc:119
FFTLUT7TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT7 > FFTLUT7TableESProducer
Definition: FFTJetLookupTableESProducer.cc:162
FFTJetCorrectorParameters::str
const std::string & str() const
Definition: FFTJetCorrectorParameters.h:23
FFTLUT8TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT8 > FFTLUT8TableESProducer
Definition: FFTJetLookupTableESProducer.cc:163
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
FFTJetLookupTableESProducer::produce
ReturnType produce(const MyRecord &)
Definition: FFTJetLookupTableESProducer.cc:137
FFTLUT0TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT0 > FFTLUT0TableESProducer
Definition: FFTJetLookupTableESProducer.cc:155
edm::ESTransientHandle
Definition: ESTransientHandle.h:41
FFTLUT4TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT4 > FFTLUT4TableESProducer
Definition: FFTJetLookupTableESProducer.cc:159
ModuleFactory.h
edm::ESProductHost
Definition: ESProductHost.h:93
FFTLUT11TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT11 > FFTLUT11TableESProducer
Definition: FFTJetLookupTableESProducer.cc:166
std
Definition: JetResolutionObject.h:76
DEFINE_FWK_EVENTSETUP_MODULE
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
FFTJetLUTTypes.h
FFTJetLookupTableRcd.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
FFTJetLookupTableESProducer::FFTJetLookupTableESProducer
FFTJetLookupTableESProducer(const edm::ParameterSet &)
Definition: FFTJetLookupTableESProducer.cc:126
FFTJetLookupTableESProducer
Definition: FFTJetLookupTableESProducer.cc:101
edm::ESProducer
Definition: ESProducer.h:104
ESProductHost.h
FFTLUT5TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT5 > FFTLUT5TableESProducer
Definition: FFTJetLookupTableESProducer.cc:160
FFTLUT14TableESProducer
FFTJetLookupTableESProducer< fftluttypes::LUT14 > FFTLUT14TableESProducer
Definition: FFTJetLookupTableESProducer.cc:169
FFTJetLookupTableESProducer::ParentRecord
FFTJetCorrectorParametersRcd< CT > ParentRecord
Definition: FFTJetLookupTableESProducer.cc:105
insertLUTItem
static void insertLUTItem(FFTJetLookupTableSequence &seq, StorableFunctorPtr fptr, const std::string &name, const std::string &category)
Definition: FFTJetLookupTableESProducer.cc:44
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
FFTJetCorrectorParametersRcd
Definition: FFTJetCorrectorParametersRcd.h:25