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