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  std::string const& iLabel, ParameterTypes iType, bool isTracked, bool hasDefault, Comment const& iComment)
26  : ParameterDescriptionNode(iComment),
27  label_(iLabel),
28  type_(iType),
29  isTracked_(isTracked),
30  hasDefault_(hasDefault) {
31  if (label_.empty()) {
32  throw Exception(errors::LogicError) << "Empty string used as a label for a parameter. This is\n"
33  "not allowed.\n";
34  }
35  }
36 
38  char const* iLabel, ParameterTypes iType, bool isTracked, bool hasDefault, Comment const& iComment)
39  : ParameterDescriptionNode(iComment),
40  label_(iLabel),
41  type_(iType),
42  isTracked_(isTracked),
43  hasDefault_(hasDefault) {
44  if (label_.empty()) {
45  throw Exception(errors::LogicError) << "Empty string used as a label for a parameter. This is\n"
46  "not allowed.\n";
47  }
48  }
49 
51 
53  std::string tr("a tracked");
54  std::string shouldBe("untracked");
55  if (isTracked()) {
56  tr = "an untracked";
57  shouldBe = "tracked";
58  }
59 
60  throw Exception(errors::Configuration) << "In the configuration, parameter \"" << label()
61  << "\" is defined "
62  "as "
63  << tr << " " << parameterTypeEnumToString(type()) << ".\n"
64  << "It should be " << shouldBe << ".\n";
65  }
66 
68  std::string tr("an untracked");
69  if (isTracked())
70  tr = "a tracked";
71 
72  throw Exception(errors::Configuration) << "Parameter \"" << label()
73  << "\" should be defined "
74  "as "
75  << tr << " " << parameterTypeEnumToString(type()) << ".\n"
76  << "The type in the configuration is incorrect.\n";
77  }
78 
80  std::string tr("untracked");
81  if (isTracked())
82  tr = "tracked";
83 
85  << "Missing required parameter. It should have label \"" << label() << "\" and have type \"" << tr << " "
86  << parameterTypeEnumToString(type()) << "\".\n"
87  << "The description has no default. The parameter must be defined "
88  "in the configuration\n";
89  }
90 
91  void ParameterDescriptionBase::checkAndGetLabelsAndTypes_(std::set<std::string>& usedLabels,
92  std::set<ParameterTypes>& parameterTypes,
93  std::set<ParameterTypes>& /*wildcardTypes*/) const {
94  usedLabels.insert(label());
95  parameterTypes.insert(type());
96  }
97 
99  std::set<std::string>& validatedLabels,
100  bool optional) const {
101  bool exists = exists_(pset, isTracked());
102 
103  if (exists) {
104  validatedLabels.insert(label());
105  } else if (exists_(pset, !isTracked())) {
107  } else if (pset.exists(label())) {
109  }
110 
111  if (!exists && !optional) {
112  if (hasDefault()) {
114  validatedLabels.insert(label());
115  } else {
117  }
118  }
119  }
120 
122  std::ostream& os, bool optional, bool& startWithComma, int indentation, bool& wroteSomething) const {
123  if (label().empty() or label()[0] == '@') {
124  return;
125  }
126  wroteSomething = true;
127  if (startWithComma)
128  os << ",";
129  startWithComma = true;
130 
131  os << "\n";
133 
134  os << label() << " = cms.";
135 
136  if (!hasDefault()) {
137  if (optional) {
138  os << "optional.";
139  } else {
140  os << "required.";
141  }
142  if (!isTracked())
143  os << "untracked.";
145  } else {
146  if (!isTracked())
147  os << "untracked.";
148  os << parameterTypeEnumToString(type()) << "(";
149  writeCfi_(os, indentation);
150  os << ")";
151  }
152  }
153 
154  void ParameterDescriptionBase::print_(std::ostream& os, bool optional, bool writeToCfi, DocFormatHelper& dfh) const {
155  if (dfh.pass() == 0) {
156  dfh.setAtLeast1(label().size());
157  if (isTracked()) {
159  } else {
160  dfh.setAtLeast2(parameterTypeEnumToString(type()).size() + 10U);
161  }
162  if (optional) {
163  dfh.setAtLeast3(8U);
164  }
165  } else {
166  if (dfh.brief()) {
167  std::ios::fmtflags oldFlags = os.flags();
168 
169  dfh.indent(os);
170  os << std::left << std::setw(dfh.column1()) << label() << " ";
171 
172  if (isTracked()) {
173  os << std::setw(dfh.column2()) << parameterTypeEnumToString(type());
174  } else {
175  std::stringstream ss;
176  ss << "untracked ";
178  os << std::setw(dfh.column2()) << ss.str();
179  }
180  os << " ";
181 
182  os << std::setw(dfh.column3());
183  if (optional) {
184  os << "optional";
185  } else {
186  os << "";
187  }
188  os << " ";
189  os.flags(oldFlags);
190  printDefault_(os, writeToCfi, dfh);
191  } else {
192  // not brief
193  dfh.indent(os);
194  os << label() << "\n";
195 
196  dfh.indent2(os);
197  os << "type: ";
198  if (!isTracked())
199  os << "untracked ";
200 
201  os << parameterTypeEnumToString(type()) << " ";
202 
203  if (optional)
204  os << "optional";
205  os << "\n";
206 
207  dfh.indent2(os);
208  printDefault_(os, writeToCfi, dfh);
209 
210  if (!comment().empty()) {
212  }
213  os << "\n";
214  }
215  }
216  }
217 
218  void ParameterDescriptionBase::printDefault_(std::ostream& os, bool writeToCfi, DocFormatHelper& dfh) const {
219  if (!dfh.brief())
220  os << "default: ";
221  if (writeToCfi && hasDefault()) {
222  if (hasNestedContent()) {
223  os << "see Section " << dfh.section() << "." << dfh.counter();
224  } else {
225  if (dfh.brief()) {
226  writeDoc_(os, dfh.indentation());
227  } else {
228  writeDoc_(os, dfh.startColumn2());
229  }
230  }
231  } else if (!writeToCfi) {
232  os << "none (do not write to cfi)";
233  } else {
234  os << "none";
235  }
236  os << "\n";
237  }
238 
239  void ParameterDescriptionBase::printNestedContent_(std::ostream& os, bool /*optional*/, DocFormatHelper& dfh) const {
240  int indentation = dfh.indentation();
241  if (dfh.parent() != DocFormatHelper::TOP) {
243  }
244 
246  os << "Section " << dfh.section() << "." << dfh.counter() << " " << label() << " default contents: ";
247  writeDoc_(os, indentation + 2);
248  os << "\n";
249  if (!dfh.brief())
250  os << "\n";
251  }
252 
254 
256  return exists(pset) ? 1 : 0;
257  }
258 } // namespace edm
std::string const & label() const
int startColumn2() const
bool partiallyExists_(ParameterSet const &pset) const override
int howManyXORSubNodesExist_(ParameterSet const &pset) const override
static void wrapAndPrintText(std::ostream &os, std::string const &text, size_t indent, size_t suggestedWidth)
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const override
void writeCfi_(std::ostream &os, bool optional, bool &startWithComma, int indentation, bool &wroteSomething) const override
std::string parameterTypeEnumToString(ParameterTypes iType)
size_t commentWidth() const
void indent2(std::ostream &os) const
size_t column1() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void setAtLeast2(size_t width)
static int offsetSectionContent()
optional
Definition: Types.py:245
size_t column3() const
size_t column2() const
std::string const & section() const
static void printSpaces(std::ostream &os, int n)
void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh) const override
std::string const & comment() const
bool exists(ParameterSet const &pset) const
virtual bool exists_(ParameterSet const &pset, bool isTracked) const =0
HLT enums.
virtual void insertDefault_(ParameterSet &pset) const =0
ParameterDescriptionBase(std::string const &iLabel, ParameterTypes iType, bool isTracked, bool hasDefault, Comment const &iComment)
virtual void writeDoc_(std::ostream &os, int indentation) const =0
virtual void printDefault_(std::ostream &os, bool writeToCfi, DocFormatHelper &dfh) const
void setAtLeast1(size_t width)
void setAtLeast3(size_t width)
void indent(std::ostream &os) const
void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh) const override
DescriptionParent parent() const
void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const override