Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
rndm::details::RandomPolicy< SEED > Class Template Reference

Implementation of the "random" policy. More...

#include <BasePolicies.h>

Inheritance diagram for rndm::details::RandomPolicy< SEED >:
rndm::details::RandomSeedPolicyBase< SEED > rndm::details::RandomSeedPolicyBase< SEED >

Classes

class  RandomImpl
 

Public Types

using base_t = RandomSeedPolicyBase< SEED >
 
using this_t = RandomPolicy< SEED >
 
using seed_t = typename base_t::seed_t
 
using base_t = RandomSeedPolicyBase< SEED >
 
using this_t = RandomPolicy< SEED >
 
using seed_t = typename base_t::seed_t
 
- Public Types inherited from rndm::details::RandomSeedPolicyBase< SEED >
using seed_t = SEED
 type of the random seed More...
 
using EventData_t = NuRandomServiceHelper::EventSeedInputData
 type of data used for event seeds More...
 
using seed_t = SEED
 type of the random seed More...
 
using EventData_t = NuRandomServiceHelper::EventSeedInputData
 type of data used for event seeds More...
 

Public Member Functions

 RandomPolicy (fhicl::ParameterSet const &pset)
 
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...
 
 RandomPolicy (fhicl::ParameterSet const &pset)
 
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...
 
- Public Member Functions inherited from rndm::details::RandomSeedPolicyBase< SEED >
 RandomSeedPolicyBase (std::string policy_name)
 Constructor; requires the policy name. More...
 
virtual ~RandomSeedPolicyBase ()
 
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...
 
std::string getName () const
 Returns the given name of the policy. More...
 
virtual bool yieldsUniqueSeeds () const override
 Returns whether the returned seed should be unique. More...
 
 RandomSeedPolicyBase (std::string policy_name)
 Constructor; requires the policy name. More...
 
virtual ~RandomSeedPolicyBase ()
 
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...
 
std::string getName () const
 Returns the given name of the policy. More...
 
virtual bool yieldsUniqueSeeds () const
 Returns whether the returned seed should be unique. More...
 

Private Member Functions

virtual seed_t createSeed (SeedMasterHelper::EngineId const &) override
 Extracts a random seed. More...
 
virtual seed_t createSeed (SeedMasterHelper::EngineId const &) override
 Extracts a random seed. More...
 

Private Attributes

std::unique_ptr< RandomImplrandom_seed
 

Additional Inherited Members

- Static Public Attributes inherited from rndm::details::RandomSeedPolicyBase< SEED >
static constexpr seed_t InvalidSeed = 0
 An invalid seed. More...
 
- Protected Member Functions inherited from rndm::details::RandomSeedPolicyBase< SEED >
virtual seed_t createEventSeed (SeedMasterHelper::EngineId const &, EventData_t const &)
 Extracts a seed for specified event information; returns InvalidSeed. More...
 
virtual seed_t createEventSeed (SeedMasterHelper::EngineId const &, EventData_t const &)
 Extracts a seed for specified event information; returns InvalidSeed. More...
 
- Protected Attributes inherited from rndm::details::RandomSeedPolicyBase< SEED >
std::string name
 name of the policy More...
 

Detailed Description

template<typename SEED>
class rndm::details::RandomPolicy< SEED >

Implementation of the "random" policy.


This policy extracts seeds randomly. Each seed is between 1 and the maximum seed value specified at construction, both extremes included. The sequence of these seeds is initialized by a random seed. The random generator used is potentially low quality – it does not matter for this application.

Definition at line 781 of file BasePolicies.h.

Member Typedef Documentation

template<typename SEED >
using rndm::details::RandomPolicy< SEED >::base_t = RandomSeedPolicyBase<SEED>

Definition at line 45 of file RandomPolicy.h.

template<typename SEED >
using rndm::details::RandomPolicy< SEED >::base_t = RandomSeedPolicyBase<SEED>

Definition at line 783 of file BasePolicies.h.

template<typename SEED >
using rndm::details::RandomPolicy< SEED >::seed_t = typename base_t::seed_t

Definition at line 47 of file RandomPolicy.h.

template<typename SEED >
using rndm::details::RandomPolicy< SEED >::seed_t = typename base_t::seed_t

Definition at line 785 of file BasePolicies.h.

template<typename SEED >
using rndm::details::RandomPolicy< SEED >::this_t = RandomPolicy<SEED>

Definition at line 46 of file RandomPolicy.h.

template<typename SEED >
using rndm::details::RandomPolicy< SEED >::this_t = RandomPolicy<SEED>

Definition at line 784 of file BasePolicies.h.

Constructor & Destructor Documentation

template<typename SEED >
rndm::details::RandomPolicy< SEED >::RandomPolicy ( fhicl::ParameterSet const &  pset)
inline

