7 #include "cetlib/HorizontalRule.h" 8 #include "cetlib/bold_fontify.h" 9 #include "cetlib/container_algorithms.h" 21 std::pair<std::string, std::string>>
const block_parameters = {
30 constexpr cet::HorizontalRule fixed_rule{100};
32 std::vector<art::detail::PluginMetadata>
33 matchesBySpec(std::string
const& specified_plugin_type,
34 std::string
const& instance_pattern)
36 std::vector<PluginMetadata> result;
37 auto collect_metadata = [&result,
38 &instance_pattern](std::string
const& suffix) {
42 std::string header_label{
"plugin_type"};
43 std::string param_to_replace{
"plugin_type"};
44 auto params = block_parameters.find(suffix);
45 if (params !=
cend(block_parameters)) {
46 header_label = params->second.first;
47 param_to_replace = params->second.second;
51 back_inserter(result),
52 [&mc, &header_label, ¶m_to_replace](
auto const& info) {
53 return mc->collect(info,
indent__2(), header_label, param_to_replace);
57 if (specified_plugin_type.empty()) {
61 collect_metadata(suffix);
64 collect_metadata(specified_plugin_type);
69 using Duplicates_t = std::map<std::string, std::vector<std::string>>;
71 duplicates_message(std::string
const& suffix, Duplicates_t
const& duplicates)
74 std::string
const type_spec =
77 <<
indent0() <<
"The " << suffix
78 <<
"s marked '*' above are degenerate--i.e. specifying the short\n" 80 <<
" value leads to an ambiguity. In order to use a degenerate\n" 82 <<
", in your configuration file, give the long specification (as\n" 84 <<
"shown in the table below), surrounded by quotation (\") marks.\n\n";
85 std::size_t
const firstColW{
86 columnWidth(duplicates, &Duplicates_t::value_type::first,
"module_type")};
88 <<
std::left <<
"Long specification" <<
'\n';
89 cout <<
indent0() << fixed_rule(
'-') <<
'\n';
90 for (
auto const& dup : duplicates) {
91 auto const& long_specs = dup.second;
92 cout <<
indent0() << std::setw(firstColW + 4) << std::left << dup.first
93 << std::left << long_specs[0] <<
'\n';
94 for (
auto it = long_specs.begin() + 1,
end = long_specs.end(); it !=
end;
96 cout <<
indent0() << std::setw(firstColW + 4) <<
"\"\"" << std::left
106 std::string
const& spec,
111 cout <<
"Unable to find any plugins with suffix '" << suffix <<
"'.\n";
117 cet::HorizontalRule
const rule{
rule_size(ms->widths())};
120 << ms->header() <<
'\n' 121 << rule(
'-') <<
'\n';
124 Duplicates_t duplicates;
125 for (
auto const& info : coll) {
126 auto summary = ms->summary(info, ++i);
127 cout << summary.message;
128 if (summary.is_duplicate)
129 duplicates[info.short_spec()].push_back(info.long_spec());
131 cout << rule(
'=') <<
"\n\n";
133 if (duplicates.empty())
136 duplicates_message(suffix, duplicates);
142 std::string
const& spec,
143 std::string
const& key)
148 throw e << (spec.empty() ?
"[Missing specification]" :
149 cet::bold_fontify(spec))
150 <<
" did not match any plugin.\n";
151 }
else if (coll.size() > 1ull) {
152 throw e << cet::bold_fontify(spec) <<
" matched more than one plugin.\n" 153 <<
"When querying plugin configurations, the plugin specification\n" 154 <<
"must resolve to a unique library.\n";
156 if (
auto config = coll.begin()->allowed_config()) {
158 *config->parameter_base(), key);
166 for (
auto const& m : matches) {
167 cout << m.header() << m.details() << m.allowed_configuration();
168 cout <<
'\n' << fixed_rule(
'=') <<
"\n\n";
173 std::pair<std::string, std::string>
174 parse_specified_plugin(std::string
const& spec)
181 std::string specified_plugin_type{};
182 std::string instance_pattern{spec};
183 auto const pos = spec.find(
":");
184 if (pos != std::string::npos) {
185 specified_plugin_type = spec.substr(0, pos);
186 if (specified_plugin_type.empty()) {
188 "Error while parsing specified plugins:\n"}
189 <<
"The specification '" << spec
190 <<
"' is missing a module type before the colon (':').\n" 191 "If you intend to search through all plugin types, remove the " 192 "colon; otherwise specify\n" 193 "one of the following plugin types:" 196 instance_pattern = spec.substr(pos + 1);
198 return std::make_pair(std::move(specified_plugin_type),
199 std::move(instance_pattern));
206 cout <<
'\n' << fixed_rule(
'=') <<
"\n\n";
207 for (
auto const& spec : specs) {
208 auto const [plugin_type, instance_pattern] = parse_specified_plugin(spec);
210 auto matches = matchesBySpec(plugin_type, instance_pattern);
211 if (matches.empty()) {
213 << (instance_pattern.empty() ?
"[Missing specification]" :
214 cet::bold_fontify(instance_pattern))
215 <<
" did not match any plugin";
216 cout << (plugin_type.empty() ?
"" :
" of type '" + plugin_type +
"'");
218 cout <<
'\n' << fixed_rule(
'=') <<
"\n\n";
static std::string const & mfStatsPlugin()
LibraryInfoCollection get_LibraryInfoCollection(std::string const &suffix, std::string const &pattern, bool verbose=false)
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
std::size_t columnWidth(T const &coll, std::string const Elem::*cp, std::string const &header)
static std::vector< std::string > const & all()
static std::string print()
static std::string const & source()
std::size_t rule_size(Widths const &widths)
bool supports_key(std::string const &suffix, std::string const &spec, std::string const &key)
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
std::unique_ptr< MetadataSummary > get_MetadataSummary(std::string const &suffix, LibraryInfoCollection const &coll)
void print_available_plugins(std::string const &suffix, std::string const &spec, bool verbose)
static std::string const & plugin()
static std::string const & tool()
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
void print_descriptions(std::vector< std::string > const &plugins)
static std::string const & mfPlugin()
static std::string const & service()
std::unique_ptr< MetadataCollector > get_MetadataCollector(std::string const &suffix)
void print_description(std::vector< PluginMetadata > const &matches)
static std::string const & module()
static bool supports_key(ParameterBase const &pb, std::string const &searched_for_key)