Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
GSLRngWrapper.h
Go to the documentation of this file.
1// @(#)root/mathmore:$Id$
2// Author: L. Moneta Fri Aug 24 17:20:45 2007
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for class GSLRngWrapper
12
13#ifndef ROOT_Math_GSLRngWrapper
14#define ROOT_Math_GSLRngWrapper
15
16
17namespace ROOT {
18
19 namespace Math {
20
21
22/**
23 GSLRngWrapper class to wrap gsl_rng structure
24*/
26
27public:
28
29
30 /**
31 Default constructor
32 */
34 fOwn(0),
35 fRng(0),
36 fRngType(0)
37 {
38 }
39
40 /**
41 Constructor with type
42 */
43 GSLRngWrapper(const gsl_rng_type * type) :
44 fOwn(1),
45 fRng(0),
47 {
48 }
49
50 /**
51 construct from an existing gsl_rng
52 it is managed externally - so will not be deleted at the end
53 */
54 GSLRngWrapper(const gsl_rng * r ) :
55 fOwn(0),
56 fRngType(0)
57 {
58 fRng = const_cast<gsl_rng *>(r);
59 }
60
61 /**
62 Copy constructor - clone the GSL object and manage it
63 */
65 fOwn(1),
67 {
68 fRng = gsl_rng_clone(r.fRng);
69 }
70
71 /**
72 Assignment operator
73 */
75 if (this == &rhs) return *this; // time saving self-test
76 fRngType = rhs.fRngType;
77 int iret = 0;
78 if (fRngType == rhs.fRngType) {
79 iret = gsl_rng_memcpy(fRng, rhs.fRng);
80 if (!iret) return *this;
81 }
82 // otherwise create a new copy
83 if (fOwn) Free();
84 fRng = gsl_rng_clone(rhs.fRng);
85 fOwn = true;
86 return *this;
87 }
88
89 /**
90 Destructor (free the rng if not done before)
91 */
93 if (fOwn) Free();
94 }
95
96 void Allocate() {
97 if (fRngType == 0) SetDefaultType();
98 if (fRng != 0 && fOwn) Free();
99 fRng = gsl_rng_alloc( fRngType );
100 fOwn = true;
101 }
102
103 void Free() {
104 if (!fOwn) return; // no operation if pointer is not own
105 //std::cout << "free gslrng " << fRngType << " " << fRng << std::endl;
106 if (fRng != 0) gsl_rng_free(fRng);
107 fRng = 0;
108 }
109
110
111 void SetType(const gsl_rng_type * type) {
112 fRngType = type;
113 }
114
116 // construct default engine
117 gsl_rng_env_setup();
118 fRngType = gsl_rng_default;
119 }
120
121 void PrintState() const {
122 gsl_rng_print_state(fRng);
123 }
124
125 inline gsl_rng * Rng() { return fRng; }
126
127 inline const gsl_rng * Rng() const { return fRng; }
128
129
130
131private:
132
133 bool fOwn; // ownership of contained pointer
134 gsl_rng * fRng;
135 const gsl_rng_type * fRngType;
136};
137
138
139 } // end namespace Math
140
141} // end namespace ROOT
142
143
144#endif /* ROOT_Math_GSLRngWrapper */
ROOT::R::TRInterface & r
Definition Object.C:4
int type
Definition TGX11.cxx:121
GSLRngWrapper class to wrap gsl_rng structure.
GSLRngWrapper(const gsl_rng *r)
construct from an existing gsl_rng it is managed externally - so will not be deleted at the end
GSLRngWrapper & operator=(const GSLRngWrapper &rhs)
Assignment operator.
GSLRngWrapper(const gsl_rng_type *type)
Constructor with type.
~GSLRngWrapper()
Destructor (free the rng if not done before)
const gsl_rng_type * fRngType
void SetType(const gsl_rng_type *type)
GSLRngWrapper()
Default constructor.
GSLRngWrapper(GSLRngWrapper &r)
Copy constructor - clone the GSL object and manage it.
const gsl_rng * Rng() const
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...