| The Gaudi Framework v30r0 (c919700c)

- 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 m_useTable ? std::make_unique<DualRand>( m_row, m_col ) : std::make_unique<DualRand>( m_seeds[0] );
146 }
147 // Specialized create function for TripleRand engine
148 template <>
149 std::unique_ptr<CLHEP::HepRandomEngine> Engine<TripleRand>::createEngine()
150 {
151 return m_useTable ? std::make_unique<TripleRand>( m_row, m_col ) : std::make_unique<TripleRand>( m_seeds[0] );
152 }
153 // Specialized create function for DRand48Engine
154 template <>
155 std::unique_ptr<CLHEP::HepRandomEngine> Engine<DRand48Engine>::createEngine()
156 {
157 return m_useTable ? std::make_unique<DRand48Engine>( m_row, m_col ) : std::make_unique<DRand48Engine>( m_seeds[0] );
158 }
159 // Specialized create function for Hurd160Engine
160 template <>
161 std::unique_ptr<CLHEP::HepRandomEngine> Engine<Hurd160Engine>::createEngine()
162 {
163 return m_useTable ? std::make_unique<Hurd160Engine>( m_row, m_col ) : std::make_unique<Hurd160Engine>( m_seeds[0] );
164 }
165 // Specialized create function for Hurd288Engine
166 template <>
167 std::unique_ptr<CLHEP::HepRandomEngine> Engine<Hurd288Engine>::createEngine()
168 {
169 return m_useTable ? std::make_unique<Hurd288Engine>( m_row, m_col ) : std::make_unique<Hurd288Engine>( m_seeds[0] );
170 }
171 // Specialized create function for RanecuEngine
172 template <>
173 std::unique_ptr<CLHEP::HepRandomEngine> Engine<RanecuEngine>::createEngine()
174 {
175 return m_useTable ? std::make_unique<RanecuEngine>( m_row ) : std::make_unique<RanecuEngine>( m_seeds[0] );
176 }
177 // Specialized create function for RanshiEngine
178 template <>
179 std::unique_ptr<CLHEP::HepRandomEngine> Engine<RanshiEngine>::createEngine()
180 {
181 return m_useTable ? std::make_unique<RanshiEngine>( m_row, m_col ) : std::make_unique<RanshiEngine>( m_seeds[0] );
182 }
183 // Specialized create function for RanluxEngine
184 template <>
185 std::unique_ptr<CLHEP::HepRandomEngine> Engine<RanluxEngine>::createEngine()
186 {
187 return m_useTable ? std::make_unique<RanluxEngine>( m_row, m_col, m_lux )
188 : std::make_unique<RanluxEngine>( m_seeds[0], m_lux );
189 }
190 // Specialized create function for Ranlux64Engine
191 template <>
192 std::unique_ptr<CLHEP::HepRandomEngine> Engine<Ranlux64Engine>::createEngine()
193 {
194 return m_useTable ? std::make_unique<Ranlux64Engine>( m_row, m_col, m_lux )
195 : std::make_unique<Ranlux64Engine>( m_seeds[0], m_lux );
196 }
197 // Specialized create function for MTwistEngine
198 template <>
199 std::unique_ptr<CLHEP::HepRandomEngine> Engine<MTwistEngine>::createEngine()
200 {
201 return m_useTable ? std::make_unique<MTwistEngine>( m_row, m_col ) : std::make_unique<MTwistEngine>( m_seeds[0] );
202 }
203 // Specialized create function for HepJamesRandom
204 template <>
205 std::unique_ptr<CLHEP::HepRandomEngine> Engine<HepJamesRandom>::createEngine()
206 {
207 return m_useTable ? std::make_unique<HepJamesRandom>( m_row, m_col )
208 : std::make_unique<HepJamesRandom>( m_seeds[0] );
209 }
210 }
211
212 typedef HepRndm::Engine<DualRand> e1;
213 DECLARE_COMPONENT( e1 )
214 typedef HepRndm::Engine<TripleRand> e2;
215 DECLARE_COMPONENT( e2 )
216 typedef HepRndm::Engine<DRand48Engine> e3;
217 DECLARE_COMPONENT( e3 )
218 typedef HepRndm::Engine<Hurd160Engine> e4;
219 DECLARE_COMPONENT( e4 )
220 typedef HepRndm::Engine<Hurd288Engine> e5;
221 DECLARE_COMPONENT( e5 )
222 typedef HepRndm::Engine<HepJamesRandom> e6;
223 DECLARE_COMPONENT( e6 )
224 typedef HepRndm::Engine<MTwistEngine> e7;
225 DECLARE_COMPONENT( e7 )
226 typedef HepRndm::Engine<RanecuEngine> e8;
227 DECLARE_COMPONENT( e8 )
228 typedef HepRndm::Engine<Ranlux64Engine> e9;
229 DECLARE_COMPONENT( e9 )
230 typedef HepRndm::Engine<RanluxEngine> e10;
231 DECLARE_COMPONENT( e10 )
232 typedef HepRndm::Engine<RanshiEngine> e11;
233 DECLARE_COMPONENT( e11 )
System.h
StatusCode::SUCCESS
Definition: StatusCode.h:29
RndmGenSvc.h
std::copy
T copy(T...args)
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:336
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:50
std::vector::end
T end(T...args)
e1
HepRndm::Engine< DualRand > e1
Definition: HepRndmEngines.cpp:212
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:26
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
StatusCode::FAILURE
Definition: StatusCode.h:29
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209