| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

HiveNumbers.h
Go to the documentation of this file.
1 #ifndef GAUDIHIVE_HIVENUMBERS_H
2 #define GAUDIHIVE_HIVENUMBERS_H
3
4 // Framework include files
5 #include "GaudiKernel/IRndmGen.h"
6 #include "GaudiKernel/SmartIF.h"
7
8 // STL includes
9 #include <memory>
10 #include <vector>
11
12 #include "tbb/spin_rw_mutex.h"
13
14 // Forward declarations
15 class IRndmGen;
16 class IRndmGenSvc;
17
18 /*
19 * This is a first solution to the problem of the thread safe random generation.
20 * It is locking, but the locking is "diluted" by a caching mechanism of the
21 * random numbers.
22 */
23
24 namespace HiveRndm
25 {
26
27 typedef tbb::spin_rw_mutex_v3 HiveNumbersMutex;
28
29 class GAUDI_API HiveNumbers
30 {
31 private:
32 unsigned int m_buffer_index;
33 const unsigned int m_buffer_size;
34 std::vector<double> m_buffer;
35 static HiveNumbersMutex m_genMutex;
36
37 protected:
39 IRndmGen* m_generator;
40
41 public:
43 HiveNumbers();
45 HiveNumbers( const HiveNumbers& copy );
47 HiveNumbers( const SmartIF<IRndmGenSvc>& svc, const IRndmGen::Param& par );
49 virtual ~HiveNumbers();
51 virtual StatusCode initialize( const SmartIF<IRndmGenSvc>& svc, const IRndmGen::Param& par );
52 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
53 HiveNumbers( IRndmGenSvc* svc, const IRndmGen::Param& par );
56 virtual StatusCode initialize( IRndmGenSvc* svc, const IRndmGen::Param& par );
57 #endif
58 virtual StatusCode finalize();
61 operator bool() const { return m_generator != 0; }
63 double operator()() { return this->shoot(); }
65 double pop() { return this->shoot(); }
67 double shoot()
68 {
69 if ( 0 != m_generator ) {
70 if ( m_buffer_index == 0 ) { // we are out of numbers
71 this->shootArray( m_buffer, m_buffer_size );
72 m_buffer_index = m_buffer_size - 1;
73 }
74 const double number = m_buffer[m_buffer_index];
75 m_buffer_index--;
76 return number;
77 }
78 return -1;
79 }
81 StatusCode shootArray( std::vector<double>& array, long num, long start = 0 )
82 {
83 if ( 0 != m_generator ) {
84 StatusCode status;
85 {
86 HiveNumbersMutex::scoped_lock lock( m_genMutex );
87 status = m_generator->shootArray( array, num, start );
88 }
89 return status;
90 }
91 return StatusCode::FAILURE;
92 }
93 };
94
95 } // end of Rndm namespace
96
97 #endif // GAUDIHIVE_HIVENumbers_H
HiveRndm::HiveNumbers::m_buffer_size
const unsigned int m_buffer_size
Definition: HiveNumbers.h:33
SmartIF< IRndmGenSvc >
HiveRndm::HiveNumbersMutex
tbb::spin_rw_mutex_v3 HiveNumbersMutex
Definition: HiveNumbers.h:27
StatusCode::FAILURE
Definition: StatusCode.h:31
IRndmGen
Definition of a interface for a generic random number generators.
Definition: IRndmGen.h:34
IRndmGen.h
HiveRndm::HiveNumbers::m_buffer
std::vector< double > m_buffer
Definition: HiveNumbers.h:34
compareOutputFiles.par
string par
Definition: compareOutputFiles.py:437
HiveRndm::HiveNumbers::m_generator
IRndmGen * m_generator
Pointer to random number generator.
Definition: HiveNumbers.h:39
IRndmGenSvc
Random Generator service interface definition Definition of a interface for a service to access rando...
Definition: IRndmGenSvc.h:35
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
IRndmGen::Param
Definition: IRndmGen.h:40
SmartIF.h
HiveRndm::HiveNumbers
Definition: HiveNumbers.h:29
IOTest.start
start
Definition: IOTest.py:99
HiveRndm::HiveNumbers::operator()
double operator()()
Operator () for the use within STL.
Definition: HiveNumbers.h:63
Containers::array
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
Definition: KeyedObjectManager.h:28
std::vector< double >
HiveRndm::HiveNumbers::shootArray
StatusCode shootArray(std::vector< double > &array, long num, long start=0)
Pop a new number from the buffer.
Definition: HiveNumbers.h:81
HiveRndm::HiveNumbers::m_buffer_index
unsigned int m_buffer_index
Definition: HiveNumbers.h:32
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.
HiveRndm::HiveNumbers::pop
double pop()
Pop a new number from the buffer.
Definition: HiveNumbers.h:65
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
HiveRndm::HiveNumbers::m_genMutex
static HiveNumbersMutex m_genMutex
Definition: HiveNumbers.h:35
HiveRndm
Definition: HiveNumbers.h:24
HiveRndm::HiveNumbers::shoot
double shoot()
Pop a new number from the buffer.
Definition: HiveNumbers.h:67