The Gaudi Framework  master (37c0b60a)
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. 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() () const
 Operator () for the use within STL. More...
 
double pop () const
 Pop a new number from the buffer. More...
 
double shoot () const
 Pop a new number from the buffer. More...
 
StatusCode shootArray (std::vector< double > &array, long num, long start=0) const
 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 359 of file RndmGenerators.h.

Constructor & Destructor Documentation

◆ Numbers() [1/4]

Rndm::Numbers::Numbers ( )
default

Standard constructor.

◆ Numbers() [2/4]

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

Copy constructor.

◆ Numbers() [3/4]

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

Initializing constructor.

Definition at line 21 of file RndmGenerators.cpp.

21  {
22  StatusCode status = initialize( svc, par );
23  if ( !status.isSuccess() ) { throw GaudiException( "Initialization failed !", "Rndm::Numbers", status ); }
24 }

◆ ~Numbers()

Rndm::Numbers::~Numbers ( )
virtual

Standard destructor.

Definition at line 27 of file RndmGenerators.cpp.

27 { finalize().ignore(); }

◆ Numbers() [4/4]

Rndm::Numbers::Numbers ( IRndmGenSvc svc,
const IRndmGen::Param par 
)

Initializing constructor.

Definition at line 48 of file RndmGenerators.cpp.

48  {
49  StatusCode status = initialize( svc, par );
50  if ( !status.isSuccess() ) { throw GaudiException( "Initialization failed !", "Rndm::Numbers", status ); }
51 }

Member Function Documentation

◆ finalize()

StatusCode Rndm::Numbers::finalize ( )
virtual

Finalization.

Definition at line 36 of file RndmGenerators.cpp.

36  {
37  if ( m_generator ) {
38  m_generator->finalize().ignore();
40  }
41  return StatusCode::SUCCESS;
42 }

◆ initialize() [1/2]

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

Initialization.

Definition at line 30 of file RndmGenerators.cpp.

30  {
31  if ( svc && !m_generator ) m_generator = svc->generator( par );
33 }

◆ initialize() [2/2]

StatusCode Rndm::Numbers::initialize ( IRndmGenSvc svc,
const IRndmGen::Param par 
)
virtual

Initialization.

Definition at line 54 of file RndmGenerators.cpp.

54  {
55  return initialize( SmartIF<IRndmGenSvc>( svc ), par );
56 }

◆ operator bool()

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

Check if the number supply is possible.

Definition at line 386 of file RndmGenerators.h.

386 { return m_generator; }

◆ operator()()

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

Operator () for the use within STL.

Definition at line 388 of file RndmGenerators.h.

388 { return this->shoot(); }

◆ pop()

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

Pop a new number from the buffer.

Definition at line 390 of file RndmGenerators.h.

390 { return this->shoot(); }

◆ shoot()

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

Pop a new number from the buffer.

Definition at line 392 of file RndmGenerators.h.

392 { 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 394 of file RndmGenerators.h.

394  {
395  return m_generator ? m_generator->shootArray( array, num, start ) : StatusCode::FAILURE;
396  }

Member Data Documentation

◆ m_generator

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

Pointer to random number generator.

Definition at line 362 of file RndmGenerators.h.


The documentation for this class was generated from the following files:
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:96
GaudiException
Definition: GaudiException.h:31
Rndm::Numbers::m_generator
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
Definition: RndmGenerators.h:362
IOTest.start
start
Definition: IOTest.py:110
compareOutputFiles.par
par
Definition: compareOutputFiles.py:477
StatusCode
Definition: StatusCode.h:65
Rndm::Numbers::finalize
virtual StatusCode finalize()
Finalization.
Definition: RndmGenerators.cpp:36
Rndm::Numbers::shoot
double shoot() const
Pop a new number from the buffer.
Definition: RndmGenerators.h:392
SmartIF< IRndmGenSvc >
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
Rndm::Numbers::initialize
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.
Definition: RndmGenerators.cpp:30
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101