4 #include "boost/filesystem.hpp" 5 #include "cetlib/LibraryManager.h" 10 namespace bfs = boost::filesystem;
11 using cet::LibraryManager;
14 template <
typename F,
typename RT = decltype(std::declval<F>()())>
16 resolve_if_present(F
f, std::string
const& caller, RT result)
22 std::cerr <<
"In: " << caller <<
'\n' << e.what() <<
'\n';
31 getFilePath(cet::LibraryManager
const& lm, std::string
const& fullspec)
33 using GetSourceLoc_t = std::string();
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)) {
43 "/ [ external source ] /" + fullspec +
"_" + lm.libType() +
".cc";
48 return resolve_if_present(path, __func__,
"[ not found ]"s);
52 getType(cet::LibraryManager
const& lm, std::string
const& fullSpec)
54 auto const& suffix = lm.libType();
55 if (suffix == Suffixes::module()) {
58 auto type = [&lm, &fullSpec] {
60 lm.getSymbolByLibspec(fullSpec,
"moduleType", symbolType);
64 return resolve_if_present(
type, __func__,
"[ error ]"s);
67 if (suffix == Suffixes::plugin()) {
68 using PluginTypeFunc_t = std::string();
70 auto type = [&lm, &fullSpec] {
71 PluginTypeFunc_t* symbolType{
nullptr};
72 lm.getSymbolByLibspec(fullSpec,
"pluginType", symbolType);
76 return resolve_if_present(
type, __func__,
"[ error ]"s);
79 if (suffix == Suffixes::tool()) {
80 using ToolTypeFunc_t = std::string();
82 auto type = [&lm, &fullSpec] {
83 ToolTypeFunc_t* symbolType{
nullptr};
84 lm.getSymbolByLibspec(fullSpec,
"toolType", symbolType);
88 return resolve_if_present(
type, __func__,
"[ error ]"s);
93 std::unique_ptr<fhicl::ConfigurationTable>
95 std::string
const& fullSpec,
96 std::string
const& name)
98 using GetAllowedConfiguration_t =
99 std::unique_ptr<fhicl::ConfigurationTable>(std::string
const&);
101 auto description = [&lm, &fullSpec, &name] {
102 GetAllowedConfiguration_t* symbolType{};
103 lm.getSymbolByLibspec(fullSpec,
"allowed_configuration", symbolType);
104 return symbolType(name);
107 return resolve_if_present(
110 std::unique_ptr<fhicl::ConfigurationTable>{
nullptr});
std::string getType(cet::LibraryManager const &lm, std::string const &fullSpec)
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)
cet::coded_exception< error, detail::translate > exception