CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
PileupRandomNumberGenerator Class Reference

#include "PileupRandomNumberGenerator.h"

Inheritance diagram for PileupRandomNumberGenerator:
edm::RandomNumberGenerator

Public Member Functions

std::unique_ptr< CLHEP::HepRandomEngine > cloneEngine (edm::LuminosityBlockIndex const &) final
 
CLHEP::HepRandomEngine & getEngine (edm::StreamID const &) final
 Use this engine in event methods. More...
 
CLHEP::HepRandomEngine & getEngine (edm::LuminosityBlockIndex const &) final
 Use this engine in the global begin luminosity block method. More...
 
std::uint32_t mySeed () const final
 
 PileupRandomNumberGenerator (std::vector< std::string > const &iModuleLabels)
 
void setEngine (CLHEP::HepRandomEngine const &)
 
void setSeed (uint32_t iSeed)
 
- Public Member Functions inherited from edm::RandomNumberGenerator
RandomNumberGenerator const & operator= (RandomNumberGenerator const &)=delete
 
 RandomNumberGenerator ()
 
 RandomNumberGenerator (RandomNumberGenerator const &)=delete
 
virtual ~RandomNumberGenerator ()
 

Private Member Functions

void consumes (edm::ConsumesCollector &&iC) const final
 
const std::string & findPresentModule () const
 
std::vector< RandomEngineState > const & getEventCache (edm::StreamID const &) const final
 
std::vector< RandomEngineState > const & getLumiCache (edm::LuminosityBlockIndex const &) const final
 
void postEventRead (edm::Event const &event) final
 
void preBeginLumi (edm::LuminosityBlock const &lumi) final
 
void print (std::ostream &os) const final
 For debugging purposes only. More...
 
void setEventCache (edm::StreamID, std::vector< RandomEngineState > const &iStates) final
 
void setLumiCache (edm::LuminosityBlockIndex, std::vector< RandomEngineState > const &iStates) final
 

Static Private Member Functions

static std::unique_ptr< CLHEP::HepRandomEngine > cloneEngine (CLHEP::HepRandomEngine const &existingEngine)
 

Private Attributes

std::unordered_map< std::string, std::unique_ptr< CLHEP::HepRandomEngine > > m_modulesToEngines
 
uint32_t m_seed
 

Detailed Description

Description: Handle forwarding random numbers to modules within a mixing module

Usage: Internal

Definition at line 32 of file PileupRandomNumberGenerator.h.

Constructor & Destructor Documentation

◆ PileupRandomNumberGenerator()

PileupRandomNumberGenerator::PileupRandomNumberGenerator ( std::vector< std::string > const &  iModuleLabels)

Definition at line 27 of file PileupRandomNumberGenerator.cc.

References m_modulesToEngines, and Skims_PA_cff::name.

27  : m_seed(0) {
28  for (auto const& name : iModuleLabels) {
29  m_modulesToEngines.emplace(name, std::unique_ptr<CLHEP::HepRandomEngine>{});
30  }
31 }
std::unordered_map< std::string, std::unique_ptr< CLHEP::HepRandomEngine > > m_modulesToEngines

Member Function Documentation

◆ cloneEngine() [1/2]

std::unique_ptr< CLHEP::HepRandomEngine > PileupRandomNumberGenerator::cloneEngine ( edm::LuminosityBlockIndex const &  )
finalvirtual

This function is not intended for general use. It is intended for the special case where multiple instances of Pythia 8 will be run concurrently and we want them to be initialized exactly the same. In this special case, the luminosity block engine(s) owned by the service should not be used to generate random numbers in between calls to cloneEngine, because the clone will be in the state that existed at the moment of cloning. Before initializing Pythia, this function should be used to clone the engine owned by the service and the cloned random engine should be used to generate numbers for initialization so that all initializations in the process get identical sequences of random numbers.

Implements edm::RandomNumberGenerator.

