SeedTestRegisterOnRun_module.cc
Go to the documentation of this file.
1 /**
2  * @file SeedTestRegisterOnRun_module.cc
3  * @brief Tests engine registration and query of seeds in beginRun() context.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date March 17, 2016
6  */
7 
8 
9 // art extensions
10 #include "nutools/RandomUtils/NuRandomService.h"
11 
12 // Supporting library include files
14 
15 // Framework includes.
21 
22 // forward declarations
23 namespace art { class SubRun; }
24 
25 
26 namespace testing {
27 
28  /**
29  * @brief Test module for NuRandomService
30  *
31  * The test tries to get a seed of an unknown engine during begin subrun.
32  *
33  * Note that the test does not actually get any random number.
34  *
35  * Configuration parameters
36  * -------------------------
37  *
38  * * *register* (bool, default: true): register the engine
39  *
40  */
42 
43  public:
44 
45  explicit SeedTestRegisterOnRun(fhicl::ParameterSet const& pset);
46 
47  virtual void analyze(const art::Event&) override {}
48 
49  virtual void beginRun(art::Run const&) override;
50 
51  private:
52 
53  bool registerEngine; ///< whether to register the engine on construction
54 
55  }; // class SeedTestRegisterOnRun
56 
57 
58  SeedTestRegisterOnRun::SeedTestRegisterOnRun
59  (fhicl::ParameterSet const& pset)
60  : art::EDAnalyzer(pset)
61  , registerEngine(pset.get<bool>("register", true))
62  {
63  if (registerEngine) {
65  Seeds->declareEngine(); // declare an engine with empty instance name
66  }
67  } // SeedTestRegisterOnRun::SeedTestRegisterOnRun()
68 
69 
70  void SeedTestRegisterOnRun::beginRun(art::Run const&) {
71 
73  auto const seed = Seeds->getSeed(); // should throw
74 
75  mf::LogInfo("SeedTestRegisterOnRun")
76  << "Got seed=" << seed
77  << " for " << (registerEngine? "registered": "unregistered")
78  << " (unnamed) engine in beginRun()";
79 
80  } // SeedTestRegisterOnRun::beginSubRun()
81 
82 } // namespace testing
83 
seed_t getSeed(std::string instanceName)
Returns a seed for the engine with specified instance name.
LArSoft test utilities.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Test module for NuRandomService.
bool registerEngine
whether to register the engine on construction
Definition: Run.h:21
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:69
T get(std::string const &key) const
Definition: ParameterSet.h:231
virtual void analyze(const art::Event &) override
seed_t declareEngine(std::string instance="")
Declares the presence of an engine with a given instance name.