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