| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HepRndmEngines.cpp
Go to the documentation of this file.
1 //====================================================================
2 // Random Engine implementations
3 //--------------------------------------------------------------------
4 //
5 // Package : HepRndm ( The LHCb Offline System)
6 // Author : M.Frank
7 // History :
8 // +---------+----------------------------------------------+---------
9 // | Date | Comment | Who
10 // +---------+----------------------------------------------+---------
11 // | 29/10/99| Initial version | MF
12 // +---------+----------------------------------------------+---------
13 //
14 // Note: Currently all engines require only ONE seed
15 // We aill return only the first number, because
16 // the implementation in CLHEP does not allow to
17 // determine the proper number of seeds used.
18 #define NUMBER_OF_SEEDS 1
19 //
20 //====================================================================
21 #define HEPRNDM_HEPRNDMENGINES_CPP
22
23 // STL include files
24 #include <iostream>
25 #include <cfloat>
26 #include <ctime>
27 #include <cmath>
28
29 // Framework include files
30 #include "GaudiKernel/System.h"
31 #include "GaudiKernel/MsgStream.h"
32 #include "GaudiKernel/IIncidentSvc.h"
33
34 #include "RndmGenSvc.h"
35 #include "HepRndmEngine.h"
36
37 #include "CLHEP/Random/Random.h"
38 #include "CLHEP/Random/DualRand.h"
39 #include "CLHEP/Random/TripleRand.h"
40 #include "CLHEP/Random/DRand48Engine.h"
41 #include "CLHEP/Random/Hurd160Engine.h"
42 #include "CLHEP/Random/Hurd288Engine.h"
43 #include "CLHEP/Random/JamesRandom.h"
44 #include "CLHEP/Random/MTwistEngine.h"
45 #include "CLHEP/Random/RanecuEngine.h"
46 #include "CLHEP/Random/Ranlux64Engine.h"
47 #include "CLHEP/Random/RanluxEngine.h"
48 #include "CLHEP/Random/RanshiEngine.h"
49
50 // Handle CLHEP 2.0.x move to CLHEP namespace
51 namespace CLHEP { }
52 using namespace CLHEP;
53
54 namespace HepRndm {
55
56 // Standard constructor
57 template <class TYPE> Engine<TYPE>::Engine(const std::string& nam, ISvcLocator* loc)
58 : BaseEngine (nam, loc) {
59 declareProperty("Seeds", m_seeds);
60 declareProperty("Column", m_col = 0);
61 declareProperty("Row", m_row = 1);
62 declareProperty("Luxury", m_lux = 3);
63 declareProperty("UseTable", m_useTable = false);
64 declareProperty("SetSingleton",m_setSingleton = false);
65 }
66
67 // Standard destructor
68 template <class TYPE> Engine<TYPE>::~Engine() {
69 }
70
71 // Initialize engine
72 template <class TYPE> StatusCode Engine<TYPE>::initialize() {
73 m_seeds.erase(m_seeds.begin(), m_seeds.end());
74 StatusCode status = RndmEngine::initialize();
75 if ( m_seeds.size() == 0 ) {
76 // Default seeds
77 long theSeed = 1234567;
78 m_seeds.push_back(theSeed);
79 m_seeds.push_back(0);
80 }
81 MsgStream log(msgSvc(), name());
82 if ( status.isSuccess() ) {
83 status = initializeEngine();
84 if ( status.isSuccess() ) {
85 log << MSG::INFO << "Generator engine type:"
86 << System::typeinfoName(typeid(TYPE))
87 << endmsg;
88 if ( m_useTable ) {
89 if ( m_row > 214 || m_col > 1 ) {
90 log << MSG::ERROR << "Generator engine seed table has dimension [215][2], you gave:"
91 << " Row=" << m_row << " Column:" << m_col << endmsg;
92 status = StatusCode::FAILURE;
93 }
94 else {
95 log << MSG::INFO << "Generator engine seeds from table."
96 << " Row=" << m_row << " Column:" << m_col << endmsg;
97 }
98 }
99 log << "Current Seed:" << m_hepEngine->getSeed();
100 log << " Luxury:" << m_lux;
101 log << endmsg;
102 // Use the default static engine if required (e.g. for GEANT4)
103 if ( m_setSingleton ) {
104 HepRandom::setTheEngine(m_hepEngine);
105 log << "This is the GEANT4 engine!" << endmsg;
106 }
107 return status;
108 }
109 }
110 log << MSG::ERROR << "Cannot initialze random engine of type:"
111 << System::typeinfoName(typeid(TYPE))
112 << endmsg;
113 return status;
114 }
115
116 // Finalize engine
117 template <class TYPE> StatusCode Engine<TYPE>::finalize() {
118 if ( m_hepEngine ) {
119 HepRandom::setTheEngine(0);
120 delete m_hepEngine;
121 }
122 m_seeds.clear();
123 m_hepEngine = 0;
124 return RndmEngine::finalize();
125 }
126
127 // Retrieve single random number
128 template <class TYPE> double Engine<TYPE>::rndm() const {
129 return m_hepEngine->flat();
130 }
131
132 // Retrieve seeds
133 template <class TYPE> StatusCode Engine<TYPE>::setSeeds(const std::vector<long>& seed) {
134 typedef std::vector<long> seed_t;
135 m_seeds.clear();
136 for ( seed_t::const_iterator i = seed.begin(); i < seed.end(); i++ ) {
137 m_seeds.push_back(*i);
138 }
139 if ( m_seeds.size() > 0 ) {
140 if ( m_seeds.back() != 0 ) {
141 m_seeds.push_back(0);
142 }
143 m_hepEngine->setSeeds(&m_seeds[0], m_lux);
144 return StatusCode::SUCCESS;
145 }
146 return StatusCode::FAILURE;
147 }
148
149 // Retrieve seeds
150 template <class TYPE> StatusCode Engine<TYPE>::seeds(std::vector<long>& seed) const {
151 /*
152 const long *s = m_hepEngine->getSeeds();
153 for ( size_t i = 0; i < NUMBER_OF_SEEDS; i++ ) {
154 seed.push_back(s[i]);
155 if ( m_seeds.size() > i )
156 m_seeds[i] = s[i];
157 else
158 m_seeds.push_back(s[i]);
159 }
160 */
161 seed.push_back(m_hepEngine->getSeed());
162 return StatusCode::SUCCESS;
163 }
164
165 // Specialized shoot function for DualRand engine
166 template <> StatusCode Engine<DualRand>::initializeEngine() {
167 m_hepEngine = (m_useTable) ? new DualRand(m_row, m_col) : new DualRand(m_seeds[0]);
168 return StatusCode::SUCCESS;
169 }
170 // Specialized shoot function for TripleRand engine
171 template <> StatusCode Engine<TripleRand>::initializeEngine() {
172 m_hepEngine = (m_useTable) ? new TripleRand(m_row, m_col) : new TripleRand(m_seeds[0]);
173 return StatusCode::SUCCESS;
174 }
175 // Specialized shoot function for DRand48Engine
176 template <> StatusCode Engine<DRand48Engine>::initializeEngine() {
177 m_hepEngine = (m_useTable) ? new DRand48Engine(m_row, m_col) : new DRand48Engine(m_seeds[0]);
178 return StatusCode::SUCCESS;
179 }
180 // Specialized shoot function for Hurd160Engine
181 template <> StatusCode Engine<Hurd160Engine>::initializeEngine() {
182 m_hepEngine = (m_useTable) ? new Hurd160Engine(m_row, m_col) : new Hurd160Engine(m_seeds[0]);
183 return StatusCode::SUCCESS;
184 }
185 // Specialized shoot function for Hurd288Engine
186 template <> StatusCode Engine<Hurd288Engine>::initializeEngine() {
187 m_hepEngine = (m_useTable) ? new Hurd288Engine(m_row, m_col) : new Hurd288Engine(m_seeds[0]);
188 return StatusCode::SUCCESS;
189 }
190 // Specialized shoot function for RanecuEngine
191 template <> StatusCode Engine<RanecuEngine>::initializeEngine() {
192 m_hepEngine = (m_useTable) ? new RanecuEngine(m_row) : new RanecuEngine(m_seeds[0]);
193 return StatusCode::SUCCESS;
194 }
195 // Specialized shoot function for RanshiEngine
196 template <> StatusCode Engine<RanshiEngine>::initializeEngine() {
197 m_hepEngine = (m_useTable) ? new RanshiEngine(m_row, m_col) : new RanshiEngine(m_seeds[0]);
198 return StatusCode::SUCCESS;
199 }
200 // Specialized shoot function for RanluxEngine
201 template <> StatusCode Engine<RanluxEngine>::initializeEngine() {
202 m_hepEngine = (m_useTable) ? new RanluxEngine(m_row, m_col, m_lux) : new RanluxEngine(m_seeds[0], m_lux);
203 return StatusCode::SUCCESS;
204 }
205 // Specialized shoot function for Ranlux64Engine
206 template <> StatusCode Engine<Ranlux64Engine>::initializeEngine() {
207 m_hepEngine = (m_useTable) ? new Ranlux64Engine(m_row, m_col, m_lux) : new Ranlux64Engine(m_seeds[0], m_lux);
208 return StatusCode::SUCCESS;
209 }
210 // Specialized shoot function for MTwistEngine
211 template <> StatusCode Engine<MTwistEngine>::initializeEngine() {
212 m_hepEngine = (m_useTable) ? new MTwistEngine(m_row, m_col) : new MTwistEngine(m_seeds[0]);
213 return StatusCode::SUCCESS;
214 }
215 // Specialized shoot function for HepJamesRandom
216 template <> StatusCode Engine<HepJamesRandom>::initializeEngine() {
217 m_hepEngine = (m_useTable) ? new HepJamesRandom(m_row, m_col) : new HepJamesRandom(m_seeds[0]);
218 return StatusCode::SUCCESS;
219 }
220
221 }
222
223 typedef HepRndm::Engine<DualRand> e1; DECLARE_COMPONENT(e1)
224 typedef HepRndm::Engine<TripleRand> e2; DECLARE_COMPONENT(e2)
225 typedef HepRndm::Engine<DRand48Engine> e3; DECLARE_COMPONENT(e3)
226 typedef HepRndm::Engine<Hurd160Engine> e4; DECLARE_COMPONENT(e4)
227 typedef HepRndm::Engine<Hurd288Engine> e5; DECLARE_COMPONENT(e5)
228 typedef HepRndm::Engine<HepJamesRandom> e6; DECLARE_COMPONENT(e6)
229 typedef HepRndm::Engine<MTwistEngine> e7; DECLARE_COMPONENT(e7)
230 typedef HepRndm::Engine<RanecuEngine> e8; DECLARE_COMPONENT(e8)
231 typedef HepRndm::Engine<Ranlux64Engine> e9; DECLARE_COMPONENT(e9)
232 typedef HepRndm::Engine<RanluxEngine> e10; DECLARE_COMPONENT(e10)
233 typedef HepRndm::Engine<RanshiEngine> e11; DECLARE_COMPONENT(e11)
234
235