CMS 3D CMS Logo

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>
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, CfiOptions&) 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  CfiOptions&,
364  bool& wroteSomething);
365 
366  static void printNode(SetDescriptionEntry const& entry, std::ostream& os, DocFormatHelper& dfh);
367 
368  void throwIfLabelsAlreadyUsed(std::set<std::string> const& nodeLabels);
369  void throwIfWildcardCollision(std::set<ParameterTypes> const& nodeParameterTypes,
370  std::set<ParameterTypes> const& nodeWildcardTypes);
371 
373  bool unknown_;
375 
376  std::set<std::string> usedLabels_;
377  std::set<ParameterTypes> typesUsedForParameters_;
378  std::set<ParameterTypes> typesUsedForWildcards_;
379 
381  };
382 } // namespace edm
383 
387 
388 namespace edm {
389 
390  template <typename T, typename U>
392  U const& iLabel, T const& value, bool isTracked, bool isOptional, bool writeToCfi) {
393  std::unique_ptr<ParameterDescriptionNode> node =
394  std::make_unique<ParameterDescription<T>>(iLabel, value, isTracked);
395  ParameterDescriptionNode* pnode = addNode(std::move(node), isOptional, writeToCfi);
396  return static_cast<ParameterDescriptionBase*>(pnode);
397  }
398 
399  template <typename T, typename U>
401  bool isTracked,
402  bool isOptional,
403  bool writeToCfi) {
404  std::unique_ptr<ParameterDescriptionNode> node = std::make_unique<ParameterDescription<T>>(iLabel, isTracked);
405  ParameterDescriptionNode* pnode = addNode(std::move(node), isOptional, writeToCfi);
406  return static_cast<ParameterDescriptionBase*>(pnode);
407  }
408 
409  template <typename U>
411  ParameterSetDescription const& validator,
412  std::vector<ParameterSet> const& defaults,
413  bool isTracked,
414  bool isOptional,
415  bool writeToCfi) {
416  std::unique_ptr<ParameterDescriptionNode> node =
417  std::make_unique<ParameterDescription<std::vector<ParameterSet>>>(iLabel, validator, isTracked, defaults);
418  ParameterDescriptionNode* pnode = addNode(std::move(node), isOptional, writeToCfi);
419  return static_cast<ParameterDescriptionBase*>(pnode);
420  }
421 
422  template <typename U>
424  U const& iLabel, ParameterSetDescription const& validator, bool isTracked, bool isOptional, bool writeToCfi) {
425  std::unique_ptr<ParameterDescriptionNode> node =
426  std::make_unique<ParameterDescription<std::vector<ParameterSet>>>(iLabel, validator, isTracked);
427  ParameterDescriptionNode* pnode = addNode(std::move(node), isOptional, writeToCfi);
428  return static_cast<ParameterDescriptionBase*>(pnode);
429  }
430 
431  template <typename T, typename U>
433  std::unique_ptr<ParameterDescriptionNode> node =
434  std::make_unique<ParameterWildcard<T>>(pattern, RequireZeroOrMore, isTracked);
435  ParameterDescriptionNode* pnode = addNode(std::move(node), true, true);
436  return static_cast<ParameterWildcardBase*>(pnode);
437  }
438 
439  template <typename T>
442  bool optional,
443  bool writeToCfi) {
444  std::unique_ptr<ParameterDescriptionNode> pdswitch =
445  std::make_unique<ParameterSwitch<T>>(switchParameter, std::move(cases));
446  return addNode(std::move(pdswitch), optional, writeToCfi);
447  }
448 
449  template <typename T, typename U>
451  bool isTracked,
452  bool optional,
453  bool writeToCfi) {
454  std::unique_ptr<ParameterDescriptionNode> pd = std::make_unique<AllowedLabelsDescription<T>>(iLabel, isTracked);
455  return addNode(std::move(pd), optional, writeToCfi);
456  }
457 
458  template <typename T, typename U, typename V>
460  U const& iLabel, bool isTracked, bool optional, bool writeToCfi, V const& desc) {
461  std::unique_ptr<ParameterDescriptionNode> pd =
462  std::make_unique<AllowedLabelsDescription<T>>(iLabel, desc, isTracked);
463  return addNode(std::move(pd), optional, writeToCfi);
464  }
465 } // namespace edm
466 
467 #endif
ParameterDescriptionNode * labelsFrom(U const &iLabel, V const &desc)
bool isLabelUnused(std::string const &label) const
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)
void print(std::ostream &os, DocFormatHelper &dfh) const
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)
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
ParameterDescriptionBase * addVPSetOptional(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
std::set< std::string > usedLabels_
edm::value_ptr< ParameterDescriptionNode > const & node() const
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)
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
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)
std::string const & comment() const
void throwIfLabelsAlreadyUsed(std::set< std::string > const &nodeLabels)
ParameterDescriptionNode * labelsFromOptional(U const &iLabel, bool writeToCfi)
ParameterDescriptionNode * addOptionalNode(ParameterDescriptionNode const &node, bool writeToCfi)
optional
Definition: Types.py:245
Definition: value.py:1
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)
void validate(ParameterSet &pset) const
ParameterDescriptionNode * labelsFromOptional(U const &iLabel, bool writeToCfi, V const &desc)
std::set< ParameterTypes > typesUsedForWildcards_
static void writeNode(SetDescriptionEntry const &entry, std::ostream &os, bool &startWithComma, int indentation, CfiOptions &, bool &wroteSomething)
HLT enums.
ParameterDescriptionNode * labelsFrom(U const &iLabel)
ParameterDescriptionBase * add(U const &iLabel)
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel, T const &value)
ParameterDescriptionBase * addUntracked(U const &iLabel)
long double T
ParameterDescriptionBase * addOptional(U const &iLabel)
void writeCfi(std::ostream &os, bool startWithComma, int indentation, CfiOptions &) const
ParameterDescriptionBase * addVPSetUntracked(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
def move(src, dest)
Definition: eostools.py:511
cfi::CfiOptions CfiOptions
edm::value_ptr< ParameterDescriptionNode > node_