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:
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
DefaultFFTJetRcdMapper::load
void load(const edm::EventSetup &iSetup, const std::string &record, const std::string &label, edm::ESHandle< DataType > &handle) const
Definition: FFTJetRcdMapper.h:63
HLT_2018_cff.DataType
DataType
Definition: HLT_2018_cff.py:31313
StaticFFTJetRcdMapper::registerRecord
static void registerRecord(const std::string &record)
Definition: FFTJetRcdMapper.h:92
ESHandle.h
patZpeak.handle
handle
Definition: patZpeak.py:23
AbsFFTJetRcdMapper::~AbsFFTJetRcdMapper
virtual ~AbsFFTJetRcdMapper()
Definition: FFTJetRcdMapper.h:22
DefaultFFTJetRcdMapper::load
void load(const edm::EventSetup &iSetup, const std::string &record, edm::ESHandle< DataType > &handle) const
Definition: FFTJetRcdMapper.h:56
DefaultFFTJetRcdMapper::operator=
DefaultFFTJetRcdMapper & operator=(const DefaultFFTJetRcdMapper &)=delete
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
DefaultFFTJetRcdMapper::data_type
DataType data_type
Definition: FFTJetRcdMapper.h:46
StaticFFTJetRcdMapper::StaticFFTJetRcdMapper
StaticFFTJetRcdMapper()=delete
DefaultFFTJetRcdMapper::DefaultFFTJetRcdMapper
DefaultFFTJetRcdMapper()
Definition: FFTJetRcdMapper.h:48
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
Mapper
Definition: DDLMap.cc:41
end
#define end
Definition: vmac.h:39
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
StaticFFTJetRcdMapper
Definition: FFTJetRcdMapper.h:82
ConcreteFFTJetRcdMapper
Definition: FFTJetRcdMapper.h:30
edm::ESHandle
Definition: DTSurvey.h:22
ConcreteFFTJetRcdMapper::load
void load(const edm::EventSetup &iSetup, const std::string &label, edm::ESHandle< DataType > &handle) const override
Definition: FFTJetRcdMapper.h:37
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DefaultFFTJetRcdMapper::~DefaultFFTJetRcdMapper
virtual ~DefaultFFTJetRcdMapper()
Definition: FFTJetRcdMapper.h:50
StaticFFTJetRcdMapper::instance
static const Mapper & instance()
Definition: FFTJetRcdMapper.h:86
StaticFFTJetRcdMapper::data_type
Mapper::Base::data_type data_type
Definition: FFTJetRcdMapper.h:84
edm::EventSetup
Definition: EventSetup.h:57
ConcreteFFTJetRcdMapper::~ConcreteFFTJetRcdMapper
~ConcreteFFTJetRcdMapper() override
Definition: FFTJetRcdMapper.h:31
get
#define get
DefaultFFTJetRcdMapper
Definition: FFTJetRcdMapper.h:45
std
Definition: JetResolutionObject.h:76
ConcreteFFTJetRcdMapper::load
void load(const edm::EventSetup &iSetup, edm::ESHandle< DataType > &handle) const override
Definition: FFTJetRcdMapper.h:33
Exception
Definition: hltDiff.cc:246
AbsFFTJetRcdMapper
Definition: FFTJetRcdMapper.h:21
EventSetup.h
Exception.h
genParticles_cff.map
map
Definition: genParticles_cff.py:11
begin
#define begin
Definition: vmac.h:32
label
const char * label
Definition: PFTauDecayModeTools.cc:11
AbsFFTJetRcdMapper::load
virtual void load(const edm::EventSetup &iSetup, edm::ESHandle< DataType > &handle) const =0