CMS 3D CMS Logo

ParameterSwitchBase.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  throw Exception(errors::LogicError) << "When adding a ParameterSwitch to a ParameterSetDescription the values\n"
17  << "associated with the different cases must be unique. Duplicate\n"
18  << "values were found for the switch with label: \"" << switchLabel << "\"\n";
19  }
20 
22  std::set<std::string>& usedLabels,
23  std::set<std::string>& labels) const {
24  std::pair<std::set<std::string>::iterator, bool> status = labels.insert(switchLabel);
25  if (status.second == false) {
27  << "The label used for the switch parameter in a ParameterSetDescription\n"
28  << "must be different from the labels used in the associated cases. The following\n"
29  << "duplicate label was found: \"" << switchLabel << "\"\n";
30  }
31  usedLabels.insert(labels.begin(), labels.end());
32  }
33 
35  std::set<ParameterTypes> const& caseParameterTypes,
36  std::set<ParameterTypes> const& caseWildcardTypes,
37  std::set<ParameterTypes>& parameterTypes,
38  std::set<ParameterTypes>& wildcardTypes) const {
39  if (caseWildcardTypes.find(switchType) != caseWildcardTypes.end()) {
41  << "The type used for the switch parameter in a ParameterSetDescription\n"
42  << "must be different from the types used for wildcards in the associated cases. The following\n"
43  << "duplicate type was found: \"" << parameterTypeEnumToString(switchType) << "\"\n";
44  }
45  parameterTypes.insert(switchType);
46  parameterTypes.insert(caseParameterTypes.begin(), caseParameterTypes.end());
47  wildcardTypes.insert(caseWildcardTypes.begin(), caseWildcardTypes.end());
48  }
49 
52  << "The default value used for the switch parameter in a ParameterSetDescription\n"
53  << "must match the value used to select one of the associated cases. This is not\n"
54  << "true for the switch named \"" << switchLabel << "\"\n";
55  }
56 
58  throw Exception(errors::Configuration) << message;
59  }
60 
61  void ParameterSwitchBase::printBase(std::ostream& os,
62  bool optional,
63  bool writeToCfi,
64  DocFormatHelper& dfh,
65  std::string const& switchLabel,
66  bool isTracked,
67  std::string const& typeString) const {
68  if (dfh.pass() == 0) {
69  dfh.setAtLeast1(switchLabel.size() + 9U);
70  if (isTracked) {
71  dfh.setAtLeast2(typeString.size());
72  } else {
73  dfh.setAtLeast2(typeString.size() + 10U);
74  }
75  dfh.setAtLeast3(8U);
76  }
77  if (dfh.pass() == 1) {
78  dfh.indent(os);
79 
80  if (dfh.brief()) {
81  std::stringstream ss;
82  ss << switchLabel << " (switch)";
83  std::ios::fmtflags oldFlags = os.flags();
84  os << std::left << std::setw(dfh.column1()) << ss.str();
85  os << " ";
86 
87  os << std::setw(dfh.column2());
88  if (isTracked) {
89  os << typeString;
90  } else {
91  std::stringstream ss1;
92  ss1 << "untracked " << typeString;
93  os << ss1.str();
94  }
95 
96  os << " " << std::setw(dfh.column3());
97  if (optional)
98  os << "optional";
99  else
100  os << "";
101 
102  if (!writeToCfi)
103  os << " (do not write to cfi)";
104 
105  os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
106  os.flags(oldFlags);
107  } else {
108  // not brief
109 
110  os << switchLabel << " (switch)\n";
111 
112  dfh.indent2(os);
113  os << "type: ";
114  if (!isTracked)
115  os << "untracked ";
116  os << typeString << " ";
117 
118  if (optional)
119  os << "optional";
120 
121  if (!writeToCfi)
122  os << " (do not write to cfi)";
123  os << "\n";
124 
125  dfh.indent2(os);
126  os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
127 
128  if (!comment().empty()) {
130  }
131  os << "\n";
132  }
133  }
134  }
135 
136  bool ParameterSwitchBase::hasNestedContent_() const { return true; }
137 
139  DocFormatHelper& dfh,
140  DocFormatHelper& new_dfh,
141  std::string const& switchLabel) const {
142  int indentation = dfh.indentation();
143  if (dfh.parent() != DocFormatHelper::TOP) {
145  }
146 
147  std::stringstream ss;
148  ss << dfh.section() << "." << dfh.counter();
149  std::string newSection = ss.str();
150 
152  os << "Section " << newSection << " " << switchLabel << " (switch):\n";
153 
154  if (!dfh.brief()) {
156  os << "The value of \"" << switchLabel << "\" controls which other parameters\n";
158  os << "are required or allowed to be in the PSet.\n";
159  }
160  if (!dfh.brief())
161  os << "\n";
162 
163  new_dfh.init();
164  new_dfh.setSection(newSection);
167  }
168 
170  std::ostream& os,
171  bool /*optional*/,
172  DocFormatHelper& dfh,
173  std::string const& switchLabel) {
174  if (dfh.pass() == 0) {
175  p.second->print(os, false, true, dfh);
176  }
177  if (dfh.pass() == 1) {
178  dfh.indent(os);
179  os << "if " << switchLabel << " = ";
180  if (p.first)
181  os << "True";
182  else
183  os << "False";
184  os << "\n";
185  p.second->print(os, false, true, dfh);
186  }
187  if (dfh.pass() == 2) {
188  p.second->printNestedContent(os, false, dfh);
189  }
190  }
191 
193  std::ostream& os,
194  bool /*optional*/,
195  DocFormatHelper& dfh,
196  std::string const& switchLabel) {
197  if (dfh.pass() == 0) {
198  p.second->print(os, false, true, dfh);
199  }
200  if (dfh.pass() == 1) {
201  dfh.indent(os);
202  os << "if " << switchLabel << " = " << p.first << "\n";
203  p.second->print(os, false, true, dfh);
204  }
205  if (dfh.pass() == 2) {
206  p.second->printNestedContent(os, false, dfh);
207  }
208  }
209 
211  std::ostream& os,
212  bool /*optional*/,
213  DocFormatHelper& dfh,
214  std::string const& switchLabel) {
215  if (dfh.pass() == 0) {
216  p.second->print(os, false, true, dfh);
217  }
218  if (dfh.pass() == 1) {
219  dfh.indent(os);
220  os << "if " << switchLabel << " = \"" << p.first << "\"\n";
221  p.second->print(os, false, true, dfh);
222  }
223  if (dfh.pass() == 2) {
224  p.second->printNestedContent(os, false, dfh);
225  }
226  }
227 
229 
231 } // namespace edm
void insertAndCheckTypes(ParameterTypes switchType, std::set< ParameterTypes > const &caseParameterTypes, std::set< ParameterTypes > const &caseWildcardTypes, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const
int startColumn2() const
static void wrapAndPrintText(std::ostream &os, std::string const &text, size_t indent, size_t suggestedWidth)
std::string parameterTypeEnumToString(ParameterTypes iType)
size_t commentWidth() const
void throwDuplicateCaseValues(std::string const &switchLabel) const
static void printCase(std::pair< bool, edm::value_ptr< ParameterDescriptionNode > > const &p, std::ostream &os, bool optional, DocFormatHelper &dfh, std::string const &switchLabel)
void indent2(std::ostream &os) const
void printBase(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh, std::string const &switchLabel, bool isTracked, std::string const &typeString) const
size_t column1() const
void setAtLeast2(size_t width)
static int offsetSectionContent()
optional
Definition: Types.py:245
size_t column3() const
size_t column2() const
std::string const & section() const
static void printSpaces(std::ostream &os, int n)
bool partiallyExists_(ParameterSet const &pset) const override
void throwNoCaseForDefault(std::string const &switchLabel) const
std::string const & comment() const
void insertAndCheckLabels(std::string const &switchLabel, std::set< std::string > &usedLabels, std::set< std::string > &labels) const
bool exists(ParameterSet const &pset) const
HLT enums.
void setAtLeast1(size_t width)
void setAtLeast3(size_t width)
int howManyXORSubNodesExist_(ParameterSet const &pset) const override
void printNestedContentBase(std::ostream &os, DocFormatHelper &dfh, DocFormatHelper &new_dfh, std::string const &switchLabel) const
void setSection(std::string const &value)
void throwNoCaseForSwitchValue(std::string const &message) const
void indent(std::ostream &os) const
bool hasNestedContent_() const override
void setParent(DescriptionParent value)
DescriptionParent parent() const
void setIndentation(int value)