File indexing completed on 2023-03-17 11:10:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "IOMC/RandomEngine/interface/cloneEngine.h"
0017 #include "IOMC/RandomEngine/interface/TRandomAdaptor.h"
0018
0019 #include "FWCore/Utilities/interface/EDMException.h"
0020
0021 #include "CLHEP/Random/engineIDulong.h"
0022 #include "CLHEP/Random/JamesRandom.h"
0023 #include "CLHEP/Random/RanecuEngine.h"
0024 #include "CLHEP/Random/MixMaxRng.h"
0025
0026 namespace edm {
0027 std::unique_ptr<CLHEP::HepRandomEngine> cloneEngine(CLHEP::HepRandomEngine const& existingEngine) {
0028 std::vector<unsigned long> stateL = existingEngine.put();
0029 long seedL = existingEngine.getSeed();
0030 std::unique_ptr<CLHEP::HepRandomEngine> newEngine;
0031 if (stateL[0] == CLHEP::engineIDulong<CLHEP::HepJamesRandom>()) {
0032 newEngine = std::make_unique<CLHEP::HepJamesRandom>(seedL);
0033 } else if (stateL[0] == CLHEP::engineIDulong<CLHEP::RanecuEngine>()) {
0034 newEngine = std::make_unique<CLHEP::RanecuEngine>();
0035 } else if (stateL[0] == CLHEP::engineIDulong<CLHEP::MixMaxRng>()) {
0036 newEngine = std::make_unique<CLHEP::MixMaxRng>(seedL);
0037 } else if (stateL[0] == CLHEP::engineIDulong<TRandomAdaptor>()) {
0038 newEngine = std::make_unique<TRandomAdaptor>(seedL);
0039 } else {
0040
0041 throw Exception(errors::Unknown) << "The RandomNumberGeneratorService is trying to clone unknown engine type\n";
0042 }
0043 newEngine->get(stateL);
0044 return newEngine;
0045 }
0046 };