#include <RandomNumberGenerator.h>
Definition at line 158 of file RandomNumberGenerator.h.
Definition at line 118 of file RandomNumberGenerator.cc.
129 actReg.sPreProcessEvent.watch(
this,
std::string const restoreFromFilename_
PerScheduleContainer< ScheduleData > data_
std::string const saveToFilename_
Atom< std::string > restoreStateLabel
void preProcessEvent(Event const &, ScheduleContext)
Atom< std::string > restoreFrom
std::string const defaultEngineKind_
Atom< std::string > saveTo
static Globals * instance()
Atom< std::string > defaultEngineKind
std::string const restoreStateLabel_
Definition at line 259 of file RandomNumberGenerator.cc.
261 std::lock_guard sentry{
mutex_};
262 return data_[sid].snapshot_;
PerScheduleContainer< ScheduleData > data_
std::recursive_mutex mutex_
Definition at line 135 of file RandomNumberGenerator.cc.
141 std::lock_guard sentry{
mutex_};
144 <<
"RNGservice::createEngine():\n" 145 <<
"Attempt to create engine \"" << engine_label <<
"\" is too late.\n";
147 if (sid.id() >=
data_.size()) {
149 <<
"RNGservice::createEngine():\n" 150 <<
"Attempt to create engine with out-of-range ScheduleID: " << sid
153 string const&
label = qualify_engine_label(sid, module_label, engine_label);
154 if (
data_[sid].tracker_.find(label) !=
data_[sid].tracker_.cend()) {
156 <<
"RNGservice::createEngine():\n" 157 <<
"Engine \"" << label <<
"\" has already been created.\n";
159 string engineKind{requested_engine_kind};
160 if (requested_engine_kind.empty()) {
166 shared_ptr<CLHEP::HepRandomEngine> eptr;
167 if (engineKind ==
"G4Engine"s) {
171 CLHEP::HepRandom::setTheEngine(eptr.get());
173 CLHEP::HepRandom::setTheSeed(seed);
175 }
else if (engineKind ==
"NonRandomEngine"s) {
176 eptr = std::make_shared<CLHEP::NonRandomEngine>();
178 eptr = engine_factory(engineKind, seed);
182 <<
"RNGservice::createEngine():\n" 183 <<
"Engine \"" << label <<
"\" could not be created.\n";
188 mf::LogInfo{
"RANDOM"} <<
"Instantiated " << engineKind <<
" engine \"" 189 << label <<
"\" with " 194 "RNGservice::createEngine() invariant failed");
PerScheduleContainer< ScheduleData > data_
static long constexpr useDefaultSeed
std::recursive_mutex mutex_
bool invariant_holds_(ScheduleID)
void validate_(std::string const &user_specified_engine_kind, long user_specified_seed) noexcept(false)
std::string const defaultEngineKind_
bool engine_creation_is_okay_
cet::coded_exception< error, detail::translate > exception
std::string const& art::RandomNumberGenerator::defaultEngineKind |
( |
| ) |
const |
|
inlinenoexcept |
Definition at line 111 of file RandomNumberGenerator.cc.
113 std::lock_guard sentry{
mutex_};
114 return (
data_[sid].dict_.size() ==
data_[sid].tracker_.size()) &&
115 (
data_[sid].dict_.size() ==
data_[sid].kind_.size());
PerScheduleContainer< ScheduleData > data_
std::recursive_mutex mutex_
void art::RandomNumberGenerator::postBeginJob |
( |
| ) |
|
|
private |
void art::RandomNumberGenerator::postEndJob |
( |
| ) |
|
|
private |
Definition at line 438 of file RandomNumberGenerator.cc.
442 std::lock_guard sentry{
mutex_};
443 ScheduleIteration iteration(
data_.size());
444 iteration.for_each_schedule(
PerScheduleContainer< ScheduleData > data_
std::recursive_mutex mutex_
void takeSnapshot_(ScheduleID)
Definition at line 428 of file RandomNumberGenerator.cc.
431 auto const sid = sc.id();
432 std::lock_guard sentry{
mutex_};
void restoreSnapshot_(ScheduleID, Event const &)
std::recursive_mutex mutex_
void takeSnapshot_(ScheduleID)
void art::RandomNumberGenerator::print_ |
( |
| ) |
const |
|
private |
Definition at line 235 of file RandomNumberGenerator.cc.
237 std::lock_guard sentry{
mutex_};
238 static unsigned ncalls = 0;
242 auto print_per_stream = [](
size_t const i,
auto const&
d) {
244 if (
d.snapshot_.empty()) {
245 log <<
"No snapshot has yet been made.\n";
248 log <<
"Snapshot information:";
249 for (
auto const& ss :
d.snapshot_) {
250 log <<
"\nEngine: " << ss.label() <<
" Kind: " << ss.ekind()
251 <<
" Schedule ID: " << i <<
" State size: " << ss.state().size();
void for_all_with_index(FwdCont &, Func)
PerScheduleContainer< ScheduleData > data_
std::recursive_mutex mutex_
void art::RandomNumberGenerator::restoreFromFile_ |
( |
| ) |
|
|
private |
Definition at line 359 of file RandomNumberGenerator.cc.
361 std::lock_guard sentry{
mutex_};
365 HEP_CONCURRENCY_ASSERT_ONLY_ONE_THREAD();
370 <<
"RNGservice::restoreFromFile_():\n" 372 <<
"\" to initialize engines\n";
377 assert(
count(label.cbegin(), label.cend(),
':') == 2u);
378 auto const p1 = label.find_first_of(
':');
379 auto const p2 = label.find_last_of(
':');
380 ScheduleID
const sid{
382 auto d =
data_[sid].dict_.find(label);
383 if (
d ==
data_[sid].dict_.end()) {
385 <<
"Attempt to restore an engine with label " << label
386 <<
" not configured in this job.\n";
388 assert((
data_[sid].tracker_.find(label) !=
data_[sid].tracker_.cend()) &&
389 "RNGservice::restoreFromFile_()");
392 auto& eptr =
d->second;
393 assert(eptr &&
"RNGservice::restoreFromFile_()");
396 <<
"RNGservice::restoreFromFile_():\n" 397 <<
"Failed during restore of state of engine for label " << label
403 <<
"Engine state file contains two engine states with the same " 408 <<
"Internal error: attempt to restore an engine state " << label
410 <<
"which was originally initialized via an unknown or impossible " 414 "RNGservice::restoreFromFile_() invariant failure");
std::string const restoreFromFilename_
PerScheduleContainer< ScheduleData > data_
std::recursive_mutex mutex_
bool invariant_holds_(ScheduleID)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
cet::coded_exception< error, detail::translate > exception
void art::RandomNumberGenerator::restoreSnapshot_ |
( |
ScheduleID |
sid, |
|
|
Event const & |
event |
|
) |
| |
|
private |
Definition at line 284 of file RandomNumberGenerator.cc.
287 std::lock_guard sentry{
mutex_};
295 for (
auto const& snapshot : saved) {
296 string const&
label = snapshot.label();
298 log <<
"RNGservice::restoreSnapshot_(): label \"" << label <<
"\"";
299 auto t =
data_[sid].tracker_.find(label);
300 if (
t ==
data_[sid].tracker_.end()) {
301 log <<
" could not be restored;\n" 302 <<
"no established engine bears this label.\n";
307 <<
"RNGservice::restoreSnapshot_():\n" 308 <<
"The state of engine \"" << label
309 <<
"\" has been previously read from a file;\n" 310 <<
"it is therefore not restorable from a snapshot product.\n";
312 shared_ptr<CLHEP::HepRandomEngine> ep{
data_[sid].dict_[
label]};
313 assert(ep &&
"RNGservice::restoreSnapshot_()");
315 auto const& est = snapshot.restoreState();
317 log <<
" successfully restored.\n";
320 <<
"RNGservice::restoreSnapshot_():\n" 321 <<
"Failed during restore of state of engine for \"" << label
PerScheduleContainer< ScheduleData > data_
std::recursive_mutex mutex_
bool invariant_holds_(ScheduleID)
cet::coded_exception< error, detail::translate > exception
std::string const restoreStateLabel_
void art::RandomNumberGenerator::saveToFile_ |
( |
| ) |
|
|
private |
Definition at line 329 of file RandomNumberGenerator.cc.
331 std::lock_guard sentry{
mutex_};
335 HEP_CONCURRENCY_ASSERT_ONLY_ONE_THREAD();
343 for (
auto const&
d :
data_) {
344 for (
auto const& pr :
d.dict_) {
346 auto const& eptr = pr.second;
347 assert(eptr &&
"RNGservice::saveToFile_()");
351 <<
"This module's engine has not been saved;\n"
PerScheduleContainer< ScheduleData > data_
std::recursive_mutex mutex_
std::string const saveToFilename_
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void art::RandomNumberGenerator::takeSnapshot_ |
( |
ScheduleID |
sid | ) |
|
|
private |
Definition at line 266 of file RandomNumberGenerator.cc.
268 std::lock_guard sentry{
mutex_};
270 log <<
"RNGservice::takeSnapshot_() of the following engine labels:\n";
271 data_[sid].snapshot_.clear();
272 for (
auto const& pr :
data_[sid].dict_) {
273 string const&
label = pr.first;
274 shared_ptr<CLHEP::HepRandomEngine>
const& eptr = pr.second;
275 assert(eptr &&
"RNGservice::takeSnapshot_()");
276 data_[sid].snapshot_.emplace_back(
277 data_[sid].kind_[label], label, eptr->put());
278 log <<
" | " <<
label;
PerScheduleContainer< ScheduleData > data_
std::recursive_mutex mutex_
void art::RandomNumberGenerator::validate_ |
( |
std::string const & |
user_specified_engine_kind, |
|
|
long |
user_specified_seed |
|
) |
| |
|
privatenoexcept |
Definition at line 199 of file RandomNumberGenerator.cc.
209 if (user_specified_seed < 0) {
210 throw cet::exception(
"RANGE") <<
"RNGservice::throw_if_invalid_seed():\n" 211 <<
"Seed " << user_specified_seed
212 <<
" is not permitted to be negative.\n";
220 if (user_specified_engine_kind ==
"MixMaxRng"s)
223 if (user_specified_engine_kind ==
"G4Engine"s &&
228 <<
"RNGservice::throw_if_invalid_seed():\n" 229 <<
"Seed " << user_specified_seed <<
" exceeds permitted maximum of " 230 <<
maxCLHEPSeed <<
" for engine type " << user_specified_engine_kind
static long constexpr maxCLHEPSeed
static long constexpr useDefaultSeed
std::string const defaultEngineKind_
cet::coded_exception< error, detail::translate > exception
bool const art::RandomNumberGenerator::debug_ |
|
private |
std::string const art::RandomNumberGenerator::defaultEngineKind_ |
|
private |
bool art::RandomNumberGenerator::engine_creation_is_okay_ {true} |
|
private |
long constexpr art::RandomNumberGenerator::maxCLHEPSeed {900000000} |
|
static |
std::recursive_mutex art::RandomNumberGenerator::mutex_ {} |
|
mutableprivate |
unsigned const art::RandomNumberGenerator::nPrint_ |
|
private |
std::string const art::RandomNumberGenerator::restoreFromFilename_ |
|
private |
std::string const art::RandomNumberGenerator::restoreStateLabel_ |
|
private |
std::string const art::RandomNumberGenerator::saveToFilename_ |
|
private |
long constexpr art::RandomNumberGenerator::useDefaultSeed {-1} |
|
static |
The documentation for this class was generated from the following files: