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.
6 
7 #include "boost/bind.hpp"
8 
9 #include <cassert>
10 #include <ostream>
11 #include <iomanip>
12 
13 namespace edm {
14 
16  ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked) :
17  ParameterWildcardBase(k_PSet, isTracked, criteria),
18  psetDesc_()
19  {
20  throwIfInvalidPattern(pattern);
21  }
22 
24  ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked) :
25  ParameterWildcardBase(k_PSet, isTracked, criteria),
26  psetDesc_()
27  {
28  throwIfInvalidPattern(pattern);
29  }
30 
32  ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked, ParameterSetDescription const& desc) :
33  ParameterWildcardBase(k_PSet, isTracked, criteria),
34  psetDesc_(new ParameterSetDescription(desc))
35  {
36  throwIfInvalidPattern(pattern);
37  }
38 
39 
41  ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked, ParameterSetDescription const& desc) :
42  ParameterWildcardBase(k_PSet, isTracked, criteria),
43  psetDesc_(new ParameterSetDescription(desc))
44  {
45  throwIfInvalidPattern(pattern);
46  }
47 
48 
51 
54  clone() const {
55  return new ParameterWildcard(*this);
56  }
57 
58  void
61  std::set<std::string> & validatedLabels,
62  bool optional) const {
63 
64  std::vector<std::string> parameterNames = pset.getParameterNamesForType<ParameterSet>(isTracked());
65  validateMatchingNames(parameterNames, validatedLabels, optional);
66 
67  if (psetDesc_) {
68  for_all(parameterNames,
70  boost::cref(this),
71  _1,
72  boost::ref(pset)));
73  }
74  }
75 
76  void
78  validateDescription(std::string const& parameterName,
79  ParameterSet & pset) const {
80  ParameterSet * containedPSet = pset.getPSetForUpdate(parameterName);
81  psetDesc_->validate(*containedPSet);
82  }
83 
84  bool
87  if (psetDesc_) return true;
88  return false;
89  }
90 
91  void
93  printNestedContent_(std::ostream & os,
94  bool optional,
95  DocFormatHelper & dfh) {
96 
97  int indentation = dfh.indentation();
98  if (dfh.parent() != DocFormatHelper::TOP) {
100  }
101 
102  printSpaces(os, indentation);
103  os << "Section " << dfh.section() << "." << dfh.counter()
104  << " description of PSet matching wildcard:";
105  os << "\n";
106  if (!dfh.brief()) os << "\n";
107 
108  std::stringstream ss;
109  ss << dfh.section() << "." << dfh.counter();
110  std::string newSection = ss.str();
111 
112  DocFormatHelper new_dfh(dfh);
113  new_dfh.setSection(newSection);
114  new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
116 
117  psetDesc_->print(os, new_dfh);
118  }
119 
120  bool
122  exists_(ParameterSet const& pset) const {
123 
124  if (criteria() == RequireZeroOrMore) return true;
125 
126  std::vector<std::string> parameterNames = pset.getParameterNamesForType<ParameterSet>(isTracked());
127 
128  if (criteria() == RequireAtLeastOne) return parameterNames.size() >= 1U;
129  return parameterNames.size() == 1U;
130  }
131 
132 // -------------------------------------------------------------------------
133 
135  ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked) :
136  ParameterWildcardBase(k_VPSet, isTracked, criteria),
137  psetDesc_()
138  {
139  throwIfInvalidPattern(pattern);
140  }
141 
143  ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked) :
144  ParameterWildcardBase(k_VPSet, isTracked, criteria),
145  psetDesc_()
146  {
147  throwIfInvalidPattern(pattern);
148  }
149 
151  ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked,
152  ParameterSetDescription const& desc) :
153  ParameterWildcardBase(k_VPSet, isTracked, criteria),
154  psetDesc_(new ParameterSetDescription(desc))
155  {
156  throwIfInvalidPattern(pattern);
157  }
158 
159 
161  ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked,
162  ParameterSetDescription const& desc) :
163  ParameterWildcardBase(k_VPSet, isTracked, criteria),
164  psetDesc_(new ParameterSetDescription(desc))
165  {
166  throwIfInvalidPattern(pattern);
167  }
168 
169 
171  ~ParameterWildcard() { }
172 
175  clone() const {
176  return new ParameterWildcard(*this);
177  }
178 
179  void
181  validate_(ParameterSet & pset,
182  std::set<std::string> & validatedLabels,
183  bool optional) const {
184 
185  std::vector<std::string> parameterNames = pset.getParameterNamesForType<std::vector<ParameterSet> >(isTracked());
186  validateMatchingNames(parameterNames, validatedLabels, optional);
187 
188  if (psetDesc_) {
189  for_all(parameterNames,
190  boost::bind(&ParameterWildcard<std::vector<ParameterSet> >::validatePSetVector,
191  boost::cref(this),
192  _1,
193  boost::ref(pset)));
194  }
195  }
196 
197  void
199  validatePSetVector(std::string const& parameterName, ParameterSet & pset) const {
200  VParameterSetEntry * vpsetEntry = pset.getPSetVectorForUpdate(parameterName);
201  assert(vpsetEntry);
202  for (unsigned i = 0; i < vpsetEntry->size(); ++i) {
203  psetDesc_->validate(vpsetEntry->psetInVector(i));
204  }
205  }
206 
207  bool
209  hasNestedContent_() {
210  if (psetDesc_) return true;
211  return false;
212  }
213 
214  void
216  printNestedContent_(std::ostream & os,
217  bool optional,
218  DocFormatHelper & dfh) {
219 
220  int indentation = dfh.indentation();
221  if (dfh.parent() != DocFormatHelper::TOP) {
222  indentation -= DocFormatHelper::offsetSectionContent();
223  }
224 
225  printSpaces(os, indentation);
226  os << "Section " << dfh.section() << "." << dfh.counter()
227  << " description used to validate all PSets which are in the VPSet matching the wildcard:";
228  os << "\n";
229  if (!dfh.brief()) os << "\n";
230 
231  std::stringstream ss;
232  ss << dfh.section() << "." << dfh.counter();
233  std::string newSection = ss.str();
234 
235  DocFormatHelper new_dfh(dfh);
236  new_dfh.setSection(newSection);
237  new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
239 
240  psetDesc_->print(os, new_dfh);
241  }
242 
243  bool
245  exists_(ParameterSet const& pset) const {
246 
247  if (criteria() == RequireZeroOrMore) return true;
248 
249  std::vector<std::string> parameterNames = pset.getParameterNamesForType<std::vector<ParameterSet> >(isTracked());
250 
251  if (criteria() == RequireAtLeastOne) return parameterNames.size() >= 1U;
252  return parameterNames.size() == 1U;
253  }
254 }
WildcardValidationCriteria
virtual bool exists_(ParameterSet const &pset) const
int i
Definition: DBlmapReader.cc:9
virtual void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh)
virtual void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const
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:188
int indentation() const
VParameterSetEntry * getPSetVectorForUpdate(std::string const &name)
static int offsetSectionContent()
tuple pset
Definition: CrabTask.py:85
static void printSpaces(std::ostream &os, int n)
WildcardValidationCriteria criteria() const
T * clone(const T *tp)
Definition: Ptr.h:42
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