LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
InputTag.cc
Go to the documentation of this file.
2 
3 #include "boost/algorithm/string/classification.hpp"
4 #include "boost/algorithm/string/split.hpp"
5 #include "boost/any.hpp"
7 #include "fhiclcpp/coding.h"
8 
9 #include <sstream>
10 #include <stdexcept>
11 #include <vector>
12 
13 namespace art {
14  void
15  InputTag::set_from_string_(std::string const& s)
16  {
17  // string is delimited by colons
18  std::vector<std::string> tokens;
19  // cet::split(s, ':', std::back_inserter(tokens));
20  boost::split(tokens, s, boost::is_any_of(":"), boost::token_compress_off);
21 
22  int nwords = tokens.size();
23  if (nwords > 3) {
24  throw art::Exception(errors::Configuration, "InputTag")
25  << "Input tag " << s << " has " << nwords << " tokens";
26  }
27  if (nwords > 0)
28  label_ = tokens[0];
29  if (nwords > 1)
30  instance_ = tokens[1];
31  if (nwords > 2)
32  process_ = tokens[2];
33  }
34 
35  std::string
37  {
38  // NOTE: since the encoding gets used to form the configuration hash I did
39  // not want
40  // to change it so that not specifying a process would cause two colons to
41  // appear in the encoding and thus not being backwards compatible
42  static std::string const separator(":");
43  std::string result = label_;
44  if (!instance_.empty() || !process_.empty()) {
45  result += separator + instance_;
46  }
47  if (!process_.empty()) {
48  result += separator + process_;
49  }
50  return result;
51  }
52 
53  std::ostream&
54  operator<<(std::ostream& ost, art::InputTag const& tag)
55  {
56  static std::string const process(", process = ");
57  ost << "InputTag: label = " << tag.label()
58  << ", instance = " << tag.instance()
59  << (tag.process().empty() ? std::string() : (process + tag.process()));
60  return ost;
61  }
62 
63  void
64  decode(boost::any const& a, InputTag& tag)
65  {
66 
68  std::vector<std::string> tmp;
69  fhicl::detail::decode(a, tmp);
70  if (tmp.size() == 2)
71  tag = {tmp.at(0), tmp.at(1)};
72  else if (tmp.size() == 3)
73  tag = {tmp.at(0), tmp.at(1), tmp.at(2)};
74  else {
75  std::ostringstream errmsg;
76  errmsg << "When converting to InputTag by a sequence, FHiCL entries "
77  "must follow the convention:\n\n"
78  << " [ label, instance ], or\n"
79  << " [ label, instance, process_name ].\n\n";
80  errmsg << "FHiCL entries provided: [ ";
81  for (auto ca = tmp.begin(); ca != tmp.cend(); ++ca) {
82  errmsg << *ca;
83  if (ca != tmp.cend() - 1) {
84  errmsg << ", ";
85  }
86  }
87  errmsg << " ]";
88  throw std::length_error(errmsg.str());
89  }
90  } else {
91  std::string tmp;
92  fhicl::detail::decode(a, tmp);
93  tag = tmp;
94  }
95  }
96 }
std::ostream & operator<<(std::ostream &os, EDAnalyzer::Table< T > const &t)
Definition: EDAnalyzer.h:184
Float_t s
Definition: plot.C:23
void decode(boost::any const &, std::string &)
void set_from_string_(std::string const &s)
Definition: InputTag.cc:15
std::string label_
Definition: InputTag.h:75
bool is_sequence(boost::any const &val)
Definition: coding.h:50
std::string process_
Definition: InputTag.h:77
Float_t tmp
Definition: plot.C:37
std::string const & process() const noexcept
Definition: InputTag.h:67
std::string encode() const
Definition: InputTag.cc:36
std::string const & instance() const noexcept
Definition: InputTag.h:60
void decode(boost::any const &a, InputTag &tag)
Definition: InputTag.cc:64
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
HLT enums.
std::string const & label() const noexcept
Definition: InputTag.h:55
std::string instance_
Definition: InputTag.h:76