CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IfExistsDescription.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  IfExistsDescription(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  IfExistsDescription(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  return;
82  }
83  else if (leftExists && rightExists) {
84  node_left_->validate(pset, validatedLabels, false);
85  node_right_->validate(pset, validatedLabels, false);
86  }
87  else if (leftExists && !rightExists) {
88  node_left_->validate(pset, validatedLabels, false);
89  if (!optional) node_right_->validate(pset, validatedLabels, false);
90  }
91  else if (!leftExists && rightExists) {
92  node_left_->validate(pset, validatedLabels, false);
93  node_right_->validate(pset, validatedLabels, false);
94  }
95  }
96 
97  void
99  writeCfi_(std::ostream & os,
100  bool & startWithComma,
101  int indentation,
102  bool & wroteSomething) const {
103  node_left_->writeCfi(os, startWithComma, indentation, wroteSomething);
104  node_right_->writeCfi(os, startWithComma, indentation, wroteSomething);
105  }
106 
107  void
109  print_(std::ostream & os,
110  bool optional,
111  bool writeToCfi,
112  DocFormatHelper & dfh) {
113 
114  if (dfh.pass() == 1) {
115 
116  dfh.indent(os);
117  os << "IfExists pair:";
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  int indentation = dfh.indentation();
160  if (dfh.parent() != DocFormatHelper::TOP) {
161  indentation -= DocFormatHelper::offsetSectionContent();
162  }
163 
164  std::stringstream ss;
165  ss << dfh.section() << "." << dfh.counter();
166  std::string newSection = ss.str();
167 
168  printSpaces(os, indentation);
169  os << "Section " << newSection;
170  if (optional) os << " optional";
171  os << " IfExists pair description:\n";
172  printSpaces(os, indentation);
173  if (optional) {
174  os << "If the first parameter exists, then the second is allowed to exist\n";
175  }
176  else {
177  os << "If the first parameter exists, then the second is required to exist\n";
178  }
179  if (!dfh.brief()) os << "\n";
180 
181  DocFormatHelper new_dfh(dfh);
182  new_dfh.init();
183  new_dfh.setSection(newSection);
184  new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
186 
187  node_left_->print(os, false, true, new_dfh);
188  node_right_->print(os, false, true, new_dfh);
189 
190  new_dfh.setPass(1);
191  new_dfh.setCounter(0);
192 
193  node_left_->print(os, false, true, new_dfh);
194  node_right_->print(os, false, true, new_dfh);
195 
196  new_dfh.setPass(2);
197  new_dfh.setCounter(0);
198 
199  node_left_->printNestedContent(os, false, new_dfh);
200  node_right_->printNestedContent(os, false , new_dfh);
201  }
202 
203  bool
205  exists_(ParameterSet const& pset) const {
206  bool leftExists = node_left_->exists(pset);
207  bool rightExists = node_right_->exists(pset);
208 
209  if (leftExists && rightExists) return true;
210  else if (!leftExists && !rightExists) return true;
211  return false;
212  }
213 
214  bool
216  partiallyExists_(ParameterSet const& pset) const {
217  return exists(pset);
218  }
219 
220  int
223  return exists(pset) ? 1 : 0;
224  }
225 
226  void
228  throwIfDuplicateLabels(std::set<std::string> const& labelsLeft,
229  std::set<std::string> const& labelsRight) const {
230 
231  std::set<std::string> duplicateLabels;
232  std::insert_iterator<std::set<std::string> > insertIter(duplicateLabels, duplicateLabels.begin());
233  std::set_intersection(labelsLeft.begin(), labelsLeft.end(),
234  labelsRight.begin(), labelsRight.end(),
235  insertIter);
236  if (!duplicateLabels.empty()) {
237  std::stringstream ss;
238  for (std::set<std::string>::const_iterator iter = duplicateLabels.begin(),
239  iEnd = duplicateLabels.end();
240  iter != iEnd;
241  ++iter) {
242  ss << " \"" << *iter << "\"\n";
243  }
245  << "Labels used in a node of a ParameterSetDescription\n"
246  << "\"ifExists\" expression must be not be the same as labels used\n"
247  << "in other nodes of the expression. The following duplicate\n"
248  << "labels were detected:\n"
249  << ss.str()
250  << "\n";
251  }
252  }
253 
254  void
256  throwIfDuplicateTypes(std::set<ParameterTypes> const& types1,
257  std::set<ParameterTypes> const& types2) const
258  {
259  if (!types1.empty()) {
260  std::set<ParameterTypes> duplicateTypes;
261  std::insert_iterator<std::set<ParameterTypes> > insertIter(duplicateTypes, duplicateTypes.begin());
262  std::set_intersection(types1.begin(), types1.end(),
263  types2.begin(), types2.end(),
264  insertIter);
265  if (!duplicateTypes.empty()) {
266  std::stringstream ss;
267  for (std::set<ParameterTypes>::const_iterator iter = duplicateTypes.begin(),
268  iEnd = duplicateTypes.end();
269  iter != iEnd;
270  ++iter) {
271  ss << " \"" << parameterTypeEnumToString(*iter) << "\"\n";
272  }
274  << "Types used for wildcards in a node of a ParameterSetDescription\n"
275  << "\"ifExists\" expression must be different from types used for other parameters\n"
276  << "in other nodes. The following duplicate types were detected:\n"
277  << ss.str()
278  << "\n";
279  }
280  }
281  }
282 }
static void wrapAndPrintText(std::ostream &os, std::string const &text, size_t indent, size_t suggestedWidth)
virtual int howManyXORSubNodesExist_(ParameterSet const &pset) const
virtual void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh)
int startColumn2() const
std::string parameterTypeEnumToString(ParameterTypes iType)
DescriptionParent parent() const
void setCounter(int value)
IfExistsDescription(ParameterDescriptionNode const &node_left, ParameterDescriptionNode const &node_right)
virtual bool exists_(ParameterSet const &pset) const
virtual void writeCfi_(std::ostream &os, bool &startWithComma, int indentation, bool &wroteSomething) const
void throwIfDuplicateLabels(std::set< std::string > const &labelsLeft, std::set< std::string > const &labelsRight) const
void throwIfDuplicateTypes(std::set< ParameterTypes > const &types1, std::set< ParameterTypes > const &types2) const
int indentation() const
std::string const & comment() const
edm::value_ptr< ParameterDescriptionNode > node_right_
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)
bool exists(ParameterSet const &pset) const
virtual void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const
virtual bool partiallyExists_(ParameterSet const &pset) const
virtual void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh)
virtual void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
void indent(std::ostream &os) const
void setSection(std::string const &value)
size_t commentWidth() const
void setParent(DescriptionParent value)
void setIndentation(int value)
std::string const & section() const