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