ATLAS Offline Software
Loading...
Searching...
No Matches
ATHRNG::RNGWrapper Class Reference

A wrapper class for event-slot-local random engines. More...

#include <RNGWrapper.h>

Collaboration diagram for ATHRNG::RNGWrapper:

Public Types

enum  SeedingOptionType { MC20Seeding =0 , MC16Seeding =1 , MC21Seeding =2 , SeedingDefault =MC21Seeding }
 Options for seeding option=0 is setSeed as in MC20 option=1 is setSeedLegacy as in MC16 option=2 is setSeedImproved. More...

Public Member Functions

 RNGWrapper (const factoryFunc &genFact, size_t nSlots)
 Constructor takes a factory function which can instantiate a CLHEP::HepRandomEngine and the number of event slots.
 ~RNGWrapper ()
void setSeed (const std::string &algName, const EventContext &ctx)
 Set the random seed using a string (e.g.
void setSeed (const std::string &algName, size_t slot, uint64_t ev, uint64_t run, EventContext::ContextEvt_t evt=EventContext::INVALID_CONTEXT_EVT)
 Set the random seed using a string (e.g.
void setSeedMC16 (const std::string &algName, size_t slot, uint64_t ev, uint64_t run, uint32_t offset=0, EventContext::ContextEvt_t evt=EventContext::INVALID_CONTEXT_EVT)
 Set the random seed using a string (e.g.
void setSeedMC20 (const std::string &algName, size_t slot, uint64_t ev, uint64_t run, EventContext::ContextEvt_t evt=EventContext::INVALID_CONTEXT_EVT)
 Set the random seed using a string (e.g.
void setSeedMC21 (const std::string &algName, size_t slot, uint64_t ev, uint64_t run, uint64_t offset=0, EventContext::ContextEvt_t evt=EventContext::INVALID_CONTEXT_EVT)
 Set the random seed using a string (e.g.
void setSeedLegacy (const std::string &algName, size_t slot, uint64_t ev, uint64_t run, uint64_t offset, SeedingOptionType seeding, EventContext::ContextEvt_t evt=EventContext::INVALID_CONTEXT_EVT)
 Set the random seed using a string (e.g.
void setSeedLegacy (const std::string &algName, const EventContext &ctx, uint32_t offset, SeedingOptionType seeding, EventContext::ContextEvt_t evt=EventContext::INVALID_CONTEXT_EVT)
 Set the random seed using a string (e.g.
void setSeed (size_t slot, size_t seed, EventContext::ContextEvt_t evt=EventContext::INVALID_CONTEXT_EVT)
 Set the seed value directly for a specified slot.
void setSeeds (size_t slot, const long *seeds, EventContext::ContextEvt_t evt=EventContext::INVALID_CONTEXT_EVT)
 Set the seed value(s) directly for a specified slot.
 operator CLHEP::HepRandomEngine * () const
 Cast-to-engine pointer operator.
CLHEP::HepRandomEngine * getEngine (const EventContext &ctx) const
 Retrieve the random engine corresponding to the provided EventContext.
EventContext::ContextEvt_t evtSeeded () const
 Return the event count at which the current slot was last seeded.
EventContext::ContextEvt_t evtSeeded (const EventContext &ctx) const
 Return the event count at which the current slot of CTX was last seeded.

Static Public Attributes

static constexpr std::initializer_list< SeedingOptionTypeall_SeedingOptions = {MC20Seeding, MC16Seeding, MC21Seeding}

Private Types

typedef std::function< CLHEP::HepRandomEngine *(void)> factoryFunc

Private Attributes

std::vector< CLHEP::HepRandomEngine * > m_engines
 Vector of random engines, ordered by slot number.
std::vector< EventContext::ContextEvt_t > m_evtSeeded
 Event counter when the engine was last seeded.

Detailed Description

A wrapper class for event-slot-local random engines.

Implemented primarily for use in services implementing IAthRNGSvc for thread-safe random number generation in AthenaMT.

The slot-local HepRandomEngine is retrieved via the dereference operator or the getEngine method.

This class also provides a seed setting and generating mechanism. The seed is calculated from an algorithm name and the slot, event, and run numbers.

Author
Sami Kama sami..nosp@m.kama.nosp@m.@cern.nosp@m..ch
Steve Farrell Steve.nosp@m.n.Fa.nosp@m.rrell.nosp@m.@cer.nosp@m.n.ch

Definition at line 55 of file RNGWrapper.h.

Member Typedef Documentation

◆ factoryFunc

typedef std::function<CLHEP::HepRandomEngine*(void)> ATHRNG::RNGWrapper::factoryFunc
private

Definition at line 58 of file RNGWrapper.h.

Member Enumeration Documentation

◆ SeedingOptionType

Options for seeding option=0 is setSeed as in MC20 option=1 is setSeedLegacy as in MC16 option=2 is setSeedImproved.

Enumerator
MC20Seeding 
MC16Seeding 
MC21Seeding 
SeedingDefault 

Definition at line 97 of file RNGWrapper.h.

Constructor & Destructor Documentation

◆ RNGWrapper()

ATHRNG::RNGWrapper::RNGWrapper ( const factoryFunc & genFact,
size_t nSlots )

Constructor takes a factory function which can instantiate a CLHEP::HepRandomEngine and the number of event slots.

Definition at line 69 of file RNGWrapper.cxx.

◆ ~RNGWrapper()

ATHRNG::RNGWrapper::~RNGWrapper ( )

Definition at line 79 of file RNGWrapper.cxx.

Member Function Documentation

◆ evtSeeded() [1/2]

EventContext::ContextEvt_t ATHRNG::RNGWrapper::evtSeeded ( ) const
inline

Return the event count at which the current slot was last seeded.

Definition at line 139 of file RNGWrapper.h.

◆ evtSeeded() [2/2]

EventContext::ContextEvt_t ATHRNG::RNGWrapper::evtSeeded ( const EventContext & ctx) const
inline

Return the event count at which the current slot of CTX was last seeded.

Definition at line 145 of file RNGWrapper.h.

◆ getEngine()

CLHEP::HepRandomEngine * ATHRNG::RNGWrapper::getEngine ( const EventContext & ctx) const
inline

Retrieve the random engine corresponding to the provided EventContext.

Definition at line 134 of file RNGWrapper.h.

◆ operator CLHEP::HepRandomEngine *()

ATHRNG::RNGWrapper::operator CLHEP::HepRandomEngine * ( ) const
inline

Cast-to-engine pointer operator.

Retrieves the current event context and returns the engine corresponding to the current event slot.

Definition at line 129 of file RNGWrapper.h.

◆ setSeed() [1/3]

void ATHRNG::RNGWrapper::setSeed ( const std::string & algName,
const EventContext & ctx )
inline

Set the random seed using a string (e.g.

algorithm name) and the current EventContext. Does nothing if the context is invalid.

Definition at line 169 of file RNGWrapper.h.

◆ setSeed() [2/3]

void ATHRNG::RNGWrapper::setSeed ( const std::string & algName,
size_t slot,
uint64_t ev,
uint64_t run,
EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT )
inline

Set the random seed using a string (e.g.

algorithm name) and the current slot, event, and run numbers.

Definition at line 163 of file RNGWrapper.h.

◆ setSeed() [3/3]

void ATHRNG::RNGWrapper::setSeed ( size_t slot,
size_t seed,
EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT )

Set the seed value directly for a specified slot.

Definition at line 129 of file RNGWrapper.cxx.

◆ setSeedLegacy() [1/2]

void ATHRNG::RNGWrapper::setSeedLegacy ( const std::string & algName,
const EventContext & ctx,
uint32_t offset,
SeedingOptionType seeding,
EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT )
inline

Set the random seed using a string (e.g.

algorithm name) and the current EventContext and an optional offset. Does nothing if the context is invalid. - Version allowing to switch the seeding options

Definition at line 177 of file RNGWrapper.h.

◆ setSeedLegacy() [2/2]

void ATHRNG::RNGWrapper::setSeedLegacy ( const std::string & algName,
size_t slot,
uint64_t ev,
uint64_t run,
uint64_t offset,
SeedingOptionType seeding,
EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT )

Set the random seed using a string (e.g.

algorithm name) and the current slot, event, and run numbers and an optional offset. - Version allowing to switch the seeding options

Definition at line 104 of file RNGWrapper.cxx.

◆ setSeedMC16()

void ATHRNG::RNGWrapper::setSeedMC16 ( const std::string & algName,
size_t slot,
uint64_t ev,
uint64_t run,
uint32_t offset = 0,
EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT )

Set the random seed using a string (e.g.

algorithm name) and the current slot, event, and run numbers and an optional offset. - MC16 Legacy Version attempting to reproduce seeds from thread-unsafe random number services

Definition at line 122 of file RNGWrapper.cxx.

◆ setSeedMC20()

void ATHRNG::RNGWrapper::setSeedMC20 ( const std::string & algName,
size_t slot,
uint64_t ev,
uint64_t run,
EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT )

Set the random seed using a string (e.g.

algorithm name) and the current slot, event, and run numbers. MC20 seeding algorithm

Definition at line 87 of file RNGWrapper.cxx.

◆ setSeedMC21()

void ATHRNG::RNGWrapper::setSeedMC21 ( const std::string & algName,
size_t slot,
uint64_t ev,
uint64_t run,
uint64_t offset = 0,
EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT )

Set the random seed using a string (e.g.

algorithm name) and the current slot, event, and run numbers. MC21 seeding algorithm

Definition at line 95 of file RNGWrapper.cxx.

◆ setSeeds()

void ATHRNG::RNGWrapper::setSeeds ( size_t slot,
const long * seeds,
EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT )

Set the seed value(s) directly for a specified slot.

Definition at line 139 of file RNGWrapper.cxx.

Member Data Documentation

◆ all_SeedingOptions

std::initializer_list<SeedingOptionType> ATHRNG::RNGWrapper::all_SeedingOptions = {MC20Seeding, MC16Seeding, MC21Seeding}
staticconstexpr

Definition at line 103 of file RNGWrapper.h.

◆ m_engines

std::vector<CLHEP::HepRandomEngine*> ATHRNG::RNGWrapper::m_engines
private

Vector of random engines, ordered by slot number.

Definition at line 153 of file RNGWrapper.h.

◆ m_evtSeeded

std::vector<EventContext::ContextEvt_t> ATHRNG::RNGWrapper::m_evtSeeded
private

Event counter when the engine was last seeded.

Definition at line 156 of file RNGWrapper.h.


The documentation for this class was generated from the following files: