CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RandomEngineGlue.h
Go to the documentation of this file.
1 #ifndef GeneratorInterface_Herwig7Interface_RandomEngineGlue_h
2 #define GeneratorInterface_Herwig7Interface_RandomEngineGlue_h
3 
4 #include <string>
5 
6 #include <ThePEG/Interface/ClassDocumentation.h>
7 #include <ThePEG/Interface/InterfacedBase.h>
8 #include <ThePEG/Interface/Parameter.h>
9 #include <ThePEG/Utilities/ClassTraits.h>
10 
11 #include <ThePEG/Repository/StandardRandom.h>
12 
14 #include "CLHEP/Random/RandomEngine.h"
15 
16 namespace CLHEP {
17  class HepRandomEngine; // forward declaration
18 }
19 
20 namespace ThePEG {
21 
22  class RandomEngineGlue : public RandomGenerator {
23  public:
25  ~RandomEngineGlue() override;
26 
27  void setRandomEngine(CLHEP::HepRandomEngine* v) { randomEngine = v; }
28  CLHEP::HepRandomEngine* getRandomEngine() const { return randomEngine; }
29  void flush();
30 
31  static void Init();
32 
33  class Proxy : public ThePEG::Proxy<Proxy> {
34  public:
35  RandomEngineGlue* getInstance() const { return instance; }
36 
37  CLHEP::HepRandomEngine* getRandomEngine() const { return randomEngine; }
38  void setRandomEngine(CLHEP::HepRandomEngine* v) { randomEngine = v; }
39 
40  private:
41  friend class RandomEngineGlue;
42  friend class ThePEG::Proxy<Proxy>;
43 
44  inline Proxy(ProxyID id) : Base(id), instance(nullptr) {}
45 
47 
48  // I do not like putting this here, but I could not
49  // think of an alternative without modifying the
50  // external code in ThePEG. The problem is the
51  // function ThePEG::Repository::makeRun both
52  // sets the pointer in the proxy and uses the
53  // engine. There is no opportunity to set the
54  // engine pointer before it is used without passing
55  // it in through the proxy.
56  CLHEP::HepRandomEngine* randomEngine;
57  };
58 
59  protected:
60  void fill() override;
61  void setSeed(long seed) override;
62 
63  IBPtr clone() const override { return new_ptr(*this); }
64  IBPtr fullclone() const override { return new_ptr(*this); }
65 
66  void doinit() noexcept(false) override;
67 
68  private:
70  CLHEP::HepRandomEngine* randomEngine;
71 
72  static ClassDescription<RandomEngineGlue> initRandomEngineGlue;
73  };
74 
75  template <>
76  struct BaseClassTrait<RandomEngineGlue, 1> : public ClassTraitsType {
78  typedef RandomGenerator NthBase;
79  };
80 
83  template <>
84  struct ClassTraits<RandomEngineGlue> : public ClassTraitsBase<RandomEngineGlue> {
86  static string className() { return "ThePEG::RandomEngineGlue"; }
87  static string library() { return "libGeneratorInterfaceHerwig7Interface.so"; }
88  };
89 
90 } // namespace ThePEG
91 
92 #endif // GeneratorInterface_Herwig7Interface_RandomEngineGlue_h
void setRandomEngine(CLHEP::HepRandomEngine *v)
CLHEP::HepRandomEngine * getRandomEngine() const
RandomEngineGlue * getInstance() const
void setSeed(long seed) override
void doinit() noexcept(false) override
CLHEP::HepRandomEngine * randomEngine
IBPtr fullclone() const override
unsigned long ProxyID
Definition: Proxy.h:16
void setRandomEngine(CLHEP::HepRandomEngine *v)
IBPtr clone() const override
def template
Definition: svgfig.py:521
CLHEP::HepRandomEngine * randomEngine
CLHEP::HepRandomEngine * getRandomEngine() const
static ClassDescription< RandomEngineGlue > initRandomEngineGlue