Rndm::Numbers Class Reference

Random number accessor This small class encapsulates the use of the random number generator. More...

#include <GaudiKernel/RndmGenerators.h>

Collaboration diagram for Rndm::Numbers:

Public Member Functions

 Numbers ()=default
 Standard constructor. More...
 
 Numbers (const Numbers &)=default
 Copy constructor. More...
 
 Numbers (const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
 Initializing constructor. More...
 
virtual ~Numbers ()
 Standard destructor. More...
 
virtual StatusCode initialize (const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
 Initialization. More...
 
 Numbers (IRndmGenSvc *svc, const IRndmGen::Param &par)
 Initializing constructor. More...
 
virtual StatusCode initialize (IRndmGenSvc *svc, const IRndmGen::Param &par)
 Initialization. More...
 
virtual StatusCode finalize ()
 Finalization. More...
 
 operator bool () const
 Check if the number supply is possible. More...
 
double operator() ()
 Operator () for the use within STL. More...
 
double pop ()
 Pop a new number from the buffer. More...
 
double shoot ()
 Pop a new number from the buffer. More...
 
StatusCode shootArray (std::vector< double > &array, long num, long start=0)
 Pop a new number from the buffer. More...
 

Protected Attributes

SmartIF< IRndmGenm_generator
 Pointer to random number generator. More...
 

Detailed Description

Random number accessor This small class encapsulates the use of the random number generator.

The sole pupose of this class is to hide the usage of the interface and make the whole thing more user friendly. The object is usable directly after creation.

The typical usage is: Rndm::Numbers numbers(); if ( numbers.initialize(rndmGenSvc, Rndm::Gauss(0.5,0.2)).isSuccess() ) { for ( int i = 0; i < 10; i++ ) { value = numbers(); ... } }

Definition at line 370 of file RndmGenerators.h.

Constructor & Destructor Documentation

Rndm::Numbers::Numbers ( )
default

Standard constructor.

Rndm::Numbers::Numbers ( const Numbers )
default

Copy constructor.

Rndm::Numbers::Numbers ( const SmartIF< IRndmGenSvc > &  svc,
const IRndmGen::Param par 
)

Initializing constructor.

Definition at line 13 of file RndmGenerators.cpp.

14 {
15  StatusCode status = initialize(svc, par);
16  if (!status.isSuccess()) {
17  throw GaudiException ("Initialization failed !", "Rndm::Numbers", status);
18  }
19 }
Define general base for Gaudi exception.
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.
Rndm::Numbers::~Numbers ( )
virtual

Standard destructor.

Definition at line 22 of file RndmGenerators.cpp.

22  {
23  finalize().ignore();
24 }
virtual StatusCode finalize()
Finalization.
void ignore() const
Definition: StatusCode.h:106
Rndm::Numbers::Numbers ( IRndmGenSvc svc,
const IRndmGen::Param par 
)

Initializing constructor.

Definition at line 44 of file RndmGenerators.cpp.

45 {
46  StatusCode status = initialize(svc, par);
47  if (!status.isSuccess()) {
48  throw GaudiException ("Initialization failed !", "Rndm::Numbers", status);
49  }
50 }
Define general base for Gaudi exception.
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.

Member Function Documentation

StatusCode Rndm::Numbers::finalize ( )
virtual

Finalization.

Definition at line 34 of file RndmGenerators.cpp.

34  {
35  if ( m_generator ) {
38  }
39  return StatusCode::SUCCESS;
40 }
virtual StatusCode finalize()=0
Finalize the generator.
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
void ignore() const
Definition: StatusCode.h:106
StatusCode Rndm::Numbers::initialize ( const SmartIF< IRndmGenSvc > &  svc,
const IRndmGen::Param par 
)
virtual

Initialization.

Definition at line 27 of file RndmGenerators.cpp.

28  {
29  if ( svc && !m_generator ) m_generator = svc->generator( par );
31 }
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
virtual StatusCode generator(const IRndmGen::Param &par, IRndmGen *&refpGen)=0
Add a Generator factory.
StatusCode Rndm::Numbers::initialize ( IRndmGenSvc svc,
const IRndmGen::Param par 
)
virtual

Initialization.

Definition at line 53 of file RndmGenerators.cpp.

53  {
54  return initialize(SmartIF<IRndmGenSvc>(svc), par);
55 }
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.
Rndm::Numbers::operator bool ( ) const
inline

Check if the number supply is possible.

Definition at line 394 of file RndmGenerators.h.

394  {
395  return m_generator;
396  }
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
double Rndm::Numbers::operator() ( void  )
inline

Operator () for the use within STL.

Definition at line 398 of file RndmGenerators.h.

398  {
399  return this->shoot();
400  }
double shoot()
Pop a new number from the buffer.
double Rndm::Numbers::pop ( )
inline

Pop a new number from the buffer.

Definition at line 402 of file RndmGenerators.h.

402  {
403  return this->shoot();
404  }
double shoot()
Pop a new number from the buffer.
double Rndm::Numbers::shoot ( )
inline

Pop a new number from the buffer.

Definition at line 406 of file RndmGenerators.h.

406  {
407  return m_generator ? m_generator->shoot()
408  : -1;
409  }
virtual double shoot() const =0
Single shot returning single random number according to specified distribution.
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
StatusCode Rndm::Numbers::shootArray ( std::vector< double > &  array,
long  num,
long  start = 0 
)
inline

Pop a new number from the buffer.

Definition at line 411 of file RndmGenerators.h.

411  {
412  return m_generator ? m_generator->shootArray(array, num, start)
414  }
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
start
Definition: IOTest.py:88
virtual StatusCode shootArray(std::vector< double > &array, long howmany, long start=0) const =0
Multiple shots returning vector with random number according to specified distribution.

Member Data Documentation

SmartIF<IRndmGen> Rndm::Numbers::m_generator
protected

Pointer to random number generator.

Definition at line 373 of file RndmGenerators.h.


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