CMS 3D CMS Logo

EventSetupRecordImpl.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_EventSetupRecordImpl_h
2 #define FWCore_Framework_EventSetupRecordImpl_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : EventSetupRecordImpl
7 //
45 //
46 // Author: Chris Jones
47 // Created: Fri Mar 25 14:38:35 EST 2005
48 //
49 
50 // user include files
59 
60 // system include files
61 #include <exception>
62 #include <map>
63 #include <memory>
64 #include <utility>
65 #include <vector>
66 #include <atomic>
67 #include <cassert>
68 
69 // forward declarations
70 namespace cms {
71  class Exception;
72 }
73 
74 namespace edm {
75  class ESHandleExceptionFactory;
76  class ESInputTag;
77  class EventSetupImpl;
78 
79  namespace eventsetup {
80  struct ComponentDescription;
81  class DataProxy;
82 
84  friend class EventSetupRecord;
85 
86  public:
88 
89  // ---------- const member functions ---------------------
90  ValidityInterval const& validityInterval() const { return validity_; }
91 
93  bool doGet(DataKey const& aKey, bool aGetTransiently = false) const;
94 
98  bool wasGotten(DataKey const& aKey) const;
99 
104  ComponentDescription const* providerDescription(DataKey const& aKey) const;
105 
106  EventSetupRecordKey const& key() const { return key_; }
107 
118  unsigned long long cacheIdentifier() const { return cacheIdentifier_; }
119 
121  void fillRegisteredDataKeys(std::vector<DataKey>& oToFill) const;
123  std::vector<ComponentDescription const*> componentsForRegisteredDataKeys() const;
124  // ---------- static member functions --------------------
125 
126  // ---------- member functions ---------------------------
127 
128  // The following member functions should only be used by EventSetupRecordProvider
129  bool add(DataKey const& iKey, DataProxy const* iProxy);
130  void clearProxies();
131  void cacheReset();
133  bool transientReset();
134 
135  void set(ValidityInterval const&);
136  void setEventSetup(EventSetupImpl const* iEventSetup) { eventSetup_ = iEventSetup; }
137 
138  void getESProducers(std::vector<ComponentDescription const*>& esproducers);
139  //protected:
140 
141  DataProxy const* find(DataKey const& aKey) const;
142 
143  EventSetupImpl const& eventSetup() const { return *eventSetup_; }
144 
145  void validate(ComponentDescription const*, ESInputTag const&) const;
146 
147  void addTraceInfoToCmsException(cms::Exception& iException,
148  char const* iName,
149  ComponentDescription const*,
150  DataKey const&) const;
151  void changeStdExceptionToCmsException(char const* iExceptionWhatMessage,
152  char const* iName,
153  ComponentDescription const*,
154  DataKey const&) const;
155 
156  void transientAccessRequested() const { transientAccessRequested_ = true; }
157 
158  private:
160 
161  EventSetupRecordImpl const& operator=(EventSetupRecordImpl const&) = delete;
162 
163  void const* getFromProxy(DataKey const& iKey,
164  ComponentDescription const*& iDesc,
165  bool iTransientAccessOnly) const;
166 
167  void const* getFromProxy(ESProxyIndex iProxyIndex,
168  bool iTransientAccessOnly,
169  ComponentDescription const*& iDesc,
170  DataKey const*& oGottenKey) const;
171 
172  template <typename DataT>
173  void getImplementation(DataT const*& iData,
174  char const* iName,
175  ComponentDescription const*& iDesc,
176  bool iTransientAccessOnly,
177  std::shared_ptr<ESHandleExceptionFactory>& whyFailedFactory) const {
178  DataKey dataKey(DataKey::makeTypeTag<DataT>(), iName, DataKey::kDoNotCopyMemory);
179 
180  void const* pValue = this->getFromProxy(dataKey, iDesc, iTransientAccessOnly);
181  if (nullptr == pValue) {
182  whyFailedFactory = makeESHandleExceptionFactory([=] {
183  NoProxyException<DataT> ex(this->key(), dataKey);
184  return std::make_exception_ptr(ex);
185  });
186  }
187  iData = reinterpret_cast<DataT const*>(pValue);
188  }
189 
190  template <typename DataT>
191  void getImplementation(DataT const*& iData,
192  ESProxyIndex iProxyIndex,
193  bool iTransientAccessOnly,
194  ComponentDescription const*& oDesc,
195  std::shared_ptr<ESHandleExceptionFactory>& whyFailedFactory) const {
196  DataKey const* dataKey = nullptr;
197  if (iProxyIndex.value() == std::numeric_limits<int>::max()) {
198  whyFailedFactory = makeESHandleExceptionFactory([=] {
199  NoProxyException<DataT> ex(this->key(), {});
200  return std::make_exception_ptr(ex);
201  });
202  iData = nullptr;
203  return;
204  }
205  assert(iProxyIndex.value() > -1 and
206  iProxyIndex.value() < static_cast<ESProxyIndex::Value_t>(keysForProxies_.size()));
207  void const* pValue = this->getFromProxy(iProxyIndex, iTransientAccessOnly, oDesc, dataKey);
208  if (nullptr == pValue) {
209  whyFailedFactory = makeESHandleExceptionFactory([=] {
210  NoProxyException<DataT> ex(this->key(), *dataKey);
211  return std::make_exception_ptr(ex);
212  });
213  }
214  iData = reinterpret_cast<DataT const*>(pValue);
215  }
216 
217  // ---------- member data --------------------------------
220  std::vector<DataKey> keysForProxies_;
221  std::vector<DataProxy const*> proxies_;
223  unsigned long long cacheIdentifier_;
224  mutable std::atomic<bool> transientAccessRequested_;
225  };
226  } // namespace eventsetup
227 } // namespace edm
228 #endif
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::shared_ptr< ESHandleExceptionFactory > makeESHandleExceptionFactory(T &&iFunctor)
unsigned long long cacheIdentifier() const
EventSetupImpl const & eventSetup() const
void setEventSetup(EventSetupImpl const *iEventSetup)
void getImplementation(DataT const *&iData, char const *iName, ComponentDescription const *&iDesc, bool iTransientAccessOnly, std::shared_ptr< ESHandleExceptionFactory > &whyFailedFactory) const
std::vector< DataProxy const * > proxies_
Namespace of DDCMS conversion namespace.
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
constexpr Value_t value() const noexcept
Definition: ESIndices.h:43
HLT enums.
void getImplementation(DataT const *&iData, ESProxyIndex iProxyIndex, bool iTransientAccessOnly, ComponentDescription const *&oDesc, std::shared_ptr< ESHandleExceptionFactory > &whyFailedFactory) const
ValidityInterval const & validityInterval() const
EventSetupRecordKey const & key() const