Skip to content

Commit

Permalink
Merge pull request #35204 from Dr15Jones/moveMPIInitSherpaHadronizer
Browse files Browse the repository at this point in the history
Fixed exceptional case handling in SherpaHadronizer
  • Loading branch information
cmsbuild committed Sep 9, 2021
2 parents 11c4c3e + ab7bccc commit 227c778
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 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 @@ -199,6 +204,9 @@ SherpaHadronizer::SherpaHadronizer(const edm::ParameterSet &params)
arguments.push_back(shRng);
isInitialized = false;
//initialization of Sherpa moved to initializeForInternalPartons
#ifdef USING__MPI
MPI::Init();
#endif
}

SherpaHadronizer::~SherpaHadronizer() {
Expand All @@ -210,14 +218,12 @@ SherpaHadronizer::~SherpaHadronizer() {

bool SherpaHadronizer::initializeForInternalPartons() {
//initialize Sherpa but only once
throw cms::Exception("TEST");
if (!isInitialized) {
int argc = arguments.size();
char *argv[argc];
for (int l = 0; l < argc; l++)
argv[l] = (char *)arguments[l].c_str();
#ifdef USING__MPI
MPI::Init();
#endif
Generator->InitializeTheRun(argc, argv);
Generator->InitializeTheEventHandler();
isInitialized = true;
Expand Down

0 comments on commit 227c778

Please sign in to comment.