Skip to content

Commit

Permalink
Merge pull request #45726 from wddgit/bugFixLabelInExceptionMessage
Browse files Browse the repository at this point in the history
Fix bug affecting label in exception message
  • Loading branch information
cmsbuild authored Aug 21, 2024
2 parents 96fbe75 + 5dea066 commit 5bf1f99
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
33 changes: 16 additions & 17 deletions FWCore/Framework/interface/EDConsumerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <vector>
#include <array>
#include <cassert>
#include <tuple>

// user include files
#include "DataFormats/Provenance/interface/BranchType.h"
Expand Down Expand Up @@ -196,14 +197,15 @@ namespace edm {

template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
auto esConsumes(ESInputTag const& tag) {
auto index = recordESConsumes(Tr,
eventsetup::EventSetupRecordKey::makeKey<
std::conditional_t<std::is_same_v<ESRecord, edm::DefaultRecord>,
eventsetup::default_record_t<ESHandleAdapter<ESProduct>>,
ESRecord>>(),
eventsetup::heterocontainer::HCTypeTag::make<ESProduct>(),
tag);
return ESGetToken<ESProduct, ESRecord>{static_cast<unsigned int>(Tr), index, labelFor(index)};
auto [index, productLabel] =
recordESConsumes(Tr,
eventsetup::EventSetupRecordKey::makeKey<
std::conditional_t<std::is_same_v<ESRecord, edm::DefaultRecord>,
eventsetup::default_record_t<ESHandleAdapter<ESProduct>>,
ESRecord>>(),
eventsetup::heterocontainer::HCTypeTag::make<ESProduct>(),
tag);
return ESGetToken<ESProduct, ESRecord>{static_cast<unsigned int>(Tr), index, productLabel};
}

template <Transition Tr = Transition::Event>
Expand All @@ -219,9 +221,8 @@ namespace edm {
///Used with EventSetupRecord::doGet
template <Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes(eventsetup::EventSetupRecordKey const& iRecord, eventsetup::DataKey const& iKey) {
return ESGetTokenGeneric(static_cast<unsigned int>(Tr),
recordESConsumes(Tr, iRecord, iKey.type(), ESInputTag("", iKey.name().value())),
iRecord.type());
auto [index, productLabel] = recordESConsumes(Tr, iRecord, iKey.type(), ESInputTag("", iKey.name().value()));
return ESGetTokenGeneric(static_cast<unsigned int>(Tr), index, iRecord.type());
}

//used for FinalPath
Expand All @@ -231,12 +232,10 @@ namespace edm {
virtual void extendUpdateLookup(BranchType iBranchType, ProductResolverIndexHelper const&);
virtual void registerLateConsumes(eventsetup::ESRecordsToProductResolverIndices const&) {}
unsigned int recordConsumes(BranchType iBranch, TypeToGet const& iType, edm::InputTag const& iTag, bool iAlwaysGets);
ESTokenIndex recordESConsumes(Transition,
eventsetup::EventSetupRecordKey const&,
eventsetup::heterocontainer::HCTypeTag const&,
edm::ESInputTag const& iTag);

const char* labelFor(ESTokenIndex) const;
std::tuple<ESTokenIndex, char const*> recordESConsumes(Transition,
eventsetup::EventSetupRecordKey const&,
eventsetup::heterocontainer::HCTypeTag const&,
edm::ESInputTag const& iTag);

void throwTypeMismatch(edm::TypeID const&, EDGetToken) const;
void throwBranchMismatch(BranchType, EDGetToken) const;
Expand Down
6 changes: 3 additions & 3 deletions FWCore/Framework/interface/EventSetupRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ namespace edm {
template <template <typename> typename H, typename T, typename R>
H<T> noResolverHandle(ESGetToken<T, R> const& iToken) const {
auto const key = this->key();
auto name = iToken.name();
return H<T>{makeESHandleExceptionFactory([key, name] {
NoProductResolverException<T> ex(key, DataKey{DataKey::makeTypeTag<T>(), name});
auto productLabel = iToken.productLabel();
return H<T>{makeESHandleExceptionFactory([key, productLabel] {
NoProductResolverException<T> ex(key, DataKey{DataKey::makeTypeTag<T>(), productLabel});
return std::make_exception_ptr(ex);
})};
}
Expand Down
16 changes: 7 additions & 9 deletions FWCore/Framework/src/EDConsumerBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ void EDConsumerBase::updateLookup(eventsetup::ESRecordsToProductResolverIndices
}
}

ESTokenIndex EDConsumerBase::recordESConsumes(Transition iTrans,
eventsetup::EventSetupRecordKey const& iRecord,
eventsetup::heterocontainer::HCTypeTag const& iDataType,
edm::ESInputTag const& iTag) {
std::tuple<ESTokenIndex, char const*> EDConsumerBase::recordESConsumes(
Transition iTrans,
eventsetup::EventSetupRecordKey const& iRecord,
eventsetup::heterocontainer::HCTypeTag const& iDataType,
edm::ESInputTag const& iTag) {
if (frozen_) {
throwESConsumesCallAfterFrozen(iRecord, iDataType, iTag);
}
Expand Down Expand Up @@ -218,7 +219,8 @@ ESTokenIndex EDConsumerBase::recordESConsumes(Transition iTrans,
auto indexForToken = esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)].size();
esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)].emplace_back(-1 * (index + 1));
esRecordsToGetFromTransition_[static_cast<unsigned int>(iTrans)].emplace_back();
return ESTokenIndex{static_cast<ESTokenIndex::Value_t>(indexForToken)};
return {ESTokenIndex{static_cast<ESTokenIndex::Value_t>(indexForToken)},
m_esTokenInfo.get<kESLookupInfo>(index).m_key.name().value()};
}

//
Expand Down Expand Up @@ -590,7 +592,3 @@ std::vector<ConsumesInfo> EDConsumerBase::consumesInfo() const {
}
return result;
}

const char* EDConsumerBase::labelFor(ESTokenIndex iIndex) const {
return m_esTokenInfo.get<kESLookupInfo>(iIndex.value()).m_key.name().value();
}
8 changes: 4 additions & 4 deletions FWCore/Utilities/interface/ESGetToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ namespace edm {
static constexpr ESTokenIndex invalidIndex() noexcept { return ESTokenIndex{std::numeric_limits<int>::max()}; }

private:
explicit constexpr ESGetToken(unsigned int transitionID, ESTokenIndex index, char const* label) noexcept
: m_label{label}, m_transitionID{transitionID}, m_index{index} {}
explicit constexpr ESGetToken(unsigned int transitionID, ESTokenIndex index, char const* productLabel) noexcept
: m_productLabel{productLabel}, m_transitionID{transitionID}, m_index{index} {}

constexpr char const* name() const noexcept { return m_label; }
char const* m_label{nullptr};
constexpr char const* productLabel() const noexcept { return m_productLabel; }
char const* m_productLabel{nullptr};
unsigned int m_transitionID{std::numeric_limits<unsigned int>::max()};
ESTokenIndex m_index{std::numeric_limits<int>::max()};
};
Expand Down

0 comments on commit 5bf1f99

Please sign in to comment.