File indexing completed on 2025-03-26 01:51:14
0001
0002 #include "FWCore/ParameterSet/interface/ParameterWildcardBase.h"
0003
0004 #include "FWCore/ParameterSet/interface/DocFormatHelper.h"
0005 #include "FWCore/Utilities/interface/EDMException.h"
0006
0007 #include <iomanip>
0008 #include <ostream>
0009 #include <sstream>
0010
0011 namespace edm {
0012
0013 ParameterWildcardBase::~ParameterWildcardBase() {}
0014
0015 ParameterWildcardBase::ParameterWildcardBase(ParameterTypes iType,
0016 bool isTracked,
0017 WildcardValidationCriteria criteria)
0018 : type_(iType), isTracked_(isTracked), criteria_(criteria) {}
0019
0020 void ParameterWildcardBase::throwIfInvalidPattern(char const* pattern) const {
0021 std::string sPattern(pattern);
0022 throwIfInvalidPattern(sPattern);
0023 }
0024
0025 void ParameterWildcardBase::throwIfInvalidPattern(std::string const& pattern) const {
0026 if (pattern != std::string("*")) {
0027 throw Exception(errors::Configuration)
0028 << "Currently, the only supported wildcard in ParameterSetDescriptions\n"
0029 << "is the single character \"*\". The configuration contains a wildcard\n"
0030 << "with pattern \"" << pattern << "\" and type \"" << parameterTypeEnumToString(type()) << "\"\n"
0031 << "At some future date, globbing or regular expression support may be added\n"
0032 << "if there are any requests for it from users.\n";
0033 }
0034 }
0035
0036 void ParameterWildcardBase::validateMatchingNames(std::vector<std::string> const& matchingNames,
0037 std::set<std::string>& validatedLabels,
0038 bool optional) const {
0039 validatedLabels.insert(matchingNames.begin(), matchingNames.end());
0040 if (criteria_ == RequireZeroOrMore)
0041 return;
0042 if (criteria_ == RequireAtLeastOne && matchingNames.empty() && !optional) {
0043 throw Exception(errors::Configuration)
0044 << "Parameter wildcard of type \"" << parameterTypeEnumToString(type()) << "\" requires "
0045 << "at least one match\n"
0046 << "and there are no parameters in the configuration matching\n"
0047 << "that type.\n";
0048 } else if (criteria_ == RequireExactlyOne) {
0049 if ((matchingNames.empty() && !optional) || matchingNames.size() > 1U) {
0050 throw Exception(errors::Configuration)
0051 << "Parameter wildcard of type \"" << parameterTypeEnumToString(type()) << "\" requires\n"
0052 << "exactly one match and there are " << matchingNames.size() << " matching parameters\n"
0053 << "in the configuration.\n";
0054 }
0055 }
0056 }
0057
0058 void ParameterWildcardBase::checkAndGetLabelsAndTypes_(std::set<std::string>& ,
0059 std::set<ParameterTypes>& ,
0060 std::set<ParameterTypes>& wildcardTypes) const {
0061 wildcardTypes.insert(type());
0062 }
0063
0064 void ParameterWildcardBase::print_(std::ostream& os,
0065 Modifier modifier,
0066 bool ,
0067 DocFormatHelper& dfh) const {
0068 if (dfh.pass() == 0) {
0069 dfh.setAtLeast1(11U);
0070 if (isTracked()) {
0071 dfh.setAtLeast2(parameterTypeEnumToString(type()).size());
0072 } else {
0073 dfh.setAtLeast2(parameterTypeEnumToString(type()).size() + 10U);
0074 }
0075 dfh.setAtLeast3(8U);
0076 } else {
0077 const bool optional = (Modifier::kOptional == modifier);
0078 const bool obsolete = (Modifier::kObsolete == modifier);
0079 if (dfh.brief()) {
0080 dfh.indent(os);
0081 std::ios::fmtflags oldFlags = os.flags();
0082 os << std::left << std::setw(dfh.column1()) << "wildcard: *"
0083 << " ";
0084
0085 if (isTracked()) {
0086 os << std::setw(dfh.column2()) << parameterTypeEnumToString(type());
0087 } else {
0088 std::stringstream ss;
0089 ss << "untracked " << parameterTypeEnumToString(type());
0090 os << ss.str();
0091 }
0092
0093 os << " ";
0094 os << std::setw(dfh.column3());
0095 if (optional)
0096 os << "optional";
0097 else if (obsolete)
0098 os << "obsolete";
0099 else
0100 os << "";
0101
0102 if (criteria() == RequireZeroOrMore) {
0103 os << " (require zero or more)";
0104 } else if (criteria() == RequireAtLeastOne) {
0105 os << " (require at least one)";
0106 } else if (criteria() == RequireExactlyOne) {
0107 os << " (require exactly one)";
0108 }
0109 os << "\n";
0110 if (hasNestedContent()) {
0111 dfh.indent(os);
0112 os << " (see Section " << dfh.section() << "." << dfh.counter() << ")\n";
0113 }
0114 os.flags(oldFlags);
0115 } else {
0116
0117
0118 dfh.indent(os);
0119 os << "labels must match this wildcard pattern: *\n";
0120
0121 dfh.indent2(os);
0122 os << "type: ";
0123 if (isTracked()) {
0124 os << parameterTypeEnumToString(type());
0125 } else {
0126 os << "untracked " << parameterTypeEnumToString(type());
0127 }
0128
0129 if (optional)
0130 os << " optional";
0131 if (obsolete)
0132 os << "obsolete";
0133 os << "\n";
0134
0135 dfh.indent2(os);
0136 os << "criteria: ";
0137 if (criteria() == RequireZeroOrMore)
0138 os << "require zero or more";
0139 else if (criteria() == RequireAtLeastOne)
0140 os << "require at least one";
0141 else if (criteria() == RequireExactlyOne)
0142 os << "require exactly one";
0143 os << "\n";
0144
0145 if (hasNestedContent()) {
0146 dfh.indent2(os);
0147 os << "(see Section " << dfh.section() << "." << dfh.counter() << ")\n";
0148 }
0149
0150 if (!comment().empty()) {
0151 DocFormatHelper::wrapAndPrintText(os, comment(), dfh.startColumn2(), dfh.commentWidth());
0152 }
0153 os << "\n";
0154 }
0155 }
0156 }
0157
0158 void ParameterWildcardBase::writeCfi_(std::ostream& os,
0159 Modifier modifier,
0160 bool& startWithComma,
0161 int indentation,
0162 CfiOptions& options,
0163 bool& wroteSomething) const {
0164 wroteSomething = true;
0165 if (startWithComma)
0166 os << ",";
0167 startWithComma = true;
0168
0169 os << "\n";
0170 printSpaces(os, indentation);
0171
0172 os << "allowAnyLabel_ = cms.";
0173
0174 if (Modifier::kOptional == modifier) {
0175 os << "optional.";
0176 } else if (Modifier::kObsolete == modifier) {
0177 os << "obsolete.";
0178 } else {
0179 os << "required.";
0180 }
0181 if (!isTracked())
0182 os << "untracked.";
0183
0184 writeTemplate(os, indentation, options);
0185 }
0186
0187 void ParameterWildcardBase::writeTemplate(std::ostream& os, int indentation, CfiOptions&) const {
0188 os << parameterTypeEnumToString(type());
0189 }
0190
0191 bool ParameterWildcardBase::partiallyExists_(ParameterSet const& pset) const { return exists(pset); }
0192
0193 int ParameterWildcardBase::howManyXORSubNodesExist_(ParameterSet const& pset) const { return exists(pset) ? 1 : 0; }
0194 }