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 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 
176  void writeCfi_(std::ostream& os, int indentation, CfiOptions&) const override {
178  }
179 
180  void writeDoc_(std::ostream& os, int indentation) const override {
182  }
183 
184  bool exists_(ParameterSet const& pset, bool isTracked) const override {
185  return pset.existsAs<T>(label(), isTracked);
186  }
187 
188  void insertDefault_(ParameterSet& pset) const override {
189  if (isTracked()) {
190  pset.addParameter(label(), value_);
191  } else {
192  pset.addUntrackedParameter(label(), value_);
193  }
194  }
195 
197  };
198 
199  template <>
201  public:
202  ParameterDescription(std::string const& iLabel,
204  bool isTracked,
205  Comment const& iComment = Comment());
206 
207  ParameterDescription(char const* iLabel,
209  bool isTracked,
210  Comment const& iComment = Comment());
211 
212  ~ParameterDescription() override;
213 
214  ParameterSetDescription const* parameterSetDescription() const override;
216 
217  ParameterDescriptionNode* clone() const override { return new ParameterDescription(*this); }
218 
219  private:
220  void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const override;
221 
222  void printDefault_(std::ostream& os, bool writeToCfi, DocFormatHelper& dfh) const override;
223 
224  bool hasNestedContent_() const override;
225 
226  void printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const override;
227 
228  bool exists_(ParameterSet const& pset) const override;
229 
231  void writeCfi_(std::ostream& os, int indentation, CfiOptions&) const override;
232 
233  void writeDoc_(std::ostream& os, int indentation) const override;
234 
235  bool exists_(ParameterSet const& pset, bool isTracked) const override;
236 
237  void insertDefault_(ParameterSet& pset) const override;
238 
240  };
241 
242  template <>
243  class ParameterDescription<std::vector<ParameterSet> > : public ParameterDescriptionBase {
244  public:
245  ParameterDescription(std::string const& iLabel,
246  ParameterSetDescription const& psetDesc,
247  bool isTracked,
248  std::vector<ParameterSet> const& vPset,
249  Comment const& iComment = Comment());
250 
251  ParameterDescription(char const* iLabel,
252  ParameterSetDescription const& psetDesc,
253  bool isTracked,
254  std::vector<ParameterSet> const& vPset,
255  Comment const& iComment = Comment());
256 
257  ParameterDescription(std::string const& iLabel,
258  ParameterSetDescription const& psetDesc,
259  bool isTracked,
260  Comment const& iComment = Comment());
261 
262  ParameterDescription(char const* iLabel,
263  ParameterSetDescription const& psetDesc,
264  bool isTracked,
265  Comment const& iComment = Comment());
266 
267  ~ParameterDescription() override;
268 
269  ParameterSetDescription const* parameterSetDescription() const override;
271 
272  ParameterDescriptionNode* clone() const override { return new ParameterDescription(*this); }
273 
274  void setPartOfDefaultOfVPSet(bool value) { partOfDefaultOfVPSet_ = value; }
275 
276  private:
277  void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const override;
278 
279  void printDefault_(std::ostream& os, bool writeToCfi, DocFormatHelper& dfh) const override;
280 
281  bool hasNestedContent_() const override;
282 
283  void printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const override;
284 
285  bool exists_(ParameterSet const& pset) const override;
286 
288  void writeCfi_(std::ostream& os, int indentation, CfiOptions&) const override;
289 
290  void writeDoc_(std::ostream& os, int indentation) const override;
291 
292  bool exists_(ParameterSet const& pset, bool isTracked) const override;
293 
294  void insertDefault_(ParameterSet& pset) const override;
295 
296  static void writeOneElementToCfi(
297  ParameterSet const& pset, std::ostream& os, int indentation, CfiOptions&, bool& nextOneStartsWithAComma);
298 
300  std::vector<ParameterSet> vPset_;
302  };
303 } // namespace edm
304 #endif
ParameterDescription(char const *iLabel, bool isTracked, Comment const &iComment=Comment())
ParameterDescriptionNode * clone() const override
bool exists_(ParameterSet const &pset, bool isTracked) const override
ParameterDescriptionNode * clone() const override
std::string const & label() const
virtual ParameterSetDescription const * parameterSetDescription() const
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const override
bool exists_(ParameterSet const &pset) const override
optional
Definition: Types.py:245
Definition: value.py:1
bool hasNestedContent_() const override
ParameterDescriptionNode * clone() const override
ParameterDescription(std::string const &iLabel, T const &value, bool isTracked, Comment const &iComment=Comment())
void writeCfi_(std::ostream &os, int indentation, CfiOptions &) const override
void writeValue(std::ostream &os, int indentation, int const &value_, ValueFormat format)
HLT enums.
void writeDoc_(std::ostream &os, int indentation) const override
virtual void printDefault_(std::ostream &os, bool writeToCfi, DocFormatHelper &dfh) const
ParameterDescription(std::string const &iLabel, bool isTracked, Comment const &iComment=Comment())
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
cfi::CfiOptions CfiOptions
virtual void writeCfi_(std::ostream &os, bool optional, bool &startWithComma, int indentation, CfiOptions &, bool &wroteSomething) const =0
ParameterDescription(char const *iLabel, T const &value, bool isTracked, Comment const &iComment=Comment())