Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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  }
55  ~MixMaxEngineImpl() {}
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<>
68 class MixMaxEngineImpl<ROOT_MM_N> {
69  rng_state_t * fRngState;
70 public:
71 
72  typedef MixMaxEngine<ROOT_MM_N,0>::StateInt_t StateInt_t;
73  typedef MixMaxEngine<ROOT_MM_N,0>::Result_t Result_t;
74 
75  MixMaxEngineImpl(uint64_t seed) {
76  fRngState = rng_alloc();
77  SetSeed(seed);
78  }
79  ~MixMaxEngineImpl() {
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