25 #include "CLHEP/Random/RandomEngine.h" 38 , verbosity(paramSet.
get<int>(
"verbosity", 0))
39 , bPrintEndOfJobSummary(paramSet.
get<bool>(
"endOfJobSummary",false))
62 (std::string moduleLabel, std::string instanceName)
const 63 {
return { moduleLabel, instanceName }; }
66 (std::string instanceName )
const 85 <<
"NuRandomService::getGlobalSeed(\"" << instanceName <<
"\")";
123 return {
seed,
true };
140 <<
"Seeding " << type <<
" engine \"" <<
id.artName()
141 <<
"\" with seed " << seed <<
".";
151 <<
"Seeding default-type engine \"" <<
id.artName()
152 <<
"\" with seed " << seed <<
".";
164 std::pair<seed_t, bool> seedInfo =
findSeed(
id, pset, pnames);
167 <<
"Seeding " << type <<
" engine \"" <<
id.artName()
168 <<
"\" with seed " << seedInfo.first <<
".";
169 if (seedInfo.second)
freezeSeed(
id, seedInfo.first);
170 return seedInfo.first;
180 std::pair<seed_t, bool> seedInfo =
findSeed(
id, pset, pnames);
183 <<
"Seeding default-type engine \"" <<
id.artName()
184 <<
"\" with seed " << seedInfo.first <<
".";
185 if (seedInfo.second)
freezeSeed(
id, seedInfo.first);
186 return seedInfo.first;
203 std::pair<seed_t, bool> seedInfo =
findSeed(
id, pset, pnames);
205 if (seedInfo.second)
freezeSeed(
id, seedInfo.first);
217 std::string instance,
246 <<
"Attempted to define engine '" <<
id.artName()
247 <<
"', that was not declared\n";
252 <<
"Attempted to redefine engine '" <<
id.artName()
253 <<
"', that has already been defined\n";
272 <<
"NuRandomService: not in a service constructor." 273 <<
" May not register \"global\" engines.\n";
285 <<
"NuRandomService: not in a module constructor." 286 <<
" May not register engines.\n";
300 <<
"No random seed specific to this event for engine '" <<
id <<
"'";
303 mf::LogInfo(
"NuRandomService") <<
"Random seed for this event, engine '" 304 <<
id <<
"': " <<
seed;
312 if (ID.moduleLabel != currentModule)
continue;
322 if (!ID.isGlobal())
continue;
335 CLHEP::HepRandomEngine& engine = rng->
getEngine(
id.instanceName);
336 engine.setSeed(seed, 0);
349 <<
"NuRandomService: an engine with ID '" <<
id.artName()
350 <<
"' has already been created!\n";
373 std::initializer_list<std::string> pnames
375 for (std::string
const& key: pnames)
407 LOG_DEBUG(
"NuRandomService") <<
"preProcessEvent(): will reseed global engines";
418 LOG_DEBUG(
"NuRandomService") <<
"preModule(): will reseed engines for module '" state_type transit_to(state_type astate)
Records the new status of ART and returns the old one.
seed_t querySeed(EngineId const &id)
Query a seed from the seed master.
void reset_module()
Records the status of ART.
bool bPrintEndOfJobSummary
print a summary at the end of job
void reset_state()
Resets the status to "something else" (inOther)
seed_t getGlobalSeed(std::string instanceName)
Returns a seed for the global engine with specified instance name.
int verbosity
Control the level of information messages.
void preModule(art::ModuleDescription const &md)
void postModule(art::ModuleDescription const &)
in module construction phase
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
#define DEFINE_ART_SERVICE(svc)
GlobalSignal< detail::SignalResponseType::FIFO, void(ModuleDescription const &)> sPreModuleConstruction
bool hasSeeder(EngineId const &id) const
Returns whether the specified engine has a valid seeder.
GlobalSignal< detail::SignalResponseType::LIFO, void()> sPostEndJob
EventSeedInputData getEventSeedInputData() const
void set_event(art::Event const &evt)
Records the specified event ID.
static bool readSeedParameter(seed_t &seed, fhicl::ParameterSet const &pset, std::string pname)
seed_t defineEngineID(EngineId const &id, SeedMaster_t::Seeder_t seeder)
Set the seeder of an existing engine.
std::string moduleLabel() const
Getters.
const std::string instance
seed_t getSeed()
Returns a seed for the engine with default instance name.
seed_t seedEngine(EngineId const &id)
Calls the seeder with the specified seed and engine ID.
NuRandomService(const fhicl::ParameterSet &, art::ActivityRegistry &)
art::RandomNumberGenerator::seed_t seed_t
GlobalSignal< detail::SignalResponseType::LIFO, void(ModuleDescription const &)> sPostModuleConstruction
void freezeSeed(EngineId const &id, seed_t frozen_seed)
Forces NuRandomService not to change the seed of the specified engine.
void registerEngineAndSeeder(EngineId const &id, SeedMaster_t::Seeder_t seeder)
Registers an engine and its seeder.
void reseedModule()
Reseeds all the engines in the current module.
EngineId qualify_engine_label(std::string moduleLabel, std::string instanceName) const
Returns a fully qualified EngineId.
void postModuleBeginRun(art::ModuleDescription const &)
void postModuleConstruction(art::ModuleDescription const &)
base_engine_t & getEngine() const
GlobalSignal< detail::SignalResponseType::FIFO, void(ModuleDescription const &)> sPreModuleBeginRun
seed_t registerEngineID(EngineId const &id, SeedMaster_t::Seeder_t seeder=SeedMaster_t::Seeder_t())
Register an engine and seeds it with the seed from the master.
in service construction phase
base_engine_t & createEngine(seed_t seed)
seed_t createEngine(art::EngineCreator &module, std::string type, std::string instance="")
Creates an engine with RandomNumberGenerator service.
SeedMaster_t::EngineId EngineId
type of random engine ID
void postProcessEvent(art::Event const &)
void registerNewSeeder(EngineId const &id, Seeder_t seeder)
Register the specified function to reseed the engine id.
void ensureValidState(bool bGlobal=false) const
void print() const
Prints to the framework Info logger.
std::function< void(EngineId const &, seed_t)> Seeder_t
type of a function setting a seed
GlobalSignal< detail::SignalResponseType::LIFO, void(ModuleDescription const &)> sPostModule
typename PolicyImpl_t::EventData_t EventData_t
type of data used for event seeds
void freezeSeed(EngineId const &id, seed_t seed)
Forces SeedMaster not to change the seed of a registered engine.
NuRandomServiceHelper::ArtState state
in event processing by a module
void preModuleConstruction(art::ModuleDescription const &md)
Identifier for a engine, made of module name and optional instance name.
bool get_if_present(std::string const &key, T &value) const
static constexpr seed_t InvalidSeed
An invalid seed.
seed_t defineEngine(SeedMaster_t::Seeder_t seeder, std::string instance={})
Defines a seeder for a previously declared engine.
std::pair< seed_t, bool > findSeed(EngineId const &id, fhicl::ParameterSet const &pset, std::initializer_list< std::string > pnames)
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
constexpr std::tuple_element_t< I, art::AssnsNode< L, R, D > > & get(art::AssnsNode< L, R, D > &t) noexcept
GlobalSignal< detail::SignalResponseType::FIFO, void(ModuleDescription const &)> sPreModuleEndJob
std::string const & moduleLabel() const
static void RandomNumberGeneratorSeeder(EngineId const &id, seed_t seed)
Seeder_t function setting the seed of an engine in RandomNumberGenerator.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::vector< TrajPoint > seeds
seed_t reseedInstance(EngineId const &id)
Reseeds the specified engine instance in the current module.
state_type state() const
Getters.
seed_t reseedEvent(EngineId const &id, EventData_t const &data)
Reseeds the specified engine with an event seed (if any)
GlobalSignal< detail::SignalResponseType::FIFO, void(ModuleDescription const &)> sPreModule
seed_t getSeed(std::string moduleLabel)
Returns the seed value for this module label.
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &)> sPreProcessEvent
static Global_t global
A constant to select a "global" flavour constructor.
void onNewEvent()
Prepares for a new event.
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
void reseedGlobal()
Reseed all the global engines.
void reset_event()
Records the status of ART.
GlobalSignal< detail::SignalResponseType::LIFO, void(ModuleDescription const &)> sPostModuleEndJob
bool hasEngine(EngineId const &id) const
Returns whether the specified engine is already registered.
in begin of run for a module
EngineInfoIteratorBox engineIDsRange() const
Returns an object to iterate in range-for through configured engine IDs.
GlobalSignal< detail::SignalResponseType::LIFO, void(Event const &)> sPostProcessEvent
void registerSeeder(EngineId const &id, Seeder_t seeder)
Register the specified function to reseed the engine id.
GlobalSignal< detail::SignalResponseType::LIFO, void(ModuleDescription const &)> sPostModuleBeginRun
void preProcessEvent(art::Event const &evt)
void preModuleBeginRun(art::ModuleDescription const &md)
seed_t declareEngine(std::string instance="")
Declares the presence of an engine with a given instance name.
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
void preModuleEndJob(art::ModuleDescription const &md)
void postModuleEndJob(art::ModuleDescription const &)
void set_module(art::ModuleDescription const &desc)
Records the specified module description.
seed_t registerEngine(SeedMaster_t::Seeder_t seeder, std::string instance="")
Registers an existing engine with NuRandomService.
seed_t prepareEngine(EngineId const &id, SeedMaster_t::Seeder_t seeder)
Registers the engine ID into SeedMaster.
SeedMaster_t seeds
Class managing the seeds.