LDMX Software
|
System for consistent seeding of random number generators. More...
#include <RandomNumberSeedService.h>
Public Member Functions | |
RandomNumberSeedService (const std::string &name, const std::string &tagname, const framework::config::Parameters ¶meters, Process &process) | |
Create the random number seed service conditions object. | |
virtual void | onNewRun (ldmx::RunHeader &header) |
Configure the seed service when a new run starts. | |
uint64_t | getSeed (const std::string &name) const |
Access a given seed by name. | |
std::vector< std::string > | getSeedNames () const |
Get a list of all the known seeds. | |
uint64_t | getMasterSeed () const |
Access the master seed. | |
virtual std::pair< const ConditionsObject *, ConditionsIOV > | getCondition (const ldmx::EventHeader &context) |
Get the seed service as a conditions object. | |
virtual void | releaseConditionsObject (const ConditionsObject *co) |
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. | |
void | stream (std::ostream &s) const |
Stream the configuration of this object to the input ostream. | |
Public Member Functions inherited from framework::ConditionsObject | |
ConditionsObject (const std::string &name) | |
Class constructor. | |
virtual | ~ConditionsObject () |
Destructor. | |
std::string | getName () const |
Get the name of this object. | |
Public Member Functions inherited from framework::ConditionsObjectProvider | |
ConditionsObjectProvider (const std::string &objname, const std::string &tagname, const framework::config::Parameters ¶meters, Process &process) | |
Class constructor. | |
virtual | ~ConditionsObjectProvider () |
Class destructor. | |
virtual void | onProcessStart () |
Callback for the ConditionsObjectProvider to take any necessary action when the processing of events starts. | |
virtual void | onProcessEnd () |
Callback for the ConditionsObjectProvider to take any necessary action when the processing of events finishes, such as closing database connections. | |
const std::string & | getConditionObjectName () const |
Get the list of conditions objects available from this provider. | |
const std::string & | getTagName () const |
Access the tag name. | |
Static Public Attributes | |
static const std::string | CONDITIONS_OBJECT_NAME |
Conditions object name. | |
Static Public Attributes inherited from framework::ConditionsObjectProvider | |
static const int | CLASSTYPE {10} |
Constant used to types by the PluginFactory. | |
Private Attributes | |
bool | initialized_ {false} |
whether the master seed has been initialized | |
int | seedMode_ {0} |
what mode of master seed are we using | |
uint64_t | masterSeed_ {0} |
what the master 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. | |
Additional Inherited Members | |
Static Public Member Functions inherited from framework::ConditionsObjectProvider | |
static void | declare (const std::string &classname, ConditionsObjectProviderMaker *) |
Internal function which is part of the PluginFactory machinery. | |
Protected Member Functions inherited from framework::ConditionsObjectProvider | |
std::pair< const ConditionsObject *, ConditionsIOV > | requestParentCondition (const std::string &name, const ldmx::EventHeader &context) |
Request another condition needed to construct this condition. | |
const Process & | process () const |
Get the process handle. | |
Protected Attributes inherited from framework::ConditionsObjectProvider | |
logging::logger | theLog_ |
The logger for this ConditionsObjectProvider. | |
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 master seed. That master seed can be constructed in a number of ways, chosen in the python configuration. (a) The master seed can be the run number of the first run observed by the service ("Run") (b) The master seed can be based on the current time ("Time") (c) The master seed can be provided in the python configuration ("External")
Individual seeds are then constructed using the master seed and a simple hash based on the name of the seed. Seeds can also be specified in the python file, in which case no autoseeding will be performed.
Definition at line 33 of file RandomNumberSeedService.h.
framework::RandomNumberSeedService::RandomNumberSeedService | ( | const std::string & | name, |
const std::string & | tagname, | ||
const framework::config::Parameters & | parameters, | ||
Process & | process | ||
) |
Create the random number seed service conditions object.
This is where we decide what seed mode we will be running in.
@TODO allow loading of hand-provided seeds from python
[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 |
Definition at line 29 of file RandomNumberSeedService.cxx.
References framework::config::Parameters::getParameter(), initialized_, masterSeed_, and seedMode_.
|
virtual |
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 framework::ConditionsObjectProvider.
Definition at line 82 of file RandomNumberSeedService.cxx.
References ldmx::EventHeader::getRun(), initialized_, masterSeed_, and seedMode_.
|
inline |
Access the master seed.
Definition at line 93 of file RandomNumberSeedService.h.
References masterSeed_.
uint64_t framework::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 master seed with a hash of the name.
[in] | name | Name of seed |
Definition at line 58 of file RandomNumberSeedService.cxx.
References masterSeed_, and seeds_.
Referenced by simcore::Simulator::onNewRun().
std::vector< std::string > framework::RandomNumberSeedService::getSeedNames | ( | ) | const |
Get a list of all the known seeds.
Definition at line 73 of file RandomNumberSeedService.cxx.
References seeds_.
|
virtual |
Configure the seed service when a new run starts.
If we are using the run number as the master seed, then we get the run number and set the master seed to it.
No matter what, we put the master seed into the RunHeader to be persisted into the output file.
[in,out] | header | RunHeader for the new run that is starting |
Reimplemented from framework::ConditionsObjectProvider.
Definition at line 49 of file RandomNumberSeedService.cxx.
References framework::Process::getPassName(), ldmx::RunHeader::getRunNumber(), initialized_, masterSeed_, framework::ConditionsObjectProvider::process(), seedMode_, and ldmx::RunHeader::setIntParameter().
|
inlinevirtual |
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 framework::ConditionsObjectProvider.
Definition at line 114 of file RandomNumberSeedService.h.
void framework::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 |
Definition at line 18 of file RandomNumberSeedService.cxx.
References masterSeed_, seedMode_, and seeds_.
|
friend |
Output streaming operator.
[in] | s | output stream to print to |
[in] | o | seed service to print |
Definition at line 132 of file RandomNumberSeedService.h.
|
static |
Conditions object name.
Definition at line 37 of file RandomNumberSeedService.h.
Referenced by recon::OverlayProducer::onNewRun(), simcore::Simulator::onNewRun(), tracking::reco::DigitizationProcessor::onNewRun(), ecal::EcalDigiProducer::produce(), hcal::HcalDigiProducer::produce(), recon::OverlayProducer::produce(), trigscint::TrigScintDigiProducer::produce(), and trigscint::TrigScintQIEDigiProducer::produce().
|
private |
whether the master seed has been initialized
Definition at line 140 of file RandomNumberSeedService.h.
Referenced by getCondition(), onNewRun(), and RandomNumberSeedService().
|
private |
what the master seed actually is
Definition at line 146 of file RandomNumberSeedService.h.
Referenced by getCondition(), getMasterSeed(), getSeed(), onNewRun(), RandomNumberSeedService(), and stream().
|
private |
what mode of master seed are we using
Definition at line 143 of file RandomNumberSeedService.h.
Referenced by getCondition(), onNewRun(), RandomNumberSeedService(), and stream().
|
mutableprivate |
cache of seeds by name
Definition at line 149 of file RandomNumberSeedService.h.
Referenced by getSeed(), getSeedNames(), and stream().