The Gaudi Framework master (934d2c3c)
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
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>
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>
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 <>
146 // Specialized create function for TripleRand engine
147 template <>
151 // Specialized create function for DRand48Engine
152 template <>
156 // Specialized create function for Hurd160Engine
157 template <>
161 // Specialized create function for Hurd288Engine
162 template <>
166 // Specialized create function for RanecuEngine
167 template <>
171 // Specialized create function for RanshiEngine
172 template <>
176 // Specialized create function for RanluxEngine
177 template <>
182 // Specialized create function for Ranlux64Engine
183 template <>
188 // Specialized create function for MTwistEngine
189 template <>
193 // Specialized create function for HepJamesRandom
194 template <>
198} // namespace HepRndm
199
202typedef HepRndm::Engine<TripleRand> e2;
204typedef HepRndm::Engine<DRand48Engine> e3;
206typedef HepRndm::Engine<Hurd160Engine> e4;
208typedef HepRndm::Engine<Hurd288Engine> e5;
210typedef HepRndm::Engine<HepJamesRandom> e6;
212typedef HepRndm::Engine<MTwistEngine> e7;
214typedef HepRndm::Engine<RanecuEngine> e8;
216typedef HepRndm::Engine<Ranlux64Engine> e9;
218typedef HepRndm::Engine<RanluxEngine> e10;
220typedef 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)
_Tp abs(const complex< _Tp > &)
constexpr _OI copy(_II __first, _II __last, _OI __result)
constexpr back_insert_iterator< _Container > back_inserter(_Container &__x)
constexpr void push_back(const value_type &__x)
constexpr const_iterator begin() const noexcept
constexpr const_iterator end() const noexcept
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
auto create_engine(Args &&... args)
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:302
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:254