LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
EngineId.h
Go to the documentation of this file.
1 
10 #ifndef NURANDOM_RANDOMUTILS_PROVIDERS_ENGINEID_H
11 #define NURANDOM_RANDOMUTILS_PROVIDERS_ENGINEID_H 1
12 
13 #include <string>
14 #include <ostream>
15 
16 namespace rndm {
17 
19  namespace SeedMasterHelper {
20 
22  struct EngineId {
23 
25  struct Global_t {};
26 
28  static constexpr Global_t global{};
29 
31  EngineId(std::string const& mod, std::string const& inst = std::string()):
32  moduleLabel(mod),
33  instanceName(inst)
34  {}
35 
37  EngineId(std::string const& inst, Global_t):
38  moduleLabel(),
39  instanceName(inst)
40  {}
41 
42  // Accept compiler written d'tor, copy c'tor, copy and move assignments.
43 
45  bool isGlobal() const { return moduleLabel.empty(); }
46 
48  bool hasInstanceName() const { return !instanceName.empty(); }
49 
51  void setGlobal(std::string inst)
52  { moduleLabel.clear(); instanceName = inst; }
53 
54 
56  bool operator== (EngineId const& rhs) const
57  {
58  if ( moduleLabel != rhs.moduleLabel ) return false;
59  if ( instanceName != rhs.instanceName ) return false;
60  return true;
61  } // operator== ()
62 
64  bool operator< (EngineId const& rhs) const
65  {
66  if (moduleLabel < rhs.moduleLabel) return true;
67  if (moduleLabel == rhs.moduleLabel) {
68  if (instanceName < rhs.instanceName) return true;
69  }
70  return false;
71  } // operator< ()
72 
74  operator std::string() const
75  {
76  std::string id = moduleLabel;
77  if (hasInstanceName()) id.append(1, '.').append(instanceName);
78  return id;
79  } // operator std::string()
80 
82  std::string artName() const { return moduleLabel + ':' + instanceName; }
83 
84  std::string moduleLabel;
85  std::string instanceName;
86 
87  }; // end class EngineId
88 
89  inline std::ostream& operator<<
90  (std::ostream& ost, const EngineId& id )
91  { return ost << std::string(id); }
92 
93  } // end namespace SeedMasterHelper
94 
95 } // namespace sim
96 
97 #endif // NURANDOM_RANDOMUTILS_PROVIDERS_ENGINEID_H
std::string artName() const
Converts the information in a module_name:instance_name string.
Definition: EngineId.h:82
bool hasInstanceName() const
Returns whether the instance label is defined.
Definition: EngineId.h:48
std::string moduleLabel
module label
Definition: EngineId.h:84
static constexpr Global_t global
A constant to select a "global" flavour constructor.
Definition: EngineId.h:28
structure to identify a "global" flavour constructor
Definition: EngineId.h:25
Identifier for a engine, made of module name and optional instance name.
Definition: EngineId.h:22
bool operator<(EngineId const &rhs) const
Lexicographic sort (module name first, then instance name)
Definition: EngineId.h:64
EngineId(std::string const &inst, Global_t)
Constructor (module name is required)
Definition: EngineId.h:37
EngineId(std::string const &mod, std::string const &inst=std::string())
Constructor (module name is required)
Definition: EngineId.h:31
void setGlobal(std::string inst)
Sets this ID to the specified global instance.
Definition: EngineId.h:51
std::string instanceName
instance name
Definition: EngineId.h:85
bool isGlobal() const
Returns whether the label is "global" (no module context)
Definition: EngineId.h:45
bool operator==(EngineId const &rhs) const
Returns true if both module and instance names match.
Definition: EngineId.h:56