CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
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);
87  bool hasNestedContent(std::vector<LuminosityBlockID> 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  // WARNING: the toEnum function is intentionally undefined if the template
105  // parameter is ParameterSet or vector<ParameterSet>. Both of these cases
106  // are handled by full template specializations below. In the first case.
107  // ParameterSetDescription should be used instead of ParameterSet.
108  // In the second case the function arguments are completely different.
109  // Note that this template parameter is most often passed through from
110  // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
111  // use the addVPSet* versions of those functions.
112  ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, true),
113  value_(value) {
114  }
115 
116  ParameterDescription(char const* iLabel,
117  T const& value,
118  bool isTracked) :
119  // WARNING: the toEnum function is intentionally undefined if the template
120  // parameter is ParameterSet or vector<ParameterSet>. Both of these cases
121  // are handled by full template specializations below. In the first case.
122  // ParameterSetDescription should be used instead of ParameterSet.
123  // In the second case the function arguments are completely different.
124  // Note that this template parameter is most often passed through from
125  // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
126  // use the addVPSet* versions of those functions.
127  ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, true),
128  value_(value) {
129  }
130 
132  bool isTracked) :
133  // WARNING: the toEnum function is intentionally undefined if the template
134  // parameter is ParameterSet or vector<ParameterSet>. Both of these cases
135  // are handled by full template specializations below. In the first case.
136  // ParameterSetDescription should be used instead of ParameterSet.
137  // In the second case the function arguments are completely different.
138  // Note that this template parameter is most often passed through from
139  // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
140  // use the addVPSet* versions of those functions.
141  ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, false),
142  value_() {
143  }
144 
145  ParameterDescription(char const* iLabel,
146  bool isTracked) :
147  // WARNING: the toEnum function is intentionally undefined if the template
148  // parameter is ParameterSet or vector<ParameterSet>. Both of these cases
149  // are handled by full template specializations below. In the first case.
150  // ParameterSetDescription should be used instead of ParameterSet.
151  // In the second case the function arguments are completely different.
152  // Note that this template parameter is most often passed through from
153  // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
154  // use the addVPSet* versions of those functions.
155  ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, false),
156  value_() {
157  }
158 
159  virtual ~ParameterDescription() { }
160 
161  virtual ParameterDescriptionNode* clone() const {
162  return new ParameterDescription(*this);
163  }
164 
165  T getDefaultValue() const { return value_; }
166 
167  private:
168 
169  virtual bool exists_(ParameterSet const& pset) const {
170  return pset.existsAs<T>(label(), isTracked());
171  }
172 
173  virtual bool hasNestedContent_() {
174  if (!hasDefault()) return false;
176  }
177 
178  virtual void writeCfi_(std::ostream& os, int indentation) const {
180  }
181 
182  virtual void writeDoc_(std::ostream& os, int indentation) const {
184  }
185 
186  virtual bool exists_(ParameterSet const& pset, bool isTracked) const {
187  return pset.existsAs<T>(label(), isTracked);
188  }
189 
190  virtual void insertDefault_(ParameterSet& pset) const {
191  if (isTracked()) {
192  pset.addParameter(label(), value_);
193  }
194  else {
196  }
197  }
198 
200  };
201 
202  template<>
204 
205  public:
206 
207  ParameterDescription(std::string const& iLabel,
209  bool isTracked);
210 
211  ParameterDescription(char const* iLabel,
212  ParameterSetDescription const& value,
213  bool isTracked);
214 
215  virtual ~ParameterDescription();
216 
217  virtual ParameterSetDescription const* parameterSetDescription() const;
219 
220  virtual ParameterDescriptionNode* clone() const {
221  return new ParameterDescription(*this);
222  }
223 
224  private:
225 
226  virtual void validate_(ParameterSet& pset,
227  std::set<std::string>& validatedLabels,
228  bool optional) const;
229 
230  virtual void printDefault_(std::ostream& os,
231  bool writeToCfi,
232  DocFormatHelper& dfh);
233 
234  virtual bool hasNestedContent_();
235 
236  virtual void printNestedContent_(std::ostream& os,
237  bool optional,
238  DocFormatHelper& dfh);
239 
240  virtual bool exists_(ParameterSet const& pset) const;
241 
242  virtual void writeCfi_(std::ostream& os, int indentation) const;
243 
244  virtual void writeDoc_(std::ostream& os, int indentation) const;
245 
246  virtual bool exists_(ParameterSet const& pset, bool isTracked) const;
247 
248  virtual void insertDefault_(ParameterSet& pset) const;
249 
251  };
252 
253  template<>
254  class ParameterDescription<std::vector<ParameterSet> > : public ParameterDescriptionBase {
255 
256  public:
257 
258  ParameterDescription(std::string const& iLabel,
259  ParameterSetDescription const& psetDesc,
260  bool isTracked,
261  std::vector<ParameterSet> const& vPset);
262 
263  ParameterDescription(char const* iLabel,
264  ParameterSetDescription const& psetDesc,
265  bool isTracked,
266  std::vector<ParameterSet> const& vPset);
267 
268  ParameterDescription(std::string const& iLabel,
269  ParameterSetDescription const& psetDesc,
270  bool isTracked);
271 
272  ParameterDescription(char const* iLabel,
273  ParameterSetDescription const& psetDesc,
274  bool isTracked);
275 
276  virtual ~ParameterDescription();
277 
278  virtual ParameterSetDescription const* parameterSetDescription() const;
280 
281  virtual ParameterDescriptionNode* clone() const {
282  return new ParameterDescription(*this);
283  }
284 
285  void setPartOfDefaultOfVPSet(bool value) { partOfDefaultOfVPSet_ = value; }
286 
287  private:
288 
289  virtual void validate_(ParameterSet& pset,
290  std::set<std::string>& validatedLabels,
291  bool optional) const;
292 
293  virtual void printDefault_(std::ostream& os,
294  bool writeToCfi,
295  DocFormatHelper& dfh);
296 
297  virtual bool hasNestedContent_();
298 
299  virtual void printNestedContent_(std::ostream& os,
300  bool optional,
301  DocFormatHelper& dfh);
302 
303  virtual bool exists_(ParameterSet const& pset) const;
304 
305  virtual void writeCfi_(std::ostream& os, int indentation) const;
306 
307  virtual void writeDoc_(std::ostream& os, int indentation) const;
308 
309  virtual bool exists_(ParameterSet const& pset, bool isTracked) const;
310 
311  virtual void insertDefault_(ParameterSet& pset) const;
312 
313  static void writeOneElementToCfi(ParameterSet const& pset,
314  std::ostream& os,
315  int indentation,
316  bool& nextOneStartsWithAComma);
317 
319  std::vector<ParameterSet> vPset_;
321  };
322 }
323 #endif
ParameterDescription(std::string const &iLabel, T const &value, bool isTracked)
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:187
virtual bool exists_(ParameterSet const &pset) const
virtual ParameterDescriptionNode * clone() const
ParameterDescription(char const *iLabel, T const &value, bool isTracked)
virtual void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const
virtual void printDefault_(std::ostream &os, bool writeToCfi, DocFormatHelper &dfh)
virtual ParameterDescriptionNode * clone() const
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:145
virtual void insertDefault_(ParameterSet &pset) const
virtual bool exists_(ParameterSet const &pset, bool isTracked) const
ParameterDescription(std::string const &iLabel, bool isTracked)
ParameterDescription(char const *iLabel, bool isTracked)
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:209
virtual ParameterSetDescription const * parameterSetDescription() const
void writeValue(std::ostream &os, int indentation, int const &value_, ValueFormat format)
virtual void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh)
bool hasNestedContent(int const &value)
long double T
virtual ParameterDescriptionNode * clone() const
virtual void writeDoc_(std::ostream &os, int indentation) const
virtual void writeCfi_(std::ostream &os, int indentation) const
std::string const & label() const