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

edm::RandomEngineStates::RandomEngineStates ( )

Definition at line 10 of file RandomEngineStates.cc.

10  {
11  }
edm::RandomEngineStates::~RandomEngineStates ( )

Definition at line 13 of file RandomEngineStates.cc.

13  {
14  }

Member Function Documentation

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

Definition at line 17 of file RandomEngineStates.cc.

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

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

Definition at line 143 of file RandomEngineStates.cc.

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

143  {
144  if (moduleLabels_ == randomEngineStates.moduleLabels_ &&
145  seedLengths_ == randomEngineStates.seedLengths_ &&
146  seedVectors_ == randomEngineStates.seedVectors_ &&
147  stateLengths_ == randomEngineStates.stateLengths_ &&
148  stateVectors_ == randomEngineStates.stateVectors_) {
149  return true;
150  }
151  return false;
152  }
std::vector< unsigned > seedLengths_
std::vector< unsigned > seedVectors_
std::vector< std::string > moduleLabels_
std::vector< unsigned > stateLengths_
std::vector< unsigned > stateVectors_
void edm::RandomEngineStates::setRandomEngineStates ( std::vector< RandomEngineState > const &  states)

Definition at line 103 of file RandomEngineStates.cc.

References diffTwoXMLs::label, moduleLabels_, seedLengths_, seedVectors_, stateLengths_, and stateVectors_.

103  {
104 
105  moduleLabels_.resize(states.size());
106  seedLengths_.resize(states.size());
107  seedVectors_.clear();
108  stateLengths_.resize(states.size());
109  stateVectors_.clear();
110 
111  std::vector<std::string>::iterator label = moduleLabels_.begin();
112  std::vector<unsigned>::iterator seedLength = seedLengths_.begin();
113  std::vector<unsigned>::iterator stateLength = stateLengths_.begin();
114 
115 
116  for (std::vector<RandomEngineState>::const_iterator state = states.begin(),
117  iEnd = states.end();
118  state != iEnd; ++state, ++label, ++seedLength, ++stateLength) {
119 
120  *label = state->getLabel();
121 
122  std::vector<uint32_t> const& seedVector = state->getSeed();
123  *seedLength = seedVector.size();
124 
125  for (std::vector<uint32_t>::const_iterator j = seedVector.begin(),
126  jEnd = seedVector.end();
127  j != jEnd; ++j) {
128  seedVectors_.push_back(*j);
129  }
130 
131  std::vector<uint32_t> const& stateVector = state->getState();
132  *stateLength = stateVector.size();
133 
134  for (std::vector<uint32_t>::const_iterator j = stateVector.begin(),
135  jEnd = stateVector.end();
136  j != jEnd; ++j) {
137  stateVectors_.push_back(*j);
138  }
139  }
140  }
std::vector< unsigned > seedLengths_
std::vector< unsigned > seedVectors_
std::vector< std::string > moduleLabels_
std::vector< unsigned > stateLengths_
std::vector< unsigned > stateVectors_

Member Data Documentation

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