CMS 3D CMS Logo

ParameterWildcard.cc
Go to the documentation of this file.
2 
7 
8 #include <cassert>
9 #include <iomanip>
10 #include <ostream>
11 
12 namespace edm {
13 
16  bool isTracked)
17  : ParameterWildcardBase(k_PSet, isTracked, criteria), psetDesc_() {
19  }
20 
23  bool isTracked)
24  : ParameterWildcardBase(k_PSet, isTracked, criteria), psetDesc_() {
26  }
27 
30  bool isTracked,
32  : ParameterWildcardBase(k_PSet, isTracked, criteria), psetDesc_(new ParameterSetDescription(desc)) {
34  }
35 
38  bool isTracked,
40  : ParameterWildcardBase(k_PSet, isTracked, criteria), psetDesc_(new ParameterSetDescription(desc)) {
42  }
43 
45 
47  return new ParameterWildcard(*this);
48  }
49 
51  std::set<std::string>& validatedLabels,
52  bool optional) const {
53  std::vector<std::string> parameterNames = pset.getParameterNamesForType<ParameterSet>(isTracked());
54  validateMatchingNames(parameterNames, validatedLabels, optional);
55 
56  if (psetDesc_) {
57  for_all(parameterNames,
59  this,
60  std::placeholders::_1,
61  std::ref(pset)));
62  }
63  }
64 
66  ParameterSet& pset) const {
67  ParameterSet* containedPSet = pset.getPSetForUpdate(parameterName);
68  psetDesc_->validate(*containedPSet);
69  }
70 
72  if (psetDesc_)
73  return true;
74  return false;
75  }
76 
78  bool /*optional*/,
79  DocFormatHelper& dfh) const {
80  int indentation = dfh.indentation();
81  if (dfh.parent() != DocFormatHelper::TOP) {
83  }
84 
86  os << "Section " << dfh.section() << "." << dfh.counter() << " description of PSet matching wildcard:";
87  os << "\n";
88  if (!dfh.brief())
89  os << "\n";
90 
91  std::stringstream ss;
92  ss << dfh.section() << "." << dfh.counter();
93  std::string newSection = ss.str();
94 
95  DocFormatHelper new_dfh(dfh);
96  new_dfh.setSection(newSection);
99 
100  psetDesc_->print(os, new_dfh);
101  }
102 
104  if (criteria() == RequireZeroOrMore)
105  return true;
106 
107  std::vector<std::string> parameterNames = pset.getParameterNamesForType<ParameterSet>(isTracked());
108 
109  if (criteria() == RequireAtLeastOne)
110  return !parameterNames.empty();
111  return parameterNames.size() == 1U;
112  }
113 
114  // -------------------------------------------------------------------------
115 
118  bool isTracked)
119  : ParameterWildcardBase(k_VPSet, isTracked, criteria), psetDesc_() {
121  }
122 
125  bool isTracked)
126  : ParameterWildcardBase(k_VPSet, isTracked, criteria), psetDesc_() {
128  }
129 
132  bool isTracked,
134  : ParameterWildcardBase(k_VPSet, isTracked, criteria), psetDesc_(new ParameterSetDescription(desc)) {
136  }
137 
140  bool isTracked,
142  : ParameterWildcardBase(k_VPSet, isTracked, criteria), psetDesc_(new ParameterSetDescription(desc)) {
144  }
145 
147 
149  return new ParameterWildcard(*this);
150  }
151 
153  std::set<std::string>& validatedLabels,
154  bool optional) const {
155  std::vector<std::string> parameterNames = pset.getParameterNamesForType<std::vector<ParameterSet> >(isTracked());
156  validateMatchingNames(parameterNames, validatedLabels, optional);
157 
158  if (psetDesc_) {
159  for_all(parameterNames,
160  std::bind(&ParameterWildcard<std::vector<ParameterSet> >::validatePSetVector,
161  this,
162  std::placeholders::_1,
163  std::ref(pset)));
164  }
165  }
166 
167  void ParameterWildcard<std::vector<ParameterSet> >::validatePSetVector(std::string const& parameterName,
168  ParameterSet& pset) const {
169  VParameterSetEntry* vpsetEntry = pset.getPSetVectorForUpdate(parameterName);
170  assert(vpsetEntry);
171  for (unsigned i = 0; i < vpsetEntry->size(); ++i) {
172  psetDesc_->validate(vpsetEntry->psetInVector(i));
173  }
174  }
175 
176  bool ParameterWildcard<std::vector<ParameterSet> >::hasNestedContent_() const {
177  if (psetDesc_)
178  return true;
179  return false;
180  }
181 
182  void ParameterWildcard<std::vector<ParameterSet> >::printNestedContent_(std::ostream& os,
183  bool /*optional*/,
184  DocFormatHelper& dfh) const {
185  int indentation = dfh.indentation();
186  if (dfh.parent() != DocFormatHelper::TOP) {
188  }
189 
190  printSpaces(os, indentation);
191  os << "Section " << dfh.section() << "." << dfh.counter()
192  << " description used to validate all PSets which are in the VPSet matching the wildcard:";
193  os << "\n";
194  if (!dfh.brief())
195  os << "\n";
196 
197  std::stringstream ss;
198  ss << dfh.section() << "." << dfh.counter();
199  std::string newSection = ss.str();
200 
201  DocFormatHelper new_dfh(dfh);
202  new_dfh.setSection(newSection);
205 
206  psetDesc_->print(os, new_dfh);
207  }
208 
210  if (criteria() == RequireZeroOrMore)
211  return true;
212 
213  std::vector<std::string> parameterNames = pset.getParameterNamesForType<std::vector<ParameterSet> >(isTracked());
214 
215  if (criteria() == RequireAtLeastOne)
216  return !parameterNames.empty();
217  return parameterNames.size() == 1U;
218  }
219 } // namespace edm
WildcardValidationCriteria
void throwIfInvalidPattern(char const *pattern) const
ParameterDescriptionNode * clone() const override
assert(be >=bs)
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:14
bool empty() const
Definition: ParameterSet.h:201
static int offsetSectionContent()
optional
Definition: Types.py:239
void validateMatchingNames(std::vector< std::string > const &matchingNames, std::set< std::string > &validatedLabels, bool optional) const
std::string const & section() const
static void printSpaces(std::ostream &os, int n)
WildcardValidationCriteria criteria() const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
HLT enums.
ParameterWildcard(std::string const &pattern, WildcardValidationCriteria criteria, bool isTracked)
ParameterSet & psetInVector(int i)
bool exists_(ParameterSet const &pset) const override
std::vector< ParameterSet >::size_type size() const
virtual void printNestedContent_(std::ostream &, bool, DocFormatHelper &) const
void setSection(std::string const &value)
void setParent(DescriptionParent value)
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const override
DescriptionParent parent() const
void setIndentation(int value)