The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
Rndm::Numbers Class Reference

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

#include </builds/gaudi/Gaudi/GaudiKernel/include/GaudiKernel/RndmGenerators.h>

Collaboration diagram for Rndm::Numbers:

Public Member Functions

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

Protected Attributes

SmartIF< IRndmGenm_generator
 Pointer to random number generator.
 

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

Constructor & Destructor Documentation

◆ Numbers() [1/3]

Rndm::Numbers::Numbers ( )
default

Standard constructor.

◆ Numbers() [2/3]

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

Copy constructor.

◆ Numbers() [3/3]

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

Initializing constructor.

Definition at line 18 of file RndmGenerators.cpp.

18 {
19 StatusCode status = initialize( svc, par );
20 if ( !status.isSuccess() ) { throw GaudiException( "Initialization failed !", "Rndm::Numbers", status ); }
21}
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.
bool isSuccess() const
Definition StatusCode.h:314

◆ ~Numbers()

Rndm::Numbers::~Numbers ( )
virtual

Standard destructor.

Definition at line 24 of file RndmGenerators.cpp.

24{ finalize().ignore(); }
virtual StatusCode finalize()
Finalization.
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition StatusCode.h:139

Member Function Documentation

◆ finalize()

StatusCode Rndm::Numbers::finalize ( )
virtual

Finalization.

Definition at line 33 of file RndmGenerators.cpp.

33 {
34 if ( m_generator ) {
35 m_generator->finalize().ignore();
36 m_generator.reset();
37 }
39}
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
constexpr static const auto SUCCESS
Definition StatusCode.h:99

◆ initialize()

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

Initialization.

Definition at line 27 of file RndmGenerators.cpp.

27 {
28 if ( svc && !m_generator ) m_generator = svc->generator( par );
30}
virtual StatusCode generator(const IRndmGen::Param &par, IRndmGen *&refpGen)=0
Add a Generator factory.
constexpr static const auto FAILURE
Definition StatusCode.h:100

◆ operator bool()

Rndm::Numbers::operator bool ( ) const
inline

Check if the number supply is possible.

Definition at line 373 of file RndmGenerators.h.

373{ return m_generator; }

◆ operator()()

double Rndm::Numbers::operator() ( ) const
inline

Operator () for the use within STL.

Definition at line 375 of file RndmGenerators.h.

375{ return this->shoot(); }
double shoot() const
Pop a new number from the buffer.

◆ pop()

double Rndm::Numbers::pop ( ) const
inline

Pop a new number from the buffer.

Definition at line 377 of file RndmGenerators.h.

377{ return this->shoot(); }

◆ shoot()

double Rndm::Numbers::shoot ( ) const
inline

Pop a new number from the buffer.

Definition at line 379 of file RndmGenerators.h.

379{ return m_generator ? m_generator->shoot() : -1; }

◆ shootArray()

StatusCode Rndm::Numbers::shootArray ( std::vector< double > & array,
long num,
long start = 0 ) const
inline

Pop a new number from the buffer.

Definition at line 381 of file RndmGenerators.h.

381 {
382 return m_generator ? m_generator->shootArray( array, num, start ) : StatusCode::FAILURE;
383 }

Member Data Documentation

◆ m_generator

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

Pointer to random number generator.

Definition at line 357 of file RndmGenerators.h.


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