The Gaudi Framework  v36r1 (3e2fb5a8)
HepRndmEngines.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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
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>
68  auto& seeds = m_seeds.value();
69  seeds.clear();
71  if ( m_seeds.size() == 0 ) {
72  // Default seeds
73  long theSeed = 1234567;
74  seeds.push_back( theSeed );
75  seeds.push_back( 0 );
76  }
77  if ( status.isSuccess() ) {
78  initEngine();
79  info() << "Generator engine type:" << System::typeinfoName( typeid( *hepEngine() ) ) << endmsg;
80  if ( m_useTable ) {
81  if ( m_row > 214 || m_col > 1 ) {
82  error() << "Generator engine seed table has dimension [215][2], you gave:"
83  << " Row=" << m_row << " Column:" << m_col << endmsg;
84  status = StatusCode::FAILURE;
85  } else {
86  info() << "Generator engine seeds from table."
87  << " Row=" << m_row << " Column:" << m_col << endmsg;
88  }
89  }
90  info() << "Current Seed:" << hepEngine()->getSeed();
91  info() << " Luxury:" << m_lux.value();
92  info() << endmsg;
93  // Use the default static engine if required (e.g. for GEANT4)
94  if ( m_setSingleton ) {
95  HepRandom::setTheEngine( hepEngine() );
96  info() << "This is the GEANT4 engine!" << endmsg;
97  }
98  return status;
99  }
100  error() << "Cannot initialze random engine of type:" << System::typeinfoName( typeid( TYPE ) ) << endmsg;
101  return status;
102  }
103 
104  // Finalize engine
105  template <class TYPE>
107  m_seeds.value().clear();
108  return BaseEngine::finalize();
109  }
110 
111  // Retrieve seeds
112  template <class TYPE>
114  auto& seeds = m_seeds.value();
115  seeds.clear();
116  std::copy( seed.begin(), seed.end(), std::back_inserter( seeds ) );
117  if ( !seeds.empty() ) {
118  if ( seeds.back() != 0 ) { seeds.push_back( 0 ); }
119  hepEngine()->setSeeds( &seeds[0], m_lux );
120  return StatusCode::SUCCESS;
121  }
122  return StatusCode::FAILURE;
123  }
124 
125  // Retrieve seeds
126  template <class TYPE>
128  /*
129  const long *s = hepEngine()->getSeeds();
130  for ( size_t i = 0; i < NUMBER_OF_SEEDS; i++ ) {
131  seed.push_back(s[i]);
132  if ( m_seeds.size() > i )
133  m_seeds[i] = s[i];
134  else
135  m_seeds.push_back(s[i]);
136  }
137  */
138  seed.push_back( hepEngine()->getSeed() );
139  return StatusCode::SUCCESS;
140  }
141 
142  // Specialized create function for DualRand engine
143  template <>
145  return m_useTable ? std::make_unique<DualRand>( m_row, m_col ) : std::make_unique<DualRand>( m_seeds[0] );
146  }
147  // Specialized create function for TripleRand engine
148  template <>
150  return m_useTable ? std::make_unique<TripleRand>( m_row, m_col ) : std::make_unique<TripleRand>( m_seeds[0] );
151  }
152  // Specialized create function for DRand48Engine
153  template <>
155  return m_useTable ? std::make_unique<DRand48Engine>( m_row, m_col ) : std::make_unique<DRand48Engine>( m_seeds[0] );
156  }
157  // Specialized create function for Hurd160Engine
158  template <>
160  return m_useTable ? std::make_unique<Hurd160Engine>( m_row, m_col ) : std::make_unique<Hurd160Engine>( m_seeds[0] );
161  }
162  // Specialized create function for Hurd288Engine
163  template <>
165  return m_useTable ? std::make_unique<Hurd288Engine>( m_row, m_col ) : std::make_unique<Hurd288Engine>( m_seeds[0] );
166  }
167  // Specialized create function for RanecuEngine
168  template <>
170  return m_useTable ? std::make_unique<RanecuEngine>( m_row ) : std::make_unique<RanecuEngine>( m_seeds[0] );
171  }
172  // Specialized create function for RanshiEngine
173  template <>
175  return m_useTable ? std::make_unique<RanshiEngine>( m_row, m_col ) : std::make_unique<RanshiEngine>( m_seeds[0] );
176  }
177  // Specialized create function for RanluxEngine
178  template <>
180  return m_useTable ? std::make_unique<RanluxEngine>( m_row, m_col, m_lux )
181  : std::make_unique<RanluxEngine>( m_seeds[0], m_lux );
182  }
183  // Specialized create function for Ranlux64Engine
184  template <>
186  return m_useTable ? std::make_unique<Ranlux64Engine>( m_row, m_col, m_lux )
187  : std::make_unique<Ranlux64Engine>( m_seeds[0], m_lux );
188  }
189  // Specialized create function for MTwistEngine
190  template <>
192  return m_useTable ? std::make_unique<MTwistEngine>( m_row, m_col ) : std::make_unique<MTwistEngine>( m_seeds[0] );
193  }
194  // Specialized create function for HepJamesRandom
195  template <>
197  return m_useTable ? std::make_unique<HepJamesRandom>( m_row, m_col )
198  : std::make_unique<HepJamesRandom>( m_seeds[0] );
199  }
200 } // namespace HepRndm
201 
204 typedef HepRndm::Engine<TripleRand> e2;
206 typedef HepRndm::Engine<DRand48Engine> e3;
208 typedef HepRndm::Engine<Hurd160Engine> e4;
210 typedef HepRndm::Engine<Hurd288Engine> e5;
212 typedef HepRndm::Engine<HepJamesRandom> e6;
214 typedef HepRndm::Engine<MTwistEngine> e7;
216 typedef HepRndm::Engine<RanecuEngine> e8;
218 typedef HepRndm::Engine<Ranlux64Engine> e9;
220 typedef HepRndm::Engine<RanluxEngine> e10;
222 typedef HepRndm::Engine<RanshiEngine> e11;
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:118
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:355
System.h
std::vector< long >
std::back_inserter
T back_inserter(T... args)
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:308
RndmGenSvc.h
IIncidentSvc.h
HepRndm
Definition: HepRndmBaseEngine.h:37
std::vector::push_back
T push_back(T... args)
e1
HepRndm::Engine< DualRand > e1
Definition: HepRndmEngines.cpp:202
HepRndmEngine.h
StatusCode
Definition: StatusCode.h:65
std::copy
T copy(T... args)
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
CLHEP
Definition: TupleAlg.cpp:37
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
std::vector::begin
T begin(T... args)
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
HepRndm::Engine
Definition: HepRndmEngine.h:35
std::vector::end
T end(T... args)
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
std::unique_ptr< CLHEP::HepRandomEngine >
MsgStream.h