Skip to content

Commit

Permalink
Protect RandomEngineSentry destructor from thrown an exception
Browse files Browse the repository at this point in the history
SherpaHadronizer::doSetRandomEngine is called by the destructor
so throwing an exception from there can happen when we are already
dealing with an exception which leads to std::termiate.
  • Loading branch information
Dr15Jones committed Sep 9, 2021
1 parent 4c6d209 commit ab7bccc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions GeneratorInterface/SherpaInterface/src/SherpaHadronizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include "CLHEP/Random/RandomEngine.h"

#include "FWCore/Utilities/interface/Exception.h"

//This unnamed namespace is used (instead of static variables) to pass the
//randomEngine passed to doSetRandomEngine to the External Random
//Number Generator CMS_SHERPA_RNG of sherpa
Expand Down Expand Up @@ -95,8 +97,11 @@ void SherpaHadronizer::doSetRandomEngine(CLHEP::HepRandomEngine *v) {
SetExternalEngine(v);
// Throw exception if there is no reference to an external RNG and it is not the first call!
} else {
throw edm::Exception(edm::errors::LogicError) << "The Sherpa interface got a randomEngine reference but there is "
"no reference to the external RNG to hand it over to\n";
if (isInitialized and v != nullptr) {
throw edm::Exception(edm::errors::LogicError)
<< "The Sherpa interface got a randomEngine reference but there is "
"no reference to the external RNG to hand it over to\n";
}
}
} else {
cmsSherpaRng->setRandomEngine(v);
Expand Down Expand Up @@ -213,6 +218,7 @@ SherpaHadronizer::~SherpaHadronizer() {

bool SherpaHadronizer::initializeForInternalPartons() {
//initialize Sherpa but only once
throw cms::Exception("TEST");
if (!isInitialized) {
int argc = arguments.size();
char *argv[argc];
Expand Down

0 comments on commit ab7bccc

Please sign in to comment.