Loading [MathJax]/jax/input/TeX/config.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Types | Public Member Functions | Static Public Attributes | Private Types | Private Attributes | List of all members
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. More...
 
 ~RNGWrapper ()
 
void setSeed (const std::string &algName, const EventContext &ctx)
 Set the random seed using a string (e.g. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
 operator CLHEP::HepRandomEngine * () const
 Cast-to-engine pointer operator. More...
 
CLHEP::HepRandomEngine * getEngine (const EventContext &ctx) const
 Retrieve the random engine corresponding to the provided EventContext. More...
 
EventContext::ContextEvt_t evtSeeded () const
 Return the event count at which the current slot was last seeded. More...
 
EventContext::ContextEvt_t evtSeeded (const EventContext &ctx) const
 Return the event count at which the current slot of CTX was last seeded. More...
 

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. More...
 
std::vector< EventContext::ContextEvt_t > m_evtSeeded
 Event counter when the engine was last seeded. More...
 

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.

97  {
98  MC20Seeding=0,
99  MC16Seeding=1,
100  MC21Seeding=2,
102  };

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.

70 {
71  // Construct the random engines; one per event slot.
72  m_engines.reserve(nSlots);
73  for(size_t t = 0; t < nSlots; t++){
74  m_engines.emplace_back(genFact());
75  }
76  m_evtSeeded.resize (nSlots, EventContext::INVALID_CONTEXT_EVT);
77 }

◆ ~RNGWrapper()

ATHRNG::RNGWrapper::~RNGWrapper ( )

Definition at line 79 of file RNGWrapper.cxx.

80 {
81  // Clean up the allocated engines
82  for(auto engPtr : m_engines) {
83  delete engPtr;
84  }
85 }

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.

140  {
141  return m_evtSeeded[Gaudi::Hive::currentContext().slot()];
142  }

◆ 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.

146  {
147  return m_evtSeeded[ctx.slot()];
148  }

◆ 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.

134  {
135  return m_engines[ctx.slot()];
136  }

◆ 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.

129  {
130  return m_engines[Gaudi::Hive::currentContext().slot()];
131  }

◆ 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.

170 {
171  setSeed( algName, ctx.slot(),
172  ctx.eventID().event_number(),
173  ctx.eventID().run_number(),
174  ctx.evt() );
175 }

◆ 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.

165 {
166  setSeedMC21(algName,slot,ev,run,0,evt);
167 }

◆ 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.

131 {
132  m_engines[slot]->setSeed(seed, 0);
133  if (evt == EventContext::INVALID_CONTEXT_EVT) {
134  evt = Gaudi::Hive::currentContext().evt();
135  }
136  m_evtSeeded[slot] = evt;
137 }

◆ 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.

179 {
180  setSeedLegacy( algName, ctx.slot(),
181  ctx.eventID().event_number(),
182  ctx.eventID().run_number(),
183  offset, seeding, evt);
184 }

◆ 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.

107 {
108  if(seeding==MC16Seeding) {
109  // Use MC16 legacy seeding
110  setSeedMC16(algName, slot, ev, run, offset, evt);
111  return;
112  }
113  if(seeding==MC20Seeding) {
114  // Use MC20 seeding
115  setSeedMC20(algName, slot, ev, run, evt);
116  return;
117  }
118  // Use MC21 seeding
119  setSeedMC21(algName, slot, ev, run, offset, evt);
120 }

◆ 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.

124 {
126  setSeed(slot, theHash, evt);
127 }

◆ 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.

90 {
91  auto hsh = calculateSeedMC20(algName, ev, run);
92  setSeed(slot, hsh, evt);
93 }

◆ 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.

98 {
99  long seeds[7]; //CLHEP uses long for seeding
101  setSeeds(slot, seeds, evt);
102 }

◆ 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.

141 {
142  m_engines[slot]->setSeeds(seeds, 0);
143  if (evt == EventContext::INVALID_CONTEXT_EVT) {
144  evt = Gaudi::Hive::currentContext().evt();
145  }
146  m_evtSeeded[slot] = evt;
147 }

Member Data Documentation

◆ all_SeedingOptions

constexpr 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:
ATHRNG::RNGWrapper::setSeed
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition: RNGWrapper.h:169
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
ATHRNG::RNGWrapper::setSeedLegacy
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.
Definition: RNGWrapper.cxx:104
xAOD::JetAlgorithmType::algName
const std::string & algName(ID id)
Converts a JetAlgorithmType::ID into a string.
Definition: JetContainerInfo.cxx:67
ATHRNG::RNGWrapper::setSeedMC21
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.
Definition: RNGWrapper.cxx:95
ATHRNG::RNGWrapper::SeedingDefault
@ SeedingDefault
Definition: RNGWrapper.h:101
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
ATHRNG::RNGWrapper::MC20Seeding
@ MC20Seeding
Definition: RNGWrapper.h:98
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATHRNG::RNGWrapper::setSeeds
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.
Definition: RNGWrapper.cxx:139
ev
int ev
Definition: globals.cxx:25
ATHRNG::RNGWrapper::m_engines
std::vector< CLHEP::HepRandomEngine * > m_engines
Vector of random engines, ordered by slot number.
Definition: RNGWrapper.h:153
ATHRNG::calculateSeedMC16
size_t calculateSeedMC16(const std::string &algName, uint64_t ev, uint64_t run, uint32_t offset=0)
Helper methods.
Definition: RNGWrapper.cxx:15
run
Definition: run.py:1
ATHRNG::RNGWrapper::MC21Seeding
@ MC21Seeding
Definition: RNGWrapper.h:100
ATHRNG::RNGWrapper::setSeedMC20
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.
Definition: RNGWrapper.cxx:87
ATHRNG::calculateSeedMC20
size_t calculateSeedMC20(const std::string &algName, uint64_t ev, uint64_t run)
Set the random seed using a string (e.g.
Definition: RNGWrapper.cxx:26
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
ATHRNG::RNGWrapper::m_evtSeeded
std::vector< EventContext::ContextEvt_t > m_evtSeeded
Event counter when the engine was last seeded.
Definition: RNGWrapper.h:156
ATHRNG::calculateSeedsMC21
void calculateSeedsMC21(long *seeds, const std::string &algName, uint64_t ev, uint64_t run, uint64_t offset=0)
Set the random seed using a string (e.g.
Definition: RNGWrapper.cxx:37
ATHRNG::RNGWrapper::setSeedMC16
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.
Definition: RNGWrapper.cxx:122
ATHRNG::RNGWrapper::MC16Seeding
@ MC16Seeding
Definition: RNGWrapper.h:99