| The Gaudi Framework v27r1

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