Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:43

0001 #include <string>
0002 
0003 #include <CLHEP/Random/RandomEngine.h>
0004 
0005 #include <ThePEG/Interface/ClassDocumentation.h>
0006 #include <ThePEG/Interface/InterfacedBase.h>
0007 #include <ThePEG/Interface/Parameter.h>
0008 #include <ThePEG/Utilities/ClassTraits.h>
0009 
0010 #include <ThePEG/Repository/StandardRandom.h>
0011 
0012 #include "GeneratorInterface/Herwig7Interface/interface/RandomEngineGlue.h"
0013 
0014 #include "FWCore/Utilities/interface/EDMException.h"
0015 
0016 using namespace ThePEG;
0017 
0018 RandomEngineGlue::RandomEngineGlue() : randomEngine(nullptr) {}
0019 
0020 RandomEngineGlue::~RandomEngineGlue() {}
0021 
0022 void RandomEngineGlue::flush() {
0023   RandomGenerator::flush();
0024   gaussSaved = false;
0025 }
0026 
0027 void RandomEngineGlue::fill() {
0028   if (randomEngine == nullptr) {
0029     throw edm::Exception(edm::errors::LogicError) << "The PEG code attempted to a generate random number while\n"
0030                                                   << "the engine pointer was null. This might mean that the code\n"
0031                                                   << "was tried to generate a random number outside the event and\n"
0032                                                   << "beginLuminosityBlock methods, which is not allowed.\n";
0033   }
0034   nextNumber = theNumbers.begin();
0035   for (RndVector::iterator it = nextNumber; it != theNumbers.end(); ++it)
0036     *it = randomEngine->flat();
0037 }
0038 
0039 void RandomEngineGlue::setSeed(long seed) {
0040   // we ignore this, CMSSW overrides the seed from ThePEG
0041 }
0042 
0043 void RandomEngineGlue::doinit() noexcept(false) {
0044   RandomGenerator::doinit();
0045 
0046   std::shared_ptr<Proxy> proxy = Proxy::find(proxyID);
0047   if (!proxy)
0048     throw InitException();
0049 
0050   proxy->instance = this;
0051   randomEngine = proxy->getRandomEngine();
0052   flush();
0053 }
0054 
0055 ClassDescription<RandomEngineGlue> RandomEngineGlue::initRandomEngineGlue;
0056 
0057 void RandomEngineGlue::Init() {
0058   typedef Proxy::ProxyID ProxyID;
0059 
0060   static ClassDocumentation<RandomEngineGlue> documentation("Interface to the CMSSW RandomNumberEngine.");
0061   static Parameter<RandomEngineGlue, ProxyID> interfaceProxyID(
0062       "ProxyID", "The ProxyID.", &RandomEngineGlue::proxyID, ProxyID(), ProxyID(), ProxyID(), false, false, false);
0063 
0064   interfaceProxyID.rank(11);
0065 }