| The Gaudi Framework v32r1 (f65d50dc)

Public Member Functions | Protected Attributes | List of all members
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:
[legend]

## 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< IRndmGen > | m_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 349 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 11 of file RndmGenerators.cpp.

11 {
12 StatusCode status = initialize( svc, par );
13 if ( !status.isSuccess() ) { throw GaudiException( "Initialization failed !", "Rndm::Numbers", status ); }
14 }
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
compareOutputFiles.par
string par
Definition: compareOutputFiles.py:465
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
Rndm::Numbers::initialize
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.
Definition: RndmGenerators.cpp:20

## ◆ ~Numbers()

Rndm::Numbers::~Numbers | ( |  | ) |
| virtual

Standard destructor.

Definition at line 17 of file RndmGenerators.cpp.

17 { finalize().ignore(); }
Rndm::Numbers::finalize
virtual StatusCode finalize()
Finalization.
Definition: RndmGenerators.cpp:26
StatusCode::ignore
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153

## ◆ Numbers() [4/4]

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

Initializing constructor.

Definition at line 36 of file RndmGenerators.cpp.

36 {
37 StatusCode status = initialize( svc, par );
38 if ( !status.isSuccess() ) { throw GaudiException( "Initialization failed !", "Rndm::Numbers", status ); }
39 }
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
compareOutputFiles.par
string par
Definition: compareOutputFiles.py:465
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
Rndm::Numbers::initialize
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.
Definition: RndmGenerators.cpp:20

## Member Function Documentation

## ◆ finalize()

StatusCode Rndm::Numbers::finalize | ( |  | ) |
| virtual

Finalization.

Definition at line 26 of file RndmGenerators.cpp.

26 {
27 if ( m_generator ) {
28 m_generator->finalize().ignore();
29 m_generator.reset();
30 }
31 return StatusCode::SUCCESS;
32 }
IRndmGen::finalize
virtual StatusCode finalize()=0
Finalize the generator.
Rndm::Numbers::m_generator
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
Definition: RndmGenerators.h:352
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
StatusCode::ignore
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:86

## ◆ initialize() [1/2]

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

Initialization.

Definition at line 20 of file RndmGenerators.cpp.

20 {
21 if ( svc && !m_generator ) m_generator = svc->generator( par );
22 return m_generator ? StatusCode::SUCCESS : StatusCode::FAILURE;
23 }
Rndm::Numbers::m_generator
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
Definition: RndmGenerators.h:352
IRndmGenSvc::generator
virtual StatusCode generator(const IRndmGen::Param &par, IRndmGen *&refpGen)=0
Add a Generator factory.
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
compareOutputFiles.par
string par
Definition: compareOutputFiles.py:465
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86

## ◆ initialize() [2/2]

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

Initialization.

Definition at line 42 of file RndmGenerators.cpp.

42 {
43 return initialize( SmartIF<IRndmGenSvc>( svc ), par );
44 }
SmartIF< IRndmGenSvc >
compareOutputFiles.par
string par
Definition: compareOutputFiles.py:465
Rndm::Numbers::initialize
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.
Definition: RndmGenerators.cpp:20

## ◆ operator bool()

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

Check if the number supply is possible.

Definition at line 374 of file RndmGenerators.h.

374 { return m_generator; }
Rndm::Numbers::m_generator
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
Definition: RndmGenerators.h:352

## ◆ operator()()

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

Operator () for the use within STL.

Definition at line 376 of file RndmGenerators.h.

376 { return this->shoot(); }
Rndm::Numbers::shoot
double shoot()
Pop a new number from the buffer.
Definition: RndmGenerators.h:380

## ◆ pop()

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

Pop a new number from the buffer.

Definition at line 378 of file RndmGenerators.h.

378 { return this->shoot(); }
Rndm::Numbers::shoot
double shoot()
Pop a new number from the buffer.
Definition: RndmGenerators.h:380

## ◆ shoot()

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

Pop a new number from the buffer.

Definition at line 380 of file RndmGenerators.h.

380 { return m_generator ? m_generator->shoot() : -1; }
Rndm::Numbers::m_generator
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
Definition: RndmGenerators.h:352
IRndmGen::shoot
virtual double shoot() const =0
Single shot returning single random number according to specified distribution.

## ◆ shootArray()

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

Pop a new number from the buffer.

Definition at line 382 of file RndmGenerators.h.

382 {
383 return m_generator ? m_generator->shootArray( array, num, start ) : StatusCode::FAILURE;
384 }
Rndm::Numbers::m_generator
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
Definition: RndmGenerators.h:352
IOTest.start
def start
Definition: IOTest.py:97
IRndmGen::shootArray
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.
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86

## Member Data Documentation

## ◆ m_generator

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

Pointer to random number generator.

Definition at line 352 of file RndmGenerators.h.

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

- GaudiKernel/GaudiKernel/RndmGenerators.h
- GaudiKernel/src/Lib/RndmGenerators.cpp