LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TypeLabel.cc
Go to the documentation of this file.
3 // vim: set sw=2 expandtab :
4 
5 #include <ostream>
6 #include <tuple>
7 
8 namespace art {
9 
10  TypeLabel::TypeLabel(TypeID const& itemtype,
11  std::string const& instanceName,
12  bool const supportsView,
13  bool const transient /* = false */)
14  : typeID_{itemtype}
15  , productInstanceName_{instanceName}
17  , transient_{transient}
18  {}
19 
20  TypeLabel::TypeLabel(TypeID const& itemtype,
21  std::string const& instanceName,
22  bool const supportsView,
23  std::string emulatedModule)
24  : typeID_{itemtype}
25  , productInstanceName_{instanceName}
27  , emulatedModule_{std::make_unique<std::string>(std::move(emulatedModule))}
28  {}
29 
30  TypeLabel::~TypeLabel() = default;
31 
32  std::string const&
34  {
35  if (!emulatedModule_) {
36  throw Exception(errors::NullPointerError, "TypeLabel::emulatedModule\n")
37  << "Attempt to retrieve an emulated module name when one does not "
38  "exist.\n";
39  }
40  return *emulatedModule_;
41  }
42 
43  // Types with the same friendlyClassName are in the same equivalence
44  // class for the purposes of this comparison.
45  bool
46  operator<(TypeLabel const& a, TypeLabel const& b)
47  {
48  auto const& a_class_name = a.className();
49  auto const& b_class_name = b.className();
50  auto const& a_emulated_module =
51  a.hasEmulatedModule() ? *a.emulatedModule_ : "<none>";
52  auto const& b_emulated_module =
53  b.hasEmulatedModule() ? *b.emulatedModule_ : "<none>";
54  return std::tie(a_emulated_module, a.productInstanceName_, a_class_name) <
55  std::tie(b_emulated_module, b.productInstanceName_, b_class_name);
56  }
57 
58  std::ostream&
59  operator<<(std::ostream& os, TypeLabel const& tl)
60  {
61  os << "Emulated module: '"
62  << (tl.hasEmulatedModule() ? tl.emulatedModule() : "<none>") << "'\n"
63  << "Product instance name: '" << tl.productInstanceName() << "'\n"
64  << "Class name: '" << tl.className() << "'\n"
65  << "Supports views: '" << std::boolalpha << tl.supportsView()
66  << '\n'
67  << "Transient: '" << tl.transient();
68  return os;
69  }
70 }
std::string const & productInstanceName() const
Definition: TypeLabel.h:52
friend std::ostream & operator<<(std::ostream &os, TypeLabel const &tl)
Definition: TypeLabel.cc:59
std::string const & emulatedModule() const
Definition: TypeLabel.cc:33
std::shared_ptr< std::string > emulatedModule_
Definition: TypeLabel.h:77
TypeLabel(TypeID const &itemtype, std::string const &instanceName, bool const supportsView, bool const transient=false)
Definition: TypeLabel.cc:10
bool hasEmulatedModule() const
Definition: TypeLabel.h:57
bool supportsView() const
Definition: TypeLabel.h:62
TypeID typeID_
Definition: TypeLabel.h:73
friend bool operator<(TypeLabel const &a, TypeLabel const &b)
Definition: TypeLabel.cc:46
bool transient_
Definition: TypeLabel.h:76
std::string productInstanceName_
Definition: TypeLabel.h:74
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool transient() const
Definition: TypeLabel.h:67
Definition: MVAAlg.h:12
std::string className() const
Definition: TypeLabel.h:41
bool supportsView_
Definition: TypeLabel.h:75