ATLAS Offline Software
Loading...
Searching...
No Matches
RNGWrapper.h
Go to the documentation of this file.
1// -*- c++ -*-
2/*
3 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
4*/
5#ifndef ATHENAKERNEL_RNGWRAPPER_H
6#define ATHENAKERNEL_RNGWRAPPER_H
7
8#include <string>
9#include <cstdint>
10#include <vector>
11#include <functional>
12
13#include "GaudiKernel/EventContext.h"
14#include "GaudiKernel/ThreadLocalContext.h"
15
16namespace CLHEP{
17 class HepRandomEngine;
18}
19
20namespace ATHRNG{
21
23
28 size_t calculateSeedMC16(const std::string& algName, uint64_t ev, uint64_t run, uint32_t offset=0);
29
32 size_t calculateSeedMC20(const std::string& algName, uint64_t ev, uint64_t run);
33
36 void calculateSeedsMC21(long* seeds, const std::string& algName, uint64_t ev, uint64_t run, uint64_t offset=0);
37
38 long calculateSeedsPython(const std::string& algName, uint64_t ev, uint64_t run, uint64_t offset=0);
56 {
57
58 typedef std::function<CLHEP::HepRandomEngine*(void)> factoryFunc;
59
60 public:
61
64 RNGWrapper(const factoryFunc& genFact, size_t nSlots);
66
69 inline void setSeed(const std::string& algName, const EventContext& ctx);
70
73 inline void setSeed(const std::string& algName, size_t slot, uint64_t ev, uint64_t run,
74 EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT);
75
80 void setSeedMC16(const std::string& algName, size_t slot, uint64_t ev, uint64_t run, uint32_t offset=0,
81 EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT);
82
85 void setSeedMC20(const std::string& algName, size_t slot, uint64_t ev, uint64_t run,
86 EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT);
87
90 void setSeedMC21(const std::string& algName, size_t slot, uint64_t ev, uint64_t run, uint64_t offset=0,
91 EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT);
92
103 static constexpr std::initializer_list<SeedingOptionType> all_SeedingOptions = {MC20Seeding, MC16Seeding, MC21Seeding};
104
108 void setSeedLegacy(const std::string& algName, size_t slot, uint64_t ev, uint64_t run, uint64_t offset, SeedingOptionType seeding,
109 EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT);
110
115 inline void setSeedLegacy(const std::string& algName, const EventContext& ctx, uint32_t offset, SeedingOptionType seeding,
116 EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT);
117
119 void setSeed(size_t slot, size_t seed,
120 EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT);
121
123 void setSeeds(size_t slot, const long * seeds,
124 EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT);
125
129 operator CLHEP::HepRandomEngine*() const {
130 return m_engines[Gaudi::Hive::currentContext().slot()];
131 }
132
134 CLHEP::HepRandomEngine* getEngine(const EventContext &ctx) const {
135 return m_engines[ctx.slot()];
136 }
137
139 EventContext::ContextEvt_t evtSeeded() const
140 {
141 return m_evtSeeded[Gaudi::Hive::currentContext().slot()];
142 }
143
145 EventContext::ContextEvt_t evtSeeded(const EventContext &ctx) const
146 {
147 return m_evtSeeded[ctx.slot()];
148 }
149
150 private:
151
153 std::vector<CLHEP::HepRandomEngine*> m_engines;
154
156 std::vector<EventContext::ContextEvt_t> m_evtSeeded;
157
158 };
159
160}
161
162//Default to MC21 seeding for now
163inline void ATHRNG::RNGWrapper::setSeed(const std::string& algName, size_t slot, uint64_t ev, uint64_t run,
164 EventContext::ContextEvt_t evt /*= EventContext::INVALID_CONTEXT_EVT*/)
165{
166 setSeedMC21(algName,slot,ev,run,0,evt);
167}
168
169inline void ATHRNG::RNGWrapper::setSeed(const std::string& algName, const EventContext& ctx)
170{
171 setSeed( algName, ctx.slot(),
172 ctx.eventID().event_number(),
173 ctx.eventID().run_number(),
174 ctx.evt() );
175}
176
177inline void ATHRNG::RNGWrapper::setSeedLegacy(const std::string& algName, const EventContext& ctx, uint32_t offset, SeedingOptionType seeding,
178 EventContext::ContextEvt_t evt /*= EventContext::INVALID_CONTEXT_EVT*/)
179{
180 setSeedLegacy( algName, ctx.slot(),
181 ctx.eventID().event_number(),
182 ctx.eventID().run_number(),
183 offset, seeding, evt);
184}
185
186
187
188#endif
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition RNGWrapper.h:169
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.
std::function< CLHEP::HepRandomEngine *(void)> factoryFunc
Definition RNGWrapper.h:58
RNGWrapper(const factoryFunc &genFact, size_t nSlots)
Constructor takes a factory function which can instantiate a CLHEP::HepRandomEngine and the number of...
EventContext::ContextEvt_t evtSeeded() const
Return the event count at which the current slot was last seeded.
Definition RNGWrapper.h:139
std::vector< EventContext::ContextEvt_t > m_evtSeeded
Event counter when the engine was last seeded.
Definition RNGWrapper.h:156
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.
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.
std::vector< CLHEP::HepRandomEngine * > m_engines
Vector of random engines, ordered by slot number.
Definition RNGWrapper.h:153
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.
SeedingOptionType
Options for seeding option=0 is setSeed as in MC20 option=1 is setSeedLegacy as in MC16 option=2 is s...
Definition RNGWrapper.h:97
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.
static constexpr std::initializer_list< SeedingOptionType > all_SeedingOptions
Definition RNGWrapper.h:103
EventContext::ContextEvt_t evtSeeded(const EventContext &ctx) const
Return the event count at which the current slot of CTX was last seeded.
Definition RNGWrapper.h:145
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition RNGWrapper.h:134
int ev
Definition globals.cxx:25
size_t calculateSeedMC20(const std::string &algName, uint64_t ev, uint64_t run)
Set the random seed using a string (e.g.
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.
long calculateSeedsPython(const std::string &algName, uint64_t ev, uint64_t run, uint64_t offset=0)
size_t calculateSeedMC16(const std::string &algName, uint64_t ev, uint64_t run, uint32_t offset=0)
Helper methods.
Definition run.py:1