CMS 3D CMS Logo

ANDGroupDescription.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  ANDGroupDescription::ANDGroupDescription(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  ANDGroupDescription::ANDGroupDescription(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 ANDGroupDescription::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 ANDGroupDescription::validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const {
57  if (partiallyExists(pset) || !optional) {
58  node_left_->validate(pset, validatedLabels, false);
59  node_right_->validate(pset, validatedLabels, false);
60  }
61  }
62 
64  std::ostream& os, bool optional, bool& startWithComma, int indentation, bool& wroteSomething) const {
65  node_left_->writeCfi(os, optional, startWithComma, indentation, wroteSomething);
66  node_right_->writeCfi(os, optional, startWithComma, indentation, wroteSomething);
67  }
68 
69  void ANDGroupDescription::print_(std::ostream& os, bool optional, bool writeToCfi, DocFormatHelper& dfh) const {
70  if (dfh.parent() == DocFormatHelper::AND) {
71  dfh.decrementCounter();
72  node_left_->print(os, false, true, dfh);
73  node_right_->print(os, false, true, dfh);
74  return;
75  }
76 
77  if (dfh.pass() == 1) {
78  dfh.indent(os);
79  os << "AND group:";
80 
81  if (dfh.brief()) {
82  if (optional)
83  os << " optional";
84 
85  if (!writeToCfi)
86  os << " (do not write to cfi)";
87 
88  os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
89  }
90  // not brief
91  else {
92  os << "\n";
93  dfh.indent2(os);
94 
95  if (optional)
96  os << "optional";
97  if (!writeToCfi)
98  os << " (do not write to cfi)";
99  if (optional || !writeToCfi) {
100  os << "\n";
101  dfh.indent2(os);
102  }
103 
104  os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
105 
106  if (!comment().empty()) {
108  }
109  os << "\n";
110  }
111  }
112  }
113 
114  void ANDGroupDescription::printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const {
115  if (dfh.parent() == DocFormatHelper::AND) {
116  dfh.decrementCounter();
117  node_left_->printNestedContent(os, false, dfh);
118  node_right_->printNestedContent(os, false, dfh);
119  return;
120  }
121 
122  int indentation = dfh.indentation();
123  if (dfh.parent() != DocFormatHelper::TOP) {
125  }
126 
127  std::stringstream ss;
128  ss << dfh.section() << "." << dfh.counter();
129  std::string newSection = ss.str();
130 
132  os << "Section " << newSection << " AND group description:\n";
134  if (optional) {
135  os << "This optional AND group requires all or none of the following to be in the PSet\n";
136  } else {
137  os << "This AND group requires all of the following to be in the PSet\n";
138  }
139  if (!dfh.brief())
140  os << "\n";
141 
142  DocFormatHelper new_dfh(dfh);
143  new_dfh.init();
144  new_dfh.setSection(newSection);
147 
148  node_left_->print(os, false, true, new_dfh);
149  node_right_->print(os, false, true, new_dfh);
150 
151  new_dfh.setPass(1);
152  new_dfh.setCounter(0);
153 
154  node_left_->print(os, false, true, new_dfh);
155  node_right_->print(os, false, true, new_dfh);
156 
157  new_dfh.setPass(2);
158  new_dfh.setCounter(0);
159 
160  node_left_->printNestedContent(os, false, new_dfh);
161  node_right_->printNestedContent(os, false, new_dfh);
162  }
163 
165  return node_left_->exists(pset) && node_right_->exists(pset);
166  }
167 
169  return node_left_->partiallyExists(pset) || node_right_->partiallyExists(pset);
170  }
171 
173 
174  void ANDGroupDescription::throwIfDuplicateLabels(std::set<std::string> const& labelsLeft,
175  std::set<std::string> const& labelsRight) const {
176  std::set<std::string> duplicateLabels;
177  std::insert_iterator<std::set<std::string> > insertIter(duplicateLabels, duplicateLabels.begin());
178  std::set_intersection(labelsLeft.begin(), labelsLeft.end(), labelsRight.begin(), labelsRight.end(), insertIter);
179  if (!duplicateLabels.empty()) {
180  std::stringstream ss;
181  for (std::set<std::string>::const_iterator iter = duplicateLabels.begin(), iEnd = duplicateLabels.end();
182  iter != iEnd;
183  ++iter) {
184  ss << " \"" << *iter << "\"\n";
185  }
186  throw edm::Exception(errors::LogicError) << "Labels used in different nodes of a ParameterSetDescription\n"
187  << "\"and\" expression must be unique. The following duplicate\n"
188  << "labels were detected:\n"
189  << ss.str() << "\n";
190  }
191  }
192 
193  void ANDGroupDescription::throwIfDuplicateTypes(std::set<ParameterTypes> const& types1,
194  std::set<ParameterTypes> const& types2) const {
195  if (!types1.empty()) {
196  std::set<ParameterTypes> duplicateTypes;
197  std::insert_iterator<std::set<ParameterTypes> > insertIter(duplicateTypes, duplicateTypes.begin());
198  std::set_intersection(types1.begin(), types1.end(), types2.begin(), types2.end(), insertIter);
199  if (!duplicateTypes.empty()) {
200  std::stringstream ss;
201  for (std::set<ParameterTypes>::const_iterator iter = duplicateTypes.begin(), iEnd = duplicateTypes.end();
202  iter != iEnd;
203  ++iter) {
204  ss << " \"" << parameterTypeEnumToString(*iter) << "\"\n";
205  }
207  << "Types used for wildcards in different nodes of a ParameterSetDescription\n"
208  << "\"and\" expression must be different from types used for other parameters.\n"
209  << "The following duplicate types were detected:\n"
210  << ss.str() << "\n";
211  }
212  }
213  }
214 } // namespace edm
void throwIfDuplicateLabels(std::set< std::string > const &labelsLeft, std::set< std::string > const &labelsRight) const
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const override
void throwIfDuplicateTypes(std::set< ParameterTypes > const &types1, std::set< ParameterTypes > const &types2) const
void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh) const override
ANDGroupDescription(ParameterDescriptionNode const &node_left, ParameterDescriptionNode const &node_right)
int startColumn2() const
static void wrapAndPrintText(std::ostream &os, std::string const &text, size_t indent, size_t suggestedWidth)
void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const override
std::string parameterTypeEnumToString(ParameterTypes iType)
edm::value_ptr< ParameterDescriptionNode > node_right_
size_t commentWidth() const
void setCounter(int value)
void indent2(std::ostream &os) const
void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh) const override
bool partiallyExists_(ParameterSet const &pset) const override
edm::value_ptr< ParameterDescriptionNode > node_left_
int howManyXORSubNodesExist_(ParameterSet const &pset) const override
static int offsetSectionContent()
optional
Definition: Types.py:239
void setPass(int value)
bool exists_(ParameterSet const &pset) const override
std::string const & section() const
static void printSpaces(std::ostream &os, int n)
bool partiallyExists(ParameterSet const &pset) const
std::string const & comment() const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
bool exists(ParameterSet const &pset) const
void writeCfi_(std::ostream &os, bool optional, bool &startWithComma, int indentation, bool &wroteSomething) const override
HLT enums.
void setSection(std::string const &value)
void indent(std::ostream &os) const
def move(src, dest)
Definition: eostools.py:511
void setParent(DescriptionParent value)
DescriptionParent parent() const
void setIndentation(int value)
std::vector< std::string > set_intersection(std::vector< std::string > const &v1, std::vector< std::string > const &v2)