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