LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
PluginSymbolResolvers.h
Go to the documentation of this file.
1 #ifndef art_Framework_Art_detail_PluginSymbolResolvers_h
2 #define art_Framework_Art_detail_PluginSymbolResolvers_h
3 
7 #include "boost/filesystem.hpp"
8 #include "cetlib/LibraryManager.h"
10 
11 #include <iostream>
12 #include <sstream>
13 #include <string>
14 
15 namespace art {
16  namespace detail {
17 
18  template <typename F, typename RT = decltype(std::declval<F>()())>
19  RT
20  resolve_if_present(F f, std::string const& caller, RT result)
21  {
22  try {
23  result = f();
24  }
25  catch (cet::exception const& e) {
26  std::cout << "In: " << caller << std::endl;
27  std::cout << e.what() << std::endl;
28  }
29  return result;
30  }
31 
32  template <art::suffix_type st>
33  std::string
34  getFilePath(cet::LibraryManager const& lm, std::string const& fullspec)
35  {
36  using GetSourceLoc_t = std::string();
37 
38  using namespace std::string_literals;
39  auto path = [&lm, &fullspec] {
40  GetSourceLoc_t* symbolLoc{};
41  lm.getSymbolByLibspec(fullspec, "get_source_location", symbolLoc);
42  std::string source{symbolLoc()};
43  boost::filesystem::path const p{source};
44  if (!boost::filesystem::exists(p)) {
45  source = "/ [ external source ] /" + fullspec + "_" +
46  Suffixes::get(st) + ".cc";
47  }
48  return source;
49  };
50 
51  return resolve_if_present(path, __func__, "[ not found ]"s);
52  }
53 
54  template <art::suffix_type>
55  std::string
56  getType(cet::LibraryManager const&, std::string const& /*fullSpec*/)
57  {
58  return {};
59  }
60 
61  template <>
62  std::string getType<suffix_type::module>(cet::LibraryManager const& lm,
63  std::string const& fullSpec);
64  template <>
65  std::string getType<suffix_type::plugin>(cet::LibraryManager const& lm,
66  std::string const& fullSpec);
67  template <>
68  std::string getType<suffix_type::tool>(cet::LibraryManager const& lm,
69  std::string const& fullSpec);
70 
71  template <art::suffix_type>
72  std::unique_ptr<fhicl::ConfigurationTable>
73  getAllowedConfiguration(cet::LibraryManager const& lm,
74  std::string const& fullSpec,
75  std::string const& name)
76  {
77  using GetAllowedConfiguration_t =
78  std::unique_ptr<fhicl::ConfigurationTable>(std::string const&);
79 
80  auto description = [&lm, &fullSpec, &name] {
81  GetAllowedConfiguration_t* symbolType{};
82  lm.getSymbolByLibspec(fullSpec, "allowed_configuration", symbolType);
83  return symbolType(name);
84  };
85 
86  return resolve_if_present(
87  description,
88  __func__,
89  std::unique_ptr<fhicl::ConfigurationTable>{nullptr});
90  }
91  }
92 }
93 
94 #endif /* art_Framework_Art_detail_PluginSymbolResolvers_h */
95 
96 // Local variables:
97 // mode: c++
98 // End:
std::string getType(cet::LibraryManager const &, std::string const &)
Float_t s
Definition: plot.C:23
TFile f
Definition: plotHisto.C:6
std::unique_ptr< fhicl::ConfigurationTable > getAllowedConfiguration(cet::LibraryManager const &lm, std::string const &fullSpec, std::string const &name)
std::string getFilePath(cet::LibraryManager const &lm, std::string const &fullspec)
RT resolve_if_present(F f, std::string const &caller, RT result)
static std::string const & get(suffix_type st)
HLT enums.
Float_t e
Definition: plot.C:34
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33