Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:04

0001 // -*- C++ -*-
0002 //
0003 // Package:     IOMC/RandomEngine
0004 // Class  :     cloneEngine
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Christopher Jones
0010 //         Created:  Fri, 02 Dec 2022 19:34:37 GMT
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
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       // Sanity check, it should not be possible for this to happen.
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 };  // namespace edm