fire v0.19.0
Framework for sImulation and Reconstruction of Events
|
System for consistent seeding of random number generators. More...
#include <RandomNumberSeedService.h>
Public Member Functions | |
RandomNumberSeedService (const fire::config::Parameters ¶meters) | |
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::string > | getSeedNames () const |
Get a list of all the known seeds. More... | |
uint64_t | getRootSeed () const |
Access the root seed. More... | |
virtual std::pair< const ConditionsObject *, ConditionsIntervalOfValidity > | getCondition (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::string & | getConditionObjectName () const |
Get the condition object available from this provider. | |
const std::string & | getTagName () 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::ostream & | operator<< (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 *, ConditionsIntervalOfValidity > | requestParentCondition (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. | |
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.
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.
[in] | name | the name of this provider |
[in] | tagname | the name of the tag generation of this condition |
[in] | parameters | configuration parameters from python |
[in] | process | reference to the running process object |
|
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.
[in] | context | EventHeader for the event context |
Implements fire::ConditionsProvider.
|
inline |
Access the root seed.
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.
[in] | name | Name of seed |
std::vector< std::string > fire::RandomNumberSeedService::getSeedNames | ( | ) | const |
Get a list of all the known seeds.
|
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.
[in,out] | header | RunHeader for the new run that is starting |
Reimplemented from fire::ConditionsProvider.
|
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.
[in] | co | ConditionsObject to release, unused |
Reimplemented from fire::ConditionsProvider.
void fire::RandomNumberSeedService::stream | ( | std::ostream & | s | ) | const |
Stream the configuration of this object to the input ostream.
[in,out] | s | output stream to print this object to |
|
friend |
Output streaming operator.
[in] | s | output stream to print to |
[in] | o | seed service to print |
|
static |
Conditions object name.