| The Gaudi Framework v28r2p1 (f1a77ff4)

- 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 <vector>
10 #include <memory>
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 typedef tbb::spin_rw_mutex_v3 HiveNumbersMutex;
27
28 class GAUDI_API HiveNumbers {
29 private:
30 unsigned int m_buffer_index;
31 const unsigned int m_buffer_size;
32 std::vector<double> m_buffer;
33 static HiveNumbersMutex m_genMutex;
34 protected:
36 IRndmGen* m_generator;
37 public:
39 HiveNumbers();
41 HiveNumbers(const HiveNumbers& copy );
43 HiveNumbers(const SmartIF<IRndmGenSvc>& svc, const IRndmGen::Param& par);
45 virtual ~HiveNumbers();
47 virtual StatusCode initialize(const SmartIF<IRndmGenSvc>& svc, const IRndmGen::Param& par);
48 #if !defined(GAUDI_V22_API) || defined(G22_NEW_SVCLOCATOR)
49 HiveNumbers(IRndmGenSvc* svc, const IRndmGen::Param& par);
52 virtual StatusCode initialize(IRndmGenSvc* svc, const IRndmGen::Param& par);
53 #endif
54 virtual StatusCode finalize();
57 operator bool () const {
58 return m_generator != 0;
59 }
61 double operator() () {
62 return this->shoot();
63 }
65 double pop() {
66 return this->shoot();
67 }
69 double shoot() {
70 if ( 0 != m_generator ) {
71 if (m_buffer_index==0){// we are out of numbers
72 this->shootArray(m_buffer, m_buffer_size);
73 m_buffer_index=m_buffer_size-1;
74 }
75 const double number=m_buffer[m_buffer_index];
76 m_buffer_index--;
77 return number;
78 }
79 return -1;
80 }
82 StatusCode shootArray(std::vector<double>& array, long num, long start=0) {
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
96 } // end of Rndm namespace
97
98
99 #endif // GAUDIHIVE_HIVENumbers_H
HiveRndm::HiveNumbers::m_buffer_size
const unsigned int m_buffer_size
Definition: HiveNumbers.h:31
SmartIF< IRndmGenSvc >
HiveRndm::HiveNumbersMutex
tbb::spin_rw_mutex_v3 HiveNumbersMutex
Definition: HiveNumbers.h:26
StatusCode::FAILURE
Definition: StatusCode.h:29
IRndmGen
Definition of a interface for a generic random number generators.
Definition: IRndmGen.h:35
IRndmGen.h
HiveRndm::HiveNumbers::m_buffer
std::vector< double > m_buffer
Definition: HiveNumbers.h:32
compareOutputFiles.par
string par
Definition: compareOutputFiles.py:386
HiveRndm::HiveNumbers::m_generator
IRndmGen * m_generator
Pointer to random number generator.
Definition: HiveNumbers.h:36
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:26
IRndmGen::Param
Definition: IRndmGen.h:40
SmartIF.h
HiveRndm::HiveNumbers
Definition: HiveNumbers.h:28
IOTest.start
start
Definition: IOTest.py:88
Containers::array
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
Definition: KeyedObjectManager.h:27
std::vector< double >
Gaudi::Functional::operator()
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
HiveRndm::HiveNumbers::shootArray
StatusCode shootArray(std::vector< double > &array, long num, long start=0)
Pop a new number from the buffer.
Definition: HiveNumbers.h:82
HiveRndm::HiveNumbers::m_buffer_index
unsigned int m_buffer_index
Definition: HiveNumbers.h:30
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:107
HiveRndm::HiveNumbers::m_genMutex
static HiveNumbersMutex m_genMutex
Definition: HiveNumbers.h:33
HiveRndm
Definition: HiveNumbers.h:24
HiveRndm::HiveNumbers::shoot
double shoot()
Pop a new number from the buffer.
Definition: HiveNumbers.h:69