LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
triton_utils.cc
Go to the documentation of this file.
2 #include "cetlib_except/exception.h"
5 
6 #include <algorithm>
7 #include <experimental/iterator>
8 #include <iostream>
9 #include <sstream>
10 #include <string>
11 
12 namespace triton_utils {
13 
14  template <typename C>
15  std::string printColl(const C& coll, const std::string& delim)
16  {
17  if (coll.empty()) return "";
18  using std::begin;
19  using std::end;
20  std::stringstream msg;
21  //avoid trailing delim
22  std::copy(begin(coll), end(coll), std::experimental::make_ostream_joiner(msg, delim));
23  return msg.str();
24  }
25 
26  void throwIfError(const Error& err, std::string_view msg)
27  {
28  if (!err.IsOk()) throw cet::exception("TritonServerFailure") << msg << ": " << err;
29  }
30 
31  bool warnIfError(const Error& err, std::string_view msg)
32  {
33  if (!err.IsOk()) MF_LOG_WARNING("TritonServerWarning") << msg << ": " << err;
34  return err.IsOk();
35  }
36 
37 } // namespace triton_utils
38 
39 template std::string triton_utils::printColl(
41  const std::string& delim);
42 template std::string triton_utils::printColl(const std::vector<uint8_t>& coll,
43  const std::string& delim);
44 template std::string triton_utils::printColl(const std::vector<float>& coll,
45  const std::string& delim);
46 template std::string triton_utils::printColl(const std::unordered_set<std::string>& coll,
47  const std::string& delim);
std::string printColl(const C &coll, const std::string &delim)
Definition: triton_utils.cc:15
bool warnIfError(const Error &err, std::string_view msg)
Definition: triton_utils.cc:31
intermediate_table::const_iterator const_iterator
void throwIfError(const Error &err, std::string_view msg)
Definition: triton_utils.cc:26
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
triton::client::Error Error
Definition: triton_utils.h:12
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
#define MF_LOG_WARNING(category)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33