LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
make_tool.h
Go to the documentation of this file.
1 #ifndef art_Utilities_make_tool_h
2 #define art_Utilities_make_tool_h
3 
7 #include "cetlib/BasicPluginFactory.h"
8 #include "cetlib/detail/wrapLibraryManagerException.h"
10 
11 namespace art {
12 
13  template <typename T>
15 
16  template <typename T>
19  {
20  cet::BasicPluginFactory factory{Suffixes::tool(), "makeTool"};
21  std::string const libspec{pset.get<std::string>("tool_type")};
22  tool_return_type<T> result;
23  try {
24  result = detail::tool_type<T>::make_plugin(factory, libspec, pset);
25  }
26  catch (cet::exception const& e) {
27  throw Exception(errors::Configuration, "make_tool: ", e)
28  << "Exception caught while processing plugin spec: " << libspec << '\n';
29  }
30  return result;
31  }
32 
33  template <typename T>
36  std::string const& function_tool_type)
37  {
38  cet::BasicPluginFactory factory{
39  Suffixes::tool(), "toolFunction", "toolType"};
40  std::string const libspec{pset.get<std::string>("tool_type")};
41  tool_return_type<T> result;
42  try {
44  factory, libspec, pset, function_tool_type);
45  }
46  catch (cet::exception const& e) {
47  throw Exception(errors::Configuration, "make_tool: ", e)
48  << "Exception caught while processing plugin spec: " << libspec << '\n';
49  }
50  return result;
51  }
52 
53  template <typename T, typename TableConfig>
55  make_tool(TableConfig const& tc, std::string const& function_tool_type)
56  {
57  if constexpr (std::is_class_v<T>) {
58  return make_tool<T>(tc.get_PSet());
59  } else if (std::is_function_v<T>) {
60  return make_tool<T>(tc.get_PSet(), function_tool_type);
61  }
62  }
63 
64 } // namespace art
65 
66 #endif /* art_Utilities_make_tool_h */
67 
68 // Local variables:
69 // mode: c++
70 // End:
std::enable_if_t< std::is_class< T >::value, tool_return_type< T > > make_tool(fhicl::ParameterSet const &pset)
Definition: make_tool.h:18
T get(std::string const &key) const
Definition: ParameterSet.h:314
static std::string const & tool()
double value
Definition: spectrum.C:18
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Definition: MVAAlg.h:12
Float_t e
Definition: plot.C:35
typename detail::tool_type< T >::return_type tool_return_type
Definition: make_tool.h:14
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33