CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ParameterDescription.h
Go to the documentation of this file.
1 #ifndef FWCore_ParameterSet_ParameterDescription_h
2 #define FWCore_ParameterSet_ParameterDescription_h
3 // -*- C++ -*-
4 //
5 // Package: ParameterSet
6 // Class : ParameterDescription
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Thu Aug 2 15:33:51 EDT 2007
19 //
20 
25 
26 #include <string>
27 #include <vector>
28 #include <iosfwd>
29 #include <set>
30 
31 namespace edm {
32 
34 
35  class EventID;
36  class LuminosityBlockID;
38  class EventRange;
39  class InputTag;
40  class ESInputTag;
41  class FileInPath;
42  class DocFormatHelper;
43 
44  namespace writeParameterValue {
45 
46  enum ValueFormat { CFI, DOC };
47 
48  void writeValue(std::ostream& os, int indentation, int const& value_, ValueFormat format);
49  void writeValue(std::ostream& os, int indentation, std::vector<int> const& value_, ValueFormat format);
50  void writeValue(std::ostream& os, int indentation, unsigned const& value_, ValueFormat format);
51  void writeValue(std::ostream& os, int indentation, std::vector<unsigned> const& value_, ValueFormat format);
52  void writeValue(std::ostream& os, int indentation, long long const& value_, ValueFormat format);
53  void writeValue(std::ostream& os, int indentation, std::vector<long long> const& value_, ValueFormat format);
54  void writeValue(std::ostream& os, int indentation, unsigned long long const& value_, ValueFormat format);
55  void writeValue(std::ostream& os,
56  int indentation,
57  std::vector<unsigned long long> const& value_,
59  void writeValue(std::ostream& os, int indentation, double const& value_, ValueFormat format);
60  void writeValue(std::ostream& os, int indentation, std::vector<double> const& value_, ValueFormat format);
61  void writeValue(std::ostream& os, int indentation, bool const& value_, ValueFormat format);
62  void writeValue(std::ostream& os, int indentation, std::string const& value_, ValueFormat format);
63  void writeValue(std::ostream& os, int indentation, std::vector<std::string> const& value_, ValueFormat format);
64  void writeValue(std::ostream& os, int indentation, EventID const& value_, ValueFormat format);
65  void writeValue(std::ostream& os, int indentation, std::vector<EventID> const& value_, ValueFormat format);
66  void writeValue(std::ostream& os, int indentation, LuminosityBlockID const& value_, ValueFormat format);
67  void writeValue(std::ostream& os, int indentation, std::vector<LuminosityBlockID> const& value_, ValueFormat format);
68  void writeValue(std::ostream& os, int indentation, LuminosityBlockRange const& value_, ValueFormat format);
69  void writeValue(std::ostream& os,
70  int indentation,
71  std::vector<LuminosityBlockRange> const& value_,
73  void writeValue(std::ostream& os, int indentation, EventRange const& value_, ValueFormat format);
74  void writeValue(std::ostream& os, int indentation, std::vector<EventRange> const& value_, ValueFormat format);
75  void writeValue(std::ostream& os, int indentation, InputTag const& value_, ValueFormat format);
76  void writeValue(std::ostream& os, int indentation, std::vector<InputTag> const& value_, ValueFormat format);
77  void writeValue(std::ostream& os, int indentation, ESInputTag const& value_, ValueFormat format);
78  void writeValue(std::ostream& os, int indentation, std::vector<ESInputTag> const& value_, ValueFormat format);
79  void writeValue(std::ostream& os, int indentation, FileInPath const& value_, ValueFormat format);
80 
81  bool hasNestedContent(int const& value);
82  bool hasNestedContent(std::vector<int> const& value);
83  bool hasNestedContent(unsigned const& value);
84  bool hasNestedContent(std::vector<unsigned> const& value);
85  bool hasNestedContent(long long const& value);
86  bool hasNestedContent(std::vector<long long> const& value);
87  bool hasNestedContent(unsigned long long const& value);
88  bool hasNestedContent(std::vector<unsigned long long> const& value);
89  bool hasNestedContent(double const& value);
90  bool hasNestedContent(std::vector<double> const& value);
91  bool hasNestedContent(bool const& value);
92  bool hasNestedContent(std::string const& value);
93  bool hasNestedContent(std::vector<std::string> const& value);
94  bool hasNestedContent(EventID const& value);
95  bool hasNestedContent(std::vector<EventID> const& value);
97  bool hasNestedContent(std::vector<LuminosityBlockID> const& value);
99  bool hasNestedContent(std::vector<LuminosityBlockRange> const& value);
100  bool hasNestedContent(EventRange const& value);
101  bool hasNestedContent(std::vector<EventRange> const& value);
102  bool hasNestedContent(InputTag const& value);
103  bool hasNestedContent(std::vector<InputTag> const& value);
104  bool hasNestedContent(ESInputTag const& value);
105  bool hasNestedContent(std::vector<ESInputTag> const& value);
106  bool hasNestedContent(FileInPath const& value);
107  } // namespace writeParameterValue
108 
109  template <typename T>
111  public:
112  ParameterDescription(std::string const& iLabel, T const& value, bool isTracked, Comment const& iComment = Comment())
113  : // WARNING: the toEnum function is intentionally undefined if the template
114  // parameter is ParameterSet or vector<ParameterSet>. Both of these cases
115  // are handled by full template specializations below. In the first case.
116  // ParameterSetDescription should be used instead of ParameterSet.
117  // In the second case the function arguments are completely different.
118  // Note that this template parameter is most often passed through from
119  // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
120  // use the addVPSet* versions of those functions.
121  ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, true, iComment),
122  value_(value) {}
123 
124  ParameterDescription(char const* iLabel, T const& value, bool isTracked, Comment const& iComment = Comment())
125  : // WARNING: the toEnum function is intentionally undefined if the template
126  // parameter is ParameterSet or vector<ParameterSet>. Both of these cases
127  // are handled by full template specializations below. In the first case.
128  // ParameterSetDescription should be used instead of ParameterSet.
129  // In the second case the function arguments are completely different.
130  // Note that this template parameter is most often passed through from
131  // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
132  // use the addVPSet* versions of those functions.
133  ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, true, iComment),
134  value_(value) {}
135 
136  ParameterDescription(std::string const& iLabel, bool isTracked, Comment const& iComment = Comment())
137  : // WARNING: the toEnum function is intentionally undefined if the template
138  // parameter is ParameterSet or vector<ParameterSet>. Both of these cases
139  // are handled by full template specializations below. In the first case.
140  // ParameterSetDescription should be used instead of ParameterSet.
141  // In the second case the function arguments are completely different.
142  // Note that this template parameter is most often passed through from
143  // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
144  // use the addVPSet* versions of those functions.
145  ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, false, iComment),
146  value_() {}
147 
148  ParameterDescription(char const* iLabel, bool isTracked, Comment const& iComment = Comment())
149  : // WARNING: the toEnum function is intentionally undefined if the template
150  // parameter is ParameterSet or vector<ParameterSet>. Both of these cases
151  // are handled by full template specializations below. In the first case.
152  // ParameterSetDescription should be used instead of ParameterSet.
153  // In the second case the function arguments are completely different.
154  // Note that this template parameter is most often passed through from
155  // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
156  // use the addVPSet* versions of those functions.
157  ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, false, iComment),
158  value_() {}
159 
160  ~ParameterDescription() override {}
161 
162  ParameterDescriptionNode* clone() const override { return new ParameterDescription(*this); }
163 
164  T getDefaultValue() const { return value_; }
165 
166  private:
167  bool exists_(ParameterSet const& pset) const override { return pset.existsAs<T>(label(), isTracked()); }
168 
169  bool hasNestedContent_() const override {
170  if (!hasDefault())
171  return false;
173  }
174 
175  void writeCfi_(std::ostream& os, int indentation) const override {
177  }
178 
179  void writeDoc_(std::ostream& os, int indentation) const override {
181  }
182 
183  bool exists_(ParameterSet const& pset, bool isTracked) const override {
184  return pset.existsAs<T>(label(), isTracked);
185  }
186 
187  void insertDefault_(ParameterSet& pset) const override {
188  if (isTracked()) {
189  pset.addParameter(label(), value_);
190  } else {
192  }
193  }
194 
196  };
197 
198  template <>
200  public:
201  ParameterDescription(std::string const& iLabel,
202  ParameterSetDescription const& value,
203  bool isTracked,
204  Comment const& iComment = Comment());
205 
206  ParameterDescription(char const* iLabel,
207  ParameterSetDescription const& value,
208  bool isTracked,
209  Comment const& iComment = Comment());
210 
211  ~ParameterDescription() override;
212 
213  ParameterSetDescription const* parameterSetDescription() const override;
215 
216  ParameterDescriptionNode* clone() const override { return new ParameterDescription(*this); }
217 
218  private:
219  void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const override;
220 
221  void printDefault_(std::ostream& os, bool writeToCfi, DocFormatHelper& dfh) const override;
222 
223  bool hasNestedContent_() const override;
224 
225  void printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const override;
226 
227  bool exists_(ParameterSet const& pset) const override;
228 
229  void writeCfi_(std::ostream& os, int indentation) const override;
230 
231  void writeDoc_(std::ostream& os, int indentation) const override;
232 
233  bool exists_(ParameterSet const& pset, bool isTracked) const override;
234 
235  void insertDefault_(ParameterSet& pset) const override;
236 
238  };
239 
240  template <>
241  class ParameterDescription<std::vector<ParameterSet> > : public ParameterDescriptionBase {
242  public:
243  ParameterDescription(std::string const& iLabel,
244  ParameterSetDescription const& psetDesc,
245  bool isTracked,
246  std::vector<ParameterSet> const& vPset,
247  Comment const& iComment = Comment());
248 
249  ParameterDescription(char const* iLabel,
250  ParameterSetDescription const& psetDesc,
251  bool isTracked,
252  std::vector<ParameterSet> const& vPset,
253  Comment const& iComment = Comment());
254 
255  ParameterDescription(std::string const& iLabel,
256  ParameterSetDescription const& psetDesc,
257  bool isTracked,
258  Comment const& iComment = Comment());
259 
260  ParameterDescription(char const* iLabel,
261  ParameterSetDescription const& psetDesc,
262  bool isTracked,
263  Comment const& iComment = Comment());
264 
265  ~ParameterDescription() override;
266 
267  ParameterSetDescription const* parameterSetDescription() const override;
269 
270  ParameterDescriptionNode* clone() const override { return new ParameterDescription(*this); }
271 
272  void setPartOfDefaultOfVPSet(bool value) { partOfDefaultOfVPSet_ = value; }
273 
274  private:
275  void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const override;
276 
277  void printDefault_(std::ostream& os, bool writeToCfi, DocFormatHelper& dfh) const override;
278 
279  bool hasNestedContent_() const override;
280 
281  void printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const override;
282 
283  bool exists_(ParameterSet const& pset) const override;
284 
285  void writeCfi_(std::ostream& os, int indentation) const override;
286 
287  void writeDoc_(std::ostream& os, int indentation) const override;
288 
289  bool exists_(ParameterSet const& pset, bool isTracked) const override;
290 
291  void insertDefault_(ParameterSet& pset) const override;
292 
293  static void writeOneElementToCfi(ParameterSet const& pset,
294  std::ostream& os,
295  int indentation,
296  bool& nextOneStartsWithAComma);
297 
299  std::vector<ParameterSet> vPset_;
301  };
302 } // namespace edm
303 #endif
tuple optional
Definition: Types.py:198
ParameterDescriptionNode * clone() const override
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
bool exists_(ParameterSet const &pset, bool isTracked) const override
ParameterDescriptionNode * clone() const override
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const override
virtual void printDefault_(std::ostream &os, bool writeToCfi, DocFormatHelper &dfh) const
void writeCfi_(std::ostream &os, int indentation) const override
bool exists_(ParameterSet const &pset) const override
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
bool hasNestedContent_() const override
ParameterDescriptionNode * clone() const override
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:192
virtual ParameterSetDescription const * parameterSetDescription() const
void writeValue(std::ostream &os, int indentation, int const &value_, ValueFormat format)
ParameterDescriptionBase(std::string const &iLabel, ParameterTypes iType, bool isTracked, bool hasDefault, Comment const &iComment)
void writeDoc_(std::ostream &os, int indentation) const override
bool hasNestedContent(int const &value)
long double T
void insertDefault_(ParameterSet &pset) const override
void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh) const override
std::string const & label() const