LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PluginSymbolResolvers.cc
Go to the documentation of this file.
4 #include "boost/filesystem.hpp"
5 #include "cetlib/LibraryManager.h"
6 
7 #include <iostream>
8 
9 using namespace std::string_literals;
10 namespace bfs = boost::filesystem;
11 using cet::LibraryManager;
12 
13 namespace {
14  template <typename F, typename RT = decltype(std::declval<F>()())>
15  RT
16  resolve_if_present(F f, std::string const& caller, RT result)
17  {
18  try {
19  result = f();
20  }
21  catch (cet::exception const& e) {
22  std::cerr << "In: " << caller << '\n' << e.what() << '\n';
23  }
24  return result;
25  }
26 }
27 
28 namespace art::detail {
29 
30  std::string
31  getFilePath(cet::LibraryManager const& lm, std::string const& fullspec)
32  {
33  using GetSourceLoc_t = std::string();
34 
35  using namespace std::string_literals;
36  auto path = [&lm, &fullspec] {
37  GetSourceLoc_t* symbolLoc{};
38  lm.getSymbolByLibspec(fullspec, "get_source_location", symbolLoc);
39  std::string source{symbolLoc()};
40  boost::filesystem::path const p{source};
41  if (!boost::filesystem::exists(p)) {
42  source =
43  "/ [ external source ] /" + fullspec + "_" + lm.libType() + ".cc";
44  }
45  return source;
46  };
47 
48  return resolve_if_present(path, __func__, "[ not found ]"s);
49  }
50 
51  std::string
52  getType(cet::LibraryManager const& lm, std::string const& fullSpec)
53  {
54  auto const& suffix = lm.libType();
55  if (suffix == Suffixes::module()) {
57 
58  auto type = [&lm, &fullSpec] {
59  ModuleTypeFunc_t* symbolType{nullptr};
60  lm.getSymbolByLibspec(fullSpec, "moduleType", symbolType);
61  return to_string(symbolType());
62  };
63 
64  return resolve_if_present(type, __func__, "[ error ]"s);
65  }
66 
67  if (suffix == Suffixes::plugin()) {
68  using PluginTypeFunc_t = std::string();
69 
70  auto type = [&lm, &fullSpec] {
71  PluginTypeFunc_t* symbolType{nullptr};
72  lm.getSymbolByLibspec(fullSpec, "pluginType", symbolType);
73  return symbolType();
74  };
75 
76  return resolve_if_present(type, __func__, "[ error ]"s);
77  }
78 
79  if (suffix == Suffixes::tool()) {
80  using ToolTypeFunc_t = std::string();
81 
82  auto type = [&lm, &fullSpec] {
83  ToolTypeFunc_t* symbolType{nullptr};
84  lm.getSymbolByLibspec(fullSpec, "toolType", symbolType);
85  return symbolType();
86  };
87 
88  return resolve_if_present(type, __func__, "[ error ]"s);
89  }
90  return {};
91  }
92 
93  std::unique_ptr<fhicl::ConfigurationTable>
94  getAllowedConfiguration(cet::LibraryManager const& lm,
95  std::string const& fullSpec,
96  std::string const& name)
97  {
98  using GetAllowedConfiguration_t =
99  std::unique_ptr<fhicl::ConfigurationTable>(std::string const&);
100 
101  auto description = [&lm, &fullSpec, &name] {
102  GetAllowedConfiguration_t* symbolType{};
103  lm.getSymbolByLibspec(fullSpec, "allowed_configuration", symbolType);
104  return symbolType(name);
105  };
106 
107  return resolve_if_present(
108  description,
109  __func__,
110  std::unique_ptr<fhicl::ConfigurationTable>{nullptr});
111  }
112 } // namespace art::detail
std::string getType(cet::LibraryManager const &lm, std::string const &fullSpec)
TFile f
Definition: plotHisto.C:6
std::unique_ptr< fhicl::ConfigurationTable > getAllowedConfiguration(cet::LibraryManager const &lm, std::string const &fullSpec, std::string const &name)
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
std::string getFilePath(cet::LibraryManager const &lm, std::string const &fullspec)
ModuleType( ModuleTypeFunc_t)
Definition: ModuleMacros.h:34
Float_t e
Definition: plot.C:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
ModuleType
Definition: ModuleType.h:11