CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ParameterSetDescription.h
Go to the documentation of this file.
1 #ifndef FWCore_ParameterSet_ParameterSetDescription_h
2 #define FWCore_ParameterSet_ParameterSetDescription_h
3 // -*- C++ -*-
4 //
5 // Package: ParameterSet
6 // Class : ParameterSetDescription
7 //
26 //
27 // Original Author: Chris Jones
28 // Created: Tue Jul 31 15:18:40 EDT 2007
29 //
30 
33 
34 #include <vector>
35 #include <set>
36 #include <string>
37 #include <memory>
38 #include <iosfwd>
39 
40 namespace edm {
41 
42  class ParameterSet;
44  class ParameterWildcardBase;
45  class ParameterDescriptionNode;
46  template <typename T> class ParameterDescription;
47  template <typename T> class ParameterDescriptionCases;
48  class DocFormatHelper;
49 
51  public:
53  public:
54  bool optional() const { return optional_; }
55  bool writeToCfi() const { return writeToCfi_; }
57  void setOptional(bool value) { optional_ = value; }
59  ParameterDescriptionNode* setNode(std::auto_ptr<ParameterDescriptionNode> node) { node_ = node; return node_.operator->(); }
60  private:
61  bool optional_;
64  };
65 
66  typedef std::vector<SetDescriptionEntry> SetDescriptionEntries;
67  typedef SetDescriptionEntries::const_iterator const_iterator;
68 
70  virtual ~ParameterSetDescription();
71 
72  std::string const& comment() const { return comment_; }
73  void setComment(std::string const & value);
74  void setComment(char const* value);
75 
77  void setAllowAnything();
78 
79  // This is set only for parameterizables which have not set their descriptions.
80  // This should only be called to allow backwards compatibility.
81  void setUnknown();
82 
83  // ***** In these next 8 functions named "add", T is the parameter type ******
84  // Exceptions: For parameters of type ParameterSet, T should be a
85  // ParameterSetDescription instead of a ParameterSet. And do not
86  // use these next 8 functions for parameters of type vector<ParameterSet>
87 
88  template<typename T, typename U>
89  ParameterDescriptionBase * add(U const& iLabel, T const& value) {
90  return add<T, U>(iLabel, value, true, false, true);
91  }
92 
93  template<typename T, typename U>
94  ParameterDescriptionBase * addUntracked(U const& iLabel, T const& value) {
95  return add<T, U>(iLabel, value, false, false, true);
96  }
97 
98  template<typename T, typename U>
99  ParameterDescriptionBase * addOptional(U const& iLabel, T const& value) {
100  return add<T, U>(iLabel, value, true, true, true);
101  }
102 
103  template<typename T, typename U>
105  return add<T, U>(iLabel, value, false, true, true);
106  }
107 
108  // For the next 4 functions, there is no default so they will not get injected
109  // during validation if missing and they will not get written into cfi files.
110 
111  template<typename T, typename U>
112  ParameterDescriptionBase * add(U const& iLabel) {
113  return add<T, U>(iLabel, true, false, false);
114  }
115 
116  template<typename T, typename U>
118  return add<T, U>(iLabel, false, false, false);
119  }
120 
121  template<typename T, typename U>
123  return add<T, U>(iLabel, true, true, false);
124  }
125 
126  template<typename T, typename U>
128  return add<T, U>(iLabel, false, true, false);
129  }
130 
131  // ***** Use these 8 functions for parameters of type vector<ParameterSet> *****
132  // When a vector<ParameterSet> appears in a configuration, all of its
133  // elements will be validated using the description in the argument named
134  // "validator" below. The argument named "defaults" is used when the
135  // a vector<ParameterSet> is required to be in the configuration and
136  // is absent. Note that these default ParameterSet's will be validated
137  // as if they had appeared in the configuration so they must be consistent
138  // with the description and missing parameters that have defaults in
139  // in the description will be inserted during validation. These defaults
140  // are also used when writing cfi files.
141 
142  template<typename U>
144  ParameterSetDescription const& validator,
145  std::vector<ParameterSet> const& defaults) {
146  return addVPSet<U>(iLabel, validator, defaults, true, false, true);
147  }
148 
149  template<typename U>
151  ParameterSetDescription const& validator,
152  std::vector<ParameterSet> const& defaults) {
153  return addVPSet<U>(iLabel, validator, defaults, false, false, true);
154  }
155 
156  template<typename U>
158  ParameterSetDescription const& validator,
159  std::vector<ParameterSet> const& defaults) {
160  return addVPSet<U>(iLabel, validator, defaults, true, true, true);
161  }
162 
163  template<typename U>
165  ParameterSetDescription const& validator,
166  std::vector<ParameterSet> const& defaults) {
167  return addVPSet<U>(iLabel, validator, defaults, false, true, true);
168  }
169 
170  template<typename U>
172  ParameterSetDescription const& validator) {
173  return addVPSet<U>(iLabel, validator, true, false, false);
174  }
175 
176  template<typename U>
178  ParameterSetDescription const& validator) {
179  return addVPSet<U>(iLabel, validator, false, false, false);
180  }
181 
182  template<typename U>
184  ParameterSetDescription const& validator) {
185  return addVPSet<U>(iLabel, validator, true, true, false);
186  }
187 
188  template<typename U>
190  ParameterSetDescription const& validator) {
191  return addVPSet<U>(iLabel, validator, false, true, false);
192  }
193 
194  // ********* Wildcards *********
195 
196  template<typename T, typename U>
198  return addWildcard<T, U>(pattern, true);
199  }
200 
201  template<typename T, typename U>
203  return addWildcard<T, U>(pattern, false);
204  }
205 
206  // ********* Used to insert generic nodes of any type ************
207 
209  ParameterDescriptionNode* addNode(std::auto_ptr<ParameterDescriptionNode> node);
211  ParameterDescriptionNode* addOptionalNode(std::auto_ptr<ParameterDescriptionNode> node, bool writeToCfi);
212 
213  // ********* Switches ************
214  // ifValue will only work with type T as a bool, int, or string.
215  // T holds the value of the switch variable.
216  // If you try using any other type, then it will not compile.
217  template <typename T>
219  ifValue(ParameterDescription<T> const& switchParameter,
220  std::auto_ptr<ParameterDescriptionCases<T> > cases) {
221  return ifValue<T>(switchParameter, cases, false, true);
222  }
223 
224  template <typename T>
226  ifValueOptional(ParameterDescription<T> const& switchParameter,
227  std::auto_ptr<ParameterDescriptionCases<T> > cases,
228  bool writeToCfi) {
229  return ifValue<T>(switchParameter, cases, true, writeToCfi);
230  }
231 
232  // ********* if exists ************
235  ParameterDescriptionNode const& node2) {
236  return ifExists(node1, node2, false, true);
237  }
238 
241  ParameterDescriptionNode const& node2,
242  bool writeToCfi) {
243  return ifExists(node1, node2, true, writeToCfi);
244  }
245 
246  // ********* for parameters that are a list of allowed labels *********
247  template<typename T, typename U>
249  labelsFrom(U const& iLabel) {
250  return labelsFrom<T,U>(iLabel, true, false, true);
251  }
252 
253  template<typename T, typename U>
255  labelsFromUntracked(U const& iLabel) {
256  return labelsFrom<T,U>(iLabel, false, false, true);
257  }
258 
259  template<typename T, typename U>
261  labelsFromOptional(U const& iLabel, bool writeToCfi) {
262  return labelsFrom<T,U>(iLabel, true, true, writeToCfi);
263  }
264 
265  template<typename T, typename U>
267  labelsFromOptionalUntracked(U const& iLabel, bool writeToCfi) {
268  return labelsFrom<T,U>(iLabel, false, true, writeToCfi);
269  }
270 
271  // These next four functions only work when the template
272  // parameters are:
273  // T = ParameterSetDescription and V = ParameterSetDescription
274  // or
275  // T = vector<ParameterSet> and V = ParameterSetDescription
276  // In either case U can be either a string or char*
277  // Note the U and V can be determined from the arguments, but
278  // T must be explicitly specified by the calling function.
279  template<typename T, typename U, typename V>
281  labelsFrom(U const& iLabel, V const& desc) {
282  return labelsFrom<T,U,V>(iLabel, true, false, true, desc);
283  }
284 
285  template<typename T, typename U, typename V>
287  labelsFromUntracked(U const& iLabel, V const& desc) {
288  return labelsFrom<T,U,V>(iLabel, false, false, true, desc);
289  }
290 
291  template<typename T, typename U, typename V>
293  labelsFromOptional(U const& iLabel, bool writeToCfi, V const& desc) {
294  return labelsFrom<T,U,V>(iLabel, true, true, writeToCfi, desc);
295  }
296 
297  template<typename T, typename U, typename V>
299  labelsFromOptionalUntracked(U const& iLabel, bool writeToCfi, V const& desc) {
300  return labelsFrom<T,U,V>(iLabel, false, true, writeToCfi, desc);
301  }
302 
303  bool anythingAllowed() const { return anythingAllowed_; }
304  bool isUnknown() const { return unknown_; }
305 
307  return entries_.begin();
308  }
309 
310  const_iterator end() const {
311  return entries_.end();
312  }
313 
314  // Better performance if space is reserved for the number of
315  // top level parameters before any are added.
317  entries_.reserve(n);
318  }
319 
320  void validate(ParameterSet & pset) const;
321 
322  void writeCfi(std::ostream & os, bool startWithComma, int indentation) const;
323 
324  void print(std::ostream & os, DocFormatHelper & dfh) const;
325 
326  bool isLabelUnused(std::string const& label) const;
327 
328  private:
329 
330  template<typename T, typename U>
331  ParameterDescriptionBase * add(U const& iLabel, T const& value,
332  bool isTracked, bool isOptional, bool writeToCfi);
333 
334  template<typename T, typename U>
335  ParameterDescriptionBase * add(U const& iLabel,
336  bool isTracked, bool isOptional, bool writeToCfi);
337 
338  template<typename U>
339  ParameterDescriptionBase * addVPSet(U const& iLabel,
340  ParameterSetDescription const& validator,
341  std::vector<ParameterSet> const& defaults,
342  bool isTracked, bool isOptional, bool writeToCfi);
343 
344  template<typename U>
345  ParameterDescriptionBase * addVPSet(U const& iLabel,
346  ParameterSetDescription const& validator,
347  bool isTracked, bool isOptional, bool writeToCfi);
348 
349  template<typename T, typename U>
350  ParameterWildcardBase * addWildcard(U const& pattern, bool isTracked);
351 
352  ParameterDescriptionNode* addNode(std::auto_ptr<ParameterDescriptionNode> node, bool optional, bool writeToCfi);
353 
354  template <typename T>
356  ifValue(ParameterDescription<T> const& switchParameter,
357  std::auto_ptr<ParameterDescriptionCases<T> > cases,
358  bool optional, bool writeToCfi);
359 
361  ifExists(ParameterDescriptionNode const& node1,
362  ParameterDescriptionNode const& node2,
363  bool optional, bool writeToCfi);
364 
365  template<typename T, typename U>
367  labelsFrom(U const& iLabel, bool isTracked, bool optional, bool writeToCfi);
368 
369  template<typename T, typename U, typename V>
371  labelsFrom(U const& iLabel, bool isTracked, bool optional, bool writeToCfi, V const& desc);
372 
373  static
374  void
375  validateNode(SetDescriptionEntry const& entry,
376  ParameterSet & pset,
377  std::set<std::string> & validatedNames);
378 
379  static void
380  throwIllegalParameters(std::vector<std::string> const& parameterNames,
381  std::set<std::string> const& validatedNames);
382 
383  static void
384  writeNode(SetDescriptionEntry const& entry,
385  std::ostream & os,
386  bool & startWithComma,
387  int indentation,
388  bool & wroteSomething);
389 
390  static void
391  printNode(SetDescriptionEntry const& entry,
392  std::ostream & os,
393  DocFormatHelper & dfh);
394 
395  void throwIfLabelsAlreadyUsed(std::set<std::string> const& nodeLabels);
396  void throwIfWildcardCollision(std::set<ParameterTypes> const& nodeParameterTypes,
397  std::set<ParameterTypes> const& nodeWildcardTypes);
398 
400  bool unknown_;
402 
403  std::set<std::string> usedLabels_;
404  std::set<ParameterTypes> typesUsedForParameters_;
405  std::set<ParameterTypes> typesUsedForWildcards_;
406 
408  };
409 }
410 
414 
415 namespace edm {
416 
417  template<typename T, typename U>
419  ParameterSetDescription::add(U const& iLabel, T const& value, bool isTracked, bool isOptional, bool writeToCfi) {
420 
421  std::auto_ptr<ParameterDescriptionNode> node(new ParameterDescription<T>(iLabel, value, isTracked));
422  ParameterDescriptionNode* pnode = addNode(node, isOptional, writeToCfi);
423  return static_cast<ParameterDescriptionBase*>(pnode);
424  }
425 
426  template<typename T, typename U>
428  ParameterSetDescription::add(U const& iLabel, bool isTracked, bool isOptional, bool writeToCfi) {
429 
430  std::auto_ptr<ParameterDescriptionNode> node(new ParameterDescription<T>(iLabel, isTracked));
431  ParameterDescriptionNode* pnode = addNode(node, isOptional, writeToCfi);
432  return static_cast<ParameterDescriptionBase*>(pnode);
433  }
434 
435  template<typename U>
438  ParameterSetDescription const& validator,
439  std::vector<ParameterSet> const& defaults,
440  bool isTracked, bool isOptional, bool writeToCfi) {
441  std::auto_ptr<ParameterDescriptionNode> node(
442  new ParameterDescription<std::vector<ParameterSet> >(iLabel, validator, isTracked, defaults));
443  ParameterDescriptionNode* pnode = addNode(node, isOptional, writeToCfi);
444  return static_cast<ParameterDescriptionBase*>(pnode);
445  }
446 
447  template<typename U>
450  ParameterSetDescription const& validator,
451  bool isTracked, bool isOptional, bool writeToCfi) {
452  std::auto_ptr<ParameterDescriptionNode> node(
453  new ParameterDescription<std::vector<ParameterSet> >(iLabel, validator, isTracked));
454  ParameterDescriptionNode* pnode = addNode(node, isOptional, writeToCfi);
455  return static_cast<ParameterDescriptionBase*>(pnode);
456  }
457 
458  template<typename T, typename U>
460  ParameterSetDescription::addWildcard(U const& pattern, bool isTracked) {
461 
462  std::auto_ptr<ParameterDescriptionNode> node(new ParameterWildcard<T>(pattern, RequireZeroOrMore, isTracked));
463  ParameterDescriptionNode* pnode = addNode(node, true, false);
464  return static_cast<ParameterWildcardBase*>(pnode);
465  }
466 
467  template <typename T>
470  std::auto_ptr<ParameterDescriptionCases<T> > cases,
471  bool optional, bool writeToCfi) {
472  std::auto_ptr<ParameterDescriptionNode> pdswitch(new ParameterSwitch<T>(switchParameter, cases));
473  return addNode(pdswitch, optional, writeToCfi);
474  }
475 
476  template<typename T, typename U>
478  ParameterSetDescription::labelsFrom(U const& iLabel, bool isTracked, bool optional, bool writeToCfi) {
479  std::auto_ptr<ParameterDescriptionNode> pd(new AllowedLabelsDescription<T>(iLabel, isTracked));
480  return addNode(pd, optional, writeToCfi);
481  }
482 
483  template<typename T, typename U, typename V>
485  ParameterSetDescription::labelsFrom(U const& iLabel, bool isTracked, bool optional, bool writeToCfi, V const& desc) {
486  std::auto_ptr<ParameterDescriptionNode> pd(new AllowedLabelsDescription<T>(iLabel, desc, isTracked));
487  return addNode(pd, optional, writeToCfi);
488  }
489 }
490 
491 #endif
ParameterDescriptionNode * labelsFrom(U const &iLabel, V const &desc)
std::vector< SetDescriptionEntry > SetDescriptionEntries
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
static void throwIllegalParameters(std::vector< std::string > const &parameterNames, std::set< std::string > const &validatedNames)
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
void reserve(SetDescriptionEntries::size_type n)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
edm::value_ptr< ParameterDescriptionNode > const & node() const
ParameterDescriptionNode * labelsFromUntracked(U const &iLabel, V const &desc)
void throwIfWildcardCollision(std::set< ParameterTypes > const &nodeParameterTypes, std::set< ParameterTypes > const &nodeWildcardTypes)
ParameterWildcardBase * addWildcard(U const &pattern)
void setAllowAnything()
allow any parameter label/value pairs
void validate(ParameterSet &pset) const
ParameterDescriptionBase * addVPSetOptional(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
std::set< std::string > usedLabels_
ParameterDescriptionNode * labelsFromOptionalUntracked(U const &iLabel, bool writeToCfi, V const &desc)
ParameterDescriptionNode * labelsFromUntracked(U const &iLabel)
SetDescriptionEntries::const_iterator const_iterator
ParameterDescriptionNode * ifExists(ParameterDescriptionNode const &node1, ParameterDescriptionNode const &node2)
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
static void writeNode(SetDescriptionEntry const &entry, std::ostream &os, bool &startWithComma, int indentation, bool &wroteSomething)
ParameterDescriptionNode * setNode(std::auto_ptr< ParameterDescriptionNode > node)
void writeCfi(std::ostream &os, bool startWithComma, int indentation) const
uint16_t size_type
ParameterWildcardBase * addWildcardUntracked(U const &pattern)
std::set< ParameterTypes > typesUsedForParameters_
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator)
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel)
void setComment(std::string const &value)
ParameterDescriptionNode * labelsFromOptionalUntracked(U const &iLabel, bool writeToCfi)
ParameterDescriptionBase * addVPSetOptionalUntracked(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
void throwIfLabelsAlreadyUsed(std::set< std::string > const &nodeLabels)
ParameterDescriptionNode * labelsFromOptional(U const &iLabel, bool writeToCfi)
void print(std::ostream &os, DocFormatHelper &dfh) const
ParameterDescriptionNode * addOptionalNode(ParameterDescriptionNode const &node, bool writeToCfi)
bool isLabelUnused(std::string const &label) const
ParameterDescriptionBase * add(U const &iLabel, T const &value)
ParameterDescriptionBase * addVPSetOptional(U const &iLabel, ParameterSetDescription const &validator)
static void validateNode(SetDescriptionEntry const &entry, ParameterSet &pset, std::set< std::string > &validatedNames)
static void printNode(SetDescriptionEntry const &entry, std::ostream &os, DocFormatHelper &dfh)
ParameterDescriptionNode * ifExistsOptional(ParameterDescriptionNode const &node1, ParameterDescriptionNode const &node2, bool writeToCfi)
ParameterDescriptionNode * ifValue(ParameterDescription< T > const &switchParameter, std::auto_ptr< ParameterDescriptionCases< T > > cases)
ParameterDescriptionBase * addVPSetOptionalUntracked(U const &iLabel, ParameterSetDescription const &validator)
ParameterDescriptionBase * addVPSetUntracked(U const &iLabel, ParameterSetDescription const &validator)
ParameterDescriptionNode * labelsFromOptional(U const &iLabel, bool writeToCfi, V const &desc)
std::set< ParameterTypes > typesUsedForWildcards_
ParameterDescriptionNode * labelsFrom(U const &iLabel)
ParameterDescriptionBase * add(U const &iLabel)
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel, T const &value)
ParameterDescriptionBase * addUntracked(U const &iLabel)
std::string const & comment() const
ParameterDescriptionNode * ifValueOptional(ParameterDescription< T > const &switchParameter, std::auto_ptr< ParameterDescriptionCases< T > > cases, bool writeToCfi)
long double T
ParameterDescriptionBase * addOptional(U const &iLabel)
ParameterDescriptionBase * addVPSetUntracked(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
edm::value_ptr< ParameterDescriptionNode > node_