Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 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/SvcFactory.h"
31 #include "GaudiKernel/System.h"
32 #include "GaudiKernel/MsgStream.h"
34 
35 #include "RndmGenSvc.h"
36 #include "HepRndmEngine.h"
37 
38 #include "CLHEP/Random/Random.h"
39 #include "CLHEP/Random/DualRand.h"
40 #include "CLHEP/Random/TripleRand.h"
41 #include "CLHEP/Random/DRand48Engine.h"
42 #include "CLHEP/Random/Hurd160Engine.h"
43 #include "CLHEP/Random/Hurd288Engine.h"
44 #include "CLHEP/Random/JamesRandom.h"
45 #include "CLHEP/Random/MTwistEngine.h"
46 #include "CLHEP/Random/RanecuEngine.h"
47 #include "CLHEP/Random/Ranlux64Engine.h"
48 #include "CLHEP/Random/RanluxEngine.h"
49 #include "CLHEP/Random/RanshiEngine.h"
50 
51 // Handle CLHEP 2.0.x move to CLHEP namespace
52 namespace CLHEP { }
53 using namespace CLHEP;
54 
55 namespace HepRndm {
56 
57  // Standard constructor
58  template <class TYPE> Engine<TYPE>::Engine(const std::string& nam, ISvcLocator* loc)
59  : BaseEngine (nam, loc) {
60  declareProperty("Seeds", m_seeds);
61  declareProperty("Column", m_col = 0);
62  declareProperty("Row", m_row = 1);
63  declareProperty("Luxury", m_lux = 3);
64  declareProperty("UseTable", m_useTable = false);
65  declareProperty("SetSingleton",m_setSingleton = false);
66  }
67 
68  // Standard destructor
69  template <class TYPE> Engine<TYPE>::~Engine() {
70  }
71 
72  // Initialize engine
73  template <class TYPE> StatusCode Engine<TYPE>::initialize() {
74  m_seeds.erase(m_seeds.begin(), m_seeds.end());
76  if ( m_seeds.size() == 0 ) {
77  // Default seeds
78  long theSeed = 1234567;
79  m_seeds.push_back(theSeed);
80  m_seeds.push_back(0);
81  }
82  MsgStream log(msgSvc(), name());
83  if ( status.isSuccess() ) {
84  status = initializeEngine();
85  if ( status.isSuccess() ) {
86  log << MSG::INFO << "Generator engine type:"
87  << System::typeinfoName(typeid(TYPE))
88  << endmsg;
89  if ( m_useTable ) {
90  if ( m_row > 214 || m_col > 1 ) {
91  log << MSG::ERROR << "Generator engine seed table has dimension [215][2], you gave:"
92  << " Row=" << m_row << " Column:" << m_col << endmsg;
93  status = StatusCode::FAILURE;
94  }
95  else {
96  log << MSG::INFO << "Generator engine seeds from table."
97  << " Row=" << m_row << " Column:" << m_col << endmsg;
98  }
99  }
100  log << "Current Seed:" << m_hepEngine->getSeed();
101  log << " Luxury:" << m_lux;
102  log << endmsg;
103  // Use the default static engine if required (e.g. for GEANT4)
104  if ( m_setSingleton ) {
105  HepRandom::setTheEngine(m_hepEngine);
106  log << "This is the GEANT4 engine!" << endmsg;
107  }
108  return status;
109  }
110  }
111  log << MSG::ERROR << "Cannot initialze random engine of type:"
112  << System::typeinfoName(typeid(TYPE))
113  << endmsg;
114  return status;
115  }
116 
117  // Finalize engine
118  template <class TYPE> StatusCode Engine<TYPE>::finalize() {
119  if ( m_hepEngine ) {
120  HepRandom::setTheEngine(0);
121  delete m_hepEngine;
122  }
123  m_seeds.clear();
124  m_hepEngine = 0;
125  return RndmEngine::finalize();
126  }
127 
128  // Retrieve single random number
129  template <class TYPE> double Engine<TYPE>::rndm() const {
130  return m_hepEngine->flat();
131  }
132 
133  // Retrieve seeds
134  template <class TYPE> StatusCode Engine<TYPE>::setSeeds(const std::vector<long>& seed) {
135  typedef std::vector<long> seed_t;
136  m_seeds.clear();
137  for ( seed_t::const_iterator i = seed.begin(); i < seed.end(); i++ ) {
138  m_seeds.push_back(*i);
139  }
140  if ( m_seeds.size() > 0 ) {
141  if ( m_seeds.back() != 0 ) {
142  m_seeds.push_back(0);
143  }
144  m_hepEngine->setSeeds(&m_seeds[0], m_lux);
145  return StatusCode::SUCCESS;
146  }
147  return StatusCode::FAILURE;
148  }
149 
150  // Retrieve seeds
151  template <class TYPE> StatusCode Engine<TYPE>::seeds(std::vector<long>& seed) const {
152  /*
153  const long *s = m_hepEngine->getSeeds();
154  for ( size_t i = 0; i < NUMBER_OF_SEEDS; i++ ) {
155  seed.push_back(s[i]);
156  if ( m_seeds.size() > i )
157  m_seeds[i] = s[i];
158  else
159  m_seeds.push_back(s[i]);
160  }
161  */
162  seed.push_back(m_hepEngine->getSeed());
163  return StatusCode::SUCCESS;
164  }
165 
166  // Specialized shoot function for DualRand engine
168  m_hepEngine = (m_useTable) ? new DualRand(m_row, m_col) : new DualRand(m_seeds[0]);
169  return StatusCode::SUCCESS;
170  }
171  // Specialized shoot function for TripleRand engine
173  m_hepEngine = (m_useTable) ? new TripleRand(m_row, m_col) : new TripleRand(m_seeds[0]);
174  return StatusCode::SUCCESS;
175  }
176  // Specialized shoot function for DRand48Engine
178  m_hepEngine = (m_useTable) ? new DRand48Engine(m_row, m_col) : new DRand48Engine(m_seeds[0]);
179  return StatusCode::SUCCESS;
180  }
181  // Specialized shoot function for Hurd160Engine
183  m_hepEngine = (m_useTable) ? new Hurd160Engine(m_row, m_col) : new Hurd160Engine(m_seeds[0]);
184  return StatusCode::SUCCESS;
185  }
186  // Specialized shoot function for Hurd288Engine
188  m_hepEngine = (m_useTable) ? new Hurd288Engine(m_row, m_col) : new Hurd288Engine(m_seeds[0]);
189  return StatusCode::SUCCESS;
190  }
191  // Specialized shoot function for RanecuEngine
193  m_hepEngine = (m_useTable) ? new RanecuEngine(m_row) : new RanecuEngine(m_seeds[0]);
194  return StatusCode::SUCCESS;
195  }
196  // Specialized shoot function for RanshiEngine
198  m_hepEngine = (m_useTable) ? new RanshiEngine(m_row, m_col) : new RanshiEngine(m_seeds[0]);
199  return StatusCode::SUCCESS;
200  }
201  // Specialized shoot function for RanluxEngine
203  m_hepEngine = (m_useTable) ? new RanluxEngine(m_row, m_col, m_lux) : new RanluxEngine(m_seeds[0], m_lux);
204  return StatusCode::SUCCESS;
205  }
206  // Specialized shoot function for Ranlux64Engine
208  m_hepEngine = (m_useTable) ? new Ranlux64Engine(m_row, m_col, m_lux) : new Ranlux64Engine(m_seeds[0], m_lux);
209  return StatusCode::SUCCESS;
210  }
211  // Specialized shoot function for MTwistEngine
213  m_hepEngine = (m_useTable) ? new MTwistEngine(m_row, m_col) : new MTwistEngine(m_seeds[0]);
214  return StatusCode::SUCCESS;
215  }
216  // Specialized shoot function for HepJamesRandom
218  m_hepEngine = (m_useTable) ? new HepJamesRandom(m_row, m_col) : new HepJamesRandom(m_seeds[0]);
219  return StatusCode::SUCCESS;
220  }
221 
222 }
223 
225 typedef HepRndm::Engine<TripleRand> e2; DECLARE_SERVICE_FACTORY(e2)
226 typedef HepRndm::Engine<DRand48Engine> e3; DECLARE_SERVICE_FACTORY(e3)
227 typedef HepRndm::Engine<Hurd160Engine> e4; DECLARE_SERVICE_FACTORY(e4)
228 typedef HepRndm::Engine<Hurd288Engine> e5; DECLARE_SERVICE_FACTORY(e5)
229 typedef HepRndm::Engine<HepJamesRandom> e6; DECLARE_SERVICE_FACTORY(e6)
230 typedef HepRndm::Engine<MTwistEngine> e7; DECLARE_SERVICE_FACTORY(e7)
231 typedef HepRndm::Engine<RanecuEngine> e8; DECLARE_SERVICE_FACTORY(e8)
232 typedef HepRndm::Engine<Ranlux64Engine> e9; DECLARE_SERVICE_FACTORY(e9)
233 typedef HepRndm::Engine<RanluxEngine> e10; DECLARE_SERVICE_FACTORY(e10)
234 typedef HepRndm::Engine<RanshiEngine> e11; DECLARE_SERVICE_FACTORY(e11)
235 
236 

Generated at Wed Nov 28 2012 12:17:17 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004