test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
39 
40 #include "CLHEP/Random/engineIDulong.h"
41 #include "CLHEP/Random/JamesRandom.h"
42 #include "CLHEP/Random/RanecuEngine.h"
43 
44 #include <algorithm>
45 #include <cassert>
46 #include <ostream>
47 #include <sstream>
48 #include <unistd.h>
49 
50 namespace edm {
51  namespace service {
52 
55  const std::uint32_t RandomNumberGeneratorService::maxSeedRanecu = 2147483647U;
56  const std::uint32_t RandomNumberGeneratorService::maxSeedHepJames = 900000000U;
57  const std::uint32_t RandomNumberGeneratorService::maxSeedTRandom3 = 4294967295U;
58 
59  // This supports the mySeed function
60  // DELETE THIS WHEN/IF that functions is deleted.
62 
64  ActivityRegistry& activityRegistry):
65  nStreams_(0),
66  saveFileName_(pset.getUntrackedParameter<std::string>("saveFileName")),
67  saveFileNameRecorded_(false),
68  restoreFileName_(pset.getUntrackedParameter<std::string>("restoreFileName")),
69  enableChecking_(pset.getUntrackedParameter<bool>("enableChecking")),
70  childIndex_(0U),
71  eventSeedOffset_(pset.getUntrackedParameter<unsigned>("eventSeedOffset")),
72  verbose_(pset.getUntrackedParameter<bool>("verbose")) {
73 
74  if(pset.exists("restoreStateTag")) {
75  restoreStateTag_ = pset.getUntrackedParameter<edm::InputTag>("restoreStateTag");
76  if(restoreStateTag_.process() == "") {
78  }
79  } else {
81  }
83 
84  if(!restoreFileName_.empty() && !restoreStateTag_.label().empty()) {
86  << "In the configuration for the RandomNumberGeneratorService both\n"
87  << "restoreFileName and restoreStateLabel were set to nonempty values\n"
88  << "which is illegal. It is impossible to restore the random engine\n"
89  << "states two different ways in the same process.\n";
90  }
91 
92  // The saveFileName must correspond to a file name without any path specification.
93  // Throw if that is not true.
94  if(!saveFileName_.empty() && (saveFileName_.find("/") != std::string::npos)) {
96  << "The saveFileName parameter must be a simple file name with no path\n"
97  << "specification. In the configuration, it was given the value \""
98  << saveFileName_ << "\"\n";
99  }
100 
101  std::uint32_t initialSeed;
102  VUint32 initialSeedSet;
103  std::string engineName;
104 
105  std::vector<std::string> pSets = pset.getParameterNamesForType<ParameterSet>();
106  for(auto const& label : pSets) {
107 
108  ParameterSet const& modulePSet = pset.getParameterSet(label);
109  engineName = modulePSet.getUntrackedParameter<std::string>("engineName", std::string("HepJamesRandom"));
110 
111  bool initialSeedExists = modulePSet.exists("initialSeed");
112  bool initialSeedSetExists = modulePSet.exists("initialSeedSet");
113 
114  if(initialSeedExists && initialSeedSetExists) {
116  << "For the module with the label \"" << label << "\",\n"
117  << "both the parameters \"initialSeed\" and \"initialSeedSet\"\n"
118  << "have been set in the configuration. You must set one or\n"
119  << "the other. It is illegal to set both.\n";
120  } else if(!initialSeedExists && !initialSeedSetExists) {
122  << "For the module with the label \"" << label << "\",\n"
123  << "neither the parameter \"initialSeed\" nor \"initialSeedSet\"\n"
124  << "has been set in the configuration. You must set one or\n"
125  << "the other.\n";
126  } else if(initialSeedExists) {
127  initialSeed = modulePSet.getUntrackedParameter<std::uint32_t>("initialSeed");
128  initialSeedSet.clear();
129  initialSeedSet.push_back(initialSeed);
130  } else if(initialSeedSetExists) {
131  initialSeedSet = modulePSet.getUntrackedParameter<VUint32>("initialSeedSet");
132  }
133  seedsAndNameMap_.insert(std::pair<std::string, SeedsAndName>(label, SeedsAndName(initialSeedSet, engineName)));
134 
135  // For the CLHEP::RanecuEngine case, require a seed set containing exactly two seeds.
136  if(engineName == std::string("RanecuEngine")) {
137  if(initialSeedSet.size() != 2U) {
139  << "Random engines of type \"RanecuEngine\" require 2 seeds\n"
140  << "be specified with the parameter named \"initialSeedSet\".\n"
141  << "Either \"initialSeedSet\" was not in the configuration\n"
142  << "or its size was not 2 for the module with label \"" << label << "\".\n" ;
143  }
144  if(initialSeedSet[0] > maxSeedRanecu ||
145  initialSeedSet[1] > maxSeedRanecu) { // They need to fit in a 31 bit integer
147  << "The RanecuEngine seeds should be in the range 0 to 2147483647.\n"
148  << "The seeds passed to the RandomNumberGenerationService from the\n"
149  "configuration file were " << initialSeedSet[0] << " and " << initialSeedSet[1]
150  << "\nThis was for the module with label \"" << label << "\".\n";
151  }
152  }
153  // For the other engines, one seed is required
154  else {
155  if(initialSeedSet.size() != 1U) {
157  << "Random engines of type \"HepJamesRandom\" and \"TRandom3\n"
158  << "require exactly 1 seed be specified in the configuration.\n"
159  << "There were " << initialSeedSet.size() << " seeds set for the\n"
160  << "module with label \"" << label << "\".\n" ;
161  }
162  if(engineName == "HepJamesRandom") {
163  if(initialSeedSet[0] > maxSeedHepJames) {
165  << "The CLHEP::HepJamesRandom engine seed should be in the range 0 to 900000000.\n"
166  << "The seed passed to the RandomNumberGenerationService from the\n"
167  "configuration file was " << initialSeedSet[0] << ". This was for \n"
168  << "the module with label " << label << ".\n";
169  }
170  } else if(engineName != "TRandom3") {
172  << "The random engine name, \"" << engineName
173  << "\", does not correspond to a supported engine.\n"
174  << "This engine was configured for the module with label \"" << label << "\"";
175  }
176  }
177  }
179 
181 
183 
184  if(enableChecking_) {
185 
188 
191 
194 
197 
200 
203  }
204 
205  // The next 5 lines support the mySeed function
206  // DELETE THEM when/if that function is deleted.
212  }
213 
215  }
216 
217  CLHEP::HepRandomEngine&
219 
221  if(mcc == nullptr) {
223  << "RandomNumberGeneratorService::getEngine\n"
224  "Requested a random number engine from the RandomNumberGeneratorService\n"
225  "when no module was active. ModuleCallingContext is null\n";
226  }
227  unsigned int moduleID = mcc->moduleDescription()->id();
228 
229  std::vector<ModuleIDToEngine> const& moduleIDVector = streamModuleIDToEngine_.at(streamID.value());
230  ModuleIDToEngine target(nullptr, moduleID);
231  std::vector<ModuleIDToEngine>::const_iterator iter = std::lower_bound(moduleIDVector.begin(),
232  moduleIDVector.end(),
233  target);
234  if(iter == moduleIDVector.end() || iter->moduleID() != moduleID) {
236  << "The module with label \""
237  << 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  " " << mcc->moduleDescription()->moduleLabel() << " = cms.PSet(\n"
244  " initialSeed = cms.untracked.uint32(your_seed),\n"
245  " engineName = cms.untracked.string('TRandom3')\n"
246  " )\n"
247  "where you replace \"your_seed\" with a number and add a comma if necessary\n"
248  "The \"engineName\" parameter is optional. If absent the default is \"HepJamesRandom\".\n";
249 
250  }
251  return *iter->labelAndEngine()->engine();
252  }
253 
254  CLHEP::HepRandomEngine&
256 
258  if(mcc == nullptr) {
260  << "RandomNumberGeneratorService::getEngine\n"
261  "Requested a random number engine from the RandomNumberGeneratorService\n"
262  "when no module was active. ModuleCallingContext is null\n";
263  }
264  unsigned int moduleID = mcc->moduleDescription()->id();
265 
266  std::vector<ModuleIDToEngine> const& moduleIDVector = lumiModuleIDToEngine_.at(lumiIndex.value());
267  ModuleIDToEngine target(nullptr, moduleID);
268  std::vector<ModuleIDToEngine>::const_iterator iter = std::lower_bound(moduleIDVector.begin(),
269  moduleIDVector.end(),
270  target);
271  if(iter == moduleIDVector.end() || iter->moduleID() != moduleID) {
273  << "The module with label \""
274  << mcc->moduleDescription()->moduleLabel()
275  << "\" requested a random number engine from the \n"
276  "RandomNumberGeneratorService, but that module was not configured\n"
277  "for random numbers. An engine is created only if a seed(s) is provided\n"
278  "in the configuration file. Please add the following PSet to the\n"
279  "configuration file for the RandomNumberGeneratorService:\n\n"
280  " " << mcc->moduleDescription()->moduleLabel() << " = cms.PSet(\n"
281  " initialSeed = cms.untracked.uint32(your_seed),\n"
282  " engineName = cms.untracked.string('TRandom3')\n"
283  " )\n"
284  "where you replace \"your_seed\" with a number and add a comma if necessary\n"
285  "The \"engineName\" parameter is optional. If absent the default is \"HepJamesRandom\".\n";
286 
287  }
288  return *iter->labelAndEngine()->engine();
289  }
290 
291  // PROBABLY TO BE DELETED, This returns the configured seed without
292  // any of the modifications for streams, forking, or the offset configuration
293  // parameter. Maybe useful to use for debugging/checks, but dangerous if one tries
294  // to create your own engines using it. It is difficult to get the offsets
295  // for streams/forking/offset parameters correct and almost certainly would break
296  // replay.
297  std::uint32_t
301  if(mcc == nullptr) {
302  if(!moduleLabel_.empty()) {
303  label = moduleLabel_;
304  }
305  else {
307  << "RandomNumberGeneratorService::getEngine()\n"
308  "Requested a random number engine from the RandomNumberGeneratorService\n"
309  "when no module was active. ModuleCallingContext is null\n";
310  }
311  } else {
312  label = mcc->moduleDescription()->moduleLabel();
313  }
314 
315  std::map<std::string, SeedsAndName>::const_iterator iter = seedsAndNameMap_.find(label);
316  if(iter == seedsAndNameMap_.end()) {
318  << "The module with label \""
319  << label
320  << "\" requested a random number seed from the \n"
321  "RandomNumberGeneratorService, but that module was not configured\n"
322  "for random numbers. An engine is created only if a seed(s) is provided\n"
323  "in the configuration file. Please add the following PSet to the\n"
324  "configuration file for the RandomNumberGeneratorService:\n\n"
325  " " << label << " = cms.PSet(\n"
326  " initialSeed = cms.untracked.uint32(your_seed),\n"
327  " engineName = cms.untracked.string('TRandom3')\n"
328  " )\n"
329  "where you replace \"your_seed\" with a number and add a comma if necessary\n"
330  "The \"engineName\" parameter is optional. If absent the default is \"HepJamesRandom\".\n";
331  }
332  return iter->second.seeds()[0];
333  }
334 
335  void
338 
340  edm::InputTag emptyInputTag("", "", "");
341 
342  desc.addNode( edm::ParameterDescription<edm::InputTag>("restoreStateTag", emptyInputTag, false) xor
343  edm::ParameterDescription<std::string>("restoreStateLabel", emptyString, false) );
344 
345  desc.addUntracked<std::string>("saveFileName", emptyString);
346  desc.addUntracked<std::string>("restoreFileName", emptyString);
347  desc.addUntracked<bool>("enableChecking", false);
348  desc.addUntracked<unsigned>("eventSeedOffset", 0U);
349  desc.addUntracked<bool>("verbose", false);
350 
352  val.addOptionalUntracked<std::uint32_t>("initialSeed");
353  val.addOptionalUntracked<std::vector<std::uint32_t> >("initialSeedSet");
354  val.addOptionalUntracked<std::string>("engineName");
355 
357  wnode.setComment("The name of each ParameterSet will be the associated module label.");
358  desc.addNode(wnode);
359 
360  descriptions.add("RandomNumberGeneratorService", desc);
361  }
362 
363  void
365  std::map<std::string, SeedsAndName>::iterator iter = seedsAndNameMap_.find(description.moduleLabel());
366  if(iter != seedsAndNameMap_.end()) {
367  iter->second.setModuleID(description.id());
368  }
369  // The next line supports the mySeed function
370  // DELETE IT when/if that function is deleted.
371  moduleLabel_ = description.moduleLabel();
372  }
373 
374  // The next 5 functions support the mySeed function
375  // DELETE THEM when/if that function is deleted.
376  void
378  moduleLabel_.clear();
379  }
380 
381  void
383  moduleLabel_ = description.moduleLabel();
384  }
385 
386  void
388  moduleLabel_.clear();
389  }
390 
391  void
393  moduleLabel_ = description.moduleLabel();
394  }
395 
396  void
398  moduleLabel_.clear();
399  }
400 
401  void
403 
405  assert(nStreams_ >= 1);
406  if(!restoreFileName_.empty() && nStreams_ != 1) {
408  << "Configuration is illegal. The RandomNumberGeneratorService is configured\n"
409  << "to run replay using a text file to input the random engine states and\n"
410  << "the number of streams is greater than 1. Either set the\n"
411  << "parameter named \"restoreFileName\" in the RandomNumberGeneratorService\n"
412  << "to the empty string or set the parameter \"numberOfStreams\" in the top\n"
413  << "level options parameter set to 1. (Probably these are the default values\n"
414  << "and just not setting the parameters will also work)\n";
415  }
416  unsigned int nConcurrentLumis = sb.maxNumberOfConcurrentLuminosityBlocks();
417 
419  lumiModuleIDToEngine_.resize(nConcurrentLumis);
420  streamEngines_.resize(nStreams_);
421  lumiEngines_.resize(nConcurrentLumis);
422  eventCache_.resize(nStreams_);
423  lumiCache_.resize(nConcurrentLumis);
424  outFiles_.resize(nStreams_);
425 
426  for(unsigned int iStream = 0; iStream < nStreams_; ++iStream) {
427  unsigned int seedOffset = iStream;
429  if(!saveFileName_.empty()) {
430  outFiles_[iStream].reset(new std::ofstream);
431  }
432  }
433  for(unsigned int iLumi = 0; iLumi < nConcurrentLumis; ++iLumi) {
434  unsigned int seedOffset = nStreams_;
435  createEnginesInVector(lumiEngines_[iLumi], seedOffset, 0, lumiModuleIDToEngine_[iLumi]);
436  snapShot(lumiEngines_[iLumi], lumiCache_[iLumi]);
437  if(!restoreFileName_.empty()) {
439  }
440  }
441 
442  if(!restoreFileName_.empty()) {
443  // There is guaranteed to be one stream in this case
447  }
448  if(verbose_) {
449  print(std::cout);
450  }
451  }
452 
453  void
454  RandomNumberGeneratorService::postForkReacquireResources(unsigned childIndex, unsigned kMaxChildren) {
455  assert(nStreams_ == 1);
456  childIndex_ = childIndex;
457 
458  if(!restoreFileName_.empty()) {
460  << "Configuration is illegal. The RandomNumberGeneratorService is configured\n"
461  << "to run replay using a text file to input the random engine states and\n"
462  << "the process is configured to fork multiple processes. No forking is\n"
463  << "is allowed with this type of replay\n";
464  }
465 
466  if (childIndex_ != 0) {
467  std::vector<LabelAndEngine>& engines = streamEngines_[0];
468  for(auto& labelAndEngine : engines) {
469  std::map<std::string, SeedsAndName>::const_iterator seedsAndName = seedsAndNameMap_.find(labelAndEngine.label());
470  assert(seedsAndName != seedsAndNameMap_.end());
471  resetEngineSeeds(labelAndEngine,
472  seedsAndName->second.engineName(),
473  seedsAndName->second.seeds(),
474  childIndex,
476  }
477  }
478  if (kMaxChildren != 0) {
479  for(unsigned int i = 0; i < lumiEngines_.size(); ++i) {
480  std::vector<LabelAndEngine>& engines = lumiEngines_.at(i);
481  for(auto& labelAndEngine : engines) {
482  std::map<std::string, SeedsAndName>::const_iterator seedsAndName = seedsAndNameMap_.find(labelAndEngine.label());
483  assert(seedsAndName != seedsAndNameMap_.end());
484  resetEngineSeeds(labelAndEngine,
485  seedsAndName->second.engineName(),
486  seedsAndName->second.seeds(),
487  kMaxChildren,
488  0);
489  }
491  }
492  }
493 
494  if(!saveFileName_.empty()) {
495  std::ostringstream suffix;
496  suffix << "_" << childIndex;
497  saveFileName_ += suffix.str();
498  }
499  if(verbose_) {
500  print(std::cout);
501  }
502  }
503 
504  void
506 
507  if(!restoreStateTag_.label().empty()) {
508  // Copy from a product in the LuminosityBlock to cache for a particular luminosityBlockIndex
510  }
511  // Copy from cache to engine the state for a particular luminosityBlockIndex
513  }
514 
515  void
517 
518  if(!restoreStateTag_.label().empty()) {
519 
520  // This initializes the cache before readFromEvent
521  snapShot(streamEngines_[event.streamID()], eventCache_[event.streamID()]);
522 
523  // copy from Event to event cache
524  readFromEvent(event);
525 
526  // copy from event cache to engines
527  restoreFromCache(eventCache_[event.streamID()], streamEngines_[event.streamID()]);
528 
529  } else {
530  // copy from engines to event cache
531  snapShot(streamEngines_[event.streamID()], eventCache_[event.streamID()]);
532  }
533 
534  // if requested write text file from both caches
535  if(!saveFileName_.empty()) {
536  saveStatesToFile(saveFileName_, event.streamID(), event.getLuminosityBlock().index());
537  bool expected = false;
538  if(saveFileNameRecorded_.compare_exchange_strong(expected, true)) {
540  Service<JobReport> reportSvc;
541  reportSvc->reportRandomStateFile(fullName);
542  }
543  }
544  }
545 
546  void
548  preModuleStreamCheck(sc, mcc);
549  }
550 
551  void
553  postModuleStreamCheck(sc, mcc);
554  }
555 
556  void
558  preModuleStreamCheck(sc, mcc);
559  }
560 
561  void
563  postModuleStreamCheck(sc, mcc);
564  }
565 
566  void
568  preModuleStreamCheck(sc, mcc);
569  }
570 
571  void
573  postModuleStreamCheck(sc, mcc);
574  }
575 
576  void
578  preModuleStreamCheck(sc, mcc);
579  }
580 
581  void
583  postModuleStreamCheck(sc, mcc);
584  }
585 
586  void
588  preModuleStreamCheck(sc, mcc);
589  }
590 
591  void
593  postModuleStreamCheck(sc, mcc);
594  }
595 
596  void
598  preModuleStreamCheck(sc, mcc);
599  }
600 
601  void
603  postModuleStreamCheck(sc, mcc);
604  }
605 
606  std::vector<RandomEngineState> const&
608  return lumiCache_.at(lumiIndex.value());
609  }
610 
611  std::vector<RandomEngineState> const&
613  return eventCache_.at(streamID.value());
614  }
615 
616  void
617  RandomNumberGeneratorService::print(std::ostream& os) const {
618 
619  os << "\n\nRandomNumberGeneratorService dump\n\n";
620 
621  os << " Contents of seedsAndNameMap (label moduleID engineType seeds)\n";
622  for(auto const& entry : seedsAndNameMap_) {
623  os << " " << entry.first
624  << " " << entry.second.moduleID()
625  << " " << entry.second.engineName();
626  for(auto val : entry.second.seeds()) {
627  os << " " << val;
628  }
629  os << "\n";
630  }
631  os << " nStreams_ = " << nStreams_ << "\n";
632  os << " saveFileName_ = " << saveFileName_ << "\n";
633  os << " saveFileNameRecorded_ = " << saveFileNameRecorded_ << "\n";
634  os << " restoreFileName_ = " << restoreFileName_ << "\n";
635  os << " enableChecking_ = " << enableChecking_ << "\n";
636  os << " childIndex_ = " << childIndex_ << "\n";
637  os << " eventSeedOffset_ = " << eventSeedOffset_ << "\n";
638  os << " verbose_ = " << verbose_ << "\n";
639  os << " restoreStateTag_ = " << restoreStateTag_ << "\n";
640  os << " restoreStateBeginLumiTag_ = " << restoreStateBeginLumiTag_ << "\n";
641 
642  os << "\n streamEngines_\n";
643  unsigned int iStream = 0;
644  for(auto const& k : streamEngines_) {
645  os << " Stream " << iStream << "\n";
646  for(auto const& i : k) {
647  os << " " << i.label();
648  for(auto const& j : i.seeds()) {
649  os << " " << j;
650  }
651  os << " " << i.engine()->name();
652  if(i.engine()->name() == std::string("HepJamesRandom")) {
653  os << " " << i.engine()->getSeed();
654  } else {
655  os << " engine does not know seeds";
656  }
657  os << "\n";
658  }
659  ++iStream;
660  }
661  os << "\n lumiEngines_\n";
662  unsigned int iLumi = 0;
663  for(auto const& k : lumiEngines_) {
664  os << " lumiIndex " << iLumi << "\n";
665  for(auto const& i : k) {
666  os << " " << i.label();
667  for(auto const& j : i.seeds()) {
668  os << " " << j;
669  }
670  os << " " << i.engine()->name();
671  if(i.engine()->name() == std::string("HepJamesRandom")) {
672  os << " " << i.engine()->getSeed();
673  } else {
674  os << " engine does not know seeds";
675  }
676  os << "\n";
677  }
678  ++iLumi;
679  }
680  }
681 
682  void
684  if(enableChecking_) {
685  unsigned int moduleID = mcc.moduleDescription()->id();
686  std::vector<ModuleIDToEngine>& moduleIDVector = streamModuleIDToEngine_.at(sc.streamID().value());
687  ModuleIDToEngine target(nullptr, moduleID);
688  std::vector<ModuleIDToEngine>::iterator iter = std::lower_bound(moduleIDVector.begin(),
689  moduleIDVector.end(),
690  target);
691  if(iter != moduleIDVector.end() && iter->moduleID() == moduleID) {
692  LabelAndEngine* labelAndEngine = iter->labelAndEngine();
693  iter->setEngineState(labelAndEngine->engine()->put());
694  }
695  }
696  }
697 
698  void
700  if(enableChecking_) {
701  unsigned int moduleID = mcc.moduleDescription()->id();
702  std::vector<ModuleIDToEngine> const& moduleIDVector = streamModuleIDToEngine_.at(sc.streamID().value());
703  ModuleIDToEngine target(nullptr, moduleID);
704  std::vector<ModuleIDToEngine>::const_iterator iter = std::lower_bound(moduleIDVector.begin(),
705  moduleIDVector.end(),
706  target);
707  if(iter != moduleIDVector.end() && iter->moduleID() == moduleID) {
708  LabelAndEngine* labelAndEngine = iter->labelAndEngine();
709  if(iter->engineState() != labelAndEngine->engine()->put()) {
711  << "It is illegal to generate random numbers during beginStream, endStream,\n"
712  "beginRun, endRun, beginLumi, endLumi because that makes it very difficult\n"
713  "to replay the processing of individual events. Random numbers were\n"
714  "generated during one of these methods for the module with class name\n\""
715  << mcc.moduleDescription()->moduleName() << "\" "
716  "and module label \"" << mcc.moduleDescription()->moduleLabel() << "\"\n";
717  }
718  }
719  }
720  }
721 
722  void
724 
726  if(tns.isAvailable()) {
727  if(tns->getProcessName() == restoreStateTag_.process()) {
729  << "In the configuration for the RandomNumberGeneratorService the\n"
730  << "restoreStateTag contains the current process which is illegal.\n"
731  << "The process name in the replay process should have been changed\n"
732  << "to be different than the original process name and the restoreStateTag\n"
733  << "should contain either the original process name or an empty process name.\n";
734  }
735  }
736 
739 
740  if(!states.isValid()) {
742  << "The RandomNumberGeneratorService is trying to restore\n"
743  << "the state of the random engines by reading a product from\n"
744  << "the LuminosityBlock with input tag \"" << restoreStateBeginLumiTag_ << "\".\n"
745  << "It could not find the product.\n"
746  << "Either the product in the LuminosityBlock was dropped or\n"
747  << "not produced or the configured input tag is incorrect or there is a bug somewhere\n";
748  return;
749  }
750  states->getRandomEngineStates(lumiCache_.at(lumi.index()));
751  }
752 
753  void
755 
757 
758  event.getByLabel(restoreStateTag_, states);
759 
760  if(!states.isValid()) {
762  << "The RandomNumberGeneratorService is trying to restore\n"
763  << "the state of the random engines by reading a product from\n"
764  << "the Event with input tag \"" << restoreStateTag_ << "\".\n"
765  << "It could not find the product.\n"
766  << "Either the product in the Event was dropped or\n"
767  << "not produced or the configured input tag is incorrect or there is a bug somewhere\n";
768  return;
769  }
770  states->getRandomEngineStates(eventCache_.at(event.streamID()));
771  }
772 
773  void
774  RandomNumberGeneratorService::snapShot(std::vector<LabelAndEngine> const& engines, std::vector<RandomEngineState>& cache) {
775  cache.resize(engines.size());
776  std::vector<RandomEngineState>::iterator state = cache.begin();
777 
778  for(std::vector<LabelAndEngine>::const_iterator iter = engines.begin();
779  iter != engines.end();
780  ++iter, ++state) {
781 
782  std::string const& label = iter->label();
783  state->setLabel(label);
784  state->setSeed(iter->seeds());
785 
786  std::vector<unsigned long> stateL = iter->engine()->put();
787  state->clearStateVector();
788  state->reserveStateVector(stateL.size());
789  for(auto element : stateL) {
790  state->push_back_stateVector(static_cast<std::uint32_t>(element));
791  }
792  }
793  }
794 
795  void
796  RandomNumberGeneratorService::restoreFromCache(std::vector<RandomEngineState> const& cache,
797  std::vector<LabelAndEngine>& engines) {
798  std::vector<LabelAndEngine>::iterator labelAndEngine = engines.begin();
799  for(auto const& cachedState : cache) {
800 
801  std::string const& engineLabel = cachedState.getLabel();
802 
803  std::vector<std::uint32_t> const& engineState = cachedState.getState();
804  std::vector<unsigned long> engineStateL;
805  engineStateL.reserve(engineState.size());
806  for(auto const& value : engineState) {
807  engineStateL.push_back(static_cast<unsigned long>(value));
808  }
809 
810  std::vector<std::uint32_t> const& engineSeeds = cachedState.getSeed();
811  std::vector<long> engineSeedsL;
812  engineSeedsL.reserve(engineSeeds.size());
813  for(auto const& val : engineSeeds) {
814  long seedL = static_cast<long>(val);
815  engineSeedsL.push_back(seedL);
816 
817  // There is a dangerous conversion from std::uint32_t to long
818  // that occurs above. In the next 2 lines we check the
819  // behavior is what we need for the service to work
820  // properly. This conversion is forced on us by the
821  // CLHEP and ROOT interfaces. If the assert ever starts
822  // to fail we will have to come up with a way to deal
823  // with this.
824  std::uint32_t seedu32 = static_cast<std::uint32_t>(seedL);
825  assert(val == seedu32);
826  }
827 
828  assert(labelAndEngine != engines.end() && engineLabel == labelAndEngine->label());
829  std::shared_ptr<CLHEP::HepRandomEngine> const& engine = labelAndEngine->engine();
830 
831  // We need to handle each type of engine differently because each
832  // has different requirements on the seed or seeds.
833  if(engineStateL[0] == CLHEP::engineIDulong<CLHEP::HepJamesRandom>()) {
834 
835  checkEngineType(engine->name(), std::string("HepJamesRandom"), engineLabel);
836 
837  // These two lines actually restore the seed and engine state.
838  engine->setSeed(engineSeedsL[0], 0);
839  engine->get(engineStateL);
840 
841  labelAndEngine->setSeed(engineSeeds[0], 0);
842  } else if(engineStateL[0] == CLHEP::engineIDulong<CLHEP::RanecuEngine>()) {
843 
844  checkEngineType(engine->name(), std::string("RanecuEngine"), engineLabel);
845 
846  // This line actually restores the engine state.
847  engine->get(engineStateL);
848 
849  labelAndEngine->setSeed(engineSeeds[0], 0);
850  labelAndEngine->setSeed(engineSeeds[1], 1);
851  } else if(engineStateL[0] == CLHEP::engineIDulong<TRandomAdaptor>()) {
852 
853  checkEngineType(engine->name(), std::string("TRandom3"), engineLabel);
854 
855  // This line actually restores the engine state.
856  engine->setSeed(engineSeedsL[0], 0);
857  engine->get(engineStateL);
858 
859  labelAndEngine->setSeed(engineSeeds[0], 0);
860  } else {
861  // This should not be possible because this code should be able to restore
862  // any kind of engine whose state can be saved.
864  << "The RandomNumberGeneratorService is trying to restore the state\n"
865  "of the random engines. The state in the event indicates an engine\n"
866  "of an unknown type. This should not be possible unless you are\n"
867  "running with an old code release on a new file that was created\n"
868  "with a newer release which had new engine types added. In this case\n"
869  "the only solution is to use a newer release. In any other case, notify\n"
870  "the EDM developers because this should not be possible\n";
871  }
872  ++labelAndEngine;
873  }
874  }
875 
876  void
878  std::string const& typeFromEvent,
879  std::string const& engineLabel) const {
880  if(typeFromConfig != typeFromEvent) {
882  << "The RandomNumberGeneratorService is trying to restore\n"
883  << "the state of the random engine for the module \""
884  << engineLabel << "\". An\n"
885  << "error was detected because the type of the engine in the\n"
886  << "input file and the configuration file do not match.\n"
887  << "In the configuration file the type is \"" << typeFromConfig
888  << "\".\nIn the input file the type is \"" << typeFromEvent << "\". If\n"
889  << "you are not generating any random numbers in this module, then\n"
890  << "remove the line in the configuration file that gives it\n"
891  << "a seed and the error will go away. Otherwise, you must give\n"
892  << "this module the same engine type in the configuration file or\n"
893  << "stop trying to restore the random engine state.\n";
894  }
895  }
896 
897  void
899  StreamID const& streamID,
900  LuminosityBlockIndex const& lumiIndex) {
901 
902  std::ofstream& outFile = *outFiles_.at(streamID);
903 
904  if(!outFile.is_open()) {
905  std::stringstream file;
906  file << fileName;
907  if(nStreams_ > 1) {
908  file << "_" << streamID.value();
909  }
910 
911  outFile.open(file.str().c_str(), std::ofstream::out | std::ofstream::trunc);
912 
913  if(!outFile) {
915  << "Unable to open the file \""
916  << file.str() << "\" to save the state of the random engines.\n";
917  }
918  }
919 
920  outFile.seekp(0, std::ios_base::beg);
921  outFile << "<RandomEngineStates>\n";
922 
923  outFile << "<Event>\n";
924  writeStates(eventCache_.at(streamID), outFile);
925  outFile << "</Event>\n";
926 
927  outFile << "<Lumi>\n";
928  writeStates(lumiCache_.at(lumiIndex), outFile);
929  outFile << "</Lumi>\n";
930 
931  outFile << "</RandomEngineStates>\n";
932  outFile.flush();
933  }
934 
935  void
936  RandomNumberGeneratorService::writeStates(std::vector<RandomEngineState> const& v,
937  std::ofstream& outFile) {
938  for(std::vector<RandomEngineState>::const_iterator iter = v.begin(),
939  iEnd = v.end();
940  iter != iEnd; ++iter) {
941 
942  std::vector<std::uint32_t> const& seedVector = iter->getSeed();
943  std::vector<std::uint32_t>::size_type seedVectorLength = seedVector.size();
944 
945  std::vector<std::uint32_t> const& stateVector = iter->getState();
946  std::vector<std::uint32_t>::size_type stateVectorLength = stateVector.size();
947 
948  outFile << "<ModuleLabel>\n" << iter->getLabel() << "\n</ModuleLabel>\n";
949 
950  outFile << "<SeedLength>\n" << seedVectorLength << "\n</SeedLength>\n" ;
951  outFile << "<InitialSeeds>\n";
952  writeVector(seedVector, outFile);
953  outFile << "</InitialSeeds>\n";
954  outFile << "<FullStateLength>\n" << stateVectorLength << "\n</FullStateLength>\n";
955  outFile << "<FullState>\n";
956  writeVector(stateVector, outFile);
957  outFile << "</FullState>\n";
958  }
959  }
960 
961  void
963  std::ofstream& outFile) {
964  if(v.empty()) return;
965  size_t numItems = v.size();
966  for(size_t i = 0; i < numItems; ++i) {
967  if(i != 0 && i % 10 == 0) outFile << "\n";
968  outFile << std::setw(13) << v[i];
969  }
970  outFile << "\n";
971  }
972 
974  char directory[1500];
975  std::string fullName(getcwd(directory, sizeof(directory)) ? directory : "/PathIsTooBig");
976  fullName += "/" + saveFileName_;
977  return fullName;
978  }
979 
980  void
982  std::vector<RandomEngineState>& cache) {
983  std::string whichStates("<Event>");
984  readStatesFromFile(fileName, cache, whichStates);
985  }
986 
987  void
989  std::vector<RandomEngineState>& cache) {
990  std::string whichStates("<Lumi>");
991  readStatesFromFile(fileName, cache, whichStates);
992  }
993 
994 
995  void
997  std::vector<RandomEngineState>& cache,
998  std::string const& whichStates) {
999  std::ifstream inFile;
1000  inFile.open(fileName.c_str(), std::ifstream::in);
1001  if(!inFile) {
1003  << "Unable to open the file \""
1004  << fileName << "\" to restore the random engine states.\n";
1005  }
1006 
1007  std::string text;
1008  inFile >> text;
1009  if(!inFile.good() || text != std::string("<RandomEngineStates>")) {
1011  << "Attempting to read file with random number engine states.\n"
1012  << "File \"" << restoreFileName_
1013  << "\" is ill-structured or otherwise corrupted.\n"
1014  << "Cannot read the file header word.\n";
1015  }
1016  bool saveToCache = false;
1017  while(readEngineState(inFile, cache, whichStates, saveToCache)) {}
1018  }
1019 
1021  std::vector<RandomEngineState>& cache,
1022  std::string const& whichStates,
1023  bool& saveToCache) {
1024  std::string leading;
1025  std::string trailing;
1026  std::string moduleLabel;
1028  std::vector<std::uint32_t> seedVector;
1029  std::vector<std::uint32_t>::size_type stateVectorSize;
1030  std::vector<std::uint32_t> stateVector;
1031 
1032  // First we need to look for the special strings
1033  // that mark the end of the file and beginning and
1034  // and end of the data for different sections.
1035 
1036  is >> leading;
1037  if(!is.good()) {
1039  << "File \"" << restoreFileName_
1040  << "\" is ill-structured or otherwise corrupted.\n"
1041  << "Cannot read next field and did not hit the end yet.\n";
1042  }
1043 
1044  // This marks the end of the file. We are done.
1045  if(leading == std::string("</RandomEngineStates>")) return false;
1046 
1047  // This marks the end of a section of the data
1048  if(leading == std::string("</Event>") ||
1049  leading == std::string("</Lumi>")) {
1050  saveToCache = false;
1051  return true;
1052  }
1053 
1054  // This marks the beginning of a section
1055  if(leading == std::string("<Event>") ||
1056  leading == std::string("<Lumi>")) {
1057  saveToCache = (leading == whichStates);
1058  return true;
1059  }
1060 
1061  // Process the next engine state
1062 
1063  is >> moduleLabel >> trailing;
1064  if(!is.good() ||
1065  leading != std::string("<ModuleLabel>") ||
1066  trailing != std::string("</ModuleLabel>")) {
1068  << "File \"" << restoreFileName_
1069  << "\" is ill-structured or otherwise corrupted.\n"
1070  << "Cannot read a module label when restoring random engine states.\n";
1071  }
1072 
1073  is >> leading >> seedVectorSize >> trailing;
1074  if(!is.good() ||
1075  leading != std::string("<SeedLength>") ||
1076  trailing != std::string("</SeedLength>")) {
1078  << "File \"" << restoreFileName_
1079  << "\" is ill-structured or otherwise corrupted.\n"
1080  << "Cannot read seed vector length when restoring random engine states.\n";
1081  }
1082 
1083  is >> leading;
1084  if(!is.good() ||
1085  leading != std::string("<InitialSeeds>")) {
1087  << "File \"" << restoreFileName_
1088  << "\" is ill-structured or otherwise corrupted.\n"
1089  << "Cannot read beginning of InitialSeeds when restoring random engine states.\n";
1090  }
1091 
1092  if(seedVectorSize > maxSeeds) {
1094  << "File \"" << restoreFileName_
1095  << "\" is ill-structured or otherwise corrupted.\n"
1096  << "The number of seeds exceeds 64K.\n";
1097  }
1098 
1099  readVector(is, seedVectorSize, seedVector);
1100 
1101  is >> trailing;
1102  if(!is.good() ||
1103  trailing != std::string("</InitialSeeds>")) {
1105  << "File \"" << restoreFileName_
1106  << "\" is ill-structured or otherwise corrupted.\n"
1107  << "Cannot read end of InitialSeeds when restoring random engine states.\n";
1108  }
1109 
1110  is >> leading >> stateVectorSize >> trailing;
1111  if(!is.good() ||
1112  leading != std::string("<FullStateLength>") ||
1113  trailing != std::string("</FullStateLength>")) {
1115  << "File \"" << restoreFileName_
1116  << "\" is ill-structured or otherwise corrupted.\n"
1117  << "Cannot read state vector length when restoring random engine states.\n";
1118  }
1119 
1120  is >> leading;
1121  if(!is.good() ||
1122  leading != std::string("<FullState>")) {
1124  << "File \"" << restoreFileName_
1125  << "\" is ill-structured or otherwise corrupted.\n"
1126  << "Cannot read beginning of FullState when restoring random engine states.\n";
1127  }
1128 
1129  if(stateVectorSize > maxStates) {
1131  << "File \"" << restoreFileName_
1132  << "\" is ill-structured or otherwise corrupted.\n"
1133  << "The number of states exceeds 64K.\n";
1134  }
1135 
1136  readVector(is, stateVectorSize, stateVector);
1137 
1138  is >> trailing;
1139  if(!is.good() ||
1140  trailing != std::string("</FullState>")) {
1142  << "File \"" << restoreFileName_
1143  << "\" is ill-structured or otherwise corrupted.\n"
1144  << "Cannot read end of FullState when restoring random engine states.\n";
1145  }
1146 
1147  if(saveToCache) {
1148  RandomEngineState randomEngineState;
1149  randomEngineState.setLabel(moduleLabel);
1150  std::vector<RandomEngineState>::iterator state =
1151  std::lower_bound(cache.begin(), cache.end(), randomEngineState);
1152 
1153  if(state != cache.end() && moduleLabel == state->getLabel()) {
1154  if(seedVector.size() != state->getSeed().size() ||
1155  stateVector.size() != state->getState().size()) {
1157  << "File \"" << restoreFileName_
1158  << "\" is ill-structured or otherwise corrupted.\n"
1159  << "Vectors containing engine state are the incorrect size for the type of random engine.\n";
1160  }
1161  state->setSeed(seedVector);
1162  state->setState(stateVector);
1163  }
1164  }
1165  return true;
1166  }
1167 
1168  void
1169  RandomNumberGeneratorService::readVector(std::istream& is, unsigned numItems, std::vector<std::uint32_t>& v) {
1170  v.clear();
1171  v.reserve(numItems);
1172  std::uint32_t data;
1173  for(unsigned i = 0; i < numItems; ++i) {
1174  is >> data;
1175  if(!is.good()) {
1177  << "File \"" << restoreFileName_
1178  << "\" is ill-structured or otherwise corrupted.\n"
1179  << "Cannot read vector when restoring random engine states.\n";
1180  }
1181  v.push_back(data);
1182  }
1183  }
1184 
1185  void
1186  RandomNumberGeneratorService::createEnginesInVector(std::vector<LabelAndEngine>& engines,
1187  unsigned int seedOffset,
1188  unsigned int eventSeedOffset,
1189  std::vector<ModuleIDToEngine>& moduleIDVector) {
1190  // The vectors we will fill here will be the same size as
1191  // or smaller than seedsAndNameMap_.
1192  engines.reserve(seedsAndNameMap_.size());
1193  moduleIDVector.reserve(seedsAndNameMap_.size());
1194 
1195  for(auto const& i : seedsAndNameMap_) {
1196  unsigned int moduleID = i.second.moduleID();
1197  if(moduleID != std::numeric_limits<unsigned int>::max()) {
1198  std::string const& label = i.first;
1199  std::string const& name = i.second.engineName();
1200  VUint32 const& seeds = i.second.seeds();
1201 
1202  if(name == "RanecuEngine") {
1203  std::shared_ptr<CLHEP::HepRandomEngine> engine(new CLHEP::RanecuEngine());
1204  engines.emplace_back(label, seeds, engine);
1205  resetEngineSeeds(engines.back(), name, seeds, seedOffset, eventSeedOffset);
1206  }
1207  // For the other engines, one seed is required
1208  else {
1209  long int seedL = static_cast<long int>(seeds[0]);
1210 
1211  if(name == "HepJamesRandom") {
1212  std::shared_ptr<CLHEP::HepRandomEngine> engine(new CLHEP::HepJamesRandom(seedL));
1213  engines.emplace_back(label, seeds, engine);
1214  if(seedOffset != 0 || eventSeedOffset != 0) {
1215  resetEngineSeeds(engines.back(), name, seeds, seedOffset, eventSeedOffset);
1216  }
1217  } else { // TRandom3, currently the only other possibility
1218 
1219  // There is a dangerous conversion from std::uint32_t to long
1220  // that occurs above. In the next 2 lines we check the
1221  // behavior is what we need for the service to work
1222  // properly. This conversion is forced on us by the
1223  // CLHEP and ROOT interfaces. If the assert ever starts
1224  // to fail we will have to come up with a way to deal
1225  // with this.
1226  std::uint32_t seedu32 = static_cast<std::uint32_t>(seedL);
1227  assert(seeds[0] == seedu32);
1228 
1229  std::shared_ptr<CLHEP::HepRandomEngine> engine(new TRandomAdaptor(seedL));
1230  engines.emplace_back(label, seeds, engine);
1231  if(seedOffset != 0 || eventSeedOffset != 0) {
1232  resetEngineSeeds(engines.back(), name, seeds, seedOffset, eventSeedOffset);
1233  }
1234  }
1235  }
1236  moduleIDVector.emplace_back(&engines.back(), moduleID);
1237  } // if moduleID valid
1238  } // loop over seedsAndMap
1239  std::sort(moduleIDVector.begin(), moduleIDVector.end());
1240  }
1241 
1242  void
1244  std::string const& engineName,
1245  VUint32 const& seeds,
1246  std::uint32_t offset1,
1247  std::uint32_t offset2) {
1248 
1249  if(engineName == "RanecuEngine") {
1250  assert(seeds.size() == 2U);
1251  // Wrap around if the offsets push the seed over the maximum allowed value
1252  std::uint32_t mod = maxSeedRanecu + 1U;
1253  offset1 %= mod;
1254  offset2 %= mod;
1255  std::uint32_t seed0 = (seeds[0] + offset1) % mod;
1256  seed0 = (seed0 + offset2) % mod;
1257  labelAndEngine.setSeed(seed0, 0);
1258  labelAndEngine.setSeed(seeds[1], 1);
1259  long int seedL[2];
1260  seedL[0] = static_cast<long int>(seed0);
1261  seedL[1] = static_cast<long int>(seeds[1]);
1262  labelAndEngine.engine()->setSeeds(seedL,0);
1263  } else {
1264  assert(seeds.size() == 1U);
1265 
1266  if(engineName == "HepJamesRandom") {
1267  // Wrap around if the offsets push the seed over the maximum allowed value
1268  std::uint32_t mod = maxSeedHepJames + 1U;
1269  offset1 %= mod;
1270  offset2 %= mod;
1271  std::uint32_t seed0 = (seeds[0] + offset1) % mod;
1272  seed0 = (seed0 + offset2) % mod;
1273  labelAndEngine.setSeed(seed0, 0);
1274 
1275  long int seedL = static_cast<long int>(seed0);
1276  labelAndEngine.engine()->setSeed(seedL, 0);
1277  } else {
1278  assert(engineName == "TRandom3");
1279  // Wrap around if the offsets push the seed over the maximum allowed value
1280  // We have to be extra careful with this one because it may also go beyond
1281  // the values 32 bits can hold
1282  std::uint32_t max32 = maxSeedTRandom3;
1283  std::uint32_t seed0 = seeds[0];
1284  if((max32 - seed0) >= offset1) {
1285  seed0 += offset1;
1286  } else {
1287  seed0 = offset1 - (max32 - seed0) - 1U;
1288  }
1289  if((max32 - seed0) >= offset2) {
1290  seed0 += offset2;
1291  } else {
1292  seed0 = offset2 - (max32 - seed0) - 1U;
1293  }
1294  labelAndEngine.setSeed(seed0, 0);
1295 
1296  long seedL = static_cast<long>(seed0);
1297 
1298  // There is a dangerous conversion from std::uint32_t to long
1299  // that occurs above. In the next 2 lines we check the
1300  // behavior is what we need for the service to work
1301  // properly. This conversion is forced on us by the
1302  // CLHEP and ROOT interfaces. If the assert ever starts
1303  // to fail we will have to come up with a way to deal
1304  // with this.
1305  std::uint32_t seedu32 = static_cast<std::uint32_t>(seedL);
1306  assert(seed0 == seedu32);
1307 
1308  labelAndEngine.engine()->setSeed(seedL, 0);
1309  }
1310  }
1311  }
1312  }
1313 }
void watchPostModuleConstruction(PostModuleConstruction::slot_type const &iSlot)
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)
int i
Definition: DBlmapReader.cc:9
void readVector(std::istream &is, unsigned numItems, std::vector< std::uint32_t > &v)
void watchPreallocate(Preallocate::slot_type const &iSlot)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
LuminosityBlockIndex index() const
std::shared_ptr< CLHEP::HepRandomEngine > const & engine() const
void postModuleEndJob(ModuleDescription const &description)
void watchPostModuleEndStream(PostModuleEndStream::slot_type const &iSlot)
void watchPreModuleConstruction(PreModuleConstruction::slot_type const &iSlot)
tuple lumi
Definition: fjr2json.py:35
string emptyString
Definition: archive.py:29
void setLabel(const std::string &value)
bool exists(std::string const &parameterName) const
checks if a parameter exists
static ModuleCallingContext const * getCurrentModuleOnThread()
std::string const & moduleName() 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)
std::vector< std::shared_ptr< std::ofstream > > outFiles_
void resetEngineSeeds(LabelAndEngine &labelAndEngine, std::string const &engineName, VUint32 const &seeds, std::uint32_t offset1, std::uint32_t offset2)
void preModuleBeginJob(ModuleDescription const &description)
bool getByLabel(std::string const &label, Handle< PROD > &result) const
void readFromLuminosityBlock(LuminosityBlock const &lumi)
std::string const & moduleLabel() const
uint16_t size_type
void preModuleBeginStream(StreamContext const &sc, ModuleCallingContext const &mcc)
void postModuleStreamBeginRun(StreamContext const &sc, ModuleCallingContext const &mcc)
void snapShot(std::vector< LabelAndEngine > const &engines, std::vector< RandomEngineState > &cache)
void postModuleEndStream(StreamContext const &sc, ModuleCallingContext const &mcc)
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:192
unsigned int maxNumberOfStreams() const
Definition: SystemBounds.h:43
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)
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)
static const std::string kSkipCurrentProcess
Definition: InputTag.h:56
ModuleDescription const * moduleDescription() const
bool isAvailable() const
Definition: Service.h:46
virtual void print(std::ostream &os) const override
For debugging.
int j
Definition: DBlmapReader.cc:9
std::vector< std::vector< LabelAndEngine > > streamEngines_
std::vector< std::vector< RandomEngineState > > eventCache_
void watchPreModuleEndJob(PreModuleEndJob::slot_type const &iSlot)
unsigned int value() const
tuple text
Definition: runonSM.py:42
void readStatesFromFile(std::string const &fileName, std::vector< RandomEngineState > &cache, std::string const &whichStates)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:76
void readEventStatesFromTextFile(std::string const &fileName, std::vector< RandomEngineState > &cache)
void watchPreModuleBeginJob(PreModuleBeginJob::slot_type const &iSlot)
std::vector< std::vector< RandomEngineState > > lumiCache_
void postModuleBeginJob(ModuleDescription const &description)
static const std::vector< std::uint32_t >::size_type maxStates
void watchPostModuleStreamEndRun(PostModuleStreamEndRun::slot_type const &iSlot)
int k[5][pyjets_maxn]
StreamID const & streamID() const
Definition: StreamContext.h:57
tuple out
Definition: dbtoconf.py:99
void preModuleStreamEndRun(StreamContext const &sc, ModuleCallingContext const &mcc)
void watchPreModuleStreamBeginLumi(PreModuleStreamBeginLumi::slot_type const &iSlot)
tuple description
Definition: idDealer.py:66
virtual std::uint32_t mySeed() const override
void watchPostModuleBeginStream(PostModuleBeginStream::slot_type const &iSlot)
unsigned int value() const
Definition: StreamID.h:46
string fullName
unsigned int maxNumberOfConcurrentLuminosityBlocks() const
Definition: SystemBounds.h:45
void watchPostModuleStreamBeginLumi(PostModuleStreamBeginLumi::slot_type const &iSlot)
ParameterSet const & getParameterSet(std::string const &) const
void preModuleEndJob(ModuleDescription const &description)
void watchPreModuleStreamEndLumi(PreModuleStreamEndLumi::slot_type const &iSlot)
void checkEngineType(std::string const &typeFromConfig, std::string const &typeFromEvent, std::string const &engineLabel) const
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &streamID) const override
Use this engine in event methods.
void watchPreModuleStreamBeginRun(PreModuleStreamBeginRun::slot_type const &iSlot)
void postForkReacquireResources(unsigned childIndex, unsigned kMaxChildren)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void watchPreModuleEndStream(PreModuleEndStream::slot_type const &iSlot)
void postModuleConstruction(ModuleDescription const &description)
std::string const & label() const
Definition: InputTag.h:42
void postModuleStreamEndLumi(StreamContext const &sc, ModuleCallingContext const &mcc)
std::string const & process() const
Definition: InputTag.h:46
void watchPostForkReacquireResources(PostForkReacquireResources::slot_type const &iSlot)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
virtual void postEventRead(Event const &event) override
virtual std::vector< RandomEngineState > const & getLumiCache(LuminosityBlockIndex const &) const override
These two are used by the RandomEngineStateProducer.
void watchPreModuleStreamEndRun(PreModuleStreamEndRun::slot_type const &iSlot)
void writeVector(VUint32 const &v, std::ofstream &outFile)
static const std::vector< std::uint32_t >::size_type maxSeeds
void watchPostModuleBeginJob(PostModuleBeginJob::slot_type const &iSlot)
StreamID streamID() const
Definition: Event.h:75
tuple cout
Definition: gather_cfg.py:121
void readLumiStatesFromTextFile(std::string const &fileName, std::vector< RandomEngineState > &cache)
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel, T const &value)
void restoreFromCache(std::vector< RandomEngineState > const &cache, std::vector< LabelAndEngine > &engines)
volatile std::atomic< bool > shutdown_flag false
std::vector< std::vector< LabelAndEngine > > lumiEngines_
void postModuleBeginStream(StreamContext const &sc, ModuleCallingContext const &mcc)
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
std::map< std::string, SeedsAndName > seedsAndNameMap_
std::vector< std::vector< ModuleIDToEngine > > lumiModuleIDToEngine_
void preModuleStreamCheck(StreamContext const &sc, ModuleCallingContext const &mcc)
virtual void preBeginLumi(LuminosityBlock const &lumi) override
void watchPostModuleEndJob(PostModuleEndJob::slot_type const &iSlot)
virtual std::vector< RandomEngineState > const & getEventCache(StreamID const &) const override
void postModuleStreamBeginLumi(StreamContext const &sc, ModuleCallingContext const &mcc)
unsigned int id() const