CMS 3D CMS Logo

RandomNumberGeneratorService.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RandomEngine
4 // Class : RandomNumberGeneratorService
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones, W. David Dagenhart
10 // Created: Tue Mar 7 09:43:46 EST 2006 (originally in FWCore/Services)
11 //
12 
14 
40 
41 #include "CLHEP/Random/engineIDulong.h"
42 #include "CLHEP/Random/JamesRandom.h"
43 #include "CLHEP/Random/RanecuEngine.h"
44 #include "CLHEP/Random/MixMaxRng.h"
45 
46 #include <algorithm>
47 #include <cassert>
48 #include <ostream>
49 #include <sstream>
50 #include <unistd.h>
51 
52 namespace edm {
53  namespace service {
54 
57  const std::uint32_t RandomNumberGeneratorService::maxSeedRanecu = 2147483647U;
58  const std::uint32_t RandomNumberGeneratorService::maxSeedHepJames = 900000000U;
59  const std::uint32_t RandomNumberGeneratorService::maxSeedTRandom3 = 4294967295U;
60 
62  ActivityRegistry& activityRegistry)
63  : nStreams_(0),
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")) {
70  if (pset.exists("restoreStateTag")) {
71  restoreStateTag_ = pset.getUntrackedParameter<edm::InputTag>("restoreStateTag");
72  if (restoreStateTag_.process().empty()) {
74  }
75  } else {
77  pset.getUntrackedParameter<std::string>("restoreStateLabel"), "", edm::InputTag::kSkipCurrentProcess);
78  }
80 
81  if (!restoreFileName_.empty() && !restoreStateTag_.label().empty()) {
82  throw Exception(errors::Configuration) << "In the configuration for the RandomNumberGeneratorService both\n"
83  << "restoreFileName and restoreStateLabel were set to nonempty values\n"
84  << "which is illegal. It is impossible to restore the random engine\n"
85  << "states two different ways in the same process.\n";
86  }
87 
88  // The saveFileName must correspond to a file name without any path specification.
89  // Throw if that is not true.
90  if (!saveFileName_.empty() && (saveFileName_.find("/") != std::string::npos)) {
92  << "The saveFileName parameter must be a simple file name with no path\n"
93  << "specification. In the configuration, it was given the value \"" << saveFileName_ << "\"\n";
94  }
95 
96  std::uint32_t initialSeed;
99 
100  std::vector<std::string> pSets = pset.getParameterNamesForType<ParameterSet>();
101  for (auto const& label : pSets) {
102  ParameterSet const& modulePSet = pset.getParameterSet(label);
103  engineName = modulePSet.getUntrackedParameter<std::string>("engineName", std::string("HepJamesRandom"));
104 
105  bool initialSeedExists = modulePSet.exists("initialSeed");
106  bool initialSeedSetExists = modulePSet.exists("initialSeedSet");
107 
108  if (initialSeedExists && initialSeedSetExists) {
109  throw Exception(errors::Configuration) << "For the module with the label \"" << label << "\",\n"
110  << "both the parameters \"initialSeed\" and \"initialSeedSet\"\n"
111  << "have been set in the configuration. You must set one or\n"
112  << "the other. It is illegal to set both.\n";
113  } else if (!initialSeedExists && !initialSeedSetExists) {
114  throw Exception(errors::Configuration) << "For the module with the label \"" << label << "\",\n"
115  << "neither the parameter \"initialSeed\" nor \"initialSeedSet\"\n"
116  << "has been set in the configuration. You must set one or\n"
117  << "the other.\n";
118  } else if (initialSeedExists) {
119  initialSeed = modulePSet.getUntrackedParameter<std::uint32_t>("initialSeed");
120  initialSeedSet.clear();
121  initialSeedSet.push_back(initialSeed);
122  } else if (initialSeedSetExists) {
123  initialSeedSet = modulePSet.getUntrackedParameter<VUint32>("initialSeedSet");
124  }
125  seedsAndNameMap_.insert(std::pair<std::string, SeedsAndName>(label, SeedsAndName(initialSeedSet, engineName)));
126 
127  // For the CLHEP::RanecuEngine case, require a seed set containing exactly two seeds.
128  if (engineName == std::string("RanecuEngine")) {
129  if (initialSeedSet.size() != 2U) {
131  << "Random engines of type \"RanecuEngine\" require 2 seeds\n"
132  << "be specified with the parameter named \"initialSeedSet\".\n"
133  << "Either \"initialSeedSet\" was not in the configuration\n"
134  << "or its size was not 2 for the module with label \"" << label << "\".\n";
135  }
136  if (initialSeedSet[0] > maxSeedRanecu ||
137  initialSeedSet[1] > maxSeedRanecu) { // They need to fit in a 31 bit integer
139  << "The RanecuEngine seeds should be in the range 0 to " << maxSeedRanecu << ".\n"
140  << "The seeds passed to the RandomNumberGenerationService from the\n"
141  "configuration file were "
142  << initialSeedSet[0] << " and " << initialSeedSet[1] << "\nThis was for the module with label \""
143  << label << "\".\n";
144  }
145  }
146  // For the other engines, one seed is required
147  else {
148  if (initialSeedSet.size() != 1U) {
150  << "Random engines of type \"HepJamesRandom\", \"TRandom3\" and \"MixMaxRng\" \n"
151  << "require exactly 1 seed be specified in the configuration.\n"
152  << "There were " << initialSeedSet.size() << " seeds set for the\n"
153  << "module with label \"" << label << "\".\n";
154  }
155  if (engineName == "HepJamesRandom") {
156  if (initialSeedSet[0] > maxSeedHepJames) {
158  << "The CLHEP::HepJamesRandom engine seed should be in the range 0 to " << maxSeedHepJames << ".\n"
159  << "The seed passed to the RandomNumberGenerationService from the\n"
160  "configuration file was "
161  << initialSeedSet[0] << ". This was for \n"
162  << "the module with label " << label << ".\n";
163  }
164  } else if (engineName == "MixMaxRng") {
165  if (initialSeedSet[0] > maxSeedTRandom3) {
167  << "The CLHEP::MixMaxRng engine seed should be in the range 0 to " << maxSeedTRandom3 << ".\n"
168  << "The seed passed to the RandomNumberGenerationService from the\n"
169  "configuration file was "
170  << initialSeedSet[0] << ". This was for \n"
171  << "the module with label " << label << ".\n";
172  }
173  } else if (engineName == "TRandom3") {
174  if (initialSeedSet[0] > maxSeedTRandom3) {
176  << "The CLHEP::MixMaxRng engine seed should be in the range 0 to " << maxSeedTRandom3 << ".\n"
177  << "The seed passed to the RandomNumberGenerationService from the\n"
178  "configuration file was "
179  << initialSeedSet[0] << ". This was for \n"
180  << "the module with label " << label << ".\n";
181  }
182  } else {
184  << "The random engine name, \"" << engineName << "\", does not correspond to a supported engine.\n"
185  << "This engine was configured for the module with label \"" << label << "\"";
186  }
187  }
188  }
190 
192 
193  if (enableChecking_) {
196 
199 
202 
205 
208 
211  }
212  }
213 
215 
218  iC.consumes<RandomEngineStates>(restoreStateTag_);
219  }
220 
221  CLHEP::HepRandomEngine& RandomNumberGeneratorService::getEngine(StreamID const& streamID) {
223  if (mcc == nullptr) {
225  << "RandomNumberGeneratorService::getEngine\n"
226  "Requested a random number engine from the RandomNumberGeneratorService\n"
227  "when no module was active. ModuleCallingContext is null\n";
228  }
229  unsigned int moduleID = mcc->moduleDescription()->id();
230 
231  std::vector<ModuleIDToEngine>& moduleIDVector = streamModuleIDToEngine_.at(streamID.value());
232  ModuleIDToEngine target(nullptr, moduleID);
233  std::vector<ModuleIDToEngine>::iterator iter =
234  std::lower_bound(moduleIDVector.begin(), moduleIDVector.end(), target);
235  if (iter == moduleIDVector.end() || iter->moduleID() != moduleID) {
237  << "The module with label \"" << mcc->moduleDescription()->moduleLabel()
238  << "\" requested a random number engine from the \n"
239  "RandomNumberGeneratorService, but that module was not configured\n"
240  "for random numbers. An engine is created only if a seed(s) is provided\n"
241  "in the configuration file. Please add the following PSet to the\n"
242  "configuration file for the RandomNumberGeneratorService:\n\n"
243  " "
244  << mcc->moduleDescription()->moduleLabel()
245  << " = cms.PSet(\n"
246  " initialSeed = cms.untracked.uint32(your_seed),\n"
247  " engineName = cms.untracked.string('TRandom3')\n"
248  " )\n"
249  "where you replace \"your_seed\" with a number and add a comma if necessary\n"
250  "The \"engineName\" parameter is optional. If absent the default is \"HepJamesRandom\".\n";
251  }
252  return *iter->labelAndEngine()->engine();
253  }
254 
257  if (mcc == nullptr) {
259  << "RandomNumberGeneratorService::getEngine\n"
260  "Requested a random number engine from the RandomNumberGeneratorService\n"
261  "when no module was active. ModuleCallingContext is null\n";
262  }
263  unsigned int moduleID = mcc->moduleDescription()->id();
264 
265  std::vector<ModuleIDToEngine>& moduleIDVector = lumiModuleIDToEngine_.at(lumiIndex.value());
266  ModuleIDToEngine target(nullptr, moduleID);
267  std::vector<ModuleIDToEngine>::iterator iter =
268  std::lower_bound(moduleIDVector.begin(), moduleIDVector.end(), target);
269  if (iter == moduleIDVector.end() || iter->moduleID() != moduleID) {
271  << "The module with label \"" << mcc->moduleDescription()->moduleLabel()
272  << "\" requested a random number engine from the \n"
273  "RandomNumberGeneratorService, but that module was not configured\n"
274  "for random numbers. An engine is created only if a seed(s) is provided\n"
275  "in the configuration file. Please add the following PSet to the\n"
276  "configuration file for the RandomNumberGeneratorService:\n\n"
277  " "
278  << mcc->moduleDescription()->moduleLabel()
279  << " = cms.PSet(\n"
280  " initialSeed = cms.untracked.uint32(your_seed),\n"
281  " engineName = cms.untracked.string('TRandom3')\n"
282  " )\n"
283  "where you replace \"your_seed\" with a number and add a comma if necessary\n"
284  "The \"engineName\" parameter is optional. If absent the default is \"HepJamesRandom\".\n";
285  }
286  return *iter->labelAndEngine()->engine();
287  }
288 
289  std::unique_ptr<CLHEP::HepRandomEngine> RandomNumberGeneratorService::cloneEngine(
291  CLHEP::HepRandomEngine& existingEngine = getEngine(lumiIndex);
292 
293  std::vector<unsigned long> stateL = existingEngine.put();
294  long seedL = existingEngine.getSeed();
295  std::unique_ptr<CLHEP::HepRandomEngine> newEngine;
296  if (stateL[0] == CLHEP::engineIDulong<CLHEP::HepJamesRandom>()) {
297  newEngine = std::make_unique<CLHEP::HepJamesRandom>(seedL);
298  } else if (stateL[0] == CLHEP::engineIDulong<CLHEP::RanecuEngine>()) {
299  newEngine = std::make_unique<CLHEP::RanecuEngine>();
300  } else if (stateL[0] == CLHEP::engineIDulong<CLHEP::MixMaxRng>()) {
301  newEngine = std::make_unique<CLHEP::MixMaxRng>(seedL);
302  } else if (stateL[0] == CLHEP::engineIDulong<TRandomAdaptor>()) {
303  newEngine = std::make_unique<TRandomAdaptor>(seedL);
304  } else {
305  // Sanity check, it should not be possible for this to happen.
306  throw Exception(errors::Unknown) << "The RandomNumberGeneratorService is trying to clone unknown engine type\n";
307  }
308  newEngine->get(stateL);
309  return newEngine;
310  }
311 
312  // PROBABLY TO BE DELETED, This returns the configured seed without
313  // any of the modifications for streams or the offset configuration
314  // parameter. Maybe useful to use for debugging/checks, but dangerous if one tries
315  // to create your own engines using it. It is difficult to get the offsets
316  // for streams/forking/offset parameters correct and almost certainly would break
317  // replay.
318  std::uint32_t RandomNumberGeneratorService::mySeed() const {
321  if (mcc == nullptr) {
323  << "RandomNumberGeneratorService::getEngine()\n"
324  "Requested a random number engine from the RandomNumberGeneratorService\n"
325  "from an unallowed transition. ModuleCallingContext is null\n";
326  } else {
327  label = mcc->moduleDescription()->moduleLabel();
328  }
329 
330  std::map<std::string, SeedsAndName>::const_iterator iter = seedsAndNameMap_.find(label);
331  if (iter == seedsAndNameMap_.end()) {
333  << "The module with label \"" << label
334  << "\" requested a random number seed from the \n"
335  "RandomNumberGeneratorService, but that module was not configured\n"
336  "for random numbers. An engine is created only if a seed(s) is provided\n"
337  "in the configuration file. Please add the following PSet to the\n"
338  "configuration file for the RandomNumberGeneratorService:\n\n"
339  " "
340  << label
341  << " = cms.PSet(\n"
342  " initialSeed = cms.untracked.uint32(your_seed),\n"
343  " engineName = cms.untracked.string('TRandom3')\n"
344  " )\n"
345  "where you replace \"your_seed\" with a number and add a comma if necessary\n"
346  "The \"engineName\" parameter is optional. If absent the default is \"HepJamesRandom\".\n";
347  }
348  return iter->second.seeds()[0];
349  }
350 
353 
355  edm::InputTag emptyInputTag("", "", "");
356 
357  desc.addNode(edm::ParameterDescription<edm::InputTag>("restoreStateTag", emptyInputTag, false) xor
358  edm::ParameterDescription<std::string>("restoreStateLabel", emptyString, false));
359 
360  desc.addUntracked<std::string>("saveFileName", emptyString);
361  desc.addUntracked<std::string>("restoreFileName", emptyString);
362  desc.addUntracked<bool>("enableChecking", false);
363  desc.addUntracked<unsigned>("eventSeedOffset", 0U);
364  desc.addUntracked<bool>("verbose", false);
365 
367  val.addOptionalUntracked<std::uint32_t>("initialSeed");
368  val.addOptionalUntracked<std::vector<std::uint32_t> >("initialSeedSet");
369  val.addOptionalUntracked<std::string>("engineName");
370 
372  wnode.setComment("The name of each ParameterSet will be the associated module label.");
373  desc.addNode(wnode);
374 
375  descriptions.add("RandomNumberGeneratorService", desc);
376  }
377 
379  std::map<std::string, SeedsAndName>::iterator iter = seedsAndNameMap_.find(description.moduleLabel());
380  if (iter != seedsAndNameMap_.end()) {
381  iter->second.setModuleID(description.id());
382  }
383  }
384 
387  assert(nStreams_ >= 1);
388  if (!restoreFileName_.empty() && nStreams_ != 1) {
390  << "Configuration is illegal. The RandomNumberGeneratorService is configured\n"
391  << "to run replay using a text file to input the random engine states and\n"
392  << "the number of streams is greater than 1. Either set the\n"
393  << "parameter named \"restoreFileName\" in the RandomNumberGeneratorService\n"
394  << "to the empty string or set the parameter \"numberOfStreams\" in the top\n"
395  << "level options parameter set to 1. (Probably these are the default values\n"
396  << "and just not setting the parameters will also work)\n";
397  }
398  unsigned int nConcurrentLumis = sb.maxNumberOfConcurrentLuminosityBlocks();
399 
401  lumiModuleIDToEngine_.resize(nConcurrentLumis);
402  streamEngines_.resize(nStreams_);
403  lumiEngines_.resize(nConcurrentLumis);
404  eventCache_.resize(nStreams_);
405  lumiCache_.resize(nConcurrentLumis);
406  outFiles_.resize(nStreams_);
407 
408  for (unsigned int iStream = 0; iStream < nStreams_; ++iStream) {
409  unsigned int seedOffset = iStream;
411  if (!saveFileName_.empty()) {
412  outFiles_[iStream] = std::make_shared<std::ofstream>(); // propagate_const<T> has no reset() function
413  }
414  }
415  for (unsigned int iLumi = 0; iLumi < nConcurrentLumis; ++iLumi) {
416  unsigned int seedOffset = nStreams_;
419  if (!restoreFileName_.empty()) {
421  }
422  }
423 
424  if (!restoreFileName_.empty()) {
425  // There is guaranteed to be one stream in this case
429  }
430  if (verbose_) {
431  print(std::cout);
432  }
433  }
434 
436  if (!restoreStateTag_.label().empty()) {
437  // Copy from a product in the LuminosityBlock to cache for a particular luminosityBlockIndex
439  }
440  // Copy from cache to engine the state for a particular luminosityBlockIndex
441  restoreFromCache(lumiCache_[lumi.index()], lumiEngines_[lumi.index()]);
442  }
443 
445  if (!restoreStateTag_.label().empty()) {
446  // This initializes the cache before readFromEvent
447  snapShot(streamEngines_[event.streamID()], eventCache_[event.streamID()]);
448 
449  // copy from Event to event cache
451 
452  // copy from event cache to engines
453  restoreFromCache(eventCache_[event.streamID()], streamEngines_[event.streamID()]);
454 
455  } else {
456  // copy from engines to event cache
457  snapShot(streamEngines_[event.streamID()], eventCache_[event.streamID()]);
458  }
459 
460  // if requested write text file from both caches
461  if (!saveFileName_.empty()) {
462  saveStatesToFile(saveFileName_, event.streamID(), event.getLuminosityBlock().index());
463  bool expected = false;
464  if (saveFileNameRecorded_.compare_exchange_strong(expected, true)) {
466  Service<JobReport> reportSvc;
467  reportSvc->reportRandomStateFile(fullName);
468  }
469  }
470  }
471 
473  std::vector<RandomEngineState> const& iStates) {
474  lumiCache_[iLumi] = iStates;
475  // Copy from cache to engine the state for a particular luminosityBlockIndex
477  }
478  void RandomNumberGeneratorService::setEventCache(StreamID iStream, std::vector<RandomEngineState> const& iStates) {
479  eventCache_[iStream] = iStates;
480  // copy from event cache to engines
481  restoreFromCache(eventCache_[iStream], streamEngines_[iStream]);
482  }
483 
485  preModuleStreamCheck(sc, mcc);
486  }
487 
489  postModuleStreamCheck(sc, mcc);
490  }
491 
493  preModuleStreamCheck(sc, mcc);
494  }
495 
497  postModuleStreamCheck(sc, mcc);
498  }
499 
501  ModuleCallingContext const& mcc) {
502  preModuleStreamCheck(sc, mcc);
503  }
504 
506  ModuleCallingContext const& mcc) {
507  postModuleStreamCheck(sc, mcc);
508  }
509 
511  preModuleStreamCheck(sc, mcc);
512  }
513 
515  ModuleCallingContext const& mcc) {
516  postModuleStreamCheck(sc, mcc);
517  }
518 
520  ModuleCallingContext const& mcc) {
521  preModuleStreamCheck(sc, mcc);
522  }
523 
525  ModuleCallingContext const& mcc) {
526  postModuleStreamCheck(sc, mcc);
527  }
528 
530  ModuleCallingContext const& mcc) {
531  preModuleStreamCheck(sc, mcc);
532  }
533 
535  ModuleCallingContext const& mcc) {
536  postModuleStreamCheck(sc, mcc);
537  }
538 
539  std::vector<RandomEngineState> const& RandomNumberGeneratorService::getLumiCache(
540  LuminosityBlockIndex const& lumiIndex) const {
541  return lumiCache_.at(lumiIndex.value());
542  }
543 
544  std::vector<RandomEngineState> const& RandomNumberGeneratorService::getEventCache(StreamID const& streamID) const {
545  return eventCache_.at(streamID.value());
546  }
547 
548  void RandomNumberGeneratorService::print(std::ostream& os) const {
549  os << "\n\nRandomNumberGeneratorService dump\n\n";
550 
551  os << " Contents of seedsAndNameMap (label moduleID engineType seeds)\n";
552  for (auto const& entry : seedsAndNameMap_) {
553  os << " " << entry.first << " " << entry.second.moduleID() << " " << entry.second.engineName();
554  for (auto val : entry.second.seeds()) {
555  os << " " << val;
556  }
557  os << "\n";
558  }
559  os << " nStreams_ = " << nStreams_ << "\n";
560  os << " saveFileName_ = " << saveFileName_ << "\n";
561  os << " saveFileNameRecorded_ = " << saveFileNameRecorded_ << "\n";
562  os << " restoreFileName_ = " << restoreFileName_ << "\n";
563  os << " enableChecking_ = " << enableChecking_ << "\n";
564  os << " eventSeedOffset_ = " << eventSeedOffset_ << "\n";
565  os << " verbose_ = " << verbose_ << "\n";
566  os << " restoreStateTag_ = " << restoreStateTag_ << "\n";
567  os << " restoreStateBeginLumiTag_ = " << restoreStateBeginLumiTag_ << "\n";
568 
569  os << "\n streamEngines_\n";
570  unsigned int iStream = 0;
571  for (auto const& k : streamEngines_) {
572  os << " Stream " << iStream << "\n";
573  for (auto const& i : k) {
574  os << " " << i.label();
575  for (auto const& j : i.seeds()) {
576  os << " " << j;
577  }
578  os << " " << i.engine()->name();
579  if (i.engine()->name() == std::string("HepJamesRandom")) {
580  os << " " << i.engine()->getSeed();
581  } else if (i.engine()->name() == std::string("MixMaxRng")) {
582  os << " " << i.engine()->getSeed();
583  } else {
584  os << " engine does not know seeds";
585  }
586  os << "\n";
587  }
588  ++iStream;
589  }
590  os << "\n lumiEngines_\n";
591  unsigned int iLumi = 0;
592  for (auto const& k : lumiEngines_) {
593  os << " lumiIndex " << iLumi << "\n";
594  for (auto const& i : k) {
595  os << " " << i.label();
596  for (auto const& j : i.seeds()) {
597  os << " " << j;
598  }
599  os << " " << i.engine()->name();
600  if (i.engine()->name() == std::string("HepJamesRandom")) {
601  os << " " << i.engine()->getSeed();
602  } else if (i.engine()->name() == std::string("MixMaxRng")) {
603  os << " " << i.engine()->getSeed();
604  } else {
605  os << " engine does not know seeds";
606  }
607  os << "\n";
608  }
609  ++iLumi;
610  }
611  }
612 
614  if (enableChecking_) {
615  unsigned int moduleID = mcc.moduleDescription()->id();
616  std::vector<ModuleIDToEngine>& moduleIDVector = streamModuleIDToEngine_.at(sc.streamID().value());
617  ModuleIDToEngine target(nullptr, moduleID);
618  std::vector<ModuleIDToEngine>::iterator iter =
619  std::lower_bound(moduleIDVector.begin(), moduleIDVector.end(), target);
620  if (iter != moduleIDVector.end() && iter->moduleID() == moduleID) {
621  LabelAndEngine* labelAndEngine = iter->labelAndEngine();
622  iter->setEngineState(labelAndEngine->engine()->put());
623  }
624  }
625  }
626 
628  if (enableChecking_) {
629  unsigned int moduleID = mcc.moduleDescription()->id();
630  std::vector<ModuleIDToEngine>& moduleIDVector = streamModuleIDToEngine_.at(sc.streamID().value());
631  ModuleIDToEngine target(nullptr, moduleID);
632  std::vector<ModuleIDToEngine>::iterator iter =
633  std::lower_bound(moduleIDVector.begin(), moduleIDVector.end(), target);
634  if (iter != moduleIDVector.end() && iter->moduleID() == moduleID) {
635  LabelAndEngine* labelAndEngine = iter->labelAndEngine();
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\""
642  << mcc.moduleDescription()->moduleName()
643  << "\" "
644  "and module label \""
645  << mcc.moduleDescription()->moduleLabel() << "\"\n";
646  }
647  }
648  }
649  }
650 
653  if (tns.isAvailable()) {
654  if (tns->getProcessName() == restoreStateTag_.process()) {
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";
661  }
662  }
663 
665  lumi.getByLabel(restoreStateBeginLumiTag_, states);
666 
667  if (!states.isValid()) {
669  << "The RandomNumberGeneratorService is trying to restore\n"
670  << "the state of the random engines by reading a product from\n"
671  << "the LuminosityBlock with input tag \"" << restoreStateBeginLumiTag_ << "\".\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";
675  return;
676  }
677  states->getRandomEngineStates(lumiCache_.at(lumi.index()));
678  }
679 
682 
683  event.getByLabel(restoreStateTag_, states);
684 
685  if (!states.isValid()) {
687  << "The RandomNumberGeneratorService is trying to restore\n"
688  << "the state of the random engines by reading a product from\n"
689  << "the Event with input tag \"" << restoreStateTag_ << "\".\n"
690  << "It could not find the product.\n"
691  << "Either the product in the Event was dropped or\n"
692  << "not produced or the configured input tag is incorrect or there is a bug somewhere\n";
693  return;
694  }
695  states->getRandomEngineStates(eventCache_.at(event.streamID()));
696  }
697 
698  void RandomNumberGeneratorService::snapShot(std::vector<LabelAndEngine> const& engines,
699  std::vector<RandomEngineState>& cache) {
700  cache.resize(engines.size());
701  std::vector<RandomEngineState>::iterator state = cache.begin();
702 
703  for (std::vector<LabelAndEngine>::const_iterator iter = engines.begin(); iter != engines.end(); ++iter, ++state) {
704  std::string const& label = iter->label();
705  state->setLabel(label);
706  state->setSeed(iter->seeds());
707 
708  std::vector<unsigned long> stateL = iter->engine()->put();
709  state->clearStateVector();
710  state->reserveStateVector(stateL.size());
711  for (auto element : stateL) {
712  state->push_back_stateVector(static_cast<std::uint32_t>(element));
713  }
714  }
715  }
716 
717  void RandomNumberGeneratorService::restoreFromCache(std::vector<RandomEngineState> const& cache,
718  std::vector<LabelAndEngine>& engines) {
719  std::vector<LabelAndEngine>::iterator labelAndEngine = engines.begin();
720  for (auto const& cachedState : cache) {
721  std::string const& engineLabel = cachedState.getLabel();
722 
723  std::vector<std::uint32_t> const& engineState = cachedState.getState();
724  std::vector<unsigned long> engineStateL;
725  engineStateL.reserve(engineState.size());
726  for (auto const& value : engineState) {
727  engineStateL.push_back(static_cast<unsigned long>(value));
728  }
729 
730  std::vector<std::uint32_t> const& engineSeeds = cachedState.getSeed();
731  std::vector<long> engineSeedsL;
732  engineSeedsL.reserve(engineSeeds.size());
733  for (auto const& val : engineSeeds) {
734  long seedL = static_cast<long>(val);
735  engineSeedsL.push_back(seedL);
736 
737  // There is a dangerous conversion from std::uint32_t to long
738  // that occurs above. In the next 2 lines we check the
739  // behavior is what we need for the service to work
740  // properly. This conversion is forced on us by the
741  // CLHEP and ROOT interfaces. If the assert ever starts
742  // to fail we will have to come up with a way to deal
743  // with this.
744  std::uint32_t seedu32 = static_cast<std::uint32_t>(seedL);
745  assert(val == seedu32);
746  }
747 
748  assert(labelAndEngine != engines.end() && engineLabel == labelAndEngine->label());
749  std::shared_ptr<CLHEP::HepRandomEngine> const& engine = labelAndEngine->engine();
750 
751  // We need to handle each type of engine differently because each
752  // has different requirements on the seed or seeds.
753  if (engineStateL[0] == CLHEP::engineIDulong<CLHEP::HepJamesRandom>()) {
754  checkEngineType(engine->name(), std::string("HepJamesRandom"), engineLabel);
755 
756  // These two lines actually restore the seed and engine state.
757  engine->setSeed(engineSeedsL[0], 0);
758  engine->get(engineStateL);
759 
760  labelAndEngine->setSeed(engineSeeds[0], 0);
761  } else if (engineStateL[0] == CLHEP::engineIDulong<CLHEP::RanecuEngine>()) {
762  checkEngineType(engine->name(), std::string("RanecuEngine"), engineLabel);
763 
764  // This line actually restores the engine state.
765  engine->get(engineStateL);
766 
767  labelAndEngine->setSeed(engineSeeds[0], 0);
768  labelAndEngine->setSeed(engineSeeds[1], 1);
769  } else if (engineStateL[0] == CLHEP::engineIDulong<CLHEP::MixMaxRng>()) {
770  checkEngineType(engine->name(), std::string("MixMaxRng"), engineLabel);
771 
772  // This line actually restores the engine state.
773  engine->setSeed(engineSeedsL[0], 0);
774  engine->get(engineStateL);
775 
776  labelAndEngine->setSeed(engineSeeds[0], 0);
777  } else if (engineStateL[0] == CLHEP::engineIDulong<TRandomAdaptor>()) {
778  checkEngineType(engine->name(), std::string("TRandom3"), engineLabel);
779 
780  // This line actually restores the engine state.
781  engine->setSeed(engineSeedsL[0], 0);
782  engine->get(engineStateL);
783 
784  labelAndEngine->setSeed(engineSeeds[0], 0);
785  } else {
786  // This should not be possible because this code should be able to restore
787  // any kind of engine whose state can be saved.
789  << "The RandomNumberGeneratorService is trying to restore the state\n"
790  "of the random engines. The state in the event indicates an engine\n"
791  "of an unknown type. This should not be possible unless you are\n"
792  "running with an old code release on a new file that was created\n"
793  "with a newer release which had new engine types added. In this case\n"
794  "the only solution is to use a newer release. In any other case, notify\n"
795  "the EDM developers because this should not be possible\n";
796  }
797  ++labelAndEngine;
798  }
799  }
800 
802  std::string const& typeFromEvent,
803  std::string const& engineLabel) const {
804  if (typeFromConfig != typeFromEvent) {
806  << "The RandomNumberGeneratorService is trying to restore\n"
807  << "the state of the random engine for the module \"" << engineLabel << "\". An\n"
808  << "error was detected because the type of the engine in the\n"
809  << "input file and the configuration file do not match.\n"
810  << "In the configuration file the type is \"" << typeFromConfig << "\".\nIn the input file the type is \""
811  << typeFromEvent << "\". If\n"
812  << "you are not generating any random numbers in this module, then\n"
813  << "remove the line in the configuration file that gives it\n"
814  << "a seed and the error will go away. Otherwise, you must give\n"
815  << "this module the same engine type in the configuration file or\n"
816  << "stop trying to restore the random engine state.\n";
817  }
818  }
819 
821  StreamID const& streamID,
823  std::ofstream& outFile = *outFiles_.at(streamID);
824 
825  if (!outFile.is_open()) {
826  std::stringstream file;
827  file << fileName;
828  if (nStreams_ > 1) {
829  file << "_" << streamID.value();
830  }
831 
832  outFile.open(file.str().c_str(), std::ofstream::out | std::ofstream::trunc);
833 
834  if (!outFile) {
836  << "Unable to open the file \"" << file.str() << "\" to save the state of the random engines.\n";
837  }
838  }
839 
840  outFile.seekp(0, std::ios_base::beg);
841  outFile << "<RandomEngineStates>\n";
842 
843  outFile << "<Event>\n";
844  writeStates(eventCache_.at(streamID), outFile);
845  outFile << "</Event>\n";
846 
847  outFile << "<Lumi>\n";
849  outFile << "</Lumi>\n";
850 
851  outFile << "</RandomEngineStates>\n";
852  outFile.flush();
853  }
854 
855  void RandomNumberGeneratorService::writeStates(std::vector<RandomEngineState> const& v, std::ofstream& outFile) {
856  for (auto& state : v) {
857  std::vector<std::uint32_t> const& seedVector = state.getSeed();
858  std::vector<std::uint32_t>::size_type seedVectorLength = seedVector.size();
859 
860  std::vector<std::uint32_t> const& stateVector = state.getState();
861  std::vector<std::uint32_t>::size_type stateVectorLength = stateVector.size();
862 
863  outFile << "<ModuleLabel>\n" << state.getLabel() << "\n</ModuleLabel>\n";
864 
865  outFile << "<SeedLength>\n" << seedVectorLength << "\n</SeedLength>\n";
866  outFile << "<InitialSeeds>\n";
867  writeVector(seedVector, outFile);
868  outFile << "</InitialSeeds>\n";
869  outFile << "<FullStateLength>\n" << stateVectorLength << "\n</FullStateLength>\n";
870  outFile << "<FullState>\n";
871  writeVector(stateVector, outFile);
872  outFile << "</FullState>\n";
873  }
874  }
875 
877  if (v.empty())
878  return;
879  size_t numItems = v.size();
880  for (size_t i = 0; i < numItems; ++i) {
881  if (i != 0 && i % 10 == 0)
882  outFile << "\n";
883  outFile << std::setw(13) << v[i];
884  }
885  outFile << "\n";
886  }
887 
889  char directory[1500];
890  std::string fullName(getcwd(directory, sizeof(directory)) ? directory : "/PathIsTooBig");
891  fullName += "/" + saveFileName_;
892  return fullName;
893  }
894 
896  std::vector<RandomEngineState>& cache) {
897  std::string whichStates("<Event>");
898  readStatesFromFile(fileName, cache, whichStates);
899  }
900 
902  std::vector<RandomEngineState>& cache) {
903  std::string whichStates("<Lumi>");
904  readStatesFromFile(fileName, cache, whichStates);
905  }
906 
908  std::vector<RandomEngineState>& cache,
909  std::string const& whichStates) {
910  std::ifstream inFile;
911  inFile.open(fileName.c_str(), std::ifstream::in);
912  if (!inFile) {
914  << "Unable to open the file \"" << fileName << "\" to restore the random engine states.\n";
915  }
916 
918  inFile >> text;
919  if (!inFile.good() || text != std::string("<RandomEngineStates>")) {
921  << "Attempting to read file with random number engine states.\n"
922  << "File \"" << restoreFileName_ << "\" is ill-structured or otherwise corrupted.\n"
923  << "Cannot read the file header word.\n";
924  }
925  bool saveToCache = false;
926  while (readEngineState(inFile, cache, whichStates, saveToCache)) {
927  }
928  }
929 
931  std::vector<RandomEngineState>& cache,
932  std::string const& whichStates,
933  bool& saveToCache) {
934  std::string leading;
935  std::string trailing;
938  std::vector<std::uint32_t> seedVector;
940  std::vector<std::uint32_t> stateVector;
941 
942  // First we need to look for the special strings
943  // that mark the end of the file and beginning and
944  // and end of the data for different sections.
945 
946  is >> leading;
947  if (!is.good()) {
949  << "File \"" << restoreFileName_ << "\" is ill-structured or otherwise corrupted.\n"
950  << "Cannot read next field and did not hit the end yet.\n";
951  }
952 
953  // This marks the end of the file. We are done.
954  if (leading == std::string("</RandomEngineStates>"))
955  return false;
956 
957  // This marks the end of a section of the data
958  if (leading == std::string("</Event>") || leading == std::string("</Lumi>")) {
959  saveToCache = false;
960  return true;
961  }
962 
963  // This marks the beginning of a section
964  if (leading == std::string("<Event>") || leading == std::string("<Lumi>")) {
965  saveToCache = (leading == whichStates);
966  return true;
967  }
968 
969  // Process the next engine state
970 
971  is >> moduleLabel >> trailing;
972  if (!is.good() || leading != std::string("<ModuleLabel>") || trailing != std::string("</ModuleLabel>")) {
974  << "File \"" << restoreFileName_ << "\" is ill-structured or otherwise corrupted.\n"
975  << "Cannot read a module label when restoring random engine states.\n";
976  }
977 
978  is >> leading >> seedVectorSize >> trailing;
979  if (!is.good() || leading != std::string("<SeedLength>") || trailing != std::string("</SeedLength>")) {
981  << "File \"" << restoreFileName_ << "\" is ill-structured or otherwise corrupted.\n"
982  << "Cannot read seed vector length when restoring random engine states.\n";
983  }
984 
985  is >> leading;
986  if (!is.good() || leading != std::string("<InitialSeeds>")) {
988  << "File \"" << restoreFileName_ << "\" is ill-structured or otherwise corrupted.\n"
989  << "Cannot read beginning of InitialSeeds when restoring random engine states.\n";
990  }
991 
992  if (seedVectorSize > maxSeeds) {
994  << "File \"" << restoreFileName_ << "\" is ill-structured or otherwise corrupted.\n"
995  << "The number of seeds exceeds 64K.\n";
996  }
997 
998  readVector(is, seedVectorSize, seedVector);
999 
1000  is >> trailing;
1001  if (!is.good() || trailing != std::string("</InitialSeeds>")) {
1003  << "File \"" << restoreFileName_ << "\" is ill-structured or otherwise corrupted.\n"
1004  << "Cannot read end of InitialSeeds when restoring random engine states.\n";
1005  }
1006 
1007  is >> leading >> stateVectorSize >> trailing;
1008  if (!is.good() || leading != std::string("<FullStateLength>") || trailing != std::string("</FullStateLength>")) {
1010  << "File \"" << restoreFileName_ << "\" is ill-structured or otherwise corrupted.\n"
1011  << "Cannot read state vector length when restoring random engine states.\n";
1012  }
1013 
1014  is >> leading;
1015  if (!is.good() || leading != std::string("<FullState>")) {
1017  << "File \"" << restoreFileName_ << "\" is ill-structured or otherwise corrupted.\n"
1018  << "Cannot read beginning of FullState when restoring random engine states.\n";
1019  }
1020 
1021  if (stateVectorSize > maxStates) {
1023  << "File \"" << restoreFileName_ << "\" is ill-structured or otherwise corrupted.\n"
1024  << "The number of states exceeds 64K.\n";
1025  }
1026 
1027  readVector(is, stateVectorSize, stateVector);
1028 
1029  is >> trailing;
1030  if (!is.good() || trailing != std::string("</FullState>")) {
1032  << "File \"" << restoreFileName_ << "\" is ill-structured or otherwise corrupted.\n"
1033  << "Cannot read end of FullState when restoring random engine states.\n";
1034  }
1035 
1036  if (saveToCache) {
1037  RandomEngineState randomEngineState;
1038  randomEngineState.setLabel(moduleLabel);
1039  std::vector<RandomEngineState>::iterator state =
1040  std::lower_bound(cache.begin(), cache.end(), randomEngineState);
1041 
1042  if (state != cache.end() && moduleLabel == state->getLabel()) {
1043  if (seedVector.size() != state->getSeed().size() || stateVector.size() != state->getState().size()) {
1045  << "File \"" << restoreFileName_ << "\" is ill-structured or otherwise corrupted.\n"
1046  << "Vectors containing engine state are the incorrect size for the type of random engine.\n";
1047  }
1048  state->setSeed(seedVector);
1049  state->setState(stateVector);
1050  }
1051  }
1052  return true;
1053  }
1054 
1055  void RandomNumberGeneratorService::readVector(std::istream& is, unsigned numItems, std::vector<std::uint32_t>& v) {
1056  v.clear();
1057  v.reserve(numItems);
1058  std::uint32_t data;
1059  for (unsigned i = 0; i < numItems; ++i) {
1060  is >> data;
1061  if (!is.good()) {
1063  << "File \"" << restoreFileName_ << "\" is ill-structured or otherwise corrupted.\n"
1064  << "Cannot read vector when restoring random engine states.\n";
1065  }
1066  v.push_back(data);
1067  }
1068  }
1069 
1070  void RandomNumberGeneratorService::createEnginesInVector(std::vector<LabelAndEngine>& engines,
1071  unsigned int seedOffset,
1072  unsigned int eventSeedOffset,
1073  std::vector<ModuleIDToEngine>& moduleIDVector) {
1074  // The vectors we will fill here will be the same size as
1075  // or smaller than seedsAndNameMap_.
1076  engines.reserve(seedsAndNameMap_.size());
1077  moduleIDVector.reserve(seedsAndNameMap_.size());
1078 
1079  for (auto const& i : seedsAndNameMap_) {
1080  unsigned int moduleID = i.second.moduleID();
1081  if (moduleID != std::numeric_limits<unsigned int>::max()) {
1082  std::string const& label = i.first;
1083  std::string const& name = i.second.engineName();
1084  VUint32 const& seeds = i.second.seeds();
1085 
1086  if (name == "RanecuEngine") {
1087  std::shared_ptr<CLHEP::HepRandomEngine> engine = std::make_shared<CLHEP::RanecuEngine>();
1088  engines.emplace_back(label, seeds, engine);
1089  resetEngineSeeds(engines.back(), name, seeds, seedOffset, eventSeedOffset);
1090  }
1091  // For the other engines, one seed is required
1092  else {
1093  long int seedL = static_cast<long int>(seeds[0]);
1094 
1095  if (name == "HepJamesRandom") {
1096  std::shared_ptr<CLHEP::HepRandomEngine> engine = std::make_shared<CLHEP::HepJamesRandom>(seedL);
1097  engines.emplace_back(label, seeds, engine);
1098  if (seedOffset != 0 || eventSeedOffset != 0) {
1099  resetEngineSeeds(engines.back(), name, seeds, seedOffset, eventSeedOffset);
1100  }
1101  } else if (name == "MixMaxRng") {
1102  std::shared_ptr<CLHEP::HepRandomEngine> engine = std::make_shared<CLHEP::MixMaxRng>(seedL);
1103  engines.emplace_back(label, seeds, engine);
1104  if (seedOffset != 0 || eventSeedOffset != 0) {
1105  resetEngineSeeds(engines.back(), name, seeds, seedOffset, eventSeedOffset);
1106  }
1107  } else { // TRandom3, currently the only other possibility
1108 
1109  // There is a dangerous conversion from std::uint32_t to long
1110  // that occurs above. In the next 2 lines we check the
1111  // behavior is what we need for the service to work
1112  // properly. This conversion is forced on us by the
1113  // CLHEP and ROOT interfaces. If the assert ever starts
1114  // to fail we will have to come up with a way to deal
1115  // with this.
1116  std::uint32_t seedu32 = static_cast<std::uint32_t>(seedL);
1117  assert(seeds[0] == seedu32);
1118 
1119  std::shared_ptr<CLHEP::HepRandomEngine> engine = std::make_shared<TRandomAdaptor>(seedL);
1120  engines.emplace_back(label, seeds, engine);
1121  if (seedOffset != 0 || eventSeedOffset != 0) {
1122  resetEngineSeeds(engines.back(), name, seeds, seedOffset, eventSeedOffset);
1123  }
1124  }
1125  }
1126  moduleIDVector.emplace_back(&engines.back(), moduleID);
1127  } // if moduleID valid
1128  } // loop over seedsAndMap
1129  std::sort(moduleIDVector.begin(), moduleIDVector.end());
1130  }
1131 
1133  std::string const& engineName,
1134  VUint32 const& seeds,
1135  std::uint32_t offset1,
1136  std::uint32_t offset2) {
1137  if (engineName == "RanecuEngine") {
1138  assert(seeds.size() == 2U);
1139  // Wrap around if the offsets push the seed over the maximum allowed value
1140  std::uint32_t mod = maxSeedRanecu + 1U;
1141  offset1 %= mod;
1142  offset2 %= mod;
1143  std::uint32_t seed0 = (seeds[0] + offset1) % mod;
1144  seed0 = (seed0 + offset2) % mod;
1145  labelAndEngine.setSeed(seed0, 0);
1146  labelAndEngine.setSeed(seeds[1], 1);
1147  long int seedL[2];
1148  seedL[0] = static_cast<long int>(seed0);
1149  seedL[1] = static_cast<long int>(seeds[1]);
1150  labelAndEngine.engine()->setSeeds(seedL, 0);
1151  } else {
1152  assert(seeds.size() == 1U);
1153 
1154  if (engineName == "HepJamesRandom" || engineName == "MixMaxRng") {
1155  // Wrap around if the offsets push the seed over the maximum allowed value
1156  std::uint32_t mod = maxSeedHepJames + 1U;
1157  offset1 %= mod;
1158  offset2 %= mod;
1159  std::uint32_t seed0 = (seeds[0] + offset1) % mod;
1160  seed0 = (seed0 + offset2) % mod;
1161  labelAndEngine.setSeed(seed0, 0);
1162 
1163  long int seedL = static_cast<long int>(seed0);
1164  labelAndEngine.engine()->setSeed(seedL, 0);
1165  } else {
1166  assert(engineName == "TRandom3");
1167  // Wrap around if the offsets push the seed over the maximum allowed value
1168  // We have to be extra careful with this one because it may also go beyond
1169  // the values 32 bits can hold
1170  std::uint32_t max32 = maxSeedTRandom3;
1171  std::uint32_t seed0 = seeds[0];
1172  if ((max32 - seed0) >= offset1) {
1173  seed0 += offset1;
1174  } else {
1175  seed0 = offset1 - (max32 - seed0) - 1U;
1176  }
1177  if ((max32 - seed0) >= offset2) {
1178  seed0 += offset2;
1179  } else {
1180  seed0 = offset2 - (max32 - seed0) - 1U;
1181  }
1182  labelAndEngine.setSeed(seed0, 0);
1183 
1184  long seedL = static_cast<long>(seed0);
1185 
1186  // There is a dangerous conversion from std::uint32_t to long
1187  // that occurs above. In the next 2 lines we check the
1188  // behavior is what we need for the service to work
1189  // properly. This conversion is forced on us by the
1190  // CLHEP and ROOT interfaces. If the assert ever starts
1191  // to fail we will have to come up with a way to deal
1192  // with this.
1193  std::uint32_t seedu32 = static_cast<std::uint32_t>(seedL);
1194  assert(seed0 == seedu32);
1195 
1196  labelAndEngine.engine()->setSeed(seedL, 0);
1197  }
1198  }
1199  }
1200  } // namespace service
1201 } // namespace edm
ConfigurationDescriptions.h
edm::ActivityRegistry::watchPreModuleEndStream
void watchPreModuleEndStream(PreModuleEndStream::slot_type const &iSlot)
Definition: ActivityRegistry.h:258
edm::StreamID
Definition: StreamID.h:30
edm::ActivityRegistry::watchPreModuleBeginStream
void watchPreModuleBeginStream(PreModuleBeginStream::slot_type const &iSlot)
Definition: ActivityRegistry.h:244
edm::service::RandomNumberGeneratorService::VUint32
std::vector< std::uint32_t > VUint32
Definition: RandomNumberGeneratorService.h:121
edm::ModuleDescription::moduleLabel
std::string const & moduleLabel() const
Definition: ModuleDescription.h:43
edm::service::RandomNumberGeneratorService::lumiCache_
std::vector< std::vector< RandomEngineState > > lumiCache_
Definition: RandomNumberGeneratorService.h:229
service
Definition: service.py:1
edm::service::RandomNumberGeneratorService::readEventStatesFromTextFile
void readEventStatesFromTextFile(std::string const &fileName, std::vector< RandomEngineState > &cache)
Definition: RandomNumberGeneratorService.cc:895
Handle.h
ModuleCallingContext.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
edm::service::RandomNumberGeneratorService::saveStatesToFile
void saveStatesToFile(std::string const &fileName, StreamID const &streamID, LuminosityBlockIndex const &lumiIndex)
Definition: RandomNumberGeneratorService.cc:820
edm::service::RandomNumberGeneratorService::maxStates
static const std::vector< std::uint32_t >::size_type maxStates
Definition: RandomNumberGeneratorService.h:274
edm::service::RandomNumberGeneratorService::streamEngines_
std::vector< std::vector< LabelAndEngine > > streamEngines_
Definition: RandomNumberGeneratorService.h:218
edm::service::RandomNumberGeneratorService::print
void print(std::ostream &os) const override
For debugging.
Definition: RandomNumberGeneratorService.cc:548
edm::service::RandomNumberGeneratorService::eventCache_
std::vector< std::vector< RandomEngineState > > eventCache_
Definition: RandomNumberGeneratorService.h:228
funct::false
false
Definition: Factorize.h:34
edm::ParameterWildcard< ParameterSetDescription >
Definition: ParameterWildcard.h:60
edm::service::RandomNumberGeneratorService::consumes
void consumes(ConsumesCollector &&iC) const override
Definition: RandomNumberGeneratorService.cc:216
edm::service::RandomNumberGeneratorService::fillDescriptions
static void fillDescriptions(ConfigurationDescriptions &descriptions)
Definition: RandomNumberGeneratorService.cc:351
edm::service::RandomNumberGeneratorService::mySeed
std::uint32_t mySeed() const override
Definition: RandomNumberGeneratorService.cc:318
edm::service::RandomNumberGeneratorService::preallocate
void preallocate(SystemBounds const &)
Definition: RandomNumberGeneratorService.cc:385
edm::service::RandomNumberGeneratorService::createEnginesInVector
void createEnginesInVector(std::vector< LabelAndEngine > &engines, unsigned int seedOffset, unsigned int eventSeedOffset, std::vector< ModuleIDToEngine > &moduleIDVector)
Definition: RandomNumberGeneratorService.cc:1070
edm::errors::LogicError
Definition: EDMException.h:37
edm::service::RandomNumberGeneratorService::readEngineState
bool readEngineState(std::istream &is, std::vector< RandomEngineState > &cache, std::string const &whichStates, bool &saveToCache)
Definition: RandomNumberGeneratorService.cc:930
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
SiStripMonitorTrack_RawStandAlone_cff.engineName
engineName
Definition: SiStripMonitorTrack_RawStandAlone_cff.py:33
edm::ActivityRegistry::watchPostModuleStreamBeginLumi
void watchPostModuleStreamBeginLumi(PostModuleStreamBeginLumi::slot_type const &iSlot)
Definition: ActivityRegistry.h:765
edm::service::RandomNumberGeneratorService::constructSaveFileName
std::string constructSaveFileName() const
Definition: RandomNumberGeneratorService.cc:888
TriggerNamesService.h
edm::service::RandomNumberGeneratorService::postModuleStreamEndLumi
void postModuleStreamEndLumi(StreamContext const &sc, ModuleCallingContext const &mcc)
Definition: RandomNumberGeneratorService.cc:534
LuminosityBlock.h
edm
HLT enums.
Definition: AlignableModifier.h:19
mps_splice.entry
entry
Definition: mps_splice.py:68
edmLumisInFiles.description
description
Definition: edmLumisInFiles.py:11
RandomEngineState::setLabel
void setLabel(const std::string &value)
Definition: RandomEngineState.h:36
mod
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
edm::service::RandomNumberGeneratorService::eventSeedOffset_
std::uint32_t eventSeedOffset_
Definition: RandomNumberGeneratorService.h:269
gather_cfg.cout
cout
Definition: gather_cfg.py:144
RandomNumberGeneratorService.h
edm::service::RandomNumberGeneratorService::getEventCache
std::vector< RandomEngineState > const & getEventCache(StreamID const &) const override
Definition: RandomNumberGeneratorService.cc:544
edm::ModuleDescription::moduleName
std::string const & moduleName() const
Definition: ModuleDescription.h:42
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::service::RandomNumberGeneratorService::readStatesFromFile
void readStatesFromFile(std::string const &fileName, std::vector< RandomEngineState > &cache, std::string const &whichStates)
Definition: RandomNumberGeneratorService.cc:907
edm::friendlyname::emptyString
static const std::string emptyString("")
cms::cuda::assert
assert(be >=bs)
edm::errors::Unknown
Definition: EDMException.h:29
edm::service::RandomNumberGeneratorService::SeedsAndName
Definition: RandomNumberGeneratorService.h:235
edm::InputTag::process
std::string const & process() const
Definition: InputTag.h:40
CurrentModuleOnThread.h
edm::service::RandomNumberGeneratorService::cloneEngine
std::unique_ptr< CLHEP::HepRandomEngine > cloneEngine(LuminosityBlockIndex const &) override
Definition: RandomNumberGeneratorService.cc:289
edm::service::RandomNumberGeneratorService::setEventCache
void setEventCache(StreamID, std::vector< RandomEngineState > const &iStates) override
Definition: RandomNumberGeneratorService.cc:478
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::StreamID::value
unsigned int value() const
Definition: StreamID.h:42
edm::ActivityRegistry::watchPostModuleStreamEndRun
void watchPostModuleStreamEndRun(PostModuleStreamEndRun::slot_type const &iSlot)
Definition: ActivityRegistry.h:751
edm::ModuleCallingContext::moduleDescription
ModuleDescription const * moduleDescription() const
Definition: ModuleCallingContext.h:50
edm::ActivityRegistry::watchPreModuleStreamBeginRun
void watchPreModuleStreamBeginRun(PreModuleStreamBeginRun::slot_type const &iSlot)
Definition: ActivityRegistry.h:730
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
findQualityFiles.v
v
Definition: findQualityFiles.py:179
edm::service::RandomNumberGeneratorService::checkEngineType
void checkEngineType(std::string const &typeFromConfig, std::string const &typeFromEvent, std::string const &engineLabel) const
Definition: RandomNumberGeneratorService.cc:801
edm::Handle
Definition: AssociativeIterator.h:50
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
edm::service::SystemBounds::maxNumberOfConcurrentLuminosityBlocks
unsigned int maxNumberOfConcurrentLuminosityBlocks() const
Definition: SystemBounds.h:37
edm::ModuleDescription
Definition: ModuleDescription.h:21
edm::ActivityRegistry::watchPostModuleBeginStream
void watchPostModuleBeginStream(PostModuleBeginStream::slot_type const &iSlot)
Definition: ActivityRegistry.h:251
edm::service::RandomNumberGeneratorService::readLumiStatesFromTextFile
void readLumiStatesFromTextFile(std::string const &fileName, std::vector< RandomEngineState > &cache)
Definition: RandomNumberGeneratorService.cc:901
ModuleDescription.h
ActivityRegistry.h
edm::service::RandomNumberGeneratorService::restoreFromCache
void restoreFromCache(std::vector< RandomEngineState > const &cache, std::vector< LabelAndEngine > &engines)
Definition: RandomNumberGeneratorService.cc:717
EDMException.h
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
RandomEngineState
Definition: RandomEngineState.h:26
edm::errors::ProductNotFound
Definition: EDMException.h:33
edm::service::RandomNumberGeneratorService::postEventRead
void postEventRead(Event const &event) override
Definition: RandomNumberGeneratorService.cc:444
edm::ActivityRegistry::watchPreModuleStreamEndLumi
void watchPreModuleStreamEndLumi(PreModuleStreamEndLumi::slot_type const &iSlot)
Definition: ActivityRegistry.h:772
edm::service::RandomNumberGeneratorService::restoreStateBeginLumiTag_
edm::InputTag restoreStateBeginLumiTag_
Definition: RandomNumberGeneratorService.h:226
edm::service::RandomNumberGeneratorService::writeVector
void writeVector(VUint32 const &v, std::ofstream &outFile)
Definition: RandomNumberGeneratorService.cc:876
edm::service::RandomNumberGeneratorService::LabelAndEngine::engine
std::shared_ptr< CLHEP::HepRandomEngine const > engine() const
Definition: RandomNumberGeneratorService.h:131
ParameterWildcard.h
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
edm::service::RandomNumberGeneratorService::maxSeeds
static const std::vector< std::uint32_t >::size_type maxSeeds
Definition: RandomNumberGeneratorService.h:273
edm::LuminosityBlockIndex
Definition: LuminosityBlockIndex.h:33
edm::service::RandomNumberGeneratorService::lumiModuleIDToEngine_
std::vector< std::vector< ModuleIDToEngine > > lumiModuleIDToEngine_
Definition: RandomNumberGeneratorService.h:215
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
edm::StreamContext
Definition: StreamContext.h:31
TRandomAdaptor.h
edm::service::RandomNumberGeneratorService::maxSeedHepJames
static const std::uint32_t maxSeedHepJames
Definition: RandomNumberGeneratorService.h:276
edm::service::RandomNumberGeneratorService::preModuleStreamCheck
void preModuleStreamCheck(StreamContext const &sc, ModuleCallingContext const &mcc)
Definition: RandomNumberGeneratorService.cc:613
edm::ActivityRegistry::watchPostModuleEndStream
void watchPostModuleEndStream(PostModuleEndStream::slot_type const &iSlot)
Definition: ActivityRegistry.h:265
edm::service::RandomNumberGeneratorService::readVector
void readVector(std::istream &is, unsigned numItems, std::vector< std::uint32_t > &v)
Definition: RandomNumberGeneratorService.cc:1055
Service.h
edm::service::RandomNumberGeneratorService::postModuleStreamBeginLumi
void postModuleStreamBeginLumi(StreamContext const &sc, ModuleCallingContext const &mcc)
Definition: RandomNumberGeneratorService.cc:524
edm::service::RandomNumberGeneratorService::verbose_
bool verbose_
Definition: RandomNumberGeneratorService.h:271
edm::ActivityRegistry
Definition: ActivityRegistry.h:132
RandomServiceHelper.initialSeedSet
initialSeedSet
Definition: RandomServiceHelper.py:264
edm::service::RandomNumberGeneratorService::lumiEngines_
std::vector< std::vector< LabelAndEngine > > lumiEngines_
Definition: RandomNumberGeneratorService.h:219
edm::service::RandomNumberGeneratorService::LabelAndEngine
Definition: RandomNumberGeneratorService.h:123
edm::service::RandomNumberGeneratorService::postModuleBeginStream
void postModuleBeginStream(StreamContext const &sc, ModuleCallingContext const &mcc)
Definition: RandomNumberGeneratorService.cc:488
edm::service::RandomNumberGeneratorService::restoreFileName_
std::string restoreFileName_
Definition: RandomNumberGeneratorService.h:262
edm::ActivityRegistry::watchPreModuleStreamBeginLumi
void watchPreModuleStreamBeginLumi(PreModuleStreamBeginLumi::slot_type const &iSlot)
Definition: ActivityRegistry.h:758
dqmdumpme.k
k
Definition: dqmdumpme.py:60
edm::service::RandomNumberGeneratorService::writeStates
void writeStates(std::vector< RandomEngineState > const &v, std::ofstream &outFile)
Definition: RandomNumberGeneratorService.cc:855
ParameterSetDescription.h
edm::service::RandomNumberGeneratorService::preModuleStreamEndLumi
void preModuleStreamEndLumi(StreamContext const &sc, ModuleCallingContext const &mcc)
Definition: RandomNumberGeneratorService.cc:529
cuda_std::lower_bound
__host__ constexpr __device__ RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:27
csv2json.lumiIndex
lumiIndex
Definition: csv2json.py:29
utilities.cache
def cache(function)
Definition: utilities.py:3
edm::RandomEngineStates
Definition: RandomEngineStates.h:23
edm::service::RandomNumberGeneratorService::preBeginLumi
void preBeginLumi(LuminosityBlock const &lumi) override
Definition: RandomNumberGeneratorService.cc:435
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
L1TdeCSCTF_cfi.outFile
outFile
Definition: L1TdeCSCTF_cfi.py:5
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
newFWLiteAna.fullName
fullName
Definition: newFWLiteAna.py:122
InitialStep_cff.seeds
seeds
Definition: InitialStep_cff.py:232
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:674
es_hardcode_cfi.iLumi
iLumi
Definition: es_hardcode_cfi.py:206
edm::ParameterSetDescription::addUntracked
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:100
edm::service::RandomNumberGeneratorService::getEngine
CLHEP::HepRandomEngine & getEngine(StreamID const &streamID) override
Use this engine in event methods.
Definition: RandomNumberGeneratorService.cc:221
edm::ActivityRegistry::watchPreModuleStreamEndRun
void watchPreModuleStreamEndRun(PreModuleStreamEndRun::slot_type const &iSlot)
Definition: ActivityRegistry.h:744
edm::service::SystemBounds
Definition: SystemBounds.h:29
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::service::RandomNumberGeneratorService::saveFileNameRecorded_
std::atomic< bool > saveFileNameRecorded_
Definition: RandomNumberGeneratorService.h:256
edm::ParameterSet
Definition: ParameterSet.h:36
edm::service::RandomNumberGeneratorService::ModuleIDToEngine
Definition: RandomNumberGeneratorService.h:144
Event.h
edm::InLumi
Definition: BranchType.h:11
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
edm::StreamContext::streamID
StreamID const & streamID() const
Definition: StreamContext.h:54
edm::service::RandomNumberGeneratorService::seedsAndNameMap_
std::map< std::string, SeedsAndName > seedsAndNameMap_
Definition: RandomNumberGeneratorService.h:249
recoMuon::in
Definition: RecoMuonEnumerators.h:6
edm::Service
Definition: Service.h:30
edm::ActivityRegistry::watchPreModuleConstruction
void watchPreModuleConstruction(PreModuleConstruction::slot_type const &iSlot)
Definition: ActivityRegistry.h:609
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
edm::service::RandomNumberGeneratorService::LabelAndEngine::setSeed
void setSeed(std::uint32_t v, unsigned int index)
Definition: RandomNumberGeneratorService.h:133
value
Definition: value.py:1
edm::service::SystemBounds::maxNumberOfStreams
unsigned int maxNumberOfStreams() const
Definition: SystemBounds.h:35
RandomEngineStates.h
edm::service::RandomNumberGeneratorService::readFromLuminosityBlock
void readFromLuminosityBlock(LuminosityBlock const &lumi)
Definition: RandomNumberGeneratorService.cc:651
edm::ParameterSetDescription::addNode
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
Definition: ParameterSetDescription.cc:41
edm::service::RandomNumberGeneratorService::maxSeedRanecu
static const std::uint32_t maxSeedRanecu
Definition: RandomNumberGeneratorService.h:275
edm::ActivityRegistry::watchPostModuleStreamEndLumi
void watchPostModuleStreamEndLumi(PostModuleStreamEndLumi::slot_type const &iSlot)
Definition: ActivityRegistry.h:779
edm::CurrentModuleOnThread::getCurrentModuleOnThread
static ModuleCallingContext const * getCurrentModuleOnThread()
Definition: CurrentModuleOnThread.h:17
RandomEngineState.h
edm::service::RandomNumberGeneratorService::readFromEvent
void readFromEvent(Event const &event)
Definition: RandomNumberGeneratorService.cc:680
edm::service::RandomNumberGeneratorService::preModuleConstruction
void preModuleConstruction(ModuleDescription const &description)
Definition: RandomNumberGeneratorService.cc:378
edm::ActivityRegistry::watchPreallocate
void watchPreallocate(Preallocate::slot_type const &iSlot)
Definition: ActivityRegistry.h:142
edm::service::RandomNumberGeneratorService::streamModuleIDToEngine_
std::vector< std::vector< ModuleIDToEngine > > streamModuleIDToEngine_
Definition: RandomNumberGeneratorService.h:214
heppy_batch.val
val
Definition: heppy_batch.py:351
std
Definition: JetResolutionObject.h:76
edm::service::RandomNumberGeneratorService::preModuleEndStream
void preModuleEndStream(StreamContext const &sc, ModuleCallingContext const &mcc)
Definition: RandomNumberGeneratorService.cc:492
edm::service::RandomNumberGeneratorService::preModuleStreamBeginLumi
void preModuleStreamBeginLumi(StreamContext const &sc, ModuleCallingContext const &mcc)
Definition: RandomNumberGeneratorService.cc:519
edm::service::RandomNumberGeneratorService::restoreStateTag_
edm::InputTag restoreStateTag_
Definition: RandomNumberGeneratorService.h:225
edm::service::RandomNumberGeneratorService::outFiles_
std::vector< edm::propagate_const< std::shared_ptr< std::ofstream > > > outFiles_
Definition: RandomNumberGeneratorService.h:257
edm::service::RandomNumberGeneratorService::~RandomNumberGeneratorService
~RandomNumberGeneratorService() override
Definition: RandomNumberGeneratorService.cc:214
Exception
Definition: hltDiff.cc:246
edm::service::RandomNumberGeneratorService::postModuleStreamCheck
void postModuleStreamCheck(StreamContext const &sc, ModuleCallingContext const &mcc)
Definition: RandomNumberGeneratorService.cc:627
edm::service::RandomNumberGeneratorService::postModuleStreamEndRun
void postModuleStreamEndRun(StreamContext const &sc, ModuleCallingContext const &mcc)
Definition: RandomNumberGeneratorService.cc:514
edm::service::RandomNumberGeneratorService::saveFileName_
std::string saveFileName_
Definition: RandomNumberGeneratorService.h:255
createBeamHaloJobs.directory
string directory
Definition: createBeamHaloJobs.py:211
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::service::RandomNumberGeneratorService::preModuleStreamBeginRun
void preModuleStreamBeginRun(StreamContext const &sc, ModuleCallingContext const &mcc)
Definition: RandomNumberGeneratorService.cc:500
Exception.h
LuminosityBlockIndex.h
edm::service::RandomNumberGeneratorService::resetEngineSeeds
void resetEngineSeeds(LabelAndEngine &labelAndEngine, std::string const &engineName, VUint32 const &seeds, std::uint32_t offset1, std::uint32_t offset2)
Definition: RandomNumberGeneratorService.cc:1132
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
filterCSVwithJSON.target
target
Definition: filterCSVwithJSON.py:32
edm::InputTag::kSkipCurrentProcess
static const std::string kSkipCurrentProcess
Definition: InputTag.h:53
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ParameterDescription.h
edm::service::RandomNumberGeneratorService::maxSeedTRandom3
static const std::uint32_t maxSeedTRandom3
Definition: RandomNumberGeneratorService.h:277
ConsumesCollector.h
edm::service::RandomNumberGeneratorService::postModuleStreamBeginRun
void postModuleStreamBeginRun(StreamContext const &sc, ModuleCallingContext const &mcc)
Definition: RandomNumberGeneratorService.cc:505
JobReport.h
ParameterSet.h
runonSM.text
text
Definition: runonSM.py:43
StreamContext.h
HerwigMaxPtPartonFilter_cfi.moduleLabel
moduleLabel
Definition: HerwigMaxPtPartonFilter_cfi.py:4
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::service::RandomNumberGeneratorService::postModuleEndStream
void postModuleEndStream(StreamContext const &sc, ModuleCallingContext const &mcc)
Definition: RandomNumberGeneratorService.cc:496
event
Definition: event.py:1
SiStripMonitorTrack_RawStandAlone_cff.initialSeed
initialSeed
Definition: SiStripMonitorTrack_RawStandAlone_cff.py:32
edm::Event
Definition: Event.h:73
lumi
Definition: LumiSectionData.h:20
edm::RequireZeroOrMore
Definition: ParameterWildcardBase.h:17
StreamID.h
pileupReCalc_HLTpaths.trunc
trunc
Definition: pileupReCalc_HLTpaths.py:144
edm::ParameterDescription
Definition: ParameterDescription.h:110
edm::errors::Configuration
Definition: EDMException.h:36
SystemBounds.h
edm::InputTag
Definition: InputTag.h:15
edm::service::RandomNumberGeneratorService::getLumiCache
std::vector< RandomEngineState > const & getLumiCache(LuminosityBlockIndex const &) const override
These two are used by the RandomEngineStateProducer.
Definition: RandomNumberGeneratorService.cc:539
edm::service::RandomNumberGeneratorService::preModuleBeginStream
void preModuleBeginStream(StreamContext const &sc, ModuleCallingContext const &mcc)
Definition: RandomNumberGeneratorService.cc:484
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
label
const char * label
Definition: PFTauDecayModeTools.cc:11
edm::ActivityRegistry::watchPostModuleStreamBeginRun
void watchPostModuleStreamBeginRun(PostModuleStreamBeginRun::slot_type const &iSlot)
Definition: ActivityRegistry.h:737
edm::service::RandomNumberGeneratorService::RandomNumberGeneratorService
RandomNumberGeneratorService(ParameterSet const &pset, ActivityRegistry &activityRegistry)
Definition: RandomNumberGeneratorService.cc:61
edm::service::RandomNumberGeneratorService::enableChecking_
bool enableChecking_
Definition: RandomNumberGeneratorService.h:267
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
edm::service::RandomNumberGeneratorService::snapShot
void snapShot(std::vector< LabelAndEngine > const &engines, std::vector< RandomEngineState > &cache)
Definition: RandomNumberGeneratorService.cc:698
edm::service::RandomNumberGeneratorService::preModuleStreamEndRun
void preModuleStreamEndRun(StreamContext const &sc, ModuleCallingContext const &mcc)
Definition: RandomNumberGeneratorService.cc:510
edm::ModuleDescription::id
unsigned int id() const
Definition: ModuleDescription.h:46
edm::service::RandomNumberGeneratorService::setLumiCache
void setLumiCache(LuminosityBlockIndex, std::vector< RandomEngineState > const &iStates) override
Definition: RandomNumberGeneratorService.cc:472
edm::ModuleCallingContext
Definition: ModuleCallingContext.h:29
edm::service::RandomNumberGeneratorService::nStreams_
unsigned int nStreams_
Definition: RandomNumberGeneratorService.h:210