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 
63  void ANDGroupDescription::writeCfi_(std::ostream& os,
64  bool optional,
65  bool& startWithComma,
66  int indentation,
68  bool& wroteSomething) const {
69  node_left_->writeCfi(os, optional, startWithComma, indentation, options, wroteSomething);
70  node_right_->writeCfi(os, optional, startWithComma, indentation, options, wroteSomething);
71  }
72 
73  void ANDGroupDescription::print_(std::ostream& os, bool optional, bool writeToCfi, DocFormatHelper& dfh) const {
74  if (dfh.parent() == DocFormatHelper::AND) {
75  dfh.decrementCounter();
76  node_left_->print(os, false, true, dfh);
77  node_right_->print(os, false, true, dfh);
78  return;
79  }
80 
81  if (dfh.pass() == 1) {
82  dfh.indent(os);
83  os << "AND group:";
84 
85  if (dfh.brief()) {
86  if (optional)
87  os << " optional";
88 
89  if (!writeToCfi)
90  os << " (do not write to cfi)";
91 
92  os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
93  }
94  // not brief
95  else {
96  os << "\n";
97  dfh.indent2(os);
98 
99  if (optional)
100  os << "optional";
101  if (!writeToCfi)
102  os << " (do not write to cfi)";
103  if (optional || !writeToCfi) {
104  os << "\n";
105  dfh.indent2(os);
106  }
107 
108  os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
109 
110  if (!comment().empty()) {
112  }
113  os << "\n";
114  }
115  }
116  }
117 
118  void ANDGroupDescription::printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const {
119  if (dfh.parent() == DocFormatHelper::AND) {
120  dfh.decrementCounter();
121  node_left_->printNestedContent(os, false, dfh);
122  node_right_->printNestedContent(os, false, dfh);
123  return;
124  }
125 
126  int indentation = dfh.indentation();
127  if (dfh.parent() != DocFormatHelper::TOP) {
129  }
130 
131  std::stringstream ss;
132  ss << dfh.section() << "." << dfh.counter();
133  std::string newSection = ss.str();
134 
136  os << "Section " << newSection << " AND group description:\n";
138  if (optional) {
139  os << "This optional AND group requires all or none of the following to be in the PSet\n";
140  } else {
141  os << "This AND group requires all of the following to be in the PSet\n";
142  }
143  if (!dfh.brief())
144  os << "\n";
145 
146  DocFormatHelper new_dfh(dfh);
147  new_dfh.init();
148  new_dfh.setSection(newSection);
151 
152  node_left_->print(os, false, true, new_dfh);
153  node_right_->print(os, false, true, new_dfh);
154 
155  new_dfh.setPass(1);
156  new_dfh.setCounter(0);
157 
158  node_left_->print(os, false, true, new_dfh);
159  node_right_->print(os, false, true, new_dfh);
160 
161  new_dfh.setPass(2);
162  new_dfh.setCounter(0);
163 
164  node_left_->printNestedContent(os, false, new_dfh);
165  node_right_->printNestedContent(os, false, new_dfh);
166  }
167 
169  return node_left_->exists(pset) && node_right_->exists(pset);
170  }
171 
173  return node_left_->partiallyExists(pset) || node_right_->partiallyExists(pset);
174  }
175 
177 
178  void ANDGroupDescription::throwIfDuplicateLabels(std::set<std::string> const& labelsLeft,
179  std::set<std::string> const& labelsRight) const {
180  std::set<std::string> duplicateLabels;
181  std::insert_iterator<std::set<std::string> > insertIter(duplicateLabels, duplicateLabels.begin());
182  std::set_intersection(labelsLeft.begin(), labelsLeft.end(), labelsRight.begin(), labelsRight.end(), insertIter);
183  if (!duplicateLabels.empty()) {
184  std::stringstream ss;
185  for (std::set<std::string>::const_iterator iter = duplicateLabels.begin(), iEnd = duplicateLabels.end();
186  iter != iEnd;
187  ++iter) {
188  ss << " \"" << *iter << "\"\n";
189  }
190  throw edm::Exception(errors::LogicError) << "Labels used in different nodes of a ParameterSetDescription\n"
191  << "\"and\" expression must be unique. The following duplicate\n"
192  << "labels were detected:\n"
193  << ss.str() << "\n";
194  }
195  }
196 
197  void ANDGroupDescription::throwIfDuplicateTypes(std::set<ParameterTypes> const& types1,
198  std::set<ParameterTypes> const& types2) const {
199  if (!types1.empty()) {
200  std::set<ParameterTypes> duplicateTypes;
201  std::insert_iterator<std::set<ParameterTypes> > insertIter(duplicateTypes, duplicateTypes.begin());
202  std::set_intersection(types1.begin(), types1.end(), types2.begin(), types2.end(), insertIter);
203  if (!duplicateTypes.empty()) {
204  std::stringstream ss;
205  for (std::set<ParameterTypes>::const_iterator iter = duplicateTypes.begin(), iEnd = duplicateTypes.end();
206  iter != iEnd;
207  ++iter) {
208  ss << " \"" << parameterTypeEnumToString(*iter) << "\"\n";
209  }
211  << "Types used for wildcards in different nodes of a ParameterSetDescription\n"
212  << "\"and\" expression must be different from types used for other parameters.\n"
213  << "The following duplicate types were detected:\n"
214  << ss.str() << "\n";
215  }
216  }
217  }
218 } // 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:245
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
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)
cfi::CfiOptions CfiOptions
void writeCfi_(std::ostream &os, bool optional, bool &startWithComma, int indentation, CfiOptions &, bool &wroteSomething) const override
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)