CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
edm::RandomEngineStates Class Reference

#include <RandomEngineStates.h>

Public Member Functions

void getRandomEngineStates (std::vector< RandomEngineState > &states) const
 
bool isProductEqual (RandomEngineStates const &randomEngineStates) const
 
 RandomEngineStates ()
 
void setRandomEngineStates (std::vector< RandomEngineState > const &states)
 
 ~RandomEngineStates ()
 

Private Attributes

std::vector< std::string > moduleLabels_
 
std::vector< unsigned > seedLengths_
 
std::vector< unsigned > seedVectors_
 
std::vector< unsigned > stateLengths_
 
std::vector< unsigned > stateVectors_
 

Detailed Description

Description: Holds the states of multiple random number engines and associated seeds and module labels.

Usage: This should only be used by the Random Number Generator Service.

Author
W. David Dagenhart, created December 3, 2010

Definition at line 23 of file RandomEngineStates.h.

Constructor & Destructor Documentation

◆ RandomEngineStates()

edm::RandomEngineStates::RandomEngineStates ( )

Definition at line 10 of file RandomEngineStates.cc.

10 {}

◆ ~RandomEngineStates()

edm::RandomEngineStates::~RandomEngineStates ( )

Definition at line 12 of file RandomEngineStates.cc.

12 {}

Member Function Documentation

◆ getRandomEngineStates()

void edm::RandomEngineStates::getRandomEngineStates ( std::vector< RandomEngineState > &  states) const

Definition at line 14 of file RandomEngineStates.cc.

14  {
15  // First check for data corruption so that the following code
16  // does not encounter out of range errors.
17  bool corrupt = false;
18 
19  if (moduleLabels_.size() != seedLengths_.size())
20  corrupt = true;
21  if (moduleLabels_.size() != stateLengths_.size())
22  corrupt = true;
23 
24  unsigned int sum = 0U;
25  for (std::vector<unsigned>::const_iterator i = seedLengths_.begin(), iEnd = seedLengths_.end(); i != iEnd; ++i) {
26  sum += *i;
27  }
28  if (sum != seedVectors_.size())
29  corrupt = true;
30 
31  sum = 0U;
32  for (std::vector<unsigned>::const_iterator i = stateLengths_.begin(), iEnd = stateLengths_.end(); i != iEnd; ++i) {
33  sum += *i;
34  }
35  if (sum != stateVectors_.size())
36  corrupt = true;
37 
38  if (corrupt) {
39  throw edm::Exception(errors::EventCorruption) << "RandomEngineStates data is corrupted.\n";
40  }
41 
42  // Done with error checks. Now do the work.
43 
44  std::vector<unsigned>::const_iterator seedLength = seedLengths_.begin();
45  std::vector<unsigned>::const_iterator seedBegin = seedVectors_.begin();
46  std::vector<unsigned>::const_iterator seedEnd = seedVectors_.begin();
47 
48  std::vector<unsigned>::const_iterator stateLength = stateLengths_.begin();
49  std::vector<unsigned>::const_iterator stateBegin = stateVectors_.begin();
50  std::vector<unsigned>::const_iterator stateEnd = stateVectors_.begin();
51 
52  for (std::vector<std::string>::const_iterator label = moduleLabels_.begin(), labelEnd = moduleLabels_.end();
53  label != labelEnd;
54  ++label, ++seedLength, ++stateLength) {
55  seedBegin = seedEnd;
56  seedEnd += *seedLength;
57 
58  stateBegin = stateEnd;
59  stateEnd += *stateLength;
60 
61  RandomEngineState randomEngineState;
62  randomEngineState.setLabel(*label);
63  std::vector<RandomEngineState>::iterator state =
64  std::lower_bound(states.begin(), states.end(), randomEngineState);
65 
66  if (state != states.end() && *label == state->getLabel()) {
67  if (*seedLength != state->getSeed().size() || *stateLength != state->getState().size()) {
69  << "When attempting to replay processing with the RandomNumberGeneratorService,\n"
70  << "the engine type for each module must be the same in the replay configuration\n"
71  << "and the original configuration. If this is not the problem, then the data\n"
72  << "is somehow corrupted or there is a bug because the vector in the data containing\n"
73  << "the seeds or engine state is the incorrect size for the type of random engine.\n";
74  }
75 
76  state->clearSeedVector();
77  state->reserveSeedVector(*seedLength);
78  for (std::vector<unsigned int>::const_iterator i = seedBegin; i != seedEnd; ++i) {
79  state->push_back_seedVector(*i);
80  }
81 
82  state->clearStateVector();
83  state->reserveStateVector(*stateLength);
84  for (std::vector<unsigned int>::const_iterator i = stateBegin; i != stateEnd; ++i) {
85  state->push_back_stateVector(*i);
86  }
87  }
88  }
89  }

