ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
RootUtils::TRandomTLS< T > Class Template Reference

Thread-local TRandom generator. More...

#include <TRandomTLS.h>

Collaboration diagram for RootUtils::TRandomTLS< T >:

Public Member Functions

 TRandomTLS (UInt_t seed=4357)
 Constructor. More...
 
 ~TRandomTLS ()=default
 Destructor. More...
 
T * get () const
 Get thread-specific TRandom. More...
 
T * operator-> () const
 
T & operator* () const
 

Private Attributes

boost::thread_specific_ptr< T > m_rand_tls
 Thread-local TRandom. More...
 
std::atomic< UInt_t > m_seed
 TRandom seed (incremented for each new instance/thread) More...
 

Detailed Description

template<class T>
class RootUtils::TRandomTLS< T >

Thread-local TRandom generator.

This class provides a thread-local TRandom instance of type T. For each new instance/thread the seed is incremented to ensure independent random numbers.

Definition at line 29 of file TRandomTLS.h.

Constructor & Destructor Documentation

◆ TRandomTLS()

template<class T >
RootUtils::TRandomTLS< T >::TRandomTLS ( UInt_t  seed = 4357)
inline

Constructor.

Parameters
seedThe seed of the first TRandom instance. Additional instances are created with the seed incremented by one. If the seed is 0, it will not be incremented as ROOT then uses a time-based seed.

Definition at line 38 of file TRandomTLS.h.

38 : m_seed(seed) {}

◆ ~TRandomTLS()

template<class T >
RootUtils::TRandomTLS< T >::~TRandomTLS ( )
default

Destructor.

Member Function Documentation

◆ get()

template<class T >
T * RootUtils::TRandomTLS< T >::get
inline

Get thread-specific TRandom.

Definition at line 62 of file TRandomTLS.h.

63  {
64  T* random = m_rand_tls.get();
65  if (!random) {
66  random = new T(m_seed > 0 ? m_seed++ : 0);
67  m_rand_tls.reset(random);
68  }
69  return random;
70  }

◆ operator*()

template<class T >
T& RootUtils::TRandomTLS< T >::operator* ( ) const
inline

Definition at line 46 of file TRandomTLS.h.

46 { return *get(); }

◆ operator->()

template<class T >
T* RootUtils::TRandomTLS< T >::operator-> ( ) const
inline

Definition at line 45 of file TRandomTLS.h.

45 { return get(); }

Member Data Documentation

◆ m_rand_tls

template<class T >
boost::thread_specific_ptr<T> RootUtils::TRandomTLS< T >::m_rand_tls
mutableprivate

Thread-local TRandom.

Definition at line 50 of file TRandomTLS.h.

◆ m_seed

template<class T >
std::atomic<UInt_t> RootUtils::TRandomTLS< T >::m_seed
mutableprivate

TRandom seed (incremented for each new instance/thread)

Definition at line 53 of file TRandomTLS.h.


The documentation for this class was generated from the following file:
RootUtils::TRandomTLS::m_rand_tls
boost::thread_specific_ptr< T > m_rand_tls
Thread-local TRandom.
Definition: TRandomTLS.h:50
RootUtils::TRandomTLS::get
T * get() const
Get thread-specific TRandom.
Definition: TRandomTLS.h:62
RootUtils::TRandomTLS::m_seed
std::atomic< UInt_t > m_seed
TRandom seed (incremented for each new instance/thread)
Definition: TRandomTLS.h:53
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35