Public Types | Public Member Functions | Private Attributes | List of all members
testing::RandomManagerTest Class Reference

Test module for random engine managing interface of NuRandomService. More...

Inheritance diagram for testing::RandomManagerTest:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Public Types

typedef art::detail::EngineCreator::seed_t seed_t
 
- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 

Public Member Functions

 RandomManagerTest (fhicl::ParameterSet const &pset)
 
void analyze (const art::Event &event) override
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob ()
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
std::string const & processName () const
 
bool wantAllEvents () const
 
bool wantEvent (Event const &e)
 
fhicl::ParameterSetID selectorConfig () const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Attributes

std::string moduleLabel
 
std::map< std::string, cet::exempt_ptr< CLHEP::HepRandomEngine > > engines
 
std::unique_ptr< CLHEP::HepRandomEngine > extEngine {nullptr}
 
cet::exempt_ptr< CLHEP::HepRandomEngine > stdEngine {nullptr}
 

Additional Inherited Members

- Protected Member Functions inherited from art::Observer
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &paths, fhicl::ParameterSet const &config)
 
detail::ProcessAndEventSelectorsprocessAndEventSelectors ()
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Test module for random engine managing interface of NuRandomService.

The test writes on screen the random seeds it gets.

Configuration parameters:

Definition at line 63 of file RandomManagerTest_module.cc.

Member Typedef Documentation

Definition at line 65 of file RandomManagerTest_module.cc.

Constructor & Destructor Documentation

testing::RandomManagerTest::RandomManagerTest ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 84 of file RandomManagerTest_module.cc.

84  :
85  art::EDAnalyzer{pset},
86  moduleLabel{pset.get<std::string>("module_label")}
87  {
89 
90  // check if we want an "external" engine
91  std::string externalInstanceName{};
92  if (pset.get_if_present("externalInstance", externalInstanceName)) {
93  mf::LogInfo("RandomManagerTest") << "Creating an unmanaged engine '"
94  << externalInstanceName << "' in module '" << moduleLabel << "'";
95  extEngine = std::make_unique<CLHEP::Ranlux64Engine>();
96 
97  EngineManager->registerEngine(
98  [this](rndm::NuRandomService::EngineId const&, seed_t seed)
99  { this->extEngine->setSeed(seed, 0); },
100  externalInstanceName, pset, "Seed_" + externalInstanceName
101  );
102  } // if we have the external engine
103 
104  // check if we want an unmanaged standard engine
105  std::string standardInstanceName{};
106  if (pset.get_if_present("standardInstance", standardInstanceName)) {
107  mf::LogInfo("RandomManagerTest") << "Creating a standard engine '"
108  << standardInstanceName << "' in module '" << moduleLabel
109  << "' with RandomNumberGenerator";
110  seed_t seed
111  = pset.get<unsigned int>("Seed_" + standardInstanceName, 0);
112  stdEngine = &createEngine(seed, "HepJamesRandom", standardInstanceName);
113  } // if we have the external engine
114 
115  // initialize the standard engines with RandomNumberGenerator
116  auto const instanceNames = pset.get<std::vector<std::string>>("instanceNames", {});
117  for (std::string const& instanceName: instanceNames) {
118  mf::LogInfo("RandomManagerTest") << "Creating a default engine '"
119  << instanceName << "' in module '" << moduleLabel << "'";
120  CLHEP::HepRandomEngine& engine = EngineManager->createEngine
121  (*this, "HepJamesRandom", instanceName, pset, "Seed_" + instanceName);
122  engines.emplace(instanceName, &engine);
123  }
124 
125  // create a default engine, if needed
126  if (instanceNames.empty() && !extEngine && !stdEngine) {
127  mf::LogInfo("RandomManagerTest")
128  << "Creating a nameless default engine in module '"
129  << moduleLabel << "'";
130  CLHEP::HepRandomEngine& engine = EngineManager->createEngine(*this, pset, "Seed");
131  engines.emplace("", &engine);
132  }
133 
134  { // anonymous block
135  mf::LogInfo log("RandomManagerTest");
136  log << "RandomManagerTest[" << moduleLabel << "]: instances:";
137  for (std::string const& instanceName: instanceNames)
138  log << " " << instanceName;
139  } // anonymous block
140 
141  // Add non-art-managed engines to list of engines
142  if (extEngine) {
143  assert(!externalInstanceName.empty());
144  engines.emplace(externalInstanceName, extEngine.get());
145  }
146 
147  if (stdEngine) {
148  assert(!standardInstanceName.empty());
149  engines.emplace(standardInstanceName, stdEngine);
150  }
151 
152  } // RandomManagerTest::RandomManagerTest()
base_engine_t & createEngine(seed_t seed)
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
unsigned long seed_t
cet::exempt_ptr< CLHEP::HepRandomEngine > stdEngine
Identifier for a engine, made of module name and optional instance name.
Definition: EngineId.h:22
std::unique_ptr< CLHEP::HepRandomEngine > extEngine
std::reference_wrapper< engine_t > createEngine(Module &module, std::string type, std::string instance="")
Creates an engine with RandomNumberGenerator service.
std::map< std::string, cet::exempt_ptr< CLHEP::HepRandomEngine > > engines
seed_t registerEngine(SeedMaster_t::Seeder_t seeder, std::string instance="")
Registers an existing engine with NuRandomService.

Member Function Documentation

void testing::RandomManagerTest::analyze ( const art::Event event)
override

Definition at line 156 of file RandomManagerTest_module.cc.

157  {
158  mf::LogVerbatim("RandomManagerTest") << "RandomManagerTest[" << moduleLabel << "]::analyze "
159  << event.id();
160 
161  for (auto& [instanceName, engine] : engines) {
162  seed_t actualSeed = testing::NuRandomService::readSeed(*engine);
163  mf::LogVerbatim("RandomManagerTest")
164  << std::setw(12) << (instanceName.empty()? "<default>": instanceName)
166  << " (seed: " << actualSeed << ")";
167  }
168  } // RandomManagerTest::analyze()
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
unsigned long seed_t
std::string CreateCharacter(CLHEP::HepRandomEngine &engine)
Creates a "character statistics" using the specified random engine.
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
seed_t readSeed(CLHEP::HepRandomEngine const &engine)
Returns the seed of the specified engine (CLHEP overload)
std::map< std::string, cet::exempt_ptr< CLHEP::HepRandomEngine > > engines

Member Data Documentation

std::map<std::string, cet::exempt_ptr<CLHEP::HepRandomEngine> > testing::RandomManagerTest::engines
private

Definition at line 74 of file RandomManagerTest_module.cc.

std::unique_ptr<CLHEP::HepRandomEngine> testing::RandomManagerTest::extEngine {nullptr}
private

Definition at line 75 of file RandomManagerTest_module.cc.

std::string testing::RandomManagerTest::moduleLabel
private

Definition at line 72 of file RandomManagerTest_module.cc.

cet::exempt_ptr<CLHEP::HepRandomEngine> testing::RandomManagerTest::stdEngine {nullptr}
private

Definition at line 76 of file RandomManagerTest_module.cc.


The documentation for this class was generated from the following file: