forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share the implementation across RandomNumberGenerators
- Loading branch information
Showing
5 changed files
with
90 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef IOMC_RandomEngine_cloneEngine_h | ||
#define IOMC_RandomEngine_cloneEngine_h | ||
// -*- C++ -*- | ||
// | ||
// Package: IOMC/RandomEngine | ||
// Class : cloneEngine | ||
// | ||
/**\function cloneEngine cloneEngine.h "IOMC/RandomEngine/interface/cloneEngine.h" | ||
Description: Function used to clone a random number engine | ||
Usage: | ||
<usage> | ||
*/ | ||
// | ||
// Original Author: Christopher Jones | ||
// Created: Fri, 02 Dec 2022 19:32:10 GMT | ||
// | ||
#include <memory> | ||
|
||
namespace CLHEP { | ||
class HepRandomEngine; | ||
} | ||
|
||
namespace edm { | ||
std::unique_ptr<CLHEP::HepRandomEngine> cloneEngine(CLHEP::HepRandomEngine const&); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// -*- C++ -*- | ||
// | ||
// Package: IOMC/RandomEngine | ||
// Class : cloneEngine | ||
// | ||
// Implementation: | ||
// [Notes on implementation] | ||
// | ||
// Original Author: Christopher Jones | ||
// Created: Fri, 02 Dec 2022 19:34:37 GMT | ||
// | ||
|
||
// system include files | ||
|
||
// user include files | ||
#include "IOMC/RandomEngine/interface/cloneEngine.h" | ||
#include "IOMC/RandomEngine/interface/TRandomAdaptor.h" | ||
|
||
#include "FWCore/Utilities/interface/EDMException.h" | ||
|
||
#include "CLHEP/Random/engineIDulong.h" | ||
#include "CLHEP/Random/JamesRandom.h" | ||
#include "CLHEP/Random/RanecuEngine.h" | ||
#include "CLHEP/Random/MixMaxRng.h" | ||
|
||
namespace edm { | ||
std::unique_ptr<CLHEP::HepRandomEngine> cloneEngine(CLHEP::HepRandomEngine const& existingEngine) { | ||
std::vector<unsigned long> stateL = existingEngine.put(); | ||
long seedL = existingEngine.getSeed(); | ||
std::unique_ptr<CLHEP::HepRandomEngine> newEngine; | ||
if (stateL[0] == CLHEP::engineIDulong<CLHEP::HepJamesRandom>()) { | ||
newEngine = std::make_unique<CLHEP::HepJamesRandom>(seedL); | ||
} else if (stateL[0] == CLHEP::engineIDulong<CLHEP::RanecuEngine>()) { | ||
newEngine = std::make_unique<CLHEP::RanecuEngine>(); | ||
} else if (stateL[0] == CLHEP::engineIDulong<CLHEP::MixMaxRng>()) { | ||
newEngine = std::make_unique<CLHEP::MixMaxRng>(seedL); | ||
} else if (stateL[0] == CLHEP::engineIDulong<TRandomAdaptor>()) { | ||
newEngine = std::make_unique<TRandomAdaptor>(seedL); | ||
} else { | ||
// Sanity check, it should not be possible for this to happen. | ||
throw Exception(errors::Unknown) << "The RandomNumberGeneratorService is trying to clone unknown engine type\n"; | ||
} | ||
newEngine->get(stateL); | ||
return newEngine; | ||
} | ||
}; // namespace edm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters