CMS 3D CMS Logo

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  Comment const& iComment)
29  :ParameterDescriptionNode(iComment),
30  label_(iLabel),
31  type_(iType),
32  isTracked_(isTracked),
33  hasDefault_(hasDefault) {
34  if(label_.empty()) {
36  << "Empty string used as a label for a parameter. This is\n"
37  "not allowed.\n";
38  }
39  }
40 
42  ParameterTypes iType,
43  bool isTracked,
44  bool hasDefault,
45  Comment const& iComment)
46  :ParameterDescriptionNode(iComment),
47  label_(iLabel),
48  type_(iType),
49  isTracked_(isTracked),
50  hasDefault_(hasDefault) {
51  if(label_.empty()) {
53  << "Empty string used as a label for a parameter. This is\n"
54  "not allowed.\n";
55  }
56  }
57 
59 
60  void
62  std::string tr("a tracked");
63  std::string shouldBe("untracked");
64  if(isTracked()) {
65  tr = "an untracked";
66  shouldBe = "tracked";
67  }
68 
70  << "In the configuration, parameter \"" << label() << "\" is defined "
71  "as " << tr << " " << parameterTypeEnumToString(type()) << ".\n"
72  << "It should be " << shouldBe << ".\n";
73  }
74 
75  void
77  std::string tr("an untracked");
78  if(isTracked()) tr = "a tracked";
79 
81  << "Parameter \"" << label() << "\" should be defined "
82  "as " << tr << " " << parameterTypeEnumToString(type()) << ".\n"
83  << "The type in the configuration is incorrect.\n";
84  }
85 
86  void
88 
89  std::string tr("untracked");
90  if(isTracked()) tr = "tracked";
91 
93  << "Missing required parameter. It should have label \""
94  << label() << "\" and have type \""
95  << tr << " " << parameterTypeEnumToString(type()) << "\".\n"
96  << "The description has no default. The parameter must be defined "
97  "in the configuration\n";
98  }
99 
100  void
102  checkAndGetLabelsAndTypes_(std::set<std::string>& usedLabels,
103  std::set<ParameterTypes>& parameterTypes,
104  std::set<ParameterTypes>& /*wildcardTypes*/) const {
105  usedLabels.insert(label());
106  parameterTypes.insert(type());
107  }
108 
109  void
112  std::set<std::string>& validatedLabels,
113  bool optional) const {
114 
115  bool exists = exists_(pset, isTracked());
116 
117  if(exists) {
118  validatedLabels.insert(label());
119  } else if(exists_(pset, !isTracked())) {
121  } else if(pset.exists(label())) {
123  }
124 
125  if(!exists && !optional) {
126  if(hasDefault()) {
127  insertDefault_(pset);
128  validatedLabels.insert(label());
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) const {
166  if(dfh.pass() == 0) {
167  dfh.setAtLeast1(label().size());
168  if(isTracked()) {
170  } else {
172  }
173  if(optional) {
174  dfh.setAtLeast3(8U);
175  }
176  } else {
177 
178  if(dfh.brief()) {
179  std::ios::fmtflags oldFlags = os.flags();
180 
181  dfh.indent(os);
182  os << std::left << std::setw(dfh.column1()) << label() << " ";
183 
184  if(isTracked()) {
185  os << std::setw(dfh.column2()) << parameterTypeEnumToString(type());
186  } else {
187  std::stringstream ss;
188  ss << "untracked ";
190  os << std::setw(dfh.column2()) << ss.str();
191  }
192  os << " ";
193 
194  os << std::setw(dfh.column3());
195  if(optional) {
196  os << "optional";
197  } else {
198  os << "";
199  }
200  os << " ";
201  os.flags(oldFlags);
202  printDefault_(os, writeToCfi, dfh);
203  } else {
204  // not brief
205  dfh.indent(os);
206  os << label() << "\n";
207 
208  dfh.indent2(os);
209  os << "type: ";
210  if(!isTracked()) os << "untracked ";
211 
212  os << parameterTypeEnumToString(type()) << " ";
213 
214  if(optional) os << "optional";
215  os << "\n";
216 
217  dfh.indent2(os);
218  printDefault_(os, writeToCfi, dfh);
219 
220  if(!comment().empty()) {
222  comment(),
223  dfh.startColumn2(),
224  dfh.commentWidth());
225  }
226  os << "\n";
227  }
228  }
229  }
230 
231  void
233  printDefault_(std::ostream& os,
234  bool writeToCfi,
235  DocFormatHelper& dfh) const {
236  if(!dfh.brief()) os << "default: ";
237  if(writeToCfi && hasDefault()) {
238  if(hasNestedContent()) {
239  os << "see Section " << dfh.section()
240  << "." << dfh.counter();
241  } else {
242  if(dfh.brief()) {
243  writeDoc_(os, dfh.indentation());
244  } else {
245  writeDoc_(os, dfh.startColumn2());
246  }
247  }
248  } else {
249  os << "none (do not write to cfi)";
250  }
251  os << "\n";
252  }
253 
254  void
256  printNestedContent_(std::ostream& os,
257  bool /*optional*/,
258  DocFormatHelper& dfh) const {
259  int indentation = dfh.indentation();
260  if(dfh.parent() != DocFormatHelper::TOP) {
261  indentation -= DocFormatHelper::offsetSectionContent();
262  }
263 
264  printSpaces(os, indentation);
265  os << "Section " << dfh.section() << "." << dfh.counter()
266  << " " << label() << " default contents: ";
267  writeDoc_(os, indentation + 2);
268  os << "\n";
269  if(!dfh.brief()) os << "\n";
270  }
271 
272  bool
275  return exists(pset);
276  }
277 
278  int
281  return exists(pset) ? 1 : 0;
282  }
283 }
size
Write out results.
void writeCfi_(std::ostream &os, bool &startWithComma, int indentation, bool &wroteSomething) const override
void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh) const override
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
virtual void printDefault_(std::ostream &os, bool writeToCfi, DocFormatHelper &dfh) const
int startColumn2() const
std::string parameterTypeEnumToString(ParameterTypes iType)
bool partiallyExists_(ParameterSet const &pset) const override
DescriptionParent parent() const
void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh) const override
int indentation() const
std::string const & comment() const
int howManyXORSubNodesExist_(ParameterSet const &pset) const override
void setAtLeast2(size_t width)
static int offsetSectionContent()
virtual bool exists_(ParameterSet const &pset, bool isTracked) const =0
void indent2(std::ostream &os) const
static void printSpaces(std::ostream &os, int n)
void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const override
size_t column2() const
bool exists(ParameterSet const &pset) const
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const override
virtual void insertDefault_(ParameterSet &pset) const =0
size_t column3() const
HLT enums.
ParameterDescriptionBase(std::string const &iLabel, ParameterTypes iType, bool isTracked, bool hasDefault, Comment const &iComment)
void setAtLeast1(size_t width)
size_t column1() const
void setAtLeast3(size_t width)
virtual void writeDoc_(std::ostream &os, int indentation) const =0
void indent(std::ostream &os) const
size_t commentWidth() const
std::string const & label() const
std::string const & section() const