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)
13 namespace mixmax_17 {
14 #elif (ROOT_MM_N==240)
15 namespace mixmax_240 {
16 #elif (ROOT_MM_N==256)
17 namespace mixmax_256 {
18 #else
19 namespace {
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)
36 using namespace mixmax_17;
37 #elif (ROOT_MM_N==240)
38 using namespace mixmax_240;
39 #elif (ROOT_MM_N==256)
40 using namespace mixmax_256;
41 #endif
42 
43 
44 namespace 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 
68 template<>
71 public:
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
ROOT::Math::MixMaxEngineImpl::MixMaxEngineImpl
MixMaxEngineImpl(uint64_t)
Definition: MixMaxEngineImpl.h:53
n
const Int_t n
Definition: legend1.C:16
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::Result_t
MixMaxEngine< ROOT_MM_N, 0 >::Result_t Result_t
Definition: MixMaxEngineImpl.h:74
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::SetCounter
void SetCounter(int val)
Definition: MixMaxEngineImpl.h:113
seed_uniquestream
void seed_uniquestream(rng_state_t *X, myID_t clusterID, myID_t machineID, myID_t runID, myID_t streamID)
Definition: mixmax.icc:361
MixMaxEngine.h
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::Counter
int Counter() const
Definition: MixMaxEngineImpl.h:110
rng_state_st::V
myuint V[N]
Definition: mixmax.h:54
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::IntRndm
Result_t IntRndm()
Definition: MixMaxEngineImpl.h:94
ROOT::Math::MixMaxEngineImpl::Counter
int Counter()
Definition: MixMaxEngineImpl.h:62
rng_free
int rng_free(rng_state_t *X)
Definition: mixmax.icc:162
rng_get_N
int rng_get_N(void)
Definition: mixmax.icc:240
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::StateInt_t
MixMaxEngine< ROOT_MM_N, 0 >::StateInt_t StateInt_t
Definition: MixMaxEngineImpl.h:73
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::GetState
void GetState(std::vector< StateInt_t > &state) const
Definition: MixMaxEngineImpl.h:101
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::ReadState
void ReadState(const char filename[])
Definition: MixMaxEngineImpl.h:124
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::RndmArray
void RndmArray(int n, double *array)
Definition: MixMaxEngineImpl.h:121
ROOT::Math::MixMaxEngineImpl::SetCounter
void SetCounter(int)
Definition: MixMaxEngineImpl.h:63
rng_state_st::counter
int counter
Definition: mixmax.h:56
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::Rndm
double Rndm()
Definition: MixMaxEngineImpl.h:90
rng_alloc
rng_state_t * rng_alloc()
Definition: mixmax.icc:154
mixmax.icc
ROOT::Math::MixMaxEngineImpl::Rndm
double Rndm()
Definition: MixMaxEngineImpl.h:58
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::Size
static int Size()
Definition: MixMaxEngineImpl.h:116
read_state
void read_state(rng_state_t *X, const char filename[])
Definition: mixmax.icc:286
get_next_float
double get_next_float(rng_state_t *X)
Definition: mixmax.icc:81
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::fRngState
rng_state_t * fRngState
Definition: MixMaxEngineImpl.h:70
ROOT::Math::MixMaxEngineImpl::~MixMaxEngineImpl
~MixMaxEngineImpl()
Definition: MixMaxEngineImpl.h:56
get_next
myuint get_next(rng_state_t *X)
Definition: mixmax.icc:77
ROOT::Math::MixMaxEngineImpl
Definition: MixMaxEngineImpl.h:51
ROOT::Math::MixMaxEngineImpl::SetState
void SetState(const std::vector< uint64_t > &)
Definition: MixMaxEngineImpl.h:60
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::SetSeed
void SetSeed(Result_t seed)
Definition: MixMaxEngineImpl.h:86
ROOT::Math::MixMaxEngineImpl::IntRndm
double IntRndm()
Definition: MixMaxEngineImpl.h:59
rng_state_st
Definition: mixmax.h:53
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::~MixMaxEngineImpl
~MixMaxEngineImpl()
Definition: MixMaxEngineImpl.h:80
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::MixMaxEngineImpl
MixMaxEngineImpl(uint64_t seed)
Definition: MixMaxEngineImpl.h:76
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::SetSeedFast
void SetSeedFast(Result_t seed)
Definition: MixMaxEngineImpl.h:83
ROOT_MM_N
#define ROOT_MM_N
Definition: MixMaxEngineImpl17.cxx:4
ROOT::Math::MixMaxEngineImpl::GetState
void GetState(std::vector< uint64_t > &)
Definition: MixMaxEngineImpl.h:61
ROOT::Math::MixMaxEngineImpl::Iterate
void Iterate()
Definition: MixMaxEngineImpl.h:64
rng_copy
rng_state_t * rng_copy(myuint *Y)
Definition: mixmax.icc:168
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::Branch
void Branch(uint32_t *seedvec)
Definition: MixMaxEngineImpl.h:128
ROOT::Math::MixMaxEngineImpl::SetSeed
void SetSeed(uint64_t)
Definition: MixMaxEngineImpl.h:57
seed_spbox
void seed_spbox(rng_state_t *X, myuint seed)
Definition: mixmax.icc:205
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::SetState
void SetState(const std::vector< StateInt_t > &state)
Definition: MixMaxEngineImpl.h:97
ROOT::Math::MixMaxEngineImpl< ROOT_MM_N >::Iterate
void Iterate()
Definition: MixMaxEngineImpl.h:107
ROOT::Math::MixMaxEngine::StateInt_t
uint64_t StateInt_t
Definition: MixMaxEngine.h:110
iterate
int iterate(rng_state_t *X)
Definition: mixmax.icc:34
branch_inplace
void branch_inplace(rng_state_t *Xin, myID_t *ID)
Definition: mixmax.icc:394
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
Math
Namespace for new Math classes and functions.
fill_array
void fill_array(rng_state_t *X, unsigned int n, double *array)
Definition: mixmax.icc:85
ROOT::Math::MixMaxEngine::Result_t
uint64_t Result_t
Definition: MixMaxEngine.h:114