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 
115  os << "PSetTemplate(";
116  indentation += 2;
117  if (psetDesc_) {
118  psetDesc_->writeCfi(os, false, indentation);
119  }
120  os << ")";
121  }
122 
123  // -------------------------------------------------------------------------
124 
127  bool isTracked)
128  : ParameterWildcardBase(k_VPSet, isTracked, criteria), psetDesc_() {
130  }
131 
134  bool isTracked)
135  : ParameterWildcardBase(k_VPSet, isTracked, criteria), psetDesc_() {
137  }
138 
141  bool isTracked,
143  : ParameterWildcardBase(k_VPSet, isTracked, criteria), psetDesc_(new ParameterSetDescription(desc)) {
145  }
146 
149  bool isTracked,
151  : ParameterWildcardBase(k_VPSet, isTracked, criteria), psetDesc_(new ParameterSetDescription(desc)) {
153  }
154 
156 
158  return new ParameterWildcard(*this);
159  }
160 
162  std::set<std::string>& validatedLabels,
163  bool optional) const {
164  std::vector<std::string> parameterNames = pset.getParameterNamesForType<std::vector<ParameterSet> >(isTracked());
165  validateMatchingNames(parameterNames, validatedLabels, optional);
166 
167  if (psetDesc_) {
168  for_all(parameterNames,
169  std::bind(&ParameterWildcard<std::vector<ParameterSet> >::validatePSetVector,
170  this,
171  std::placeholders::_1,
172  std::ref(pset)));
173  }
174  }
175 
176  void ParameterWildcard<std::vector<ParameterSet> >::validatePSetVector(std::string const& parameterName,
177  ParameterSet& pset) const {
178  VParameterSetEntry* vpsetEntry = pset.getPSetVectorForUpdate(parameterName);
179  assert(vpsetEntry);
180  for (unsigned i = 0; i < vpsetEntry->size(); ++i) {
181  psetDesc_->validate(vpsetEntry->psetInVector(i));
182  }
183  }
184 
185  bool ParameterWildcard<std::vector<ParameterSet> >::hasNestedContent_() const {
186  if (psetDesc_)
187  return true;
188  return false;
189  }
190 
191  void ParameterWildcard<std::vector<ParameterSet> >::printNestedContent_(std::ostream& os,
192  bool /*optional*/,
193  DocFormatHelper& dfh) const {
194  int indentation = dfh.indentation();
195  if (dfh.parent() != DocFormatHelper::TOP) {
197  }
198 
199  printSpaces(os, indentation);
200  os << "Section " << dfh.section() << "." << dfh.counter()
201  << " description used to validate all PSets which are in the VPSet matching the wildcard:";
202  os << "\n";
203  if (!dfh.brief())
204  os << "\n";
205 
206  std::stringstream ss;
207  ss << dfh.section() << "." << dfh.counter();
208  std::string newSection = ss.str();
209 
210  DocFormatHelper new_dfh(dfh);
211  new_dfh.setSection(newSection);
214 
215  psetDesc_->print(os, new_dfh);
216  }
217 
219  if (criteria() == RequireZeroOrMore)
220  return true;
221 
222  std::vector<std::string> parameterNames = pset.getParameterNamesForType<std::vector<ParameterSet> >(isTracked());
223 
224  if (criteria() == RequireAtLeastOne)
225  return !parameterNames.empty();
226  return parameterNames.size() == 1U;
227  }
228 } // namespace edm
WildcardValidationCriteria
void throwIfInvalidPattern(char const *pattern) const
virtual void writeTemplate(std::ostream &os, int indentation) 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:202
static int offsetSectionContent()
optional
Definition: Types.py:245
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)