RndmGenSvc Class Reference

Random Generator service definition. More...

#include <src/RndmGenSvc/RndmGenSvc.h>

Inheritance diagram for RndmGenSvc:
Collaboration diagram for RndmGenSvc:

Public Member Functions

 RndmGenSvc (const std::string &name, ISvcLocator *svc)
 Standard Service constructor. More...
 
 ~RndmGenSvc () override=default
 Standard Service destructor. More...
 
StatusCode initialize () override
 Service override: initialization. More...
 
StatusCode finalize () override
 Service override: finalization. More...
 
StreamBufferserialize (StreamBuffer &str) override
 IRndmGenSvc interface implementation. More...
 
StreamBufferserialize (StreamBuffer &str) const override
 Output serialization to stream buffer. Saves the status of the generator engine. More...
 
IRndmEngineengine () override
 Retrieve engine. More...
 
StatusCode generator (const IRndmGen::Param &par, IRndmGen *&refpGen) override
 Retrieve a valid generator from the service. More...
 
double rndm () const override
 Single shot returning single random number. More...
 
StatusCode rndmArray (std::vector< double > &array, long howmany, long start=0) const override
 Multiple shots returning vector with flat random numbers. More...
 
StatusCode setSeeds (const std::vector< long > &seeds) override
 Allow to set new seeds. More...
 
StatusCode seeds (std::vector< long > &seeds) const override
 Allow to get seeds. More...
 
- Public Member Functions inherited from extends< BASE, Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Attributes

SmartIF< IRndmEnginem_engine
 Random number engine. More...
 
SmartIF< ISerializem_serialize
 Serialization interface of random number engine. More...
 
std::string m_engineName
 Engine name. More...
 

Additional Inherited Members

- Public Types inherited from extends< BASE, Interfaces >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

Detailed Description

Random Generator service definition.

Description: Definition of a interface for a service to access random generators according to predefined distributions. For more detailed explanations please see the interface definition.

Dependencies:

  • Base class: Gaudi/RndmGenSvc/ISerialize.h
  • Base class: Gaudi/RndmGenSvc/IRandomGenSvc.h

History :

+---------+----------------------------------------------+--------+
|    Date |                 Comment                      | Who    |
+---------+----------------------------------------------+--------+
| 21/04/99| Initial version.                             | MF     |
+---------+----------------------------------------------+--------+

Author: M.Frank Version: 1.0

Definition at line 49 of file RndmGenSvc.h.

Constructor & Destructor Documentation

RndmGenSvc::RndmGenSvc ( const std::string &  name,
ISvcLocator svc 
)

Standard Service constructor.

Definition at line 36 of file RndmGenSvc.cpp.

37 : base_class(nam, svc)
38 {
39  declareProperty("Engine", m_engineName = "HepRndm::Engine<CLHEP::RanluxEngine>");
40 }
std::string m_engineName
Engine name.
Definition: RndmGenSvc.h:56
extends base_class
Typedef to this class.
Definition: extends.h:14
RndmGenSvc::~RndmGenSvc ( )
overridedefault

Standard Service destructor.

Member Function Documentation

IRndmEngine * RndmGenSvc::engine ( )
override

Retrieve engine.

Definition at line 106 of file RndmGenSvc.cpp.

106  {
107  return m_engine.get();
108 }
SmartIF< IRndmEngine > m_engine
Random number engine.
Definition: RndmGenSvc.h:52
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
StatusCode RndmGenSvc::finalize ( )
override

Service override: finalization.

Definition at line 78 of file RndmGenSvc.cpp.

78  {
79  StatusCode status = Service::finalize();
81  if ( m_engine ) {
83  m_engine.reset();
84  }
85  return status;
86 }
StatusCode finalize() override
Definition: Service.cpp:188
StatusCode finalize() override
Service override: finalization.
Definition: RndmGenSvc.cpp:78
SmartIF< IRndmEngine > m_engine
Random number engine.
Definition: RndmGenSvc.h:52
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:110
General service interface definition.
Definition: IService.h:18
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
SmartIF< ISerialize > m_serialize
Serialization interface of random number engine.
Definition: RndmGenSvc.h:54
void ignore() const
Definition: StatusCode.h:108
StatusCode RndmGenSvc::generator ( const IRndmGen::Param par,
IRndmGen *&  refpGen 
)
override

Retrieve a valid generator from the service.

Definition at line 111 of file RndmGenSvc.cpp.

111  {
112  auto pGen = SmartIF<IRndmGen>( ObjFactory::create(par.type(),m_engine.get()) );
113  if (!pGen) {
114  refpGen = nullptr;
115  return StatusCode::FAILURE;
116  }
117  refpGen = pGen.get();
118  refpGen->addRef(); // insure the caller gets something with a refCount of (at least) one back...
119  return refpGen->initialize(par);
120 }
virtual StatusCode initialize(const IRndmGen::Param &par)=0
Initialize the generator.
virtual const InterfaceID & type() const
Parameter's type.
Definition: IRndmGen.h:50
SmartIF< IRndmEngine > m_engine
Random number engine.
Definition: RndmGenSvc.h:52
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
StatusCode RndmGenSvc::initialize ( )
override

Service override: initialization.

Definition at line 43 of file RndmGenSvc.cpp.