Definition at line 41 of file PileupRandomNumberGenerator.cc.

References edm::cloneEngine(), findPresentModule(), and m_modulesToEngines.

41  {
42  auto& engine = m_modulesToEngines[findPresentModule()];
43  return edm::cloneEngine(*engine);
44 }
std::unique_ptr< CLHEP::HepRandomEngine > cloneEngine(CLHEP::HepRandomEngine const &)
Definition: cloneEngine.cc:27
std::unordered_map< std::string, std::unique_ptr< CLHEP::HepRandomEngine > > m_modulesToEngines
const std::string & findPresentModule() const

◆ cloneEngine() [2/2]

static std::unique_ptr<CLHEP::HepRandomEngine> PileupRandomNumberGenerator::cloneEngine ( CLHEP::HepRandomEngine const &  existingEngine)
staticprivate

◆ consumes()

void PileupRandomNumberGenerator::consumes ( edm::ConsumesCollector &&  iC) const
finalprivatevirtual

Implements edm::RandomNumberGenerator.

Definition at line 70 of file PileupRandomNumberGenerator.cc.

70 {}

◆ findPresentModule()

const std::string & PileupRandomNumberGenerator::findPresentModule ( ) const
private

Definition at line 74 of file PileupRandomNumberGenerator.cc.

References Exception, edm::CurrentModuleOnThread::getCurrentModuleOnThread(), edm::errors::LogicError, edm::ModuleCallingContext::moduleDescription(), and edm::ModuleDescription::moduleLabel().

Referenced by cloneEngine(), and getEngine().

74  {
76  if (mcc == nullptr) {
78  << "PileupRandomNumberGenerator::getEngine()\n"
79  "Requested a random number engine from the RandomNumberGeneratorService\n"
80  "from an unallowed transition. ModuleCallingContext is null\n";
81  }
82  return mcc->moduleDescription()->moduleLabel();
83 }
static ModuleCallingContext const * getCurrentModuleOnThread()
ModuleDescription const * moduleDescription() const noexcept
std::string const & moduleLabel() const

◆ getEngine() [1/2]

CLHEP::HepRandomEngine & PileupRandomNumberGenerator::getEngine ( edm::StreamID const &  )
finalvirtual

Use this engine in event methods.

Use the next 2 functions to get the random number engine. These are the only functions most modules should call.

Implements edm::RandomNumberGenerator.

Definition at line 33 of file PileupRandomNumberGenerator.cc.

References findPresentModule(), and m_modulesToEngines.

33  {
35 }
std::unordered_map< std::string, std::unique_ptr< CLHEP::HepRandomEngine > > m_modulesToEngines
const std::string & findPresentModule() const

◆ getEngine() [2/2]

CLHEP::HepRandomEngine & PileupRandomNumberGenerator::getEngine ( edm::LuminosityBlockIndex const &  )
finalvirtual

Use this engine in the global begin luminosity block method.

Implements edm::RandomNumberGenerator.

Definition at line 37 of file PileupRandomNumberGenerator.cc.

References findPresentModule(), and m_modulesToEngines.

37  {
39 }
std::unordered_map< std::string, std::unique_ptr< CLHEP::HepRandomEngine > > m_modulesToEngines
const std::string & findPresentModule() const

◆ getEventCache()

std::vector< RandomEngineState > const & PileupRandomNumberGenerator::getEventCache ( edm::StreamID const &  ) const
finalprivatevirtual

Implements edm::RandomNumberGenerator.

Definition at line 61 of file PileupRandomNumberGenerator.cc.

61  {
62  static const std::vector<RandomEngineState> s_dummy;
63  return s_dummy;
64 }

◆ getLumiCache()

std::vector< RandomEngineState > const & PileupRandomNumberGenerator::getLumiCache ( edm::LuminosityBlockIndex const &  ) const
finalprivatevirtual

Implements edm::RandomNumberGenerator.

