| The Gaudi Framework v32r1 (f65d50dc)

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 constexpr double HIVENUMBERS_BUFFER_SIZE = 1000;
10 }
11
12 HiveRndm::HiveNumbersMutex HiveRndm::HiveNumbers::m_genMutex;
13
14 // Standard constructor
15 HiveRndm::HiveNumbers::HiveNumbers() : m_buffer_index( 0 ), m_buffer_size( HIVENUMBERS_BUFFER_SIZE ), m_generator( 0 ) {
16 m_buffer.reserve( m_buffer_size );
17 }
18
19 // Copy constructor
20 HiveRndm::HiveNumbers::HiveNumbers( const HiveRndm::HiveNumbers& copy )
21 : m_buffer_index( 0 ), m_buffer_size( HIVENUMBERS_BUFFER_SIZE ), m_generator( copy.m_generator ) {
22 m_buffer.reserve( m_buffer_size );
23 if ( 0 != m_generator ) { m_generator->addRef(); }
24 }
25
26 // Construct and initialize the generator
27 HiveRndm::HiveNumbers::HiveNumbers( const SmartIF<IRndmGenSvc>& svc, const IRndmGen::Param& par )
28 : m_buffer_index( 0 ), m_buffer_size( HIVENUMBERS_BUFFER_SIZE ), m_generator( 0 ) {
29 m_buffer.reserve( m_buffer_size );
30 StatusCode status = initialize( svc, par );
31 if ( !status.isSuccess() ) { throw GaudiException( "Initialization failed !", "HiveRndm::HiveNumbers", status ); }
32 }
33
34 // Standard destructor
35 HiveRndm::HiveNumbers::~HiveNumbers() { finalize().ignore(); }
36
37 // Initialize the generator
38 StatusCode HiveRndm::HiveNumbers::initialize( const SmartIF<IRndmGenSvc>& svc, const IRndmGen::Param& par ) {
39 if ( svc.isValid() && 0 == m_generator ) {
42 return svc->generator( par, m_generator );
43 }
44 return StatusCode::FAILURE;
45 }
46
47 // Initialize the generator
48 StatusCode HiveRndm::HiveNumbers::finalize() {
49 if ( 0 != m_generator ) {
50 m_generator->finalize().ignore();
51 m_generator->release();
52 m_generator = 0;
53 }
54 return StatusCode::SUCCESS;
55 }
56
57 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
58 // Construct and initialize the generator
59 HiveRndm::HiveNumbers::HiveNumbers( IRndmGenSvc* svc, const IRndmGen::Param& par )
60 : m_buffer_index( 0 ), m_buffer_size( HIVENUMBERS_BUFFER_SIZE ), m_generator( 0 ) {
61 StatusCode status = initialize( svc, par );
62 if ( !status.isSuccess() ) { throw GaudiException( "Initialization failed !", "HiveRndm::HiveNumbers", status ); }
63 }
64 #endif
65 // Initialize the generator
66 StatusCode HiveRndm::HiveNumbers::initialize( IRndmGenSvc* svc, const IRndmGen::Param& par ) {
67 return initialize( SmartIF<IRndmGenSvc>( svc ), par );
68 }
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:48
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
HiveRndm::HiveNumbersMutex
tbb::spin_rw_mutex_v3 HiveNumbersMutex
Definition: HiveNumbers.h:26
IRndmGenSvc::generator
virtual StatusCode generator(const IRndmGen::Param &par, IRndmGen *&refpGen)=0
Add a Generator factory.
SmartIF::isValid
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:62
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
IRndmGen.h
HiveRndm::HiveNumbers::m_buffer
std::vector< double > m_buffer
Definition: HiveNumbers.h:32
compareOutputFiles.par
string par
Definition: compareOutputFiles.py:465
HiveRndm::HiveNumbers::m_generator
IRndmGen * m_generator
Pointer to random number generator.
Definition: HiveNumbers.h:37
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:50
IRndmGen::Param
Definition: IRndmGen.h:39
GaudiException.h
SmartIF.h
HiveRndm::HiveNumbers
Definition: HiveNumbers.h:28
HiveRndm::HiveNumbers::~HiveNumbers
virtual ~HiveNumbers()
Standard destructor.
Definition: HiveNumbers.cpp:35
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
StatusCode::ignore
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
IRndmGenSvc.h
HiveRndm::HiveNumbers::initialize
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.
Definition: HiveNumbers.cpp:38
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
IInterface::addRef
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
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