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 
14 
18 
19 #include <iomanip>
20 #include <iostream>
21 
22 namespace edm {
23 
25  ParameterTypes iType,
26  bool isTracked,
27  bool hasDefault)
28  :label_(iLabel),
29  type_(iType),
30  isTracked_(isTracked),
31  hasDefault_(hasDefault) {
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  if(label_.empty()) {
49  << "Empty string used as a label for a parameter. This is\n"
50  "not allowed.\n";
51  }
52  }
53 
55 
56  void
58  std::string tr("a tracked");
59  std::string shouldBe("untracked");
60  if(isTracked()) {
61  tr = "an untracked";
62  shouldBe = "tracked";
63  }
64 
66  << "In the configuration, parameter \"" << label() << "\" is defined "
67  "as " << tr << " " << parameterTypeEnumToString(type()) << ".\n"
68  << "It should be " << shouldBe << ".\n";
69  }
70 
71  void
73  std::string tr("an untracked");
74  if(isTracked()) tr = "a tracked";
75 
77  << "Parameter \"" << label() << "\" should be defined "
78  "as " << tr << " " << parameterTypeEnumToString(type()) << ".\n"
79  << "The type in the configuration is incorrect.\n";
80  }
81 
82  void
84 
85  std::string tr("untracked");
86  if(isTracked()) tr = "tracked";
87 
89  << "Missing required parameter. It should have label \""
90  << label() << "\" and have type \""
91  << tr << " " << parameterTypeEnumToString(type()) << "\".\n"
92  << "The description has no default. The parameter must be defined "
93  "in the configuration\n";
94  }
95 
96  void
98  checkAndGetLabelsAndTypes_(std::set<std::string>& usedLabels,
99  std::set<ParameterTypes>& parameterTypes,
100  std::set<ParameterTypes>& /*wildcardTypes*/) const {
101  usedLabels.insert(label());
102  parameterTypes.insert(type());
103  }
104 
105  void
108  std::set<std::string>& validatedLabels,
109  bool optional) const {
110 
111  bool exists = exists_(pset, isTracked());
112 
113  if(exists) {
114  validatedLabels.insert(label());
115  } else if(exists_(pset, !isTracked())) {
117  } else if(pset.exists(label())) {
119  }
120 
121  if(!exists && !optional) {
122  if(hasDefault()) {
123  insertDefault_(pset);
124  validatedLabels.insert(label());
125  } else {
127  }
128  }
129  }
130 
131  void
133  writeCfi_(std::ostream& os,
134  bool& startWithComma,
135  int indentation,
136  bool& wroteSomething) const {
137 
138  if(!hasDefault()) return;
139 
140  wroteSomething = true;
141  if(startWithComma) os << ",";
142  startWithComma = true;
143 
144  os << "\n";
145  printSpaces(os, indentation);
146 
147  os << label()
148  << " = cms.";
149  if(!isTracked()) os << "untracked.";
151  << "(";
152  writeCfi_(os, indentation);
153  os << ")";
154  }
155 
156  void
158  print_(std::ostream& os,
159  bool optional,
160  bool writeToCfi,
161  DocFormatHelper& dfh) {
162  if(dfh.pass() == 0) {
163  dfh.setAtLeast1(label().size());
164  if(isTracked()) {
166  } else {
168  }
169  if(optional) {
170  dfh.setAtLeast3(8U);
171  }
172  } else {
173 
174  if(dfh.brief()) {
175  std::ios::fmtflags oldFlags = os.flags();
176 
177  dfh.indent(os);
178  os << std::left << std::setw(dfh.column1()) << label() << " ";
179 
180  if(isTracked()) {
181  os << std::setw(dfh.column2()) << parameterTypeEnumToString(type());
182  } else {
183  std::stringstream ss;
184  ss << "untracked ";
186  os << std::setw(dfh.column2()) << ss.str();
187  }
188  os << " ";
189 
190  os << std::setw(dfh.column3());
191  if(optional) {
192  os << "optional";
193  } else {
194  os << "";
195  }
196  os << " ";
197  os.flags(oldFlags);
198  printDefault_(os, writeToCfi, dfh);
199  } else {
200  // not brief
201  dfh.indent(os);
202  os << label() << "\n";
203 
204  dfh.indent2(os);
205  os << "type: ";
206  if(!isTracked()) os << "untracked ";
207 
208  os << parameterTypeEnumToString(type()) << " ";
209 
210  if(optional) os << "optional";
211  os << "\n";
212 
213  dfh.indent2(os);
214  printDefault_(os, writeToCfi, dfh);
215 
216  if(!comment().empty()) {
218  comment(),
219  dfh.startColumn2(),
220  dfh.commentWidth());
221  }
222  os << "\n";
223  }
224  }
225  }
226 
227  void
229  printDefault_(std::ostream& os,
230  bool writeToCfi,
231  DocFormatHelper& dfh) {
232  if(!dfh.brief()) os << "default: ";
233  if(writeToCfi && hasDefault()) {
234  if(hasNestedContent()) {
235  os << "see Section " << dfh.section()
236  << "." << dfh.counter();
237  } else {
238  if(dfh.brief()) {
239  writeDoc_(os, dfh.indentation());
240  } else {
241  writeDoc_(os, dfh.startColumn2());
242  }
243  }
244  } else {
245  os << "none (do not write to cfi)";
246  }
247  os << "\n";
248  }
249 
250  void
252  printNestedContent_(std::ostream& os,
253  bool /*optional*/,
254  DocFormatHelper& dfh) {
255  int indentation = dfh.indentation();
256  if(dfh.parent() != DocFormatHelper::TOP) {
257  indentation -= DocFormatHelper::offsetSectionContent();
258  }
259 
260  printSpaces(os, indentation);
261  os << "Section " << dfh.section() << "." << dfh.counter()
262  << " " << label() << " default contents: ";
263  writeDoc_(os, indentation + 2);
264  os << "\n";
265  if(!dfh.brief()) os << "\n";
266  }
267 
268  bool
271  return exists(pset);
272  }
273 
274  int
277  return exists(pset) ? 1 : 0;
278  }
279 }
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()
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