CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ParameterSwitchBase.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 
14  void
16  throwDuplicateCaseValues(std::string const& switchLabel) const {
18  << "When adding a ParameterSwitch to a ParameterSetDescription the values\n"
19  << "associated with the different cases must be unique. Duplicate\n"
20  << "values were found for the switch with label: \"" << switchLabel
21  << "\"\n";
22  }
23 
24  void
26  insertAndCheckLabels(std::string const& switchLabel,
27  std::set<std::string> & usedLabels,
28  std::set<std::string> & labels) const {
29 
30  std::pair<std::set<std::string>::iterator,bool> status = labels.insert(switchLabel);
31  if (status.second == false) {
33  << "The label used for the switch parameter in a ParameterSetDescription\n"
34  << "must be different from the labels used in the associated cases. The following\n"
35  << "duplicate label was found: \"" << switchLabel << "\"\n";
36  }
37  usedLabels.insert(labels.begin(), labels.end());
38  }
39 
40 
41  void
44  std::set<ParameterTypes> const& caseParameterTypes,
45  std::set<ParameterTypes> const& caseWildcardTypes,
46  std::set<ParameterTypes> & parameterTypes,
47  std::set<ParameterTypes> & wildcardTypes) const {
48 
49  if (caseWildcardTypes.find(switchType) != caseWildcardTypes.end()) {
51  << "The type used for the switch parameter in a ParameterSetDescription\n"
52  << "must be different from the types used for wildcards in the associated cases. The following\n"
53  << "duplicate type was found: \"" << parameterTypeEnumToString(switchType) << "\"\n";
54  }
55  parameterTypes.insert(switchType);
56  parameterTypes.insert(caseParameterTypes.begin(), caseParameterTypes.end());
57  wildcardTypes.insert(caseWildcardTypes.begin(), caseWildcardTypes.end());
58  }
59 
60  void
62  throwNoCaseForDefault(std::string const& switchLabel) const {
64  << "The default value used for the switch parameter in a ParameterSetDescription\n"
65  << "must match the value used to select one of the associated cases. This is not\n"
66  << "true for the switch named \"" << switchLabel << "\"\n";
67  }
68 
69  void
71  throwNoCaseForSwitchValue(std::string const& message) const {
73  << message;
74  }
75 
76  void
78  printBase(std::ostream & os,
79  bool optional,
80  bool writeToCfi,
81  DocFormatHelper & dfh,
82  std::string const& switchLabel,
83  bool isTracked,
84  std::string const& typeString) const {
85 
86  if (dfh.pass() == 0) {
87  dfh.setAtLeast1(switchLabel.size() + 9U);
88  if (isTracked) {
89  dfh.setAtLeast2(typeString.size());
90  }
91  else {
92  dfh.setAtLeast2(typeString.size() + 10U);
93  }
94  dfh.setAtLeast3(8U);
95  }
96  if (dfh.pass() == 1) {
97 
98  dfh.indent(os);
99 
100  if (dfh.brief()) {
101 
102  std::stringstream ss;
103  ss << switchLabel << " (switch)";
104  std::ios::fmtflags oldFlags = os.flags();
105  os << std::left << std::setw(dfh.column1()) << ss.str();
106  os << " ";
107 
108  os << std::setw(dfh.column2());
109  if (isTracked) {
110  os << typeString;
111  }
112  else {
113  std::stringstream ss1;
114  ss1 << "untracked " << typeString;
115  os << ss1.str();
116  }
117 
118  os << " " << std::setw(dfh.column3());
119  if (optional) os << "optional";
120  else os << "";
121 
122  if (!writeToCfi) os << " (do not write to cfi)";
123 
124  os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
125  os.flags(oldFlags);
126  }
127  // not brief
128  else {
129 
130  os << switchLabel << " (switch)\n";
131 
132  dfh.indent2(os);
133  os << "type: ";
134  if (!isTracked) os << "untracked ";
135  os << typeString << " ";
136 
137  if (optional) os << "optional";
138 
139  if (!writeToCfi) os << " (do not write to cfi)";
140  os << "\n";
141 
142  dfh.indent2(os);
143  os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
144 
145  if (!comment().empty()) {
147  comment(),
148  dfh.startColumn2(),
149  dfh.commentWidth());
150  }
151  os << "\n";
152  }
153  }
154  }
155 
156  bool
159  return true;
160  }
161 
162  void
164  printNestedContentBase(std::ostream & os,
165  DocFormatHelper & dfh,
166  DocFormatHelper & new_dfh,
167  std::string const& switchLabel) {
168 
169  int indentation = dfh.indentation();
170  if (dfh.parent() != DocFormatHelper::TOP) {
171  indentation -= DocFormatHelper::offsetSectionContent();
172  }
173 
174  std::stringstream ss;
175  ss << dfh.section() << "." << dfh.counter();
176  std::string newSection = ss.str();
177 
178  printSpaces(os, indentation);
179  os << "Section " << newSection
180  << " " << switchLabel << " (switch):\n";
181 
182  if (!dfh.brief()) {
183  printSpaces(os, indentation);
184  os << "The value of \"" << switchLabel << "\" controls which other parameters\n";
185  printSpaces(os, indentation);
186  os << "are required or allowed to be in the PSet.\n";
187  }
188  if (!dfh.brief()) os << "\n";
189 
190  new_dfh.init();
191  new_dfh.setSection(newSection);
192  new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
194  }
195 
196 
197  void
200  std::ostream & os,
201  bool optional,
202  DocFormatHelper & dfh,
203  std::string const& switchLabel) {
204  if (dfh.pass() == 0) {
205  p.second->print(os, false, true, dfh);
206  }
207  if (dfh.pass() == 1) {
208  dfh.indent(os);
209  os << "if " << switchLabel << " = ";
210  if (p.first) os << "True";
211  else os << "False";
212  os << "\n";
213  p.second->print(os, false, true, dfh);
214  }
215  if (dfh.pass() == 2) {
216  p.second->printNestedContent(os, false, dfh);
217  }
218  }
219 
220  void
223  std::ostream & os,
224  bool optional,
225  DocFormatHelper & dfh,
226  std::string const& switchLabel) {
227  if (dfh.pass() == 0) {
228  p.second->print(os, false, true, dfh);
229  }
230  if (dfh.pass() == 1) {
231  dfh.indent(os);
232  os << "if " << switchLabel << " = " << p.first << "\n";
233  p.second->print(os, false, true, dfh);
234  }
235  if (dfh.pass() == 2) {
236  p.second->printNestedContent(os, false, dfh);
237  }
238  }
239 
240  void
242  printCase(std::pair<std::string, edm::value_ptr<ParameterDescriptionNode> > const& p,
243  std::ostream & os,
244  bool optional,
245  DocFormatHelper & dfh,
246  std::string const& switchLabel) {
247  if (dfh.pass() == 0) {
248  p.second->print(os, false, true, dfh);
249  }
250  if (dfh.pass() == 1) {
251  dfh.indent(os);
252  os << "if " << switchLabel << " = \"" << p.first << "\"\n";
253  p.second->print(os, false, true, dfh);
254  }
255  if (dfh.pass() == 2) {
256  p.second->printNestedContent(os, false, dfh);
257  }
258  }
259 
260  bool
263  return exists(pset);
264  }
265 
266  int
269  return exists(pset) ? 1 : 0;
270  }
271 }
void insertAndCheckTypes(ParameterTypes switchType, std::set< ParameterTypes > const &caseParameterTypes, std::set< ParameterTypes > const &caseWildcardTypes, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const
static void wrapAndPrintText(std::ostream &os, std::string const &text, size_t indent, size_t suggestedWidth)
int startColumn2() const
void insertAndCheckLabels(std::string const &switchLabel, std::set< std::string > &usedLabels, std::set< std::string > &labels) const
std::string parameterTypeEnumToString(ParameterTypes iType)
DescriptionParent parent() const
static void printCase(std::pair< bool, edm::value_ptr< ParameterDescriptionNode > > const &p, std::ostream &os, bool optional, DocFormatHelper &dfh, std::string const &switchLabel)
int indentation() const
void throwDuplicateCaseValues(std::string const &switchLabel) const
std::string const & comment() const
void throwNoCaseForDefault(std::string const &switchLabel) const
void setAtLeast2(size_t width)
static int offsetSectionContent()
tuple pset
Definition: CrabTask.py:85
void indent2(std::ostream &os) const
static void printSpaces(std::ostream &os, int n)
size_t column2() const
bool exists(ParameterSet const &pset) const
tuple labels
Definition: L1TDQM_cfg.py:62
void printBase(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh, std::string const &switchLabel, bool isTracked, std::string const &typeString) const
void throwNoCaseForSwitchValue(std::string const &message) const
size_t column3() const
virtual int howManyXORSubNodesExist_(ParameterSet const &pset) const
string message
Definition: argparse.py:126
void printNestedContentBase(std::ostream &os, DocFormatHelper &dfh, DocFormatHelper &new_dfh, std::string const &switchLabel)
void setAtLeast1(size_t width)
size_t column1() const
void setAtLeast3(size_t width)
tuple status
Definition: ntuplemaker.py:245
void indent(std::ostream &os) const
void setSection(std::string const &value)
size_t commentWidth() const
void setParent(DescriptionParent value)
virtual bool partiallyExists_(ParameterSet const &pset) const
void setIndentation(int value)
std::string const & section() const