The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
HepRndmEngines.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2024 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
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
60namespace CLHEP {}
61using namespace CLHEP;
62
63namespace HepRndm {
64
65 // Initialize engine
66 template <class TYPE>
68 auto& seeds = m_seeds.value();
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>
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 ? std::make_unique<DualRand>( m_row, m_col ) : std::make_unique<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 ? std::make_unique<TripleRand>( m_row, m_col ) : std::make_unique<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 ? std::make_unique<DRand48Engine>( m_row, m_col ) : std::make_unique<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 ? std::make_unique<Hurd160Engine>( m_row, m_col ) : std::make_unique<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 ? std::make_unique<Hurd288Engine>( m_row, m_col ) : std::make_unique<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 ? std::make_unique<RanecuEngine>( m_row ) : std::make_unique<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 ? std::make_unique<RanshiEngine>( m_row, m_col ) : std::make_unique<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 ? std::make_unique<RanluxEngine>( m_row, m_col, m_lux )
180 : std::make_unique<RanluxEngine>( 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 ? std::make_unique<Ranlux64Engine>( m_row, m_col, m_lux )
186 : std::make_unique<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 ? std::make_unique<MTwistEngine>( m_row, m_col ) : std::make_unique<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 ? std::make_unique<HepJamesRandom>( m_row, m_col )
197 : std::make_unique<HepJamesRandom>( m_seeds[0] );
198 }
199} // namespace HepRndm
200
203typedef HepRndm::Engine<TripleRand> e2;
205typedef HepRndm::Engine<DRand48Engine> e3;
207typedef HepRndm::Engine<Hurd160Engine> e4;
209typedef HepRndm::Engine<Hurd288Engine> e5;
211typedef HepRndm::Engine<HepJamesRandom> e6;
213typedef HepRndm::Engine<MTwistEngine> e7;
215typedef HepRndm::Engine<RanecuEngine> e8;
217typedef HepRndm::Engine<Ranlux64Engine> e9;
219typedef HepRndm::Engine<RanluxEngine> e10;
221typedef HepRndm::Engine<RanshiEngine> e11;
HepRndm::Engine< Hurd160Engine > e4
HepRndm::Engine< RanecuEngine > e8
HepRndm::Engine< HepJamesRandom > e6
HepRndm::Engine< RanshiEngine > e11
HepRndm::Engine< RanluxEngine > e10
HepRndm::Engine< TripleRand > e2
HepRndm::Engine< Hurd288Engine > e5
HepRndm::Engine< DRand48Engine > e3
HepRndm::Engine< MTwistEngine > e7
HepRndm::Engine< DualRand > e1
HepRndm::Engine< Ranlux64Engine > e9
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
StatusCode finalize() override
CLHEP::HepRandomEngine * hepEngine()
StatusCode finalize() override
Finalize the Engine.
Gaudi::Property< std::vector< long > > m_seeds
Gaudi::Property< int > m_lux
StatusCode initialize() override
Initialize the Engine.
Gaudi::Property< int > m_row
Gaudi::Property< bool > m_setSingleton
Gaudi::Property< int > m_col
StatusCode setSeeds(const std::vector< long > &seed) override
Set seeds.
std::unique_ptr< CLHEP::HepRandomEngine > createEngine() override
Create new HepEngine....
StatusCode seeds(std::vector< long > &seed) const override
Retrieve seeds.
Gaudi::Property< bool > m_useTable
StatusCode initialize() override
Definition Service.cpp:118
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isSuccess() const
Definition StatusCode.h:314
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition System.cpp:260