LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
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 // $Id: pyRandomize.cc 76884 2013-11-18 12:54:03Z gcosmo $
27 // ====================================================================
28 // pyRandomize.cc
29 //
30 // 2005 Q
31 // ====================================================================
32 #include <boost/python.hpp>
33 #include "Randomize.hh"
34 #include <vector>
35 
36 using namespace boost::python;
37 using namespace CLHEP;
38 
39 // ====================================================================
40 // thin wrappers
41 // ====================================================================
42 namespace pyRandomize {
43 
44 // problem with BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS for static method
45 // setTheSeed
46 void f1_setTheSeed(long seed)
47 {
48  HepRandom::setTheSeed(seed);
49 }
50 
51 void f2_setTheSeed(long seed, int lux)
52 {
53  HepRandom::setTheSeed(seed, lux);
54 }
55 
56 // setTheSeeds
57 void f1_setTheSeeds(const list& seedList)
58 {
59  // check size...
60  int idx=0;
61  while(1) {
62  long val= extract<long>(seedList[idx]);
63  if(val==0) break;
64  idx++;
65  }
66  int nsize= idx+1;
67 
68  long* seedArray= new long[nsize]; // should not be deleted!!
69  // (this is a problem with CLHEP.)
70  for (int i=0; i< nsize; i++) {
71  seedArray[i]= extract<long>(seedList[i]);
72  }
73 
74  HepRandom::setTheSeeds(seedArray);
75 }
76 
77 void f2_setTheSeeds(const list& seedList, int aux)
78 {
79  // check size...
80  int idx=0;
81  while(1) {
82  long val= extract<long>(seedList[idx]);
83  if(val==0) break;
84  idx++;
85  }
86  int nsize= idx+1;
87 
88  long* seedArray= new long[nsize];
89  for (int i=0; i< nsize; i++) {
90  seedArray[i]= extract<long>(seedList[i]);
91  }
92 
93  HepRandom::setTheSeeds(seedArray, aux);
94 }
95 
96 // getTheSeeds
98 {
99  list seedList;
100  const long* seeds= HepRandom::getTheSeeds();
101  int idx=0;
102  while(1) {
103  if( seeds[idx]==0) break;
104  seedList.append(seeds[idx]);
105  idx++;
106  }
107  return seedList;
108 }
109 
110 // getTheTableSeeds
111 list f_getTheTableSeeds(int index)
112 {
113  long seedPair[2];
114  HepRandom::getTheTableSeeds(seedPair, index);
115 
116  list seedList;
117  seedList.append(seedPair[0]);
118  seedList.append(seedPair[1]);
119 
120  return seedList;
121 }
122 
123 
124 // saveEngineStatus
126 {
127  HepRandom::saveEngineStatus();
128 }
129 
130 void f2_saveEngineStatus(const char* filename)
131 {
132  HepRandom::saveEngineStatus(filename);
133 }
134 
135 // restoreEngineStatus
137 {
138  HepRandom::restoreEngineStatus();
139 }
140 
141 void f2_restoreEngineStatus(const char* filename)
142 {
143  HepRandom::restoreEngineStatus(filename);
144 }
145 
146 // RandBit::shootBit
148 {
149  return RandBit::shootBit();
150 }
151 
152 // RandGaussQ::shoot
154 {
155  return RandGaussQ::shoot();
156 }
157 
158 double f2_RandGaussQ_shoot(double mean, double stdDev)
159 {
160  return RandGaussQ::shoot(mean, stdDev);
161 }
162 
163 
164 // G4UniformRand
166 {
167  return G4UniformRand();
168 }
169 
170 }
171 
172 using namespace pyRandomize;
173 
174 // ====================================================================
175 // module definition
176 // ====================================================================
178 {
179  class_<HepRandom>("HepRandom", "generate random number")
180  // ---
181  .def(init<long>())
182  .def(init<HepRandomEngine&>())
183  .def(init<HepRandomEngine*>())
184  // ---
185  .def("setTheSeed", f1_setTheSeed)
186  .def("setTheSeed", f2_setTheSeed)
187  .staticmethod("setTheSeed")
188  .def("getTheSeed", &HepRandom::getTheSeed)
189  .staticmethod("getTheSeed")
190  .def("setTheSeeds", f1_setTheSeeds)
191  .def("setTheSeeds", f2_setTheSeeds)
192  .staticmethod("setTheSeeds")
193  .def("getTheSeeds", f_getTheSeeds)
194  .staticmethod("getTheSeeds")
195  .def("getTheTableSeeds", f_getTheTableSeeds)
196  .staticmethod("getTheTableSeeds")
197  // ---
198  .def("getTheGenerator", &HepRandom::getTheGenerator,
199  return_value_policy<reference_existing_object>())
200  .staticmethod("getTheGenerator")
201  .def("setTheEngine", &HepRandom::setTheEngine)
202  .staticmethod("setTheEngine")
203  .def("getTheEngine", &HepRandom::getTheEngine,
204  return_value_policy<reference_existing_object>())
205  .staticmethod("getTheEngine")
206  .def("saveEngineStatus", f1_saveEngineStatus)
207  .def("saveEngineStatus", f2_saveEngineStatus)
208  .staticmethod("saveEngineStatus")
209  .def("restoreEngineStatus", f1_restoreEngineStatus)
210  .def("restoreEngineStatus", f2_restoreEngineStatus)
211  .staticmethod("restoreEngineStatus")
212  .def("showEngineStatus", &HepRandom::showEngineStatus)
213  .staticmethod("showEngineStatus")
214  .def("createInstance", &HepRandom::createInstance)
215  .staticmethod("createInstance")
216  ;
217 
218  // ---
219  class_<RandBit, boost::noncopyable>
220  ("RandBit", "generate bit random number", no_init)
221  .def("shootBit", f1_RandBit_shootBit)
222  .staticmethod("shootBit")
223  ;
224 
225  // ---
226  class_<G4RandGauss, boost::noncopyable>
227  ("G4RandGauss", "generate gaussian random number", no_init)
228  .def("shoot", f1_RandGaussQ_shoot)
229  .def("shoot", f2_RandGaussQ_shoot)
230  .staticmethod("shoot")
231  ;
232 
233  // ---
234  def("G4UniformRand", f_G4UniformRand);
235 
236 }
237 
void f1_setTheSeed(long seed)
Definition: pyRandomize.cc:46
void f1_setTheSeeds(const list &seedList)
Definition: pyRandomize.cc:57
void f1_saveEngineStatus()
Definition: pyRandomize.cc:125
list f_getTheSeeds()
Definition: pyRandomize.cc:97
void f2_setTheSeed(long seed, int lux)
Definition: pyRandomize.cc:51
long seed
Definition: chem4.cc:68
list f_getTheTableSeeds(int index)
Definition: pyRandomize.cc:111
double f1_RandGaussQ_shoot()
Definition: pyRandomize.cc:153
void f2_saveEngineStatus(const char *filename)
Definition: pyRandomize.cc:130
void f1_restoreEngineStatus()
Definition: pyRandomize.cc:136
int f1_RandBit_shootBit()
Definition: pyRandomize.cc:147
std::vector< TrajPoint > seeds
Definition: DataStructs.cxx:11
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:15
void f2_restoreEngineStatus(const char *filename)
Definition: pyRandomize.cc:141
double f_G4UniformRand()
Definition: pyRandomize.cc:165
double f2_RandGaussQ_shoot(double mean, double stdDev)
Definition: pyRandomize.cc:158
void export_Randomize()
Definition: pyRandomize.cc:177
void f2_setTheSeeds(const list &seedList, int aux)
Definition: pyRandomize.cc:77