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 
21 
22 template <class DataType>
24  virtual ~AbsFFTJetRcdMapper() {}
25 
26  virtual void acquireToken(edm::ConsumesCollector iC) = 0;
27 
28  virtual void acquireToken(edm::ConsumesCollector iC, const std::string& label) = 0;
29 
30  virtual edm::ESHandle<DataType> load(const edm::EventSetup& iSetup) const = 0;
31 };
32 
33 template <class DataType, class RecordType>
34 class ConcreteFFTJetRcdMapper : public AbsFFTJetRcdMapper<DataType> {
35 public:
37 
38  inline void acquireToken(edm::ConsumesCollector iC) override {
39  if (tokenAcquired_)
40  throw cms::Exception("ESGetTokenAlreadyAcquired");
41  token_ = iC.esConsumes<DataType, RecordType>();
42  tokenAcquired_ = true;
43  }
44 
45  inline void acquireToken(edm::ConsumesCollector iC, const std::string& label) override {
46  if (tokenAcquired_)
47  throw cms::Exception("ESGetTokenAlreadyAcquired");
48  token_ = iC.esConsumes<DataType, RecordType>(edm::ESInputTag("", label));
49  tokenAcquired_ = true;
50  }
51 
52  inline edm::ESHandle<DataType> load(const edm::EventSetup& iSetup) const override {
53  if (!tokenAcquired_)
54  throw cms::Exception("ESGetTokenNotAcquired");
55  return iSetup.getHandle(token_);
56  }
57 
58 private:
60  bool tokenAcquired_ = false;
61 };
62 
63 template <class DataType>
64 struct DefaultFFTJetRcdMapper : public std::map<std::string, AbsFFTJetRcdMapper<DataType>*> {
66 
68 
70  for (typename std::map<std::string, AbsFFTJetRcdMapper<DataType>*>::iterator it = this->begin(); it != this->end();
71  ++it)
72  delete it->second;
73  }
74 
76  typename std::map<std::string, AbsFFTJetRcdMapper<DataType>*>::iterator it = this->find(record);
77  if (it == this->end())
78  throw cms::Exception("KeyNotFound") << "Record \"" << record << "\" is not registered\n";
79  it->second->acquireToken(iC);
80  }
81 
83  typename std::map<std::string, AbsFFTJetRcdMapper<DataType>*>::iterator it = this->find(record);
84  if (it == this->end())
85  throw cms::Exception("KeyNotFound") << "Record \"" << record << "\" is not registered\n";
86  it->second->acquireToken(iC, label);
87  }
88 
89  inline edm::ESHandle<DataType> load(const std::string& record, const edm::EventSetup& iSetup) const {
90  typename std::map<std::string, AbsFFTJetRcdMapper<DataType>*>::const_iterator it = this->find(record);
91  if (it == this->end())
92  throw cms::Exception("KeyNotFound") << "Record \"" << record << "\" is not registered\n";
93  return it->second->load(iSetup);
94  }
95 
98 };
99 
100 #endif // JetMETCorrections_FFTJetObjects_FFTJetRcdMapper_h
edm::ESHandle< DataType > load(const edm::EventSetup &iSetup) const override
DefaultFFTJetRcdMapper & operator=(const DefaultFFTJetRcdMapper &)=delete
edm::ESHandle< DataType > load(const std::string &record, const edm::EventSetup &iSetup) const
virtual edm::ESHandle< DataType > load(const edm::EventSetup &iSetup) const =0
void acquireToken(const std::string &record, edm::ConsumesCollector iC, const std::string &label)
edm::ESGetToken< DataType, RecordType > token_
~ConcreteFFTJetRcdMapper() override
void acquireToken(edm::ConsumesCollector iC, const std::string &label) override
void acquireToken(const std::string &record, edm::ConsumesCollector iC)
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
void acquireToken(edm::ConsumesCollector iC) override
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
virtual ~AbsFFTJetRcdMapper()
virtual void acquireToken(edm::ConsumesCollector iC)=0