Skip to content

Commit

Permalink
Throw a separate exception if ESGetToken is uninitialized
Browse files Browse the repository at this point in the history
  • Loading branch information
makortel committed Jul 2, 2020
1 parent 67d33e4 commit 771ba07
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion FWCore/Framework/interface/EventSetupRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,12 @@ namespace edm {
protected:
template <template <typename> typename H, typename T, typename R>
H<T> getHandleImpl(ESGetToken<T, R> const& iToken) const {
if UNLIKELY (not iToken.isInitialized()) {
std::rethrow_exception(makeInvalidTokenException(this->key(), DataKey::makeTypeTag<T>()));
}
if UNLIKELY (iToken.transitionID() != transitionID()) {
throwWrongTransitionID();
}
assert(iToken.isInitialized());
assert(getTokenIndices_);
//need to check token has valid index
if UNLIKELY (not iToken.hasValidIndex()) {
Expand Down
9 changes: 9 additions & 0 deletions FWCore/Framework/test/eventsetup_t.cppunit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ namespace {
}

ESGetToken<edm::eventsetup::test::DummyData, edm::DefaultRecord> m_token;
ESGetToken<edm::eventsetup::test::DummyData, edm::DefaultRecord> m_tokenUninitialized;
};

class ConsumesProducer : public ESProducer {
Expand Down Expand Up @@ -763,6 +764,14 @@ void testEventsetup::getDataWithESGetTokenTest() {
true};
auto const& data = eventSetup.getData(consumer.m_token);
CPPUNIT_ASSERT(kGood.value_ == data.value_);
bool uninitializedTokenThrewException = false;
try {
(void)eventSetup.getData(consumer.m_tokenUninitialized);
} catch (cms::Exception& ex) {
uninitializedTokenThrewException = true;
CPPUNIT_ASSERT(ex.category() == "InvalidESGetToken");
}
CPPUNIT_ASSERT(uninitializedTokenThrewException);
}

{
Expand Down

0 comments on commit 771ba07

Please sign in to comment.