| The Gaudi Framework v28r2p1 (f1a77ff4)

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