| The Gaudi Framework v29r0 (ff2e7097)

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

- File List
- File Members

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 <cfloat>
25 #include <cmath>
26 #include <ctime>
27 #include <iostream>
28
29 // Framework include files
30 #include "GaudiKernel/IIncidentSvc.h"
31 #include "GaudiKernel/MsgStream.h"
32 #include "GaudiKernel/System.h"
33
34 #include "HepRndmEngine.h"
35 #include "RndmGenSvc.h"
36
37 #include "CLHEP/Random/DRand48Engine.h"
38 #include "CLHEP/Random/DualRand.h"
39 #include "CLHEP/Random/Hurd160Engine.h"
40 #include "CLHEP/Random/Hurd288Engine.h"
41 #include "CLHEP/Random/JamesRandom.h"
42 #include "CLHEP/Random/MTwistEngine.h"
43 #include "CLHEP/Random/RanecuEngine.h"
44 #include "CLHEP/Random/Ranlux64Engine.h"
45 #include "CLHEP/Random/RanluxEngine.h"
46 #include "CLHEP/Random/RanshiEngine.h"
47 #include "CLHEP/Random/TripleRand.h"
48
49 // Handle CLHEP 2.0.x move to CLHEP namespace
50 namespace CLHEP
51 {
52 }
53 using namespace CLHEP;
54
55 namespace HepRndm
56 {
57
58 // Initialize engine
59 template <class TYPE>
60 StatusCode Engine<TYPE>::initialize()
61 {
62 auto& seeds = m_seeds.value();
63 seeds.clear();
64 StatusCode status = RndmEngine::initialize();
65 if ( m_seeds.size() == 0 ) {
66 // Default seeds
67 long theSeed = 1234567;
68 seeds.push_back( theSeed );
69 seeds.push_back( 0 );
70 }
71 if ( status.isSuccess() ) {
72 initEngine();
73 info() << "Generator engine type:" << System::typeinfoName( typeid( *hepEngine() ) ) << endmsg;
74 if ( m_useTable ) {
75 if ( m_row > 214 || m_col > 1 ) {
76 error() << "Generator engine seed table has dimension [215][2], you gave:"
77 << " Row=" << m_row << " Column:" << m_col << endmsg;
78 status = StatusCode::FAILURE;
79 } else {
80 info() << "Generator engine seeds from table."
81 << " Row=" << m_row << " Column:" << m_col << endmsg;
82 }
83 }
84 info() << "Current Seed:" << hepEngine()->getSeed();
85 info() << " Luxury:" << m_lux.value();
86 info() << endmsg;
87 // Use the default static engine if required (e.g. for GEANT4)
88 if ( m_setSingleton ) {
89 HepRandom::setTheEngine( hepEngine() );
90 info() << "This is the GEANT4 engine!" << endmsg;
91 }
92 return status;
93 }
94 error() << "Cannot initialze random engine of type:" << System::typeinfoName( typeid( TYPE ) ) << endmsg;
95 return status;
96 }
97
98 // Finalize engine
99 template <class TYPE>
100 StatusCode Engine<TYPE>::finalize()
101 {
102 m_seeds.value().clear();
103 return BaseEngine::finalize();
104 }
105
106 // Retrieve seeds
107 template <class TYPE>
108 StatusCode Engine<TYPE>::setSeeds( const std::vector<long>& seed )
109 {
110 auto& seeds = m_seeds.value();
111 seeds.clear();
112 std::copy( seed.begin(), seed.end(), std::back_inserter( seeds ) );
113 if ( !seeds.empty() ) {
114 if ( seeds.back() != 0 ) {
115 seeds.push_back( 0 );
116 }
117 hepEngine()->setSeeds( &seeds[0], m_lux );
118 return StatusCode::SUCCESS;
119 }
120 return StatusCode::FAILURE;
121 }
122
123 // Retrieve seeds
124 template <class TYPE>
125 StatusCode Engine<TYPE>::seeds( std::vector<long>& seed ) const
126 {
127 /*
128 const long *s = hepEngine()->getSeeds();
129 for ( size_t i = 0; i < NUMBER_OF_SEEDS; i++ ) {
130 seed.push_back(s[i]);
131 if ( m_seeds.size() > i )
132 m_seeds[i] = s[i];
133 else
134 m_seeds.push_back(s[i]);
135 }
136 */
137 seed.push_back( hepEngine()->getSeed() );
138 return StatusCode::SUCCESS;
139 }
140
141 // Specialized create function for DualRand engine
142 template <>
143 std::unique_ptr<CLHEP::HepRandomEngine> Engine<DualRand>::createEngine()
144 {
145 return std::unique_ptr<CLHEP::HepRandomEngine>( m_useTable ? new DualRand( m_row, m_col )
146 : new DualRand( m_seeds[0] ) );
147 }
148 // Specialized create function for TripleRand engine
149 template <>
150 std::unique_ptr<CLHEP::HepRandomEngine> Engine<TripleRand>::createEngine()
151 {
152 return std::unique_ptr<CLHEP::HepRandomEngine>( m_useTable ? new TripleRand( m_row, m_col )
153 : new TripleRand( m_seeds[0] ) );
154 }
155 // Specialized create function for DRand48Engine
156 template <>
157 std::unique_ptr<CLHEP::HepRandomEngine> Engine<DRand48Engine>::createEngine()
158 {
159 return std::unique_ptr<CLHEP::HepRandomEngine>( m_useTable ? new DRand48Engine( m_row, m_col )
160 : new DRand48Engine( m_seeds[0] ) );
161 }
162 // Specialized create function for Hurd160Engine
163 template <>
164 std::unique_ptr<CLHEP::HepRandomEngine> Engine<Hurd160Engine>::createEngine()
165 {
166 return std::unique_ptr<CLHEP::HepRandomEngine>( m_useTable ? new Hurd160Engine( m_row, m_col )
167 : new Hurd160Engine( m_seeds[0] ) );
168 }
169 // Specialized create function for Hurd288Engine
170 template <>
171 std::unique_ptr<CLHEP::HepRandomEngine> Engine<Hurd288Engine>::createEngine()
172 {
173 return std::unique_ptr<CLHEP::HepRandomEngine>( m_useTable ? new Hurd288Engine( m_row, m_col )
174 : new Hurd288Engine( m_seeds[0] ) );
175 }
176 // Specialized create function for RanecuEngine
177 template <>
178 std::unique_ptr<CLHEP::HepRandomEngine> Engine<RanecuEngine>::createEngine()
179 {
180 return std::unique_ptr<CLHEP::HepRandomEngine>( m_useTable ? new RanecuEngine( m_row )
181 : new RanecuEngine( m_seeds[0] ) );
182 }
183 // Specialized create function for RanshiEngine
184 template <>
185 std::unique_ptr<CLHEP::HepRandomEngine> Engine<RanshiEngine>::createEngine()
186 {
187 return std::unique_ptr<CLHEP::HepRandomEngine>( m_useTable ? new RanshiEngine( m_row, m_col )
188 : new RanshiEngine( m_seeds[0] ) );
189 }
190 // Specialized create function for RanluxEngine
191 template <>
192 std::unique_ptr<CLHEP::HepRandomEngine> Engine<RanluxEngine>::createEngine()
193 {
194 return std::unique_ptr<CLHEP::HepRandomEngine>( m_useTable ? new RanluxEngine( m_row, m_col, m_lux )
195 : new RanluxEngine( m_seeds[0], m_lux ) );
196 }
197 // Specialized create function for Ranlux64Engine
198 template <>
199 std::unique_ptr<CLHEP::HepRandomEngine> Engine<Ranlux64Engine>::createEngine()
200 {
201 return std::unique_ptr<CLHEP::HepRandomEngine>( m_useTable ? new Ranlux64Engine( m_row, m_col, m_lux )
202 : new Ranlux64Engine( m_seeds[0], m_lux ) );
203 }
204 // Specialized create function for MTwistEngine
205 template <>
206 std::unique_ptr<CLHEP::HepRandomEngine> Engine<MTwistEngine>::createEngine()
207 {
208 return std::unique_ptr<CLHEP::HepRandomEngine>( m_useTable ? new MTwistEngine( m_row, m_col )
209 : new MTwistEngine( m_seeds[0] ) );
210 }
211 // Specialized create function for HepJamesRandom
212 template <>
213 std::unique_ptr<CLHEP::HepRandomEngine> Engine<HepJamesRandom>::createEngine()
214 {
215 return std::unique_ptr<CLHEP::HepRandomEngine>( m_useTable ? new HepJamesRandom( m_row, m_col )
216 : new HepJamesRandom( m_seeds[0] ) );
217 }
218 }
219
220 typedef HepRndm::Engine<DualRand> e1;
221 DECLARE_COMPONENT( e1 )
222 typedef HepRndm::Engine<TripleRand> e2;
223 DECLARE_COMPONENT( e2 )
224 typedef HepRndm::Engine<DRand48Engine> e3;
225 DECLARE_COMPONENT( e3 )
226 typedef HepRndm::Engine<Hurd160Engine> e4;
227 DECLARE_COMPONENT( e4 )
228 typedef HepRndm::Engine<Hurd288Engine> e5;
229 DECLARE_COMPONENT( e5 )
230 typedef HepRndm::Engine<HepJamesRandom> e6;
231 DECLARE_COMPONENT( e6 )
232 typedef HepRndm::Engine<MTwistEngine> e7;
233 DECLARE_COMPONENT( e7 )
234 typedef HepRndm::Engine<RanecuEngine> e8;
235 DECLARE_COMPONENT( e8 )
236 typedef HepRndm::Engine<Ranlux64Engine> e9;
237 DECLARE_COMPONENT( e9 )
238 typedef HepRndm::Engine<RanluxEngine> e10;
239 DECLARE_COMPONENT( e10 )
240 typedef HepRndm::Engine<RanshiEngine> e11;
241 DECLARE_COMPONENT( e11 )
System.h
StatusCode::SUCCESS
Definition: StatusCode.h:31
RndmGenSvc.h
std::copy
T copy(T...args)
StatusCode::FAILURE
Definition: StatusCode.h:31
MsgStream.h
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:329
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
std::vector::end
T end(T...args)
e1
HepRndm::Engine< DualRand > e1
Definition: HepRndmEngines.cpp:220
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
HepRndm::Engine
Definition: HepRndmEngine.h:26
std::vector::push_back
T push_back(T...args)
IIncidentSvc.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
RndmEngine::initialize
StatusCode initialize() override
Service override: initialization.
Definition: RndmEngine.cpp:37
HepRndm
Definition: HepRndmBaseEngine.h:28
HepRndmEngine.h
std::vector< long >
std::unique_ptr< CLHEP::HepRandomEngine >
std::vector::begin
T begin(T...args)
std::back_inserter
T back_inserter(T...args)
CLHEP
Definition: IFuncMinimum.h:16
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209