File indexing completed on 2024-05-23 03:13:15
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, bool optional, bool , DocFormatHelper& dfh) const {
0065 if (dfh.pass() == 0) {
0066 dfh.setAtLeast1(11U);
0067 if (isTracked()) {
0068 dfh.setAtLeast2(parameterTypeEnumToString(type()).size());
0069 } else {
0070 dfh.setAtLeast2(parameterTypeEnumToString(type()).size() + 10U);
0071 }
0072 dfh.setAtLeast3(8U);
0073 } else {
0074 if (dfh.brief()) {
0075 dfh.indent(os);
0076 std::ios::fmtflags oldFlags = os.flags();
0077 os << std::left << std::setw(dfh.column1()) << "wildcard: *"
0078 << " ";
0079
0080 if (isTracked()) {
0081 os << std::setw(dfh.column2()) << parameterTypeEnumToString(type());
0082 } else {
0083 std::stringstream ss;
0084 ss << "untracked " << parameterTypeEnumToString(type());
0085 os << ss.str();
0086 }
0087
0088 os << " ";
0089 os << std::setw(dfh.column3());
0090 if (optional)
0091 os << "optional";
0092 else
0093 os << "";
0094
0095 if (criteria() == RequireZeroOrMore) {
0096 os << " (require zero or more)";
0097 } else if (criteria() == RequireAtLeastOne) {
0098 os << " (require at least one)";
0099 } else if (criteria() == RequireExactlyOne) {
0100 os << " (require exactly one)";
0101 }
0102 os << "\n";
0103 if (hasNestedContent()) {
0104 dfh.indent(os);
0105 os << " (see Section " << dfh.section() << "." << dfh.counter() << ")\n";
0106 }
0107 os.flags(oldFlags);
0108 } else {
0109
0110
0111 dfh.indent(os);
0112 os << "labels must match this wildcard pattern: *\n";
0113
0114 dfh.indent2(os);
0115 os << "type: ";
0116 if (isTracked()) {
0117 os << parameterTypeEnumToString(type());
0118 } else {
0119 os << "untracked " << parameterTypeEnumToString(type());
0120 }
0121
0122 if (optional)
0123 os << " optional";
0124 os << "\n";
0125
0126 dfh.indent2(os);
0127 os << "criteria: ";
0128 if (criteria() == RequireZeroOrMore)
0129 os << "require zero or more";
0130 else if (criteria() == RequireAtLeastOne)
0131 os << "require at least one";
0132 else if (criteria() == RequireExactlyOne)
0133 os << "require exactly one";
0134 os << "\n";
0135
0136 if (hasNestedContent()) {
0137 dfh.indent2(os);
0138 os << "(see Section " << dfh.section() << "." << dfh.counter() << ")\n";
0139 }
0140
0141 if (!comment().empty()) {
0142 DocFormatHelper::wrapAndPrintText(os, comment(), dfh.startColumn2(), dfh.commentWidth());
0143 }
0144 os << "\n";
0145 }
0146 }
0147 }
0148
0149 void ParameterWildcardBase::writeCfi_(std::ostream& os,
0150 bool optional,
0151 bool& startWithComma,
0152 int indentation,
0153 CfiOptions& options,
0154 bool& wroteSomething) const {
0155 wroteSomething = true;
0156 if (startWithComma)
0157 os << ",";
0158 startWithComma = true;
0159
0160 os << "\n";
0161 printSpaces(os, indentation);
0162
0163 os << "allowAnyLabel_ = cms.";
0164
0165 if (optional) {
0166 os << "optional.";
0167 } else {
0168 os << "required.";
0169 }
0170 if (!isTracked())
0171 os << "untracked.";
0172
0173 writeTemplate(os, indentation, options);
0174 }
0175
0176 void ParameterWildcardBase::writeTemplate(std::ostream& os, int indentation, CfiOptions&) const {
0177 os << parameterTypeEnumToString(type());
0178 }
0179
0180 bool ParameterWildcardBase::partiallyExists_(ParameterSet const& pset) const { return exists(pset); }
0181
0182 int ParameterWildcardBase::howManyXORSubNodesExist_(ParameterSet const& pset) const { return exists(pset) ? 1 : 0; }
0183 }