Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (01b473db)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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...
 
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 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 }

◆ ~Numbers()

Rndm::Numbers::~Numbers ( )
virtual

Standard destructor.

Definition at line 24 of file RndmGenerators.cpp.

24 { finalize().ignore(); }

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();
37  }
38  return StatusCode::SUCCESS;
39 }

◆ 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 }

◆ 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(); }

◆ 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:
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:88
GaudiException
Definition: GaudiException.h:29
Rndm::Numbers::m_generator
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
Definition: RndmGenerators.h:357
IOTest.start
start
Definition: IOTest.py:110
compareOutputFiles.par
par
Definition: compareOutputFiles.py:477
StatusCode
Definition: StatusCode.h:64
Rndm::Numbers::finalize
virtual StatusCode finalize()
Finalization.
Definition: RndmGenerators.cpp:33
Rndm::Numbers::shoot
double shoot() const
Pop a new number from the buffer.
Definition: RndmGenerators.h:379
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:27
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:99
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:100