EngineCreator.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // EngineCreator - enable a derived class to access the
4 // RandomNumberGenerator::createEngine()
5 //
6 // ======================================================================
7 
10 #include "cetlib/bold_fontify.h"
11 
13 
14 EngineCreator::EngineCreator(std::string const& moduleLabel,
15  ScheduleID const sid)
16  : moduleLabel_{moduleLabel}, sid_{sid}
17 {}
18 
21 {
22  return createEngine(seed, rng()->defaultEngineKind());
23 }
24 
27  std::string const& kind_of_engine_to_make)
28 {
29  requireValid();
30  return rng()->createEngine(sid_, moduleLabel_, seed, kind_of_engine_to_make);
31 }
32 
35  std::string const& kind_of_engine_to_make,
36  label_t const& engine_label)
37 {
38  requireValid();
39  return rng()->createEngine(
40  sid_, moduleLabel_, seed, kind_of_engine_to_make, engine_label);
41 }
42 
45 {
47  return rng;
48 }
49 
50 void
52 {
53  if (sid_.isValid() && !moduleLabel_.empty()) {
54  return;
55  }
56  throw Exception{
58  "An error occurred while creating a random-number engine.\n\n"}
59  << "No module label or schedule ID available to create engine.\n"
60  << "Please ensure that your module calls the correct base-class\n"
61  "constructor. The module class and module label can be determined\n"
62  "by looking for the '<module class>:<module label>@Construction' "
63  "string\n"
64  "in the message context a few lines above. For example, if your\n"
65  "module is a filter with class name 'MyFilter' please make the\n"
66  "following change to your constructor:\n\n"
67  << " Wrong: MyFilter(ParameterSet const& ps) :\n"
68  << " dataMembers_, ...\n"
69  << " {}\n\n"
70  << " Right: MyFilter(ParameterSet const& ps) :\n"
71  << " " << cet::bold_fontify("art::EDFilter{ps},")
72  << " dataMembers_, ...\n"
73  << " {}\n\n"
74  << "If your module is a producer, 'art::EDFilter{ps}' above should be\n"
75  "replaced with 'art::EDProducer{ps}.\n";
76 }
77 
78 // ======================================================================
base_engine_t & createEngine(seed_t seed)
std::string string
Definition: nybbler.cc:12
RNGsnapshot::label_t label_t
Definition: EngineCreator.h:37
constexpr bool isValid() const noexcept
Definition: ScheduleID.h:71
std::string const moduleLabel_
Definition: EngineCreator.h:53
std::string bold_fontify(std::string const &s)
Definition: bold_fontify.h:8
CLHEP::HepRandomEngine base_engine_t
Definition: EngineCreator.h:36
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
static ServiceHandle< RandomNumberGenerator > & rng()