CMS 3D CMS Logo

FFTJetRcdMapper.h
Go to the documentation of this file.
1 #ifndef JetMETCorrections_FFTJetObjects_FFTJetRcdMapper_h
2 #define JetMETCorrections_FFTJetObjects_FFTJetRcdMapper_h
3 
4 //
5 // A factory to combat the proliferation of ES record types
6 // (multiple record types are necessary due to deficiencies
7 // in the record dependency tracking mechanism). Templated
8 // upon the data type which records hold.
9 //
10 // Igor Volobouev
11 // 08/03/2012
12 
13 #include <map>
14 #include <string>
15 
19 
20 template <class DataType>
22  virtual ~AbsFFTJetRcdMapper() {}
23 
24  virtual void load(const edm::EventSetup& iSetup, edm::ESHandle<DataType>& handle) const = 0;
25 
26  virtual void load(const edm::EventSetup& iSetup, const std::string& label, edm::ESHandle<DataType>& handle) const = 0;
27 };
28 
29 template <class DataType, class RecordType>
30 struct ConcreteFFTJetRcdMapper : public AbsFFTJetRcdMapper<DataType> {
32 
33  inline void load(const edm::EventSetup& iSetup, edm::ESHandle<DataType>& handle) const override {
34  iSetup.get<RecordType>().get(handle);
35  }
36 
37  inline void load(const edm::EventSetup& iSetup,
38  const std::string& label,
39  edm::ESHandle<DataType>& handle) const override {
40  iSetup.get<RecordType>().get(label, handle);
41  }
42 };
43 
44 template <class DataType>
45 struct DefaultFFTJetRcdMapper : public std::map<std::string, AbsFFTJetRcdMapper<DataType>*> {
47 
49 
51  for (typename std::map<std::string, AbsFFTJetRcdMapper<DataType>*>::iterator it = this->begin(); it != this->end();
52  ++it)
53  delete it->second;
54  }
55 
56  inline void load(const edm::EventSetup& iSetup, const std::string& record, edm::ESHandle<DataType>& handle) const {
57  typename std::map<std::string, AbsFFTJetRcdMapper<DataType>*>::const_iterator it = this->find(record);
58  if (it == this->end())
59  throw cms::Exception("KeyNotFound") << "Record \"" << record << "\" is not registered\n";
60  it->second->load(iSetup, handle);
61  }
62 
63  inline void load(const edm::EventSetup& iSetup,
64  const std::string& record,
65  const std::string& label,
67  typename std::map<std::string, AbsFFTJetRcdMapper<DataType>*>::const_iterator it = this->find(record);
68  if (it == this->end())
69  throw cms::Exception("KeyNotFound") << "Record \"" << record << "\" is not registered\n";
70  it->second->load(iSetup, label, handle);
71  }
72 
73 private:
75  DefaultFFTJetRcdMapper& operator=(const DefaultFFTJetRcdMapper&) = delete;
76 };
77 
78 //
79 // Singleton for the mapper
80 //
81 template <class Mapper>
83 public:
84  typedef typename Mapper::Base::data_type data_type;
85 
86  static const Mapper& instance() {
87  static Mapper obj;
88  return obj;
89  }
90 
91  template <class Record>
92  static void registerRecord(const std::string& record) {
93  Mapper& rd = const_cast<Mapper&>(instance());
94  delete rd[record];
96  }
97 
98 private:
99  StaticFFTJetRcdMapper() = delete;
100 };
101 
102 #endif // JetMETCorrections_FFTJetObjects_FFTJetRcdMapper_h
JetCorrectorParameters::Record record
Definition: classes.h:7
static PFTauRenderPlugin instance
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
virtual ~DefaultFFTJetRcdMapper()
void load(const edm::EventSetup &iSetup, const std::string &label, edm::ESHandle< DataType > &handle) const override
char const * label
static void registerRecord(const std::string &record)
virtual void load(const edm::EventSetup &iSetup, edm::ESHandle< DataType > &handle) const =0
Mapper::Base::data_type data_type
#define end
Definition: vmac.h:39
Definition: DDLMap.cc:41
virtual ~AbsFFTJetRcdMapper()
void load(const edm::EventSetup &iSetup, const std::string &record, edm::ESHandle< DataType > &handle) const
void load(const edm::EventSetup &iSetup, edm::ESHandle< DataType > &handle) const override
#define begin
Definition: vmac.h:32
T get() const
Definition: EventSetup.h:73
~ConcreteFFTJetRcdMapper() override
static const Mapper & instance()
void load(const edm::EventSetup &iSetup, const std::string &record, const std::string &label, edm::ESHandle< DataType > &handle) const