12 #define NUTOOLS_RANDOMUTILS_NuRandomService_USECLHEP 1 13 #include "nutools/RandomUtils/NuRandomService.h" 29 #include "CLHEP/Random/RandomEngine.h" 30 #include "CLHEP/Random/JamesRandom.h" 31 #include "CLHEP/Random/RandFlat.h" 73 virtual void endJob()
override;
88 std::map<std::string, CLHEP::HepRandomEngine*>
engines;
124 log <<
"Construct SeedTestPolicy with " 127 log <<
" " << instanceName;
143 log <<
"\nSeed for '" << instanceName <<
"' is: " << seed;
151 for (
size_t iEngine = 0; iEngine < instanceNames.size(); ++iEngine) {
152 std::string const& instanceName = instanceNames[iEngine];
161 localEngine = std::make_unique<CLHEP::HepJamesRandom>();
164 seed = Seeds->defineEngine(*
localEngine, instanceName);
170 <<
"Engine instance '" << instanceName
171 <<
"' will be owned by the test module.";
178 auto& engine =
createEngine(seed,
"HepJamesRandom", instanceName);
180 Seeds->defineEngine(engine, instanceName);
182 engines.emplace(instanceName, &engine);
188 if (seed != expectedSeed) {
190 <<
"NuRandomService returned different seed values for engine instance '" 191 << instanceName <<
"': first " << expectedSeed <<
", now " << seed
204 Seeds->declareEngine(instanceNames.front());
212 <<
"Registration of local engine with duplicate label" 213 " did not throw an exception";
223 <<
"SeedTestPolicy::analyze() " <<
event.id() <<
" with " 232 CLHEP::HepRandomEngine& engine = *
engines.at(instanceName);
239 if (actualSeed == startSeed) {
242 <<
"per event seed " << actualSeed <<
" of engine '" << instanceName
243 <<
"' is the same as at beginning!\n";
247 if (actualSeed != startSeed) {
249 <<
"expected seed " << startSeed <<
" for engine '" << instanceName
250 <<
"', got " << actualSeed <<
" instead!\n";
258 <<
std::setw(12) << (instanceName.empty()?
"<default>": instanceName)
260 <<
" (seed: " << actualSeed <<
")";
275 e <<
"SeedTestPolicy: detected " <<
nErrors <<
" errors";
294 = instanceName.empty()? seeds->
getSeed(): seeds->
getSeed(instanceName);
303 log <<
" error #" <<
nErrors <<
":\n" <<
e;
318 log <<
" error #" <<
nErrors <<
":\n" << e <<
"\n";
338 if (actualSeed != expectedSeed) {
340 <<
"expected seed " << expectedSeed <<
" for engine '" << instanceName
341 <<
"', got " << actualSeed <<
" instead!";
base_engine_t & createEngine(seed_t seed)
unsigned int nErrors
Number of errors detected so far.
seed_t getSeed(std::string instanceName)
Returns a seed for the engine with specified instance name.
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
virtual void analyze(art::Event const &event) override
virtual void endJob() override
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::string const moduleLabel
configured module label
art::detail::EngineCreator::seed_t seed_t
Type of seed.
bool handleSeedServiceException(art::Exception &e)
Returns whether e is an exception we can handle (and, if so, it handles)
std::vector< std::string > instanceNames
EDAnalyzer(fhicl::ParameterSet const &pset)
SeedTestPolicy(fhicl::ParameterSet const &pset)
seed_t verifySeed(CLHEP::HepRandomEngine &, std::string const &instanceName)
#define DEFINE_ART_MODULE(klass)
std::string CreateCharacter(CLHEP::HepRandomEngine &engine)
Creates a "character statistics" using the specified random engine.
bool perEventSeeds
whether we expect different seeds on each event
std::unique_ptr< CLHEP::HepRandomEngine > localEngine
self-managed
static constexpr seed_t InvalidSeed
An invalid seed.
Functions used in NuRandomService tests.
static constexpr bool isSeedValid(seed_t seed)
Returns whether the specified seed is valid.
seed_t obtainSeed(std::string instanceName="")
unsigned int nExpectedErrors
number of expected errors
std::map< std::string, seed_t > startSeeds
seeds after the constructor
Test module for NuRandomService.
Q_EXPORT QTSManip setw(int w)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::vector< TrajPoint > seeds
seed_t readSeed(CLHEP::HepRandomEngine const &engine)
Returns the seed of the specified engine (CLHEP overload)
std::map< std::string, CLHEP::HepRandomEngine * > engines
bool isSeedServiceException(std::exception const &e)
Returns whether the exception looks to be from NuRandomService.
bool isLocalEngine(size_t iEngine) const
Returns whether the engine associated with the specified index is local.
auto const & get(AssnsNode< L, R, D > const &r)
bool useGenerators
instanciate and use random number generators
testing::NuRandomService::seed_t seed_t
cet::coded_exception< error, detail::translate > exception
Event finding and building.