12 #ifndef NURANDOM_RANDOMUTILS_PROVIDERS_PEREVENTPOLICY_H 13 #define NURANDOM_RANDOMUTILS_PROVIDERS_PEREVENTPOLICY_H 1 18 #include <type_traits> 77 template <
typename SEED>
121 virtual void print(std::ostream& out)
const override;
129 template <
typename Hashable>
131 {
return makeValid(std::hash<Hashable>()(info)); }
172 template <
typename T>
181 static const std::vector<std::string>
algoNames;
193 template <
typename SEED>
196 std::vector<std::string> names((
size_t)
NAlgos);
204 template <
typename SEED>
210 template <
typename SEED>
221 template <
typename SEED>
230 template <
typename SEED>
237 <<
"Input event has an invalid timestamp," 238 " random seed per-event policy EventTimestamp_v1 can't be used.\n";
242 +
" Module: " +
id.moduleLabel;
243 if (!
id.instanceName.empty())
244 s.append(
" Instance: ").append(
id.instanceName);
252 template <
typename SEED>
256 std::string algorithm_name
257 = pset.
get<std::string>(
"algorithm",
"default");
261 for (
size_t iAlgo = 0; iAlgo < (size_t)
NAlgos; ++iAlgo) {
262 if (algorithm_name !=
algoNames[iAlgo])
continue;
269 <<
"No valid event random seed algorithm specified!\n";
279 auto const& initSeedConfig
281 if (!initSeedConfig.is_empty()) {
287 <<
"Error creating the pre-event policy of `perEvent` random policy" 288 " from configuration:\n" 289 << initSeedConfig.to_indented_string(2);
298 template <
typename SEED>
304 out <<
"\n constant offset: " <<
offset;
306 out <<
"\n special policy for random seeds before the event: '" 308 <<
"'\n" << std::string(60,
'-');
310 out <<
"\n" << std::string(60,
'-');
316 template <
typename SEED>
323 template <
typename SEED>
334 <<
"Per-event random number seeder not configured!\n";
337 <<
"Unsupported per-event random number seeder (#" 338 << ((int)
algo) <<
")\n";
349 #endif // NURANDOM_RANDOMUTILS_PROVIDERS_PEREVENTPOLICY_H virtual void print(std::ostream &out) const override
Prints the details of the configuration of the random generator.
virtual seed_t createEventSeed(SeedMasterHelper::EngineId const &id, EventData_t const &info) override
Returns a seed proper for the specified event information.
static std::string UniqueEventIDString(EventData_t const &info)
Converts run, subrun and event numbers into a string.
SEED seed_t
type of the random seed
static seed_t EventTimestamp_v1(SeedMasterHelper::EngineId const &id, EventData_t const &info)
Implementation of the EventTimestamp_v1 algorithm.
SeedOffset_t offset
offset added to all the seeds
std::string const & policyName(Policy policy)
Returns the name of the specified policy.
total number of seed algorithms
typename std::make_signed< seed_t >::type SeedOffset_t
type for seed offset
virtual void print(std::ostream &out) const
Prints information on the configuration of this policy.
virtual void configure(fhicl::ParameterSet const &pset) override
Configure this policy.
static seed_t SeedFromHash(Hashable const &info)
Converts some information into a valid seed by means of hash values.
virtual seed_t getSeed(SeedMasterHelper::EngineId const &id)
Returns the next random number.
typename base_t::seed_t seed_t
static std::vector< std::string > InitAlgoNames()
Algorithm name (manual) handling.
Interface for a policy implementation.
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
T get(std::string const &key) const
static const std::vector< std::string > algoNames
Algorithm name (manual) handling.
Identifier for a engine, made of module name and optional instance name.
SeedAlgo_t algo
the algorithm to extract the seed
Defines an interface for random seed assignment policies.
static seed_t makeValid(T value)
Renders a seed valid.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Helper to instantiate a random number policy class.
Implementation of the "perEvent" policy.
Class storing a seed in the valid range.
static constexpr seed_t InvalidSeed
An invalid seed.
event timestamp algorithm (v1)
PolicyStruct_t< seed_t > initSeedPolicy
Policy used for initialization before the event (none by default).
PerEventPolicy(fhicl::ParameterSet const &pset)
static constexpr const char * DefaultVersion
Default algorithm version.
virtual seed_t createSeed(SeedMasterHelper::EngineId const &id) override
Per-job seed: pre-event seeds are returned (or invalid if none).
static std::string UniqueEventString(EventData_t const &info)
Converts event ID and timestamp information into a string.
cet::coded_exception< error, detail::translate > exception
virtual bool yieldsUniqueSeeds() const override
Returns whether the returned seed should be unique: for us it "no".
An identifier for random engines.