| The Gaudi Framework v32r1 (f65d50dc)

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 using namespace CLHEP;
52
53 namespace HepRndm {
54
55 // Initialize engine
56 template <class TYPE>
57 StatusCode Engine<TYPE>::initialize() {
58 auto& seeds = m_seeds.value();
59 seeds.clear();
60 StatusCode status = RndmEngine::initialize();
61 if ( m_seeds.size() == 0 ) {
62 // Default seeds
63 long theSeed = 1234567;
64 seeds.push_back( theSeed );
65 seeds.push_back( 0 );
66 }
67 if ( status.isSuccess() ) {
68 initEngine();
69 info() << "Generator engine type:" << System::typeinfoName( typeid( *hepEngine() ) ) << endmsg;
70 if ( m_useTable ) {
71 if ( m_row > 214 || m_col > 1 ) {
72 error() << "Generator engine seed table has dimension [215][2], you gave:"
73 << " Row=" << m_row << " Column:" << m_col << endmsg;
74 status = StatusCode::FAILURE;
75 } else {
76 info() << "Generator engine seeds from table."
77 << " Row=" << m_row << " Column:" << m_col << endmsg;
78 }
79 }
80 info() << "Current Seed:" << hepEngine()->getSeed();
81 info() << " Luxury:" << m_lux.value();
82 info() << endmsg;
83 // Use the default static engine if required (e.g. for GEANT4)
84 if ( m_setSingleton ) {
85 HepRandom::setTheEngine( hepEngine() );
86 info() << "This is the GEANT4 engine!" << endmsg;
87 }
88 return status;
89 }
90 error() << "Cannot initialze random engine of type:" << System::typeinfoName( typeid( TYPE ) ) << endmsg;
91 return status;
92 }
93
94 // Finalize engine
95 template <class TYPE>
96 StatusCode Engine<TYPE>::finalize() {
97 m_seeds.value().clear();
98 return BaseEngine::finalize();
99 }
100
101 // Retrieve seeds
102 template <class TYPE>
103 StatusCode Engine<TYPE>::setSeeds( const std::vector<long>& seed ) {
104 auto& seeds = m_seeds.value();
105 seeds.clear();
106 std::copy( seed.begin(), seed.end(), std::back_inserter( seeds ) );
107 if ( !seeds.empty() ) {
108 if ( seeds.back() != 0 ) { seeds.push_back( 0 ); }
109 hepEngine()->setSeeds( &seeds[0], m_lux );
110 return StatusCode::SUCCESS;
111 }
112 return StatusCode::FAILURE;
113 }
114
115 // Retrieve seeds
116 template <class TYPE>
117 StatusCode Engine<TYPE>::seeds( std::vector<long>& seed ) const {
118 /*
119 const long *s = hepEngine()->getSeeds();
120 for ( size_t i = 0; i < NUMBER_OF_SEEDS; i++ ) {
121 seed.push_back(s[i]);
122 if ( m_seeds.size() > i )
123 m_seeds[i] = s[i];
124 else
125 m_seeds.push_back(s[i]);
126 }
127 */
128 seed.push_back( hepEngine()->getSeed() );
129 return StatusCode::SUCCESS;
130 }
131
132 // Specialized create function for DualRand engine
133 template <>
134 std::unique_ptr<CLHEP::HepRandomEngine> Engine<DualRand>::createEngine() {
135 return m_useTable ? std::make_unique<DualRand>( m_row, m_col ) : std::make_unique<DualRand>( m_seeds[0] );
136 }
137 // Specialized create function for TripleRand engine
138 template <>
139 std::unique_ptr<CLHEP::HepRandomEngine> Engine<TripleRand>::createEngine() {
140 return m_useTable ? std::make_unique<TripleRand>( m_row, m_col ) : std::make_unique<TripleRand>( m_seeds[0] );
141 }
142 // Specialized create function for DRand48Engine
143 template <>
144 std::unique_ptr<CLHEP::HepRandomEngine> Engine<DRand48Engine>::createEngine() {
145 return m_useTable ? std::make_unique<DRand48Engine>( m_row, m_col ) : std::make_unique<DRand48Engine>( m_seeds[0] );
146 }
147 // Specialized create function for Hurd160Engine
148 template <>
149 std::unique_ptr<CLHEP::HepRandomEngine> Engine<Hurd160Engine>::createEngine() {
150 return m_useTable ? std::make_unique<Hurd160Engine>( m_row, m_col ) : std::make_unique<Hurd160Engine>( m_seeds[0] );
151 }
152 // Specialized create function for Hurd288Engine
153 template <>
154 std::unique_ptr<CLHEP::HepRandomEngine> Engine<Hurd288Engine>::createEngine() {
155 return m_useTable ? std::make_unique<Hurd288Engine>( m_row, m_col ) : std::make_unique<Hurd288Engine>( m_seeds[0] );
156 }
157 // Specialized create function for RanecuEngine
158 template <>
159 std::unique_ptr<CLHEP::HepRandomEngine> Engine<RanecuEngine>::createEngine() {
160 return m_useTable ? std::make_unique<RanecuEngine>( m_row ) : std::make_unique<RanecuEngine>( m_seeds[0] );
161 }
162 // Specialized create function for RanshiEngine
163 template <>
164 std::unique_ptr<CLHEP::HepRandomEngine> Engine<RanshiEngine>::createEngine() {
165 return m_useTable ? std::make_unique<RanshiEngine>( m_row, m_col ) : std::make_unique<RanshiEngine>( m_seeds[0] );
166 }
167 // Specialized create function for RanluxEngine
168 template <>
169 std::unique_ptr<CLHEP::HepRandomEngine> Engine<RanluxEngine>::createEngine() {
170 return m_useTable ? std::make_unique<RanluxEngine>( m_row, m_col, m_lux )
171 : std::make_unique<RanluxEngine>( m_seeds[0], m_lux );
172 }
173 // Specialized create function for Ranlux64Engine
174 template <>
175 std::unique_ptr<CLHEP::HepRandomEngine> Engine<Ranlux64Engine>::createEngine() {
176 return m_useTable ? std::make_unique<Ranlux64Engine>( m_row, m_col, m_lux )
177 : std::make_unique<Ranlux64Engine>( m_seeds[0], m_lux );
178 }
179 // Specialized create function for MTwistEngine
180 template <>
181 std::unique_ptr<CLHEP::HepRandomEngine> Engine<MTwistEngine>::createEngine() {
182 return m_useTable ? std::make_unique<MTwistEngine>( m_row, m_col ) : std::make_unique<MTwistEngine>( m_seeds[0] );
183 }
184 // Specialized create function for HepJamesRandom
185 template <>
186 std::unique_ptr<CLHEP::HepRandomEngine> Engine<HepJamesRandom>::createEngine() {
187 return m_useTable ? std::make_unique<HepJamesRandom>( m_row, m_col )
188 : std::make_unique<HepJamesRandom>( m_seeds[0] );
189 }
190 } // namespace HepRndm
191
192 typedef HepRndm::Engine<DualRand> e1;
193 DECLARE_COMPONENT( e1 )
194 typedef HepRndm::Engine<TripleRand> e2;
195 DECLARE_COMPONENT( e2 )
196 typedef HepRndm::Engine<DRand48Engine> e3;
197 DECLARE_COMPONENT( e3 )
198 typedef HepRndm::Engine<Hurd160Engine> e4;
199 DECLARE_COMPONENT( e4 )
200 typedef HepRndm::Engine<Hurd288Engine> e5;
201 DECLARE_COMPONENT( e5 )
202 typedef HepRndm::Engine<HepJamesRandom> e6;
203 DECLARE_COMPONENT( e6 )
204 typedef HepRndm::Engine<MTwistEngine> e7;
205 DECLARE_COMPONENT( e7 )
206 typedef HepRndm::Engine<RanecuEngine> e8;
207 DECLARE_COMPONENT( e8 )
208 typedef HepRndm::Engine<Ranlux64Engine> e9;
209 DECLARE_COMPONENT( e9 )
210 typedef HepRndm::Engine<RanluxEngine> e10;
211 DECLARE_COMPONENT( e10 )
212 typedef HepRndm::Engine<RanshiEngine> e11;
213 DECLARE_COMPONENT( e11 )
System.h
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:298
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std::vector::end
T end(T... args)
e1
HepRndm::Engine< DualRand > e1
Definition: HepRndmEngines.cpp:192
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
HepRndm::Engine
Definition: HepRndmEngine.h:25
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:50
RndmEngine::initialize
StatusCode initialize() override
Service override: initialization.
Definition: RndmEngine.cpp:31
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
HepRndm
Definition: HepRndmBaseEngine.h:27
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: TupleDecorator.h:31
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192