Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:06:53

0001 #ifndef GeneratorInterface_Herwig7Interface_RandomEngineGlue_h
0002 #define GeneratorInterface_Herwig7Interface_RandomEngineGlue_h
0003 
0004 #include <string>
0005 
0006 #include <ThePEG/Interface/ClassDocumentation.h>
0007 #include <ThePEG/Interface/InterfacedBase.h>
0008 #include <ThePEG/Interface/Parameter.h>
0009 #include <ThePEG/Utilities/ClassTraits.h>
0010 
0011 #include <ThePEG/Repository/StandardRandom.h>
0012 
0013 #include "GeneratorInterface/Herwig7Interface/interface/Proxy.h"
0014 #include "CLHEP/Random/RandomEngine.h"
0015 
0016 namespace CLHEP {
0017   class HepRandomEngine;  // forward declaration
0018 }
0019 
0020 namespace ThePEG {
0021 
0022   class RandomEngineGlue : public RandomGenerator {
0023   public:
0024     RandomEngineGlue();
0025     ~RandomEngineGlue() override;
0026 
0027     void setRandomEngine(CLHEP::HepRandomEngine* v) { randomEngine = v; }
0028     CLHEP::HepRandomEngine* getRandomEngine() const { return randomEngine; }
0029     void flush();
0030 
0031     static void Init();
0032 
0033     class Proxy : public ThePEG::Proxy<Proxy> {
0034     public:
0035       RandomEngineGlue* getInstance() const { return instance; }
0036 
0037       CLHEP::HepRandomEngine* getRandomEngine() const { return randomEngine; }
0038       void setRandomEngine(CLHEP::HepRandomEngine* v) { randomEngine = v; }
0039 
0040     private:
0041       friend class RandomEngineGlue;
0042       friend class ThePEG::Proxy<Proxy>;
0043 
0044       inline Proxy(ProxyID id) : Base(id), instance(nullptr) {}
0045 
0046       RandomEngineGlue* instance;
0047 
0048       // I do not like putting this here, but I could not
0049       // think of an alternative without modifying the
0050       // external code in ThePEG. The problem is the
0051       // function ThePEG::Repository::makeRun both
0052       // sets the pointer in the proxy and uses the
0053       // engine. There is no opportunity to set the
0054       // engine pointer before it is used without passing
0055       // it in through the proxy.
0056       CLHEP::HepRandomEngine* randomEngine;
0057     };
0058 
0059   protected:
0060     void fill() override;
0061     void setSeed(long seed) override;
0062 
0063     IBPtr clone() const override { return new_ptr(*this); }
0064     IBPtr fullclone() const override { return new_ptr(*this); }
0065 
0066     void doinit() noexcept(false) override;
0067 
0068   private:
0069     Proxy::ProxyID proxyID;
0070     CLHEP::HepRandomEngine* randomEngine;
0071 
0072     static ClassDescription<RandomEngineGlue> initRandomEngineGlue;
0073   };
0074 
0075   template <>
0076   struct BaseClassTrait<RandomEngineGlue, 1> : public ClassTraitsType {
0077     /** Typedef of the first base class of RandomEngineGlue. */
0078     typedef RandomGenerator NthBase;
0079   };
0080 
0081   /** This template specialization informs ThePEG about the name of the
0082  *  RandomEngineGlue class. */
0083   template <>
0084   struct ClassTraits<RandomEngineGlue> : public ClassTraitsBase<RandomEngineGlue> {
0085     /** Return a platform-independent class name */
0086     static string className() { return "ThePEG::RandomEngineGlue"; }
0087     static string library() { return "libGeneratorInterfaceHerwig7Interface.so"; }
0088   };
0089 
0090 }  // namespace ThePEG
0091 
0092 #endif  // GeneratorInterface_Herwig7Interface_RandomEngineGlue_h