41 #include "CLHEP/Random/engineIDulong.h" 42 #include "CLHEP/Random/JamesRandom.h" 43 #include "CLHEP/Random/RanecuEngine.h" 44 #include "CLHEP/Random/MixMaxRng.h" 64 saveFileName_(pset.getUntrackedParameter<
std::
string>(
"saveFileName")),
65 saveFileNameRecorded_(
false),
66 restoreFileName_(pset.getUntrackedParameter<
std::
string>(
"restoreFileName")),
67 enableChecking_(pset.getUntrackedParameter<
bool>(
"enableChecking")),
68 eventSeedOffset_(pset.getUntrackedParameter<unsigned>(
"eventSeedOffset")),
69 verbose_(pset.getUntrackedParameter<
bool>(
"verbose")) {
71 if(pset.
exists(
"restoreStateTag")) {
83 <<
"In the configuration for the RandomNumberGeneratorService both\n" 84 <<
"restoreFileName and restoreStateLabel were set to nonempty values\n" 85 <<
"which is illegal. It is impossible to restore the random engine\n" 86 <<
"states two different ways in the same process.\n";
93 <<
"The saveFileName parameter must be a simple file name with no path\n" 94 <<
"specification. In the configuration, it was given the value \"" 103 for(
auto const&
label : pSets) {
108 bool initialSeedExists = modulePSet.
exists(
"initialSeed");
109 bool initialSeedSetExists = modulePSet.
exists(
"initialSeedSet");
111 if(initialSeedExists && initialSeedSetExists) {
113 <<
"For the module with the label \"" <<
label <<
"\",\n" 114 <<
"both the parameters \"initialSeed\" and \"initialSeedSet\"\n" 115 <<
"have been set in the configuration. You must set one or\n" 116 <<
"the other. It is illegal to set both.\n";
117 }
else if(!initialSeedExists && !initialSeedSetExists) {
119 <<
"For the module with the label \"" <<
label <<
"\",\n" 120 <<
"neither the parameter \"initialSeed\" nor \"initialSeedSet\"\n" 121 <<
"has been set in the configuration. You must set one or\n" 123 }
else if(initialSeedExists) {
125 initialSeedSet.clear();
126 initialSeedSet.push_back(initialSeed);
127 }
else if(initialSeedSetExists) {
134 if(initialSeedSet.size() != 2
U) {
136 <<
"Random engines of type \"RanecuEngine\" require 2 seeds\n" 137 <<
"be specified with the parameter named \"initialSeedSet\".\n" 138 <<
"Either \"initialSeedSet\" was not in the configuration\n" 139 <<
"or its size was not 2 for the module with label \"" <<
label <<
"\".\n" ;
144 <<
"The RanecuEngine seeds should be in the range 0 to " <<
maxSeedRanecu <<
".\n" 145 <<
"The seeds passed to the RandomNumberGenerationService from the\n" 146 "configuration file were " << initialSeedSet[0] <<
" and " << initialSeedSet[1]
147 <<
"\nThis was for the module with label \"" <<
label <<
"\".\n";
152 if(initialSeedSet.size() != 1
U) {
154 <<
"Random engines of type \"HepJamesRandom\", \"TRandom3\" and \"MixMaxRng\" \n" 155 <<
"require exactly 1 seed be specified in the configuration.\n" 156 <<
"There were " << initialSeedSet.size() <<
" seeds set for the\n" 157 <<
"module with label \"" <<
label <<
"\".\n" ;
159 if(engineName ==
"HepJamesRandom") {
162 <<
"The CLHEP::HepJamesRandom engine seed should be in the range 0 to " <<
maxSeedHepJames <<
".\n" 163 <<
"The seed passed to the RandomNumberGenerationService from the\n" 164 "configuration file was " << initialSeedSet[0] <<
". This was for \n" 165 <<
"the module with label " <<
label <<
".\n";
167 }
else if(engineName ==
"MixMaxRng") {
170 <<
"The CLHEP::MixMaxRng engine seed should be in the range 0 to " <<
maxSeedTRandom3 <<
".\n" 171 <<
"The seed passed to the RandomNumberGenerationService from the\n" 172 "configuration file was " << initialSeedSet[0] <<
". This was for \n" 173 <<
"the module with label " <<
label <<
".\n";
175 }
else if(engineName ==
"TRandom3") {
178 <<
"The CLHEP::MixMaxRng engine seed should be in the range 0 to " <<
maxSeedTRandom3 <<
".\n" 179 <<
"The seed passed to the RandomNumberGenerationService from the\n" 180 "configuration file was " << initialSeedSet[0] <<
". This was for \n" 181 <<
"the module with label " <<
label <<
".\n";
185 <<
"The random engine name, \"" << engineName
186 <<
"\", does not correspond to a supported engine.\n" 187 <<
"This engine was configured for the module with label \"" <<
label <<
"\"";
227 CLHEP::HepRandomEngine&
233 <<
"RandomNumberGeneratorService::getEngine\n" 234 "Requested a random number engine from the RandomNumberGeneratorService\n" 235 "when no module was active. ModuleCallingContext is null\n";
241 std::vector<ModuleIDToEngine>::iterator iter = std::lower_bound(moduleIDVector.begin(),
242 moduleIDVector.end(),
244 if(iter == moduleIDVector.end() || iter->moduleID() != moduleID) {
246 <<
"The module with label \"" 248 <<
"\" requested a random number engine from the \n" 249 "RandomNumberGeneratorService, but that module was not configured\n" 250 "for random numbers. An engine is created only if a seed(s) is provided\n" 251 "in the configuration file. Please add the following PSet to the\n" 252 "configuration file for the RandomNumberGeneratorService:\n\n" 254 " initialSeed = cms.untracked.uint32(your_seed),\n" 255 " engineName = cms.untracked.string('TRandom3')\n" 257 "where you replace \"your_seed\" with a number and add a comma if necessary\n" 258 "The \"engineName\" parameter is optional. If absent the default is \"HepJamesRandom\".\n";
261 return *iter->labelAndEngine()->engine();
264 CLHEP::HepRandomEngine&
270 <<
"RandomNumberGeneratorService::getEngine\n" 271 "Requested a random number engine from the RandomNumberGeneratorService\n" 272 "when no module was active. ModuleCallingContext is null\n";
278 std::vector<ModuleIDToEngine>::iterator iter = std::lower_bound(moduleIDVector.begin(),
279 moduleIDVector.end(),
281 if(iter == moduleIDVector.end() || iter->moduleID() != moduleID) {
283 <<
"The module with label \"" 285 <<
"\" requested a random number engine from the \n" 286 "RandomNumberGeneratorService, but that module was not configured\n" 287 "for random numbers. An engine is created only if a seed(s) is provided\n" 288 "in the configuration file. Please add the following PSet to the\n" 289 "configuration file for the RandomNumberGeneratorService:\n\n" 291 " initialSeed = cms.untracked.uint32(your_seed),\n" 292 " engineName = cms.untracked.string('TRandom3')\n" 294 "where you replace \"your_seed\" with a number and add a comma if necessary\n" 295 "The \"engineName\" parameter is optional. If absent the default is \"HepJamesRandom\".\n";
298 return *iter->labelAndEngine()->engine();
313 <<
"RandomNumberGeneratorService::getEngine()\n" 314 "Requested a random number engine from the RandomNumberGeneratorService\n" 315 "from an unallowed transition. ModuleCallingContext is null\n";
320 std::map<std::string, SeedsAndName>::const_iterator iter =
seedsAndNameMap_.find(label);
323 <<
"The module with label \"" 325 <<
"\" requested a random number seed from the \n" 326 "RandomNumberGeneratorService, but that module was not configured\n" 327 "for random numbers. An engine is created only if a seed(s) is provided\n" 328 "in the configuration file. Please add the following PSet to the\n" 329 "configuration file for the RandomNumberGeneratorService:\n\n" 330 " " << label <<
" = cms.PSet(\n" 331 " initialSeed = cms.untracked.uint32(your_seed),\n" 332 " engineName = cms.untracked.string('TRandom3')\n" 334 "where you replace \"your_seed\" with a number and add a comma if necessary\n" 335 "The \"engineName\" parameter is optional. If absent the default is \"HepJamesRandom\".\n";
337 return iter->second.seeds()[0];
357 val.addOptionalUntracked<std::uint32_t>(
"initialSeed");
358 val.addOptionalUntracked<std::vector<std::uint32_t> >(
"initialSeedSet");
359 val.addOptionalUntracked<
std::string>(
"engineName");
362 wnode.setComment(
"The name of each ParameterSet will be the associated module label.");
365 descriptions.
add(
"RandomNumberGeneratorService", desc);
372 iter->second.setModuleID(description.
id());
383 <<
"Configuration is illegal. The RandomNumberGeneratorService is configured\n" 384 <<
"to run replay using a text file to input the random engine states and\n" 385 <<
"the number of streams is greater than 1. Either set the\n" 386 <<
"parameter named \"restoreFileName\" in the RandomNumberGeneratorService\n" 387 <<
"to the empty string or set the parameter \"numberOfStreams\" in the top\n" 388 <<
"level options parameter set to 1. (Probably these are the default values\n" 389 <<
"and just not setting the parameters will also work)\n";
401 for(
unsigned int iStream = 0; iStream <
nStreams_; ++iStream) {
402 unsigned int seedOffset = iStream;
405 outFiles_[iStream] = std::make_shared<std::ofstream>();
408 for(
unsigned int iLumi = 0; iLumi < nConcurrentLumis; ++iLumi) {
461 bool expected =
false;
465 reportSvc->reportRandomStateFile(fullName);
530 std::vector<RandomEngineState>
const&
535 std::vector<RandomEngineState>
const&
543 os <<
"\n\nRandomNumberGeneratorService dump\n\n";
545 os <<
" Contents of seedsAndNameMap (label moduleID engineType seeds)\n";
547 os <<
" " <<
entry.first
548 <<
" " <<
entry.second.moduleID()
549 <<
" " <<
entry.second.engineName();
550 for(
auto val :
entry.second.seeds()) {
555 os <<
" nStreams_ = " <<
nStreams_ <<
"\n";
561 os <<
" verbose_ = " <<
verbose_ <<
"\n";
565 os <<
"\n streamEngines_\n";
566 unsigned int iStream = 0;
568 os <<
" Stream " << iStream <<
"\n";
569 for(
auto const&
i :
k) {
570 os <<
" " <<
i.label();
571 for(
auto const& j :
i.seeds()) {
574 os <<
" " <<
i.engine()->name();
575 if(
i.engine()->name() ==
std::string(
"HepJamesRandom")) {
576 os <<
" " <<
i.engine()->getSeed();
577 }
else if(
i.engine()->name() ==
std::string(
"MixMaxRng")) {
578 os <<
" " <<
i.engine()->getSeed();
580 os <<
" engine does not know seeds";
586 os <<
"\n lumiEngines_\n";
587 unsigned int iLumi = 0;
589 os <<
" lumiIndex " << iLumi <<
"\n";
590 for(
auto const&
i :
k) {
591 os <<
" " <<
i.label();
592 for(
auto const& j :
i.seeds()) {
595 os <<
" " <<
i.engine()->name();
596 if(
i.engine()->name() ==
std::string(
"HepJamesRandom")) {
597 os <<
" " <<
i.engine()->getSeed();
598 }
else if(
i.engine()->name() ==
std::string(
"MixMaxRng")) {
599 os <<
" " <<
i.engine()->getSeed();
601 os <<
" engine does not know seeds";
615 std::vector<ModuleIDToEngine>::iterator iter = std::lower_bound(moduleIDVector.begin(),
616 moduleIDVector.end(),
618 if(iter != moduleIDVector.end() && iter->moduleID() == moduleID) {
620 iter->setEngineState(labelAndEngine->
engine()->put());
631 std::vector<ModuleIDToEngine>::iterator iter = std::lower_bound(moduleIDVector.begin(),
632 moduleIDVector.end(),
634 if(iter != moduleIDVector.end() && iter->moduleID() == moduleID) {
636 if(iter->engineState() != labelAndEngine->
engine()->put()) {
638 <<
"It is illegal to generate random numbers during beginStream, endStream,\n" 639 "beginRun, endRun, beginLumi, endLumi because that makes it very difficult\n" 640 "to replay the processing of individual events. Random numbers were\n" 641 "generated during one of these methods for the module with class name\n\"" 656 <<
"In the configuration for the RandomNumberGeneratorService the\n" 657 <<
"restoreStateTag contains the current process which is illegal.\n" 658 <<
"The process name in the replay process should have been changed\n" 659 <<
"to be different than the original process name and the restoreStateTag\n" 660 <<
"should contain either the original process name or an empty process name.\n";
669 <<
"The RandomNumberGeneratorService is trying to restore\n" 670 <<
"the state of the random engines by reading a product from\n" 672 <<
"It could not find the product.\n" 673 <<
"Either the product in the LuminosityBlock was dropped or\n" 674 <<
"not produced or the configured input tag is incorrect or there is a bug somewhere\n";
689 <<
"The RandomNumberGeneratorService is trying to restore\n" 690 <<
"the state of the random engines by reading a product from\n" 692 <<
"It could not find the product.\n" 693 <<
"Either the product in the Event was dropped or\n" 694 <<
"not produced or the configured input tag is incorrect or there is a bug somewhere\n";
702 cache.resize(engines.size());
703 std::vector<RandomEngineState>::iterator state = cache.begin();
705 for(std::vector<LabelAndEngine>::const_iterator iter = engines.begin();
706 iter != engines.end();
710 state->setLabel(label);
711 state->setSeed(iter->seeds());
713 std::vector<unsigned long> stateL = iter->engine()->put();
714 state->clearStateVector();
715 state->reserveStateVector(stateL.size());
716 for(
auto element : stateL) {
717 state->push_back_stateVector(static_cast<std::uint32_t>(element));
724 std::vector<LabelAndEngine>& engines) {
725 std::vector<LabelAndEngine>::iterator labelAndEngine = engines.begin();
726 for(
auto const& cachedState : cache) {
728 std::string const& engineLabel = cachedState.getLabel();
730 std::vector<std::uint32_t>
const& engineState = cachedState.getState();
731 std::vector<unsigned long> engineStateL;
732 engineStateL.reserve(engineState.size());
733 for(
auto const&
value : engineState) {
734 engineStateL.push_back(static_cast<unsigned long>(
value));
737 std::vector<std::uint32_t>
const& engineSeeds = cachedState.getSeed();
738 std::vector<long> engineSeedsL;
739 engineSeedsL.reserve(engineSeeds.size());
740 for(
auto const&
val : engineSeeds) {
741 long seedL =
static_cast<long>(
val);
742 engineSeedsL.push_back(seedL);
751 std::uint32_t seedu32 =
static_cast<std::uint32_t
>(seedL);
752 assert(
val == seedu32);
755 assert(labelAndEngine != engines.end() && engineLabel == labelAndEngine->label());
756 std::shared_ptr<CLHEP::HepRandomEngine>
const& engine = labelAndEngine->engine();
760 if(engineStateL[0] == CLHEP::engineIDulong<CLHEP::HepJamesRandom>()) {
765 engine->setSeed(engineSeedsL[0], 0);
766 engine->get(engineStateL);
768 labelAndEngine->setSeed(engineSeeds[0], 0);
769 }
else if(engineStateL[0] == CLHEP::engineIDulong<CLHEP::RanecuEngine>()) {
774 engine->get(engineStateL);
776 labelAndEngine->setSeed(engineSeeds[0], 0);
777 labelAndEngine->setSeed(engineSeeds[1], 1);
778 }
else if(engineStateL[0] == CLHEP::engineIDulong<CLHEP::MixMaxRng>()) {
783 engine->setSeed(engineSeedsL[0], 0);
784 engine->get(engineStateL);
786 labelAndEngine->setSeed(engineSeeds[0], 0);
787 }
else if(engineStateL[0] == CLHEP::engineIDulong<TRandomAdaptor>()) {
792 engine->setSeed(engineSeedsL[0], 0);
793 engine->get(engineStateL);
795 labelAndEngine->setSeed(engineSeeds[0], 0);
800 <<
"The RandomNumberGeneratorService is trying to restore the state\n" 801 "of the random engines. The state in the event indicates an engine\n" 802 "of an unknown type. This should not be possible unless you are\n" 803 "running with an old code release on a new file that was created\n" 804 "with a newer release which had new engine types added. In this case\n" 805 "the only solution is to use a newer release. In any other case, notify\n" 806 "the EDM developers because this should not be possible\n";
816 if(typeFromConfig != typeFromEvent) {
818 <<
"The RandomNumberGeneratorService is trying to restore\n" 819 <<
"the state of the random engine for the module \"" 820 << engineLabel <<
"\". An\n" 821 <<
"error was detected because the type of the engine in the\n" 822 <<
"input file and the configuration file do not match.\n" 823 <<
"In the configuration file the type is \"" << typeFromConfig
824 <<
"\".\nIn the input file the type is \"" << typeFromEvent <<
"\". If\n" 825 <<
"you are not generating any random numbers in this module, then\n" 826 <<
"remove the line in the configuration file that gives it\n" 827 <<
"a seed and the error will go away. Otherwise, you must give\n" 828 <<
"this module the same engine type in the configuration file or\n" 829 <<
"stop trying to restore the random engine state.\n";
840 if(!outFile.is_open()) {
841 std::stringstream
file;
844 file <<
"_" << streamID.
value();
851 <<
"Unable to open the file \"" 852 << file.str() <<
"\" to save the state of the random engines.\n";
856 outFile.seekp(0, std::ios_base::beg);
857 outFile <<
"<RandomEngineStates>\n";
859 outFile <<
"<Event>\n";
861 outFile <<
"</Event>\n";
863 outFile <<
"<Lumi>\n";
865 outFile <<
"</Lumi>\n";
867 outFile <<
"</RandomEngineStates>\n";
874 for(
auto & state : v) {
875 std::vector<std::uint32_t>
const& seedVector = state.getSeed();
878 std::vector<std::uint32_t>
const& stateVector = state.getState();
881 outFile <<
"<ModuleLabel>\n" << state.getLabel() <<
"\n</ModuleLabel>\n";
883 outFile <<
"<SeedLength>\n" << seedVectorLength <<
"\n</SeedLength>\n" ;
884 outFile <<
"<InitialSeeds>\n";
886 outFile <<
"</InitialSeeds>\n";
887 outFile <<
"<FullStateLength>\n" << stateVectorLength <<
"\n</FullStateLength>\n";
888 outFile <<
"<FullState>\n";
890 outFile <<
"</FullState>\n";
897 if(v.empty())
return;
898 size_t numItems = v.size();
899 for(
size_t i = 0;
i < numItems; ++
i) {
900 if(
i != 0 &&
i % 10 == 0) outFile <<
"\n";
901 outFile << std::setw(13) << v[
i];
908 std::string fullName(getcwd(directory,
sizeof(directory)) ? directory :
"/PathIsTooBig");
915 std::vector<RandomEngineState>&
cache) {
922 std::vector<RandomEngineState>&
cache) {
930 std::vector<RandomEngineState>&
cache,
932 std::ifstream inFile;
936 <<
"Unable to open the file \"" 937 << fileName <<
"\" to restore the random engine states.\n";
942 if(!inFile.good() || text !=
std::string(
"<RandomEngineStates>")) {
944 <<
"Attempting to read file with random number engine states.\n" 946 <<
"\" is ill-structured or otherwise corrupted.\n" 947 <<
"Cannot read the file header word.\n";
949 bool saveToCache =
false;
954 std::vector<RandomEngineState>&
cache,
961 std::vector<std::uint32_t> seedVector;
963 std::vector<std::uint32_t> stateVector;
973 <<
"\" is ill-structured or otherwise corrupted.\n" 974 <<
"Cannot read next field and did not hit the end yet.\n";
978 if(leading ==
std::string(
"</RandomEngineStates>"))
return false;
990 saveToCache = (leading == whichStates);
996 is >> moduleLabel >> trailing;
1002 <<
"\" is ill-structured or otherwise corrupted.\n" 1003 <<
"Cannot read a module label when restoring random engine states.\n";
1006 is >> leading >> seedVectorSize >> trailing;
1012 <<
"\" is ill-structured or otherwise corrupted.\n" 1013 <<
"Cannot read seed vector length when restoring random engine states.\n";
1021 <<
"\" is ill-structured or otherwise corrupted.\n" 1022 <<
"Cannot read beginning of InitialSeeds when restoring random engine states.\n";
1028 <<
"\" is ill-structured or otherwise corrupted.\n" 1029 <<
"The number of seeds exceeds 64K.\n";
1039 <<
"\" is ill-structured or otherwise corrupted.\n" 1040 <<
"Cannot read end of InitialSeeds when restoring random engine states.\n";
1043 is >> leading >> stateVectorSize >> trailing;
1049 <<
"\" is ill-structured or otherwise corrupted.\n" 1050 <<
"Cannot read state vector length when restoring random engine states.\n";
1058 <<
"\" is ill-structured or otherwise corrupted.\n" 1059 <<
"Cannot read beginning of FullState when restoring random engine states.\n";
1065 <<
"\" is ill-structured or otherwise corrupted.\n" 1066 <<
"The number of states exceeds 64K.\n";
1069 readVector(is, stateVectorSize, stateVector);
1076 <<
"\" is ill-structured or otherwise corrupted.\n" 1077 <<
"Cannot read end of FullState when restoring random engine states.\n";
1082 randomEngineState.
setLabel(moduleLabel);
1083 std::vector<RandomEngineState>::iterator state =
1084 std::lower_bound(cache.begin(), cache.end(), randomEngineState);
1086 if(state != cache.end() && moduleLabel == state->getLabel()) {
1087 if(seedVector.size() != state->getSeed().size() ||
1088 stateVector.size() != state->getState().size()) {
1091 <<
"\" is ill-structured or otherwise corrupted.\n" 1092 <<
"Vectors containing engine state are the incorrect size for the type of random engine.\n";
1094 state->setSeed(seedVector);
1095 state->setState(stateVector);
1104 v.reserve(numItems);
1106 for(
unsigned i = 0;
i < numItems; ++
i) {
1111 <<
"\" is ill-structured or otherwise corrupted.\n" 1112 <<
"Cannot read vector when restoring random engine states.\n";
1120 unsigned int seedOffset,
1121 unsigned int eventSeedOffset,
1122 std::vector<ModuleIDToEngine>& moduleIDVector) {
1129 unsigned int moduleID =
i.second.moduleID();
1133 VUint32 const& seeds =
i.second.seeds();
1135 if(name ==
"RanecuEngine") {
1136 std::shared_ptr<CLHEP::HepRandomEngine> engine = std::make_shared<CLHEP::RanecuEngine>();
1137 engines.emplace_back(label, seeds, engine);
1142 long int seedL =
static_cast<long int>(seeds[0]);
1144 if(name ==
"HepJamesRandom") {
1145 std::shared_ptr<CLHEP::HepRandomEngine> engine = std::make_shared<CLHEP::HepJamesRandom>(seedL);
1146 engines.emplace_back(label, seeds, engine);
1147 if(seedOffset != 0 || eventSeedOffset != 0) {
1150 }
else if(name ==
"MixMaxRng") {
1151 std::shared_ptr<CLHEP::HepRandomEngine> engine = std::make_shared<CLHEP::MixMaxRng>(seedL);
1152 engines.emplace_back(label, seeds, engine);
1153 if(seedOffset != 0 || eventSeedOffset != 0) {
1165 std::uint32_t seedu32 =
static_cast<std::uint32_t
>(seedL);
1166 assert(seeds[0] == seedu32);
1168 std::shared_ptr<CLHEP::HepRandomEngine> engine = std::make_shared<TRandomAdaptor>(seedL);
1169 engines.emplace_back(label, seeds, engine);
1170 if(seedOffset != 0 || eventSeedOffset != 0) {
1175 moduleIDVector.emplace_back(&engines.back(), moduleID);
1178 std::sort(moduleIDVector.begin(), moduleIDVector.end());
1185 std::uint32_t offset1,
1186 std::uint32_t offset2) {
1188 if(engineName ==
"RanecuEngine") {
1189 assert(seeds.size() == 2
U);
1194 std::uint32_t seed0 = (seeds[0] + offset1) % mod;
1195 seed0 = (seed0 + offset2) % mod;
1196 labelAndEngine.
setSeed(seed0, 0);
1197 labelAndEngine.
setSeed(seeds[1], 1);
1199 seedL[0] =
static_cast<long int>(seed0);
1200 seedL[1] =
static_cast<long int>(seeds[1]);
1201 labelAndEngine.
engine()->setSeeds(seedL,0);
1203 assert(seeds.size() == 1
U);
1205 if(engineName ==
"HepJamesRandom" || engineName ==
"MixMaxRng") {
1210 std::uint32_t seed0 = (seeds[0] + offset1) % mod;
1211 seed0 = (seed0 + offset2) % mod;
1212 labelAndEngine.
setSeed(seed0, 0);
1214 long int seedL =
static_cast<long int>(seed0);
1215 labelAndEngine.
engine()->setSeed(seedL, 0);
1217 assert(engineName ==
"TRandom3");
1222 std::uint32_t seed0 = seeds[0];
1223 if((max32 - seed0) >= offset1) {
1226 seed0 = offset1 - (max32 - seed0) - 1
U;
1228 if((max32 - seed0) >= offset2) {
1231 seed0 = offset2 - (max32 - seed0) - 1
U;
1233 labelAndEngine.
setSeed(seed0, 0);
1235 long seedL =
static_cast<long>(seed0);
1244 std::uint32_t seedu32 =
static_cast<std::uint32_t
>(seedL);
1245 assert(seed0 == seedu32);
1247 labelAndEngine.
engine()->setSeed(seedL, 0);
void writeStates(std::vector< RandomEngineState > const &v, std::ofstream &outFile)
T getUntrackedParameter(std::string const &, T const &) const
void preModuleStreamEndLumi(StreamContext const &sc, ModuleCallingContext const &mcc)
void readVector(std::istream &is, unsigned numItems, std::vector< std::uint32_t > &v)
void watchPreallocate(Preallocate::slot_type const &iSlot)
CLHEP::HepRandomEngine & getEngine(StreamID const &streamID) override
Use this engine in event methods.
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static const std::uint32_t maxSeedRanecu
LuminosityBlockIndex index() const
void watchPostModuleEndStream(PostModuleEndStream::slot_type const &iSlot)
void readFromEvent(Event const &event)
std::uint32_t mySeed() const override
void watchPreModuleConstruction(PreModuleConstruction::slot_type const &iSlot)
std::atomic< bool > saveFileNameRecorded_
std::string constructSaveFileName() const
void setLabel(const std::string &value)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
static ModuleCallingContext const * getCurrentModuleOnThread()
std::string const & moduleName() const
std::shared_ptr< CLHEP::HepRandomEngine const > engine() const
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
void preModuleEndStream(StreamContext const &sc, ModuleCallingContext const &mcc)
void watchPostModuleStreamEndLumi(PostModuleStreamEndLumi::slot_type const &iSlot)
void watchPostModuleStreamBeginRun(PostModuleStreamBeginRun::slot_type const &iSlot)
void preModuleConstruction(ModuleDescription const &description)
void postModuleStreamEndRun(StreamContext const &sc, ModuleCallingContext const &mcc)
void postModuleStreamCheck(StreamContext const &sc, ModuleCallingContext const &mcc)
void watchPreModuleBeginStream(PreModuleBeginStream::slot_type const &iSlot)
void resetEngineSeeds(LabelAndEngine &labelAndEngine, std::string const &engineName, VUint32 const &seeds, std::uint32_t offset1, std::uint32_t offset2)
bool getByLabel(std::string const &label, Handle< PROD > &result) const
void readFromLuminosityBlock(LuminosityBlock const &lumi)
std::string const & moduleLabel() const
void preModuleBeginStream(StreamContext const &sc, ModuleCallingContext const &mcc)
edm::InputTag restoreStateTag_
void postModuleStreamBeginRun(StreamContext const &sc, ModuleCallingContext const &mcc)
void setSeed(std::uint32_t v, unsigned int index)
void snapShot(std::vector< LabelAndEngine > const &engines, std::vector< RandomEngineState > &cache)
std::string saveFileName_
void postModuleEndStream(StreamContext const &sc, ModuleCallingContext const &mcc)
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
unsigned int maxNumberOfStreams() const
std::vector< std::vector< ModuleIDToEngine > > streamModuleIDToEngine_
void saveStatesToFile(std::string const &fileName, StreamID const &streamID, LuminosityBlockIndex const &lumiIndex)
RandomNumberGeneratorService(ParameterSet const &pset, ActivityRegistry &activityRegistry)
void preModuleStreamBeginLumi(StreamContext const &sc, ModuleCallingContext const &mcc)
std::vector< edm::propagate_const< std::shared_ptr< std::ofstream > > > outFiles_
~RandomNumberGeneratorService() override
void consumes(ConsumesCollector &&iC) const override
void createEnginesInVector(std::vector< LabelAndEngine > &engines, unsigned int seedOffset, unsigned int eventSeedOffset, std::vector< ModuleIDToEngine > &moduleIDVector)
bool readEngineState(std::istream &is, std::vector< RandomEngineState > &cache, std::string const &whichStates, bool &saveToCache)
void preModuleStreamBeginRun(StreamContext const &sc, ModuleCallingContext const &mcc)
ModuleDescription const * moduleDescription() const
static const std::uint32_t maxSeedTRandom3
std::vector< std::vector< LabelAndEngine > > streamEngines_
std::uint32_t eventSeedOffset_
std::vector< std::vector< RandomEngineState > > eventCache_
unsigned int value() const
void readStatesFromFile(std::string const &fileName, std::vector< RandomEngineState > &cache, std::string const &whichStates)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
void readEventStatesFromTextFile(std::string const &fileName, std::vector< RandomEngineState > &cache)
std::vector< std::vector< RandomEngineState > > lumiCache_
std::vector< RandomEngineState > const & getLumiCache(LuminosityBlockIndex const &) const override
These two are used by the RandomEngineStateProducer.
static const std::vector< std::uint32_t >::size_type maxStates
void watchPostModuleStreamEndRun(PostModuleStreamEndRun::slot_type const &iSlot)
StreamID const & streamID() const
void preModuleStreamEndRun(StreamContext const &sc, ModuleCallingContext const &mcc)
void watchPreModuleStreamBeginLumi(PreModuleStreamBeginLumi::slot_type const &iSlot)
void preallocate(SystemBounds const &)
void watchPostModuleBeginStream(PostModuleBeginStream::slot_type const &iSlot)
std::vector< std::uint32_t > VUint32
unsigned int value() const
unsigned int maxNumberOfConcurrentLuminosityBlocks() const
void watchPostModuleStreamBeginLumi(PostModuleStreamBeginLumi::slot_type const &iSlot)
ParameterSet const & getParameterSet(std::string const &) const
void watchPreModuleStreamEndLumi(PreModuleStreamEndLumi::slot_type const &iSlot)
void checkEngineType(std::string const &typeFromConfig, std::string const &typeFromEvent, std::string const &engineLabel) const
void watchPreModuleStreamBeginRun(PreModuleStreamBeginRun::slot_type const &iSlot)
edm::InputTag restoreStateBeginLumiTag_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void watchPreModuleEndStream(PreModuleEndStream::slot_type const &iSlot)
void postModuleStreamEndLumi(StreamContext const &sc, ModuleCallingContext const &mcc)
static std::string const emptyString("")
char data[epos_bytes_allocation]
void postEventRead(Event const &event) override
void watchPreModuleStreamEndRun(PreModuleStreamEndRun::slot_type const &iSlot)
void writeVector(VUint32 const &v, std::ofstream &outFile)
std::string restoreFileName_
static const std::vector< std::uint32_t >::size_type maxSeeds
StreamID streamID() const
void readLumiStatesFromTextFile(std::string const &fileName, std::vector< RandomEngineState > &cache)
std::vector< RandomEngineState > const & getEventCache(StreamID const &) const override
void restoreFromCache(std::vector< RandomEngineState > const &cache, std::vector< LabelAndEngine > &engines)
std::vector< std::vector< LabelAndEngine > > lumiEngines_
void postModuleBeginStream(StreamContext const &sc, ModuleCallingContext const &mcc)
void print(std::ostream &os) const override
For debugging.
T mod(const T &a, const T &b)
std::map< std::string, SeedsAndName > seedsAndNameMap_
std::vector< std::vector< ModuleIDToEngine > > lumiModuleIDToEngine_
void preModuleStreamCheck(StreamContext const &sc, ModuleCallingContext const &mcc)
static const std::uint32_t maxSeedHepJames
void preBeginLumi(LuminosityBlock const &lumi) override
void postModuleStreamBeginLumi(StreamContext const &sc, ModuleCallingContext const &mcc)