11 #ifndef NUTOOLS_RANDOMUTILS_NuRandomService_H 12 #define NUTOOLS_RANDOMUTILS_NuRandomService_H 1 14 #ifndef NUTOOLS_RANDOMUTILS_NuRandomService_USECLHEP 15 # define NUTOOLS_RANDOMUTILS_NuRandomService_USECLHEP 1 17 #endif // NUTOOLS_RANDOMUTILS_NuRandomService_USECLHEP 20 #ifndef NUTOOLS_RANDOMUTILS_NuRandomService_USEROOT 21 # define NUTOOLS_RANDOMUTILS_NuRandomService_USEROOT 0 23 #endif // NUTOOLS_RANDOMUTILS_NuRandomService_USEROOT 29 #include <initializer_list> 36 #if (NUTOOLS_RANDOMUTILS_NuRandomService_USECLHEP) 37 # include "CLHEP/Random/RandomEngine.h" 38 #endif // NUTOOLS_RANDOMUTILS_NuRandomService_USECLHEP 41 #if (NUTOOLS_RANDOMUTILS_NuRandomService_USEROOT) 43 #endif // NUTOOLS_RANDOMUTILS_NuRandomService_USEROOT 52 class ActivityRegistry;
53 class ModuleDescription;
369 static constexpr
seed_t InvalidSeed = SeedMaster_t::InvalidSeed;
383 {
return seed != InvalidSeed; }
405 seed_t getSeed(std::string instanceName);
440 seed_t getGlobalSeed(std::string instanceName);
445 {
return seeds.getCurrentSeed(qualify_engine_label(instanceName)); }
449 {
return seeds.getCurrentSeed(qualify_engine_label()); }
453 {
return seeds.getCurrentSeed(qualify_global_engine(instanceName)); }
543 {
return createEngine(module, type, instance, pset, { pname }); }
552 {
return createEngine(module, type,
"", pset, pname); }
557 {
return createEngine(module, type,
"", pset, pnames); }
562 {
return createEngine(module, pset, { pname }); }
634 {
return registerEngine(seeder, instance, pset, { pname }); }
643 {
return registerEngine(seeder,
"", pset, pname); }
648 {
return registerEngine(seeder,
"", pset, pnames); }
651 #if (NUTOOLS_RANDOMUTILS_NuRandomService_USECLHEP) 667 (CLHEP::HepRandomEngine& engine, std::string instance =
"")
670 CLHEP::HepRandomEngine& engine, std::string instance,
674 return registerEngine
677 #endif // NUTOOLS_RANDOMUTILS_NuRandomService_USECLHEP 697 seed_t declareEngine(std::string instance =
"");
721 {
return declareEngine(instance, pset, { pname }); }
737 std::string instance,
753 {
return declareEngine(
"", pset, pname); }
771 {
return declareEngine(
"", pset, pnames); }
794 #if (NUTOOLS_RANDOMUTILS_NuRandomService_USECLHEP) 807 (CLHEP::HepRandomEngine& engine, std::string instance = {})
809 #endif // NUTOOLS_RANDOMUTILS_NuRandomService_USECLHEP 814 template<
class Stream>
816 {
seeds.print(std::forward<Stream>(out)); }
824 #if (NUTOOLS_RANDOMUTILS_NuRandomService_USEROOT) 825 class TRandomSeeder {
828 TRandomSeeder(TRandom* engine): pRandom(engine) {}
830 {
if (pRandom) pRandom->SetSeed(seed); }
832 TRandom* pRandom =
nullptr;
834 #endif // NUTOOLS_RANDOMUTILS_NuRandomService_USEROOT 836 #if (NUTOOLS_RANDOMUTILS_NuRandomService_USECLHEP) 844 engine.setSeed(seed, 0);
846 <<
"CLHEP engine: '" << engine.name() <<
"'[" << ((
void*) &engine)
847 <<
"].setSeed(" << seed <<
", 0)";
852 #endif // NUTOOLS_RANDOMUTILS_NuRandomService_USECLHEP 873 bool bPrintEndOfJobSummary =
false;
902 void reseedModule(std::string currentModule);
914 void ensureValidState(
bool bGlobal =
false)
const;
919 (std::string moduleLabel, std::string instanceName)
const;
920 EngineId qualify_engine_label(std::string instanceName =
"")
const;
922 {
return EngineId(instanceName, EngineId::global); }
926 static bool readSeedParameter
930 {
return readSeedParameter(seed, pset, { pname }); }
931 static bool readSeedParameter(
933 std::initializer_list<std::string> pnames
942 std::pair<seed_t, bool> findSeed(
951 void registerEngineAndSeeder
979 #endif // NUTOOLS_RANDOMUTILS_NuRandomService_H
A class to assist in the distribution of guaranteed unique seeds.
void print(Stream &&out) const
Prints known (EngineId,seed) pairs.
Seeder_t functor setting the seed of a CLHEP::HepRandomEngine engine (untested!)
seed_t registerEngine(CLHEP::HepRandomEngine &engine, std::string instance, fhicl::ParameterSet const &pset, std::initializer_list< std::string > pnames)
seed_t getCurrentSeed() const
Returns the last computed seed for the default engine of current module.
Class holding the current state of art processing.
seed_t getCurrentSeed(std::string instanceName) const
Returns the last computed seed for specified engine of current module.
const std::string instance
seed_t seedEngine(EngineId const &id)
Calls the seeder with the specified seed and engine ID.
seed_t registerEngine(SeedMaster_t::Seeder_t seeder, fhicl::ParameterSet const &pset, std::initializer_list< std::string > pnames)
Registers an existing engine with NuRandomService.
#define DECLARE_ART_SERVICE(svc, scope)
seed_t registerEngine(SeedMaster_t::Seeder_t seeder, fhicl::ParameterSet const &pset, std::string pname)
Registers an existing engine with NuRandomService.
art::RandomNumberGenerator::seed_t seed_t
CLHEP::HepRandomEngine & engine
bool hasEngine(EngineId const &id) const
Returns whether the specified engine is already registered.
EngineId qualify_global_engine(std::string instanceName="") const
Returns a fully qualified EngineId.
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
Describe the current state of art processing, as understood by the NuRandomService.
CLHEPengineSeeder(CLHEP::HepRandomEngine *e)
NuRandomServiceHelper::ArtState state
Identifier for a engine, made of module name and optional instance name.
seed_t createEngine(art::EngineCreator &module, std::string type, std::string instance, fhicl::ParameterSet const &pset, std::string pname)
Creates an engine with RandomNumberGenerator service.
static constexpr bool isSeedValid(seed_t seed)
Returns whether the specified seed is valid.
seed_t declareEngine(fhicl::ParameterSet const &pset, std::string pname)
Declares the presence of an engine with a default instance name.
CLHEPengineSeeder(CLHEP::HepRandomEngine &e)
seed_t getGlobalCurrentSeed(std::string instanceName) const
Returns the last computed seed for the specified global engine.
std::vector< TrajPoint > seeds
seed_t createEngine(art::EngineCreator &module, std::string type, fhicl::ParameterSet const &pset, std::string pname)
Creates an engine with RandomNumberGenerator service.
seed_t createEngine(art::EngineCreator &module, fhicl::ParameterSet const &pset, std::string pname)
Creates an engine with RandomNumberGenerator service.
seed_t createEngine(art::EngineCreator &module, std::string type, fhicl::ParameterSet const &pset, std::initializer_list< std::string > pnames)
Creates an engine with RandomNumberGenerator service.
seed_t registerEngine(SeedMaster_t::Seeder_t seeder, std::string instance, fhicl::ParameterSet const &pset, std::string pname)
Registers an existing engine with NuRandomService.
bool hasEngine(EngineId const &id) const
Returns whether the specified engine is already registered.
seed_t reseed(EngineId const &id)
Reseeds the specified engine with a global seed (if any)
seed_t declareEngine(fhicl::ParameterSet const &pset, std::initializer_list< std::string > pnames)
Declares the presence of an engine with a default instance name.
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
SeedMaster_t seeds
Class managing the seeds.