CMS 3D CMS Logo

ORGroupDescription.cc
Go to the documentation of this file.
1 
5 
6 #include <algorithm>
7 #include <sstream>
8 #include <ostream>
9 #include <iomanip>
10 
11 namespace edm {
12 
14  ParameterDescriptionNode const& node_right)
15  : node_left_(node_left.clone()), node_right_(node_right.clone()) {}
16 
17  ORGroupDescription::ORGroupDescription(std::unique_ptr<ParameterDescriptionNode> node_left,
18  ParameterDescriptionNode const& node_right)
19  : node_left_(std::move(node_left)), node_right_(node_right.clone()) {}
20 
22  std::unique_ptr<ParameterDescriptionNode> node_right)
23  : node_left_(node_left.clone()), node_right_(std::move(node_right)) {}
24 
25  ORGroupDescription::ORGroupDescription(std::unique_ptr<ParameterDescriptionNode> node_left,
26  std::unique_ptr<ParameterDescriptionNode> node_right)
27  : node_left_(std::move(node_left)), node_right_(std::move(node_right)) {}
28 
29  void ORGroupDescription::checkAndGetLabelsAndTypes_(std::set<std::string>& usedLabels,
30  std::set<ParameterTypes>& parameterTypes,
31  std::set<ParameterTypes>& wildcardTypes) const {
32  std::set<std::string> labelsLeft;
33  std::set<ParameterTypes> parameterTypesLeft;
34  std::set<ParameterTypes> wildcardTypesLeft;
35  node_left_->checkAndGetLabelsAndTypes(labelsLeft, parameterTypesLeft, wildcardTypesLeft);
36 
37  std::set<std::string> labelsRight;
38  std::set<ParameterTypes> parameterTypesRight;
39  std::set<ParameterTypes> wildcardTypesRight;
40  node_right_->checkAndGetLabelsAndTypes(labelsRight, parameterTypesRight, wildcardTypesRight);
41 
42  throwIfDuplicateLabels(labelsLeft, labelsRight);
43  throwIfDuplicateTypes(wildcardTypesLeft, parameterTypesRight);
44  throwIfDuplicateTypes(wildcardTypesRight, parameterTypesLeft);
45 
46  usedLabels.insert(labelsLeft.begin(), labelsLeft.end());
47  usedLabels.insert(labelsRight.begin(), labelsRight.end());
48 
49  parameterTypes.insert(parameterTypesRight.begin(), parameterTypesRight.end());
50  parameterTypes.insert(parameterTypesLeft.begin(), parameterTypesLeft.end());
51 
52  wildcardTypes.insert(wildcardTypesRight.begin(), wildcardTypesRight.end());
53  wildcardTypes.insert(wildcardTypesLeft.begin(), wildcardTypesLeft.end());
54  }
55 
56  void ORGroupDescription::validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const {
57  bool leftExists = node_left_->exists(pset);
58  bool rightExists = node_right_->exists(pset);
59 
60  if (leftExists || rightExists) {
61  if (leftExists)
62  node_left_->validate(pset, validatedLabels, false);
63  if (rightExists)
64  node_right_->validate(pset, validatedLabels, false);
65  return;
66  }
67 
68  if (optional)
69  return;
70 
71  node_left_->validate(pset, validatedLabels, false);
72  }
73 
74  void ORGroupDescription::writeCfi_(std::ostream& os,
75  bool& startWithComma,
76  int indentation,
77  bool& wroteSomething) const {
78  node_left_->writeCfi(os, startWithComma, indentation, wroteSomething);
79  }
80 
81  void ORGroupDescription::print_(std::ostream& os, bool optional, bool writeToCfi, DocFormatHelper& dfh) const {
82  if (dfh.parent() == DocFormatHelper::OR) {
83  dfh.decrementCounter();
84  node_left_->print(os, false, true, dfh);
85  node_right_->print(os, false, true, dfh);
86  return;
87  }
88 
89  if (dfh.pass() == 1) {
90  dfh.indent(os);
91  os << "OR group:";
92 
93  if (dfh.brief()) {
94  if (optional)
95  os << " optional";
96 
97  if (!writeToCfi)
98  os << " (do not write to cfi)";
99 
100  os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
101  }
102  // not brief
103  else {
104  os << "\n";
105  dfh.indent2(os);
106 
107  if (optional)
108  os << "optional";
109  if (!writeToCfi)
110  os << " (do not write to cfi)";
111  if (optional || !writeToCfi) {
112  os << "\n";
113  dfh.indent2(os);
114  }
115 
116  os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
117 
118  if (!comment().empty()) {
120  }
121  os << "\n";
122  }
123  }
124  }
125 
126  void ORGroupDescription::printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const {
127  if (dfh.parent() == DocFormatHelper::OR) {
128  dfh.decrementCounter();
129  node_left_->printNestedContent(os, false, dfh);
130  node_right_->printNestedContent(os, false, dfh);
131  return;
132  }
133 
134  int indentation = dfh.indentation();
135  if (dfh.parent() != DocFormatHelper::TOP) {
136  indentation -= DocFormatHelper::offsetSectionContent();
137  }
138 
139  std::stringstream ss;
140  ss << dfh.section() << "." << dfh.counter();
141  std::string newSection = ss.str();
142 
143  printSpaces(os, indentation);
144  os << "Section " << newSection << " OR group description:\n";
145  printSpaces(os, indentation);
146  if (optional) {
147  // An optional OR group is kind of pointless, it would be
148  // easier just make the parameters be independent optional parameters
149  // I only allow it to make the behavior analogous to the other groups
150  os << "This optional OR group requires at least one or none of the following to be in the PSet\n";
151  } else {
152  os << "This OR group requires at least one of the following to be in the PSet\n";
153  }
154  if (!dfh.brief())
155  os << "\n";
156 
157  DocFormatHelper new_dfh(dfh);
158  new_dfh.init();
159  new_dfh.setSection(newSection);
160  new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
162 
163  node_left_->print(os, false, true, new_dfh);
164  node_right_->print(os, false, true, new_dfh);
165 
166  new_dfh.setPass(1);
167  new_dfh.setCounter(0);
168 
169  node_left_->print(os, false, true, new_dfh);
170  node_right_->print(os, false, true, new_dfh);
171 
172  new_dfh.setPass(2);
173  new_dfh.setCounter(0);
174 
175  node_left_->printNestedContent(os, false, new_dfh);
176  node_right_->printNestedContent(os, false, new_dfh);
177  }
178 
180  return node_left_->exists(pset) || node_right_->exists(pset);
181  }
182 
183  bool ORGroupDescription::partiallyExists_(ParameterSet const& pset) const { return exists(pset); }
184 
185  int ORGroupDescription::howManyXORSubNodesExist_(ParameterSet const& pset) const { return exists(pset) ? 1 : 0; }
186 
187  void ORGroupDescription::throwIfDuplicateLabels(std::set<std::string> const& labelsLeft,
188  std::set<std::string> const& labelsRight) const {
189  std::set<std::string> duplicateLabels;
190  std::insert_iterator<std::set<std::string> > insertIter(duplicateLabels, duplicateLabels.begin());
191  std::set_intersection(labelsLeft.begin(), labelsLeft.end(), labelsRight.begin(), labelsRight.end(), insertIter);
192  if (!duplicateLabels.empty()) {
193  std::stringstream ss;
194  for (std::set<std::string>::const_iterator iter = duplicateLabels.begin(), iEnd = duplicateLabels.end();
195  iter != iEnd;
196  ++iter) {
197  ss << " \"" << *iter << "\"\n";
198  }
199  throw edm::Exception(errors::LogicError) << "Labels used in a node of a ParameterSetDescription\n"
200  << "\"or\" expression must be not be the same as labels used\n"
201  << "in other nodes of the expression. The following duplicate\n"
202  << "labels were detected:\n"
203  << ss.str() << "\n";
204  }
205  }
206 
207  void ORGroupDescription::throwIfDuplicateTypes(std::set<ParameterTypes> const& types1,
208  std::set<ParameterTypes> const& types2) const {
209  if (!types1.empty()) {
210  std::set<ParameterTypes> duplicateTypes;
211  std::insert_iterator<std::set<ParameterTypes> > insertIter(duplicateTypes, duplicateTypes.begin());
212  std::set_intersection(types1.begin(), types1.end(), types2.begin(), types2.end(), insertIter);
213  if (!duplicateTypes.empty()) {
214  std::stringstream ss;
215  for (std::set<ParameterTypes>::const_iterator iter = duplicateTypes.begin(), iEnd = duplicateTypes.end();
216  iter != iEnd;
217  ++iter) {
218  ss << " \"" << parameterTypeEnumToString(*iter) << "\"\n";
219  }
221  << "Types used for wildcards in a node of a ParameterSetDescription\n"
222  << "\"or\" expression must be different from types used for other parameters\n"
223  << "in other nodes. The following duplicate types were detected:\n"
224  << ss.str() << "\n";
225  }
226  }
227  }
228 } // namespace edm
bool exists_(ParameterSet const &pset) const override
static void wrapAndPrintText(std::ostream &os, std::string const &text, size_t indent, size_t suggestedWidth)
edm::value_ptr< ParameterDescriptionNode > node_left_
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const override
ParameterDescriptionNode * clone() const override
int startColumn2() const
std::string parameterTypeEnumToString(ParameterTypes iType)
DescriptionParent parent() const
void setCounter(int value)
int howManyXORSubNodesExist_(ParameterSet const &pset) const override
int indentation() const
std::string const & comment() const
static int offsetSectionContent()
void indent2(std::ostream &os) const
void writeCfi_(std::ostream &os, bool &startWithComma, int indentation, bool &wroteSomething) const override
void setPass(int value)
static void printSpaces(std::ostream &os, int n)
ORGroupDescription(ParameterDescriptionNode const &node_left, ParameterDescriptionNode const &node_right)
bool exists(ParameterSet const &pset) const
void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh) const override
bool partiallyExists_(ParameterSet const &pset) const override
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
void throwIfDuplicateTypes(std::set< ParameterTypes > const &types1, std::set< ParameterTypes > const &types2) const
void throwIfDuplicateLabels(std::set< std::string > const &labelsLeft, std::set< std::string > const &labelsRight) const
HLT enums.
void indent(std::ostream &os) const
void setSection(std::string const &value)
void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const override
edm::value_ptr< ParameterDescriptionNode > node_right_
size_t commentWidth() const
def move(src, dest)
Definition: eostools.py:511
void setParent(DescriptionParent value)
void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh) const override
void setIndentation(int value)
std::string const & section() const