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_() {
18  throwIfInvalidPattern(pattern);
19  }
20 
23  bool isTracked)
24  : ParameterWildcardBase(k_PSet, isTracked, criteria), psetDesc_() {
25  throwIfInvalidPattern(pattern);
26  }
27 
30  bool isTracked,
31  ParameterSetDescription const& desc)
32  : ParameterWildcardBase(k_PSet, isTracked, criteria), psetDesc_(new ParameterSetDescription(desc)) {
33  throwIfInvalidPattern(pattern);
34  }
35 
38  bool isTracked,
39  ParameterSetDescription const& desc)
40  : ParameterWildcardBase(k_PSet, isTracked, criteria), psetDesc_(new ParameterSetDescription(desc)) {
41  throwIfInvalidPattern(pattern);
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 
85  printSpaces(os, indentation);
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_() {
120  throwIfInvalidPattern(pattern);
121  }
122 
125  bool isTracked)
126  : ParameterWildcardBase(k_VPSet, isTracked, criteria), psetDesc_() {
127  throwIfInvalidPattern(pattern);
128  }
129 
132  bool isTracked,
133  ParameterSetDescription const& desc)
134  : ParameterWildcardBase(k_VPSet, isTracked, criteria), psetDesc_(new ParameterSetDescription(desc)) {
135  throwIfInvalidPattern(pattern);
136  }
137 
140  bool isTracked,
141  ParameterSetDescription const& desc)
142  : ParameterWildcardBase(k_VPSet, isTracked, criteria), psetDesc_(new ParameterSetDescription(desc)) {
143  throwIfInvalidPattern(pattern);
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 
177  if (psetDesc_)
178  return true;
179  return false;
180  }
181 
183  bool /*optional*/,
184  DocFormatHelper& dfh) const {
185  int indentation = dfh.indentation();
186  if (dfh.parent() != DocFormatHelper::TOP) {
187  indentation -= DocFormatHelper::offsetSectionContent();
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);
203  new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
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
bool empty() const
Definition: ParameterSet.h:191
virtual void printNestedContent_(std::ostream &, bool, DocFormatHelper &) const
DescriptionParent parent() const
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:14
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:169
bool exists_(ParameterSet const &pset) const override
int indentation() const
VParameterSetEntry * getPSetVectorForUpdate(std::string const &name)
static int offsetSectionContent()
static void printSpaces(std::ostream &os, int n)
WildcardValidationCriteria criteria() const
ParameterDescriptionNode * clone() const override
void throwIfInvalidPattern(char const *pattern) const
HLT enums.
ParameterWildcard(std::string const &pattern, WildcardValidationCriteria criteria, bool isTracked)
std::vector< ParameterSet >::size_type size() const
ParameterSet & psetInVector(int i)
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const override
void validateMatchingNames(std::vector< std::string > const &matchingNames, std::set< std::string > &validatedLabels, bool optional) const
void setSection(std::string const &value)
void setParent(DescriptionParent value)
void setIndentation(int value)
ParameterSet * getPSetForUpdate(std::string const &name, bool &isTracked)
std::string const & section() const