File indexing completed on 2024-09-12 04:16:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <cassert>
0015 #include <algorithm>
0016
0017
0018 #include "FWCore/Framework/interface/ESRecordsToProductResolverIndices.h"
0019 #include "FWCore/Framework/interface/ComponentDescription.h"
0020
0021
0022
0023
0024
0025 namespace edm::eventsetup {
0026 ESRecordsToProductResolverIndices::ESRecordsToProductResolverIndices(std::vector<EventSetupRecordKey> iRecords)
0027 : recordKeys_{std::move(iRecords)} {
0028 assert(std::is_sorted(recordKeys_.begin(), recordKeys_.end()));
0029 recordOffsets_.reserve(recordKeys_.size() + 1);
0030 recordOffsets_.push_back(0);
0031 }
0032
0033 unsigned int ESRecordsToProductResolverIndices::dataKeysInRecord(
0034 unsigned int iRecordIndex,
0035 EventSetupRecordKey const& iRecord,
0036 std::vector<DataKey> const& iDataKeys,
0037 std::vector<ComponentDescription const*> const& iComponents) {
0038 assert(iRecord == recordKeys_[iRecordIndex]);
0039 assert(iDataKeys.size() == iComponents.size());
0040 assert(iRecordIndex + 1 == recordOffsets_.size());
0041 dataKeys_.insert(dataKeys_.end(), iDataKeys.begin(), iDataKeys.end());
0042 ++iRecordIndex;
0043 components_.insert(components_.end(), iComponents.begin(), iComponents.end());
0044 recordOffsets_.push_back(dataKeys_.size());
0045 return iRecordIndex;
0046 }
0047
0048
0049
0050
0051 ESResolverIndex ESRecordsToProductResolverIndices::indexInRecord(EventSetupRecordKey const& iRK,
0052 DataKey const& iDK) const noexcept {
0053 auto it = std::lower_bound(recordKeys_.begin(), recordKeys_.end(), iRK);
0054 if (it == recordKeys_.end() or *it != iRK) {
0055 return ESResolverIndex::noResolverConfigured();
0056 }
0057
0058 auto beginOffset = recordOffsets_[std::distance(recordKeys_.begin(), it)];
0059 ++it;
0060 auto endOffset = recordOffsets_[std::distance(recordKeys_.begin(), it)];
0061
0062 auto itDK = std::lower_bound(dataKeys_.begin() + beginOffset, dataKeys_.begin() + endOffset, iDK);
0063 if (itDK == dataKeys_.begin() + endOffset or *itDK != iDK) {
0064 return ESResolverIndex::noResolverConfigured();
0065 }
0066
0067 return ESResolverIndex{static_cast<int>(std::distance(dataKeys_.begin() + beginOffset, itDK))};
0068 }
0069
0070 ESRecordIndex ESRecordsToProductResolverIndices::recordIndexFor(EventSetupRecordKey const& iRK) const noexcept {
0071 auto it = std::lower_bound(recordKeys_.begin(), recordKeys_.end(), iRK);
0072 if (it == recordKeys_.end() or *it != iRK) {
0073 return missingRecordIndex();
0074 }
0075 return ESRecordIndex{static_cast<ESRecordIndex::Value_t>(it - recordKeys_.begin())};
0076 }
0077
0078 ComponentDescription const* ESRecordsToProductResolverIndices::component(EventSetupRecordKey const& iRK,
0079 DataKey const& iDK) const noexcept {
0080 auto it = std::lower_bound(recordKeys_.begin(), recordKeys_.end(), iRK);
0081 if (it == recordKeys_.end() or *it != iRK) {
0082 return nullptr;
0083 }
0084
0085 auto beginOffset = recordOffsets_[std::distance(recordKeys_.begin(), it)];
0086 ++it;
0087 auto endOffset = recordOffsets_[std::distance(recordKeys_.begin(), it)];
0088
0089 auto itDK = std::lower_bound(dataKeys_.begin() + beginOffset, dataKeys_.begin() + endOffset, iDK);
0090 if (itDK == dataKeys_.begin() + endOffset or *itDK != iDK) {
0091 return nullptr;
0092 }
0093 return components_[std::distance(dataKeys_.begin(), itDK)];
0094 }
0095
0096 ESTagGetter ESRecordsToProductResolverIndices::makeTagGetter(EventSetupRecordKey const& iRK,
0097 TypeTag const& iTT) const {
0098 auto recIndex = recordIndexFor(iRK);
0099 if (recIndex == missingRecordIndex()) {
0100 return ESTagGetter();
0101 }
0102
0103 auto const beginIndex = recordOffsets_[recIndex.value()];
0104 auto const endIndex = recordOffsets_[recIndex.value() + 1];
0105 auto keyIndex = beginIndex;
0106
0107 std::vector<ESTagGetter::Info> returnValue;
0108 returnValue.reserve(endIndex - beginIndex);
0109 bool foundFirstIndex = false;
0110 while (keyIndex < endIndex) {
0111 if (dataKeys_[keyIndex].type() != iTT) {
0112 if (foundFirstIndex) {
0113
0114 break;
0115 }
0116 } else {
0117 foundFirstIndex = true;
0118 returnValue.emplace_back(
0119 keyIndex - beginIndex,
0120 dataKeys_[keyIndex].name().value(),
0121 components_[keyIndex] ? std::string_view(components_[keyIndex]->label_) : std::string_view());
0122 }
0123 ++keyIndex;
0124 }
0125 return returnValue;
0126 }
0127
0128 std::pair<std::vector<DataKey>::const_iterator, std::vector<DataKey>::const_iterator>
0129 ESRecordsToProductResolverIndices::keysForRecord(EventSetupRecordKey const& iRK) const noexcept {
0130 auto recIndex = recordIndexFor(iRK);
0131 if (recIndex == missingRecordIndex()) {
0132 return std::make_pair(dataKeys_.end(), dataKeys_.end());
0133 }
0134 auto const beginIndex = recordOffsets_[recIndex.value()];
0135 auto const endIndex = recordOffsets_[recIndex.value() + 1];
0136 return std::make_pair(dataKeys_.begin() + beginIndex, dataKeys_.begin() + endIndex);
0137 }
0138
0139 }