10 #ifndef NURANDOM_RANDOMUTILS_NuRandomService_H 11 #define NURANDOM_RANDOMUTILS_NuRandomService_H 1 13 #ifndef NURANDOM_RANDOMUTILS_NuRandomService_USECLHEP 14 # define NURANDOM_RANDOMUTILS_NuRandomService_USECLHEP 1 16 #endif // NURANDOM_RANDOMUTILS_NuRandomService_USECLHEP 19 #ifndef NURANDOM_RANDOMUTILS_NuRandomService_USEROOT 20 # define NURANDOM_RANDOMUTILS_NuRandomService_USEROOT 0 22 #endif // NURANDOM_RANDOMUTILS_NuRandomService_USEROOT 29 #include <initializer_list> 36 #if (NURANDOM_RANDOMUTILS_NuRandomService_USECLHEP) 37 # include "CLHEP/Random/RandomEngine.h" 38 #endif // NURANDOM_RANDOMUTILS_NuRandomService_USECLHEP 41 #if (NURANDOM_RANDOMUTILS_NuRandomService_USEROOT) 43 #endif // NURANDOM_RANDOMUTILS_NuRandomService_USEROOT 55 class ActivityRegistry;
56 class ModuleDescription;
410 static constexpr
seed_t InvalidSeed = SeedMaster_t::InvalidSeed;
424 {
return seed != InvalidSeed; }
451 (std::string
const& moduleLabel, std::string
const& instanceName);
465 seed_t getSeed(std::string instanceName =
"");
491 seed_t getGlobalSeed(std::string instanceName);
496 {
return seeds.getCurrentSeed(qualify_engine_label(instanceName)); }
500 {
return seeds.getCurrentSeed(qualify_engine_label()); }
504 {
return seeds.getCurrentSeed(qualify_global_engine(instanceName)); }
508 #if (NURANDOM_RANDOMUTILS_NuRandomService_USECLHEP) 559 std::reference_wrapper<NuRandomService::engine_t> registerAndSeedEngine(
562 std::optional<seed_t>
const seed = std::nullopt
580 [[nodiscard]] std::reference_wrapper<engine_t> registerAndSeedEngine(
600 [[nodiscard]] std::reference_wrapper<engine_t> registerAndSeedEngine
602 {
return registerAndSeedEngine(engine, type,
"", seedParam); }
619 [[nodiscard]] std::reference_wrapper<engine_t> registerAndSeedEngine
621 {
return registerAndSeedEngine(engine,
"",
"", seedParam); }
641 engine_t& engine, std::string type, std::string instance,
644 {
return registerAndSeedEngine(engine, type, instance, pset, { pname }); }
663 [[nodiscard]] std::reference_wrapper<engine_t> registerAndSeedEngine(
664 engine_t& engine, std::string type, std::string instance,
686 {
return registerAndSeedEngine(engine, type,
"", pset, pname); }
709 {
return registerAndSeedEngine(engine, type,
"", pset, pnames); }
729 {
return registerAndSeedEngine(engine, pset, { pname }); }
751 {
return registerAndSeedEngine(engine,
"",
"", pset, pnames); }
753 #endif // NURANDOM_RANDOMUTILS_NuRandomService_USECLHEP 815 std::optional<seed_t>
const seed = std::nullopt
854 {
return registerEngine(seeder,
"", seedParam); }
875 {
return registerEngine(seeder, instance, pset, { pname }); }
917 {
return registerEngine(seeder,
"", pset, pname); }
938 {
return registerEngine(seeder,
"", pset, pnames); }
940 #if (NURANDOM_RANDOMUTILS_NuRandomService_USECLHEP) 954 (CLHEP::HepRandomEngine& engine, std::string instance =
"")
971 CLHEP::HepRandomEngine& engine, std::string instance,
991 CLHEP::HepRandomEngine& engine, std::string instance,
995 return registerEngine
998 #endif // NURANDOM_RANDOMUTILS_NuRandomService_USECLHEP 1020 seed_t declareEngine(std::string instance =
"");
1044 {
return declareEngine(instance, pset, { pname }); }
1060 std::string instance,
1076 {
return declareEngine(
"", pset, pname); }
1094 {
return declareEngine(
"", pset, pnames); }
1117 #if (NURANDOM_RANDOMUTILS_NuRandomService_USECLHEP) 1130 (CLHEP::HepRandomEngine& engine, std::string instance = {})
1132 #endif // NURANDOM_RANDOMUTILS_NuRandomService_USECLHEP 1137 template<
class Stream>
1139 {
seeds.print(std::forward<Stream>(out)); }
1144 #if (NURANDOM_RANDOMUTILS_NuRandomService_USEROOT) 1145 class TRandomSeeder {
1148 TRandomSeeder(TRandom* engine): pRandom(engine) {}
1150 {
if (pRandom) pRandom->SetSeed(seed); }
1152 TRandom* pRandom =
nullptr;
1154 #endif // NURANDOM_RANDOMUTILS_NuRandomService_USEROOT 1156 #if (NURANDOM_RANDOMUTILS_NuRandomService_USECLHEP) 1164 engine.setSeed(seed, 0);
1166 <<
"CLHEP engine: '" << engine.name() <<
"'[" << ((
void*) &engine)
1167 <<
"].setSeed(" << seed <<
", 0)";
1172 #endif // NURANDOM_RANDOMUTILS_NuRandomService_USECLHEP 1192 bool bPrintEndOfJobSummary =
false;
1221 void reseedModule(std::string currentModule);
1223 void reseedModule();
1227 void reseedGlobal();
1233 void ensureValidState(
bool bGlobal =
false)
const;
1238 (std::string moduleLabel, std::string instanceName)
const;
1239 EngineId qualify_engine_label(std::string instanceName =
"")
const;
1241 {
return EngineId(instanceName, EngineId::global); }
1245 static std::optional<seed_t> readSeedParameter
1249 {
return readSeedParameter(pset, { pname }); }
1250 static std::optional<seed_t> readSeedParameter(
1252 std::initializer_list<std::string> pnames
1254 static std::optional<seed_t> readSeedParameter(
SeedAtom const& param);
1263 std::pair<seed_t, bool> extractSeed
1270 void registerEngineIdAndSeeder
1293 #if (NURANDOM_RANDOMUTILS_NuRandomService_USECLHEP) 1300 inline std::reference_wrapper<NuRandomService::engine_t>
1301 NuRandomService::registerAndSeedEngine(
engine_t& engine,
1303 std::string instance,
1304 std::optional<seed_t>
const seed)
1306 EngineId const id = qualify_engine_label(instance);
1308 auto const [seedValue, frozen] = extractSeed(
id, seed);
1309 engine.setSeed(seedValue, 0);
1311 <<
"Seeding " << type <<
" engine \"" <<
id.artName()
1312 <<
"\" with seed " << seedValue <<
".";
1313 if (frozen) freezeSeed(
id, seedValue);
1318 inline std::reference_wrapper<NuRandomService::engine_t>
1319 NuRandomService::registerAndSeedEngine(
engine_t& engine,
1321 std::string instance,
1324 return registerAndSeedEngine(engine, type, instance, readSeedParameter(seedParam));
1328 inline std::reference_wrapper<NuRandomService::engine_t>
1329 NuRandomService::registerAndSeedEngine(
engine_t& engine,
1331 std::string instance,
1333 std::initializer_list<std::string> pnames)
1336 registerAndSeedEngine(engine, type, instance, readSeedParameter(pset, pnames));
1340 #endif // NURANDOM_RANDOMUTILS_NuRandomService_USECLHEP 1346 #endif // NURANDOM_RANDOMUTILS_NuRandomService_H
CLHEP::HepRandomEngine engine_t
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)
Registers an existing CLHEP engine with art::NuRandomService.
seed_t getCurrentSeed() const
Returns the last computed seed for the default engine of current module.
Class holding the current state of art processing.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::reference_wrapper< engine_t > registerAndSeedEngine(engine_t &engine, fhicl::ParameterSet const &pset, std::initializer_list< std::string > pnames)
Creates an engine with art::RandomNumberGenerator service.
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 art::NuRandomService.
seed_t registerEngine(SeedMaster_t::Seeder_t seeder, fhicl::ParameterSet const &pset, std::string pname)
Registers an existing engine with art::NuRandomService.
CLHEP::HepRandomEngine & engine
art::detail::EngineCreator::seed_t seed_t
Type of seed used in art and by us.
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.
seed_t registerEngine(CLHEP::HepRandomEngine &engine, std::string instance, SeedAtom const &seedParam)
Registers an existing CLHEP engine with art::NuRandomService.
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.
#define DECLARE_ART_SERVICE(svc, scope)
CLHEPengineSeeder(CLHEP::HepRandomEngine *e)
NuRandomServiceHelper::ArtState state
Identifier for a engine, made of module name and optional instance name.
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
std::reference_wrapper< engine_t > registerAndSeedEngine(engine_t &engine, fhicl::ParameterSet const &pset, std::string pname)
Creates an engine with art::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 art::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.
std::reference_wrapper< engine_t > registerAndSeedEngine(engine_t &engine, std::string type, fhicl::ParameterSet const &pset, std::initializer_list< std::string > pnames)
Creates an engine with art::RandomNumberGenerator service.
std::reference_wrapper< engine_t > registerAndSeedEngine(engine_t &engine, std::string type, std::string instance, fhicl::ParameterSet const &pset, std::string pname)
Creates an engine with art::RandomNumberGenerator service.
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.
std::reference_wrapper< engine_t > registerAndSeedEngine(engine_t &engine, std::string type, fhicl::ParameterSet const &pset, std::string pname)
Creates an engine with art::RandomNumberGenerator service.
art::detail::EngineCreator::seed_t seed_t