The Gaudi Framework  master (37c0b60a)
HiveRndm::HiveNumbers Class Reference

#include </builds/gaudi/Gaudi/GaudiHive/src/HiveNumbers.h>

Collaboration diagram for HiveRndm::HiveNumbers:

Public Member Functions

 HiveNumbers ()
 Standard constructor. More...
 
 HiveNumbers (const HiveNumbers &copy)
 Copy constructor. More...
 
 HiveNumbers (const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
 Initializing constructor. More...
 
virtual ~HiveNumbers ()
 Standard destructor. More...
 
virtual StatusCode initialize (const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
 Initialization. More...
 
 HiveNumbers (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

IRndmGenm_generator
 Pointer to random number generator. More...
 

Private Attributes

unsigned int m_buffer_index
 
const unsigned int m_buffer_size
 
std::vector< double > m_buffer
 

Static Private Attributes

static HiveNumbersMutex m_genMutex
 

Detailed Description

Definition at line 38 of file HiveNumbers.h.

Constructor & Destructor Documentation

◆ HiveNumbers() [1/4]

HiveRndm::HiveNumbers::HiveNumbers ( )

Standard constructor.

Definition at line 25 of file HiveNumbers.cpp.

25  : m_buffer_index( 0 ), m_buffer_size( HIVENUMBERS_BUFFER_SIZE ), m_generator( 0 ) {
27 }

◆ HiveNumbers() [2/4]

HiveRndm::HiveNumbers::HiveNumbers ( const HiveNumbers copy)

Copy constructor.

Definition at line 30 of file HiveNumbers.cpp.

31  : m_buffer_index( 0 ), m_buffer_size( HIVENUMBERS_BUFFER_SIZE ), m_generator( copy.m_generator ) {
33  if ( 0 != m_generator ) { m_generator->addRef(); }
34 }

◆ HiveNumbers() [3/4]

HiveRndm::HiveNumbers::HiveNumbers ( const SmartIF< IRndmGenSvc > &  svc,
const IRndmGen::Param par 
)

Initializing constructor.

Definition at line 37 of file HiveNumbers.cpp.

38  : m_buffer_index( 0 ), m_buffer_size( HIVENUMBERS_BUFFER_SIZE ), m_generator( 0 ) {
40  StatusCode status = initialize( svc, par );
41  if ( !status.isSuccess() ) { throw GaudiException( "Initialization failed !", "HiveRndm::HiveNumbers", status ); }
42 }

◆ ~HiveNumbers()

HiveRndm::HiveNumbers::~HiveNumbers ( )
virtual

Standard destructor.

Definition at line 45 of file HiveNumbers.cpp.

45 { finalize().ignore(); }

◆ HiveNumbers() [4/4]

HiveRndm::HiveNumbers::HiveNumbers ( IRndmGenSvc svc,
const IRndmGen::Param par 
)

Initializing constructor.

Definition at line 71 of file HiveNumbers.cpp.

72  : m_buffer_index( 0 ), m_buffer_size( HIVENUMBERS_BUFFER_SIZE ), m_generator( 0 ) {
73  StatusCode status = initialize( svc, par );
74  if ( !status.isSuccess() ) { throw GaudiException( "Initialization failed !", "HiveRndm::HiveNumbers", status ); }
75 }

Member Function Documentation

◆ finalize()

StatusCode HiveRndm::HiveNumbers::finalize ( )
virtual

Finalization.

Definition at line 58 of file HiveNumbers.cpp.

58  {
59  if ( 0 != m_generator ) {
62  m_generator = 0;
63  }
64  return StatusCode::SUCCESS;
65 }

◆ initialize() [1/2]

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

Initialization.

Fix-Me:
: this is a hack, but I do not have the time to review the correct constantness of all the methods

Definition at line 48 of file HiveNumbers.cpp.

48  {
49  if ( svc.isValid() && 0 == m_generator ) {
52  return svc->generator( par, m_generator );
53  }
54  return StatusCode::FAILURE;
55 }

◆ initialize() [2/2]

StatusCode HiveRndm::HiveNumbers::initialize ( IRndmGenSvc svc,
const IRndmGen::Param par 
)
virtual

Initialization.

Definition at line 78 of file HiveNumbers.cpp.

78  {
79  return initialize( SmartIF<IRndmGenSvc>( svc ), par );
80 }

◆ operator bool()

HiveRndm::HiveNumbers::operator bool ( ) const
inline

Check if the number supply is possible.

Definition at line 69 of file HiveNumbers.h.

69 { return m_generator != 0; }

◆ operator()()

double HiveRndm::HiveNumbers::operator() ( )
inline

Operator () for the use within STL.

Definition at line 71 of file HiveNumbers.h.

71 { return this->shoot(); }

◆ pop()

double HiveRndm::HiveNumbers::pop ( )
inline

Pop a new number from the buffer.

Definition at line 73 of file HiveNumbers.h.

73 { return this->shoot(); }

◆ shoot()

double HiveRndm::HiveNumbers::shoot ( )
inline

Pop a new number from the buffer.

Definition at line 75 of file HiveNumbers.h.

75  {
76  if ( 0 != m_generator ) {
77  if ( m_buffer_index == 0 ) { // we are out of numbers
78  this->shootArray( m_buffer, m_buffer_size ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
80  }
81  const double number = m_buffer[m_buffer_index];
83  return number;
84  }
85  return -1;
86  }

◆ shootArray()

StatusCode HiveRndm::HiveNumbers::shootArray ( std::vector< double > &  array,
long  num,
long  start = 0 
)
inline

Pop a new number from the buffer.

Definition at line 88 of file HiveNumbers.h.

88  {
89  if ( 0 != m_generator ) {
90  StatusCode status;
91  {
92  HiveNumbersMutex::scoped_lock lock( m_genMutex );
93  status = m_generator->shootArray( array, num, start );
94  }
95  return status;
96  }
97  return StatusCode::FAILURE;
98  }

Member Data Documentation

◆ m_buffer

std::vector<double> HiveRndm::HiveNumbers::m_buffer
private

Definition at line 42 of file HiveNumbers.h.

◆ m_buffer_index

unsigned int HiveRndm::HiveNumbers::m_buffer_index
private

Definition at line 40 of file HiveNumbers.h.

◆ m_buffer_size

const unsigned int HiveRndm::HiveNumbers::m_buffer_size
private

Definition at line 41 of file HiveNumbers.h.

◆ m_generator

IRndmGen* HiveRndm::HiveNumbers::m_generator
protected

Pointer to random number generator.

Definition at line 47 of file HiveNumbers.h.

◆ m_genMutex

HiveRndm::HiveNumbersMutex HiveRndm::HiveNumbers::m_genMutex
staticprivate

Definition at line 43 of file HiveNumbers.h.


The documentation for this class was generated from the following files:
std::lock
T lock(T... args)
IRndmGen::finalize
virtual StatusCode finalize()=0
Finalize the generator.
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
HiveRndm::HiveNumbers::m_genMutex
static HiveNumbersMutex m_genMutex
Definition: HiveNumbers.h:43
std::vector::reserve
T reserve(T... args)
HiveRndm::HiveNumbers::initialize
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.
Definition: HiveNumbers.cpp:48
GaudiException
Definition: GaudiException.h:31
IOTest.start
start
Definition: IOTest.py:110
compareOutputFiles.par
par
Definition: compareOutputFiles.py:477
SmartIF::isValid
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:72
HiveRndm::HiveNumbers::m_buffer_index
unsigned int m_buffer_index
Definition: HiveNumbers.h:40
HiveRndm::HiveNumbers::m_generator
IRndmGen * m_generator
Pointer to random number generator.
Definition: HiveNumbers.h:47
StatusCode
Definition: StatusCode.h:65
HiveRndm::HiveNumbers::shootArray
StatusCode shootArray(std::vector< double > &array, long num, long start=0)
Pop a new number from the buffer.
Definition: HiveNumbers.h:88
HiveRndm::HiveNumbers::m_buffer
std::vector< double > m_buffer
Definition: HiveNumbers.h:42
std::copy
T copy(T... args)
SmartIF< IRndmGenSvc >
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
HiveRndm::HiveNumbers::m_buffer_size
const unsigned int m_buffer_size
Definition: HiveNumbers.h:41
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::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
Containers::array
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
Definition: KeyedObjectManager.h:37
HiveRndm::HiveNumbers::shoot
double shoot()
Pop a new number from the buffer.
Definition: HiveNumbers.h:75
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
IInterface::release
virtual unsigned long release()=0
Release Interface instance.
HiveRndm::HiveNumbers::finalize
virtual StatusCode finalize()
Finalization.
Definition: HiveNumbers.cpp:58
IInterface::addRef
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.