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"
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>
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()};
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>
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>
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 &)
const XML_Char * name
Definition: expat.h:151
#define F(x, y, z)
const char * p
Definition: xmltok.h:285
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
T getSymbolByLibspec(std::string const &libspec, std::string const &sym_name) const
const XML_Char * s
Definition: expat.h:262
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)
const char * source
Definition: lz4.h:436
OStream cout
Definition: OStream.cxx:6
const std::string path
Definition: plot_BEN.C:43
RT resolve_if_present(F f, std::string const &caller, RT result)
static std::string const & get(suffix_type st)
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
Float_t e
Definition: plot.C:35
enum BeamMode string