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 
15  ParameterDescriptionNode const& node_right) :
16  node_left_(node_left.clone()),
17  node_right_(node_right.clone()) {
18  }
19 
21  ANDGroupDescription(std::unique_ptr<ParameterDescriptionNode> node_left,
22  ParameterDescriptionNode const& node_right) :
23  node_left_(std::move(node_left)),
24  node_right_(node_right.clone()) {
25  }
26 
29  std::unique_ptr<ParameterDescriptionNode> node_right) :
30  node_left_(node_left.clone()),
31  node_right_(std::move(node_right)) {
32  }
33 
35  ANDGroupDescription(std::unique_ptr<ParameterDescriptionNode> node_left,
36  std::unique_ptr<ParameterDescriptionNode> node_right) :
37  node_left_(std::move(node_left)),
38  node_right_(std::move(node_right)) {
39  }
40 
41  void
43  checkAndGetLabelsAndTypes_(std::set<std::string> & usedLabels,
44  std::set<ParameterTypes> & parameterTypes,
45  std::set<ParameterTypes> & wildcardTypes) const {
46 
47  std::set<std::string> labelsLeft;
48  std::set<ParameterTypes> parameterTypesLeft;
49  std::set<ParameterTypes> wildcardTypesLeft;
50  node_left_->checkAndGetLabelsAndTypes(labelsLeft, parameterTypesLeft, wildcardTypesLeft);
51 
52  std::set<std::string> labelsRight;
53  std::set<ParameterTypes> parameterTypesRight;
54  std::set<ParameterTypes> wildcardTypesRight;
55  node_right_->checkAndGetLabelsAndTypes(labelsRight, parameterTypesRight, wildcardTypesRight);
56 
57  throwIfDuplicateLabels(labelsLeft, labelsRight);
58  throwIfDuplicateTypes(wildcardTypesLeft, parameterTypesRight);
59  throwIfDuplicateTypes(wildcardTypesRight, parameterTypesLeft);
60 
61  usedLabels.insert(labelsLeft.begin(), labelsLeft.end());
62  usedLabels.insert(labelsRight.begin(), labelsRight.end());
63 
64  parameterTypes.insert(parameterTypesRight.begin(), parameterTypesRight.end());
65  parameterTypes.insert(parameterTypesLeft.begin(), parameterTypesLeft.end());
66 
67  wildcardTypes.insert(wildcardTypesRight.begin(), wildcardTypesRight.end());
68  wildcardTypes.insert(wildcardTypesLeft.begin(), wildcardTypesLeft.end());
69  }
70 
71  void
74  std::set<std::string> & validatedLabels,
75  bool optional) const {
76  if (partiallyExists(pset) || !optional) {
77  node_left_->validate(pset, validatedLabels, false);
78  node_right_->validate(pset, validatedLabels, false);
79  }
80  }
81 
82  void
84  writeCfi_(std::ostream & os,
85  bool & startWithComma,
86  int indentation,
87  bool & wroteSomething) const {
88  node_left_->writeCfi(os, startWithComma, indentation, wroteSomething);
89  node_right_->writeCfi(os, startWithComma, indentation, wroteSomething);
90  }
91 
92  void
94  print_(std::ostream & os,
95  bool optional,
96  bool writeToCfi,
97  DocFormatHelper & dfh) const {
98 
99  if (dfh.parent() == DocFormatHelper::AND) {
100  dfh.decrementCounter();
101  node_left_->print(os, false, true, dfh);
102  node_right_->print(os, false, true, dfh);
103  return;
104  }
105 
106  if (dfh.pass() == 1) {
107 
108  dfh.indent(os);
109  os << "AND group:";
110 
111  if (dfh.brief()) {
112 
113  if (optional) os << " optional";
114 
115  if (!writeToCfi) os << " (do not write to cfi)";
116 
117  os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
118  }
119  // not brief
120  else {
121 
122  os << "\n";
123  dfh.indent2(os);
124 
125  if (optional) os << "optional";
126  if (!writeToCfi) os << " (do not write to cfi)";
127  if (optional || !writeToCfi) {
128  os << "\n";
129  dfh.indent2(os);
130  }
131 
132  os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
133 
134  if (!comment().empty()) {
136  comment(),
137  dfh.startColumn2(),
138  dfh.commentWidth());
139  }
140  os << "\n";
141  }
142  }
143  }
144 
145  void
147  printNestedContent_(std::ostream & os,
148  bool optional,
149  DocFormatHelper & dfh) const {
150 
151  if (dfh.parent() == DocFormatHelper::AND) {
152  dfh.decrementCounter();
153  node_left_->printNestedContent(os, false, dfh);
154  node_right_->printNestedContent(os, false, dfh);
155  return;
156  }
157 
158  int indentation = dfh.indentation();
159  if (dfh.parent() != DocFormatHelper::TOP) {
160  indentation -= DocFormatHelper::offsetSectionContent();
161  }
162 
163  std::stringstream ss;
164  ss << dfh.section() << "." << dfh.counter();
165  std::string newSection = ss.str();
166 
167  printSpaces(os, indentation);
168  os << "Section " << newSection
169  << " AND group description:\n";
170  printSpaces(os, indentation);
171  if (optional) {
172  os << "This optional AND group requires all or none of the following to be in the PSet\n";
173  }
174  else {
175  os << "This AND group requires all of the following to be in the PSet\n";
176  }
177  if (!dfh.brief()) os << "\n";
178 
179  DocFormatHelper new_dfh(dfh);
180  new_dfh.init();
181  new_dfh.setSection(newSection);
182  new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
184 
185  node_left_->print(os, false, true, new_dfh);
186  node_right_->print(os, false, true, new_dfh);
187 
188  new_dfh.setPass(1);
189  new_dfh.setCounter(0);
190 
191  node_left_->print(os, false, true, new_dfh);
192  node_right_->print(os, false, true, new_dfh);
193 
194  new_dfh.setPass(2);
195  new_dfh.setCounter(0);
196 
197  node_left_->printNestedContent(os, false, new_dfh);
198  node_right_->printNestedContent(os, false, new_dfh);
199  }
200 
201  bool
203  exists_(ParameterSet const& pset) const {
204  return node_left_->exists(pset) && node_right_->exists(pset);
205  }
206 
207  bool
210  return node_left_->partiallyExists(pset) || node_right_->partiallyExists(pset);
211  }
212 
213  int
216  return exists(pset) ? 1 : 0;
217  }
218 
219  void
221  throwIfDuplicateLabels(std::set<std::string> const& labelsLeft,
222  std::set<std::string> const& labelsRight) const {
223 
224  std::set<std::string> duplicateLabels;
225  std::insert_iterator<std::set<std::string> > insertIter(duplicateLabels, duplicateLabels.begin());
226  std::set_intersection(labelsLeft.begin(), labelsLeft.end(),
227  labelsRight.begin(), labelsRight.end(),
228  insertIter);
229  if (!duplicateLabels.empty()) {
230  std::stringstream ss;
231  for (std::set<std::string>::const_iterator iter = duplicateLabels.begin(),
232  iEnd = duplicateLabels.end();
233  iter != iEnd;
234  ++iter) {
235  ss << " \"" << *iter << "\"\n";
236  }
238  << "Labels used in different nodes of a ParameterSetDescription\n"
239  << "\"and\" expression must be unique. The following duplicate\n"
240  << "labels were detected:\n"
241  << ss.str()
242  << "\n";
243  }
244  }
245 
246  void
248  throwIfDuplicateTypes(std::set<ParameterTypes> const& types1,
249  std::set<ParameterTypes> const& types2) const
250  {
251  if (!types1.empty()) {
252  std::set<ParameterTypes> duplicateTypes;
253  std::insert_iterator<std::set<ParameterTypes> > insertIter(duplicateTypes, duplicateTypes.begin());
254  std::set_intersection(types1.begin(), types1.end(),
255  types2.begin(), types2.end(),
256  insertIter);
257  if (!duplicateTypes.empty()) {
258  std::stringstream ss;
259  for (std::set<ParameterTypes>::const_iterator iter = duplicateTypes.begin(),
260  iEnd = duplicateTypes.end();
261  iter != iEnd;
262  ++iter) {
263  ss << " \"" << parameterTypeEnumToString(*iter) << "\"\n";
264  }
266  << "Types used for wildcards in different nodes of a ParameterSetDescription\n"
267  << "\"and\" expression must be different from types used for other parameters.\n"
268  << "The following duplicate types were detected:\n"
269  << ss.str()
270  << "\n";
271  }
272  }
273  }
274 }
virtual void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh) const
void throwIfDuplicateTypes(std::set< ParameterTypes > const &types1, std::set< ParameterTypes > const &types2) const
ANDGroupDescription(ParameterDescriptionNode const &node_left, ParameterDescriptionNode const &node_right)
virtual void writeCfi_(std::ostream &os, bool &startWithComma, int indentation, bool &wroteSomething) const
static void wrapAndPrintText(std::ostream &os, std::string const &text, size_t indent, size_t suggestedWidth)
virtual ParameterDescriptionNode * clone() const
virtual bool partiallyExists_(ParameterSet const &pset) const
int startColumn2() const
std::string parameterTypeEnumToString(ParameterTypes iType)
edm::value_ptr< ParameterDescriptionNode > node_right_
DescriptionParent parent() const
void setCounter(int value)
virtual void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh) const
int indentation() const
std::string const & comment() const
virtual void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const
edm::value_ptr< ParameterDescriptionNode > node_left_
static int offsetSectionContent()
void indent2(std::ostream &os) const
void setPass(int value)
static void printSpaces(std::ostream &os, int n)
virtual int howManyXORSubNodesExist_(ParameterSet const &pset) const
bool exists(ParameterSet const &pset) const
bool partiallyExists(ParameterSet const &pset) const
virtual bool exists_(ParameterSet const &pset) const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
HLT enums.
virtual void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const
void indent(std::ostream &os) const
void setSection(std::string const &value)
void throwIfDuplicateLabels(std::set< std::string > const &labelsLeft, std::set< std::string > const &labelsRight) const
size_t commentWidth() const
def move(src, dest)
Definition: eostools.py:510
void setParent(DescriptionParent value)
void setIndentation(int value)
std::string const & section() const