Geant4-11
pyRandomize.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// ====================================================================
27// pyRandomize.cc
28//
29// 2005 Q
30// ====================================================================
31#include <boost/python.hpp>
32#include "Randomize.hh"
33#include <vector>
34
35using namespace boost::python;
36using namespace CLHEP;
37
38// ====================================================================
39// thin wrappers
40// ====================================================================
41namespace pyRandomize {
42
43// problem with BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS for static method
44// setTheSeed
45void f1_setTheSeed(long seed)
46{
47 HepRandom::setTheSeed(seed);
48}
49
50void f2_setTheSeed(long seed, int lux)
51{
52 HepRandom::setTheSeed(seed, lux);
53}
54
55// setTheSeeds
56void f1_setTheSeeds(const list& seedList)
57{
58 // check size...
59 int idx=0;
60 while(1) {
61 long val= extract<long>(seedList[idx]);
62 if(val==0) break;
63 idx++;
64 }
65 int nsize= idx+1;
66
67 long* seedArray= new long[nsize]; // should not be deleted!!
68 // (this is a problem with CLHEP.)
69 for (int i=0; i< nsize; i++) {
70 seedArray[i]= extract<long>(seedList[i]);
71 }
72
73 HepRandom::setTheSeeds(seedArray);
74}
75
76void f2_setTheSeeds(const list& seedList, int aux)
77{
78 // check size...
79 int idx=0;
80 while(1) {
81 long val= extract<long>(seedList[idx]);
82 if(val==0) break;
83 idx++;
84 }
85 int nsize= idx+1;
86
87 long* seedArray= new long[nsize];
88 for (int i=0; i< nsize; i++) {
89 seedArray[i]= extract<long>(seedList[i]);
90 }
91
92 HepRandom::setTheSeeds(seedArray, aux);
93}
94
95// getTheSeeds
97{
98 list seedList;
99 const long* seeds= HepRandom::getTheSeeds();
100 int idx=0;
101 while(1) {
102 if( seeds[idx]==0) break;
103 seedList.append(seeds[idx]);
104 idx++;
105 }
106 return seedList;
107}
108
109// getTheTableSeeds
110list f_getTheTableSeeds(int index)
111{
112 long seedPair[2];
113 HepRandom::getTheTableSeeds(seedPair, index);
114
115 list seedList;
116 seedList.append(seedPair[0]);
117 seedList.append(seedPair[1]);
118
119 return seedList;
120}
121
122
123// saveEngineStatus
125{
126 HepRandom::saveEngineStatus();
127}
128
129void f2_saveEngineStatus(const char* filename)
130{
131 HepRandom::saveEngineStatus(filename);
132}
133
134// restoreEngineStatus
136{
137 HepRandom::restoreEngineStatus();
138}
139
140void f2_restoreEngineStatus(const char* filename)
141{
142 HepRandom::restoreEngineStatus(filename);
143}
144
145// RandBit::shootBit
147{
148 return RandBit::shootBit();
149}
150
151// RandGaussQ::shoot
153{
154 return RandGaussQ::shoot();
155}
156
157double f2_RandGaussQ_shoot(double mean, double stdDev)
158{
159 return RandGaussQ::shoot(mean, stdDev);
160}
161
162
163// G4UniformRand
165{
166 return G4UniformRand();
167}
168
169}
170
171using namespace pyRandomize;
172
173// ====================================================================
174// module definition
175// ====================================================================
177{
178 class_<HepRandom>("HepRandom", "generate random number")
179 // ---
180 .def(init<long>())
181 .def(init<HepRandomEngine&>())
182 .def(init<HepRandomEngine*>())
183 // ---
184 .def("setTheSeed", f1_setTheSeed)
185 .def("setTheSeed", f2_setTheSeed)
186 .staticmethod("setTheSeed")
187 .def("getTheSeed", &HepRandom::getTheSeed)
188 .staticmethod("getTheSeed")
189 .def("setTheSeeds", f1_setTheSeeds)
190 .def("setTheSeeds", f2_setTheSeeds)
191 .staticmethod("setTheSeeds")
192 .def("getTheSeeds", f_getTheSeeds)
193 .staticmethod("getTheSeeds")
194 .def("getTheTableSeeds", f_getTheTableSeeds)
195 .staticmethod("getTheTableSeeds")
196 // ---
197 .def("getTheGenerator", &HepRandom::getTheGenerator,
198 return_value_policy<reference_existing_object>())
199 .staticmethod("getTheGenerator")
200 .def("setTheEngine", &HepRandom::setTheEngine)
201 .staticmethod("setTheEngine")
202 .def("getTheEngine", &HepRandom::getTheEngine,
203 return_value_policy<reference_existing_object>())
204 .staticmethod("getTheEngine")
205 .def("saveEngineStatus", f1_saveEngineStatus)
206 .def("saveEngineStatus", f2_saveEngineStatus)
207 .staticmethod("saveEngineStatus")
208 .def("restoreEngineStatus", f1_restoreEngineStatus)
209 .def("restoreEngineStatus", f2_restoreEngineStatus)
210 .staticmethod("restoreEngineStatus")
211 .def("showEngineStatus", &HepRandom::showEngineStatus)
212 .staticmethod("showEngineStatus")
213 .def("createInstance", &HepRandom::createInstance)
214 .staticmethod("createInstance")
215 ;
216
217 // ---
218 class_<RandBit, boost::noncopyable>
219 ("RandBit", "generate bit random number", no_init)
220 .def("shootBit", f1_RandBit_shootBit)
221 .staticmethod("shootBit")
222 ;
223
224 // ---
225 class_<G4RandGauss, boost::noncopyable>
226 ("G4RandGauss", "generate gaussian random number", no_init)
227 .def("shoot", f1_RandGaussQ_shoot)
228 .def("shoot", f2_RandGaussQ_shoot)
229 .staticmethod("shoot")
230 ;
231
232 // ---
233 def("G4UniformRand", f_G4UniformRand);
234
235}
236
static constexpr double lux
Definition: G4SIunits.hh:320
#define G4UniformRand()
Definition: Randomize.hh:52
Definition: DoubConv.h:17
ThreeVector shoot(const G4int Ap, const G4int Af)
double f2_RandGaussQ_shoot(double mean, double stdDev)
Definition: pyRandomize.cc:157
void f2_setTheSeed(long seed, int lux)
Definition: pyRandomize.cc:50
void f2_setTheSeeds(const list &seedList, int aux)
Definition: pyRandomize.cc:76
list f_getTheTableSeeds(int index)
Definition: pyRandomize.cc:110
void f1_setTheSeeds(const list &seedList)
Definition: pyRandomize.cc:56
void f2_saveEngineStatus(const char *filename)
Definition: pyRandomize.cc:129
list f_getTheSeeds()
Definition: pyRandomize.cc:96
double f1_RandGaussQ_shoot()
Definition: pyRandomize.cc:152
void f1_restoreEngineStatus()
Definition: pyRandomize.cc:135
void f2_restoreEngineStatus(const char *filename)
Definition: pyRandomize.cc:140
int f1_RandBit_shootBit()
Definition: pyRandomize.cc:146
void f1_setTheSeed(long seed)
Definition: pyRandomize.cc:45
void f1_saveEngineStatus()
Definition: pyRandomize.cc:124
double f_G4UniformRand()
Definition: pyRandomize.cc:164
void export_Randomize()
Definition: pyRandomize.cc:176