LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
rndm::details Namespace Reference

Classes

class  AutoIncrementPolicy
 Implementation of the "autoIncrement" policy. More...
 
class  CheckedRangePolicy
 Range-checked policy (abstract) More...
 
class  LinearMappingPolicy
 Implementation of the "linearMapping" policy. More...
 
class  PerEventPolicy
 Implementation of the "perEvent" policy. More...
 
class  PerInstancePolicy
 Base class for policies reacting at engine instance level. More...
 
struct  PolicyStruct_t
 
class  PredefinedOffsetPolicy
 Implementation of the "preDefinedOffset" policy. More...
 
class  PredefinedSeedPolicy
 Implementation of the "preDefinedSeed" policy. More...
 
class  RandomPolicy
 Implementation of the "random" policy. More...
 
class  RandomSeedPolicyBase
 Interface for a policy implementation. More...
 
class  RangeCheckHelper
 Helper class to support range checking. More...
 
class  ValidSeed
 Class storing a seed in the valid range. More...
 

Enumerations

enum  Policy : unsigned { Policy::NURANDOM_SEED_SERVICE_POLICY, Policy::NURANDOM_SEED_SERVICE_POLICIES }
 Enumeration of all supported random seed policies. More...
 

Functions

template<typename SEED >
PolicyStruct_t< SEED > makeRandomSeedPolicy (fhicl::ParameterSet const &config)
 Constructs and returns a RandomSeedPolicyBase based on config. More...
 
std::vector< std::string > const & policyNames ()
 Returns a list of names of policies, in the same order as Policy enum. More...
 
std::string const & policyName (Policy policy)
 Returns the name of the specified policy. More...
 
Policy policyFromName (std::string const &name)
 Returns the policy with the specified name. More...
 

Enumeration Type Documentation

enum rndm::details::Policy : unsigned
strong

Enumeration of all supported random seed policies.

Enumerator
NURANDOM_SEED_SERVICE_POLICY 
NURANDOM_SEED_SERVICE_POLICIES 

Definition at line 38 of file PolicyNames.h.

38  : unsigned {
39  #define NURANDOM_SEED_SERVICE_POLICY(x) x,
41  #undef NURANDOM_SEED_SERVICE_POLICY
42  };
#define NURANDOM_SEED_SERVICE_POLICIES
Definition: PolicyNames.h:22

Function Documentation

template<typename SEED >
PolicyStruct_t<SEED> rndm::details::makeRandomSeedPolicy ( fhicl::ParameterSet const &  config)

Constructs and returns a RandomSeedPolicyBase based on config.

Template Parameters
SEEDthe type of seed RandomSeedPolicyBase is serving
Parameters
configconfiguration of the policy object
Returns
a new RandomSeedPolicyBase object

The policy class is created according to the parameters in the specified config parameter set. The type of policy is determined by the "policy" key in that parameter set.

Definition at line 63 of file PolicyFactory.h.

References fhicl::ParameterSet::get(), rndm::details::PolicyStruct_t< SEED >::policy, policyFromName(), and policyName().

63  {
64  std::string const& policyName = config.get<std::string>("policy");
65 
66  // Throws if policy is not recognized.
67  Policy const policy = policyFromName(policyName);
68 
69  switch (policy) {
70  case Policy::autoIncrement:
71  return { policy, std::make_unique<AutoIncrementPolicy<SEED>>(config) };
72  case Policy::linearMapping:
73  return { policy, std::make_unique<LinearMappingPolicy<SEED>>(config) };
74  case Policy::preDefinedOffset:
75  return { policy, std::make_unique<PredefinedOffsetPolicy<SEED>>(config) };
76  case Policy::preDefinedSeed:
77  return { policy, std::make_unique<PredefinedSeedPolicy<SEED>>(config) };
78  case Policy::random:
79  return { policy, std::make_unique<RandomPolicy<SEED>>(config) };
80  case Policy::perEvent:
81  return { policy, std::make_unique<PerEventPolicy<SEED>>(config) };
82  case Policy::unDefined:
83  default:
84  // this should have been prevented by an exception by `policyFromName()`
85  throw cet::exception("rndm::details::makeRandomSeedPolicy")
86  << "Internal error: unknown policy '" << policyName << "'\n";
87  } // switch
88 
89  } // rndm::details::makeRandomSeedPolicy()
Policy
Enumeration of all supported random seed policies.
Definition: PolicyNames.h:38
std::string const & policyName(Policy policy)
Returns the name of the specified policy.
Definition: PolicyNames.cxx:56
Policy policyFromName(std::string const &policyName)
Returns the policy with the specified name.
Definition: PolicyNames.cxx:67
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Policy rndm::details::policyFromName ( std::string const &  name)

Returns the policy with the specified name.

Parameters
namename of the desired policy
Returns
enumerator value matching the policy with the specified name
Exceptions
cet::exception(category: rndm::details::policyFromName) if the name is unknown or if it matches Policy::unDefined

The policy placeholder unDefined is not accepted by this function and treated as a non-existing policy.

Definition at line 67 of file PolicyNames.cxx.

References util::begin(), e, util::end(), and policyNames().

Referenced by makeRandomSeedPolicy(), and rndm::SeedMaster< SEED >::setPolicy().

67  {
68 
69  auto const& names = policyNames();
70  assert(!names.empty());
71  auto const nbegin { begin(names) }, nend { end(names) };
72 
73  auto const iter = std::find(nbegin, nend, policyName);
74 
75  Policy const policy = (iter == nend)
76  ? Policy::unDefined
77  : static_cast<Policy>(std::distance(begin(names), iter))
78  ;
79 
80  if (policy != Policy::unDefined) return policy;
81 
82  // the first policy, `unDefined`, is deliberately omitted from this message
83  cet::exception e { "rndm::details::policyFromName" };
84  e << "rndm::details::policyFromName(\"" << policyName
85  << "\"): unrecognized policy.\nKnown policies are: ";
86  auto iName = nbegin;
87  while (++iName != nend) e << " '" << (*iName) << '\'';
88  throw e << ".\n";
89 
90  } // policyFromName()
std::vector< std::string > const & policyNames()
Returns a list of names of policies, in the same order as Policy enum.
Definition: PolicyNames.cxx:52
Policy
Enumeration of all supported random seed policies.
Definition: PolicyNames.h:38
std::string const & policyName(Policy policy)
Returns the name of the specified policy.
Definition: PolicyNames.cxx:56
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
Float_t e
Definition: plot.C:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::string const & rndm::details::policyName ( Policy  policy)

Returns the name of the specified policy.

Exceptions
cet::exception(category: rndm::details::policyName) if the name is unknown

Definition at line 56 of file PolicyNames.cxx.

References policyNames().

Referenced by makeRandomSeedPolicy(), and rndm::details::PerEventPolicy< SEED >::print().

56  {
57  std::size_t const index { static_cast<unsigned>(policy) };
58  if (index < policyNames().size()) return policyNames()[index];
59 
60  throw cet::exception("rndm::details::policyName")
61  << "Invalid policy (index #" << index << ")\n";
62 
63  } // policyName()
std::vector< std::string > const & policyNames()
Returns a list of names of policies, in the same order as Policy enum.
Definition: PolicyNames.cxx:52
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::vector< std::string > const & rndm::details::policyNames ( )

Returns a list of names of policies, in the same order as Policy enum.

Definition at line 52 of file PolicyNames.cxx.

Referenced by policyFromName(), policyName(), and rndm::SeedMaster< SEED >::policyNames().

52 { return ::PolicyNames; }