CMS 3D CMS Logo

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