CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ExternalRandomNumberGeneratorService.cc
Go to the documentation of this file.
2 
5 
8 
9 #include "CLHEP/Random/engineIDulong.h"
10 #include "CLHEP/Random/JamesRandom.h"
11 #include "CLHEP/Random/RanecuEngine.h"
12 #include "CLHEP/Random/MixMaxRng.h"
13 
15 
16 using namespace edm;
17 
18 namespace {
19  const std::vector<RandomEngineState> s_dummyStates;
20 }
21 
23 
24 void ExternalRandomNumberGeneratorService::setState(std::vector<unsigned long> const& iState, long iSeed) {
25  if (not engine_) {
26  engine_ = createFromState(iState, iSeed);
27  } else {
28  engine_->get(iState);
29  }
30 }
31 
32 std::vector<unsigned long> ExternalRandomNumberGeneratorService::getState() const { return engine_->put(); }
33 
34 CLHEP::HepRandomEngine& ExternalRandomNumberGeneratorService::getEngine(StreamID const&) { return *engine_; }
36  return *engine_;
37 }
38 
39 std::unique_ptr<CLHEP::HepRandomEngine> ExternalRandomNumberGeneratorService::cloneEngine(LuminosityBlockIndex const&) {
40  std::vector<unsigned long> stateL = engine_->put();
41 
42  long seedL = engine_->getSeed();
43  return createFromState(stateL, seedL);
44 }
45 
46 std::unique_ptr<CLHEP::HepRandomEngine> ExternalRandomNumberGeneratorService::createFromState(
47  std::vector<unsigned long> const& stateL, long seedL) const {
48  std::unique_ptr<CLHEP::HepRandomEngine> newEngine;
49  if (stateL[0] == CLHEP::engineIDulong<CLHEP::HepJamesRandom>()) {
50  newEngine = std::make_unique<CLHEP::HepJamesRandom>(seedL);
51  } else if (stateL[0] == CLHEP::engineIDulong<CLHEP::RanecuEngine>()) {
52  newEngine = std::make_unique<CLHEP::RanecuEngine>();
53  } else if (stateL[0] == CLHEP::engineIDulong<CLHEP::MixMaxRng>()) {
54  newEngine = std::make_unique<CLHEP::MixMaxRng>(seedL);
55  //} else if (stateL[0] == CLHEP::engineIDulong<TRandomAdaptor>()) {
56  // newEngine = std::make_unique<TRandomAdaptor>(seedL);
57  } else {
58  // Sanity check, it should not be possible for this to happen.
60  << "The ExternalRandomNumberGeneratorService is trying to clone unknown engine type\n";
61  }
62  if (stateL[0] != CLHEP::engineIDulong<CLHEP::RanecuEngine>()) {
63  newEngine->setSeed(seedL, 0);
64  }
65  newEngine->get(stateL);
66  return newEngine;
67 }
68 
69 std::uint32_t ExternalRandomNumberGeneratorService::mySeed() const { return 0; }
70 
72 
74 
76  std::vector<RandomEngineState> const& iStates) {}
77 void ExternalRandomNumberGeneratorService::setEventCache(StreamID, std::vector<RandomEngineState> const& iStates) {}
78 
79 std::vector<RandomEngineState> const& ExternalRandomNumberGeneratorService::getEventCache(StreamID const&) const {
80  return s_dummyStates;
81 }
82 
83 std::vector<RandomEngineState> const& ExternalRandomNumberGeneratorService::getLumiCache(
84  LuminosityBlockIndex const&) const {
85  return s_dummyStates;
86 }
87 
89 
91 void ExternalRandomNumberGeneratorService::print(std::ostream& os) const {}
std::unique_ptr< CLHEP::HepRandomEngine > engine_
void print(std::ostream &os) const final
For debugging purposes only.
std::unique_ptr< CLHEP::HepRandomEngine > cloneEngine(LuminosityBlockIndex const &) final
void setState(std::vector< unsigned long > const &, long seed)
void setLumiCache(LuminosityBlockIndex, std::vector< RandomEngineState > const &iStates) final
CLHEP::HepRandomEngine & getEngine(StreamID const &) final
Use this engine in event methods.
std::vector< RandomEngineState > const & getEventCache(StreamID const &) const final
std::vector< RandomEngineState > const & getLumiCache(LuminosityBlockIndex const &) const final
std::unique_ptr< CLHEP::HepRandomEngine > createFromState(std::vector< unsigned long > const &, long seed) const
void setEventCache(StreamID, std::vector< RandomEngineState > const &iStates) final