CMS 3D CMS Logo

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 
14  ParameterDescriptionNode const& node_right)
15  : node_left_(node_left.clone()), node_right_(node_right.clone()) {}
16 
17  IfExistsDescription::IfExistsDescription(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  IfExistsDescription::IfExistsDescription(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 IfExistsDescription::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 IfExistsDescription::validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const {
57  bool leftExists = node_left_->exists(pset);
58  bool rightExists = node_right_->exists(pset);
59 
60  if (!leftExists && !rightExists) {
61  return;
62  } else if (leftExists && rightExists) {
63  node_left_->validate(pset, validatedLabels, false);
64  node_right_->validate(pset, validatedLabels, false);
65  } else if (leftExists && !rightExists) {
66  node_left_->validate(pset, validatedLabels, false);
67  if (!optional)
68  node_right_->validate(pset, validatedLabels, false);
69  } else if (!leftExists && rightExists) {
70  node_left_->validate(pset, validatedLabels, false);
71  node_right_->validate(pset, validatedLabels, false);
72  }
73  }
74 
76  std::ostream& os, bool optional, bool& startWithComma, int indentation, bool& wroteSomething) const {
77  node_left_->writeCfi(os, optional, startWithComma, indentation, wroteSomething);
78  node_right_->writeCfi(os, optional, startWithComma, indentation, wroteSomething);
79  }
80 
81  void IfExistsDescription::print_(std::ostream& os, bool optional, bool writeToCfi, DocFormatHelper& dfh) const {
82  if (dfh.pass() == 1) {
83  dfh.indent(os);
84  os << "IfExists pair:";
85 
86  if (dfh.brief()) {
87  if (optional)
88  os << " optional";
89 
90  if (!writeToCfi)
91  os << " (do not write to cfi)";
92 
93  os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
94  }
95  // not brief
96  else {
97  os << "\n";
98  dfh.indent2(os);
99 
100  if (optional)
101  os << "optional";
102  if (!writeToCfi)
103  os << " (do not write to cfi)";
104  if (optional || !writeToCfi) {
105  os << "\n";
106  dfh.indent2(os);
107  }
108 
109  os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
110 
111  if (!comment().empty()) {
113  }
114  os << "\n";
115  }
116  }
117  }
118 
119  void IfExistsDescription::printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const {
120  int indentation = dfh.indentation();
121  if (dfh.parent() != DocFormatHelper::TOP) {
123  }
124 
125  std::stringstream ss;
126  ss << dfh.section() << "." << dfh.counter();
127  std::string newSection = ss.str();
128 
130  os << "Section " << newSection;
131  if (optional)
132  os << " optional";
133  os << " IfExists pair description:\n";
135  if (optional) {
136  os << "If the first parameter exists, then the second is allowed to exist\n";
137  } else {
138  os << "If the first parameter exists, then the second is required to exist\n";
139  }
140  if (!dfh.brief())
141  os << "\n";
142 
143  DocFormatHelper new_dfh(dfh);
144  new_dfh.init();
145  new_dfh.setSection(newSection);
148 
149  node_left_->print(os, false, true, new_dfh);
150  node_right_->print(os, false, true, new_dfh);
151 
152  new_dfh.setPass(1);
153  new_dfh.setCounter(0);
154 
155  node_left_->print(os, false, true, new_dfh);
156  node_right_->print(os, false, true, new_dfh);
157 
158  new_dfh.setPass(2);
159  new_dfh.setCounter(0);
160 
161  node_left_->printNestedContent(os, false, new_dfh);
162  node_right_->printNestedContent(os, false, new_dfh);
163  }
164 
166  bool leftExists = node_left_->exists(pset);
167  bool rightExists = node_right_->exists(pset);
168 
169  if (leftExists && rightExists)
170  return true;
171  else if (!leftExists && !rightExists)
172  return true;
173  return false;
174  }
175 
177 
179 
180  void IfExistsDescription::throwIfDuplicateLabels(std::set<std::string> const& labelsLeft,
181  std::set<std::string> const& labelsRight) const {
182  std::set<std::string> duplicateLabels;
183  std::insert_iterator<std::set<std::string> > insertIter(duplicateLabels, duplicateLabels.begin());
184  std::set_intersection(labelsLeft.begin(), labelsLeft.end(), labelsRight.begin(), labelsRight.end(), insertIter);
185  if (!duplicateLabels.empty()) {
186  std::stringstream ss;
187  for (std::set<std::string>::const_iterator iter = duplicateLabels.begin(), iEnd = duplicateLabels.end();
188  iter != iEnd;
189  ++iter) {
190  ss << " \"" << *iter << "\"\n";
191  }
192  throw edm::Exception(errors::LogicError) << "Labels used in a node of a ParameterSetDescription\n"
193  << "\"ifExists\" expression must be not be the same as labels used\n"
194  << "in other nodes of the expression. The following duplicate\n"
195  << "labels were detected:\n"
196  << ss.str() << "\n";
197  }
198  }
199 
200  void IfExistsDescription::throwIfDuplicateTypes(std::set<ParameterTypes> const& types1,
201  std::set<ParameterTypes> const& types2) const {
202  if (!types1.empty()) {
203  std::set<ParameterTypes> duplicateTypes;
204  std::insert_iterator<std::set<ParameterTypes> > insertIter(duplicateTypes, duplicateTypes.begin());
205  std::set_intersection(types1.begin(), types1.end(), types2.begin(), types2.end(), insertIter);
206  if (!duplicateTypes.empty()) {
207  std::stringstream ss;
208  for (std::set<ParameterTypes>::const_iterator iter = duplicateTypes.begin(), iEnd = duplicateTypes.end();
209  iter != iEnd;
210  ++iter) {
211  ss << " \"" << parameterTypeEnumToString(*iter) << "\"\n";
212  }
214  << "Types used for wildcards in a node of a ParameterSetDescription\n"
215  << "\"ifExists\" expression must be different from types used for other parameters\n"
216  << "in other nodes. The following duplicate types were detected:\n"
217  << ss.str() << "\n";
218  }
219  }
220  }
221 } // namespace edm
edm::DocFormatHelper::TOP
Definition: DocFormatHelper.h:17
edm::DocFormatHelper::init
void init()
Definition: DocFormatHelper.cc:113
edm::DocFormatHelper::setCounter
void setCounter(int value)
Definition: DocFormatHelper.h:67
edm::ParameterDescriptionNode::exists
bool exists(ParameterSet const &pset) const
Definition: ParameterDescriptionNode.h:134
edm::errors::LogicError
Definition: EDMException.h:37
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::DocFormatHelper::setSection
void setSection(std::string const &value)
Definition: DocFormatHelper.h:44
Types.optional
optional
Definition: Types.py:199
edm::IfExistsDescription::exists_
bool exists_(ParameterSet const &pset) const override
Definition: IfExistsDescription.cc:165
IfExistsDescription.h
edm::DocFormatHelper::parent
DescriptionParent parent() const
Definition: DocFormatHelper.h:71
edm::IfExistsDescription::node_left_
edm::value_ptr< ParameterDescriptionNode > node_left_
Definition: IfExistsDescription.h:60
edm::parameterTypeEnumToString
std::string parameterTypeEnumToString(ParameterTypes iType)
Definition: ParameterDescriptionNode.cc:64
EDMException.h
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
edm::IfExistsDescription::throwIfDuplicateTypes
void throwIfDuplicateTypes(std::set< ParameterTypes > const &types1, std::set< ParameterTypes > const &types2) const
Definition: IfExistsDescription.cc:200
edm::DocFormatHelper
Definition: DocFormatHelper.h:15
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
edm::IfExistsDescription::validate_
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const override
Definition: IfExistsDescription.cc:56
edm::IfExistsDescription::howManyXORSubNodesExist_
int howManyXORSubNodesExist_(ParameterSet const &pset) const override
Definition: IfExistsDescription.cc:178
edm::IfExistsDescription::throwIfDuplicateLabels
void throwIfDuplicateLabels(std::set< std::string > const &labelsLeft, std::set< std::string > const &labelsRight) const
Definition: IfExistsDescription.cc:180
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::DocFormatHelper::startColumn2
int startColumn2() const
Definition: DocFormatHelper.h:37
edm::ParameterSet
Definition: ParameterSet.h:47
edm::DocFormatHelper::brief
bool brief() const
Definition: DocFormatHelper.h:34
edm::DocFormatHelper::wrapAndPrintText
static void wrapAndPrintText(std::ostream &os, std::string const &text, size_t indent, size_t suggestedWidth)
Definition: DocFormatHelper.cc:97
edm::IfExistsDescription::partiallyExists_
bool partiallyExists_(ParameterSet const &pset) const override
Definition: IfExistsDescription.cc:176
edm::IfExistsDescription::printNestedContent_
void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh) const override
Definition: IfExistsDescription.cc:119
edm::IfExistsDescription::writeCfi_
void writeCfi_(std::ostream &os, bool optional, bool &startWithComma, int indentation, bool &wroteSomething) const override
Definition: IfExistsDescription.cc:75
edm::DocFormatHelper::setParent
void setParent(DescriptionParent value)
Definition: DocFormatHelper.h:72
edm::DocFormatHelper::setIndentation
void setIndentation(int value)
Definition: DocFormatHelper.h:41
edm::IfExistsDescription::print_
void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh) const override
Definition: IfExistsDescription.cc:81
edm::DocFormatHelper::indent
void indent(std::ostream &os) const
Definition: DocFormatHelper.cc:133
edm::DocFormatHelper::commentWidth
size_t commentWidth() const
Definition: DocFormatHelper.cc:123
edm::IfExistsDescription::node_right_
edm::value_ptr< ParameterDescriptionNode > node_right_
Definition: IfExistsDescription.h:61
edm::DocFormatHelper::indent2
void indent2(std::ostream &os) const
Definition: DocFormatHelper.cc:139
edm::ParameterDescriptionNode::printSpaces
static void printSpaces(std::ostream &os, int n)
Definition: ParameterDescriptionNode.cc:124
edm::DocFormatHelper::counter
int counter() const
Definition: DocFormatHelper.h:66
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
DocFormatHelper.h
edm::DocFormatHelper::offsetSectionContent
static int offsetSectionContent()
Definition: DocFormatHelper.h:83
edm::DocFormatHelper::pass
int pass() const
Definition: DocFormatHelper.h:46
edm::IfExistsDescription::IfExistsDescription
IfExistsDescription(ParameterDescriptionNode const &node_left, ParameterDescriptionNode const &node_right)
Definition: IfExistsDescription.cc:13
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
Exception
Definition: hltDiff.cc:245
printContent_cfi.indentation
indentation
Definition: printContent_cfi.py:10
edm::IfExistsDescription::checkAndGetLabelsAndTypes_
void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const override
Definition: IfExistsDescription.cc:29
edm::DocFormatHelper::setPass
void setPass(int value)
Definition: DocFormatHelper.h:47
edm::ParameterDescriptionNode::comment
std::string const & comment() const
Definition: ParameterDescriptionNode.h:92
edm::DocFormatHelper::section
std::string const & section() const
Definition: DocFormatHelper.h:43
edm::DocFormatHelper::OTHER
Definition: DocFormatHelper.h:17
edm::ParameterDescriptionNode
Definition: ParameterDescriptionNode.h:82
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
edm::DocFormatHelper::indentation
int indentation() const
Definition: DocFormatHelper.h:36