From 03973ad0c7337dd57f9fcf81ae50baf4495b1379 Mon Sep 17 00:00:00 2001 From: "W. David Dagenhart" Date: Tue, 22 Oct 2024 20:55:14 +0200 Subject: [PATCH] Fix unlabeled case in mayConsumes EventSetup --- .../src/ESRecordsToProductResolverIndices.cc | 10 ++-- FWCore/Framework/test/eventsetup_t.cppunit.cc | 56 +++++++++++++++++++ 2 files changed, 62 insertions(+), 4 deletions(-) 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;