Skip to content

Commit

Permalink
Merge pull request #46484 from wddgit/fixUnlabeledCase
Browse files Browse the repository at this point in the history
Fix unlabeled case in mayConsumes EventSetup
  • Loading branch information
cmsbuild authored Oct 23, 2024
2 parents 854bda7 + 03973ad commit 55fd977
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
10 changes: 6 additions & 4 deletions FWCore/Framework/src/ESRecordsToProductResolverIndices.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
56 changes: 56 additions & 0 deletions FWCore/Framework/test/eventsetup_t.cppunit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>("name", "test22");
ps.addParameter<std::string>("appendToDataLabel", "blahblah");
ps.registerIt();
description.pid_ = ps.id();
auto dummyProv = std::make_shared<DummyESProductResolverProvider>(kGood);
dummyProv->setDescription(description);
dummyProv->setAppendToDataLabel(ps);
provider.add(dummyProv);
}
{
edm::eventsetup::ComponentDescription description("ConsumesProducer", "consumes", 2, false);
edm::ParameterSet ps;
Expand Down Expand Up @@ -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<std::string>("name", "thisIsNotUsed");
ps.registerIt();
description.pid_ = ps.id();
auto dummyProv = std::make_shared<SetMayConsumeProducer>(
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<std::string>("name", "thisIsNotUsed");
ps.registerIt();
description.pid_ = ps.id();
auto dummyProv = std::make_shared<SetMayConsumeProducer>(
true, "doesNotExist", "blahblah", "productLabelForProducerWithMayConsumesUnlabeledCaseNonexistent");
dummyProv->setDescription(description);
dummyProv->setAppendToDataLabel(ps);
provider.add(dummyProv);
}

edm::ESParentContext pc;
controller.eventSetupForInstance(IOVSyncValue(Timestamp(2)));
Expand Down Expand Up @@ -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<unsigned int>(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;
Expand Down

0 comments on commit 55fd977

Please sign in to comment.