The Gaudi Framework  v30r3 (a5ef0a68)
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 368 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 11 of file RndmGenerators.cpp.

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

Standard destructor.

Definition at line 20 of file RndmGenerators.cpp.

20 { finalize().ignore(); }
virtual StatusCode finalize()
Finalization.
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:165
Rndm::Numbers::Numbers ( IRndmGenSvc svc,
const IRndmGen::Param par 
)

Initializing constructor.

Definition at line 41 of file RndmGenerators.cpp.

42 {
43  StatusCode status = initialize( svc, par );
44  if ( !status.isSuccess() ) {
45  throw GaudiException( "Initialization failed !", "Rndm::Numbers", status );
46  }
47 }
Define general base for Gaudi exception.
bool isSuccess() const
Definition: StatusCode.h:287
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.

Member Function Documentation

StatusCode Rndm::Numbers::finalize ( )
virtual

Finalization.

Definition at line 30 of file RndmGenerators.cpp.

31 {
32  if ( m_generator ) {
35  }
36  return StatusCode::SUCCESS;
37 }
virtual StatusCode finalize()=0
Finalize the generator.
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:165
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:92
StatusCode Rndm::Numbers::initialize ( const SmartIF< IRndmGenSvc > &  svc,
const IRndmGen::Param par 
)
virtual

Initialization.

Definition at line 23 of file RndmGenerators.cpp.

24 {
25  if ( svc && !m_generator ) m_generator = svc->generator( par );
27 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
virtual StatusCode generator(const IRndmGen::Param &par, IRndmGen *&refpGen)=0
Add a Generator factory.
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
StatusCode Rndm::Numbers::initialize ( IRndmGenSvc svc,
const IRndmGen::Param par 
)
virtual

Initialization.

Definition at line 50 of file RndmGenerators.cpp.

51 {
52  return initialize( SmartIF<IRndmGenSvc>( svc ), par );
53 }
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 { return m_generator; }
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
double Rndm::Numbers::operator() ( )
inline

Operator () for the use within STL.

Definition at line 396 of file RndmGenerators.h.

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

Pop a new number from the buffer.

Definition at line 398 of file RndmGenerators.h.

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

Pop a new number from the buffer.

Definition at line 400 of file RndmGenerators.h.

400 { return m_generator ? m_generator->shoot() : -1; }
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 402 of file RndmGenerators.h.

403  {
404  return m_generator ? m_generator->shootArray( array, num, start ) : StatusCode::FAILURE;
405  }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
start
Definition: IOTest.py:99
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 372 of file RndmGenerators.h.


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