test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
15  ParameterDescriptionNode const& node_right) :
16  node_left_(node_left.clone()),
17  node_right_(node_right.clone()) {
18  }
19 
21  ORGroupDescription(std::auto_ptr<ParameterDescriptionNode> node_left,
22  ParameterDescriptionNode const& node_right) :
23  node_left_(node_left),
24  node_right_(node_right.clone()) {
25  }
26 
29  std::auto_ptr<ParameterDescriptionNode> node_right) :
30  node_left_(node_left.clone()),
31  node_right_(node_right) {
32  }
33 
35  ORGroupDescription(std::auto_ptr<ParameterDescriptionNode> node_left,
36  std::auto_ptr<ParameterDescriptionNode> node_right) :
37  node_left_(node_left),
38  node_right_(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 
77  bool leftExists = node_left_->exists(pset);
78  bool rightExists = node_right_->exists(pset);
79 
80  if (leftExists || rightExists) {
81  if (leftExists) node_left_->validate(pset, validatedLabels, false);
82  if (rightExists) node_right_->validate(pset, validatedLabels, false);
83  return;
84  }
85 
86  if (optional) return;
87 
88  node_left_->validate(pset, validatedLabels, false);
89  }
90 
91  void
93  writeCfi_(std::ostream & os,
94  bool & startWithComma,
95  int indentation,
96  bool & wroteSomething) const {
97  node_left_->writeCfi(os, startWithComma, indentation, wroteSomething);
98  }
99 
100  void
102  print_(std::ostream & os,
103  bool optional,
104  bool writeToCfi,
105  DocFormatHelper & dfh) {
106 
107  if (dfh.parent() == DocFormatHelper::OR) {
108  dfh.decrementCounter();
109  node_left_->print(os, false, true, dfh);
110  node_right_->print(os, false, true, dfh);
111  return;
112  }
113 
114  if (dfh.pass() == 1) {
115 
116  dfh.indent(os);
117  os << "OR group:";
118 
119  if (dfh.brief()) {
120 
121  if (optional) os << " optional";
122 
123  if (!writeToCfi) os << " (do not write to cfi)";
124 
125  os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
126  }
127  // not brief
128  else {
129 
130  os << "\n";
131  dfh.indent2(os);
132 
133  if (optional) os << "optional";
134  if (!writeToCfi) os << " (do not write to cfi)";
135  if (optional || !writeToCfi) {
136  os << "\n";
137  dfh.indent2(os);
138  }
139 
140  os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
141 
142  if (!comment().empty()) {
144  comment(),
145  dfh.startColumn2(),
146  dfh.commentWidth());
147  }
148  os << "\n";
149  }
150  }
151  }
152 
153  void
155  printNestedContent_(std::ostream & os,
156  bool optional,
157  DocFormatHelper & dfh) {
158 
159  if (dfh.parent() == DocFormatHelper::OR) {
160  dfh.decrementCounter();
161  node_left_->printNestedContent(os, false, dfh);
162  node_right_->printNestedContent(os, false, dfh);
163  return;
164  }
165 
166  int indentation = dfh.indentation();
167  if (dfh.parent() != DocFormatHelper::TOP) {
168  indentation -= DocFormatHelper::offsetSectionContent();
169  }
170 
171  std::stringstream ss;
172  ss << dfh.section() << "." << dfh.counter();
173  std::string newSection = ss.str();
174 
175  printSpaces(os, indentation);
176  os << "Section " << newSection
177  << " OR group description:\n";
178  printSpaces(os, indentation);
179  if (optional) {
180  // An optional OR group is kind of pointless, it would be
181  // easier just make the parameters be independent optional parameters
182  // I only allow it to make the behavior analogous to the other groups
183  os << "This optional OR group requires at least one or none of the following to be in the PSet\n";
184  }
185  else {
186  os << "This OR group requires at least one of the following to be in the PSet\n";
187  }
188  if (!dfh.brief()) os << "\n";
189 
190  DocFormatHelper new_dfh(dfh);
191  new_dfh.init();
192  new_dfh.setSection(newSection);
193  new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
195 
196  node_left_->print(os, false, true, new_dfh);
197  node_right_->print(os, false, true, new_dfh);
198 
199  new_dfh.setPass(1);
200  new_dfh.setCounter(0);
201 
202  node_left_->print(os, false, true, new_dfh);
203  node_right_->print(os, false, true, new_dfh);
204 
205  new_dfh.setPass(2);
206  new_dfh.setCounter(0);
207 
208  node_left_->printNestedContent(os, false, new_dfh);
209  node_right_->printNestedContent(os, false, new_dfh);
210  }
211 
212  bool
214  exists_(ParameterSet const& pset) const {
215  return node_left_->exists(pset) ||
216  node_right_->exists(pset);
217  }
218 
219  bool
221  partiallyExists_(ParameterSet const& pset) const {
222  return exists(pset);
223  }
224 
225  int
228  return exists(pset) ? 1 : 0;
229  }
230 
231  void
233  throwIfDuplicateLabels(std::set<std::string> const& labelsLeft,
234  std::set<std::string> const& labelsRight) const {
235 
236  std::set<std::string> duplicateLabels;
237  std::insert_iterator<std::set<std::string> > insertIter(duplicateLabels, duplicateLabels.begin());
238  std::set_intersection(labelsLeft.begin(), labelsLeft.end(),
239  labelsRight.begin(), labelsRight.end(),
240  insertIter);
241  if (!duplicateLabels.empty()) {
242  std::stringstream ss;
243  for (std::set<std::string>::const_iterator iter = duplicateLabels.begin(),
244  iEnd = duplicateLabels.end();
245  iter != iEnd;
246  ++iter) {
247  ss << " \"" << *iter << "\"\n";
248  }
250  << "Labels used in a node of a ParameterSetDescription\n"
251  << "\"or\" expression must be not be the same as labels used\n"
252  << "in other nodes of the expression. The following duplicate\n"
253  << "labels were detected:\n"
254  << ss.str()
255  << "\n";
256  }
257  }
258 
259  void
261  throwIfDuplicateTypes(std::set<ParameterTypes> const& types1,
262  std::set<ParameterTypes> const& types2) const
263  {
264  if (!types1.empty()) {
265  std::set<ParameterTypes> duplicateTypes;
266  std::insert_iterator<std::set<ParameterTypes> > insertIter(duplicateTypes, duplicateTypes.begin());
267  std::set_intersection(types1.begin(), types1.end(),
268  types2.begin(), types2.end(),
269  insertIter);
270  if (!duplicateTypes.empty()) {
271  std::stringstream ss;
272  for (std::set<ParameterTypes>::const_iterator iter = duplicateTypes.begin(),
273  iEnd = duplicateTypes.end();
274  iter != iEnd;
275  ++iter) {
276  ss << " \"" << parameterTypeEnumToString(*iter) << "\"\n";
277  }
279  << "Types used for wildcards in a node of a ParameterSetDescription\n"
280  << "\"or\" expression must be different from types used for other parameters\n"
281  << "in other nodes. The following duplicate types were detected:\n"
282  << ss.str()
283  << "\n";
284  }
285  }
286  }
287 }
virtual void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh)
static void wrapAndPrintText(std::ostream &os, std::string const &text, size_t indent, size_t suggestedWidth)
edm::value_ptr< ParameterDescriptionNode > node_left_
virtual void writeCfi_(std::ostream &os, bool &startWithComma, int indentation, bool &wroteSomething) const
int startColumn2() const
virtual bool exists_(ParameterSet const &pset) const
std::string parameterTypeEnumToString(ParameterTypes iType)
DescriptionParent parent() const
void setCounter(int value)
int indentation() const
std::string const & comment() const
virtual bool partiallyExists_(ParameterSet const &pset) const
static int offsetSectionContent()
void indent2(std::ostream &os) const
void setPass(int value)
virtual void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh)
static void printSpaces(std::ostream &os, int n)
ORGroupDescription(ParameterDescriptionNode const &node_left, ParameterDescriptionNode const &node_right)
bool exists(ParameterSet const &pset) const
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
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)
edm::value_ptr< ParameterDescriptionNode > node_right_
size_t commentWidth() const
virtual int howManyXORSubNodesExist_(ParameterSet const &pset) const
void setParent(DescriptionParent value)
void setIndentation(int value)
virtual void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const
std::string const & section() const