Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
GSLQRngWrapper.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 GSLQRngWrapper
12
13#ifndef ROOT_Math_GSLQRngWrapper
14#define ROOT_Math_GSLQRngWrapper
15
16#include "gsl/gsl_qrng.h"
17
18namespace ROOT {
19
20 namespace Math {
21
22
23/**
24 GSLQRngWrapper class to wrap gsl_qrng structure
25*/
27
28public:
29
30
31 /**
32 Default constructor
33 */
35 fOwn(0),
36 fRng(nullptr),
37 fRngType(nullptr)
38 {
39 }
40
41 /**
42 Constructor with type
43 */
44 GSLQRngWrapper(const gsl_qrng_type * type) :
45 fOwn(1),
46 fRng(nullptr),
48 {
49 }
50
51 /**
52 construct from an existing gsl_qrng
53 it is managed externally - so will not be deleted at the end
54 */
55 GSLQRngWrapper(const gsl_qrng * r ) :
56 fOwn(0),
57 fRngType(nullptr)
58 {
59 fRng = const_cast<gsl_qrng *>(r);
60 }
61
62 /**
63 Copy constructor - clone the GSL object and manage it
64 */
66 fOwn(1),
68 {
69 fRng = gsl_qrng_clone(r.fRng);
70 }
71
72 /**
73 Assignment operator
74 */
76 if (this == &rhs) return *this; // time saving self-test
77 fRngType = rhs.fRngType;
78 int iret = 0;
79 if (fRngType == rhs.fRngType) {
80 iret = gsl_qrng_memcpy(fRng, rhs.fRng);
81 if (!iret) return *this;
82 }
83 // otherwise create a new copy
84 if (fOwn) Free();
85 fRng = gsl_qrng_clone(rhs.fRng);
86 fOwn = true;
87 return *this;
88 }
89
90 /**
91 Destructor (free the rng if not done before)
92 */
94 if (fOwn) Free();
95 }
96
97 void Allocate(unsigned int dimension) {
98 if (fRngType == nullptr) SetDefaultType();
99 if (fRng != nullptr && fOwn) Free();
100 fRng = gsl_qrng_alloc( fRngType, dimension );
101 //std::cout << " allocate " << fRng << std::endl;
102 }
103
104 void Free() {
105 if (!fOwn) return; // no operation if pointer is not own
106 //std::cout << "free gslrng " << fRngType << " " << fRng << std::endl;
107 if (fRng != nullptr) gsl_qrng_free(fRng);
108 fRng = nullptr;
109 }
110
111
112 void SetType(const gsl_qrng_type * type) {
113 fRngType = type;
114 }
115
117 // construct default engine (Sobol)
118 fRngType = gsl_qrng_sobol;
119 }
120
121
122 unsigned int Dimension() const { return fRng->dimension; }
123
124 inline gsl_qrng * Rng() { return fRng; }
125
126 inline const gsl_qrng * Rng() const { return fRng; }
127
128
129
130private:
131
132 bool fOwn; // ownership of contained pointer
133 gsl_qrng * fRng;
134 const gsl_qrng_type * fRngType;
135};
136
137
138 } // end namespace Math
139
140} // end namespace ROOT
141
142
143#endif /* ROOT_Math_GSLQRngWrapper */
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
GSLQRngWrapper class to wrap gsl_qrng structure.
void Allocate(unsigned int dimension)
unsigned int Dimension() const
void SetType(const gsl_qrng_type *type)
GSLQRngWrapper()
Default constructor.
const gsl_qrng_type * fRngType
GSLQRngWrapper(const gsl_qrng *r)
construct from an existing gsl_qrng it is managed externally - so will not be deleted at the end
GSLQRngWrapper(const gsl_qrng_type *type)
Constructor with type.
GSLQRngWrapper(GSLQRngWrapper &r)
Copy constructor - clone the GSL object and manage it.
const gsl_qrng * Rng() const
~GSLQRngWrapper()
Destructor (free the rng if not done before)
GSLQRngWrapper & operator=(const GSLQRngWrapper &rhs)
Assignment operator.
Namespace for new Math classes and functions.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.