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  wroteSomething = true;
124  if (startWithComma)
125  os << ",";
126  startWithComma = true;
127 
128  os << "\n";
130 
131  os << label() << " = cms.";
132 
133  if (!hasDefault()) {
134  if (optional) {
135  os << "optional.";
136  } else {
137  os << "required.";
138  }
139  if (!isTracked())
140  os << "untracked.";
142  } else {
143  if (!isTracked())
144  os << "untracked.";
145  os << parameterTypeEnumToString(type()) << "(";
146  writeCfi_(os, indentation);
147  os << ")";
148  }
149  }
150 
151  void ParameterDescriptionBase::print_(std::ostream& os, bool optional, bool writeToCfi, DocFormatHelper& dfh) const {
152  if (dfh.pass() == 0) {
153  dfh.setAtLeast1(label().size());
154  if (isTracked()) {
156  } else {
158  }
159  if (optional) {
160  dfh.setAtLeast3(8U);
161  }
162  } else {
163  if (dfh.brief()) {
164  std::ios::fmtflags oldFlags = os.flags();
165 
166  dfh.indent(os);
167  os << std::left << std::setw(dfh.column1()) << label() << " ";
168 
169  if (isTracked()) {
170  os << std::setw(dfh.column2()) << parameterTypeEnumToString(type());
171  } else {
172  std::stringstream ss;
173  ss << "untracked ";
175  os << std::setw(dfh.column2()) << ss.str();
176  }
177  os << " ";
178 
179  os << std::setw(dfh.column3());
180  if (optional) {
181  os << "optional";
182  } else {
183  os << "";
184  }
185  os << " ";
186  os.flags(oldFlags);
187  printDefault_(os, writeToCfi, dfh);
188  } else {
189  // not brief
190  dfh.indent(os);
191  os << label() << "\n";
192 
193  dfh.indent2(os);
194  os << "type: ";
195  if (!isTracked())
196  os << "untracked ";
197 
198  os << parameterTypeEnumToString(type()) << " ";
199 
200  if (optional)
201  os << "optional";
202  os << "\n";
203 
204  dfh.indent2(os);
205  printDefault_(os, writeToCfi, dfh);
206 
207  if (!comment().empty()) {
209  }
210  os << "\n";
211  }
212  }
213  }
214 
215  void ParameterDescriptionBase::printDefault_(std::ostream& os, bool writeToCfi, DocFormatHelper& dfh) const {
216  if (!dfh.brief())
217  os << "default: ";
218  if (writeToCfi && hasDefault()) {
219  if (hasNestedContent()) {
220  os << "see Section " << dfh.section() << "." << dfh.counter();
221  } else {
222  if (dfh.brief()) {
223  writeDoc_(os, dfh.indentation());
224  } else {
225  writeDoc_(os, dfh.startColumn2());
226  }
227  }
228  } else if (!writeToCfi) {
229  os << "none (do not write to cfi)";
230  } else {
231  os << "none";
232  }
233  os << "\n";
234  }
235 
236  void ParameterDescriptionBase::printNestedContent_(std::ostream& os, bool /*optional*/, DocFormatHelper& dfh) const {
237  int indentation = dfh.indentation();
238  if (dfh.parent() != DocFormatHelper::TOP) {
240  }
241 
243  os << "Section " << dfh.section() << "." << dfh.counter() << " " << label() << " default contents: ";
244  writeDoc_(os, indentation + 2);
245  os << "\n";
246  if (!dfh.brief())
247  os << "\n";
248  }
249 
251 
253  return exists(pset) ? 1 : 0;
254  }
255 } // namespace edm
edm::ParameterDescriptionBase::printNestedContent_
void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh) const override
Definition: ParameterDescriptionBase.cc:236
edm::DocFormatHelper::TOP
Definition: DocFormatHelper.h:17
edm::ParameterDescriptionNode::exists
bool exists(ParameterSet const &pset) const
Definition: ParameterDescriptionNode.h:134
edm::ParameterTypes
ParameterTypes
Definition: ParameterDescriptionNode.h:33
edm::ParameterDescriptionBase::label
std::string const & label() const
Definition: ParameterDescriptionBase.h:37
edm::errors::LogicError
Definition: EDMException.h:37
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::DocFormatHelper::setAtLeast2
void setAtLeast2(size_t width)
Definition: DocFormatHelper.h:57
edm::ParameterDescriptionBase::label_
std::string label_
Definition: ParameterDescriptionBase.h:85
Types.optional
optional
Definition: Types.py:167
edm::DocFormatHelper::setAtLeast3
void setAtLeast3(size_t width)
Definition: DocFormatHelper.h:61
edm::ParameterDescriptionBase::throwParameterWrongTrackiness
void throwParameterWrongTrackiness() const
Definition: ParameterDescriptionBase.cc:52
edm::DocFormatHelper::column2
size_t column2() const
Definition: DocFormatHelper.h:50
edm::ParameterDescriptionBase::howManyXORSubNodesExist_
int howManyXORSubNodesExist_(ParameterSet const &pset) const override
Definition: ParameterDescriptionBase.cc:252
edm::DocFormatHelper::parent
DescriptionParent parent() const
Definition: DocFormatHelper.h:71
edm::ParameterDescriptionBase::hasDefault
bool hasDefault() const
Definition: ParameterDescriptionBase.h:40
edm::parameterTypeEnumToString
std::string parameterTypeEnumToString(ParameterTypes iType)
Definition: ParameterDescriptionNode.cc:64
edm::ParameterDescriptionBase::writeCfi_
void writeCfi_(std::ostream &os, bool optional, bool &startWithComma, int indentation, bool &wroteSomething) const override
Definition: ParameterDescriptionBase.cc:121
EDMException.h
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
edm::DocFormatHelper
Definition: DocFormatHelper.h:15
edm::ParameterDescriptionBase::throwMissingRequiredNoDefault
void throwMissingRequiredNoDefault() const
Definition: ParameterDescriptionBase.cc:79
edm::ParameterDescriptionBase::print_
void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh) const override
Definition: ParameterDescriptionBase.cc:151
edm::ParameterDescriptionBase::throwParameterWrongType
void throwParameterWrongType() const
Definition: ParameterDescriptionBase.cc:67
edm::ParameterDescriptionBase::insertDefault_
virtual void insertDefault_(ParameterSet &pset) const =0
ParameterDescriptionBase.h
edm::ParameterDescriptionBase::printDefault_
virtual void printDefault_(std::ostream &os, bool writeToCfi, DocFormatHelper &dfh) const
Definition: ParameterDescriptionBase.cc:215
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterDescriptionBase::~ParameterDescriptionBase
~ParameterDescriptionBase() override
Definition: ParameterDescriptionBase.cc:50
edm::DocFormatHelper::startColumn2
int startColumn2() const
Definition: DocFormatHelper.h:37
edm::ParameterSet
Definition: ParameterSet.h:36
edm::Comment
Definition: ParameterDescriptionNode.h:71
edm::DocFormatHelper::brief
bool brief() const
Definition: DocFormatHelper.h:34
edm::DocFormatHelper::wrapAndPrintText
static void wrapAndPrintText(std::ostream &os, std::string const &text, size_t indent, size_t suggestedWidth)
Definition: DocFormatHelper.cc:97
edm::DocFormatHelper::setAtLeast1
void setAtLeast1(size_t width)
Definition: DocFormatHelper.h:53
edm::ParameterDescriptionBase::validate_
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const override
Definition: ParameterDescriptionBase.cc:98
edm::ParameterDescriptionNode::hasNestedContent
bool hasNestedContent() const
Definition: ParameterDescriptionNode.h:123
edm::ParameterDescriptionBase::checkAndGetLabelsAndTypes_
void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const override
Definition: ParameterDescriptionBase.cc:91
edm::DocFormatHelper::indent
void indent(std::ostream &os) const
Definition: DocFormatHelper.cc:133
edm::ParameterDescriptionBase::ParameterDescriptionBase
ParameterDescriptionBase(std::string const &iLabel, ParameterTypes iType, bool isTracked, bool hasDefault, Comment const &iComment)
Definition: ParameterDescriptionBase.cc:24
edm::DocFormatHelper::commentWidth
size_t commentWidth() const
Definition: DocFormatHelper.cc:123
edm::ParameterDescriptionBase::exists_
virtual bool exists_(ParameterSet const &pset, bool isTracked) const =0
edm::DocFormatHelper::indent2
void indent2(std::ostream &os) const
Definition: DocFormatHelper.cc:139
edm::ParameterDescriptionNode::printSpaces
static void printSpaces(std::ostream &os, int n)
Definition: ParameterDescriptionNode.cc:124
edm::DocFormatHelper::counter
int counter() const
Definition: DocFormatHelper.h:66
DocFormatHelper.h
edm::ParameterDescriptionBase::isTracked
bool isTracked() const
Definition: ParameterDescriptionBase.h:39
edm::DocFormatHelper::offsetSectionContent
static int offsetSectionContent()
Definition: DocFormatHelper.h:83
edm::DocFormatHelper::pass
int pass() const
Definition: DocFormatHelper.h:46
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
Exception
Definition: hltDiff.cc:246
printContent_cfi.indentation
indentation
Definition: printContent_cfi.py:10
edm::DocFormatHelper::column1
size_t column1() const
Definition: DocFormatHelper.h:49
edm::ParameterDescriptionBase::partiallyExists_
bool partiallyExists_(ParameterSet const &pset) const override
Definition: ParameterDescriptionBase.cc:250
edm::ParameterDescriptionNode::comment
std::string const & comment() const
Definition: ParameterDescriptionNode.h:92
edm::DocFormatHelper::section
std::string const & section() const
Definition: DocFormatHelper.h:43
edm::ParameterDescriptionBase::type
ParameterTypes type() const
Definition: ParameterDescriptionBase.h:38
ParameterSet.h
edm::DocFormatHelper::column3
size_t column3() const
Definition: DocFormatHelper.h:51
edm::ParameterDescriptionNode
Definition: ParameterDescriptionNode.h:82
edm::errors::Configuration
Definition: EDMException.h:36
edm::ParameterDescriptionBase::writeDoc_
virtual void writeDoc_(std::ostream &os, int indentation) const =0
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
edm::DocFormatHelper::indentation
int indentation() const
Definition: DocFormatHelper.h:36
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443