| The Gaudi Framework v29r0 (ff2e7097)

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