CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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>*> {
46  typedef DataType data_type;
47 
48  inline DefaultFFTJetRcdMapper() : std::map<std::string, AbsFFTJetRcdMapper<DataType>*>() {}
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 
75 };
76 
77 //
78 // Singleton for the mapper
79 //
80 template <class Mapper>
82 public:
84 
85  static const Mapper& instance() {
86  static Mapper obj;
87  return obj;
88  }
89 
90  template <class Record>
91  static void registerRecord(const std::string& record) {
92  Mapper& rd = const_cast<Mapper&>(instance());
93  delete rd[record];
95  }
96 
97  StaticFFTJetRcdMapper() = delete;
98 };
99 
100 #endif // JetMETCorrections_FFTJetObjects_FFTJetRcdMapper_h
DefaultFFTJetRcdMapper & operator=(const DefaultFFTJetRcdMapper &)=delete
::ecal::reco::ComputationScalarType data_type
void load(const edm::EventSetup &iSetup, const std::string &label, edm::ESHandle< DataType > &handle) const override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
virtual ~DefaultFFTJetRcdMapper()
char const * label
static void registerRecord(const std::string &record)
virtual void load(const edm::EventSetup &iSetup, edm::ESHandle< DataType > &handle) const =0
tuple handle
Definition: patZpeak.py:23
Mapper::Base::data_type data_type
StaticFFTJetRcdMapper()=delete
Definition: DDLMap.cc:41
virtual ~AbsFFTJetRcdMapper()
void load(const edm::EventSetup &iSetup, const std::string &record, edm::ESHandle< DataType > &handle) const
T get() const
Definition: EventSetup.h:88
string end
Definition: dataset.py:937
void load(const edm::EventSetup &iSetup, edm::ESHandle< DataType > &handle) const override
~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