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),
19  isTracked_(isTracked),
20  criteria_(criteria) {
21  }
22 
23  void
25  throwIfInvalidPattern(char const* pattern) const {
26  std::string sPattern(pattern);
27  throwIfInvalidPattern(sPattern);
28  }
29 
30  void
33  if(pattern != std::string("*")) {
35  << "Currently, the only supported wildcard in ParameterSetDescriptions\n"
36  << "is the single character \"*\". The configuration contains a wildcard\n"
37  << "with pattern \"" << pattern << "\" and type \"" << parameterTypeEnumToString(type()) << "\"\n"
38  << "At some future date, globbing or regular expression support may be added\n"
39  << "if there are any requests for it from users.\n";
40  }
41  }
42 
43  void
45  validateMatchingNames(std::vector<std::string> const& matchingNames,
46  std::set<std::string>& validatedLabels,
47  bool optional) const {
48  validatedLabels.insert(matchingNames.begin(), matchingNames.end());
49  if(criteria_ == RequireZeroOrMore) return;
50  if(criteria_ == RequireAtLeastOne && matchingNames.size() < 1U && !optional) {
52  << "Parameter wildcard of type \"" << parameterTypeEnumToString(type()) << "\" requires "
53  << "at least one match\n"
54  << "and there are no parameters in the configuration matching\n"
55  << "that type.\n";
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) const {
81  if(dfh.pass() == 0) {
82  dfh.setAtLeast1(11U);
83  if(isTracked()) {
85  } else {
87  }
88  dfh.setAtLeast3(8U);
89  } else {
90 
91  if(dfh.brief()) {
92 
93  dfh.indent(os);
94  std::ios::fmtflags oldFlags = os.flags();
95  os << std::left << std::setw(dfh.column1()) << "wildcard: *" << " ";
96 
97  if(isTracked()) {
98  os << std::setw(dfh.column2()) << parameterTypeEnumToString(type());
99  } else {
100  std::stringstream ss;
101  ss << "untracked " << parameterTypeEnumToString(type());
102  os << ss.str();
103  }
104 
105  os << " ";
106  os << std::setw(dfh.column3());
107  if(optional) os << "optional";
108  else os << "";
109 
110  if(criteria() == RequireZeroOrMore) {
111  os << " (require zero or more)";
112  } else if(criteria() == RequireAtLeastOne) {
113  os << " (require at least one)";
114  } else if(criteria() == RequireExactlyOne) {
115  os << " (require exactly one)";
116  }
117  os << "\n";
118  if(hasNestedContent()) {
119  dfh.indent(os);
120  os << " (see Section " << dfh.section()
121  << "." << dfh.counter() << ")\n";
122  }
123  os.flags(oldFlags);
124  } else {
125  // not brief
126 
127  dfh.indent(os);
128  os << "labels must match this wildcard pattern: *\n";
129 
130  dfh.indent2(os);
131  os << "type: ";
132  if(isTracked()) {
134  } else {
135  os << "untracked " << parameterTypeEnumToString(type());
136  }
137 
138  if(optional) os << " optional";
139  os << "\n";
140 
141  dfh.indent2(os);
142  os << "criteria: ";
143  if(criteria() == RequireZeroOrMore) os << "require zero or more";
144  else if(criteria() == RequireAtLeastOne) os << "require at least one";
145  else if(criteria() == RequireExactlyOne) os << "require exactly one";
146  os << "\n";
147 
148  if(hasNestedContent()) {
149  dfh.indent2(os);
150  os << "(see Section " << dfh.section()
151  << "." << dfh.counter() << ")\n";
152  }
153 
154  if(!comment().empty()) {
156  comment(),
157  dfh.startColumn2(),
158  dfh.commentWidth());
159  }
160  os << "\n";
161  }
162  }
163  }
164 
165  void
167  writeCfi_(std::ostream&,
168  bool& /*startWithComma*/,
169  int /*indentation*/,
170  bool& /*wroteSomething*/) const {
171  // Until we implement default labels and values there is nothing
172  // to do here.
173  }
174 
175  bool
178  return exists(pset);
179  }
180 
181  int
184  return exists(pset) ? 1 : 0;
185  }
186 }
size
Write out results.
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
void indent2(std::ostream &os) const
size_t column2() const
bool exists(ParameterSet const &pset) const
WildcardValidationCriteria criteria() const
size_t column3() const
virtual void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh) const
void throwIfInvalidPattern(char const *pattern) const
HLT enums.
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
size_t commentWidth() const
virtual int howManyXORSubNodesExist_(ParameterSet const &pset) const
ParameterWildcardBase(ParameterTypes iType, bool isTracked, WildcardValidationCriteria criteria)
std::string const & section() const