Configures from a parameter set

See also
configure()

Definition at line 789 of file BasePolicies.h.

789  : base_t("random")
790  { this_t::configure(pset); }
RandomSeedPolicyBase< SEED > base_t
Definition: BasePolicies.h:783
virtual void configure(fhicl::ParameterSet const &pset) override
Configure this policy.
Definition: BasePolicies.h:836
template<typename SEED >
rndm::details::RandomPolicy< SEED >::RandomPolicy ( fhicl::ParameterSet const &  pset)
inline

Configures from a parameter set

See also
configure()

Definition at line 51 of file RandomPolicy.h.

51  : base_t("random")
52  { this_t::configure(pset); }
RandomSeedPolicyBase< SEED > base_t
Definition: BasePolicies.h:783
virtual void configure(fhicl::ParameterSet const &pset) override
Configure this policy.
Definition: BasePolicies.h:836

Member Function Documentation

template<typename SEED >
virtual void rndm::details::RandomPolicy< SEED >::configure ( fhicl::ParameterSet const &  pset)
overridevirtual

Configure this policy.

Parameters
psetthe parameter set for the configuration

Parameters:

  • masterSeed (unsigned integer, optional): the seed of the seed generator; by default, it's taken from the system clock

Reimplemented from rndm::details::RandomSeedPolicyBase< SEED >.

template<typename SEED >
void rndm::details::RandomPolicy< SEED >::configure ( fhicl::ParameterSet const &  pset)
overridevirtual

Configure this policy.

Parameters
psetthe parameter set for the configuration

Parameters:

  • masterSeed (unsigned integer, optional): the seed of the seed generator; by default, it's taken from the system clock

Reimplemented from rndm::details::RandomSeedPolicyBase< SEED >.

Definition at line 836 of file BasePolicies.h.

836  {
837  constexpr seed_t MagicMaxSeed = 900000000;
838  seed_t master_seed = 0;
839  if (!pset.get_if_present("masterSeed", master_seed)) {
840  // get the base seed randomly too, from the clock,
841  // and within [1; MagicMaxSeed]
842  master_seed = 1 +
843  std::chrono::system_clock::now().time_since_epoch().count()
844  % MagicMaxSeed;
845  }
846  random_seed.reset(new RandomImpl(master_seed, 1, MagicMaxSeed));
847  } // RandomPolicy<SEED>::configure()
std::unique_ptr< RandomImpl > random_seed
Definition: BasePolicies.h:826
unsigned long seed_t
template<typename SEED >
virtual seed_t rndm::details::RandomPolicy< SEED >::createSeed ( SeedMasterHelper::EngineId const &  )
inlineoverrideprivatevirtual

Extracts a random seed.

Implements rndm::details::RandomSeedPolicyBase< SEED >.

Definition at line 91 of file RandomPolicy.h.

92  { return (*random_seed)(); }
std::unique_ptr< RandomImpl > random_seed
Definition: BasePolicies.h:826
template<typename SEED >
virtual seed_t rndm::details::RandomPolicy< SEED >::createSeed ( SeedMasterHelper::EngineId const &  )
inlineoverrideprivatevirtual

Extracts a random seed.

Implements rndm::details::RandomSeedPolicyBase< SEED >.

Definition at line 829 of file BasePolicies.h.

830  { return (*random_seed)(); }
std::unique_ptr< RandomImpl > random_seed
Definition: BasePolicies.h:826
template<typename SEED >
virtual void rndm::details::RandomPolicy< SEED >::print ( std::ostream &  out) const
overridevirtual

Prints the details of the configuration of the random generator.

Reimplemented from rndm::details::RandomSeedPolicyBase< SEED >.

template<typename SEED >
void rndm::details::RandomPolicy< SEED >::print ( std::ostream &  out) const
overridevirtual

Prints the details of the configuration of the random generator.

Reimplemented from rndm::details::RandomSeedPolicyBase< SEED >.

Definition at line 852 of file BasePolicies.h.

852  {
853  base_t::print(out);
854  out
855  << "\n master seed: " << random_seed->master_seed()
856  << "\n seed within: [ " << random_seed->min()
857  << " ; " << random_seed->max() << " ]"
858  ;
859  } // RandomPolicy<SEED>::print()
std::unique_ptr< RandomImpl > random_seed
Definition: BasePolicies.h:826
virtual void print(std::ostream &out) const
Prints information on the configuration of this policy.
Definition: BasePolicies.h:76

Member Data Documentation

template<typename SEED >
std::unique_ptr< RandomImpl > rndm::details::RandomPolicy< SEED >::random_seed
private

Definition at line 826 of file BasePolicies.h.


The documentation for this class was generated from the following files: