CMS 3D CMS Logo

cloneEngine.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: IOMC/RandomEngine
4 // Class : cloneEngine
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Christopher Jones
10 // Created: Fri, 02 Dec 2022 19:34:37 GMT
11 //
12 
13 // system include files
14 
15 // user include files
18 
20 
21 #include "CLHEP/Random/engineIDulong.h"
22 #include "CLHEP/Random/JamesRandom.h"
23 #include "CLHEP/Random/RanecuEngine.h"
24 #include "CLHEP/Random/MixMaxRng.h"
25 
26 namespace edm {
27  std::unique_ptr<CLHEP::HepRandomEngine> cloneEngine(CLHEP::HepRandomEngine const& existingEngine) {
28  std::vector<unsigned long> stateL = existingEngine.put();
29  long seedL = existingEngine.getSeed();
30  std::unique_ptr<CLHEP::HepRandomEngine> newEngine;
31  if (stateL[0] == CLHEP::engineIDulong<CLHEP::HepJamesRandom>()) {
32  newEngine = std::make_unique<CLHEP::HepJamesRandom>(seedL);
33  } else if (stateL[0] == CLHEP::engineIDulong<CLHEP::RanecuEngine>()) {
34  newEngine = std::make_unique<CLHEP::RanecuEngine>();
35  } else if (stateL[0] == CLHEP::engineIDulong<CLHEP::MixMaxRng>()) {
36  newEngine = std::make_unique<CLHEP::MixMaxRng>(seedL);
37  } else if (stateL[0] == CLHEP::engineIDulong<TRandomAdaptor>()) {
38  newEngine = std::make_unique<TRandomAdaptor>(seedL);
39  } else {
40  // Sanity check, it should not be possible for this to happen.
41  throw Exception(errors::Unknown) << "The RandomNumberGeneratorService is trying to clone unknown engine type\n";
42  }
43  newEngine->get(stateL);
44  return newEngine;
45  }
46 }; // namespace edm
std::unique_ptr< CLHEP::HepRandomEngine > cloneEngine(CLHEP::HepRandomEngine const &)
Definition: cloneEngine.cc:27
HLT enums.