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