CMS 3D CMS Logo

ParameterSwitchBase.cc
Go to the documentation of this file.
1 
3 
6 
7 #include <iomanip>
8 #include <ostream>
9 #include <sstream>
10 
11 namespace edm {
12 
14 
16  throw Exception(errors::LogicError) << "When adding a ParameterSwitch to a ParameterSetDescription the values\n"
17  << "associated with the different cases must be unique. Duplicate\n"
18  << "values were found for the switch with label: \"" << switchLabel << "\"\n";
19  }
20 
22  std::set<std::string>& usedLabels,
23  std::set<std::string>& labels) const {
24  std::pair<std::set<std::string>::iterator, bool> status = labels.insert(switchLabel);
25  if (status.second == false) {
27  << "The label used for the switch parameter in a ParameterSetDescription\n"
28  << "must be different from the labels used in the associated cases. The following\n"
29  << "duplicate label was found: \"" << switchLabel << "\"\n";
30  }
31  usedLabels.insert(labels.begin(), labels.end());
32  }
33 
35  std::set<ParameterTypes> const& caseParameterTypes,
36  std::set<ParameterTypes> const& caseWildcardTypes,
37  std::set<ParameterTypes>& parameterTypes,
38  std::set<ParameterTypes>& wildcardTypes) const {
39  if (caseWildcardTypes.find(switchType) != caseWildcardTypes.end()) {
41  << "The type used for the switch parameter in a ParameterSetDescription\n"
42  << "must be different from the types used for wildcards in the associated cases. The following\n"
43  << "duplicate type was found: \"" << parameterTypeEnumToString(switchType) << "\"\n";
44  }
45  parameterTypes.insert(switchType);
46  parameterTypes.insert(caseParameterTypes.begin(), caseParameterTypes.end());
47  wildcardTypes.insert(caseWildcardTypes.begin(), caseWildcardTypes.end());
48  }
49 
52  << "The default value used for the switch parameter in a ParameterSetDescription\n"
53  << "must match the value used to select one of the associated cases. This is not\n"
54  << "true for the switch named \"" << switchLabel << "\"\n";
55  }
56 
58  throw Exception(errors::Configuration) << message;
59  }
60 
61  void ParameterSwitchBase::printBase(std::ostream& os,
62  bool optional,
63  bool writeToCfi,
64  DocFormatHelper& dfh,
65  std::string const& switchLabel,
66  bool isTracked,
67  std::string const& typeString) const {
68  if (dfh.pass() == 0) {
69  dfh.setAtLeast1(switchLabel.size() + 9U);
70  if (isTracked) {
71  dfh.setAtLeast2(typeString.size());
72  } else {
73  dfh.setAtLeast2(typeString.size() + 10U);
74  }
75  dfh.setAtLeast3(8U);
76  }
77  if (dfh.pass() == 1) {
78  dfh.indent(os);
79 
80  if (dfh.brief()) {
81  std::stringstream ss;
82  ss << switchLabel << " (switch)";
83  std::ios::fmtflags oldFlags = os.flags();
84  os << std::left << std::setw(dfh.column1()) << ss.str();
85  os << " ";
86 
87  os << std::setw(dfh.column2());
88  if (isTracked) {
89  os << typeString;
90  } else {
91  std::stringstream ss1;
92  ss1 << "untracked " << typeString;
93  os << ss1.str();
94  }
95 
96  os << " " << std::setw(dfh.column3());
97  if (optional)
98  os << "optional";
99  else
100  os << "";
101 
102  if (!writeToCfi)
103  os << " (do not write to cfi)";
104 
105  os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
106  os.flags(oldFlags);
107  } else {
108  // not brief
109 
110  os << switchLabel << " (switch)\n";
111 
112  dfh.indent2(os);
113  os << "type: ";
114  if (!isTracked)
115  os << "untracked ";
116  os << typeString << " ";
117 
118  if (optional)
119  os << "optional";
120 
121  if (!writeToCfi)
122  os << " (do not write to cfi)";
123  os << "\n";
124 
125  dfh.indent2(os);
126  os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
127 
128  if (!comment().empty()) {
130  }
131  os << "\n";
132  }
133  }
134  }
135 
136  bool ParameterSwitchBase::hasNestedContent_() const { return true; }
137 
139  DocFormatHelper& dfh,
140  DocFormatHelper& new_dfh,
141  std::string const& switchLabel) const {
142  int indentation = dfh.indentation();
143  if (dfh.parent() != DocFormatHelper::TOP) {
145  }
146 
147  std::stringstream ss;
148  ss << dfh.section() << "." << dfh.counter();
149  std::string newSection = ss.str();
150 
152  os << "Section " << newSection << " " << switchLabel << " (switch):\n";
153 
154  if (!dfh.brief()) {
156  os << "The value of \"" << switchLabel << "\" controls which other parameters\n";
158  os << "are required or allowed to be in the PSet.\n";
159  }
160  if (!dfh.brief())
161  os << "\n";
162 
163  new_dfh.init();
164  new_dfh.setSection(newSection);
167  }
168 
170  std::ostream& os,
171  bool /*optional*/,
172  DocFormatHelper& dfh,
173  std::string const& switchLabel) {
174  if (dfh.pass() == 0) {
175  p.second->print(os, false, true, dfh);
176  }
177  if (dfh.pass() == 1) {
178  dfh.indent(os);
179  os << "if " << switchLabel << " = ";
180  if (p.first)
181  os << "True";
182  else
183  os << "False";
184  os << "\n";
185  p.second->print(os, false, true, dfh);
186  }
187  if (dfh.pass() == 2) {
188  p.second->printNestedContent(os, false, dfh);
189  }
190  }
191 
193  std::ostream& os,
194  bool /*optional*/,
195  DocFormatHelper& dfh,
196  std::string const& switchLabel) {
197  if (dfh.pass() == 0) {
198  p.second->print(os, false, true, dfh);
199  }
200  if (dfh.pass() == 1) {
201  dfh.indent(os);
202  os << "if " << switchLabel << " = " << p.first << "\n";
203  p.second->print(os, false, true, dfh);
204  }
205  if (dfh.pass() == 2) {
206  p.second->printNestedContent(os, false, dfh);
207  }
208  }
209 
211  std::ostream& os,
212  bool /*optional*/,
213  DocFormatHelper& dfh,
214  std::string const& switchLabel) {
215  if (dfh.pass() == 0) {
216  p.second->print(os, false, true, dfh);
217  }
218  if (dfh.pass() == 1) {
219  dfh.indent(os);
220  os << "if " << switchLabel << " = \"" << p.first << "\"\n";
221  p.second->print(os, false, true, dfh);
222  }
223  if (dfh.pass() == 2) {
224  p.second->printNestedContent(os, false, dfh);
225  }
226  }
227 
229 
231 } // namespace edm
edm::DocFormatHelper::TOP
Definition: DocFormatHelper.h:17
edm::ParameterSwitchBase::throwNoCaseForSwitchValue
void throwNoCaseForSwitchValue(std::string const &message) const
Definition: ParameterSwitchBase.cc:57
SummaryClient_cfi.labels
labels
Definition: SummaryClient_cfi.py:61
edm::DocFormatHelper::init
void init()
Definition: DocFormatHelper.cc:113
edm::ParameterSwitchBase::partiallyExists_
bool partiallyExists_(ParameterSet const &pset) const override
Definition: ParameterSwitchBase.cc:228
edm::ParameterDescriptionNode::exists
bool exists(ParameterSet const &pset) const
Definition: ParameterDescriptionNode.h:134
edm::ParameterSwitchBase::howManyXORSubNodesExist_
int howManyXORSubNodesExist_(ParameterSet const &pset) const override
Definition: ParameterSwitchBase.cc:230
edm::ParameterTypes
ParameterTypes
Definition: ParameterDescriptionNode.h:33
edm::errors::LogicError
Definition: EDMException.h:37
mps_update.status
status
Definition: mps_update.py:69
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
edm::DocFormatHelper::setAtLeast2
void setAtLeast2(size_t width)
Definition: DocFormatHelper.h:57
edm::DocFormatHelper::setSection
void setSection(std::string const &value)
Definition: DocFormatHelper.h:44
Types.optional
optional
Definition: Types.py:199
edm::DocFormatHelper::setAtLeast3
void setAtLeast3(size_t width)
Definition: DocFormatHelper.h:61
edm::DocFormatHelper::column2
size_t column2() const
Definition: DocFormatHelper.h:50
edm::DocFormatHelper::parent
DescriptionParent parent() const
Definition: DocFormatHelper.h:71
edm::parameterTypeEnumToString
std::string parameterTypeEnumToString(ParameterTypes iType)
Definition: ParameterDescriptionNode.cc:64
edm::ParameterSwitchBase::~ParameterSwitchBase
~ParameterSwitchBase() override
Definition: ParameterSwitchBase.cc:13
EDMException.h
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
edm::DocFormatHelper
Definition: DocFormatHelper.h:15
edm::ParameterSwitchBase::printNestedContentBase
void printNestedContentBase(std::ostream &os, DocFormatHelper &dfh, DocFormatHelper &new_dfh, std::string const &switchLabel) const
Definition: ParameterSwitchBase.cc:138
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSwitchBase::insertAndCheckLabels
void insertAndCheckLabels(std::string const &switchLabel, std::set< std::string > &usedLabels, std::set< std::string > &labels) const
Definition: ParameterSwitchBase.cc:21
edm::ParameterSwitchBase::hasNestedContent_
bool hasNestedContent_() const override
Definition: ParameterSwitchBase.cc:136
edm::DocFormatHelper::startColumn2
int startColumn2() const
Definition: DocFormatHelper.h:37
edm::ParameterSet
Definition: ParameterSet.h:47
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::value_ptr
Definition: value_ptr.h:63
edm::ParameterSwitchBase::throwDuplicateCaseValues
void throwDuplicateCaseValues(std::string const &switchLabel) const
Definition: ParameterSwitchBase.cc:15
edm::DocFormatHelper::setParent
void setParent(DescriptionParent value)
Definition: DocFormatHelper.h:72
edm::DocFormatHelper::setIndentation
void setIndentation(int value)
Definition: DocFormatHelper.h:41
edm::ParameterSwitchBase::insertAndCheckTypes
void insertAndCheckTypes(ParameterTypes switchType, std::set< ParameterTypes > const &caseParameterTypes, std::set< ParameterTypes > const &caseWildcardTypes, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const
Definition: ParameterSwitchBase.cc:34
edm::ParameterSwitchBase::printBase
void printBase(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh, std::string const &switchLabel, bool isTracked, std::string const &typeString) const
Definition: ParameterSwitchBase.cc:61
edm::DocFormatHelper::indent
void indent(std::ostream &os) const
Definition: DocFormatHelper.cc:133
edm::DocFormatHelper::commentWidth
size_t commentWidth() const
Definition: DocFormatHelper.cc:123
edm::DocFormatHelper::indent2
void indent2(std::ostream &os) const
Definition: DocFormatHelper.cc:139
ParameterSwitchBase.h
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::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:245
printContent_cfi.indentation
indentation
Definition: printContent_cfi.py:10
edm::DocFormatHelper::column1
size_t column1() const
Definition: DocFormatHelper.h:49
edm::ParameterDescriptionNode::comment
std::string const & comment() const
Definition: ParameterDescriptionNode.h:92
edm::ParameterSwitchBase::throwNoCaseForDefault
void throwNoCaseForDefault(std::string const &switchLabel) const
Definition: ParameterSwitchBase.cc:50
edm::DocFormatHelper::section
std::string const & section() const
Definition: DocFormatHelper.h:43
edm::ParameterSwitchBase::printCase
static void printCase(std::pair< bool, edm::value_ptr< ParameterDescriptionNode > > const &p, std::ostream &os, bool optional, DocFormatHelper &dfh, std::string const &switchLabel)
Definition: ParameterSwitchBase.cc:169
edm::DocFormatHelper::OTHER
Definition: DocFormatHelper.h:17
edm::DocFormatHelper::column3
size_t column3() const
Definition: DocFormatHelper.h:51
edm::errors::Configuration
Definition: EDMException.h:36
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
edm::DocFormatHelper::indentation
int indentation() const
Definition: DocFormatHelper.h:36