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