Logo ROOT   6.13/01
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)
12 namespace mixmax_17 {
13 #elif (ROOT_MM_N==240)
14 namespace mixmax_240 {
15 #elif (ROOT_MM_N==256)
16 namespace mixmax_256 {
17 #else
18 namespace {
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)
35 using namespace mixmax_17;
36 #elif (ROOT_MM_N==240)
37 using namespace mixmax_240;
38 #elif (ROOT_MM_N==256)
39 using namespace mixmax_256;
40 #endif
41 
42 
43 namespace ROOT {
44  namespace Math {
45 
46 
47 
48  // dummy implementation
49  template<int N>
50  class MixMaxEngineImpl {
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 
67 template<>
70 public:
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
93  Result_t IntRndm() {
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
int rng_free(rng_state_t *X)
Definition: mixmax.icc:162
int iterate(rng_state_t *X)
Definition: mixmax.icc:34
Namespace for new ROOT classes and functions.
Definition: TFoamSampler.h:19
#define ROOT_MM_N
myuint V[N]
Definition: mixmax.h:54
MixMaxEngine< ROOT_MM_N, 0 >::StateInt_t StateInt_t
MixMaxEngine< ROOT_MM_N, 0 >::Result_t Result_t
void fill_array(rng_state_t *X, unsigned int n, double *array)
Definition: mixmax.icc:85
void SetState(const std::vector< uint64_t > &)
void GetState(std::vector< uint64_t > &)
myuint get_next(rng_state_t *X)
Definition: mixmax.icc:77
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
double get_next_float(rng_state_t *X)
Definition: mixmax.icc:81
void read_state(rng_state_t *X, const char filename[])
Definition: mixmax.icc:286
void GetState(std::vector< StateInt_t > &state) const
int counter
Definition: mixmax.h:56
void seed_spbox(rng_state_t *X, myuint seed)
Definition: mixmax.icc:205
void SetState(const std::vector< StateInt_t > &state)
Namespace for new Math classes and functions.
rng_state_t * rng_copy(myuint *Y)
Definition: mixmax.icc:168
void branch_inplace(rng_state_t *Xin, myID_t *ID)
Definition: mixmax.icc:394
int rng_get_N(void)
Definition: mixmax.icc:240