CMS 3D CMS Logo

ParameterWildcardBase.cc
Go to the documentation of this file.
1 
3 
6 
7 #include <iomanip>
8 #include <ostream>
9 #include <sstream>
10 
11 namespace edm {
12 
14 
16  bool isTracked,
18  : type_(iType), isTracked_(isTracked), criteria_(criteria) {}
19 
21  std::string sPattern(pattern);
22  throwIfInvalidPattern(sPattern);
23  }
24 
26  if (pattern != std::string("*")) {
28  << "Currently, the only supported wildcard in ParameterSetDescriptions\n"
29  << "is the single character \"*\". The configuration contains a wildcard\n"
30  << "with pattern \"" << pattern << "\" and type \"" << parameterTypeEnumToString(type()) << "\"\n"
31  << "At some future date, globbing or regular expression support may be added\n"
32  << "if there are any requests for it from users.\n";
33  }
34  }
35 
36  void ParameterWildcardBase::validateMatchingNames(std::vector<std::string> const& matchingNames,
37  std::set<std::string>& validatedLabels,
38  bool optional) const {
39  validatedLabels.insert(matchingNames.begin(), matchingNames.end());
41  return;
42  if (criteria_ == RequireAtLeastOne && matchingNames.empty() && !optional) {
44  << "Parameter wildcard of type \"" << parameterTypeEnumToString(type()) << "\" requires "
45  << "at least one match\n"
46  << "and there are no parameters in the configuration matching\n"
47  << "that type.\n";
48  } else if (criteria_ == RequireExactlyOne) {
49  if ((matchingNames.empty() && !optional) || matchingNames.size() > 1U) {
51  << "Parameter wildcard of type \"" << parameterTypeEnumToString(type()) << "\" requires\n"
52  << "exactly one match and there are " << matchingNames.size() << " matching parameters\n"
53  << "in the configuration.\n";
54  }
55  }
56  }
57 
58  void ParameterWildcardBase::checkAndGetLabelsAndTypes_(std::set<std::string>& /*usedLabels*/,
59  std::set<ParameterTypes>& /*parameterTypes*/,
60  std::set<ParameterTypes>& wildcardTypes) const {
61  wildcardTypes.insert(type());
62  }
63 
64  void ParameterWildcardBase::print_(std::ostream& os, bool optional, bool /*writeToCfi*/, DocFormatHelper& dfh) const {
65  if (dfh.pass() == 0) {
66  dfh.setAtLeast1(11U);
67  if (isTracked()) {
69  } else {
70  dfh.setAtLeast2(parameterTypeEnumToString(type()).size() + 10U);
71  }
72  dfh.setAtLeast3(8U);
73  } else {
74  if (dfh.brief()) {
75  dfh.indent(os);
76  std::ios::fmtflags oldFlags = os.flags();
77  os << std::left << std::setw(dfh.column1()) << "wildcard: *"
78  << " ";
79 
80  if (isTracked()) {
81  os << std::setw(dfh.column2()) << parameterTypeEnumToString(type());
82  } else {
83  std::stringstream ss;
84  ss << "untracked " << parameterTypeEnumToString(type());
85  os << ss.str();
86  }
87 
88  os << " ";
89  os << std::setw(dfh.column3());
90  if (optional)
91  os << "optional";
92  else
93  os << "";
94 
95  if (criteria() == RequireZeroOrMore) {
96  os << " (require zero or more)";
97  } else if (criteria() == RequireAtLeastOne) {
98  os << " (require at least one)";
99  } else if (criteria() == RequireExactlyOne) {
100  os << " (require exactly one)";
101  }
102  os << "\n";
103  if (hasNestedContent()) {
104  dfh.indent(os);
105  os << " (see Section " << dfh.section() << "." << dfh.counter() << ")\n";
106  }
107  os.flags(oldFlags);
108  } else {
109  // not brief
110 
111  dfh.indent(os);
112  os << "labels must match this wildcard pattern: *\n";
113 
114  dfh.indent2(os);
115  os << "type: ";
116  if (isTracked()) {
118  } else {
119  os << "untracked " << parameterTypeEnumToString(type());
120  }
121 
122  if (optional)
123  os << " optional";
124  os << "\n";
125 
126  dfh.indent2(os);
127  os << "criteria: ";
128  if (criteria() == RequireZeroOrMore)
129  os << "require zero or more";
130  else if (criteria() == RequireAtLeastOne)
131  os << "require at least one";
132  else if (criteria() == RequireExactlyOne)
133  os << "require exactly one";
134  os << "\n";
135 
136  if (hasNestedContent()) {
137  dfh.indent2(os);
138  os << "(see Section " << dfh.section() << "." << dfh.counter() << ")\n";
139  }
140 
141  if (!comment().empty()) {
143  }
144  os << "\n";
145  }
146  }
147  }
148 
150  bool optional,
151  bool& startWithComma,
152  int indentation,
154  bool& wroteSomething) const {
155  wroteSomething = true;
156  if (startWithComma)
157  os << ",";
158  startWithComma = true;
159 
160  os << "\n";
162 
163  os << "allowAnyLabel_ = cms.";
164 
165  if (optional) {
166  os << "optional.";
167  } else {
168  os << "required.";
169  }
170  if (!isTracked())
171  os << "untracked.";
172 
174  }
175 
178  }
179 
181 
183 } // namespace edm
WildcardValidationCriteria
bool partiallyExists_(ParameterSet const &pset) const override
void throwIfInvalidPattern(char const *pattern) const
void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const override
int startColumn2() const
static void wrapAndPrintText(std::ostream &os, std::string const &text, size_t indent, size_t suggestedWidth)
void writeCfi_(std::ostream &os, bool optional, bool &startWithComma, int indentation, CfiOptions &, bool &wroteSomething) const override
std::string parameterTypeEnumToString(ParameterTypes iType)
virtual void writeTemplate(std::ostream &os, int indentation, CfiOptions &) const
size_t commentWidth() const
WildcardValidationCriteria criteria_
void indent2(std::ostream &os) const
size_t column1() const
void setAtLeast2(size_t width)
optional
Definition: Types.py:245
size_t column3() const
size_t column2() const
void validateMatchingNames(std::vector< std::string > const &matchingNames, std::set< std::string > &validatedLabels, bool optional) const
std::string const & section() const
static void printSpaces(std::ostream &os, int n)
ParameterTypes type() const
WildcardValidationCriteria criteria() const
std::string const & comment() const
bool exists(ParameterSet const &pset) const
HLT enums.
void setAtLeast1(size_t width)
void setAtLeast3(size_t width)
void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh) const override
void indent(std::ostream &os) const
int howManyXORSubNodesExist_(ParameterSet const &pset) const override
cfi::CfiOptions CfiOptions
ParameterWildcardBase(ParameterTypes iType, bool isTracked, WildcardValidationCriteria criteria)