9 #include "nutools/RandomUtils/NuRandomService.h" 25 #include "CLHEP/Random/RandomEngine.h" 38 , verbosity(paramSet.
get<
int>(
"verbosity", 0))
39 , bPrintEndOfJobSummary(paramSet.
get<
bool>(
"endOfJobSummary",false))
63 {
return { moduleLabel, instanceName }; }
85 <<
"NuRandomService::getGlobalSeed(\"" << instanceName <<
"\")";
123 return { seed,
true };
144 std::pair<seed_t, bool> seedInfo =
findSeed(
id, pset, pnames);
146 if (seedInfo.second)
freezeSeed(
id, seedInfo.first);
147 seed_t const seed = seedInfo.first;
187 <<
"Attempted to define engine '" <<
id.artName()
188 <<
"', that was not declared\n";
193 <<
"Attempted to redefine engine '" <<
id.artName()
194 <<
"', that has already been defined\n";
213 <<
"NuRandomService: not in a service constructor." 214 <<
" May not register \"global\" engines.\n";
226 <<
"NuRandomService: not in a module constructor." 227 <<
" May not register engines.\n";
241 <<
"No random seed specific to this event for engine '" <<
id <<
"'";
244 mf::LogInfo(
"NuRandomService") <<
"Random seed for this event, engine '" 245 <<
id <<
"': " << seed;
253 if (
ID.moduleLabel != currentModule)
continue;
263 if (!
ID.isGlobal())
continue;
278 <<
"NuRandomService: an engine with ID '" <<
id.artName()
279 <<
"' has already been created!\n";
302 std::initializer_list<std::string> pnames
336 MF_LOG_DEBUG(
"NuRandomService") <<
"preProcessEvent(): will reseed global engines";
347 MF_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.
bool bPrintEndOfJobSummary
print a summary at the end of job
GlobalSignal< detail::SignalResponseType::FIFO, void(ModuleContext const &)> sPreModuleBeginRun
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.
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.
void preProcessEvent(art::Event const &evt, art::ScheduleContext)
GlobalSignal< detail::SignalResponseType::FIFO, void(ModuleContext const &)> sPreModule
void postModuleBeginRun(art::ModuleContext const &)
std::string moduleLabel() const
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 &)
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.
EngineId qualify_engine_label(std::string moduleLabel, std::string instanceName) const
Returns a fully qualified EngineId.
void postModuleConstruction(art::ModuleDescription const &)
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
SeedMaster_t::EngineId EngineId
type of random engine ID
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
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
GlobalSignal< detail::SignalResponseType::LIFO, void(ModuleContext const &)> sPostModuleBeginRun
static constexpr seed_t InvalidSeed
An invalid seed.
void postModule(art::ModuleContext const &)
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)
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &, ScheduleContext)> sPreProcessEvent
GlobalSignal< detail::SignalResponseType::FIFO, void(ModuleDescription const &)> sPreModuleEndJob
void preModule(art::ModuleContext const &mc)
GlobalSignal< detail::SignalResponseType::LIFO, void(Event const &, ScheduleContext)> sPostProcessEvent
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::vector< TrajPoint > seeds
void preModuleBeginRun(art::ModuleContext const &mc)
seed_t reseedInstance(EngineId const &id)
Reseeds the specified engine instance in the current module.
GlobalSignal< detail::SignalResponseType::LIFO, void(ModuleContext const &)> sPostModule
static QCString currentModule
name of the current enclosing 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)
seed_t getSeed(std::string moduleLabel)
Returns the seed value for this module label.
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.
auto const & moduleDescription() const
auto const & moduleLabel() const
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.
void registerSeeder(EngineId const &id, Seeder_t seeder)
Register the specified function to reseed the engine id.
void postProcessEvent(art::Event const &, art::ScheduleContext)
auto const & get(AssnsNode< L, R, D > const &r)
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.
art::detail::EngineCreator::seed_t seed_t