LArSoft
v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
|
Implementation of the "perEvent" policy. More...
#include "PerEventPolicy.h"
Public Types | |
enum | SeedAlgo_t { saEventTimestamp_v1, NAlgos, saUndefined, saDefault = saEventTimestamp_v1 } |
using | base_t = RandomSeedPolicyBase< SEED > |
using | this_t = PerEventPolicy< SEED > |
using | seed_t = typename base_t::seed_t |
using | EventData_t = NuRandomServiceHelper::EventSeedInputData |
type for contextual event information More... | |
Public Member Functions | |
PerEventPolicy (fhicl::ParameterSet const &pset) | |
virtual bool | yieldsUniqueSeeds () const override |
Returns whether the returned seed should be unique: for us it "no". More... | |
virtual void | configure (fhicl::ParameterSet const &pset) override |
Configure this policy. More... | |
virtual void | print (std::ostream &out) const override |
Prints the details of the configuration of the random generator. More... | |
virtual seed_t | getSeed (SeedMasterHelper::EngineId const &id) |
Returns the next random number. More... | |
virtual seed_t | getSeed (SeedMasterHelper::EngineId const &id) |
Returns the next random number. More... | |
virtual seed_t | getEventSeed (SeedMasterHelper::EngineId const &id, EventData_t const &eventInfo) |
Returns a random number specific to an event. More... | |
virtual seed_t | getEventSeed (SeedMasterHelper::EngineId const &id, EventData_t const &eventInfo) |
Returns a random number specific to an event. More... | |
std::string | getName () const |
Returns the given name of the policy. More... | |
std::string | getName () const |
Returns the given name of the policy. More... | |
Static Public Member Functions | |
template<typename Hashable > | |
static seed_t | SeedFromHash (Hashable const &info) |
Converts some information into a valid seed by means of hash values. More... | |
static std::string | UniqueEventIDString (EventData_t const &info) |
Converts run, subrun and event numbers into a string. More... | |
static std::string | UniqueEventString (EventData_t const &info) |
Converts event ID and timestamp information into a string. More... | |
Static Public Attributes | |
static constexpr const char * | DefaultVersion = "v1" |
Default algorithm version. More... | |
static constexpr seed_t | InvalidSeed = 0 |
An invalid seed. More... | |
Protected Attributes | |
std::string | name |
name of the policy More... | |
Private Types | |
using | SeedOffset_t = typename std::make_signed< seed_t >::type |
type for seed offset More... | |
Private Member Functions | |
virtual seed_t | createSeed (SeedMasterHelper::EngineId const &id) override |
Per-job seed: pre-event seeds are returned (or invalid if none). More... | |
virtual seed_t | createEventSeed (SeedMasterHelper::EngineId const &id, EventData_t const &info) override |
Returns a seed proper for the specified event information. More... | |
Static Private Member Functions | |
template<typename T > | |
static seed_t | makeValid (T value) |
Renders a seed valid. More... | |
static seed_t | EventTimestamp_v1 (SeedMasterHelper::EngineId const &id, EventData_t const &info) |
Implementation of the EventTimestamp_v1 algorithm. More... | |
Private Attributes | |
SeedAlgo_t | algo |
the algorithm to extract the seed More... | |
SeedOffset_t | offset |
offset added to all the seeds More... | |
PolicyStruct_t< seed_t > | initSeedPolicy |
Policy used for initialization before the event (none by default). More... | |
static const std::vector< std::string > | algoNames = PerEventPolicy<SEED>::InitAlgoNames() |
Algorithm name (manual) handling. More... | |
static std::vector< std::string > | InitAlgoNames () |
Algorithm name (manual) handling. More... | |
Implementation of the "perEvent" policy.
This policy extracts seeds depending on contextual information from the event. The information that enters the seed is the event ID (run, subrun, event), the process name, and the engine ID.
The policy is only effective if an event is being processed. Before the first event is processed, seeds are initialized to a fixed value, while in between the events they are not modified and the random numbers extracted at that time will depend on which event was processed last.
As a partial mitigation to this, it is possible to specify a "pre-event" policy that is used to initialize the random engines on construction, just like the policies which do not depend on the event (like autoIncrement
and random
) do. This is achieved by specifying in the initSeedPolicy
configuration table the whole configuration of this "fallback" policy. For example:
sets up the perEvent
policy, and uses a preDefinedSeed
for the seeds before the first event.
Definition at line 78 of file PerEventPolicy.h.
using rndm::details::PerEventPolicy< SEED >::base_t = RandomSeedPolicyBase<SEED> |
Definition at line 80 of file PerEventPolicy.h.
using rndm::details::PerEventPolicy< SEED >::EventData_t = NuRandomServiceHelper::EventSeedInputData |
type for contextual event information
Definition at line 85 of file PerEventPolicy.h.
using rndm::details::PerEventPolicy< SEED >::seed_t = typename base_t::seed_t |
Definition at line 82 of file PerEventPolicy.h.
|
private |
type for seed offset
Definition at line 143 of file PerEventPolicy.h.
using rndm::details::PerEventPolicy< SEED >::this_t = PerEventPolicy<SEED> |
Definition at line 81 of file PerEventPolicy.h.
enum rndm::details::PerEventPolicy::SeedAlgo_t |
Enumerator | |
---|---|
saEventTimestamp_v1 |
event timestamp algorithm (v1) |
NAlgos |
total number of seed algorithms |
saUndefined |
algorithm not defined |
saDefault |
default algorithm |
Definition at line 87 of file PerEventPolicy.h.
|
inline |
Configures from a parameter set
Definition at line 96 of file PerEventPolicy.h.
References rndm::details::PerEventPolicy< SEED >::configure().
|
overridevirtual |
Configure this policy.
pset | the parameter set for the configuration |
Parameters:
Reimplemented from rndm::details::RandomSeedPolicyBase< SEED >.
Definition at line 253 of file PerEventPolicy.h.
References rndm::details::PerEventPolicy< SEED >::algo, rndm::details::PerEventPolicy< SEED >::algoNames, art::errors::Configuration, e, fhicl::ParameterSet::get(), rndm::details::PerEventPolicy< SEED >::initSeedPolicy, rndm::details::PerEventPolicy< SEED >::NAlgos, rndm::details::PerEventPolicy< SEED >::offset, rndm::details::PerEventPolicy< SEED >::saDefault, and rndm::details::PerEventPolicy< SEED >::saUndefined.
Referenced by rndm::details::PerEventPolicy< SEED >::PerEventPolicy(), and rndm::details::PerEventPolicy< SEED >::yieldsUniqueSeeds().
|
overrideprivatevirtual |
Returns a seed proper for the specified event information.
id | random number engine ID (moule label and instance name) |
info | event information |
The algorithm used to combine the provided information into a seed is defined by the configuration. The following algorithms are supported:
Reimplemented from rndm::details::RandomSeedPolicyBase< SEED >.
Definition at line 325 of file PerEventPolicy.h.
References rndm::details::PerEventPolicy< SEED >::algo, art::errors::Configuration, rndm::details::PerEventPolicy< SEED >::EventTimestamp_v1(), rndm::details::RandomSeedPolicyBase< SEED >::InvalidSeed, art::errors::LogicError, rndm::details::PerEventPolicy< SEED >::offset, rndm::details::PerEventPolicy< SEED >::saEventTimestamp_v1, rndm::details::PerEventPolicy< SEED >::saUndefined, and seed.
Referenced by rndm::details::PerEventPolicy< SEED >::createSeed().
|
overrideprivatevirtual |
Per-job seed: pre-event seeds are returned (or invalid if none).
Implements rndm::details::RandomSeedPolicyBase< SEED >.
Definition at line 318 of file PerEventPolicy.h.
References rndm::details::PerEventPolicy< SEED >::createEventSeed(), rndm::details::RandomSeedPolicyBase< SEED >::getSeed(), rndm::details::PerEventPolicy< SEED >::initSeedPolicy, and rndm::details::RandomSeedPolicyBase< SEED >::InvalidSeed.
Referenced by rndm::details::PerEventPolicy< SEED >::print().
|
staticprivate |
Implementation of the EventTimestamp_v1 algorithm.
Definition at line 232 of file PerEventPolicy.h.
References art::errors::InvalidNumber, rndm::NuRandomServiceHelper::EventSeedInputData::isTimeValid, MF_LOG_DEBUG, rndm::NuRandomServiceHelper::EventSeedInputData::processName, seed, rndm::details::PerEventPolicy< SEED >::SeedFromHash(), and rndm::details::PerEventPolicy< SEED >::UniqueEventString().
Referenced by rndm::details::PerEventPolicy< SEED >::createEventSeed(), rndm::details::PerEventPolicy< SEED >::makeValid(), and rndm::details::PerEventPolicy< SEED >::UniqueEventString().
|
inlinevirtualinherited |
Returns a random number specific to an event.
Definition at line 69 of file BasePolicies.h.
Referenced by rndm::details::RandomSeedPolicyBase< seed_t >::getSeed().
|
inlinevirtualinherited |
Returns a random number specific to an event.
Definition at line 114 of file RandomSeedPolicyBase.h.
|
inlineinherited |
Returns the given name of the policy.
Definition at line 73 of file BasePolicies.h.
Referenced by rndm::details::CheckedRangePolicy< SEED >::CheckRangeConfiguration(), rndm::details::CheckedRangePolicy< SEED >::ensureRange(), and rndm::details::RandomSeedPolicyBase< seed_t >::print().
|
inlineinherited |
Returns the given name of the policy.
Definition at line 118 of file RandomSeedPolicyBase.h.
|
inlinevirtualinherited |
Returns the next random number.
Reimplemented in rndm::details::CheckedRangePolicy< SEED >, and rndm::details::CheckedRangePolicy< SEED >.
Definition at line 64 of file BasePolicies.h.
Referenced by rndm::details::PerEventPolicy< SEED >::createSeed().
|
inlinevirtualinherited |
Returns the next random number.
Reimplemented in rndm::details::CheckedRangePolicy< SEED >, and rndm::details::CheckedRangePolicy< SEED >.
Definition at line 109 of file RandomSeedPolicyBase.h.
|
staticprivate |
Algorithm name (manual) handling.
Definition at line 194 of file PerEventPolicy.h.
References rndm::details::PerEventPolicy< SEED >::NAlgos, rndm::details::PerEventPolicy< SEED >::saEventTimestamp_v1, and rndm::details::PerEventPolicy< SEED >::UniqueEventIDString().
Referenced by rndm::details::PerEventPolicy< SEED >::makeValid().
|
inlinestaticprivate |
Renders a seed valid.
Definition at line 173 of file PerEventPolicy.h.
References rndm::details::PerEventPolicy< SEED >::algoNames, rndm::details::PerEventPolicy< SEED >::EventTimestamp_v1(), rndm::details::PerEventPolicy< SEED >::InitAlgoNames(), and value.
Referenced by rndm::details::PerEventPolicy< SEED >::SeedFromHash().
|
overridevirtual |
Prints the details of the configuration of the random generator.
Reimplemented from rndm::details::RandomSeedPolicyBase< SEED >.
Definition at line 299 of file PerEventPolicy.h.
References rndm::details::PerEventPolicy< SEED >::algo, rndm::details::PerEventPolicy< SEED >::algoNames, rndm::details::PerEventPolicy< SEED >::createSeed(), rndm::details::PerEventPolicy< SEED >::initSeedPolicy, rndm::details::PerEventPolicy< SEED >::offset, rndm::details::PolicyStruct_t< SEED >::policy, rndm::details::policyName(), and rndm::details::RandomSeedPolicyBase< SEED >::print().
Referenced by rndm::details::PerEventPolicy< SEED >::yieldsUniqueSeeds().
|
inlinestatic |
Converts some information into a valid seed by means of hash values.
Definition at line 130 of file PerEventPolicy.h.
References rndm::details::PerEventPolicy< SEED >::makeValid(), rndm::details::PerEventPolicy< SEED >::UniqueEventIDString(), and rndm::details::PerEventPolicy< SEED >::UniqueEventString().
Referenced by rndm::details::PerEventPolicy< SEED >::EventTimestamp_v1().
|
static |
Converts run, subrun and event numbers into a string.
Definition at line 212 of file PerEventPolicy.h.
References rndm::NuRandomServiceHelper::EventSeedInputData::eventNumber, rndm::NuRandomServiceHelper::EventSeedInputData::runNumber, rndm::NuRandomServiceHelper::EventSeedInputData::subRunNumber, util::to_string(), and rndm::details::PerEventPolicy< SEED >::UniqueEventString().
Referenced by rndm::details::PerEventPolicy< SEED >::InitAlgoNames(), rndm::details::PerEventPolicy< SEED >::SeedFromHash(), and rndm::details::PerEventPolicy< SEED >::UniqueEventString().
|
static |
Converts event ID and timestamp information into a string.
Definition at line 223 of file PerEventPolicy.h.
References rndm::details::PerEventPolicy< SEED >::EventTimestamp_v1(), rndm::NuRandomServiceHelper::EventSeedInputData::time, util::to_string(), and rndm::details::PerEventPolicy< SEED >::UniqueEventIDString().
Referenced by rndm::details::PerEventPolicy< SEED >::EventTimestamp_v1(), rndm::details::PerEventPolicy< SEED >::SeedFromHash(), and rndm::details::PerEventPolicy< SEED >::UniqueEventIDString().
|
inlineoverridevirtual |
Returns whether the returned seed should be unique: for us it "no".
Reimplemented from rndm::details::RandomSeedPolicyBase< SEED >.
Definition at line 100 of file PerEventPolicy.h.
References rndm::details::PerEventPolicy< SEED >::configure(), and rndm::details::PerEventPolicy< SEED >::print().
|
private |
the algorithm to extract the seed
Definition at line 145 of file PerEventPolicy.h.
Referenced by rndm::details::PerEventPolicy< SEED >::configure(), rndm::details::PerEventPolicy< SEED >::createEventSeed(), and rndm::details::PerEventPolicy< SEED >::print().
|
staticprivate |
Algorithm name (manual) handling.
Definition at line 182 of file PerEventPolicy.h.
Referenced by rndm::details::PerEventPolicy< SEED >::configure(), rndm::details::PerEventPolicy< SEED >::makeValid(), and rndm::details::PerEventPolicy< SEED >::print().
|
static |
Default algorithm version.
Definition at line 125 of file PerEventPolicy.h.
|
private |
Policy used for initialization before the event (none by default).
Definition at line 150 of file PerEventPolicy.h.
Referenced by rndm::details::PerEventPolicy< SEED >::configure(), rndm::details::PerEventPolicy< SEED >::createSeed(), and rndm::details::PerEventPolicy< SEED >::print().
|
staticinherited |
An invalid seed.
Definition at line 51 of file BasePolicies.h.
Referenced by rndm::details::RandomSeedPolicyBase< seed_t >::createEventSeed(), rndm::details::PerEventPolicy< SEED >::createEventSeed(), and rndm::details::PerEventPolicy< SEED >::createSeed().
|
protectedinherited |
name of the policy
Definition at line 83 of file BasePolicies.h.
Referenced by rndm::details::RandomSeedPolicyBase< seed_t >::getName().
|
private |
offset added to all the seeds
Definition at line 147 of file PerEventPolicy.h.
Referenced by rndm::details::PerEventPolicy< SEED >::configure(), rndm::details::PerEventPolicy< SEED >::createEventSeed(), and rndm::details::PerEventPolicy< SEED >::print().