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