Logo ROOT  
Reference Guide
MixMaxEngineImpl.h
Go to the documentation of this file.
1
2
3#include <stdio.h>
4#include <stdint.h>
5#include <stdlib.h>
6
7#ifndef ROOT_Math_MixMaxEngineImpl
8#define ROOT_Math_MixMaxEngineImpl
9
10
11#if (ROOT_MM_N==17)
12namespace mixmax_17 {
13#elif (ROOT_MM_N==240)
14namespace mixmax_240 {
15#elif (ROOT_MM_N==256)
16namespace mixmax_256 {
17#else
18namespace {
19#endif
20
21#ifdef WIN32
22#define __thread __declspec(thread)
23#endif
24
25#include "mixmax.icc"
26
27#undef N
28}
29
30#include "Math/MixMaxEngine.h"
31
32#include <iostream>
33
34#if (ROOT_MM_N==17)
35using namespace mixmax_17;
36#elif (ROOT_MM_N==240)
37using namespace mixmax_240;
38#elif (ROOT_MM_N==256)
39using namespace mixmax_256;
40#endif
41
42
43namespace ROOT {
44 namespace Math {
45
46
47
48 // dummy implementation
49 template<int N>
51 public:
52 MixMaxEngineImpl(uint64_t) {
53 std::cerr << "MixMaxEngineImpl - These template parameters are not supported for MixMaxEngine" << std::endl;
54 }
56 void SetSeed(uint64_t) { }
57 double Rndm() { return -1; }
58 double IntRndm() { return 0; }
59 void SetState(const std::vector<uint64_t> &) { }
60 void GetState(std::vector<uint64_t> &) { }
61 int Counter() { return -1; }
62 void SetCounter(int) {}
63 void Iterate() {}
64 };
65
66
67template<>
70public:
71
74
75 MixMaxEngineImpl(uint64_t seed) {
76 fRngState = rng_alloc();
77 SetSeed(seed);
78 }
80 rng_free(fRngState);
81 }
82 void SetSeedFast(Result_t seed) {
83 seed_spbox(fRngState, seed);
84 }
85 void SetSeed(Result_t seed) {
86 //seed_spbox(fRngState, seed);
87 seed_uniquestream(fRngState, 0, 0, (uint32_t)(seed>>32), (uint32_t)seed );
88 }
89 double Rndm() {
90 return get_next_float(fRngState);
91 }
92 // generate one integer number
94 return get_next(fRngState);
95 }
96 void SetState(const std::vector<StateInt_t> & state) {
97 if (fRngState) rng_free(fRngState);
98 fRngState = rng_copy(const_cast<StateInt_t*>(state.data()) );
99 }
100 void GetState(std::vector<StateInt_t> & state) const {
101 int n = rng_get_N();
102 state.resize(n);
103 for (int i = 0; i < n; ++i)
104 state[i] = fRngState->V[i];
105 }
106 void Iterate() {
107 iterate(fRngState);
108 }
109 int Counter() const {
110 return fRngState->counter;
111 }
112 void SetCounter(int val) {
113 fRngState->counter = val;
114 }
115 static int Size() {
116 return rng_get_N();
117 }
118
119 // to silent some warning
120 void RndmArray(int n, double * array) {
121 fill_array(fRngState, n, array);
122 }
123 void ReadState(const char filename[] ) {
124 read_state(fRngState, filename);
125 }
126 // branch generator given a vector of seed (at least 4 32 bit values)
127 void Branch(uint32_t * seedvec) {
128 branch_inplace(fRngState, seedvec);
129 }
130
131
132};
133
134
135 } // end namesapce Math
136} // end namespace ROOT
137
138#endif
#define ROOT_MM_N
MixMaxEngine< ROOT_MM_N, 0 >::Result_t Result_t
void SetState(const std::vector< StateInt_t > &state)
MixMaxEngine< ROOT_MM_N, 0 >::StateInt_t StateInt_t
void GetState(std::vector< StateInt_t > &state) const
void SetState(const std::vector< uint64_t > &)
void GetState(std::vector< uint64_t > &)
const Int_t n
Definition: legend1.C:16
void seed_spbox(rng_state_t *X, myuint seed)
Definition: mixmax.icc:205
int rng_get_N(void)
Definition: mixmax.icc:240
int iterate(rng_state_t *X)
Definition: mixmax.icc:34
void branch_inplace(rng_state_t *Xin, myID_t *ID)
Definition: mixmax.icc:394
void seed_uniquestream(rng_state_t *X, myID_t clusterID, myID_t machineID, myID_t runID, myID_t streamID)
Definition: mixmax.icc:361
rng_state_t * rng_alloc()
Definition: mixmax.icc:154
rng_state_t * rng_copy(myuint *Y)
Definition: mixmax.icc:168
int rng_free(rng_state_t *X)
Definition: mixmax.icc:162
void read_state(rng_state_t *X, const char filename[])
Definition: mixmax.icc:286
void fill_array(rng_state_t *X, unsigned int n, double *array)
Definition: mixmax.icc:85
double get_next_float(rng_state_t *X)
Definition: mixmax.icc:81
myuint get_next(rng_state_t *X)
Definition: mixmax.icc:77
Namespace for new Math classes and functions.
VSD Structures.
Definition: StringConv.hxx:21
myuint V[N]
Definition: mixmax.h:54
int counter
Definition: mixmax.h:56