CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions
edm::RandomNumberGenerator Class Referenceabstract

#include <RandomNumberGenerator.h>

Inheritance diagram for edm::RandomNumberGenerator:
edm::service::RandomNumberGeneratorService

Public Member Functions

virtual CLHEP::HepRandomEngine & getEngine () const =0
 Use this to get the random number engine, this is the only function most users should call. More...
 
virtual std::vector
< RandomEngineState > const & 
getEventCache () const =0
 
virtual std::vector
< RandomEngineState > const & 
getLumiCache () const =0
 
virtual uint32_t mySeed () const =0
 Exists for backward compatibility. More...
 
virtual void postEventRead (Event const &event)=0
 
virtual void preBeginLumi (LuminosityBlock const &lumi)=0
 
virtual void print ()=0
 For debugging purposes only. More...
 
 RandomNumberGenerator ()
 
virtual ~RandomNumberGenerator ()
 

Private Member Functions

RandomNumberGenerator const & operator= (RandomNumberGenerator const &)
 
 RandomNumberGenerator (RandomNumberGenerator const &)
 

Detailed Description

Description: Interface for obtaining random number engines.

Usage: This class is the abstract interface to a Service which provides access to the random number engines which are used generate random numbers. One accesses the service using the Service system.

edm::Service<edm::RandomNumberGenerator> rng; CLHEP::HepRandomEngine& engine = rng->getEngine();

The RandomNumberGenerator automatically knows what module is requesting an engine and will return the proper one for that module.

A source cannot use this service and sources should not generate random numbers.

Random numbers should only be generated in two functions of a module, the function used to process the Event and also the beginLuminosityBlock function. Random numbers should not be generated at any other time, not in the constructor, not at beginJob, not at beginRun ... Note that this restriction applies to generating the random numbers only, it is fine to get the reference to the engine and save it or a pointer to it at other times as long as it is not used to generate random numbers.

The service owns the engines and handles memory management for them.

The service does a lot of work behind the scene to allow one to replay specific events of a prior process. There are two different mechanisms.

First, if the parameter named "saveFileName" is set the state of the random engines will be written to a separate text file before each event is processed. This text file is overwritten at each event. If a job crashes while processing an event, then one can replay the processing of the event where the crash occurred and get the same random number sequences.

Second, when a separate Producer module is also included in a path the state of all the engines managed by this service can be saved to the both the Event and LuminosityBlock. Then in a later process, the RandomNumberGenerator is capable of restoring the state of the engines in order to be able to exactly replay the earlier process starting at any event without having to replay the entire process.

This service performs tasks so that the random sequences in multiprocess jobs are independent sequences with different seeds.

Two warnings.

  1. When there is more than one LuminosityBlock in a single process, the random number engines are reset to the same starting state at beginLuminosityBlock for all of them. This allows the initialization performed in all of them to be identical. At the end of beginLuminosityBlock (after the first one), the engine states are reset to what they were before beginLuminosityBlock so that the sequences for events continue forward to produce independent events. In current CMS use cases this is the correct behavior, but one could imagine cases where it is not. This is the best scheme we could come up with to allow replay in an environment including random numbers being generated during initialization and file merging and multi process jobs.
  2. In multiprocess jobs, the sequences for the child processes are reinitialized with new seeds after the first beginLuminosityBlock but before any events are processed. The seed used is the original seed plus the child index. In existing work management schemes this works well, but if one were to run multiple overlapping jobs and increment the seeds in the configuration by 1 for each succeeding job and use multiprocess jobs, then there would be a problem with the same seeds being used in the child processes spawned by different parent processes.

There are more details explaining this service on a TWIKI page which can be accessed through a link on the Framework TWIKI page of the SWGuide.

Author
Chris Jones and W. David Dagenhart, created March 7, 2006

Definition at line 106 of file RandomNumberGenerator.h.

Constructor & Destructor Documentation

edm::RandomNumberGenerator::RandomNumberGenerator ( )
inline

