CMS 3D CMS Logo

EventSetupRecord.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_EventSetupRecord_h
2 #define FWCore_Framework_EventSetupRecord_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : EventSetupRecord
7 //
45 //
46 // Author: Chris Jones
47 // Created: Fri Mar 25 14:38:35 EST 2005
48 //
49 
50 // user include files
60 
61 // system include files
62 #include <exception>
63 #include <map>
64 #include <memory>
65 #include <utility>
66 #include <vector>
67 #include <atomic>
68 #include <cassert>
69 #include <limits>
70 
71 // forward declarations
72 namespace cms {
73  class Exception;
74 }
75 
76 class testEventsetup;
77 class testEventsetupRecord;
78 
79 namespace edm {
80  template <typename T>
81  class ESHandle;
82  class ESHandleExceptionFactory;
83  class ESInputTag;
84  class EventSetupImpl;
85 
86  namespace eventsetup {
87  struct ComponentDescription;
88  class DataProxy;
89  class EventSetupRecordKey;
90 
92  friend class ::testEventsetup;
93  friend class ::testEventsetupRecord;
94 
95  public:
98  EventSetupRecord& operator=(EventSetupRecord&&) = default;
99 
100  EventSetupRecord(EventSetupRecord const&) = default;
101  EventSetupRecord& operator=(EventSetupRecord const&) = default;
102  virtual ~EventSetupRecord();
103 
104  // ---------- const member functions ---------------------
105  ValidityInterval const& validityInterval() const { return impl_->validityInterval(); }
106 
107  void setImpl(EventSetupRecordImpl const* iImpl, unsigned int transitionID, ESProxyIndex const* getTokenIndices) {
108  impl_ = iImpl;
109  transitionID_ = transitionID;
110  getTokenIndices_ = getTokenIndices;
111  }
112 
113  template <typename HolderT>
114  bool get(HolderT& iHolder) const {
115  return get("", iHolder);
116  }
117 
118  template <typename HolderT>
119  bool get(char const* iName, HolderT& iHolder) const {
120  typename HolderT::value_type const* value = nullptr;
121  ComponentDescription const* desc = nullptr;
122  std::shared_ptr<ESHandleExceptionFactory> whyFailedFactory;
123  impl_->getImplementation(value, iName, desc, iHolder.transientAccessOnly, whyFailedFactory);
124 
125  if (value) {
126  iHolder = HolderT(value, desc);
127  return true;
128  } else {
129  iHolder = HolderT(std::move(whyFailedFactory));
130  return false;
131  }
132  }
133  template <typename HolderT>
134  bool get(std::string const& iName, HolderT& iHolder) const {
135  return get(iName.c_str(), iHolder);
136  }
137 
138  template <typename HolderT>
139  bool get(ESInputTag const& iTag, HolderT& iHolder) const {
140  typename HolderT::value_type const* value = nullptr;
141  ComponentDescription const* desc = nullptr;
142  std::shared_ptr<ESHandleExceptionFactory> whyFailedFactory;
143  impl_->getImplementation(value, iTag.data().c_str(), desc, iHolder.transientAccessOnly, whyFailedFactory);
144 
145  if (value) {
146  validate(desc, iTag);
147  iHolder = HolderT(value, desc);
148  return true;
149  } else {
150  iHolder = HolderT(std::move(whyFailedFactory));
151  return false;
152  }
153  }
154 
156  bool doGet(DataKey const& aKey, bool aGetTransiently = false) const;
157 
161  bool wasGotten(DataKey const& aKey) const;
162 
167  ComponentDescription const* providerDescription(DataKey const& aKey) const;
168 
169  virtual EventSetupRecordKey key() const = 0;
170 
181  unsigned long long cacheIdentifier() const { return impl_->cacheIdentifier(); }
182 
184  void fillRegisteredDataKeys(std::vector<DataKey>& oToFill) const { impl_->fillRegisteredDataKeys(oToFill); }
185 
186  protected:
187  template <template <typename> typename H, typename T, typename R>
188  H<T> getHandleImpl(ESGetToken<T, R> const& iToken) const {
189  assert(iToken.transitionID() == transitionID());
190  assert(iToken.isInitialized());
191  assert(getTokenIndices_);
192  //need to check token has valid index
193  if
194  UNLIKELY(not iToken.hasValidIndex()) { return invalidTokenHandle<H>(iToken); }
195 
196  auto proxyIndex = getTokenIndices_[iToken.index().value()];
197  if
198  UNLIKELY(proxyIndex.value() == std::numeric_limits<int>::max()) { return noProxyHandle<H>(iToken); }
199 
200  T const* value = nullptr;
201  ComponentDescription const* desc = nullptr;
202  std::shared_ptr<ESHandleExceptionFactory> whyFailedFactory;
203  impl_->getImplementation(value, proxyIndex, H<T>::transientAccessOnly, desc, whyFailedFactory);
204 
205  if
206  UNLIKELY(not value) { return H<T>(std::move(whyFailedFactory)); }
207  return H<T>(value, desc);
208  }
209 
210  DataProxy const* find(DataKey const& aKey) const;
211 
212  EventSetupImpl const& eventSetup() const { return impl_->eventSetup(); }
213 
214  ESProxyIndex const* getTokenIndices() const { return getTokenIndices_; }
215 
216  void validate(ComponentDescription const*, ESInputTag const&) const;
217 
218  void addTraceInfoToCmsException(cms::Exception& iException,
219  char const* iName,
220  ComponentDescription const*,
221  DataKey const&) const;
222  void changeStdExceptionToCmsException(char const* iExceptionWhatMessage,
223  char const* iName,
224  ComponentDescription const*,
225  DataKey const&) const;
226 
227  EventSetupRecordImpl const* impl() const { return impl_; }
228 
229  unsigned int transitionID() const { return transitionID_; }
230 
231  private:
232  template <template <typename> typename H, typename T, typename R>
233  H<T> invalidTokenHandle(ESGetToken<T, R> const& iToken) const {
234  auto const key = this->key();
235  return H<T>{
236  makeESHandleExceptionFactory([key] { return makeInvalidTokenException(key, DataKey::makeTypeTag<T>()); })};
237  }
238 
239  template <template <typename> typename H, typename T, typename R>
240  H<T> noProxyHandle(ESGetToken<T, R> const& iToken) const {
241  auto const key = this->key();
242  auto name = iToken.name();
243  return H<T>{makeESHandleExceptionFactory([key, name] {
244  NoProxyException<T> ex(key, DataKey{DataKey::makeTypeTag<T>(), name});
245  return std::make_exception_ptr(ex);
246  })};
247  }
248 
249  void const* getFromProxy(DataKey const& iKey,
250  ComponentDescription const*& iDesc,
251  bool iTransientAccessOnly) const;
252 
253  static std::exception_ptr makeInvalidTokenException(EventSetupRecordKey const&, TypeTag const&);
254  // ---------- member data --------------------------------
255  EventSetupRecordImpl const* impl_ = nullptr;
256  ESProxyIndex const* getTokenIndices_ = nullptr;
257  unsigned int transitionID_ = std::numeric_limits<unsigned int>::max();
258  };
259 
261  public:
263  unsigned int iTransitionID,
264  ESProxyIndex const* getTokenIndices) {
265  setImpl(iImpl, iTransitionID, getTokenIndices);
266  }
267 
268  EventSetupRecordKey key() const final { return impl()->key(); }
269  };
270  } // namespace eventsetup
271 } // namespace edm
272 #endif
unsigned long long cacheIdentifier() const
EventSetupRecordImpl const * impl() const
EventSetupRecordGeneric(EventSetupRecordImpl const *iImpl, unsigned int iTransitionID, ESProxyIndex const *getTokenIndices)
constexpr unsigned int transitionID() const noexcept
Definition: ESGetToken.h:51
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)
H< T > noProxyHandle(ESGetToken< T, R > const &iToken) const
unsigned int transitionID() const
void setImpl(EventSetupRecordImpl const *iImpl, unsigned int transitionID, ESProxyIndex const *getTokenIndices)
Definition: value.py:1
EventSetupRecordKey key() const final
Namespace of DDCMS conversion namespace.
EventSetupImpl const & eventSetup() const
constexpr char const * name() const noexcept
Definition: ESGetToken.h:61
void fillRegisteredDataKeys(std::vector< DataKey > &oToFill) const
clears the oToFill vector and then fills it with the keys for all registered data keys ...
constexpr ESTokenIndex index() const noexcept
Definition: ESGetToken.h:53
HLT enums.
H< T > getHandleImpl(ESGetToken< T, R > const &iToken) const
constexpr bool isInitialized() const noexcept
Definition: ESGetToken.h:52
ESProxyIndex const * getTokenIndices() const
#define UNLIKELY(x)
Definition: Likely.h:21
long double T
ValidityInterval const & validityInterval() const
constexpr bool hasValidIndex() const noexcept
Definition: ESGetToken.h:54
def move(src, dest)
Definition: eostools.py:511
H< T > invalidTokenHandle(ESGetToken< T, R > const &iToken) const