CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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>
48  template <typename T>
49  class ParameterDescriptionCases;
50  class DocFormatHelper;
51 
53  public:
55  public:
56  bool optional() const { return optional_; }
57  bool writeToCfi() const { return writeToCfi_; }
59  void setOptional(bool value) { optional_ = value; }
61  ParameterDescriptionNode* setNode(std::unique_ptr<ParameterDescriptionNode> node) {
62  node_ = std::move(node);
63  return node_.operator->();
64  }
65 
66  private:
67  bool optional_;
70  };
71 
72  typedef std::vector<SetDescriptionEntry> SetDescriptionEntries;
73  typedef SetDescriptionEntries::const_iterator const_iterator;
74 
76  virtual ~ParameterSetDescription();
77 
78  std::string const& comment() const { return comment_; }
79  void setComment(std::string const& value);
80  void setComment(char const* value);
81 
83  void setAllowAnything();
84 
85  // This is set only for parameterizables which have not set their descriptions.
86  // This should only be called to allow backwards compatibility.
87  void setUnknown();
88 
89  // ***** In these next 8 functions named "add", T is the parameter type ******
90  // Exceptions: For parameters of type ParameterSet, T should be a
91  // ParameterSetDescription instead of a ParameterSet. And do not
92  // use these next 8 functions for parameters of type vector<ParameterSet>
93 
94  template <typename T, typename U>
95  ParameterDescriptionBase* add(U const& iLabel, T const& value) {
96  return add<T, U>(iLabel, value, true, false, true);
97  }
98 
99  template <typename T, typename U>
100  ParameterDescriptionBase* addUntracked(U const& iLabel, T const& value) {
101  return add<T, U>(iLabel, value, false, false, true);
102  }
103 
104  template <typename T, typename U>
105  ParameterDescriptionBase* addOptional(U const& iLabel, T const& value) {
106  return add<T, U>(iLabel, value, true, true, true);
107  }
108 
109  template <typename T, typename U>
111  return add<T, U>(iLabel, value, false, true, true);
112  }
113 
114  // For the next 4 functions, there is no default so they will not get injected
115  // during validation if missing and they will not get written into cfi files.
116 
117  template <typename T, typename U>
118  ParameterDescriptionBase* add(U const& iLabel) {
119  return add<T, U>(iLabel, true, false, true);
120  }
121 
122  template <typename T, typename U>
124  return add<T, U>(iLabel, false, false, true);
125  }
126 
127  template <typename T, typename U>
129  return add<T, U>(iLabel, true, true, true);
130  }
131 
132  template <typename T, typename U>
134  return add<T, U>(iLabel, false, true, true);
135  }
136 
137  // ***** Use these 8 functions for parameters of type vector<ParameterSet> *****
138  // When a vector<ParameterSet> appears in a configuration, all of its
139  // elements will be validated using the description in the argument named
140  // "validator" below. The argument named "defaults" is used when the
141  // a vector<ParameterSet> is required to be in the configuration and
142  // is absent. Note that these default ParameterSet's will be validated
143  // as if they had appeared in the configuration so they must be consistent
144  // with the description and missing parameters that have defaults in
145  // in the description will be inserted during validation. These defaults
146  // are also used when writing cfi files.
147 
148  template <typename U>
150  ParameterSetDescription const& validator,
151  std::vector<ParameterSet> const& defaults) {
152  return addVPSet<U>(iLabel, validator, defaults, true, false, true);
153  }
154 
155  template <typename U>
157  ParameterSetDescription const& validator,
158  std::vector<ParameterSet> const& defaults) {
159  return addVPSet<U>(iLabel, validator, defaults, false, false, true);
160  }
161 
162  template <typename U>
164  ParameterSetDescription const& validator,
165  std::vector<ParameterSet> const& defaults) {
166  return addVPSet<U>(iLabel, validator, defaults, true, true, true);
167  }
168 
169  template <typename U>
171  ParameterSetDescription const& validator,
172  std::vector<ParameterSet> const& defaults) {
173  return addVPSet<U>(iLabel, validator, defaults, false, true, true);
174  }
175 
176  template <typename U>
177  ParameterDescriptionBase* addVPSet(U const& iLabel, ParameterSetDescription const& validator) {
178  return addVPSet<U>(iLabel, validator, true, false, true);
179  }
180 
181  template <typename U>
183  return addVPSet<U>(iLabel, validator, false, false, true);
184  }
185 
186  template <typename U>
188  return addVPSet<U>(iLabel, validator, true, true, true);
189  }
190 
191  template <typename U>
193  return addVPSet<U>(iLabel, validator, false, true, true);
194  }
195 
196  // ********* Wildcards *********
197 
198  template <typename T, typename U>
199  ParameterWildcardBase* addWildcard(U const& pattern) {
200  return addWildcard<T, U>(pattern, true);
201  }
202 
203  template <typename T, typename U>
205  return addWildcard<T, U>(pattern, false);
206  }
207 
208  // ********* Used to insert generic nodes of any type ************
209 
211  ParameterDescriptionNode* addNode(std::unique_ptr<ParameterDescriptionNode> node);
213  ParameterDescriptionNode* addOptionalNode(std::unique_ptr<ParameterDescriptionNode> node, bool writeToCfi);
214 
215  // ********* Switches ************
216  // ifValue will only work with type T as a bool, int, or string.
217  // T holds the value of the switch variable.
218  // If you try using any other type, then it will not compile.
219  template <typename T>
222  return ifValue<T>(switchParameter, std::move(cases), false, true);
223  }
224 
225  template <typename T>
228  bool writeToCfi) {
229  return ifValue<T>(switchParameter, std::move(cases), true, writeToCfi);
230  }
231 
232  // ********* if exists ************
234  return ifExists(node1, node2, false, true);
235  }
236 
238  ParameterDescriptionNode const& node2,
239  bool writeToCfi) {
240  return ifExists(node1, node2, true, writeToCfi);
241  }
242 
243  // ********* for parameters that are a list of allowed labels *********
244  template <typename T, typename U>
246  return labelsFrom<T, U>(iLabel, true, false, true);
247  }
248 
249  template <typename T, typename U>
251  return labelsFrom<T, U>(iLabel, false, false, true);
252  }
253 
254  template <typename T, typename U>
255  ParameterDescriptionNode* labelsFromOptional(U const& iLabel, bool writeToCfi) {
256  return labelsFrom<T, U>(iLabel, true, true, writeToCfi);
257  }
258 
259  template <typename T, typename U>
260  ParameterDescriptionNode* labelsFromOptionalUntracked(U const& iLabel, bool writeToCfi) {
261  return labelsFrom<T, U>(iLabel, false, true, writeToCfi);
262  }
263 
264  // These next four functions only work when the template
265  // parameters are:
266  // T = ParameterSetDescription and V = ParameterSetDescription
267  // or
268  // T = vector<ParameterSet> and V = ParameterSetDescription
269  // In either case U can be either a string or char*
270  // Note the U and V can be determined from the arguments, but
271  // T must be explicitly specified by the calling function.
272  template <typename T, typename U, typename V>
273  ParameterDescriptionNode* labelsFrom(U const& iLabel, V const& desc) {
274  return labelsFrom<T, U, V>(iLabel, true, false, true, desc);
275  }
276 
277  template <typename T, typename U, typename V>
279  return labelsFrom<T, U, V>(iLabel, false, false, true, desc);
280  }
281 
282  template <typename T, typename U, typename V>
283  ParameterDescriptionNode* labelsFromOptional(U const& iLabel, bool writeToCfi, V const& desc) {
284  return labelsFrom<T, U, V>(iLabel, true, true, writeToCfi, desc);
285  }
286 
287  template <typename T, typename U, typename V>
288  ParameterDescriptionNode* labelsFromOptionalUntracked(U const& iLabel, bool writeToCfi, V const& desc) {
289  return labelsFrom<T, U, V>(iLabel, false, true, writeToCfi, desc);
290  }
291 
292  bool anythingAllowed() const { return anythingAllowed_; }
293  bool isUnknown() const { return unknown_; }
294 
295  const_iterator begin() const { return entries_.begin(); }
296 
297  const_iterator end() const { return entries_.end(); }
298 
299  // Better performance if space is reserved for the number of
300  // top level parameters before any are added.
302 
303  void validate(ParameterSet& pset) const;
304 
305  void writeCfi(std::ostream& os, bool startWithComma, int indentation) const;
306 
307  void print(std::ostream& os, DocFormatHelper& dfh) const;
308 
309  bool isLabelUnused(std::string const& label) const;
310 
311  private:
312  template <typename T, typename U>
313  ParameterDescriptionBase* add(U const& iLabel, T const& value, bool isTracked, bool isOptional, bool writeToCfi);
314 
315  template <typename T, typename U>
316  ParameterDescriptionBase* add(U const& iLabel, bool isTracked, bool isOptional, bool writeToCfi);
317 
318  template <typename U>
319  ParameterDescriptionBase* addVPSet(U const& iLabel,
320  ParameterSetDescription const& validator,
321  std::vector<ParameterSet> const& defaults,
322  bool isTracked,
323  bool isOptional,
324  bool writeToCfi);
325 
326  template <typename U>
328  U const& iLabel, ParameterSetDescription const& validator, bool isTracked, bool isOptional, bool writeToCfi);
329 
330  template <typename T, typename U>
331  ParameterWildcardBase* addWildcard(U const& pattern, bool isTracked);
332 
333  ParameterDescriptionNode* addNode(std::unique_ptr<ParameterDescriptionNode> node, bool optional, bool writeToCfi);
334 
335  template <typename T>
338  bool optional,
339  bool writeToCfi);
340 
342  ParameterDescriptionNode const& node2,
343  bool optional,
344  bool writeToCfi);
345 
346  template <typename T, typename U>
347  ParameterDescriptionNode* labelsFrom(U const& iLabel, bool isTracked, bool optional, bool writeToCfi);
348 
349  template <typename T, typename U, typename V>
350  ParameterDescriptionNode* labelsFrom(U const& iLabel, bool isTracked, bool optional, bool writeToCfi, V const& desc);
351 
352  static void validateNode(SetDescriptionEntry const& entry,
354  std::set<std::string>& validatedNames);
355 
356  static void throwIllegalParameters(std::vector<std::string> const& parameterNames,
357  std::set<std::string> const& validatedNames);
358 
359  static void writeNode(SetDescriptionEntry const& entry,
360  std::ostream& os,
361  bool& startWithComma,
362  int indentation,
363  bool& wroteSomething);
364 
365  static void printNode(SetDescriptionEntry const& entry, std::ostream& os, DocFormatHelper& dfh);
366 
367  void throwIfLabelsAlreadyUsed(std::set<std::string> const& nodeLabels);
368  void throwIfWildcardCollision(std::set<ParameterTypes> const& nodeParameterTypes,
369  std::set<ParameterTypes> const& nodeWildcardTypes);
370 
372  bool unknown_;
374 
375  std::set<std::string> usedLabels_;
376  std::set<ParameterTypes> typesUsedForParameters_;
377  std::set<ParameterTypes> typesUsedForWildcards_;
378 
380  };
381 } // namespace edm
382 
386 
387 namespace edm {
388 
389  template <typename T, typename U>
391  U const& iLabel, T const& value, bool isTracked, bool isOptional, bool writeToCfi) {
392  std::unique_ptr<ParameterDescriptionNode> node =
393  std::make_unique<ParameterDescription<T>>(iLabel, value, isTracked);
394  ParameterDescriptionNode* pnode = addNode(std::move(node), isOptional, writeToCfi);
395  return static_cast<ParameterDescriptionBase*>(pnode);
396  }
397 
398  template <typename T, typename U>
400  bool isTracked,
401  bool isOptional,
402  bool writeToCfi) {
403  std::unique_ptr<ParameterDescriptionNode> node = std::make_unique<ParameterDescription<T>>(iLabel, isTracked);
404  ParameterDescriptionNode* pnode = addNode(std::move(node), isOptional, writeToCfi);
405  return static_cast<ParameterDescriptionBase*>(pnode);
406  }
407 
408  template <typename U>
410  ParameterSetDescription const& validator,
411  std::vector<ParameterSet> const& defaults,
412  bool isTracked,
413  bool isOptional,
414  bool writeToCfi) {
415  std::unique_ptr<ParameterDescriptionNode> node =
416  std::make_unique<ParameterDescription<std::vector<ParameterSet>>>(iLabel, validator, isTracked, defaults);
417  ParameterDescriptionNode* pnode = addNode(std::move(node), isOptional, writeToCfi);
418  return static_cast<ParameterDescriptionBase*>(pnode);
419  }
420 
421  template <typename U>
423  U const& iLabel, ParameterSetDescription const& validator, bool isTracked, bool isOptional, bool writeToCfi) {
424  std::unique_ptr<ParameterDescriptionNode> node =
425  std::make_unique<ParameterDescription<std::vector<ParameterSet>>>(iLabel, validator, isTracked);
426  ParameterDescriptionNode* pnode = addNode(std::move(node), isOptional, writeToCfi);
427  return static_cast<ParameterDescriptionBase*>(pnode);
428  }
429 
430  template <typename T, typename U>
431  ParameterWildcardBase* ParameterSetDescription::addWildcard(U const& pattern, bool isTracked) {
432  std::unique_ptr<ParameterDescriptionNode> node =
433  std::make_unique<ParameterWildcard<T>>(pattern, RequireZeroOrMore, isTracked);
434  ParameterDescriptionNode* pnode = addNode(std::move(node), true, false);
435  return static_cast<ParameterWildcardBase*>(pnode);
436  }
437 
438  template <typename T>
441  bool optional,
442  bool writeToCfi) {
443  std::unique_ptr<ParameterDescriptionNode> pdswitch =
444  std::make_unique<ParameterSwitch<T>>(switchParameter, std::move(cases));
445  return addNode(std::move(pdswitch), optional, writeToCfi);
446  }
447 
448  template <typename T, typename U>
450  bool isTracked,
451  bool optional,
452  bool writeToCfi) {
453  std::unique_ptr<ParameterDescriptionNode> pd = std::make_unique<AllowedLabelsDescription<T>>(iLabel, isTracked);
454  return addNode(std::move(pd), optional, writeToCfi);
455  }
456 
457  template <typename T, typename U, typename V>
459  U const& iLabel, bool isTracked, bool optional, bool writeToCfi, V const& desc) {
460  std::unique_ptr<ParameterDescriptionNode> pd =
461  std::make_unique<AllowedLabelsDescription<T>>(iLabel, desc, isTracked);
462  return addNode(std::move(pd), optional, writeToCfi);
463  }
464 } // namespace edm
465 
466 #endif
ParameterDescriptionNode * labelsFrom(U const &iLabel, V const &desc)
tuple optional
Definition: Types.py:198
ParameterDescriptionNode * ifValue(ParameterDescription< T > const &switchParameter, std::unique_ptr< ParameterDescriptionCases< T >> cases)
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)
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
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)
char const * label
void setComment(std::string const &value)
ParameterDescriptionNode * labelsFromOptionalUntracked(U const &iLabel, bool writeToCfi)
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t V
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)
def move
Definition: eostools.py:511
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 * setNode(std::unique_ptr< ParameterDescriptionNode > node)
ParameterDescriptionNode * ifValueOptional(ParameterDescription< T > const &switchParameter, std::unique_ptr< ParameterDescriptionCases< T >> cases, bool writeToCfi)
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_
list entry
Definition: mps_splice.py:68
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
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_