Definition at line 110 of file RandomNumberGenerator.h.

110 {}
edm::RandomNumberGenerator::~RandomNumberGenerator ( )
virtual

Definition at line 4 of file RandomNumberGenerator.cc.

4 {}
edm::RandomNumberGenerator::RandomNumberGenerator ( RandomNumberGenerator const &  )
private

Member Function Documentation

virtual CLHEP::HepRandomEngine& edm::RandomNumberGenerator::getEngine ( ) const
pure virtual

Use this to get the random number engine, this is the only function most users should call.

Implemented in edm::service::RandomNumberGeneratorService.

Referenced by AfterBurnerGenerator::AfterBurnerGenerator(), gen::AMPTHadronizer::AMPTHadronizer(), CaloHitResponse::analogSignalAmplitude(), BaseEvtVtxGenerator::BaseEvtVtxGenerator(), edm::BeamHaloProducer::BeamHaloProducer(), edm::BeamHaloSource::BeamHaloSource(), TauSpinnerCMS::beginJob(), BetaBoostEvtVtxGenerator::BetaBoostEvtVtxGenerator(), ElectronEnergyCalibrator::calibrate(), CastorDigiProducer::CastorDigiProducer(), CSCDigiProducer::CSCDigiProducer(), DTDigitizer::DTDigitizer(), EcalElectronicsSim::EcalElectronicsSim(), EcalHitResponse::EcalHitResponse(), EcalTBMCInfoProducer::EcalTBMCInfoProducer(), ESElectronicsSim::encode(), ESDigitizer::ESDigitizer(), ESElectronicsSimFast::ESElectronicsSimFast(), gen::EvtGenInterface::EvtGenInterface(), edm::ExhumeProducer::ExhumeProducer(), GaussianZBeamSpotFilter::GaussianZBeamSpotFilter(), HcalQie::getCode(), gen::getEngineReference(), HcalDigitizer::HcalDigitizer(), gen::HijingHadronizer::HijingHadronizer(), HcalSiPM::hitCells(), L1DummyProducer::L1DummyProducer(), L1EmulBias::L1EmulBias(), pat::ObjectEnergyScale< T >::ObjectEnergyScale(), pat::ObjectSpatialResolution< T >::ObjectSpatialResolution(), edm::PileUp::PileUp(), edm::PomwigProducer::PomwigProducer(), PythiaFilterIsolatedTrack::PythiaFilterIsolatedTrack(), RandomEngine::RandomEngine(), edm::RandomFilter::RandomFilter(), CaloHitRespoNew::ranGauss(), CaloHitRespoNew::ranPois(), gen::ReggeGribovPartonMCHadronizer::ReggeGribovPartonMCHadronizer(), edm::PileUp::reload(), HPDNoiseLibraryReader::setRandomEngine(), gen::TauolappInterface::Setup(), SubsystemNeutronWriter::SubsystemNeutronWriter(), TauSpinnerFilter::TauSpinnerFilter(), TxCalculator::TxCalculator(), HcalTB02Analysis::update(), and HcalTB04Analysis::xtalAnalysis().

virtual std::vector<RandomEngineState> const& edm::RandomNumberGenerator::getEventCache ( ) const
pure virtual
virtual std::vector<RandomEngineState> const& edm::RandomNumberGenerator::getLumiCache ( ) const
pure virtual
virtual uint32_t edm::RandomNumberGenerator::mySeed ( ) const
pure virtual
RandomNumberGenerator const& edm::RandomNumberGenerator::operator= ( RandomNumberGenerator const &  )
private
virtual void edm::RandomNumberGenerator::postEventRead ( Event const &  event)
pure virtual
virtual void edm::RandomNumberGenerator::preBeginLumi ( LuminosityBlock const &  lumi)
pure virtual
virtual void edm::RandomNumberGenerator::print ( )
pure virtual

For debugging purposes only.

Implemented in edm::service::RandomNumberGeneratorService.