CMS 3D CMS Logo

XORGroupDescription.cc
Go to the documentation of this file.
1 
5 
6 #include <ostream>
7 #include <iomanip>
8 
9 namespace edm {
10 
12  ParameterDescriptionNode const& node_right)
13  : node_left_(node_left.clone()), node_right_(node_right.clone()) {}
14 
15  XORGroupDescription::XORGroupDescription(std::unique_ptr<ParameterDescriptionNode> node_left,
16  ParameterDescriptionNode const& node_right)
17  : node_left_(std::move(node_left)), node_right_(node_right.clone()) {}
18 
20  std::unique_ptr<ParameterDescriptionNode> node_right)
21  : node_left_(node_left.clone()), node_right_(std::move(node_right)) {}
22 
23  XORGroupDescription::XORGroupDescription(std::unique_ptr<ParameterDescriptionNode> node_left,
24  std::unique_ptr<ParameterDescriptionNode> node_right)
25  : node_left_(std::move(node_left)), node_right_(std::move(node_right)) {}
26 
27  void XORGroupDescription::checkAndGetLabelsAndTypes_(std::set<std::string>& usedLabels,
28  std::set<ParameterTypes>& parameterTypes,
29  std::set<ParameterTypes>& wildcardTypes) const {
30  std::set<std::string> labelsLeft;
31  std::set<ParameterTypes> parameterTypesLeft;
32  std::set<ParameterTypes> wildcardTypesLeft;
33  node_left_->checkAndGetLabelsAndTypes(labelsLeft, parameterTypesLeft, wildcardTypesLeft);
34 
35  std::set<std::string> labelsRight;
36  std::set<ParameterTypes> parameterTypesRight;
37  std::set<ParameterTypes> wildcardTypesRight;
38  node_right_->checkAndGetLabelsAndTypes(labelsRight, parameterTypesRight, wildcardTypesRight);
39 
40  usedLabels.insert(labelsLeft.begin(), labelsLeft.end());
41  usedLabels.insert(labelsRight.begin(), labelsRight.end());
42 
43  parameterTypes.insert(parameterTypesRight.begin(), parameterTypesRight.end());
44  parameterTypes.insert(parameterTypesLeft.begin(), parameterTypesLeft.end());
45 
46  wildcardTypes.insert(wildcardTypesRight.begin(), wildcardTypesRight.end());
47  wildcardTypes.insert(wildcardTypesLeft.begin(), wildcardTypesLeft.end());
48  }
49 
50  void XORGroupDescription::validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const {
51  int nExistLeft = node_left_->howManyXORSubNodesExist(pset);
52  int nExistRight = node_right_->howManyXORSubNodesExist(pset);
53  int nTotal = nExistLeft + nExistRight;
54 
55  if (nTotal == 0 && optional)
56  return;
57 
58  if (nTotal > 1) {
60  }
61 
62  if (nExistLeft == 1) {
63  node_left_->validate(pset, validatedLabels, false);
64  } else if (nExistRight == 1) {
65  node_right_->validate(pset, validatedLabels, false);
66  } else if (nTotal == 0) {
67  node_left_->validate(pset, validatedLabels, false);
68 
69  // When missing parameters get inserted, both nodes could
70  // be affected so we have to recheck both nodes.
71  nExistLeft = node_left_->howManyXORSubNodesExist(pset);
72  nExistRight = node_right_->howManyXORSubNodesExist(pset);
73  nTotal = nExistLeft + nExistRight;
74 
75  if (nTotal != 1) {
77  }
78  }
79  }
80 
82  std::ostream& os, bool optional, bool& startWithComma, int indentation, bool& wroteSomething) const {
83  node_left_->writeCfi(os, optional, startWithComma, indentation, wroteSomething);
84  }
85 
86  void XORGroupDescription::print_(std::ostream& os, bool optional, bool writeToCfi, DocFormatHelper& dfh) const {
87  if (dfh.parent() == DocFormatHelper::XOR) {
88  dfh.decrementCounter();
89  node_left_->print(os, false, true, dfh);
90  node_right_->print(os, false, true, dfh);
91  return;
92  }
93 
94  if (dfh.pass() == 1) {
95  dfh.indent(os);
96  os << "XOR group:";
97 
98  if (dfh.brief()) {
99  if (optional)
100  os << " optional";
101 
102  if (!writeToCfi)
103  os << " (do not write to cfi)";
104 
105  os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
106  }
107  // not brief
108  else {
109  os << "\n";
110  dfh.indent2(os);
111 
112  if (optional)
113  os << "optional";
114  if (!writeToCfi)
115  os << " (do not write to cfi)";
116  if (optional || !writeToCfi) {
117  os << "\n";
118  dfh.indent2(os);
119  }
120 
121  os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
122 
123  if (!comment().empty()) {
125  }
126  os << "\n";
127  }
128  }
129  }
130 
131  void XORGroupDescription::printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const {
132  if (dfh.parent() == DocFormatHelper::XOR) {
133  dfh.decrementCounter();
134  node_left_->printNestedContent(os, false, dfh);
135  node_right_->printNestedContent(os, false, dfh);
136  return;
137  }
138 
139  int indentation = dfh.indentation();
140  if (dfh.parent() != DocFormatHelper::TOP) {
142  }
143 
144  std::stringstream ss;
145  ss << dfh.section() << "." << dfh.counter();
146  std::string newSection = ss.str();
147 
149  os << "Section " << newSection << " XOR group description:\n";
151  if (optional) {
152  os << "This optional XOR group requires exactly one or none of the following to be in the PSet\n";
153  } else {
154  os << "This XOR group requires exactly one of the following to be in the PSet\n";
155  }
156  if (!dfh.brief())
157  os << "\n";
158 
159  DocFormatHelper new_dfh(dfh);
160  new_dfh.init();
161  new_dfh.setSection(newSection);
164 
165  node_left_->print(os, false, true, new_dfh);
166  node_right_->print(os, false, true, new_dfh);
167 
168  new_dfh.setPass(1);
169  new_dfh.setCounter(0);
170 
171  node_left_->print(os, false, true, new_dfh);
172  node_right_->print(os, false, true, new_dfh);
173 
174  new_dfh.setPass(2);
175  new_dfh.setCounter(0);
176 
177  node_left_->printNestedContent(os, false, new_dfh);
178  node_right_->printNestedContent(os, false, new_dfh);
179  }
180 
182  int nTotal = node_left_->howManyXORSubNodesExist(pset) + node_right_->howManyXORSubNodesExist(pset);
183  return nTotal == 1;
184  }
185 
187 
189  return node_left_->howManyXORSubNodesExist(pset) + node_right_->howManyXORSubNodesExist(pset);
190  }
191 
193  // Need to expand this error message to print more information
194  // I guess I need to print out the entire node structure of
195  // of the xor node and all the nodes it contains.
197  << "Exactly one parameter can exist in a ParameterSet from a list of\n"
198  << "parameters described by an \"xor\" operator in a ParameterSetDescription.\n"
199  << "This rule also applies in a more general sense to the other types\n"
200  << "of nodes that can appear within a ParameterSetDescription. Only one\n"
201  << "can pass validation as \"existing\".\n";
202  }
203 
205  // Need to expand this error message to print more information
206  // I guess I need to print out the entire node structure of
207  // of the xor node and all the nodes it contains.
209  << "Exactly one parameter can exist in a ParameterSet from a list of\n"
210  << "parameters described by an \"xor\" operator in a ParameterSetDescription.\n"
211  << "This rule also applies in a more general sense to the other types\n"
212  << "of nodes that can appear within a ParameterSetDescription. Only one\n"
213  << "can pass validation as \"existing\". This error has occurred after an\n"
214  << "attempt to insert missing parameters to fix the problem.\n";
215  }
216 } // namespace edm
edm::DocFormatHelper::TOP
Definition: DocFormatHelper.h:17
edm::XORGroupDescription::exists_
bool exists_(ParameterSet const &pset) const override
Definition: XORGroupDescription.cc:181
edm::DocFormatHelper::init
void init()
Definition: DocFormatHelper.cc:113
edm::DocFormatHelper::setCounter
void setCounter(int value)
Definition: DocFormatHelper.h:67
edm::ParameterDescriptionNode::exists
bool exists(ParameterSet const &pset) const
Definition: ParameterDescriptionNode.h:134
edm::errors::LogicError
Definition: EDMException.h:37
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::XORGroupDescription::node_right_
edm::value_ptr< ParameterDescriptionNode > node_right_
Definition: XORGroupDescription.h:59
edm::XORGroupDescription::throwAfterValidation
void throwAfterValidation() const
Definition: XORGroupDescription.cc:204
edm::DocFormatHelper::setSection
void setSection(std::string const &value)
Definition: DocFormatHelper.h:44
edm::XORGroupDescription::printNestedContent_
void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh) const override
Definition: XORGroupDescription.cc:131
Types.optional
optional
Definition: Types.py:199
edm::DocFormatHelper::parent
DescriptionParent parent() const
Definition: DocFormatHelper.h:71
XORGroupDescription.h
EDMException.h
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
edm::DocFormatHelper
Definition: DocFormatHelper.h:15
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
edm::XORGroupDescription::XORGroupDescription
XORGroupDescription(ParameterDescriptionNode const &node_left, ParameterDescriptionNode const &node_right)
Definition: XORGroupDescription.cc:11
edm::XORGroupDescription::howManyXORSubNodesExist_
int howManyXORSubNodesExist_(ParameterSet const &pset) const override
Definition: XORGroupDescription.cc:188
edm::XORGroupDescription::node_left_
edm::value_ptr< ParameterDescriptionNode > node_left_
Definition: XORGroupDescription.h:58
edm::XORGroupDescription::validate_
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const override
Definition: XORGroupDescription.cc:50
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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::XORGroupDescription::checkAndGetLabelsAndTypes_
void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const override
Definition: XORGroupDescription.cc:27
edm::DocFormatHelper::setParent
void setParent(DescriptionParent value)
Definition: DocFormatHelper.h:72
edm::XORGroupDescription::print_
void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh) const override
Definition: XORGroupDescription.cc:86
edm::DocFormatHelper::setIndentation
void setIndentation(int value)
Definition: DocFormatHelper.h:41
edm::XORGroupDescription::writeCfi_
void writeCfi_(std::ostream &os, bool optional, bool &startWithComma, int indentation, bool &wroteSomething) const override
Definition: XORGroupDescription.cc:81
edm::DocFormatHelper::decrementCounter
void decrementCounter()
Definition: DocFormatHelper.h:69
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
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
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
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::XOR
Definition: DocFormatHelper.h:17
edm::XORGroupDescription::partiallyExists_
bool partiallyExists_(ParameterSet const &pset) const override
Definition: XORGroupDescription.cc:186
edm::DocFormatHelper::setPass
void setPass(int value)
Definition: DocFormatHelper.h:47
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::ParameterDescriptionNode
Definition: ParameterDescriptionNode.h:82
edm::XORGroupDescription::throwMoreThanOneParameter
void throwMoreThanOneParameter() const
Definition: XORGroupDescription.cc:192
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
edm::DocFormatHelper::indentation
int indentation() const
Definition: DocFormatHelper.h:36