From a4e0ad983aedc532f595fc7fe1c400bb964a8f3f Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Tue, 25 Jan 2022 15:35:54 -0600 Subject: [PATCH] Fix calling methods on nullptr in Concurrent*Filter modules Check if the decayer exists before calling methods. --- .../Core/interface/ConcurrentGeneratorFilter.h | 10 ++++++++-- .../Core/interface/ConcurrentHadronizerFilter.h | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/GeneratorInterface/Core/interface/ConcurrentGeneratorFilter.h b/GeneratorInterface/Core/interface/ConcurrentGeneratorFilter.h index 6c30e37c5ebdc..d27e727160d16 100644 --- a/GeneratorInterface/Core/interface/ConcurrentGeneratorFilter.h +++ b/GeneratorInterface/Core/interface/ConcurrentGeneratorFilter.h @@ -174,10 +174,16 @@ namespace edm { Service rng; auto enginePtr = rng->cloneEngine(lumi.index()); cache->hadronizer_.setRandomEngine(enginePtr.get()); - cache->decayer_->setRandomEngine(enginePtr.get()); + if (cache->decayer_) { + cache->decayer_->setRandomEngine(enginePtr.get()); + } auto unsetH = [](HAD* h) { h->setRandomEngine(nullptr); }; - auto unsetD = [](DEC* d) { d->setRandomEngine(nullptr); }; + auto unsetD = [](DEC* d) { + if (d) { + d->setRandomEngine(nullptr); + } + }; std::unique_ptr randomEngineSentry(&cache->hadronizer_, unsetH); std::unique_ptr randomEngineSentryDecay(cache->decayer_.get(), unsetD); diff --git a/GeneratorInterface/Core/interface/ConcurrentHadronizerFilter.h b/GeneratorInterface/Core/interface/ConcurrentHadronizerFilter.h index 45c51c57e3766..fef294b845f3c 100644 --- a/GeneratorInterface/Core/interface/ConcurrentHadronizerFilter.h +++ b/GeneratorInterface/Core/interface/ConcurrentHadronizerFilter.h @@ -400,10 +400,16 @@ namespace edm { Service rng; auto enginePtr = rng->cloneEngine(lumi.index()); cache->hadronizer_.setRandomEngine(enginePtr.get()); - cache->decayer_->setRandomEngine(enginePtr.get()); + if (cache->decayer_) { + cache->decayer_->setRandomEngine(enginePtr.get()); + } auto unsetH = [](HAD* h) { h->setRandomEngine(nullptr); }; - auto unsetD = [](DEC* d) { d->setRandomEngine(nullptr); }; + auto unsetD = [](DEC* d) { + if (d) { + d->setRandomEngine(nullptr); + } + }; std::unique_ptr randomEngineSentry(&cache->hadronizer_, unsetH); std::unique_ptr randomEngineSentryDecay(cache->decayer_.get(), unsetD);