InputTag.cc
Go to the documentation of this file.
2 // vim: set sw=2 expandtab :
3 
4 #include "boost/algorithm/string/classification.hpp"
5 #include "boost/algorithm/string/split.hpp"
7 #include "fhiclcpp/coding.h"
8 
9 #include <ostream>
10 #include <stdexcept>
11 #include <string>
12 #include <vector>
13 
14 using namespace std;
15 
16 namespace art {
17 
18  InputTag::~InputTag() = default;
19  InputTag::InputTag() = default;
20 
21  InputTag::InputTag(string const& label,
22  string const& instance,
23  string const& processName)
24  : label_{label}, instance_{instance}, process_{processName}
25  {}
26 
28  char const* instance,
29  char const* processName)
30  : label_{label}, instance_{instance}, process_{processName}
31  {}
32 
33  InputTag::InputTag(string const& s)
34  {
35  vector<string> tokens;
36  boost::split(tokens, s, boost::is_any_of(":"), boost::token_compress_off);
37  auto const nwords = tokens.size();
38  if (nwords > 3u) {
40  "An error occurred while creating an input tag.\n")
41  << "The string '" << s
42  << "' has more than three colon-delimited tokens.\n"
43  "The supported syntax is '<module_label>:<optional instance "
44  "name>:<optional process name>'.";
45  }
46  if (nwords > 0) {
47  label_ = tokens[0];
48  }
49  if (nwords > 1) {
50  instance_ = tokens[1];
51  }
52  if (nwords > 2) {
53  process_ = tokens[2];
54  }
55  }
56 
57  InputTag::InputTag(char const* s) : InputTag{string{s}} {}
58 
59  InputTag::InputTag(InputTag const& rhs) = default;
60  InputTag::InputTag(InputTag&& rhs) = default;
61 
62  InputTag& InputTag::operator=(InputTag const& rhs) = default;
63  InputTag& InputTag::operator=(InputTag&& rhs) = default;
64 
65  bool
66  InputTag::operator==(InputTag const& tag) const noexcept
67  {
68  return (label_ == tag.label_) && (instance_ == tag.instance_) &&
69  (process_ == tag.process_);
70  }
71 
72  bool
74  {
75  return label_.empty() && instance_.empty() && process_.empty();
76  }
77 
78  string const&
80  {
81  return label_;
82  }
83 
84  string const&
86  {
87  return instance_;
88  }
89 
90  string const&
92  {
93  return process_;
94  }
95 
96  string
98  {
99  static string const separator{":"};
100  string result = label_;
101  if (!instance_.empty() || !process_.empty()) {
102  result += separator + instance_;
103  }
104  if (!process_.empty()) {
105  result += separator + process_;
106  }
107  return result;
108  }
109 
110  bool
112  {
113  return !(left == right);
114  }
115 
116  void
117  decode(std::any const& a, InputTag& tag)
118  {
120  vector<string> tmp;
121  fhicl::detail::decode(a, tmp);
122  if (tmp.size() == 2) {
123  tag = {tmp[0], tmp[1]};
124  } else if (tmp.size() == 3) {
125  tag = {tmp[0], tmp[1], tmp[2]};
126  } else {
127  ostringstream errmsg;
128  errmsg << "When converting to InputTag by a sequence, FHiCL entries "
129  "must follow the convention:\n\n"
130  << " [ label, instance ], or\n"
131  << " [ label, instance, process_name ].\n\n";
132  errmsg << "FHiCL entries provided: [ ";
133  for (auto ca = tmp.begin(); ca != tmp.cend(); ++ca) {
134  errmsg << *ca;
135  if (ca != tmp.cend() - 1) {
136  errmsg << ", ";
137  }
138  }
139  errmsg << " ]";
140  throw length_error(errmsg.str());
141  }
142  } else {
143  string tmp;
144  fhicl::detail::decode(a, tmp);
145  tag = tmp;
146  }
147  }
148 
149  ostream&
150  operator<<(ostream& os, InputTag const& tag)
151  {
152  static string const process("', process = '");
153  os << "InputTag: label = '" << tag.label() << "', instance = '"
154  << tag.instance()
155  << (tag.process().empty() ? string() : (process + tag.process())) << "'";
156  return os;
157  }
158 
159 } // namespace art
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:102
static QCString result
std::string string
Definition: nybbler.cc:12
const std::string instance
std::string const & instance() const noexcept
Definition: InputTag.cc:85
std::string label_
Definition: InputTag.h:46
STL namespace.
std::string process_
Definition: InputTag.h:48
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
std::string encode() const
Definition: InputTag.cc:97
std::string const & process() const noexcept
Definition: InputTag.cc:91
void decode(std::any const &, std::string &)
bool empty() const noexcept
Definition: InputTag.cc:73
bool operator==(InputTag const &) const noexcept
Definition: InputTag.cc:66
std::string const & label() const noexcept
Definition: InputTag.cc:79
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
const double a
string tmp
Definition: languages.py:63
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:94
InputTag & operator=(InputTag const &)
void split(std::string const &s, char c, OutIter dest)
Definition: split.h:35
std::string instance_
Definition: InputTag.h:47
static QCString * s
Definition: config.cpp:1042
bool is_sequence(std::any const &val)
Definition: coding.h:49
void decode(std::any const &a, InputTag &tag)
Definition: InputTag.cc:117