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 
3 
6 
7 #include <iomanip>
8 #include <ostream>
9 #include <sstream>
10 
11 namespace edm {
12 
14 
15  void
17  throwDuplicateCaseValues(std::string const& switchLabel) const {
19  << "When adding a ParameterSwitch to a ParameterSetDescription the values\n"
20  << "associated with the different cases must be unique. Duplicate\n"
21  << "values were found for the switch with label: \"" << switchLabel
22  << "\"\n";
23  }
24 
25  void
28  std::set<std::string>& usedLabels,
29  std::set<std::string>& labels) const {
30 
31  std::pair<std::set<std::string>::iterator,bool> status = labels.insert(switchLabel);
32  if(status.second == false) {
34  << "The label used for the switch parameter in a ParameterSetDescription\n"
35  << "must be different from the labels used in the associated cases. The following\n"
36  << "duplicate label was found: \"" << switchLabel << "\"\n";
37  }
38  usedLabels.insert(labels.begin(), labels.end());
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
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  } else {
91  dfh.setAtLeast2(typeString.size() + 10U);
92  }
93  dfh.setAtLeast3(8U);
94  }
95  if(dfh.pass() == 1) {
96 
97  dfh.indent(os);
98 
99  if(dfh.brief()) {
100 
101  std::stringstream ss;
102  ss << switchLabel << " (switch)";
103  std::ios::fmtflags oldFlags = os.flags();
104  os << std::left << std::setw(dfh.column1()) << ss.str();
105  os << " ";
106 
107  os << std::setw(dfh.column2());
108  if(isTracked) {
109  os << typeString;
110  } else {
111  std::stringstream ss1;
112  ss1 << "untracked " << typeString;
113  os << ss1.str();
114  }
115 
116  os << " " << std::setw(dfh.column3());
117  if(optional) os << "optional";
118  else os << "";
119 
120  if(!writeToCfi) os << " (do not write to cfi)";
121 
122  os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
123  os.flags(oldFlags);
124  } else {
125  // not brief
126 
127  os << switchLabel << " (switch)\n";
128 
129  dfh.indent2(os);
130  os << "type: ";
131  if(!isTracked) os << "untracked ";
132  os << typeString << " ";
133 
134  if(optional) os << "optional";
135 
136  if(!writeToCfi) os << " (do not write to cfi)";
137  os << "\n";
138 
139  dfh.indent2(os);
140  os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
141 
142  if(!comment().empty()) {
144  comment(),
145  dfh.startColumn2(),
146  dfh.commentWidth());
147  }
148  os << "\n";
149  }
150  }
151  }
152 
153  bool
156  return true;
157  }
158 
159  void
161  printNestedContentBase(std::ostream& os,
162  DocFormatHelper& dfh,
163  DocFormatHelper& new_dfh,
164  std::string const& switchLabel) {
165 
166  int indentation = dfh.indentation();
167  if(dfh.parent() != DocFormatHelper::TOP) {
168  indentation -= DocFormatHelper::offsetSectionContent();
169  }
170 
171  std::stringstream ss;
172  ss << dfh.section() << "." << dfh.counter();
173  std::string newSection = ss.str();
174 
175  printSpaces(os, indentation);
176  os << "Section " << newSection
177  << " " << switchLabel << " (switch):\n";
178 
179  if(!dfh.brief()) {
180  printSpaces(os, indentation);
181  os << "The value of \"" << switchLabel << "\" controls which other parameters\n";
182  printSpaces(os, indentation);
183  os << "are required or allowed to be in the PSet.\n";
184  }
185  if(!dfh.brief()) os << "\n";
186 
187  new_dfh.init();
188  new_dfh.setSection(newSection);
189  new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
191  }
192 
193 
194  void
197  std::ostream& os,
198  bool /*optional*/,
199  DocFormatHelper& dfh,
200  std::string const& switchLabel) {
201  if(dfh.pass() == 0) {
202  p.second->print(os, false, true, dfh);
203  }
204  if(dfh.pass() == 1) {
205  dfh.indent(os);
206  os << "if " << switchLabel << " = ";
207  if(p.first) os << "True";
208  else os << "False";
209  os << "\n";
210  p.second->print(os, false, true, dfh);
211  }
212  if(dfh.pass() == 2) {
213  p.second->printNestedContent(os, false, dfh);
214  }
215  }
216 
217  void
220  std::ostream& os,
221  bool /*optional*/,
222  DocFormatHelper& dfh,
223  std::string const& switchLabel) {
224  if(dfh.pass() == 0) {
225  p.second->print(os, false, true, dfh);
226  }
227  if(dfh.pass() == 1) {
228  dfh.indent(os);
229  os << "if " << switchLabel << " = " << p.first << "\n";
230  p.second->print(os, false, true, dfh);
231  }
232  if(dfh.pass() == 2) {
233  p.second->printNestedContent(os, false, dfh);
234  }
235  }
236 
237  void
240  std::ostream& os,
241  bool /*optional*/,
242  DocFormatHelper& dfh,
243  std::string const& switchLabel) {
244  if(dfh.pass() == 0) {
245  p.second->print(os, false, true, dfh);
246  }
247  if(dfh.pass() == 1) {
248  dfh.indent(os);
249  os << "if " << switchLabel << " = \"" << p.first << "\"\n";
250  p.second->print(os, false, true, dfh);
251  }
252  if(dfh.pass() == 2) {
253  p.second->printNestedContent(os, false, dfh);
254  }
255  }
256 
257  bool
259  partiallyExists_(ParameterSet const& pset) const {
260  return exists(pset);
261  }
262 
263  int
266  return exists(pset) ? 1 : 0;
267  }
268 }
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()
void indent2(std::ostream &os) const
static void printSpaces(std::ostream &os, int n)
size_t column2() const
bool exists(ParameterSet const &pset) const
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
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