diff --git a/FWCore/Framework/src/ESRecordsToProductResolverIndices.cc b/FWCore/Framework/src/ESRecordsToProductResolverIndices.cc index 9a9c476ba906b..8e90594423da0 100644 --- a/FWCore/Framework/src/ESRecordsToProductResolverIndices.cc +++ b/FWCore/Framework/src/ESRecordsToProductResolverIndices.cc @@ -115,10 +115,12 @@ namespace edm::eventsetup { } } else { foundFirstIndex = true; - returnValue.emplace_back( - keyIndex - beginIndex, - dataKeys_[keyIndex].name().value(), - components_[keyIndex] ? std::string_view(components_[keyIndex]->label_) : std::string_view()); + returnValue.emplace_back(keyIndex - beginIndex, + dataKeys_[keyIndex].name().value(), + components_[keyIndex] ? components_[keyIndex]->label_.empty() + ? std::string_view(components_[keyIndex]->type_) + : std::string_view(components_[keyIndex]->label_) + : std::string_view()); } ++keyIndex; } diff --git a/FWCore/Framework/test/eventsetup_t.cppunit.cc b/FWCore/Framework/test/eventsetup_t.cppunit.cc index a87f0b14d0bbc..4b7075b31982e 100644 --- a/FWCore/Framework/test/eventsetup_t.cppunit.cc +++ b/FWCore/Framework/test/eventsetup_t.cppunit.cc @@ -656,6 +656,18 @@ void testEventsetup::getDataWithESGetTokenTest() { dummyProv->setAppendToDataLabel(ps); provider.add(dummyProv); } + { + edm::eventsetup::ComponentDescription description("DummyESProductResolverProvider", "", 100, false); + edm::ParameterSet ps; + ps.addParameter("name", "test22"); + ps.addParameter("appendToDataLabel", "blahblah"); + ps.registerIt(); + description.pid_ = ps.id(); + auto dummyProv = std::make_shared(kGood); + dummyProv->setDescription(description); + dummyProv->setAppendToDataLabel(ps); + provider.add(dummyProv); + } { edm::eventsetup::ComponentDescription description("ConsumesProducer", "consumes", 2, false); edm::ParameterSet ps; @@ -739,6 +751,32 @@ void testEventsetup::getDataWithESGetTokenTest() { dummyProv->setAppendToDataLabel(ps); provider.add(dummyProv); } + { + edm::eventsetup::ComponentDescription description( + "SetMayConsumeProducer", "setMayConsumeWithUnlabeledModuleLabel", 101, false); + edm::ParameterSet ps; + ps.addParameter("name", "thisIsNotUsed"); + ps.registerIt(); + description.pid_ = ps.id(); + auto dummyProv = std::make_shared( + true, "DummyESProductResolverProvider", "blahblah", "productLabelForProducerWithMayConsumesUnlabeledCase"); + dummyProv->setDescription(description); + dummyProv->setAppendToDataLabel(ps); + provider.add(dummyProv); + } + { + edm::eventsetup::ComponentDescription description( + "SetMayConsumeProducer", "setMayConsumeWithUnlabeledModuleLabel", 102, false); + edm::ParameterSet ps; + ps.addParameter("name", "thisIsNotUsed"); + ps.registerIt(); + description.pid_ = ps.id(); + auto dummyProv = std::make_shared( + true, "doesNotExist", "blahblah", "productLabelForProducerWithMayConsumesUnlabeledCaseNonexistent"); + dummyProv->setDescription(description); + dummyProv->setAppendToDataLabel(ps); + provider.add(dummyProv); + } edm::ESParentContext pc; controller.eventSetupForInstance(IOVSyncValue(Timestamp(2))); @@ -878,6 +916,24 @@ void testEventsetup::getDataWithESGetTokenTest() { CPPUNIT_ASSERT_THROW(consumer.prefetch(provider.eventSetupImpl()), edm::eventsetup::NoProductResolverException); } + { + DummyDataConsumer consumer{edm::ESInputTag("", "productLabelForProducerWithMayConsumesUnlabeledCase")}; + consumer.updateLookup(provider.recordsToResolverIndices()); + consumer.prefetch(provider.eventSetupImpl()); + EventSetup eventSetup{provider.eventSetupImpl(), + static_cast(edm::Transition::Event), + consumer.esGetTokenIndices(edm::Transition::Event), + pc}; + const DummyData& data = eventSetup.getData(consumer.m_token); + CPPUNIT_ASSERT(kGood.value_ == data.value_); + } + + { + DummyDataConsumer consumer{edm::ESInputTag("", "productLabelForProducerWithMayConsumesUnlabeledCaseNonexistent")}; + consumer.updateLookup(provider.recordsToResolverIndices()); + CPPUNIT_ASSERT_THROW(consumer.prefetch(provider.eventSetupImpl()), edm::eventsetup::NoProductResolverException); + } + } catch (const cms::Exception& iException) { std::cout << "caught " << iException.explainSelf() << std::endl; throw;