Go to the documentation of this file.00001
00002 #include "FWCore/ParameterSet/interface/ParameterWildcardBase.h"
00003 #include "FWCore/Utilities/interface/EDMException.h"
00004 #include "FWCore/ParameterSet/interface/DocFormatHelper.h"
00005
00006 #include <ostream>
00007 #include <iomanip>
00008 #include <sstream>
00009
00010 namespace edm {
00011
00012 ParameterWildcardBase::~ParameterWildcardBase() { }
00013
00014 ParameterWildcardBase::ParameterWildcardBase(ParameterTypes iType,
00015 bool isTracked,
00016 WildcardValidationCriteria criteria)
00017 :type_(iType),
00018 isTracked_(isTracked),
00019 criteria_(criteria)
00020 { }
00021
00022 void
00023 ParameterWildcardBase::
00024 throwIfInvalidPattern(char const* pattern) const {
00025 std::string sPattern(pattern);
00026 throwIfInvalidPattern(sPattern);
00027 }
00028
00029 void
00030 ParameterWildcardBase::
00031 throwIfInvalidPattern(std::string const& pattern) const {
00032 if (pattern != std::string("*")) {
00033 throw edm::Exception(errors::Configuration)
00034 << "Currently, the only supported wildcard in ParameterSetDescriptions\n"
00035 << "is the single character \"*\". The configuration contains a wildcard\n"
00036 << "with pattern \"" << pattern << "\" and type \"" << parameterTypeEnumToString(type()) << "\"\n"
00037 << "At some future date, globbing or regular expression support may be added\n"
00038 << "if there are any requests for it from users.\n";
00039 }
00040 }
00041
00042 void
00043 ParameterWildcardBase::
00044 validateMatchingNames(std::vector<std::string> const& matchingNames,
00045 std::set<std::string> & validatedLabels,
00046 bool optional) const {
00047 validatedLabels.insert(matchingNames.begin(), matchingNames.end());
00048 if (criteria_ == RequireZeroOrMore) return;
00049 if (criteria_ == RequireAtLeastOne && matchingNames.size() < 1U && !optional) {
00050 throw edm::Exception(errors::Configuration)
00051 << "Parameter wildcard of type \"" << parameterTypeEnumToString(type()) << "\" requires "
00052 << "at least one match\n"
00053 << "and there are no parameters in the configuration matching\n"
00054 << "that type.\n";
00055 }
00056 else if (criteria_ == RequireExactlyOne) {
00057 if ( (matchingNames.size() < 1U && !optional) ||
00058 matchingNames.size() > 1U) {
00059 throw edm::Exception(errors::Configuration)
00060 << "Parameter wildcard of type \"" << parameterTypeEnumToString(type()) << "\" requires\n"
00061 << "exactly one match and there are " << matchingNames.size() << " matching parameters\n"
00062 << "in the configuration.\n";
00063 }
00064 }
00065 }
00066
00067 void
00068 ParameterWildcardBase::
00069 checkAndGetLabelsAndTypes_(std::set<std::string> & usedLabels,
00070 std::set<ParameterTypes> & parameterTypes,
00071 std::set<ParameterTypes> & wildcardTypes) const {
00072 wildcardTypes.insert(type());
00073 }
00074
00075 void
00076 ParameterWildcardBase::
00077 print_(std::ostream & os,
00078 bool optional,
00079 bool writeToCfi,
00080 DocFormatHelper & dfh)
00081 {
00082 if (dfh.pass() == 0) {
00083 dfh.setAtLeast1(11U);
00084 if (isTracked()) {
00085 dfh.setAtLeast2(parameterTypeEnumToString(type()).size());
00086 }
00087 else {
00088 dfh.setAtLeast2(parameterTypeEnumToString(type()).size() + 10U);
00089 }
00090 dfh.setAtLeast3(8U);
00091 }
00092 else {
00093
00094 if (dfh.brief()) {
00095
00096 dfh.indent(os);
00097 std::ios::fmtflags oldFlags = os.flags();
00098 os << std::left << std::setw(dfh.column1()) << "wildcard: *" << " ";
00099
00100 if (isTracked()) {
00101 os << std::setw(dfh.column2()) << parameterTypeEnumToString(type());
00102 }
00103 else {
00104 std::stringstream ss;
00105 ss << "untracked " << parameterTypeEnumToString(type());
00106 os << ss.str();
00107 }
00108
00109 os << " ";
00110 os << std::setw(dfh.column3());
00111 if (optional) os << "optional";
00112 else os << "";
00113
00114 if (criteria() == RequireZeroOrMore) {
00115 os << " (require zero or more)";
00116 }
00117 else if (criteria() == RequireAtLeastOne) {
00118 os << " (require at least one)";
00119 }
00120 else if (criteria() == RequireExactlyOne) {
00121 os << " (require exactly one)";
00122 }
00123 os << "\n";
00124 if (hasNestedContent()) {
00125 dfh.indent(os);
00126 os << " (see Section " << dfh.section()
00127 << "." << dfh.counter() << ")\n";
00128 }
00129 os.flags(oldFlags);
00130 }
00131
00132 else {
00133
00134 dfh.indent(os);
00135 os << "labels must match this wildcard pattern: *\n";
00136
00137 dfh.indent2(os);
00138 os << "type: ";
00139 if (isTracked()) {
00140 os << parameterTypeEnumToString(type());
00141 }
00142 else {
00143 os << "untracked " << parameterTypeEnumToString(type());
00144 }
00145
00146 if (optional) os << " optional";
00147 os << "\n";
00148
00149 dfh.indent2(os);
00150 os << "criteria: ";
00151 if (criteria() == RequireZeroOrMore) os << "require zero or more";
00152 else if (criteria() == RequireAtLeastOne) os << "require at least one";
00153 else if (criteria() == RequireExactlyOne) os << "require exactly one";
00154 os << "\n";
00155
00156 if (hasNestedContent()) {
00157 dfh.indent2(os);
00158 os << "(see Section " << dfh.section()
00159 << "." << dfh.counter() << ")\n";
00160 }
00161
00162 if (!comment().empty()) {
00163 DocFormatHelper::wrapAndPrintText(os,
00164 comment(),
00165 dfh.startColumn2(),
00166 dfh.commentWidth());
00167 }
00168 os << "\n";
00169 }
00170 }
00171 }
00172
00173 void
00174 ParameterWildcardBase::
00175 writeCfi_(std::ostream & os,
00176 bool & startWithComma,
00177 int indentation,
00178 bool & wroteSomething) const {
00179
00180
00181 }
00182
00183 bool
00184 ParameterWildcardBase::
00185 partiallyExists_(ParameterSet const& pset) const {
00186 return exists(pset);
00187 }
00188
00189 int
00190 ParameterWildcardBase::
00191 howManyXORSubNodesExist_(ParameterSet const& pset) const {
00192 return exists(pset) ? 1 : 0;
00193 }
00194 }