References edm::errors::Configuration, edm::errors::EventCorruption, Exception, mps_fire::i, label, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, moduleLabels_, seedLengths_, seedVectors_, RandomEngineState::setLabel(), stateLengths_, stateVectors_, and mitigatedMETSequence_cff::U.

◆ isProductEqual()

bool edm::RandomEngineStates::isProductEqual ( RandomEngineStates const &  randomEngineStates) const

Definition at line 122 of file RandomEngineStates.cc.

122  {
123  if (moduleLabels_ == randomEngineStates.moduleLabels_ && seedLengths_ == randomEngineStates.seedLengths_ &&
124  seedVectors_ == randomEngineStates.seedVectors_ && stateLengths_ == randomEngineStates.stateLengths_ &&
125  stateVectors_ == randomEngineStates.stateVectors_) {
126  return true;
127  }
128  return false;
129  }

References moduleLabels_, seedLengths_, seedVectors_, stateLengths_, and stateVectors_.

◆ setRandomEngineStates()

void edm::RandomEngineStates::setRandomEngineStates ( std::vector< RandomEngineState > const &  states)

Definition at line 91 of file RandomEngineStates.cc.

91  {
92  moduleLabels_.resize(states.size());
93  seedLengths_.resize(states.size());
94  seedVectors_.clear();
95  stateLengths_.resize(states.size());
96  stateVectors_.clear();
97 
98  std::vector<std::string>::iterator label = moduleLabels_.begin();
99  std::vector<unsigned>::iterator seedLength = seedLengths_.begin();
100  std::vector<unsigned>::iterator stateLength = stateLengths_.begin();
101 
102  for (std::vector<RandomEngineState>::const_iterator state = states.begin(), iEnd = states.end(); state != iEnd;
103  ++state, ++label, ++seedLength, ++stateLength) {
104  *label = state->getLabel();
105 
106  std::vector<uint32_t> const& seedVector = state->getSeed();
107  *seedLength = seedVector.size();
108 
109  for (std::vector<uint32_t>::const_iterator j = seedVector.begin(), jEnd = seedVector.end(); j != jEnd; ++j) {
110  seedVectors_.push_back(*j);
111  }
112 
113  std::vector<uint32_t> const& stateVector = state->getState();
114  *stateLength = stateVector.size();
115 
116  for (std::vector<uint32_t>::const_iterator j = stateVector.begin(), jEnd = stateVector.end(); j != jEnd; ++j) {
117  stateVectors_.push_back(*j);
118  }
119  }
120  }

References dqmiolumiharvest::j, label, moduleLabels_, seedLengths_, seedVectors_, stateLengths_, and stateVectors_.

Member Data Documentation

◆ moduleLabels_

std::vector<std::string> edm::RandomEngineStates::moduleLabels_
private

◆ seedLengths_

std::vector<unsigned> edm::RandomEngineStates::seedLengths_
private

◆ seedVectors_

std::vector<unsigned> edm::RandomEngineStates::seedVectors_
private

◆ stateLengths_

std::vector<unsigned> edm::RandomEngineStates::stateLengths_
private

◆ stateVectors_

std::vector<unsigned> edm::RandomEngineStates::stateVectors_
private
mps_fire.i
i
Definition: mps_fire.py:428
edm::RandomEngineStates::seedLengths_
std::vector< unsigned > seedLengths_
Definition: RandomEngineStates.h:36
edm::RandomEngineStates::stateLengths_
std::vector< unsigned > stateLengths_
Definition: RandomEngineStates.h:39
RandomEngineState::setLabel
void setLabel(const std::string &value)
Definition: RandomEngineState.h:36
edm::errors::EventCorruption
Definition: EDMException.h:43
edm::RandomEngineStates::stateVectors_
std::vector< unsigned > stateVectors_
Definition: RandomEngineStates.h:40
RandomEngineState
Definition: RandomEngineState.h:26
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
RunInfoPI::state
state
Definition: RunInfoPayloadInspectoHelper.h:16
edm::RandomEngineStates::seedVectors_
std::vector< unsigned > seedVectors_
Definition: RandomEngineStates.h:37
Exception
Definition: hltDiff.cc:245
edm::RandomEngineStates::moduleLabels_
std::vector< std::string > moduleLabels_
Definition: RandomEngineStates.h:34
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::errors::Configuration
Definition: EDMException.h:36
label
const char * label
Definition: PFTauDecayModeTools.cc:11