CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EventSetupImpl.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Framework
4 // Module: EventSetup
5 //
6 // Description: <one line class summary>
7 //
8 // Implementation:
9 // <Notes on implementation>
10 //
11 // Author: Chris Jones
12 // Created: Thu Mar 24 16:27:10 EST 2005
13 //
14 
15 // system include files
16 #include <algorithm>
17 
18 // user include files
23 
24 namespace edm {
25 
26  EventSetupImpl::EventSetupImpl(tbb::task_arena* iArena) : taskArena_{iArena} {}
27 
29 
31  const eventsetup::EventSetupRecordImpl* iRecord) {
32  auto lb = std::lower_bound(keysBegin_, keysEnd_, iKey);
33  if (lb == keysEnd_ || iKey != *lb) {
34  throw cms::Exception("LogicError") << "EventSetupImpl::insert Could not find key\n"
35  << "Should be impossible. Please contact Framework developer.\n";
36  }
37  auto index = std::distance(keysBegin_, lb);
38  recordImpls_[index] = iRecord;
39  }
40 
42  insertRecordImpl(iRecord.key(), &iRecord);
43  }
44 
45  std::optional<eventsetup::EventSetupRecordGeneric> EventSetupImpl::find(const eventsetup::EventSetupRecordKey& iKey,
46  unsigned int iTransitionID,
47  ESProxyIndex const* getTokenIndices,
48  ESParentContext const& iParent) const {
49  auto lb = std::lower_bound(keysBegin_, keysEnd_, iKey);
50  if (lb == keysEnd_ || iKey != *lb) {
51  return std::nullopt;
52  }
53  auto index = std::distance(keysBegin_, lb);
54  if (recordImpls_[index] == nullptr) {
55  return std::nullopt;
56  }
57  return eventsetup::EventSetupRecordGeneric(recordImpls_[index], iTransitionID, getTokenIndices, this, &iParent);
58  }
59 
61  auto lb = std::lower_bound(keysBegin_, keysEnd_, iKey);
62  if (lb == keysEnd_ || iKey != *lb) {
63  return nullptr;
64  }
65  auto index = std::distance(keysBegin_, lb);
66  return recordImpls_[index];
67  }
68 
70  if UNLIKELY (iKey.value() == ESRecordIndex::invalidValue()) {
71  return nullptr;
72  }
73  return recordImpls_[iKey.value()];
74  }
75 
76  void EventSetupImpl::fillAvailableRecordKeys(std::vector<eventsetup::EventSetupRecordKey>& oToFill) const {
77  oToFill.clear();
78  oToFill.reserve(recordImpls_.size());
79 
80  for (auto const& recordImpl : recordImpls_) {
81  if (recordImpl != nullptr) {
82  oToFill.push_back(recordImpl->key());
83  }
84  }
85  }
86 
88  auto lb = std::lower_bound(keysBegin_, keysEnd_, iKey);
89  return lb != keysEnd_ && iKey == *lb;
90  }
91 
93  auto lb = std::lower_bound(keysBegin_, keysEnd_, iKey);
94  if (lb != keysEnd_ && iKey == *lb) {
95  auto index = std::distance(keysBegin_, lb);
96  return recordImpls_[index] != nullptr;
97  }
98  return false;
99  }
100 
101  void EventSetupImpl::setKeyIters(std::vector<eventsetup::EventSetupRecordKey>::const_iterator const& keysBegin,
102  std::vector<eventsetup::EventSetupRecordKey>::const_iterator const& keysEnd) {
103  keysBegin_ = keysBegin;
104  keysEnd_ = keysEnd;
105  recordImpls_.resize(keysEnd_ - keysBegin_, nullptr);
106  }
107 
108 } // namespace edm
static constexpr Value_t invalidValue()
Definition: ESIndices.h:97
void setKeyIters(std::vector< eventsetup::EventSetupRecordKey >::const_iterator const &keysBegin, std::vector< eventsetup::EventSetupRecordKey >::const_iterator const &keysEnd)
std::vector< eventsetup::EventSetupRecordKey >::const_iterator keysBegin_
std::vector< eventsetup::EventSetupRecordKey >::const_iterator keysEnd_
void fillAvailableRecordKeys(std::vector< eventsetup::EventSetupRecordKey > &oToFill) const
clears the oToFill vector and then fills it with the keys for all available records ...
constexpr Value_t value() const noexcept
Definition: ESIndices.h:95
bool validRecord(eventsetup::EventSetupRecordKey const &iKey) const
void addRecordImpl(const eventsetup::EventSetupRecordImpl &iRecord)
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
std::vector< eventsetup::EventSetupRecordImpl const * > recordImpls_
void insertRecordImpl(const eventsetup::EventSetupRecordKey &, const eventsetup::EventSetupRecordImpl *)
#define UNLIKELY(x)
Definition: Likely.h:21
eventsetup::EventSetupRecordImpl const * findImpl(const eventsetup::EventSetupRecordKey &) const
bool recordIsProvidedByAModule(eventsetup::EventSetupRecordKey const &) const
std::optional< eventsetup::EventSetupRecordGeneric > find(const eventsetup::EventSetupRecordKey &, unsigned int iTransitionID, ESProxyIndex const *getTokenIndices, ESParentContext const &iParent) const
EventSetupRecordKey const & key() const