CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ParameterDescriptionBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ParameterSet
4 // Class : ParameterDescriptionBase
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Thu Aug 2 15:35:43 EDT 2007
11 //
12 
17 
18 #include <iostream>
19 #include <iomanip>
20 
21 namespace edm {
22 
24  ParameterTypes iType,
25  bool isTracked,
26  bool hasDefault)
27  :label_(iLabel),
28  type_(iType),
29  isTracked_(isTracked),
30  hasDefault_(hasDefault)
31  {
32  if(label_.empty()) {
34  << "Empty string used as a label for a parameter. This is\n"
35  "not allowed.\n";
36  }
37  }
38 
40  ParameterTypes iType,
41  bool isTracked,
42  bool hasDefault)
43  :label_(iLabel),
44  type_(iType),
45  isTracked_(isTracked),
46  hasDefault_(hasDefault)
47  {
48  if (label_.empty()) {
50  << "Empty string used as a label for a parameter. This is\n"
51  "not allowed.\n";
52  }
53  }
54 
56 
57  void
59  std::string tr("a tracked");
60  std::string shouldBe("untracked");
61  if (isTracked()) {
62  tr = "an untracked";
63  shouldBe = "tracked";
64  }
65 
67  << "In the configuration, parameter \"" << label() << "\" is defined "
68  "as " << tr << " " << parameterTypeEnumToString(type()) << ".\n"
69  << "It should be " << shouldBe << ".\n";
70  }
71 
72  void
74  std::string tr("an untracked");
75  if (isTracked()) tr = "a tracked";
76 
78  << "Parameter \"" << label() << "\" should be defined "
79  "as " << tr << " " << parameterTypeEnumToString(type()) << ".\n"
80  << "The type in the configuration is incorrect.\n";
81  }
82 
83  void
85 
86  std::string tr("untracked");
87  if (isTracked()) tr = "tracked";
88 
90  << "Missing required parameter. It should have label \""
91  << label() << "\" and have type \""
92  << tr << " " << parameterTypeEnumToString(type()) << "\".\n"
93  << "The description has no default. The parameter must be defined "
94  "in the configuration\n";
95  }
96 
97  void
99  checkAndGetLabelsAndTypes_(std::set<std::string> & usedLabels,
100  std::set<ParameterTypes> & parameterTypes,
101  std::set<ParameterTypes> & wildcardTypes) const {
102  usedLabels.insert(label());
103  parameterTypes.insert(type());
104  }
105 
106  void
109  std::set<std::string> & validatedLabels,
110  bool optional) const {
111 
112  bool exists = exists_(pset, isTracked());
113 
114  if (exists) {
115  validatedLabels.insert(label());
116  }
117  else if (exists_(pset, !isTracked())) {
119  }
120  else if (pset.exists(label())) {
122  }
123 
124  if (!exists && !optional) {
125  if (hasDefault()) {
126  insertDefault_(pset);
127  validatedLabels.insert(label());
128  }
129  else {
131  }
132  }
133  }
134 
135  void
137  writeCfi_(std::ostream & os,
138  bool & startWithComma,
139  int indentation,
140  bool & wroteSomething) const {
141 
142  if (!hasDefault()) return;
143 
144  wroteSomething = true;
145  if (startWithComma) os << ",";
146  startWithComma = true;
147 
148  os << "\n";
149  printSpaces(os, indentation);
150 
151  os << label()
152  << " = cms.";
153  if (!isTracked()) os << "untracked.";
155  << "(";
156  writeCfi_(os, indentation);
157  os << ")";
158  }
159 
160  void
162  print_(std::ostream & os,
163  bool optional,
164  bool writeToCfi,
165  DocFormatHelper & dfh)
166  {
167  if (dfh.pass() == 0) {
168  dfh.setAtLeast1(label().size());
169  if (isTracked()) {
171  }
172  else {
174  }
175  if (optional) {
176  dfh.setAtLeast3(8U);
177  }
178  }
179  else {
180 
181  if (dfh.brief()) {
182  std::ios::fmtflags oldFlags = os.flags();
183 
184  dfh.indent(os);
185  os << std::left << std::setw(dfh.column1()) << label() << " ";
186 
187  if (isTracked()) {
188  os << std::setw(dfh.column2()) << parameterTypeEnumToString(type());
189  }
190  else {
191  std::stringstream ss;
192  ss << "untracked ";
194  os << std::setw(dfh.column2()) << ss.str();
195  }
196  os << " ";
197 
198  os << std::setw(dfh.column3());
199  if (optional) {
200  os << "optional";
201  }
202  else {
203  os << "";
204  }
205  os << " ";
206  os.flags(oldFlags);
207  printDefault_(os, writeToCfi, dfh);
208  }
209  // not brief
210  else {
211 
212  dfh.indent(os);
213  os << label() << "\n";
214 
215  dfh.indent2(os);
216  os << "type: ";
217  if (!isTracked()) os << "untracked ";
218 
219  os << parameterTypeEnumToString(type()) << " ";
220 
221  if (optional) os << "optional";
222  os << "\n";
223 
224  dfh.indent2(os);
225  printDefault_(os, writeToCfi, dfh);
226 
227  if (!comment().empty()) {
229  comment(),
230  dfh.startColumn2(),
231  dfh.commentWidth());
232  }
233  os << "\n";
234  }
235  }
236  }
237 
238  void
240  printDefault_(std::ostream & os,
241  bool writeToCfi,
242  DocFormatHelper & dfh) {
243  if (!dfh.brief()) os << "default: ";
244  if (writeToCfi && hasDefault()) {
245  if (hasNestedContent()) {
246  os << "see Section " << dfh.section()
247  << "." << dfh.counter();
248  }
249  else {
250  if (dfh.brief()) {
251  writeDoc_(os, dfh.indentation());
252  }
253  else {
254  writeDoc_(os, dfh.startColumn2());
255  }
256  }
257  }
258  else {
259  os << "none (do not write to cfi)";
260  }
261  os << "\n";
262  }
263 
264  void
266  printNestedContent_(std::ostream & os,
267  bool optional,
268  DocFormatHelper & dfh) {
269  int indentation = dfh.indentation();
270  if (dfh.parent() != DocFormatHelper::TOP) {
271  indentation -= DocFormatHelper::offsetSectionContent();
272  }
273 
274  printSpaces(os, indentation);
275  os << "Section " << dfh.section() << "." << dfh.counter()
276  << " " << label() << " default contents: ";
277  writeDoc_(os, indentation + 2);
278  os << "\n";
279  if (!dfh.brief()) os << "\n";
280  }
281 
282  bool
285  return exists(pset);
286  }
287 
288  int
291  return exists(pset) ? 1 : 0;
292  }
293 }
static void wrapAndPrintText(std::ostream &os, std::string const &text, size_t indent, size_t suggestedWidth)
bool exists(std::string const &parameterName) const
checks if a parameter exists
int startColumn2() const
std::string parameterTypeEnumToString(ParameterTypes iType)
DescriptionParent parent() const
virtual void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const
int indentation() const
virtual void printDefault_(std::ostream &os, bool writeToCfi, DocFormatHelper &dfh)
ParameterDescriptionBase(std::string const &iLabel, ParameterTypes iType, bool isTracked, bool hasDefault)
std::string const & comment() const
virtual int howManyXORSubNodesExist_(ParameterSet const &pset) const
void setAtLeast2(size_t width)
virtual void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const
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
virtual bool partiallyExists_(ParameterSet const &pset) const
size_t column3() const
virtual bool exists_(ParameterSet const &pset, bool isTracked) const =0
virtual void writeCfi_(std::ostream &os, bool &startWithComma, int indentation, bool &wroteSomething) const
virtual void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh)
virtual void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh)
virtual void insertDefault_(ParameterSet &pset) const =0
virtual void writeDoc_(std::ostream &os, int indentation) const =0
void setAtLeast1(size_t width)
size_t column1() const
void setAtLeast3(size_t width)
void indent(std::ostream &os) const
tuple size
Write out results.
size_t commentWidth() const
std::string const & label() const
std::string const & section() const