CMS 3D CMS Logo

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
edm::EventSetupImpl::findImpl
eventsetup::EventSetupRecordImpl const * findImpl(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetupImpl.cc:60
edm::ESRecordIndex::invalidValue
static constexpr Value_t invalidValue()
Definition: ESIndices.h:97
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::EventSetupImpl::fillAvailableRecordKeys
void fillAvailableRecordKeys(std::vector< eventsetup::EventSetupRecordKey > &oToFill) const
clears the oToFill vector and then fills it with the keys for all available records
Definition: EventSetupImpl.cc:76
EventSetupImpl.h
edm::EventSetupImpl::validRecord
bool validRecord(eventsetup::EventSetupRecordKey const &iKey) const
Definition: EventSetupImpl.cc:92
edm::EventSetupImpl::EventSetupImpl
EventSetupImpl()=delete
edm::ESRecordIndex
Definition: ESIndices.h:80
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
edm::ESProxyIndex
Definition: ESIndices.h:30
EventSetupRecord.h
UNLIKELY
#define UNLIKELY(x)
Definition: Likely.h:21
edm::ESRecordIndex::value
constexpr Value_t value() const noexcept
Definition: ESIndices.h:95
edm::EventSetupImpl::keysEnd_
std::vector< eventsetup::EventSetupRecordKey >::const_iterator keysEnd_
Definition: EventSetupImpl.h:97
edm::eventsetup::EventSetupRecordImpl
Definition: EventSetupRecordImpl.h:77
edm::EventSetupImpl::setKeyIters
void setKeyIters(std::vector< eventsetup::EventSetupRecordKey >::const_iterator const &keysBegin, std::vector< eventsetup::EventSetupRecordKey >::const_iterator const &keysEnd)
Definition: EventSetupImpl.cc:101
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
edm::eventsetup::EventSetupRecordGeneric
Definition: EventSetupRecord.h:296
edm::eventsetup::EventSetupRecordImpl::key
EventSetupRecordKey const & key() const
Definition: EventSetupRecordImpl.h:107
edm::EventSetupImpl::~EventSetupImpl
~EventSetupImpl()
Definition: EventSetupImpl.cc:28
edm::EventSetupImpl::insertRecordImpl
void insertRecordImpl(const eventsetup::EventSetupRecordKey &, const eventsetup::EventSetupRecordImpl *)
Definition: EventSetupImpl.cc:30
edm::EventSetupImpl::keysBegin_
std::vector< eventsetup::EventSetupRecordKey >::const_iterator keysBegin_
Definition: EventSetupImpl.h:96
edm::EventSetupImpl::recordIsProvidedByAModule
bool recordIsProvidedByAModule(eventsetup::EventSetupRecordKey const &) const
Definition: EventSetupImpl.cc:87
edm::ESParentContext
Definition: ESParentContext.h:21
Exception
Definition: hltDiff.cc:245
Exception.h
edm::EventSetupImpl::recordImpls_
std::vector< eventsetup::EventSetupRecordImpl const * > recordImpls_
Definition: EventSetupImpl.h:98
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
EventSetupRecordKey.h
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7733
edm::EventSetupImpl::find
std::optional< eventsetup::EventSetupRecordGeneric > find(const eventsetup::EventSetupRecordKey &, unsigned int iTransitionID, ESProxyIndex const *getTokenIndices, ESParentContext const &iParent) const
Definition: EventSetupImpl.cc:45
edm::EventSetupImpl::addRecordImpl
void addRecordImpl(const eventsetup::EventSetupRecordImpl &iRecord)
Definition: EventSetupImpl.cc:41