CMS 3D CMS Logo

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 <boost/shared_ptr.hpp>
7 
8 #include <ThePEG/Interface/ClassDocumentation.h>
9 #include <ThePEG/Interface/InterfacedBase.h>
10 #include <ThePEG/Interface/Parameter.h>
11 #include <ThePEG/Utilities/ClassTraits.h>
12 
13 #include <ThePEG/Repository/StandardRandom.h>
14 
16 #include "CLHEP/Random/RandomEngine.h"
17 
18 namespace CLHEP {
19  class HepRandomEngine; // forward declaration
20 }
21 
22 namespace ThePEG {
23 
24 class RandomEngineGlue : public RandomGenerator {
25  public:
27  ~RandomEngineGlue() override;
28 
29  void setRandomEngine(CLHEP::HepRandomEngine* v) { randomEngine = v; }
30  CLHEP::HepRandomEngine* getRandomEngine() const { return randomEngine; }
31  void flush();
32 
33  static void Init();
34 
35  class Proxy : public ThePEG::Proxy<Proxy> {
36  public:
37  RandomEngineGlue *getInstance() const { return instance; }
38 
39  CLHEP::HepRandomEngine* getRandomEngine() const { return randomEngine; }
40  void setRandomEngine(CLHEP::HepRandomEngine* v) { randomEngine = v; }
41 
42  private:
43  friend class RandomEngineGlue;
44  friend class ThePEG::Proxy<Proxy>;
45 
46  inline Proxy(ProxyID id) : Base(id), instance(nullptr) {}
47 
49 
50  // I do not like putting this here, but I could not
51  // think of an alternative without modifying the
52  // external code in ThePEG. The problem is the
53  // function ThePEG::Repository::makeRun both
54  // sets the pointer in the proxy and uses the
55  // engine. There is no opportunity to set the
56  // engine pointer before it is used without passing
57  // it in through the proxy.
58  CLHEP::HepRandomEngine *randomEngine;
59  };
60 
61  protected:
62  void fill() override;
63  void setSeed(long seed) override;
64 
65  IBPtr clone() const override { return new_ptr(*this); }
66  IBPtr fullclone() const override { return new_ptr(*this); }
67 
68  void doinit() noexcept(false) override;
69 
70  private:
72  CLHEP::HepRandomEngine *randomEngine;
73 
74  static ClassDescription<RandomEngineGlue> initRandomEngineGlue;
75 };
76 
77 template<>
78 struct BaseClassTrait<RandomEngineGlue, 1> : public ClassTraitsType {
80  typedef RandomGenerator NthBase;
81 };
82 
85 template<>
86 struct ClassTraits<RandomEngineGlue> :
87  public ClassTraitsBase<RandomEngineGlue> {
89  static string className() { return "ThePEG::RandomEngineGlue"; }
90  static string library() { return "libGeneratorInterfaceHerwig7Interface.so"; }
91 };
92 
93 } // namespace ThePEG
94 
95 #endif // GeneratorInterface_Herwig7Interface_RandomEngineGlue_h
CLHEP::HepRandomEngine * randomEngine
Definition: Dummies.cc:7
void setRandomEngine(CLHEP::HepRandomEngine *v)
CLHEP::HepRandomEngine * getRandomEngine() const
static PFTauRenderPlugin instance
RandomEngineGlue * getInstance() const
#define nullptr
IBPtr fullclone() const override
IBPtr clone() const override
#define noexcept
CLHEP::HepRandomEngine * randomEngine
unsigned long ProxyID
Definition: Proxy.h:16
void setRandomEngine(CLHEP::HepRandomEngine *v)
CLHEP::HepRandomEngine * randomEngine
CLHEP::HepRandomEngine * getRandomEngine() const
static ClassDescription< RandomEngineGlue > initRandomEngineGlue