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