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  int indentation,
116  CfiOptions& options) const {
117  os << "PSetTemplate(";
118  indentation += 2;
119  if (psetDesc_) {
120  psetDesc_->writeCfi(os, false, indentation, options);
121  }
122  os << ")";
123  }
124 
125  // -------------------------------------------------------------------------
126 
129  bool isTracked)
130  : ParameterWildcardBase(k_VPSet, isTracked, criteria), psetDesc_() {
132  }
133 
136  bool isTracked)
137  : ParameterWildcardBase(k_VPSet, isTracked, criteria), psetDesc_() {
139  }
140 
143  bool isTracked,
145  : ParameterWildcardBase(k_VPSet, isTracked, criteria), psetDesc_(new ParameterSetDescription(desc)) {
147  }
148 
151  bool isTracked,
153  : ParameterWildcardBase(k_VPSet, isTracked, criteria), psetDesc_(new ParameterSetDescription(desc)) {
155  }
156 
158 
160  return new ParameterWildcard(*this);
161  }
162 
164  std::set<std::string>& validatedLabels,
165  bool optional) const {
166  std::vector<std::string> parameterNames = pset.getParameterNamesForType<std::vector<ParameterSet> >(isTracked());
167  validateMatchingNames(parameterNames, validatedLabels, optional);
168 
169  if (psetDesc_) {
170  for_all(parameterNames,
171  std::bind(&ParameterWildcard<std::vector<ParameterSet> >::validatePSetVector,
172  this,
173  std::placeholders::_1,
174  std::ref(pset)));
175  }
176  }
177 
178  void ParameterWildcard<std::vector<ParameterSet> >::validatePSetVector(std::string const& parameterName,
179  ParameterSet& pset) const {
180  VParameterSetEntry* vpsetEntry = pset.getPSetVectorForUpdate(parameterName);
181  assert(vpsetEntry);
182  for (unsigned i = 0; i < vpsetEntry->size(); ++i) {
183  psetDesc_->validate(vpsetEntry->psetInVector(i));
184  }
185  }
186 
187  bool ParameterWildcard<std::vector<ParameterSet> >::hasNestedContent_() const {
188  if (psetDesc_)
189  return true;
190  return false;
191  }
192 
193  void ParameterWildcard<std::vector<ParameterSet> >::printNestedContent_(std::ostream& os,
194  bool /*optional*/,
195  DocFormatHelper& dfh) const {
196  int indentation = dfh.indentation();
197  if (dfh.parent() != DocFormatHelper::TOP) {
199  }
200 
201  printSpaces(os, indentation);
202  os << "Section " << dfh.section() << "." << dfh.counter()
203  << " description used to validate all PSets which are in the VPSet matching the wildcard:";
204  os << "\n";
205  if (!dfh.brief())
206  os << "\n";
207 
208  std::stringstream ss;
209  ss << dfh.section() << "." << dfh.counter();
210  std::string newSection = ss.str();
211 
212  DocFormatHelper new_dfh(dfh);
213  new_dfh.setSection(newSection);
216 
217  psetDesc_->print(os, new_dfh);
218  }
219 
221  if (criteria() == RequireZeroOrMore)
222  return true;
223 
224  std::vector<std::string> parameterNames = pset.getParameterNamesForType<std::vector<ParameterSet> >(isTracked());
225 
226  if (criteria() == RequireAtLeastOne)
227  return !parameterNames.empty();
228  return parameterNames.size() == 1U;
229  }
230 } // namespace edm
WildcardValidationCriteria
void throwIfInvalidPattern(char const *pattern) const
ParameterDescriptionNode * clone() const override
assert(be >=bs)
virtual void writeTemplate(std::ostream &os, int indentation, CfiOptions &) const
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)
cfi::CfiOptions CfiOptions
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const override
DescriptionParent parent() const
void setIndentation(int value)