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();
303 CLHEP::HepRandomEngine& existingEngine =
getEngine(lumiIndex);
305 std::vector<unsigned long> stateL = existingEngine.put();
306 long seedL = existingEngine.getSeed();
307 std::unique_ptr<CLHEP::HepRandomEngine> newEngine;
308 if (stateL[0] == CLHEP::engineIDulong<CLHEP::HepJamesRandom>()) {
309 newEngine = std::make_unique<CLHEP::HepJamesRandom>(seedL);
310 }
else if (stateL[0] == CLHEP::engineIDulong<CLHEP::RanecuEngine>()) {
311 newEngine = std::make_unique<CLHEP::RanecuEngine>();
312 }
else if (stateL[0] == CLHEP::engineIDulong<CLHEP::MixMaxRng>()) {
313 newEngine = std::make_unique<CLHEP::MixMaxRng>(seedL);
314 }
else if (stateL[0] == CLHEP::engineIDulong<TRandomAdaptor>()) {
315 newEngine = std::make_unique<TRandomAdaptor>(seedL);
320 newEngine->get(stateL);
336 <<
"RandomNumberGeneratorService::getEngine()\n" 337 "Requested a random number engine from the RandomNumberGeneratorService\n" 338 "from an unallowed transition. ModuleCallingContext is null\n";
343 std::map<std::string, SeedsAndName>::const_iterator iter =
seedsAndNameMap_.find(label);
346 <<
"The module with label \"" 348 <<
"\" requested a random number seed from the \n" 349 "RandomNumberGeneratorService, but that module was not configured\n" 350 "for random numbers. An engine is created only if a seed(s) is provided\n" 351 "in the configuration file. Please add the following PSet to the\n" 352 "configuration file for the RandomNumberGeneratorService:\n\n" 353 " " << label <<
" = cms.PSet(\n" 354 " initialSeed = cms.untracked.uint32(your_seed),\n" 355 " engineName = cms.untracked.string('TRandom3')\n" 357 "where you replace \"your_seed\" with a number and add a comma if necessary\n" 358 "The \"engineName\" parameter is optional. If absent the default is \"HepJamesRandom\".\n";
360 return iter->second.seeds()[0];
380 val.addOptionalUntracked<std::uint32_t>(
"initialSeed");
381 val.addOptionalUntracked<std::vector<std::uint32_t> >(
"initialSeedSet");
382 val.addOptionalUntracked<
std::string>(
"engineName");
385 wnode.setComment(
"The name of each ParameterSet will be the associated module label.");
388 descriptions.
add(
"RandomNumberGeneratorService", desc);
395 iter->second.setModuleID(description.
id());
406 <<
"Configuration is illegal. The RandomNumberGeneratorService is configured\n" 407 <<
"to run replay using a text file to input the random engine states and\n" 408 <<
"the number of streams is greater than 1. Either set the\n" 409 <<
"parameter named \"restoreFileName\" in the RandomNumberGeneratorService\n" 410 <<
"to the empty string or set the parameter \"numberOfStreams\" in the top\n" 411 <<
"level options parameter set to 1. (Probably these are the default values\n" 412 <<
"and just not setting the parameters will also work)\n";
424 for(
unsigned int iStream = 0; iStream <
nStreams_; ++iStream) {
425 unsigned int seedOffset = iStream;
428 outFiles_[iStream] = std::make_shared<std::ofstream>();
431 for(
unsigned int iLumi = 0; iLumi < nConcurrentLumis; ++iLumi) {
484 bool expected =
false;
488 reportSvc->reportRandomStateFile(fullName);
566 std::vector<RandomEngineState>
const&
571 std::vector<RandomEngineState>
const&
579 os <<
"\n\nRandomNumberGeneratorService dump\n\n";
581 os <<
" Contents of seedsAndNameMap (label moduleID engineType seeds)\n";
583 os <<
" " <<
entry.first
584 <<
" " <<
entry.second.moduleID()
585 <<
" " <<
entry.second.engineName();
586 for(
auto val :
entry.second.seeds()) {
591 os <<
" nStreams_ = " <<
nStreams_ <<
"\n";
597 os <<
" verbose_ = " <<
verbose_ <<
"\n";
601 os <<
"\n streamEngines_\n";
602 unsigned int iStream = 0;
604 os <<
" Stream " << iStream <<
"\n";
605 for(
auto const&
i :
k) {
606 os <<
" " <<
i.label();
607 for(
auto const& j :
i.seeds()) {
610 os <<
" " <<
i.engine()->name();
611 if(
i.engine()->name() ==
std::string(
"HepJamesRandom")) {
612 os <<
" " <<
i.engine()->getSeed();
613 }
else if(
i.engine()->name() ==
std::string(
"MixMaxRng")) {
614 os <<
" " <<
i.engine()->getSeed();
616 os <<
" engine does not know seeds";
622 os <<
"\n lumiEngines_\n";
623 unsigned int iLumi = 0;
625 os <<
" lumiIndex " << iLumi <<
"\n";
626 for(
auto const&
i :
k) {
627 os <<
" " <<
i.label();
628 for(
auto const& j :
i.seeds()) {
631 os <<
" " <<
i.engine()->name();
632 if(
i.engine()->name() ==
std::string(
"HepJamesRandom")) {
633 os <<
" " <<
i.engine()->getSeed();
634 }
else if(
i.engine()->name() ==
std::string(
"MixMaxRng")) {
635 os <<
" " <<
i.engine()->getSeed();
637 os <<
" engine does not know seeds";
651 std::vector<ModuleIDToEngine>::iterator iter =
std::lower_bound(moduleIDVector.begin(),
652 moduleIDVector.end(),
654 if(iter != moduleIDVector.end() && iter->moduleID() == moduleID) {
656 iter->setEngineState(labelAndEngine->
engine()->put());
667 std::vector<ModuleIDToEngine>::iterator iter =
std::lower_bound(moduleIDVector.begin(),
668 moduleIDVector.end(),
670 if(iter != moduleIDVector.end() && iter->moduleID() == moduleID) {
672 if(iter->engineState() != labelAndEngine->
engine()->put()) {
674 <<
"It is illegal to generate random numbers during beginStream, endStream,\n" 675 "beginRun, endRun, beginLumi, endLumi because that makes it very difficult\n" 676 "to replay the processing of individual events. Random numbers were\n" 677 "generated during one of these methods for the module with class name\n\"" 692 <<
"In the configuration for the RandomNumberGeneratorService the\n" 693 <<
"restoreStateTag contains the current process which is illegal.\n" 694 <<
"The process name in the replay process should have been changed\n" 695 <<
"to be different than the original process name and the restoreStateTag\n" 696 <<
"should contain either the original process name or an empty process name.\n";
705 <<
"The RandomNumberGeneratorService is trying to restore\n" 706 <<
"the state of the random engines by reading a product from\n" 708 <<
"It could not find the product.\n" 709 <<
"Either the product in the LuminosityBlock was dropped or\n" 710 <<
"not produced or the configured input tag is incorrect or there is a bug somewhere\n";
725 <<
"The RandomNumberGeneratorService is trying to restore\n" 726 <<
"the state of the random engines by reading a product from\n" 728 <<
"It could not find the product.\n" 729 <<
"Either the product in the Event was dropped or\n" 730 <<
"not produced or the configured input tag is incorrect or there is a bug somewhere\n";
738 cache.resize(engines.size());
739 std::vector<RandomEngineState>::iterator state = cache.begin();
741 for(std::vector<LabelAndEngine>::const_iterator iter = engines.begin();
742 iter != engines.end();
746 state->setLabel(label);
747 state->setSeed(iter->seeds());
749 std::vector<unsigned long> stateL = iter->engine()->put();
750 state->clearStateVector();
751 state->reserveStateVector(stateL.size());
752 for(
auto element : stateL) {
753 state->push_back_stateVector(static_cast<std::uint32_t>(element));
760 std::vector<LabelAndEngine>& engines) {
761 std::vector<LabelAndEngine>::iterator labelAndEngine = engines.begin();
762 for(
auto const& cachedState : cache) {
764 std::string const& engineLabel = cachedState.getLabel();
766 std::vector<std::uint32_t>
const& engineState = cachedState.getState();
767 std::vector<unsigned long> engineStateL;
768 engineStateL.reserve(engineState.size());
769 for(
auto const&
value : engineState) {
770 engineStateL.push_back(static_cast<unsigned long>(
value));
773 std::vector<std::uint32_t>
const& engineSeeds = cachedState.getSeed();
774 std::vector<long> engineSeedsL;
775 engineSeedsL.reserve(engineSeeds.size());
776 for(
auto const&
val : engineSeeds) {
777 long seedL =
static_cast<long>(
val);
778 engineSeedsL.push_back(seedL);
787 std::uint32_t seedu32 =
static_cast<std::uint32_t
>(seedL);
788 assert(
val == seedu32);
791 assert(labelAndEngine != engines.end() && engineLabel == labelAndEngine->label());
792 std::shared_ptr<CLHEP::HepRandomEngine>
const& engine = labelAndEngine->engine();
796 if(engineStateL[0] == CLHEP::engineIDulong<CLHEP::HepJamesRandom>()) {
801 engine->setSeed(engineSeedsL[0], 0);
802 engine->get(engineStateL);
804 labelAndEngine->setSeed(engineSeeds[0], 0);
805 }
else if(engineStateL[0] == CLHEP::engineIDulong<CLHEP::RanecuEngine>()) {
810 engine->get(engineStateL);
812 labelAndEngine->setSeed(engineSeeds[0], 0);
813 labelAndEngine->setSeed(engineSeeds[1], 1);
814 }
else if(engineStateL[0] == CLHEP::engineIDulong<CLHEP::MixMaxRng>()) {
819 engine->setSeed(engineSeedsL[0], 0);
820 engine->get(engineStateL);
822 labelAndEngine->setSeed(engineSeeds[0], 0);
823 }
else if(engineStateL[0] == CLHEP::engineIDulong<TRandomAdaptor>()) {
828 engine->setSeed(engineSeedsL[0], 0);
829 engine->get(engineStateL);
831 labelAndEngine->setSeed(engineSeeds[0], 0);
836 <<
"The RandomNumberGeneratorService is trying to restore the state\n" 837 "of the random engines. The state in the event indicates an engine\n" 838 "of an unknown type. This should not be possible unless you are\n" 839 "running with an old code release on a new file that was created\n" 840 "with a newer release which had new engine types added. In this case\n" 841 "the only solution is to use a newer release. In any other case, notify\n" 842 "the EDM developers because this should not be possible\n";
852 if(typeFromConfig != typeFromEvent) {
854 <<
"The RandomNumberGeneratorService is trying to restore\n" 855 <<
"the state of the random engine for the module \"" 856 << engineLabel <<
"\". An\n" 857 <<
"error was detected because the type of the engine in the\n" 858 <<
"input file and the configuration file do not match.\n" 859 <<
"In the configuration file the type is \"" << typeFromConfig
860 <<
"\".\nIn the input file the type is \"" << typeFromEvent <<
"\". If\n" 861 <<
"you are not generating any random numbers in this module, then\n" 862 <<
"remove the line in the configuration file that gives it\n" 863 <<
"a seed and the error will go away. Otherwise, you must give\n" 864 <<
"this module the same engine type in the configuration file or\n" 865 <<
"stop trying to restore the random engine state.\n";
876 if(!outFile.is_open()) {
877 std::stringstream
file;
880 file <<
"_" << streamID.
value();
887 <<
"Unable to open the file \"" 888 << file.str() <<
"\" to save the state of the random engines.\n";
892 outFile.seekp(0, std::ios_base::beg);
893 outFile <<
"<RandomEngineStates>\n";
895 outFile <<
"<Event>\n";
897 outFile <<
"</Event>\n";
899 outFile <<
"<Lumi>\n";
901 outFile <<
"</Lumi>\n";
903 outFile <<
"</RandomEngineStates>\n";
910 for(
auto & state : v) {
911 std::vector<std::uint32_t>
const& seedVector = state.getSeed();
914 std::vector<std::uint32_t>
const& stateVector = state.getState();
917 outFile <<
"<ModuleLabel>\n" << state.getLabel() <<
"\n</ModuleLabel>\n";
919 outFile <<
"<SeedLength>\n" << seedVectorLength <<
"\n</SeedLength>\n" ;
920 outFile <<
"<InitialSeeds>\n";
922 outFile <<
"</InitialSeeds>\n";
923 outFile <<
"<FullStateLength>\n" << stateVectorLength <<
"\n</FullStateLength>\n";
924 outFile <<
"<FullState>\n";
926 outFile <<
"</FullState>\n";
933 if(v.empty())
return;
934 size_t numItems = v.size();
935 for(
size_t i = 0;
i < numItems; ++
i) {
936 if(
i != 0 &&
i % 10 == 0) outFile <<
"\n";
937 outFile << std::setw(13) << v[
i];
944 std::string fullName(getcwd(directory,
sizeof(directory)) ? directory :
"/PathIsTooBig");
951 std::vector<RandomEngineState>&
cache) {
958 std::vector<RandomEngineState>&
cache) {
966 std::vector<RandomEngineState>&
cache,
968 std::ifstream inFile;
972 <<
"Unable to open the file \"" 973 << fileName <<
"\" to restore the random engine states.\n";
978 if(!inFile.good() || text !=
std::string(
"<RandomEngineStates>")) {
980 <<
"Attempting to read file with random number engine states.\n" 982 <<
"\" is ill-structured or otherwise corrupted.\n" 983 <<
"Cannot read the file header word.\n";
985 bool saveToCache =
false;
990 std::vector<RandomEngineState>&
cache,
997 std::vector<std::uint32_t> seedVector;
999 std::vector<std::uint32_t> stateVector;
1009 <<
"\" is ill-structured or otherwise corrupted.\n" 1010 <<
"Cannot read next field and did not hit the end yet.\n";
1014 if(leading ==
std::string(
"</RandomEngineStates>"))
return false;
1019 saveToCache =
false;
1026 saveToCache = (leading == whichStates);
1032 is >> moduleLabel >> trailing;
1038 <<
"\" is ill-structured or otherwise corrupted.\n" 1039 <<
"Cannot read a module label when restoring random engine states.\n";
1042 is >> leading >> seedVectorSize >> trailing;
1048 <<
"\" is ill-structured or otherwise corrupted.\n" 1049 <<
"Cannot read seed vector length when restoring random engine states.\n";
1057 <<
"\" is ill-structured or otherwise corrupted.\n" 1058 <<
"Cannot read beginning of InitialSeeds when restoring random engine states.\n";
1064 <<
"\" is ill-structured or otherwise corrupted.\n" 1065 <<
"The number of seeds exceeds 64K.\n";
1075 <<
"\" is ill-structured or otherwise corrupted.\n" 1076 <<
"Cannot read end of InitialSeeds when restoring random engine states.\n";
1079 is >> leading >> stateVectorSize >> trailing;
1085 <<
"\" is ill-structured or otherwise corrupted.\n" 1086 <<
"Cannot read state vector length when restoring random engine states.\n";
1094 <<
"\" is ill-structured or otherwise corrupted.\n" 1095 <<
"Cannot read beginning of FullState when restoring random engine states.\n";
1101 <<
"\" is ill-structured or otherwise corrupted.\n" 1102 <<
"The number of states exceeds 64K.\n";
1105 readVector(is, stateVectorSize, stateVector);
1112 <<
"\" is ill-structured or otherwise corrupted.\n" 1113 <<
"Cannot read end of FullState when restoring random engine states.\n";
1118 randomEngineState.
setLabel(moduleLabel);
1119 std::vector<RandomEngineState>::iterator state =
1122 if(state != cache.end() && moduleLabel == state->getLabel()) {
1123 if(seedVector.size() != state->getSeed().size() ||
1124 stateVector.size() != state->getState().size()) {
1127 <<
"\" is ill-structured or otherwise corrupted.\n" 1128 <<
"Vectors containing engine state are the incorrect size for the type of random engine.\n";
1130 state->setSeed(seedVector);
1131 state->setState(stateVector);
1140 v.reserve(numItems);
1142 for(
unsigned i = 0;
i < numItems; ++
i) {
1147 <<
"\" is ill-structured or otherwise corrupted.\n" 1148 <<
"Cannot read vector when restoring random engine states.\n";
1156 unsigned int seedOffset,
1157 unsigned int eventSeedOffset,
1158 std::vector<ModuleIDToEngine>& moduleIDVector) {
1165 unsigned int moduleID =
i.second.moduleID();
1169 VUint32 const& seeds =
i.second.seeds();
1171 if(name ==
"RanecuEngine") {
1172 std::shared_ptr<CLHEP::HepRandomEngine> engine = std::make_shared<CLHEP::RanecuEngine>();
1173 engines.emplace_back(label, seeds, engine);
1178 long int seedL =
static_cast<long int>(seeds[0]);
1180 if(name ==
"HepJamesRandom") {
1181 std::shared_ptr<CLHEP::HepRandomEngine> engine = std::make_shared<CLHEP::HepJamesRandom>(seedL);
1182 engines.emplace_back(label, seeds, engine);
1183 if(seedOffset != 0 || eventSeedOffset != 0) {
1186 }
else if(name ==
"MixMaxRng") {
1187 std::shared_ptr<CLHEP::HepRandomEngine> engine = std::make_shared<CLHEP::MixMaxRng>(seedL);
1188 engines.emplace_back(label, seeds, engine);
1189 if(seedOffset != 0 || eventSeedOffset != 0) {
1201 std::uint32_t seedu32 =
static_cast<std::uint32_t
>(seedL);
1202 assert(seeds[0] == seedu32);
1204 std::shared_ptr<CLHEP::HepRandomEngine> engine = std::make_shared<TRandomAdaptor>(seedL);
1205 engines.emplace_back(label, seeds, engine);
1206 if(seedOffset != 0 || eventSeedOffset != 0) {
1211 moduleIDVector.emplace_back(&engines.back(), moduleID);
1214 std::sort(moduleIDVector.begin(), moduleIDVector.end());
1221 std::uint32_t offset1,
1222 std::uint32_t offset2) {
1224 if(engineName ==
"RanecuEngine") {
1225 assert(seeds.size() == 2
U);
1230 std::uint32_t seed0 = (seeds[0] + offset1) % mod;
1231 seed0 = (seed0 + offset2) % mod;
1232 labelAndEngine.
setSeed(seed0, 0);
1233 labelAndEngine.
setSeed(seeds[1], 1);
1235 seedL[0] =
static_cast<long int>(seed0);
1236 seedL[1] =
static_cast<long int>(seeds[1]);
1237 labelAndEngine.
engine()->setSeeds(seedL,0);
1239 assert(seeds.size() == 1
U);
1241 if(engineName ==
"HepJamesRandom" || engineName ==
"MixMaxRng") {
1246 std::uint32_t seed0 = (seeds[0] + offset1) % mod;
1247 seed0 = (seed0 + offset2) % mod;
1248 labelAndEngine.
setSeed(seed0, 0);
1250 long int seedL =
static_cast<long int>(seed0);
1251 labelAndEngine.
engine()->setSeed(seedL, 0);
1253 assert(engineName ==
"TRandom3");
1258 std::uint32_t seed0 = seeds[0];
1259 if((max32 - seed0) >= offset1) {
1262 seed0 = offset1 - (max32 - seed0) - 1
U;
1264 if((max32 - seed0) >= offset2) {
1267 seed0 = offset2 - (max32 - seed0) - 1
U;
1269 labelAndEngine.
setSeed(seed0, 0);
1271 long seedL =
static_cast<long>(seed0);
1280 std::uint32_t seedu32 =
static_cast<std::uint32_t
>(seedL);
1281 assert(seed0 == seedu32);
1283 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)
void setLumiCache(LuminosityBlockIndex, std::vector< RandomEngineState > const &iStates) override
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("")
void setEventCache(StreamID, std::vector< RandomEngineState > const &iStates) override
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
std::unique_ptr< CLHEP::HepRandomEngine > cloneEngine(LuminosityBlockIndex 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)