43  {
45 
46  MsgStream log(msgSvc(), name());
47  auto mgr = serviceLocator()->as<ISvcManager>();
48 
49  if ( status.isSuccess() ) {
50  status = setProperties();
51  if ( status.isSuccess() ) { // Check if the Engine service exists:
52  // FIXME: (MCl) why RndmGenSvc cannot create the engine service in a standard way?
53  const bool CREATE = false;
54  std::string machName = name()+".Engine";
55  auto engine = serviceLocator()->service<IRndmEngine>(machName, CREATE);
56  if ( !engine && mgr ) {
58  engine = mgr->createService(TypeNameString(machName, m_engineName));
59  }
60  if ( engine ) {
61  auto serial = engine.as<ISerialize>();
62  auto service = engine.as<IService>();
63  if ( serial && service ) {
64  status = service->sysInitialize();
65  if ( status.isSuccess() ) {
66  m_engine = engine;
67  m_serialize = serial;
68  log << MSG::INFO << "Using Random engine:" << m_engineName << endmsg;
69  }
70  }
71  }
72  }
73  }
74  return status;
75 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode initialize() override
Definition: Service.cpp:63
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
The ISvcManager is the interface implemented by the Service Factory in the Application Manager to sup...
Definition: ISvcManager.h:28
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
std::string m_engineName
Engine name.
Definition: RndmGenSvc.h:56
SmartIF< IRndmEngine > m_engine
Random number engine.
Definition: RndmGenSvc.h:52
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:9
General service interface definition.
Definition: IService.h:18
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Definition of a interface for a generic random number generator giving randomly distributed numbers i...
Definition: IRndmEngine.h:19
IRndmEngine * engine() override
Retrieve engine.
Definition: RndmGenSvc.cpp:106
SmartIF< ISerialize > m_serialize
Serialization interface of random number engine.
Definition: RndmGenSvc.h:54
Object serialization interface definition.
Definition: ISerialize.h:17
double RndmGenSvc::rndm ( ) const
override

Single shot returning single random number.

Definition at line 123 of file RndmGenSvc.cpp.

123  {
124  return m_engine ? m_engine->rndm() : -1;
125 }
SmartIF< IRndmEngine > m_engine
Random number engine.
Definition: RndmGenSvc.h:52
virtual double rndm() const =0
Single shot returning single random number.
StatusCode RndmGenSvc::rndmArray ( std::vector< double > &  array,
long  howmany,
long  start = 0 
) const
override

Multiple shots returning vector with flat random numbers.

Parameters
arrayArray containing random numbers
howmanyfill 'howmany' random numbers into array
start... starting at position start
Returns
StatusCode indicating failure or success.

Definition at line 133 of file RndmGenSvc.cpp.

133  {
134  return m_engine ? m_engine->rndmArray(array, howmany, start)
136 }
virtual StatusCode rndmArray(std::vector< double > &array, long howmany, long start=0) const =0
Multiple shots returning vector with flat random numbers.
SmartIF< IRndmEngine > m_engine
Random number engine.
Definition: RndmGenSvc.h:52
tuple start
Definition: IOTest.py:88
StatusCode RndmGenSvc::seeds ( std::vector< long > &  seeds) const
override

Allow to get seeds.

Definition at line 145 of file RndmGenSvc.cpp.

145  {
146  return m_engine ? m_engine->seeds(seeds)
148 }
SmartIF< IRndmEngine > m_engine
Random number engine.
Definition: RndmGenSvc.h:52
virtual StatusCode seeds(std::vector< long > &seeds) const =0
Allow to retrieve seeds.
StreamBuffer & RndmGenSvc::serialize ( StreamBuffer str)
override

IRndmGenSvc interface implementation.

Input serialization from stream buffer. Restores the status of the generator engine.

Definition at line 90 of file RndmGenSvc.cpp.

90  {
91  if ( m_serialize ) return m_serialize->serialize(str);
92  MsgStream log(msgSvc(), name());
93  log << MSG::ERROR << "Cannot input serialize Generator settings!" << endmsg;
94  return str;
95 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual StreamBuffer & serialize(StreamBuffer &str)=0
Input serialization from stream buffer.
SmartIF< ISerialize > m_serialize
Serialization interface of random number engine.
Definition: RndmGenSvc.h:54
StreamBuffer & RndmGenSvc::serialize ( StreamBuffer str) const
override

Output serialization to stream buffer. Saves the status of the generator engine.

Definition at line 98 of file RndmGenSvc.cpp.

98  {
99  if ( m_serialize ) return m_serialize->serialize(str);
100  MsgStream log(msgSvc(), name());
101  log << MSG::ERROR << "Cannot output serialize Generator settings!" << endmsg;
102  return str;
103 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual StreamBuffer & serialize(StreamBuffer &str)=0
Input serialization from stream buffer.
SmartIF< ISerialize > m_serialize
Serialization interface of random number engine.
Definition: RndmGenSvc.h:54
StatusCode RndmGenSvc::setSeeds ( const std::vector< long > &  seeds)
override

Allow to set new seeds.

Definition at line 139 of file RndmGenSvc.cpp.

139  {
140  return m_engine ? m_engine->setSeeds(seeds)
142 }
SmartIF< IRndmEngine > m_engine
Random number engine.
Definition: RndmGenSvc.h:52
virtual StatusCode setSeeds(const std::vector< long > &seeds)=0
Allow to set new seeds.

Member Data Documentation

SmartIF<IRndmEngine> RndmGenSvc::m_engine
mutableprivate

Random number engine.

Definition at line 52 of file RndmGenSvc.h.

std::string RndmGenSvc::m_engineName
private

Engine name.

Definition at line 56 of file RndmGenSvc.h.

SmartIF<ISerialize> RndmGenSvc::m_serialize
mutableprivate

Serialization interface of random number engine.

Definition at line 54 of file RndmGenSvc.h.


The documentation for this class was generated from the following files: