All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 ()
 Standard constructor. More...
 
 Numbers (const Numbers &copy)
 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

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 389 of file RndmGenerators.h.

Constructor & Destructor Documentation

Rndm::Numbers::Numbers ( )

Standard constructor.

Definition at line 12 of file RndmGenerators.cpp.

13 : m_generator(0)
14 {
15 }
IRndmGen * m_generator
Pointer to random number generator.
Rndm::Numbers::Numbers ( const Numbers copy)

Copy constructor.

Definition at line 18 of file RndmGenerators.cpp.

19 : m_generator(copy.m_generator) {
20  if ( 0 != m_generator ) {
22  }
23 }
IRndmGen * m_generator
Pointer to random number generator.
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
Rndm::Numbers::Numbers ( const SmartIF< IRndmGenSvc > &  svc,
const IRndmGen::Param par 
)

Initializing constructor.

Definition at line 26 of file RndmGenerators.cpp.

27 : m_generator(0)
28 {
29  StatusCode status = initialize(svc, par);
30  if (!status.isSuccess()) {
31  throw GaudiException ("Initialization failed !", "Rndm::Numbers", status);
32  }
33 }
Define general base for Gaudi exception.
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:62
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
IRndmGen * m_generator
Pointer to random number generator.
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.
Rndm::Numbers::~Numbers ( )
virtual

Standard destructor.

Definition at line 36 of file RndmGenerators.cpp.

36  {
37  finalize().ignore();
38 }
virtual StatusCode finalize()
Finalization.
void ignore() const
Definition: StatusCode.h:94
Rndm::Numbers::Numbers ( IRndmGenSvc svc,
const IRndmGen::Param par 
)

Initializing constructor.

Definition at line 63 of file RndmGenerators.cpp.

64 : m_generator(0)
65 {
66  StatusCode status = initialize(svc, par);
67  if (!status.isSuccess()) {
68  throw GaudiException ("Initialization failed !", "Rndm::Numbers", status);
69  }
70 }
Define general base for Gaudi exception.
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:62
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
IRndmGen * m_generator
Pointer to random number generator.
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.

Member Function Documentation

StatusCode Rndm::Numbers::finalize ( )
virtual

Finalization.

Definition at line 52 of file RndmGenerators.cpp.

52  {
53  if ( 0 != m_generator ) {
56  m_generator = 0;
57  }
58  return StatusCode::SUCCESS;
59 }
virtual StatusCode finalize()=0
Initialize the generator.
IRndmGen * m_generator
Pointer to random number generator.
virtual unsigned long release()=0
Release Interface instance.
void ignore() const
Definition: StatusCode.h:94
StatusCode Rndm::Numbers::initialize ( const SmartIF< IRndmGenSvc > &  svc,
const IRndmGen::Param par 
)
virtual

Initialization.

Fix-Me:
: this is a hack, but I do not have the time to review the correct constantness of all the methods

Definition at line 41 of file RndmGenerators.cpp.

42  {
43  if ( svc.isValid() && 0 == m_generator ) {
46  return const_cast<IRndmGenSvc*>(svc.get())->generator( par, m_generator );
47  }
48  return StatusCode::FAILURE;
49 }
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
Random Generator service interface definition Definition of a interface for a service to access rando...
Definition: IRndmGenSvc.h:35
IRndmGen * m_generator
Pointer to random number generator.
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
StatusCode Rndm::Numbers::initialize ( IRndmGenSvc svc,
const IRndmGen::Param par 
)
virtual

Initialization.

Definition at line 73 of file RndmGenerators.cpp.

73  {
74  return initialize(SmartIF<IRndmGenSvc>(svc), par);
75 }
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 413 of file RndmGenerators.h.

413  {
414  return m_generator != 0;
415  }
IRndmGen * m_generator
Pointer to random number generator.
double Rndm::Numbers::operator() ( )
inline

Operator () for the use within STL.

Definition at line 417 of file RndmGenerators.h.

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

Pop a new number from the buffer.

Definition at line 421 of file RndmGenerators.h.

421  {
422  return this->shoot();
423  }
double shoot()
Pop a new number from the buffer.
double Rndm::Numbers::shoot ( )
inline

Pop a new number from the buffer.

Definition at line 425 of file RndmGenerators.h.

425  {
426  if ( 0 != m_generator ) {
427  return m_generator->shoot();
428  }
429  return -1;
430  }
IRndmGen * m_generator
Pointer to random number generator.
virtual double shoot() const =0
Single shot returning single random number according to specified distribution.
StatusCode Rndm::Numbers::shootArray ( std::vector< double > &  array,
long  num,
long  start = 0 
)
inline

Pop a new number from the buffer.

Definition at line 432 of file RndmGenerators.h.

432  {
433  if ( 0 != m_generator ) {
434  return m_generator->shootArray(array, num, start);
435  }
436  return StatusCode::FAILURE;
437  }
IRndmGen * m_generator
Pointer to random number generator.
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.
tuple start
Definition: IOTest.py:88

Member Data Documentation

IRndmGen* Rndm::Numbers::m_generator
protected

Pointer to random number generator.

Definition at line 392 of file RndmGenerators.h.


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