SeedTestQuerySeeds_module.cc
Go to the documentation of this file.
1 /**
2  * @file SeedTestQuerySeeds_module.cc
3  * @brief Tests query of seeds in various contexts.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date March 18, 2016
6  */
7 
8 
9 // art extensions
10 #include "nutools/RandomUtils/NuRandomService.h"
11 
12 // Supporting library include files
14 
15 // Framework includes.
19 
20 
21 // forward declarations
22 namespace art {
23  class Run;
24  class SubRun;
25  class Event;
26 } // namespace art
27 
28 
29 namespace testing {
30 
31  /**
32  * @brief Test module for NuRandomService
33  *
34  * The test tries to get a seed of an unknown engine during event processing.
35  *
36  * It is expected to fail, since the engine should be registered on
37  * construction.
38  *
39  * Note that the test does not actually get any random number.
40  *
41  * Configuration parameters: none
42  */
44 
45  public:
46 
47  explicit SeedTestQuerySeeds(fhicl::ParameterSet const& pset);
48 
49  virtual void analyze(art::Event const&) override;
50 
51  virtual void beginRun (art::Run const&) override;
52  virtual void beginSubRun(art::SubRun const&) override;
53 
54  virtual void endJob() override;
55 
56  }; // class SeedTestQuerySeeds
57 
58 
59  //----------------------------------------------------------------------------
60  SeedTestQuerySeeds::SeedTestQuerySeeds
61  (fhicl::ParameterSet const& pSet)
62  : art::EDAnalyzer(pSet)
63  {
64  // This call has two effects:
65  // 1. declares the existence of a random engine, and associates it with
66  // a default (empty) instance name
67  // [we don't have such engine, but that does not matter for the test]
68  // 2. gets the seed associated with that engine
69 
70  auto seed = art::ServiceHandle<rndm::NuRandomService>()->getSeed();
71  mf::LogInfo("SeedTestQuerySeeds")
72  << "Declared a default engine, got seed=" << seed;
73  }
74 
75 
76  //----------------------------------------------------------------------------
78 
79  auto seed = art::ServiceHandle<rndm::NuRandomService>()->getSeed();
80  mf::LogInfo("SeedTestQuerySeeds")
81  << "In event loop: got seed=" << seed << " for the default engine";
82 
83  } // SeedTestQuerySeeds::analyze()
84 
85 
86  void SeedTestQuerySeeds::beginRun(art::Run const&) {
87 
88  auto seed = art::ServiceHandle<rndm::NuRandomService>()->getSeed();
89  mf::LogInfo("SeedTestQuerySeeds")
90  << "At begin run: got seed=" << seed << " for the default engine";
91 
92  } // SeedTestQuerySeeds::beginRun()
93 
94 
95  void SeedTestQuerySeeds::beginSubRun(art::SubRun const&) {
96 
97  auto seed = art::ServiceHandle<rndm::NuRandomService>()->getSeed();
98  mf::LogInfo("SeedTestQuerySeeds")
99  << "At begin subrun: got seed=" << seed << " for the default engine";
100 
101  } // SeedTestQuerySeeds::beginSubRun()
102 
103 
104  void SeedTestQuerySeeds::endJob() {
105 
106  auto seed = art::ServiceHandle<rndm::NuRandomService>()->getSeed();
107  mf::LogInfo("SeedTestQuerySeeds")
108  << "At end job: got seed=" << seed << " for the default engine";
109 
110  } // SeedTestQuerySeeds::endJob()
111 
112 
113  //----------------------------------------------------------------------------
114 
115 } // namespace testing
116 
def analyze(root, level, gtrees, gbranches, doprint)
Definition: rootstat.py:67
LArSoft test utilities.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Definition: Run.h:21
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:69
Test module for NuRandomService.
Definition: types.h:32