CMS 3D CMS Logo

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