The Gaudi Framework  master (37c0b60a)
HiveNumbers.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // Framework include files
12 #include "HiveNumbers.h"
14 #include <GaudiKernel/IRndmGen.h>
16 #include <GaudiKernel/SmartIF.h>
17 
18 namespace {
19  constexpr double HIVENUMBERS_BUFFER_SIZE = 1000;
20 }
21 
23 
24 // Standard constructor
25 HiveRndm::HiveNumbers::HiveNumbers() : m_buffer_index( 0 ), m_buffer_size( HIVENUMBERS_BUFFER_SIZE ), m_generator( 0 ) {
27 }
28 
29 // Copy constructor
31  : m_buffer_index( 0 ), m_buffer_size( HIVENUMBERS_BUFFER_SIZE ), m_generator( copy.m_generator ) {
33  if ( 0 != m_generator ) { m_generator->addRef(); }
34 }
35 
36 // Construct and initialize the generator
38  : m_buffer_index( 0 ), m_buffer_size( HIVENUMBERS_BUFFER_SIZE ), m_generator( 0 ) {
40  StatusCode status = initialize( svc, par );
41  if ( !status.isSuccess() ) { throw GaudiException( "Initialization failed !", "HiveRndm::HiveNumbers", status ); }
42 }
43 
44 // Standard destructor
45 HiveRndm::HiveNumbers::~HiveNumbers() { finalize().ignore(); }
46 
47 // Initialize the generator
49  if ( svc.isValid() && 0 == m_generator ) {
52  return svc->generator( par, m_generator );
53  }
54  return StatusCode::FAILURE;
55 }
56 
57 // Initialize the generator
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 # pragma GCC diagnostic push
69 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
70 // Construct and initialize the generator
72  : m_buffer_index( 0 ), m_buffer_size( HIVENUMBERS_BUFFER_SIZE ), m_generator( 0 ) {
73  StatusCode status = initialize( svc, par );
74  if ( !status.isSuccess() ) { throw GaudiException( "Initialization failed !", "HiveRndm::HiveNumbers", status ); }
75 }
76 
77 // Initialize the generator
79  return initialize( SmartIF<IRndmGenSvc>( svc ), par );
80 }
81 # pragma GCC diagnostic pop
82 #endif
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
HiveRndm::HiveNumbers::m_genMutex
static HiveNumbersMutex m_genMutex
Definition: HiveNumbers.h:43
std::vector::reserve
T reserve(T... args)
GaudiException.h
HiveRndm::HiveNumbers::initialize
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.
Definition: HiveNumbers.cpp:48
GaudiException
Definition: GaudiException.h:31
HiveRndm::HiveNumbers::~HiveNumbers
virtual ~HiveNumbers()
Standard destructor.
Definition: HiveNumbers.cpp:45
IRndmGenSvc.h
HiveRndm::HiveNumbersMutex
tbb::spin_rw_mutex HiveNumbersMutex
Definition: HiveNumbers.h:36
HiveNumbers.h
compareOutputFiles.par
par
Definition: compareOutputFiles.py:477
HiveRndm::HiveNumbers::HiveNumbers
HiveNumbers()
Standard constructor.
Definition: HiveNumbers.cpp:25
SmartIF.h
IRndmGen.h
SmartIF::isValid
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:72
HiveRndm::HiveNumbers::m_generator
IRndmGen * m_generator
Pointer to random number generator.
Definition: HiveNumbers.h:47
StatusCode
Definition: StatusCode.h:65
HiveRndm::HiveNumbers::m_buffer
std::vector< double > m_buffer
Definition: HiveNumbers.h:42
IRndmGen::Param
Definition: IRndmGen.h:49
IRndmGenSvc
Definition: IRndmGenSvc.h:45
SmartIF< IRndmGenSvc >
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
HiveRndm::HiveNumbers::m_buffer_size
const unsigned int m_buffer_size
Definition: HiveNumbers.h:41
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
HiveRndm::HiveNumbers
Definition: HiveNumbers.h:38
HiveRndm::HiveNumbers::finalize
virtual StatusCode finalize()
Finalization.
Definition: HiveNumbers.cpp:58
IInterface::addRef
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.