CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ParameterWildcard.cc
Go to the documentation of this file.
2 
7 
8 #include "boost/bind.hpp"
9 
10 #include <cassert>
11 #include <iomanip>
12 #include <ostream>
13 
14 namespace edm {
15 
18  ParameterWildcardBase(k_PSet, isTracked, criteria),
19  psetDesc_() {
20  throwIfInvalidPattern(pattern);
21  }
22 
24  ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked) :
25  ParameterWildcardBase(k_PSet, isTracked, criteria),
26  psetDesc_() {
27  throwIfInvalidPattern(pattern);
28  }
29 
32  ParameterWildcardBase(k_PSet, isTracked, criteria),
33  psetDesc_(new ParameterSetDescription(desc)) {
34  throwIfInvalidPattern(pattern);
35  }
36 
37 
39  ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked, ParameterSetDescription const& desc) :
40  ParameterWildcardBase(k_PSet, isTracked, criteria),
41  psetDesc_(new ParameterSetDescription(desc)) {
42  throwIfInvalidPattern(pattern);
43  }
44 
45 
48 
51  clone() const {
52  return new ParameterWildcard(*this);
53  }
54 
55  void
58  std::set<std::string>& validatedLabels,
59  bool optional) const {
60 
61  std::vector<std::string> parameterNames = pset.getParameterNamesForType<ParameterSet>(isTracked());
62  validateMatchingNames(parameterNames, validatedLabels, optional);
63 
64  if(psetDesc_) {
65  for_all(parameterNames,
67  boost::cref(this),
68  _1,
69  boost::ref(pset)));
70  }
71  }
72 
73  void
75  validateDescription(std::string const& parameterName,
76  ParameterSet& pset) const {
77  ParameterSet* containedPSet = pset.getPSetForUpdate(parameterName);
78  psetDesc_->validate(*containedPSet);
79  }
80 
81  bool
84  if(psetDesc_) return true;
85  return false;
86  }
87 
88  void
90  printNestedContent_(std::ostream& os,
91  bool /*optional*/,
92  DocFormatHelper& dfh) {
93 
94  int indentation = dfh.indentation();
95  if(dfh.parent() != DocFormatHelper::TOP) {
97  }
98 
99  printSpaces(os, indentation);
100  os << "Section " << dfh.section() << "." << dfh.counter()
101  << " description of PSet matching wildcard:";
102  os << "\n";
103  if(!dfh.brief()) os << "\n";
104 
105  std::stringstream ss;
106  ss << dfh.section() << "." << dfh.counter();
107  std::string newSection = ss.str();
108 
109  DocFormatHelper new_dfh(dfh);
110  new_dfh.setSection(newSection);
111  new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
113 
114  psetDesc_->print(os, new_dfh);
115  }
116 
117  bool
119  exists_(ParameterSet const& pset) const {
120 
121  if(criteria() == RequireZeroOrMore) return true;
122 
123  std::vector<std::string> parameterNames = pset.getParameterNamesForType<ParameterSet>(isTracked());
124 
125  if(criteria() == RequireAtLeastOne) return parameterNames.size() >= 1U;
126  return parameterNames.size() == 1U;
127  }
128 
129 // -------------------------------------------------------------------------
130 
133  ParameterWildcardBase(k_VPSet, isTracked, criteria),
134  psetDesc_() {
135  throwIfInvalidPattern(pattern);
136  }
137 
139  ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked) :
140  ParameterWildcardBase(k_VPSet, isTracked, criteria),
141  psetDesc_() {
142  throwIfInvalidPattern(pattern);
143  }
144 
147  ParameterSetDescription const& desc) :
148  ParameterWildcardBase(k_VPSet, isTracked, criteria),
149  psetDesc_(new ParameterSetDescription(desc)) {
150  throwIfInvalidPattern(pattern);
151  }
152 
153 
155  ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked,
156  ParameterSetDescription const& desc) :
157  ParameterWildcardBase(k_VPSet, isTracked, criteria),
158  psetDesc_(new ParameterSetDescription(desc)) {
159  throwIfInvalidPattern(pattern);
160  }
161 
162 
164  ~ParameterWildcard() { }
165 
168  clone() const {
169  return new ParameterWildcard(*this);
170  }
171 
172  void
174  validate_(ParameterSet& pset,
175  std::set<std::string>& validatedLabels,
176  bool optional) const {
177 
178  std::vector<std::string> parameterNames = pset.getParameterNamesForType<std::vector<ParameterSet> >(isTracked());
179  validateMatchingNames(parameterNames, validatedLabels, optional);
180 
181  if(psetDesc_) {
182  for_all(parameterNames,
183  boost::bind(&ParameterWildcard<std::vector<ParameterSet> >::validatePSetVector,
184  boost::cref(this),
185  _1,
186  boost::ref(pset)));
187  }
188  }
189 
190  void
192  validatePSetVector(std::string const& parameterName, ParameterSet& pset) const {
193  VParameterSetEntry* vpsetEntry = pset.getPSetVectorForUpdate(parameterName);
194  assert(vpsetEntry);
195  for(unsigned i = 0; i < vpsetEntry->size(); ++i) {
196  psetDesc_->validate(vpsetEntry->psetInVector(i));
197  }
198  }
199 
200  bool
202  hasNestedContent_() {
203  if(psetDesc_) return true;
204  return false;
205  }
206 
207  void
209  printNestedContent_(std::ostream& os,
210  bool /*optional*/,
211  DocFormatHelper& dfh) {
212 
213  int indentation = dfh.indentation();
214  if(dfh.parent() != DocFormatHelper::TOP) {
215  indentation -= DocFormatHelper::offsetSectionContent();
216  }
217 
218  printSpaces(os, indentation);
219  os << "Section " << dfh.section() << "." << dfh.counter()
220  << " description used to validate all PSets which are in the VPSet matching the wildcard:";
221  os << "\n";
222  if(!dfh.brief()) os << "\n";
223 
224  std::stringstream ss;
225  ss << dfh.section() << "." << dfh.counter();
226  std::string newSection = ss.str();
227 
228  DocFormatHelper new_dfh(dfh);
229  new_dfh.setSection(newSection);
230  new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
232 
233  psetDesc_->print(os, new_dfh);
234  }
235 
236  bool
238  exists_(ParameterSet const& pset) const {
239 
240  if(criteria() == RequireZeroOrMore) return true;
241 
242  std::vector<std::string> parameterNames = pset.getParameterNamesForType<std::vector<ParameterSet> >(isTracked());
243 
244  if(criteria() == RequireAtLeastOne) return parameterNames.size() >= 1U;
245  return parameterNames.size() == 1U;
246  }
247 }
WildcardValidationCriteria
virtual bool exists_(ParameterSet const &pset) const
int i
Definition: DBlmapReader.cc:9
virtual void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const
virtual void printNestedContent_(std::ostream &, bool, DocFormatHelper &)
virtual ParameterDescriptionNode * clone() const
DescriptionParent parent() const
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:16
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:192
int indentation() const
VParameterSetEntry * getPSetVectorForUpdate(std::string const &name)
static int offsetSectionContent()
static void printSpaces(std::ostream &os, int n)
WildcardValidationCriteria criteria() const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
void throwIfInvalidPattern(char const *pattern) const
std::vector< ParameterSet >::size_type size() const
ParameterWildcard(std::string const &pattern, WildcardValidationCriteria criteria, bool isTracked)
ParameterSet & psetInVector(int i)
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