ATLAS Offline Software
Loading...
Searching...
No Matches
RNGWrapper.h
Go to the documentation of this file.
1// -*- c++ -*-
2/*
3 Copyright (C) 2002-2026 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
83 static constexpr std::initializer_list<SeedingOptionType> all_SeedingOptions = {MC20Seeding, MC16Seeding, MC21Seeding};
84
89 void setSeedLegacy(const std::string& algName, const EventContext& ctx, uint32_t offset, SeedingOptionType seeding,
90 EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT);
91
93 void setSeed(size_t slot, size_t seed,
94 EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT);
95
97 void setSeeds(size_t slot, const long * seeds,
98 EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT);
99
103 operator CLHEP::HepRandomEngine*() const {
104 return m_engines[Gaudi::Hive::currentContext().slot()];
105 }
106
108 CLHEP::HepRandomEngine* getEngine(const EventContext &ctx) const {
109 return m_engines[ctx.slot()];
110 }
111
113 EventContext::ContextEvt_t evtSeeded(const EventContext &ctx) const
114 {
115 return m_evtSeeded[ctx.slot()];
116 }
117
118 private:
119
124 void setSeedMC16(const std::string& algName, size_t slot, uint64_t ev, uint64_t run, uint32_t offset=0,
125 EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT);
126
129 void setSeedMC20(const std::string& algName, size_t slot, uint64_t ev, uint64_t run,
130 EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT);
131
134 void setSeedMC21(const std::string& algName, size_t slot, uint64_t ev, uint64_t run, uint64_t offset=0,
135 EventContext::ContextEvt_t evt = EventContext::INVALID_CONTEXT_EVT);
136
138 std::vector<CLHEP::HepRandomEngine*> m_engines;
139
141 std::vector<EventContext::ContextEvt_t> m_evtSeeded;
142
143 };
144
145}
146
147//Default to MC21 seeding for now
148inline void ATHRNG::RNGWrapper::setSeed(const std::string& algName, size_t slot, uint64_t ev, uint64_t run,
149 EventContext::ContextEvt_t evt /*= EventContext::INVALID_CONTEXT_EVT*/)
150{
151 setSeedMC21(algName,slot,ev,run,0,evt);
152}
153
154inline void ATHRNG::RNGWrapper::setSeed(const std::string& algName, const EventContext& ctx)
155{
156 setSeed( algName, ctx.slot(),
157 ctx.eventID().event_number(),
158 ctx.eventID().run_number(),
159 ctx.evt() );
160}
161
162
163#endif
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition RNGWrapper.h:154
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 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...
std::vector< EventContext::ContextEvt_t > m_evtSeeded
Event counter when the engine was last seeded.
Definition RNGWrapper.h:141
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:138
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.
Definition RNGWrapper.h:77
static constexpr std::initializer_list< SeedingOptionType > all_SeedingOptions
Definition RNGWrapper.h:83
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:113
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition RNGWrapper.h:108
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.
int run(int argc, char *argv[])