| The Gaudi Framework v27r1

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

- File List
- File Members

HiveNumbers.cpp
Go to the documentation of this file.
1 // Framework include files
2 #include "GaudiKernel/SmartIF.h"
3 #include "GaudiKernel/IRndmGen.h"
4 #include "GaudiKernel/IRndmGenSvc.h"
5 #include "GaudiKernel/GaudiException.h"
6 #include "HiveNumbers.h"
7
8 namespace {
9 constexpr double HIVENUMBERS_BUFFER_SIZE=1000;
10 }
11
12 HiveRndm::HiveNumbersMutex HiveRndm::HiveNumbers::m_genMutex;
13
14 // Standard constructor
15 HiveRndm::HiveNumbers::HiveNumbers()
16 : m_buffer_index(0),
17 m_buffer_size(HIVENUMBERS_BUFFER_SIZE),
18 m_generator(0)
19 {
20 m_buffer.reserve(m_buffer_size);
21 }
22
23 // Copy constructor
24 HiveRndm::HiveNumbers::HiveNumbers(const HiveRndm::HiveNumbers& copy )
25 : m_buffer_index(0),
26 m_buffer_size(HIVENUMBERS_BUFFER_SIZE),
27 m_generator(copy.m_generator){
28 m_buffer.reserve(m_buffer_size);
29 if ( 0 != m_generator ) {
30 m_generator->addRef();
31 }
32 }
33
34 // Construct and initialize the generator
35 HiveRndm::HiveNumbers::HiveNumbers(const SmartIF<IRndmGenSvc>& svc, const IRndmGen::Param& par)
36 : m_buffer_index(0),
37 m_buffer_size(HIVENUMBERS_BUFFER_SIZE),
38 m_generator(0)
39 {
40 m_buffer.reserve(m_buffer_size);
41 StatusCode status = initialize(svc, par);
42 if (!status.isSuccess()) {
43 throw GaudiException ("Initialization failed !", "HiveRndm::HiveNumbers", status);
44 }
45 }
46
47 // Standard destructor
48 HiveRndm::HiveNumbers::~HiveNumbers() {
49 finalize().ignore();
50 }
51
52 // Initialize the generator
53 StatusCode HiveRndm::HiveNumbers::initialize(const SmartIF<IRndmGenSvc>& svc,
54 const IRndmGen::Param& par) {
55 if ( svc.isValid() && 0 == m_generator ) {
58 return const_cast<IRndmGenSvc*>(svc.get())->generator( par, m_generator );
59 }
60 return StatusCode::FAILURE;
61 }
62
63 // Initialize the generator
64 StatusCode HiveRndm::HiveNumbers::finalize() {
65 if ( 0 != m_generator ) {
66 m_generator->finalize().ignore();
67 m_generator->release();
68 m_generator = 0;
69 }
70 return StatusCode::SUCCESS;
71 }
72
73 #if !defined(GAUDI_V22_API) || defined(G22_NEW_SVCLOCATOR)
74 // Construct and initialize the generator
75 HiveRndm::HiveNumbers::HiveNumbers(IRndmGenSvc* svc, const IRndmGen::Param& par)
76 : m_buffer_index(0),
77 m_buffer_size(HIVENUMBERS_BUFFER_SIZE),
78 m_generator(0)
79 {
80 StatusCode status = initialize(svc, par);
81 if (!status.isSuccess()) {
82 throw GaudiException ("Initialization failed !", "HiveRndm::HiveNumbers", status);
83 }
84 }
85 #endif
86 // Initialize the generator
87 StatusCode HiveRndm::HiveNumbers::initialize(IRndmGenSvc* svc, const IRndmGen::Param& par) {
88 return initialize(SmartIF<IRndmGenSvc>(svc), par);
89 }
HiveRndm::HiveNumbers::m_buffer_size
const unsigned int m_buffer_size
Definition: HiveNumbers.h:31
SmartIF< IRndmGenSvc >
HiveRndm::HiveNumbers::finalize
virtual StatusCode finalize()
Finalization.
Definition: HiveNumbers.cpp:64
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23
AnalysisTest.initialize
def initialize()
Definition: AnalysisTest.py:12
HiveRndm::HiveNumbersMutex
tbb::spin_rw_mutex_v3 HiveNumbersMutex
Definition: HiveNumbers.h:26
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
IRndmGen.h
HiveRndm::HiveNumbers::m_buffer
std::vector< double > m_buffer
Definition: HiveNumbers.h:32
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
compareOutputFiles.par
string par
Definition: compareOutputFiles.py:386
HiveRndm::HiveNumbers::m_generator
IRndmGen * m_generator
Pointer to random number generator.
Definition: HiveNumbers.h:36
StatusCode::FAILURE
Definition: StatusCode.h:29
IRndmGenSvc
Random Generator service interface definition Definition of a interface for a service to access rando...
Definition: IRndmGenSvc.h:35
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
IRndmGen::Param
Definition: IRndmGen.h:40
GaudiException.h
SmartIF.h
HiveRndm::HiveNumbers
Definition: HiveNumbers.h:28
HiveRndm::HiveNumbers::~HiveNumbers
virtual ~HiveNumbers()
Standard destructor.
Definition: HiveNumbers.cpp:48
IRndmGenSvc.h
SmartIF::isValid
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:62
HiveRndm::HiveNumbers::initialize
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.
Definition: HiveNumbers.cpp:53
IInterface::addRef
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:108
HiveRndm::HiveNumbers::HiveNumbers
HiveNumbers()
Standard constructor.
Definition: HiveNumbers.cpp:15
HiveRndm::HiveNumbers::m_genMutex
static HiveNumbersMutex m_genMutex
Definition: HiveNumbers.h:33
std::vector::reserve
T reserve(T...args)
HiveNumbers.h