The Gaudi Framework
master (bdbe7744)
Toggle main menu visibility
Loading...
Searching...
No Matches
HepRndmEngines.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2026 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
//====================================================================
12
// Random Engine implementations
13
//--------------------------------------------------------------------
14
//
15
// Package : HepRndm ( The LHCb Offline System)
16
// Author : M.Frank
17
// History :
18
// +---------+----------------------------------------------+---------
19
// | Date | Comment | Who
20
// +---------+----------------------------------------------+---------
21
// | 29/10/99| Initial version | MF
22
// +---------+----------------------------------------------+---------
23
//
24
// Note: Currently all engines require only ONE seed
25
// We aill return only the first number, because
26
// the implementation in CLHEP does not allow to
27
// determine the proper number of seeds used.
28
#define NUMBER_OF_SEEDS 1
29
//
30
//====================================================================
31
#define HEPRNDM_HEPRNDMENGINES_CPP
32
33
// STL include files
34
#include <cfloat>
35
#include <cmath>
36
#include <ctime>
37
#include <iostream>
38
39
// Framework include files
40
#include <
GaudiKernel/IIncidentSvc.h
>
41
#include <
GaudiKernel/MsgStream.h
>
42
#include <
GaudiKernel/System.h
>
43
44
#include "
HepRndmEngine.h
"
45
#include "
RndmGenSvc.h
"
46
47
#include <CLHEP/Random/DRand48Engine.h>
48
#include <CLHEP/Random/DualRand.h>
49
#include <CLHEP/Random/Hurd160Engine.h>
50
#include <CLHEP/Random/Hurd288Engine.h>
51
#include <CLHEP/Random/JamesRandom.h>
52
#include <CLHEP/Random/MTwistEngine.h>
53
#include <CLHEP/Random/RanecuEngine.h>
54
#include <CLHEP/Random/Ranlux64Engine.h>
55
#include <CLHEP/Random/RanluxEngine.h>
56
#include <CLHEP/Random/RanshiEngine.h>
57
#include <CLHEP/Random/TripleRand.h>
58
59
// Handle CLHEP 2.0.x move to CLHEP namespace
60
namespace
CLHEP
{}
61
using namespace
CLHEP
;
62
63
namespace
HepRndm
{
64
65
// Initialize engine
66
template
<
class
TYPE>
67
StatusCode
Engine<TYPE>::initialize
() {
68
auto
&
seeds
=
m_seeds
.value();
69
StatusCode
status =
RndmEngine::initialize
();
70
if
(
m_seeds
.size() == 0 ) {
71
// Default seeds
72
long
theSeed = 1234567;
73
seeds
.push_back( theSeed );
74
seeds
.push_back( 0 );
75
}
76
if
( status.
isSuccess
() ) {
77
initEngine
();
78
info
() <<
"Generator engine type:"
<<
System::typeinfoName
(
typeid
( *
hepEngine
() ) ) <<
endmsg
;
79
if
(
m_useTable
) {
80
if
(
m_row
> 214 ||
m_col
> 1 ) {
81
error
() <<
"Generator engine seed table has dimension [215][2], you gave:"
82
<<
" Row="
<<
m_row
<<
" Column:"
<<
m_col
<<
endmsg
;
83
status =
StatusCode::FAILURE
;
84
}
else
{
85
info
() <<
"Generator engine seeds from table."
86
<<
" Row="
<<
m_row
<<
" Column:"
<<
m_col
<<
endmsg
;
87
}
88
}
89
info
() <<
"Current Seed:"
<<
hepEngine
()->getSeed();
90
info
() <<
" Luxury:"
<<
m_lux
.value();
91
info
() <<
endmsg
;
92
// Use the default static engine if required (e.g. for GEANT4)
93
if
(
m_setSingleton
) {
94
HepRandom::setTheEngine(
hepEngine
() );
95
info
() <<
"This is the GEANT4 engine!"
<<
endmsg
;
96
}
97
return
status;
98
}
99
error
() <<
"Cannot initialze random engine of type:"
<<
System::typeinfoName
(
typeid
( TYPE ) ) <<
endmsg
;
100
return
status;
101
}
102
103
// Finalize engine
104
template
<
class
TYPE>
105
StatusCode
Engine<TYPE>::finalize
() {
106
m_seeds
.value().clear();
107
return
BaseEngine::finalize
();
108
}
109
110
// Retrieve seeds
111
template
<
class
TYPE>
112
StatusCode
Engine<TYPE>::setSeeds
(
const
std::vector<long>& seed ) {
113
auto
&
seeds
=
m_seeds
.value();
114
seeds
.clear();
115
std::copy( seed.begin(), seed.end(), std::back_inserter(
seeds
) );
116
if
( !
seeds
.empty() ) {
117
if
(
seeds
.back() != 0 ) {
seeds
.push_back( 0 ); }
118
hepEngine
()->setSeeds( &
seeds
[0],
m_lux
);
119
return
StatusCode::SUCCESS
;
120
}
121
return
StatusCode::FAILURE
;
122
}
123
124
// Retrieve seeds
125
template
<
class
TYPE>
126
StatusCode
Engine<TYPE>::seeds
( std::vector<long>& seed )
const
{
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
return
m_useTable
?
create_engine<DualRand>
(
m_row
,
m_col
) :
create_engine<DualRand>
(
m_seeds
[0] );
145
}
146
// Specialized create function for TripleRand engine
147
template
<>
148
std::unique_ptr<CLHEP::HepRandomEngine>
Engine<TripleRand>::createEngine
() {
149
return
m_useTable
?
create_engine<TripleRand>
(
m_row
,
m_col
) :
create_engine<TripleRand>
(
m_seeds
[0] );
150
}
151
// Specialized create function for DRand48Engine
152
template
<>
153
std::unique_ptr<CLHEP::HepRandomEngine>
Engine<DRand48Engine>::createEngine
() {
154
return
m_useTable
?
create_engine<DRand48Engine>
(
m_row
,
m_col
) :
create_engine<DRand48Engine>
(
m_seeds
[0] );
155
}
156
// Specialized create function for Hurd160Engine
157
template
<>
158
std::unique_ptr<CLHEP::HepRandomEngine>
Engine<Hurd160Engine>::createEngine
() {
159
return
m_useTable
?
create_engine<Hurd160Engine>
(
m_row
,
m_col
) :
create_engine<Hurd160Engine>
(
m_seeds
[0] );
160
}
161
// Specialized create function for Hurd288Engine
162
template
<>
163
std::unique_ptr<CLHEP::HepRandomEngine>
Engine<Hurd288Engine>::createEngine
() {
164
return
m_useTable
?
create_engine<Hurd288Engine>
(
m_row
,
m_col
) :
create_engine<Hurd288Engine>
(
m_seeds
[0] );
165
}
166
// Specialized create function for RanecuEngine
167
template
<>
168
std::unique_ptr<CLHEP::HepRandomEngine>
Engine<RanecuEngine>::createEngine
() {
169
return
m_useTable
?
create_engine<RanecuEngine>
(
m_row
) :
create_engine<RanecuEngine>
(
m_seeds
[0] );
170
}
171
// Specialized create function for RanshiEngine
172
template
<>
173
std::unique_ptr<CLHEP::HepRandomEngine>
Engine<RanshiEngine>::createEngine
() {
174
return
m_useTable
?
create_engine<RanshiEngine>
(
m_row
,
m_col
) :
create_engine<RanshiEngine>
(
m_seeds
[0] );
175
}
176
// Specialized create function for RanluxEngine
177
template
<>
178
std::unique_ptr<CLHEP::HepRandomEngine>
Engine<RanluxEngine>::createEngine
() {
179
return
m_useTable
?
create_engine<RanluxEngine>
(
m_row
,
m_col
,
m_lux
)
180
:
create_engine<RanluxEngine>
(
std::abs
(
m_seeds
[0] ),
m_lux
);
181
}
182
// Specialized create function for Ranlux64Engine
183
template
<>
184
std::unique_ptr<CLHEP::HepRandomEngine>
Engine<Ranlux64Engine>::createEngine
() {
185
return
m_useTable
?
create_engine<Ranlux64Engine>
(
m_row
,
m_col
,
m_lux
)
186
:
create_engine<Ranlux64Engine>
(
m_seeds
[0],
m_lux
);
187
}
188
// Specialized create function for MTwistEngine
189
template
<>
190
std::unique_ptr<CLHEP::HepRandomEngine>
Engine<MTwistEngine>::createEngine
() {
191
return
m_useTable
?
create_engine<MTwistEngine>
(
m_row
,
m_col
) :
create_engine<MTwistEngine>
(
m_seeds
[0] );
192
}
193
// Specialized create function for HepJamesRandom
194
template
<>
195
std::unique_ptr<CLHEP::HepRandomEngine>
Engine<HepJamesRandom>::createEngine
() {
196
return
m_useTable
?
create_engine<HepJamesRandom>
(
m_row
,
m_col
) :
create_engine<HepJamesRandom>
(
m_seeds
[0] );
197
}
198
}
// namespace HepRndm
199
200
typedef
HepRndm::Engine<DualRand>
e1
;
201
DECLARE_COMPONENT
(
e1
)
202
typedef
HepRndm
::Engine<TripleRand>
e2
;
203
DECLARE_COMPONENT
(
e2
)
204
typedef
HepRndm
::Engine<DRand48Engine>
e3
;
205
DECLARE_COMPONENT
(
e3
)
206
typedef
HepRndm
::Engine<Hurd160Engine>
e4
;
207
DECLARE_COMPONENT
(
e4
)
208
typedef
HepRndm
::Engine<Hurd288Engine>
e5
;
209
DECLARE_COMPONENT
(
e5
)
210
typedef
HepRndm
::Engine<HepJamesRandom>
e6
;
211
DECLARE_COMPONENT
(
e6
)
212
typedef
HepRndm
::Engine<MTwistEngine>
e7
;
213
DECLARE_COMPONENT
(
e7
)
214
typedef
HepRndm
::Engine<RanecuEngine>
e8
;
215
DECLARE_COMPONENT
(
e8
)
216
typedef
HepRndm
::Engine<Ranlux64Engine>
e9
;
217
DECLARE_COMPONENT
(
e9
)
218
typedef
HepRndm
::Engine<RanluxEngine>
e10
;
219
DECLARE_COMPONENT
(
e10
)
220
typedef
HepRndm
::Engine<RanshiEngine>
e11
;
221
DECLARE_COMPONENT
(
e11
)
HepRndmEngine.h
e4
HepRndm::Engine< Hurd160Engine > e4
Definition
HepRndmEngines.cpp:206
e8
HepRndm::Engine< RanecuEngine > e8
Definition
HepRndmEngines.cpp:214
e6
HepRndm::Engine< HepJamesRandom > e6
Definition
HepRndmEngines.cpp:210
e11
HepRndm::Engine< RanshiEngine > e11
Definition
HepRndmEngines.cpp:220
e10
HepRndm::Engine< RanluxEngine > e10
Definition
HepRndmEngines.cpp:218
e2
HepRndm::Engine< TripleRand > e2
Definition
HepRndmEngines.cpp:202
e5
HepRndm::Engine< Hurd288Engine > e5
Definition
HepRndmEngines.cpp:208
e3
HepRndm::Engine< DRand48Engine > e3
Definition
HepRndmEngines.cpp:204
e7
HepRndm::Engine< MTwistEngine > e7
Definition
HepRndmEngines.cpp:212
e1
HepRndm::Engine< DualRand > e1
Definition
HepRndmEngines.cpp:200
e9
HepRndm::Engine< Ranlux64Engine > e9
Definition
HepRndmEngines.cpp:216
IIncidentSvc.h
MsgStream.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition
PluginServiceV1.h:45
RndmGenSvc.h
System.h
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition
CommonMessaging.h:109
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition
CommonMessaging.h:115
HepRndm::BaseEngine::create_engine
auto create_engine(Args &&... args)
Definition
HepRndmBaseEngine.h:141
HepRndm::BaseEngine::finalize
StatusCode finalize() override
Definition
HepRndmBaseEngine.h:131
HepRndm::BaseEngine::hepEngine
CLHEP::HepRandomEngine * hepEngine()
Definition
HepRndmBaseEngine.h:126
HepRndm::BaseEngine::initEngine
void initEngine()
Definition
HepRndmBaseEngine.h:138
HepRndm::Engine
Definition
HepRndmEngine.h:34
HepRndm::Engine::finalize
StatusCode finalize() override
Finalize the Engine.
Definition
HepRndmEngines.cpp:105
HepRndm::Engine::m_seeds
Gaudi::Property< std::vector< long > > m_seeds
Definition
HepRndmEngine.h:36
HepRndm::Engine::m_lux
Gaudi::Property< int > m_lux
Definition
HepRndmEngine.h:40
HepRndm::Engine::initialize
StatusCode initialize() override
Initialize the Engine.
Definition
HepRndmEngines.cpp:67
HepRndm::Engine::m_row
Gaudi::Property< int > m_row
Definition
HepRndmEngine.h:39
HepRndm::Engine::m_setSingleton
Gaudi::Property< bool > m_setSingleton
Definition
HepRndmEngine.h:42
HepRndm::Engine::m_col
Gaudi::Property< int > m_col
Definition
HepRndmEngine.h:38
HepRndm::Engine::setSeeds
StatusCode setSeeds(const std::vector< long > &seed) override
Set seeds.
Definition
HepRndmEngines.cpp:112
HepRndm::Engine::createEngine
std::unique_ptr< CLHEP::HepRandomEngine > createEngine() override
Create new HepEngine....
HepRndm::Engine::seeds
StatusCode seeds(std::vector< long > &seed) const override
Retrieve seeds.
Definition
HepRndmEngines.cpp:126
HepRndm::Engine::m_useTable
Gaudi::Property< bool > m_useTable
Definition
HepRndmEngine.h:41
Service::initialize
StatusCode initialize() override
Definition
Service.cpp:118
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::isSuccess
bool isSuccess() const
Definition
StatusCode.h:302
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
CLHEP
Definition
HepRndmBaseEngine.h:35
HepRndm
Definition
HepRndmBaseEngine.h:39
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition
System.cpp:254
std::abs
Gaudi::ParticleID abs(const Gaudi::ParticleID &p)
Return the absolute value for a PID.
Definition
ParticleID.h:191
GaudiSvc
src
RndmGenSvc
HepRndmEngines.cpp
Generated on
for The Gaudi Framework by
1.17.0