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 {
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& /*startWithComma*/,
151  int /*indentation*/,
152  bool& /*wroteSomething*/) const {
153  // Until we implement default labels and values there is nothing
154  // to do here.
155  }
156 
158 
159  int ParameterWildcardBase::howManyXORSubNodesExist_(ParameterSet const& pset) const { return exists(pset) ? 1 : 0; }
160 } // namespace edm
size
Write out results.
WildcardValidationCriteria
void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const override
bool partiallyExists_(ParameterSet const &pset) const override
static void wrapAndPrintText(std::ostream &os, std::string const &text, size_t indent, size_t suggestedWidth)
ParameterTypes type() const
int startColumn2() const
std::string parameterTypeEnumToString(ParameterTypes iType)
int howManyXORSubNodesExist_(ParameterSet const &pset) const override
WildcardValidationCriteria criteria_
std::string const & comment() const
void setAtLeast2(size_t width)
void indent2(std::ostream &os) const
size_t column2() const
bool exists(ParameterSet const &pset) const
WildcardValidationCriteria criteria() const
void writeCfi_(std::ostream &os, bool &startWithComma, int indentation, bool &wroteSomething) const override
size_t column3() const
void throwIfInvalidPattern(char const *pattern) const
HLT enums.
void setAtLeast1(size_t width)
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
void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh) const override
size_t commentWidth() const
ParameterWildcardBase(ParameterTypes iType, bool isTracked, WildcardValidationCriteria criteria)
std::string const & section() const