CMS 3D CMS Logo

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 FileInPath;
41  class DocFormatHelper;
42 
43  namespace writeParameterValue {
44 
45  enum ValueFormat { CFI, DOC };
46 
47  void writeValue(std::ostream& os, int indentation, int const& value_, ValueFormat format);
48  void writeValue(std::ostream& os, int indentation, std::vector<int> const& value_, ValueFormat format);
49  void writeValue(std::ostream& os, int indentation, unsigned const& value_, ValueFormat format);
50  void writeValue(std::ostream& os, int indentation, std::vector<unsigned> const& value_, ValueFormat format);
51  void writeValue(std::ostream& os, int indentation, long long const& value_, ValueFormat format);
52  void writeValue(std::ostream& os, int indentation, std::vector<long long> const& value_, ValueFormat format);
53  void writeValue(std::ostream& os, int indentation, unsigned long long const& value_, ValueFormat format);
54  void writeValue(std::ostream& os, int indentation, std::vector<unsigned long long> const& value_, ValueFormat format);
55  void writeValue(std::ostream& os, int indentation, double const& value_, ValueFormat format);
56  void writeValue(std::ostream& os, int indentation, std::vector<double> const& value_, ValueFormat format);
57  void writeValue(std::ostream& os, int indentation, bool const& value_, ValueFormat format);
58  void writeValue(std::ostream& os, int indentation, std::string const& value_, ValueFormat format);
59  void writeValue(std::ostream& os, int indentation, std::vector<std::string> const& value_, ValueFormat format);
60  void writeValue(std::ostream& os, int indentation, EventID const& value_, ValueFormat format);
61  void writeValue(std::ostream& os, int indentation, std::vector<EventID> const& value_, ValueFormat format);
62  void writeValue(std::ostream& os, int indentation, LuminosityBlockID const& value_, ValueFormat format);
63  void writeValue(std::ostream& os, int indentation, std::vector<LuminosityBlockID> const& value_, ValueFormat format);
64  void writeValue(std::ostream& os, int indentation, LuminosityBlockRange const& value_, ValueFormat format);
65  void writeValue(std::ostream& os, int indentation, std::vector<LuminosityBlockRange> const& value_, ValueFormat format);
66  void writeValue(std::ostream& os, int indentation, EventRange const& value_, ValueFormat format);
67  void writeValue(std::ostream& os, int indentation, std::vector<EventRange> const& value_, ValueFormat format);
68  void writeValue(std::ostream& os, int indentation, InputTag const& value_, ValueFormat format);
69  void writeValue(std::ostream& os, int indentation, std::vector<InputTag> const& value_, ValueFormat format);
70  void writeValue(std::ostream& os, int indentation, FileInPath const& value_, ValueFormat format);
71 
72  bool hasNestedContent(int const& value);
73  bool hasNestedContent(std::vector<int> const& value);
74  bool hasNestedContent(unsigned const& value);
75  bool hasNestedContent(std::vector<unsigned> const& value);
76  bool hasNestedContent(long long const& value);
77  bool hasNestedContent(std::vector<long long> const& value);
78  bool hasNestedContent(unsigned long long const& value);
79  bool hasNestedContent(std::vector<unsigned long long> const& value);
80  bool hasNestedContent(double const& value);
81  bool hasNestedContent(std::vector<double> const& value);
82  bool hasNestedContent(bool const& value);
83  bool hasNestedContent(std::string const& value);
84  bool hasNestedContent(std::vector<std::string> const& value);
85  bool hasNestedContent(EventID const& value);
86  bool hasNestedContent(std::vector<EventID> const& value);
87  bool hasNestedContent(LuminosityBlockID const& value);
88  bool hasNestedContent(std::vector<LuminosityBlockID> const& value);
89  bool hasNestedContent(LuminosityBlockRange const& value);
90  bool hasNestedContent(std::vector<LuminosityBlockRange> const& value);
91  bool hasNestedContent(EventRange const& value);
92  bool hasNestedContent(std::vector<EventRange> const& value);
93  bool hasNestedContent(InputTag const& value);
94  bool hasNestedContent(std::vector<InputTag> const& value);
95  bool hasNestedContent(FileInPath const& value);
96  }
97 
98  template<typename T>
100  public:
101 
103  T const& value,
104  bool isTracked,
105  Comment const& iComment = Comment()) :
106  // WARNING: the toEnum function is intentionally undefined if the template
107  // parameter is ParameterSet or vector<ParameterSet>. Both of these cases
108  // are handled by full template specializations below. In the first case.
109  // ParameterSetDescription should be used instead of ParameterSet.
110  // In the second case the function arguments are completely different.
111  // Note that this template parameter is most often passed through from
112  // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
113  // use the addVPSet* versions of those functions.
114  ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, true, iComment),
115  value_(value) {
116  }
117 
118  ParameterDescription(char const* iLabel,
119  T const& value,
120  bool isTracked,
121  Comment const& iComment = Comment()) :
122  // WARNING: the toEnum function is intentionally undefined if the template
123  // parameter is ParameterSet or vector<ParameterSet>. Both of these cases
124  // are handled by full template specializations below. In the first case.
125  // ParameterSetDescription should be used instead of ParameterSet.
126  // In the second case the function arguments are completely different.
127  // Note that this template parameter is most often passed through from
128  // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
129  // use the addVPSet* versions of those functions.
130  ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, true, iComment),
131  value_(value) {
132  }
133 
135  bool isTracked,
136  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 
149  ParameterDescription(char const* iLabel,
150  bool isTracked,
151  Comment const& iComment = Comment()) :
152  // WARNING: the toEnum function is intentionally undefined if the template
153  // parameter is ParameterSet or vector<ParameterSet>. Both of these cases
154  // are handled by full template specializations below. In the first case.
155  // ParameterSetDescription should be used instead of ParameterSet.
156  // In the second case the function arguments are completely different.
157  // Note that this template parameter is most often passed through from
158  // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
159  // use the addVPSet* versions of those functions.
160  ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, false, iComment),
161  value_() {
162  }
163 
164  ~ParameterDescription() override { }
165 
166  ParameterDescriptionNode* clone() const override {
167  return new ParameterDescription(*this);
168  }
169 
170  T getDefaultValue() const { return value_; }
171 
172  private:
173 
174  bool exists_(ParameterSet const& pset) const override {
175  return pset.existsAs<T>(label(), isTracked());
176  }
177 
178  bool hasNestedContent_() const override {
179  if (!hasDefault()) return false;
181  }
182 
183  void writeCfi_(std::ostream& os, int indentation) const override {
185  }
186 
187  void writeDoc_(std::ostream& os, int indentation) const override {
189  }
190 
191  bool exists_(ParameterSet const& pset, bool isTracked) const override {
192  return pset.existsAs<T>(label(), isTracked);
193  }
194 
195  void insertDefault_(ParameterSet& pset) const override {
196  if (isTracked()) {
197  pset.addParameter(label(), value_);
198  }
199  else {
200  pset.addUntrackedParameter(label(), value_);
201  }
202  }
203 
205  };
206 
207  template<>
209 
210  public:
211 
212  ParameterDescription(std::string const& iLabel,
213  ParameterSetDescription const& value,
214  bool isTracked,
215  Comment const& iComment = Comment());
216 
217  ParameterDescription(char const* iLabel,
218  ParameterSetDescription const& value,
219  bool isTracked,
220  Comment const& iComment = Comment());
221 
222  ~ParameterDescription() override;
223 
224  ParameterSetDescription const* parameterSetDescription() const override;
225  ParameterSetDescription * parameterSetDescription() override;
226 
227  ParameterDescriptionNode* clone() const override {
228  return new ParameterDescription(*this);
229  }
230 
231  private:
232 
233  void validate_(ParameterSet& pset,
234  std::set<std::string>& validatedLabels,
235  bool optional) const override;
236 
237  void printDefault_(std::ostream& os,
238  bool writeToCfi,
239  DocFormatHelper& dfh) const override;
240 
241  bool hasNestedContent_() const override;
242 
243  void printNestedContent_(std::ostream& os,
244  bool optional,
245  DocFormatHelper& dfh) const override;
246 
247  bool exists_(ParameterSet const& pset) const override;
248 
249  void writeCfi_(std::ostream& os, int indentation) const override;
250 
251  void writeDoc_(std::ostream& os, int indentation) const override;
252 
253  bool exists_(ParameterSet const& pset, bool isTracked) const override;
254 
255  void insertDefault_(ParameterSet& pset) const override;
256 
258  };
259 
260  template<>
261  class ParameterDescription<std::vector<ParameterSet> > : public ParameterDescriptionBase {
262 
263  public:
264 
265  ParameterDescription(std::string const& iLabel,
266  ParameterSetDescription const& psetDesc,
267  bool isTracked,
268  std::vector<ParameterSet> const& vPset,
269  Comment const& iComment = Comment());
270 
271  ParameterDescription(char const* iLabel,
272  ParameterSetDescription const& psetDesc,
273  bool isTracked,
274  std::vector<ParameterSet> const& vPset,
275  Comment const& iComment = Comment());
276 
277  ParameterDescription(std::string const& iLabel,
278  ParameterSetDescription const& psetDesc,
279  bool isTracked,
280  Comment const& iComment = Comment());
281 
282  ParameterDescription(char const* iLabel,
283  ParameterSetDescription const& psetDesc,
284  bool isTracked,
285  Comment const& iComment = Comment());
286 
287  ~ParameterDescription() override;
288 
289  ParameterSetDescription const* parameterSetDescription() const override;
290  ParameterSetDescription * parameterSetDescription() override;
291 
292  ParameterDescriptionNode* clone() const override {
293  return new ParameterDescription(*this);
294  }
295 
296  void setPartOfDefaultOfVPSet(bool value) { partOfDefaultOfVPSet_ = value; }
297 
298  private:
299 
300  void validate_(ParameterSet& pset,
301  std::set<std::string>& validatedLabels,
302  bool optional) const override;
303 
304  void printDefault_(std::ostream& os,
305  bool writeToCfi,
306  DocFormatHelper& dfh) const override;
307 
308  bool hasNestedContent_() const override;
309 
310  void printNestedContent_(std::ostream& os,
311  bool optional,
312  DocFormatHelper& dfh) const override;
313 
314  bool exists_(ParameterSet const& pset) const override;
315 
316  void writeCfi_(std::ostream& os, int indentation) const override;
317 
318  void writeDoc_(std::ostream& os, int indentation) const override;
319 
320  bool exists_(ParameterSet const& pset, bool isTracked) const override;
321 
322  void insertDefault_(ParameterSet& pset) const override;
323 
324  static void writeOneElementToCfi(ParameterSet const& pset,
325  std::ostream& os,
326  int indentation,
327  bool& nextOneStartsWithAComma);
328 
330  std::vector<ParameterSet> vPset_;
332  };
333 }
334 #endif
ParameterDescription(char const *iLabel, bool isTracked, Comment const &iComment=Comment())
void writeDoc_(std::ostream &os, int indentation) const override
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:185
bool exists_(ParameterSet const &pset) const override
ParameterDescriptionNode * clone() const override
ParameterDescriptionNode * clone() const override
ParameterDescriptionNode * clone() const override
bool exists_(ParameterSet const &pset, bool isTracked) const override
void writeCfi_(std::ostream &os, int indentation) const override
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:143
Definition: value.py:1
ParameterDescription(std::string const &iLabel, T const &value, bool isTracked, Comment const &iComment=Comment())
void insertDefault_(ParameterSet &pset) const override
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:207
bool hasNestedContent_() const override
void writeValue(std::ostream &os, int indentation, int const &value_, ValueFormat format)
HLT enums.
ParameterDescription(std::string const &iLabel, bool isTracked, Comment const &iComment=Comment())
bool hasNestedContent(int const &value)
long double T
ParameterDescription(char const *iLabel, T const &value, bool isTracked, Comment const &iComment=Comment())