CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
XORGroupDescription.cc
Go to the documentation of this file.
1 
5 
6 #include <ostream>
7 #include <iomanip>
8 
9 namespace edm {
10 
13  ParameterDescriptionNode const& node_right) :
14  node_left_(node_left.clone()),
15  node_right_(node_right.clone()) {
16  }
17 
19  XORGroupDescription(std::auto_ptr<ParameterDescriptionNode> node_left,
20  ParameterDescriptionNode const& node_right) :
21  node_left_(node_left),
22  node_right_(node_right.clone()) {
23  }
24 
27  std::auto_ptr<ParameterDescriptionNode> node_right) :
28  node_left_(node_left.clone()),
29  node_right_(node_right) {
30  }
31 
33  XORGroupDescription(std::auto_ptr<ParameterDescriptionNode> node_left,
34  std::auto_ptr<ParameterDescriptionNode> node_right) :
35  node_left_(node_left),
36  node_right_(node_right) {
37  }
38 
39  void
41  checkAndGetLabelsAndTypes_(std::set<std::string> & usedLabels,
42  std::set<ParameterTypes> & parameterTypes,
43  std::set<ParameterTypes> & wildcardTypes) const {
44 
45  std::set<std::string> labelsLeft;
46  std::set<ParameterTypes> parameterTypesLeft;
47  std::set<ParameterTypes> wildcardTypesLeft;
48  node_left_->checkAndGetLabelsAndTypes(labelsLeft, parameterTypesLeft, wildcardTypesLeft);
49 
50  std::set<std::string> labelsRight;
51  std::set<ParameterTypes> parameterTypesRight;
52  std::set<ParameterTypes> wildcardTypesRight;
53  node_right_->checkAndGetLabelsAndTypes(labelsRight, parameterTypesRight, wildcardTypesRight);
54 
55  usedLabels.insert(labelsLeft.begin(), labelsLeft.end());
56  usedLabels.insert(labelsRight.begin(), labelsRight.end());
57 
58  parameterTypes.insert(parameterTypesRight.begin(), parameterTypesRight.end());
59  parameterTypes.insert(parameterTypesLeft.begin(), parameterTypesLeft.end());
60 
61  wildcardTypes.insert(wildcardTypesRight.begin(), wildcardTypesRight.end());
62  wildcardTypes.insert(wildcardTypesLeft.begin(), wildcardTypesLeft.end());
63  }
64 
65  void
68  std::set<std::string> & validatedLabels,
69  bool optional) const {
70 
71  int nExistLeft = node_left_->howManyXORSubNodesExist(pset);
72  int nExistRight = node_right_->howManyXORSubNodesExist(pset);
73  int nTotal = nExistLeft + nExistRight;
74 
75  if (nTotal == 0 && optional) return;
76 
77  if (nTotal > 1) {
79  }
80 
81  if (nExistLeft == 1) {
82  node_left_->validate(pset, validatedLabels, false);
83  }
84  else if (nExistRight == 1) {
85  node_right_->validate(pset, validatedLabels, false);
86  }
87  else if (nTotal == 0) {
88  node_left_->validate(pset, validatedLabels, false);
89 
90  // When missing parameters get inserted, both nodes could
91  // be affected so we have to recheck both nodes.
92  nExistLeft = node_left_->howManyXORSubNodesExist(pset);
93  nExistRight = node_right_->howManyXORSubNodesExist(pset);
94  nTotal = nExistLeft + nExistRight;
95 
96  if (nTotal != 1) {
98  }
99  }
100  }
101 
102  void
104  writeCfi_(std::ostream & os,
105  bool & startWithComma,
106  int indentation,
107  bool & wroteSomething) const {
108  node_left_->writeCfi(os, startWithComma, indentation, wroteSomething);
109  }
110 
111  void
113  print_(std::ostream & os,
114  bool optional,
115  bool writeToCfi,
116  DocFormatHelper & dfh) {
117 
118  if (dfh.parent() == DocFormatHelper::XOR) {
119  dfh.decrementCounter();
120  node_left_->print(os, false, true, dfh);
121  node_right_->print(os, false, true, dfh);
122  return;
123  }
124 
125  if (dfh.pass() == 1) {
126 
127  dfh.indent(os);
128  os << "XOR group:";
129 
130  if (dfh.brief()) {
131 
132  if (optional) os << " optional";
133 
134  if (!writeToCfi) os << " (do not write to cfi)";
135 
136  os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
137  }
138  // not brief
139  else {
140 
141  os << "\n";
142  dfh.indent2(os);
143 
144  if (optional) os << "optional";
145  if (!writeToCfi) os << " (do not write to cfi)";
146  if (optional || !writeToCfi) {
147  os << "\n";
148  dfh.indent2(os);
149  }
150 
151  os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
152 
153  if (!comment().empty()) {
155  comment(),
156  dfh.startColumn2(),
157  dfh.commentWidth());
158  }
159  os << "\n";
160  }
161  }
162  }
163 
164  void
166  printNestedContent_(std::ostream & os,
167  bool optional,
168  DocFormatHelper & dfh) {
169 
170  if (dfh.parent() == DocFormatHelper::XOR) {
171  dfh.decrementCounter();
172  node_left_->printNestedContent(os, false, dfh);
173  node_right_->printNestedContent(os, false, dfh);
174  return;
175  }
176 
177  int indentation = dfh.indentation();
178  if (dfh.parent() != DocFormatHelper::TOP) {
179  indentation -= DocFormatHelper::offsetSectionContent();
180  }
181 
182  std::stringstream ss;
183  ss << dfh.section() << "." << dfh.counter();
184  std::string newSection = ss.str();
185 
186  printSpaces(os, indentation);
187  os << "Section " << newSection
188  << " XOR group description:\n";
189  printSpaces(os, indentation);
190  if (optional) {
191  os << "This optional XOR group requires exactly one or none of the following to be in the PSet\n";
192  }
193  else {
194  os << "This XOR group requires exactly one of the following to be in the PSet\n";
195  }
196  if (!dfh.brief()) os << "\n";
197 
198  DocFormatHelper new_dfh(dfh);
199  new_dfh.init();
200  new_dfh.setSection(newSection);
201  new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
203 
204  node_left_->print(os, false, true, new_dfh);
205  node_right_->print(os, false, true, new_dfh);
206 
207  new_dfh.setPass(1);
208  new_dfh.setCounter(0);
209 
210  node_left_->print(os, false, true, new_dfh);
211  node_right_->print(os, false, true, new_dfh);
212 
213  new_dfh.setPass(2);
214  new_dfh.setCounter(0);
215 
216  node_left_->printNestedContent(os, false, new_dfh);
217  node_right_->printNestedContent(os, false, new_dfh);
218  }
219 
220  bool
222  exists_(ParameterSet const& pset) const {
223  int nTotal = node_left_->howManyXORSubNodesExist(pset) +
224  node_right_->howManyXORSubNodesExist(pset);
225  return nTotal == 1;
226  }
227 
228  bool
230  partiallyExists_(ParameterSet const& pset) const {
231  return exists(pset);
232  }
233 
234  int
237  return node_left_->howManyXORSubNodesExist(pset) +
238  node_right_->howManyXORSubNodesExist(pset);
239  }
240 
241  void
244  // Need to expand this error message to print more information
245  // I guess I need to print out the entire node structure of
246  // of the xor node and all the nodes it contains.
248  << "Exactly one parameter can exist in a ParameterSet from a list of\n"
249  << "parameters described by an \"xor\" operator in a ParameterSetDescription.\n"
250  << "This rule also applies in a more general sense to the other types\n"
251  << "of nodes that can appear within a ParameterSetDescription. Only one\n"
252  << "can pass validation as \"existing\".\n";
253  }
254 
255  void
258  // Need to expand this error message to print more information
259  // I guess I need to print out the entire node structure of
260  // of the xor node and all the nodes it contains.
262  << "Exactly one parameter can exist in a ParameterSet from a list of\n"
263  << "parameters described by an \"xor\" operator in a ParameterSetDescription.\n"
264  << "This rule also applies in a more general sense to the other types\n"
265  << "of nodes that can appear within a ParameterSetDescription. Only one\n"
266  << "can pass validation as \"existing\". This error has occurred after an\n"
267  << "attempt to insert missing parameters to fix the problem.\n";
268  }
269 }
virtual void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const
static void wrapAndPrintText(std::ostream &os, std::string const &text, size_t indent, size_t suggestedWidth)
virtual void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh)
virtual bool exists_(ParameterSet const &pset) const
virtual bool partiallyExists_(ParameterSet const &pset) const
int startColumn2() const
virtual void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const
DescriptionParent parent() const
virtual void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh)
void setCounter(int value)
int indentation() const
std::string const & comment() const
static int offsetSectionContent()
void indent2(std::ostream &os) const
virtual void writeCfi_(std::ostream &os, bool &startWithComma, int indentation, bool &wroteSomething) const
void setPass(int value)
static void printSpaces(std::ostream &os, int n)
bool exists(ParameterSet const &pset) const
virtual int howManyXORSubNodesExist_(ParameterSet const &pset) const
XORGroupDescription(ParameterDescriptionNode const &node_left, ParameterDescriptionNode const &node_right)
edm::value_ptr< ParameterDescriptionNode > node_left_
tuple clone
Definition: statics.py:58
void indent(std::ostream &os) const
void setSection(std::string const &value)
size_t commentWidth() const
void setParent(DescriptionParent value)
edm::value_ptr< ParameterDescriptionNode > node_right_
void setIndentation(int value)
std::string const & section() const