fire v0.19.0
Framework for sImulation and Reconstruction of Events
fire::RandomNumberSeedService Class Reference

System for consistent seeding of random number generators. More...

#include <RandomNumberSeedService.h>

Inheritance diagram for fire::RandomNumberSeedService:
[legend]
Collaboration diagram for fire::RandomNumberSeedService:
[legend]

Public Member Functions

 RandomNumberSeedService (const fire::config::Parameters &parameters)
 Create the random number seed service conditions object. More...
 
virtual void onNewRun (RunHeader &header) final override
 Configure the seed service when a new run starts. More...
 
uint64_t getSeed (const std::string &name) const
 Access a given seed by name. More...
 
std::vector< std::stringgetSeedNames () const
 Get a list of all the known seeds. More...
 
uint64_t getRootSeed () const
 Access the root seed. More...
 
virtual std::pair< const ConditionsObject *, ConditionsIntervalOfValiditygetCondition (const EventHeader &context) final override
 Get the seed service as a conditions object. More...
 
virtual void release (const ConditionsObject *co) final override
 This object is both the provider of the seed service and the conditions object itself, so it does nothing when asked to release the object. More...
 
void stream (std::ostream &s) const
 Stream the configuration of this object to the input ostream. More...
 
- Public Member Functions inherited from fire::ConditionsObject
 ConditionsObject (const std::string &name) noexcept
 Define the name of the condition.
 
virtual ~ConditionsObject ()=default
 Default destructor. More...
 
std::string getName () const
 Get the name of this object. More...
 
- Public Member Functions inherited from fire::ConditionsProvider
 ConditionsProvider (const fire::config::Parameters &ps)
 Configure the registered provider. More...
 
virtual ~ConditionsProvider ()=default
 default destructor, virtual so derived types can be destructed
 
virtual void onProcessStart ()
 Callback for the ConditionsProvider to take any necessary action when the processing of events starts.
 
virtual void onProcessEnd ()
 Callback for the ConditionsProvider to take any necessary action when the processing of events finishes, such as closing database connections.
 
const std::stringgetConditionObjectName () const
 Get the condition object available from this provider.
 
const std::stringgetTagName () const
 Access the tag name.
 
virtual void attach (Conditions *c) final
 Attach the central conditions system to this provider.
 

Static Public Attributes

static const std::string CONDITIONS_OBJECT_NAME
 Conditions object name. More...
 

Private Attributes

bool initialized_ {false}
 whether the root seed has been initialized
 
int mode_ {0}
 what mode of root seed are we using
 
uint64_t root_ {0}
 what the root seed actually is
 
std::map< std::string, uint64_t > seeds_
 cache of seeds by name
 

Friends

std::ostreamoperator<< (std::ostream &s, const RandomNumberSeedService &o)
 Output streaming operator. More...
 

Additional Inherited Members

- Public Types inherited from fire::ConditionsProvider
using Factory = factory::Factory< ConditionsProvider, std::shared_ptr< ConditionsProvider >, const config::Parameters & >
 The factory type that can create this class. More...
 
- Protected Member Functions inherited from fire::ConditionsProvider
std::pair< const ConditionsObject *, ConditionsIntervalOfValidityrequestParentCondition (const std::string &name, const EventHeader &context)
 Request another condition needed to construct this condition. More...
 
- Protected Attributes inherited from fire::ConditionsProvider
logging::logger theLog_
 The logger for this ConditionsProvider.
 

Detailed Description

System for consistent seeding of random number generators.

The system can be configured in a number of different ways. In general, seeds are constructed based on a root seed. That root seed can be constructed in a number of ways, chosen in the python configuration. (a) The root seed can be the run number of the first run observed by the service ("Run") (b) The root seed can be based on the current time ("Time") (c) The root seed can be provided in the python configuration ("External")

Individual seeds are then constructed using the root seed and a simple hash based on the name of the seed.

Seeds can also be specified in the python file (using the 'override' function), in which case no autoseeding will be performed.

Constructor & Destructor Documentation

◆ RandomNumberSeedService()

fire::RandomNumberSeedService::RandomNumberSeedService ( const fire::config::Parameters parameters)

Create the random number seed service conditions object.

This is where we decide what seed mode we will be running in.

Parameters
[in]namethe name of this provider
[in]tagnamethe name of the tag generation of this condition
[in]parametersconfiguration parameters from python
[in]processreference to the running process object

Member Function Documentation

◆ getCondition()

std::pair< const ConditionsObject *, ConditionsIntervalOfValidity > fire::RandomNumberSeedService::getCondition ( const EventHeader context)
finaloverridevirtual

Get the seed service as a conditions object.

This object is both the provider of the seed service and the conditions object itself, so after checking if it has been initialized, we return a refernce to ourselves with the unlimited interval of validity.

Parameters
[in]contextEventHeader for the event context
Returns
reference to ourselves and unlimited interval of validity

Implements fire::ConditionsProvider.

◆ getRootSeed()

uint64_t fire::RandomNumberSeedService::getRootSeed ( ) const
inline

Access the root seed.

Returns
root seed that is used to derive all other seeds

◆ getSeed()

uint64_t fire::RandomNumberSeedService::getSeed ( const std::string name) const

Access a given seed by name.

Checks the cache for the input name. If the input name is not in the cache, it generates the seed for that name by combining the root seed with a hash of the name.

Parameters
[in]nameName of seed
Returns
seed derived from root seed using the input name

◆ getSeedNames()

std::vector< std::string > fire::RandomNumberSeedService::getSeedNames ( ) const

Get a list of all the known seeds.

Returns
vector of seed names that have already been requested (in cache)

◆ onNewRun()

void fire::RandomNumberSeedService::onNewRun ( RunHeader header)
finaloverridevirtual

Configure the seed service when a new run starts.

If we are using the run number as the root seed, then we get the run number and set the root seed to it.

No matter what, we put the root seed into the RunHeader to be persisted into the output file.

Parameters
[in,out]headerRunHeader for the new run that is starting

Reimplemented from fire::ConditionsProvider.

◆ release()

virtual void fire::RandomNumberSeedService::release ( const ConditionsObject co)
inlinefinaloverridevirtual

This object is both the provider of the seed service and the conditions object itself, so it does nothing when asked to release the object.

Parameters
[in]coConditionsObject to release, unused

Reimplemented from fire::ConditionsProvider.

◆ stream()

void fire::RandomNumberSeedService::stream ( std::ostream s) const

Stream the configuration of this object to the input ostream.

Parameters
[in,out]soutput stream to print this object to

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream s,
const RandomNumberSeedService o 
)
friend

Output streaming operator.

See also
fire::RandomNumberSeedService::stream
Parameters
[in]soutput stream to print to
[in]oseed service to print
Returns
modified output stream

Member Data Documentation

◆ CONDITIONS_OBJECT_NAME

const std::string fire::RandomNumberSeedService::CONDITIONS_OBJECT_NAME
static
Initial value:
=
"RandomNumberSeedService"

Conditions object name.


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