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 
81  void XORGroupDescription::writeCfi_(std::ostream& os,
82  bool optional,
83  bool& startWithComma,
84  int indentation,
86  bool& wroteSomething) const {
87  node_left_->writeCfi(os, optional, startWithComma, indentation, options, wroteSomething);
88  }
89 
90  void XORGroupDescription::print_(std::ostream& os, bool optional, bool writeToCfi, DocFormatHelper& dfh) const {
91  if (dfh.parent() == DocFormatHelper::XOR) {
92  dfh.decrementCounter();
93  node_left_->print(os, false, true, dfh);
94  node_right_->print(os, false, true, dfh);
95  return;
96  }
97 
98  if (dfh.pass() == 1) {
99  dfh.indent(os);
100  os << "XOR group:";
101 
102  if (dfh.brief()) {
103  if (optional)
104  os << " optional";
105 
106  if (!writeToCfi)
107  os << " (do not write to cfi)";
108 
109  os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
110  }
111  // not brief
112  else {
113  os << "\n";
114  dfh.indent2(os);
115 
116  if (optional)
117  os << "optional";
118  if (!writeToCfi)
119  os << " (do not write to cfi)";
120  if (optional || !writeToCfi) {
121  os << "\n";
122  dfh.indent2(os);
123  }
124 
125  os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
126 
127  if (!comment().empty()) {
129  }
130  os << "\n";
131  }
132  }
133  }
134 
135  void XORGroupDescription::printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const {
136  if (dfh.parent() == DocFormatHelper::XOR) {
137  dfh.decrementCounter();
138  node_left_->printNestedContent(os, false, dfh);
139  node_right_->printNestedContent(os, false, dfh);
140  return;
141  }
142 
143  int indentation = dfh.indentation();
144  if (dfh.parent() != DocFormatHelper::TOP) {
146  }
147 
148  std::stringstream ss;
149  ss << dfh.section() << "." << dfh.counter();
150  std::string newSection = ss.str();
151 
153  os << "Section " << newSection << " XOR group description:\n";
155  if (optional) {
156  os << "This optional XOR group requires exactly one or none of the following to be in the PSet\n";
157  } else {
158  os << "This XOR group requires exactly one of the following to be in the PSet\n";
159  }
160  if (!dfh.brief())
161  os << "\n";
162 
163  DocFormatHelper new_dfh(dfh);
164  new_dfh.init();
165  new_dfh.setSection(newSection);
168 
169  node_left_->print(os, false, true, new_dfh);
170  node_right_->print(os, false, true, new_dfh);
171 
172  new_dfh.setPass(1);
173  new_dfh.setCounter(0);
174 
175  node_left_->print(os, false, true, new_dfh);
176  node_right_->print(os, false, true, new_dfh);
177 
178  new_dfh.setPass(2);
179  new_dfh.setCounter(0);
180 
181  node_left_->printNestedContent(os, false, new_dfh);
182  node_right_->printNestedContent(os, false, new_dfh);
183  }
184 
186  int nTotal = node_left_->howManyXORSubNodesExist(pset) + node_right_->howManyXORSubNodesExist(pset);
187  return nTotal == 1;
188  }
189 
191 
193  return node_left_->howManyXORSubNodesExist(pset) + node_right_->howManyXORSubNodesExist(pset);
194  }
195 
197  // Need to expand this error message to print more information
198  // I guess I need to print out the entire node structure of
199  // of the xor node and all the nodes it contains.
201  << "Exactly one parameter can exist in a ParameterSet from a list of\n"
202  << "parameters described by an \"xor\" operator in a ParameterSetDescription.\n"
203  << "This rule also applies in a more general sense to the other types\n"
204  << "of nodes that can appear within a ParameterSetDescription. Only one\n"
205  << "can pass validation as \"existing\".\n";
206  }
207 
209  // Need to expand this error message to print more information
210  // I guess I need to print out the entire node structure of
211  // of the xor node and all the nodes it contains.
213  << "Exactly one parameter can exist in a ParameterSet from a list of\n"
214  << "parameters described by an \"xor\" operator in a ParameterSetDescription.\n"
215  << "This rule also applies in a more general sense to the other types\n"
216  << "of nodes that can appear within a ParameterSetDescription. Only one\n"
217  << "can pass validation as \"existing\". This error has occurred after an\n"
218  << "attempt to insert missing parameters to fix the problem.\n";
219  }
220 } // namespace edm
int startColumn2() const
static void wrapAndPrintText(std::ostream &os, std::string const &text, size_t indent, size_t suggestedWidth)
bool exists_(ParameterSet const &pset) const override
int howManyXORSubNodesExist_(ParameterSet const &pset) const override
void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh) const override
size_t commentWidth() const
void setCounter(int value)
void indent2(std::ostream &os) const
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const override
void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const override
static int offsetSectionContent()
bool partiallyExists_(ParameterSet const &pset) const override
optional
Definition: Types.py:245
void writeCfi_(std::ostream &os, bool optional, bool &startWithComma, int indentation, CfiOptions &, bool &wroteSomething) const override
void setPass(int value)
std::string const & section() const
static void printSpaces(std::ostream &os, int n)
XORGroupDescription(ParameterDescriptionNode const &node_left, ParameterDescriptionNode const &node_right)
std::string const & comment() const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
bool exists(ParameterSet const &pset) const
edm::value_ptr< ParameterDescriptionNode > node_left_
HLT enums.
void setSection(std::string const &value)
void indent(std::ostream &os) const
def move(src, dest)
Definition: eostools.py:511
void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh) const override
void setParent(DescriptionParent value)
cfi::CfiOptions CfiOptions
edm::value_ptr< ParameterDescriptionNode > node_right_
DescriptionParent parent() const
void setIndentation(int value)