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