File indexing completed on 2025-01-18 10:10:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef ROOT_Math_MixMaxEngine_icc
0018 #define ROOT_Math_MixMaxEngine_icc
0019
0020 #ifndef ROOT_Math_MixMaxEngine
0021 #error "Do not use MixMaxEngine.icc directly. #include \"MixMaxEngine.h\" instead."
0022 #endif
0023
0024
0025 #include <cassert>
0026 #include "Math/Util.h"
0027
0028
0029 namespace ROOT {
0030 namespace Math {
0031
0032
0033
0034 template<int N, int S>
0035 MixMaxEngine<N,S>::MixMaxEngine(uint64_t seed) {
0036
0037
0038 fRng = new MixMaxEngineImpl<N>(seed);
0039 }
0040
0041 template<int N, int S>
0042 MixMaxEngine<N,S>::~MixMaxEngine() {
0043 if (fRng) delete fRng;
0044 }
0045
0046
0047
0048
0049
0050
0051
0052 template<int N, int S>
0053 void MixMaxEngine<N,S>::SetSeed(uint64_t seed) {
0054
0055 fRng->SetSeed(seed);
0056 }
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 template<int SkipNumber>
0073 struct SkipFunction {
0074 template<class Engine>
0075 static void Apply (Engine * rng, int counter, int n) {
0076
0077 if (counter < n) return;
0078 for (int iskip = 0; iskip < SkipNumber; ++iskip)
0079 rng->Iterate();
0080 }
0081 };
0082
0083 template<>
0084 struct SkipFunction<0> {
0085 template<class Engine>
0086 static void Apply (Engine *, int , int ) {
0087
0088 }
0089 };
0090
0091 template<int N, int S>
0092 double MixMaxEngine<N,S>::Rndm_impl() {
0093 int counter = fRng->Counter();
0094 SkipFunction<S>::Apply(fRng, counter, N);
0095
0096
0097 fRng->SetCounter(counter);
0098 return fRng->Rndm();
0099 }
0100
0101
0102 template<int N, int S>
0103 uint64_t MixMaxEngine<N,S>::IntRndm() {
0104 int counter = fRng->Counter();
0105 SkipFunction<S>::Apply(fRng, counter,N);
0106 fRng->SetCounter(counter);
0107 return fRng->IntRndm();
0108 }
0109
0110 template<int N, int S>
0111 uint64_t MixMaxEngine<N,S>::MaxInt() {
0112
0113 return 2305843009213693951ULL;
0114 }
0115
0116 template<int N, int S>
0117 uint64_t MixMaxEngine<N,S>::MinInt() {
0118
0119 return 0;
0120 }
0121
0122 template<int N, int S>
0123 void MixMaxEngine<N,S>::RndmArray(int n, double *array){
0124
0125 for (int i = 0; i < n; ++i)
0126 array[i] = Rndm_impl();
0127 }
0128
0129 template<int N, int S>
0130 void MixMaxEngine<N,S>::SetState(const std::vector<StateInt_t> & state) {
0131 assert(state.size() >= N);
0132
0133
0134
0135
0136 fRng->SetState(state);
0137 fRng->SetCounter(N);
0138 }
0139
0140 template<int N, int S>
0141 void MixMaxEngine<N,S>::GetState(std::vector<StateInt_t> & state) const {
0142 state.resize(N);
0143 fRng->GetState(state);
0144 }
0145
0146 template<int N, int S>
0147 int MixMaxEngine<N,S>::Size() {
0148 return MixMaxEngineImpl<N>::Size();
0149 }
0150
0151 template<int N, int S>
0152 int MixMaxEngine<N,S>::Counter() const {
0153 return fRng->Counter();
0154 }
0155
0156 template<int N, int S>
0157 const char *MixMaxEngine<N, S>::Name() {
0158 static const std::string name = "MixMax" + Util::ToString(N) + (S > 0 ? "_" + Util::ToString(S) : "");
0159 return name.c_str();
0160 }
0161
0162 }
0163 }
0164
0165 #endif