Logo ROOT   6.12/07
Reference Guide
GSLRngROOTWrapper.h
Go to the documentation of this file.
1 // wrapper class used to wrap ROOT random number engines with GSL interface
2 
3 // @(#)root/mathmore:$Id$
4 // Author: L. Moneta Fri Aug 24 17:20:45 2007
5 
6 /**********************************************************************
7  * *
8  * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
9  * *
10  * *
11  **********************************************************************/
12 
13 // Header file for class GSLRngWrapper
14 
15 #ifndef ROOT_Math_GSLRngROOTWrapper
16 #define ROOT_Math_GSLRngROOTWrapper
17 
18 #include "gsl/gsl_rng.h"
19 
20 
21 namespace ROOT {
22 
23  namespace Math {
24 
25  template<class Engine>
27 
28  Engine * fEngine;
29  bool fFirst;
30 
31 
33  fEngine = nullptr;
34  fFirst = false;
35  }
36 
38  if (fEngine) delete fEngine;
39  }
40 
41  static double Rndm(void * p) {
42  return ((GSLRngROOTWrapper *) p)->fEngine->operator()();
43  }
44  static unsigned long IntRndm(void * p) {
45  return ((GSLRngROOTWrapper *) p)->fEngine->IntRndm();
46  }
47  static void Seed(void * p, unsigned long seed) {
48  //if (fFirst) {
49  // this will be a memory leak because I have no way to delete
50  // the engine class
51  auto wr = ((GSLRngROOTWrapper *) p);
52  if (wr->fFirst) {
53  //printf("calling the seed function with %d on %p . Build Engine class \n",seed,p);
54  wr->fEngine = new Engine();
55  wr->fFirst = false;
56  }
57  // the seed cannot be zero (GSL calls at the beginning with seed 0)
58  if (seed == 0) return;
59  ((GSLRngROOTWrapper *) p)->fEngine->SetSeed(seed);
60  }
61  static void Free(void *p) {
62  auto wr = ((GSLRngROOTWrapper *) p);
63  if (wr->fEngine) delete wr->fEngine;
64  wr->fFirst = true;
65  //printf("deleting gsl mixmax\n");
66  }
67 
68  static unsigned long Max() { return Engine::MaxInt(); }
69  static unsigned long Min() { return Engine::MinInt(); }
70  static size_t Size() { return sizeof( GSLRngROOTWrapper<Engine>); }
71  static std::string Name() { return std::string("GSL_")+Engine::Name(); }
72  };
73  }
74 }
75 
76 #include "Math/MixMaxEngine.h"
77 
78 // now define and implement the specific types
79 
81 
82 static const gsl_rng_type mixmax_type =
83 {
84  GSLMixMaxWrapper::Name().c_str(),
91 };
92 
93 const gsl_rng_type *gsl_rng_mixmax = &mixmax_type;
94 
95 #endif
96 
static unsigned long IntRndm(void *p)
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
static void Seed(void *p, unsigned long seed)
const char * Name
Definition: TXMLSetup.cxx:66
static const gsl_rng_type mixmax_type
static double Rndm(void *p)
static unsigned long Max()
Namespace for new Math classes and functions.
static unsigned long Min()
ROOT::Math::GSLRngROOTWrapper< ROOT::Math::MixMaxEngine< 240, 0 > > GSLMixMaxWrapper
const gsl_rng_type * gsl_rng_mixmax