LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
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
 
using EventData_t = NuRandomServiceHelper::EventSeedInputData
 type of data used for event seeds 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...
 
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...
 
virtual bool yieldsUniqueSeeds () const override
 Returns whether the returned seed should be unique. More...
 
virtual bool yieldsUniqueSeeds () const
 Returns whether the returned seed should be unique. More...
 

Static Public Attributes

static constexpr seed_t InvalidSeed = 0
 An invalid seed. More...
 

Protected Member Functions

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

std::string name
 name of the policy 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
 

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.

type of data used for event seeds

Definition at line 48 of file BasePolicies.h.

type of data used for event seeds

Definition at line 93 of file RandomSeedPolicyBase.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.

References rndm::details::RandomSeedPolicyBase< SEED >::configure(), and rndm::details::RandomSeedPolicyBase< SEED >::print().

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.

References rndm::details::RandomPolicy< SEED >::configure(), and rndm::details::RandomPolicy< SEED >::print().

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.

References fhicl::ParameterSet::get_if_present().

Referenced by rndm::details::RandomPolicy< SEED >::createSeed(), and rndm::details::RandomPolicy< SEED >::RandomPolicy().

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
typename base_t::seed_t seed_t
Definition: BasePolicies.h:785
template<typename SEED>
virtual seed_t rndm::details::RandomSeedPolicyBase< SEED >::createEventSeed ( SeedMasterHelper::EngineId const &  ,
EventData_t const &   
)
inlineprotectedvirtualinherited

Extracts a seed for specified event information; returns InvalidSeed.

Reimplemented in rndm::details::PerEventPolicy< SEED >.

Definition at line 90 of file BasePolicies.h.

References rndm::details::RandomSeedPolicyBase< SEED >::InvalidSeed.

Referenced by rndm::details::RandomSeedPolicyBase< SEED >::getEventSeed().

91  { return InvalidSeed; }
static constexpr seed_t InvalidSeed
An invalid seed.
Definition: BasePolicies.h:51
template<typename SEED>
virtual seed_t rndm::details::RandomSeedPolicyBase< SEED >::createEventSeed ( SeedMasterHelper::EngineId const &  ,
EventData_t const &   
)
inlineprotectedvirtualinherited

Extracts a seed for specified event information; returns InvalidSeed.

Reimplemented in rndm::details::PerEventPolicy< SEED >.

Definition at line 135 of file RandomSeedPolicyBase.h.

136  { return InvalidSeed; }
static constexpr seed_t InvalidSeed
An invalid seed.
Definition: BasePolicies.h:51
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 seed_t rndm::details::RandomSeedPolicyBase< SEED >::getEventSeed ( SeedMasterHelper::EngineId const &  id,
EventData_t const &  eventInfo 
)
inlinevirtualinherited

Returns a random number specific to an event.

Definition at line 69 of file BasePolicies.h.

References rndm::details::RandomSeedPolicyBase< SEED >::createEventSeed().

Referenced by rndm::details::RandomSeedPolicyBase< SEED >::getSeed().

70  { return createEventSeed(id, eventInfo); }
virtual seed_t createEventSeed(SeedMasterHelper::EngineId const &, EventData_t const &)
Extracts a seed for specified event information; returns InvalidSeed.
Definition: BasePolicies.h:90
template<typename SEED>
virtual seed_t rndm::details::RandomSeedPolicyBase< SEED >::getEventSeed ( SeedMasterHelper::EngineId const &  id,
EventData_t const &  eventInfo 
)
inlinevirtualinherited

Returns a random number specific to an event.

Definition at line 114 of file RandomSeedPolicyBase.h.

115  { return createEventSeed(id, eventInfo); }
virtual seed_t createEventSeed(SeedMasterHelper::EngineId const &, EventData_t const &)
Extracts a seed for specified event information; returns InvalidSeed.
Definition: BasePolicies.h:90
template<typename SEED>
std::string rndm::details::RandomSeedPolicyBase< SEED >::getName ( ) const
inlineinherited
template<typename SEED>
std::string rndm::details::RandomSeedPolicyBase< SEED >::getName ( ) const
inlineinherited

Returns the given name of the policy.

Definition at line 118 of file RandomSeedPolicyBase.h.

118 { return name; }
std::string name
name of the policy
Definition: BasePolicies.h:83
template<typename SEED>
virtual seed_t rndm::details::RandomSeedPolicyBase< SEED >::getSeed ( SeedMasterHelper::EngineId const &  id)
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.

References rndm::details::RandomSeedPolicyBase< SEED >::createSeed(), and rndm::details::RandomSeedPolicyBase< SEED >::getEventSeed().

65  { return createSeed(id); }
virtual seed_t createSeed(SeedMasterHelper::EngineId const &)=0
Extracts the next random number seed.
template<typename SEED>
virtual seed_t rndm::details::RandomSeedPolicyBase< SEED >::getSeed ( SeedMasterHelper::EngineId const &  id)
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.

110  { return createSeed(id); }
virtual seed_t createSeed(SeedMasterHelper::EngineId const &)=0
Extracts the next random number seed.
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.

Referenced by rndm::details::RandomPolicy< SEED >::createSeed(), and rndm::details::RandomPolicy< SEED >::RandomPolicy().

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
template<typename SEED>
virtual bool rndm::details::RandomSeedPolicyBase< SEED >::yieldsUniqueSeeds ( ) const
inlineoverridevirtualinherited

Returns whether the returned seed should be unique.

Reimplemented in rndm::details::PredefinedSeedPolicy< SEED >, rndm::details::PredefinedSeedPolicy< SEED >, and rndm::details::PerEventPolicy< SEED >.

Definition at line 80 of file BasePolicies.h.

80 { return true; }
template<typename SEED>
virtual bool rndm::details::RandomSeedPolicyBase< SEED >::yieldsUniqueSeeds ( ) const
inlinevirtualinherited

Returns whether the returned seed should be unique.

Reimplemented in rndm::details::PredefinedSeedPolicy< SEED >, rndm::details::PredefinedSeedPolicy< SEED >, and rndm::details::PerEventPolicy< SEED >.

Definition at line 125 of file RandomSeedPolicyBase.h.

125 { return true; }

Member Data Documentation

template<typename SEED>
static constexpr seed_t rndm::details::RandomSeedPolicyBase< SEED >::InvalidSeed = 0
staticinherited
template<typename SEED>
std::string rndm::details::RandomSeedPolicyBase< SEED >::name
protectedinherited

name of the policy

Definition at line 83 of file BasePolicies.h.

Referenced by rndm::details::RandomSeedPolicyBase< SEED >::getName().

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

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