Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:13

0001 #include "FWCore/Services/interface/ExternalRandomNumberGeneratorService.h"
0002 #include "FWCore/Utilities/interface/StreamID.h"
0003 
0004 #include "CLHEP/Random/JamesRandom.h"
0005 #include "CLHEP/Random/RanecuEngine.h"
0006 #include "CLHEP/Random/MixMaxRng.h"
0007 
0008 //#define CATCH_CONFIG_MAIN
0009 #include "catch.hpp"
0010 
0011 namespace {
0012   void test(CLHEP::HepRandomEngine& iRand, CLHEP::HepRandomEngine& iEngine) {
0013     REQUIRE(iRand.flat() == iEngine.flat());
0014     REQUIRE(iRand.flat() == iEngine.flat());
0015     REQUIRE(iRand.flat() == iEngine.flat());
0016     REQUIRE(iRand.flat() == iEngine.flat());
0017   }
0018 }  // namespace
0019 
0020 TEST_CASE("Test ExternalRandomNumberGeneratorService", "[externalrandomnumbergeneratorservice]") {
0021   SECTION("JamesRandom") {
0022     edm::ExternalRandomNumberGeneratorService service;
0023     CLHEP::HepJamesRandom rand(12345);
0024 
0025     service.setState(rand.put(), rand.getSeed());
0026     test(rand, service.getEngine(edm::StreamID::invalidStreamID()));
0027 
0028     //advance the one to see how it works
0029     rand.flat();
0030     service.setState(rand.put(), rand.getSeed());
0031     test(rand, service.getEngine(edm::StreamID::invalidStreamID()));
0032   }
0033 
0034   SECTION("RanecuEngine") {
0035     edm::ExternalRandomNumberGeneratorService service;
0036     CLHEP::RanecuEngine rand(12345);
0037 
0038     service.setState(rand.put(), rand.getSeed());
0039     test(rand, service.getEngine(edm::StreamID::invalidStreamID()));
0040 
0041     //advance the one to see how it works
0042     rand.flat();
0043     service.setState(rand.put(), rand.getSeed());
0044     test(rand, service.getEngine(edm::StreamID::invalidStreamID()));
0045   }
0046 
0047   SECTION("MixMaxRng") {
0048     edm::ExternalRandomNumberGeneratorService service;
0049     CLHEP::MixMaxRng rand(12345);
0050 
0051     service.setState(rand.put(), rand.getSeed());
0052     test(rand, service.getEngine(edm::StreamID::invalidStreamID()));
0053 
0054     //advance the one to see how it works
0055     rand.flat();
0056     service.setState(rand.put(), rand.getSeed());
0057     test(rand, service.getEngine(edm::StreamID::invalidStreamID()));
0058   }
0059 }