Definition at line 65 of file PileupRandomNumberGenerator.cc.

65  {
66  static const std::vector<RandomEngineState> s_dummy;
67  return s_dummy;
68 }

◆ mySeed()

std::uint32_t PileupRandomNumberGenerator::mySeed ( ) const
inlinefinalvirtual

This returns the seed from the configuration. In the unusual case where an an engine type takes multiple seeds to initialize a sequence, this function only returns the first. As a general rule, this function should not be used, but is available for backward compatibility and debugging. It might be useful for some types of tests. Using this to seed engines constructed in modules is not recommended because (unless done very carefully) it will create duplicate sequences in different threads and/or data races. Also, if engines are created by modules the replay mechanism will be broken. Because it is dangerous and could be misused, this function might be deleted someday if we ever find time to delete all uses of it in CMSSW. There are of order 10 last time I checked ...

Implements edm::RandomNumberGenerator.

Definition at line 45 of file PileupRandomNumberGenerator.h.

References m_seed.

◆ postEventRead()

void PileupRandomNumberGenerator::postEventRead ( edm::Event const &  event)
finalprivatevirtual

Implements edm::RandomNumberGenerator.

Definition at line 55 of file PileupRandomNumberGenerator.cc.

55 {}

◆ preBeginLumi()

void PileupRandomNumberGenerator::preBeginLumi ( edm::LuminosityBlock const &  lumi)
finalprivatevirtual

Implements edm::RandomNumberGenerator.

Definition at line 54 of file PileupRandomNumberGenerator.cc.

54 {}

◆ print()

void PileupRandomNumberGenerator::print ( std::ostream &  os) const
finalprivatevirtual

For debugging purposes only.

Implements edm::RandomNumberGenerator.

Definition at line 72 of file PileupRandomNumberGenerator.cc.

72 {}

◆ setEngine()

void PileupRandomNumberGenerator::setEngine ( CLHEP::HepRandomEngine const &  iEngine)

Definition at line 48 of file PileupRandomNumberGenerator.cc.

References edm::cloneEngine(), m_modulesToEngines, and findQualityFiles::v.

Referenced by edm::PileUp::setRandomEngine().

48  {
49  for (auto& v : m_modulesToEngines) {
50  v.second = edm::cloneEngine(iEngine);
51  }
52 }
std::unique_ptr< CLHEP::HepRandomEngine > cloneEngine(CLHEP::HepRandomEngine const &)
Definition: cloneEngine.cc:27
std::unordered_map< std::string, std::unique_ptr< CLHEP::HepRandomEngine > > m_modulesToEngines

◆ setEventCache()

void PileupRandomNumberGenerator::setEventCache ( edm::StreamID  ,
std::vector< RandomEngineState > const &  iStates 
)
finalprivatevirtual

Implements edm::RandomNumberGenerator.

Definition at line 59 of file PileupRandomNumberGenerator.cc.

59 {}

◆ setLumiCache()

void PileupRandomNumberGenerator::setLumiCache ( edm::LuminosityBlockIndex  ,
std::vector< RandomEngineState > const &  iStates 
)
finalprivatevirtual

Implements edm::RandomNumberGenerator.

Definition at line 57 of file PileupRandomNumberGenerator.cc.

58  {}

◆ setSeed()

void PileupRandomNumberGenerator::setSeed ( uint32_t  iSeed)

Definition at line 46 of file PileupRandomNumberGenerator.cc.

References m_seed.

Referenced by edm::PileUp::setRandomEngine().

Member Data Documentation

◆ m_modulesToEngines

std::unordered_map<std::string, std::unique_ptr<CLHEP::HepRandomEngine> > PileupRandomNumberGenerator::m_modulesToEngines
private

◆ m_seed

uint32_t PileupRandomNumberGenerator::m_seed
private

Definition at line 67 of file PileupRandomNumberGenerator.h.

Referenced by mySeed(), and setSeed().