File indexing completed on 2025-03-26 01:51:12
0001 #ifndef FWCore_ParameterSet_ParameterDescription_h
0002 #define FWCore_ParameterSet_ParameterDescription_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include "FWCore/ParameterSet/interface/ParameterDescriptionBase.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSetDescriptionTraits.h"
0024 #include "FWCore/Utilities/interface/value_ptr.h"
0025
0026 #include <string>
0027 #include <vector>
0028 #include <iosfwd>
0029 #include <set>
0030
0031 namespace edm {
0032
0033 class ParameterSetDescription;
0034
0035 class EventID;
0036 class LuminosityBlockID;
0037 class LuminosityBlockRange;
0038 class EventRange;
0039 class InputTag;
0040 class ESInputTag;
0041 class FileInPath;
0042 class DocFormatHelper;
0043
0044 namespace writeParameterValue {
0045
0046 enum ValueFormat { CFI, DOC };
0047
0048 void writeValue(std::ostream& os, int indentation, int const& value_, ValueFormat format);
0049 void writeValue(std::ostream& os, int indentation, std::vector<int> const& value_, ValueFormat format);
0050 void writeValue(std::ostream& os, int indentation, unsigned const& value_, ValueFormat format);
0051 void writeValue(std::ostream& os, int indentation, std::vector<unsigned> const& value_, ValueFormat format);
0052 void writeValue(std::ostream& os, int indentation, long long const& value_, ValueFormat format);
0053 void writeValue(std::ostream& os, int indentation, std::vector<long long> const& value_, ValueFormat format);
0054 void writeValue(std::ostream& os, int indentation, unsigned long long const& value_, ValueFormat format);
0055 void writeValue(std::ostream& os,
0056 int indentation,
0057 std::vector<unsigned long long> const& value_,
0058 ValueFormat format);
0059 void writeValue(std::ostream& os, int indentation, double const& value_, ValueFormat format);
0060 void writeValue(std::ostream& os, int indentation, std::vector<double> const& value_, ValueFormat format);
0061 void writeValue(std::ostream& os, int indentation, bool const& value_, ValueFormat format);
0062 void writeValue(std::ostream& os, int indentation, std::string const& value_, ValueFormat format);
0063 void writeValue(std::ostream& os, int indentation, std::vector<std::string> const& value_, ValueFormat format);
0064 void writeValue(std::ostream& os, int indentation, EventID const& value_, ValueFormat format);
0065 void writeValue(std::ostream& os, int indentation, std::vector<EventID> const& value_, ValueFormat format);
0066 void writeValue(std::ostream& os, int indentation, LuminosityBlockID const& value_, ValueFormat format);
0067 void writeValue(std::ostream& os, int indentation, std::vector<LuminosityBlockID> const& value_, ValueFormat format);
0068 void writeValue(std::ostream& os, int indentation, LuminosityBlockRange const& value_, ValueFormat format);
0069 void writeValue(std::ostream& os,
0070 int indentation,
0071 std::vector<LuminosityBlockRange> const& value_,
0072 ValueFormat format);
0073 void writeValue(std::ostream& os, int indentation, EventRange const& value_, ValueFormat format);
0074 void writeValue(std::ostream& os, int indentation, std::vector<EventRange> const& value_, ValueFormat format);
0075 void writeValue(std::ostream& os, int indentation, InputTag const& value_, ValueFormat format);
0076 void writeValue(std::ostream& os, int indentation, std::vector<InputTag> const& value_, ValueFormat format);
0077 void writeValue(std::ostream& os, int indentation, ESInputTag const& value_, ValueFormat format);
0078 void writeValue(std::ostream& os, int indentation, std::vector<ESInputTag> const& value_, ValueFormat format);
0079 void writeValue(std::ostream& os, int indentation, FileInPath const& value_, ValueFormat format);
0080
0081 bool hasNestedContent(int const& value);
0082 bool hasNestedContent(std::vector<int> const& value);
0083 bool hasNestedContent(unsigned const& value);
0084 bool hasNestedContent(std::vector<unsigned> const& value);
0085 bool hasNestedContent(long long const& value);
0086 bool hasNestedContent(std::vector<long long> const& value);
0087 bool hasNestedContent(unsigned long long const& value);
0088 bool hasNestedContent(std::vector<unsigned long long> const& value);
0089 bool hasNestedContent(double const& value);
0090 bool hasNestedContent(std::vector<double> const& value);
0091 bool hasNestedContent(bool const& value);
0092 bool hasNestedContent(std::string const& value);
0093 bool hasNestedContent(std::vector<std::string> const& value);
0094 bool hasNestedContent(EventID const& value);
0095 bool hasNestedContent(std::vector<EventID> const& value);
0096 bool hasNestedContent(LuminosityBlockID const& value);
0097 bool hasNestedContent(std::vector<LuminosityBlockID> const& value);
0098 bool hasNestedContent(LuminosityBlockRange const& value);
0099 bool hasNestedContent(std::vector<LuminosityBlockRange> const& value);
0100 bool hasNestedContent(EventRange const& value);
0101 bool hasNestedContent(std::vector<EventRange> const& value);
0102 bool hasNestedContent(InputTag const& value);
0103 bool hasNestedContent(std::vector<InputTag> const& value);
0104 bool hasNestedContent(ESInputTag const& value);
0105 bool hasNestedContent(std::vector<ESInputTag> const& value);
0106 bool hasNestedContent(FileInPath const& value);
0107 }
0108
0109 template <typename T>
0110 class ParameterDescription : public ParameterDescriptionBase {
0111 public:
0112 ParameterDescription(std::string const& iLabel, T const& value, bool isTracked, Comment const& iComment = Comment())
0113 :
0114
0115
0116
0117
0118
0119
0120
0121 ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, true, iComment),
0122 value_(value) {}
0123
0124 ParameterDescription(char const* iLabel, T const& value, bool isTracked, Comment const& iComment = Comment())
0125 :
0126
0127
0128
0129
0130
0131
0132
0133 ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, true, iComment),
0134 value_(value) {}
0135
0136 ParameterDescription(std::string const& iLabel, bool isTracked, Comment const& iComment = Comment())
0137 :
0138
0139
0140
0141
0142
0143
0144
0145 ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, false, iComment),
0146 value_() {}
0147
0148 ParameterDescription(char const* iLabel, bool isTracked, Comment const& iComment = Comment())
0149 :
0150
0151
0152
0153
0154
0155
0156
0157 ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, false, iComment),
0158 value_() {}
0159
0160 ~ParameterDescription() override {}
0161
0162 ParameterDescriptionNode* clone() const override { return new ParameterDescription(*this); }
0163
0164 T getDefaultValue() const { return value_; }
0165
0166 private:
0167 bool exists_(ParameterSet const& pset) const override { return pset.existsAs<T>(label(), isTracked()); }
0168
0169 bool hasNestedContent_() const override {
0170 if (!hasDefault())
0171 return false;
0172 return writeParameterValue::hasNestedContent(value_);
0173 }
0174
0175 using ParameterDescriptionNode::writeCfi_;
0176 void writeCfi_(std::ostream& os, int indentation, CfiOptions&) const override {
0177 writeParameterValue::writeValue(os, indentation, value_, writeParameterValue::CFI);
0178 }
0179
0180 void writeDoc_(std::ostream& os, int indentation) const override {
0181 writeParameterValue::writeValue(os, indentation, value_, writeParameterValue::DOC);
0182 }
0183
0184 bool exists_(ParameterSet const& pset, bool isTracked) const override {
0185 return pset.existsAs<T>(label(), isTracked);
0186 }
0187
0188 void insertDefault_(ParameterSet& pset) const override {
0189 if (isTracked()) {
0190 pset.addParameter(label(), value_);
0191 } else {
0192 pset.addUntrackedParameter(label(), value_);
0193 }
0194 }
0195
0196 T value_;
0197 };
0198
0199 template <>
0200 class ParameterDescription<ParameterSetDescription> : public ParameterDescriptionBase {
0201 public:
0202 ParameterDescription(std::string const& iLabel,
0203 ParameterSetDescription const& value,
0204 bool isTracked,
0205 Comment const& iComment = Comment());
0206
0207 ParameterDescription(char const* iLabel,
0208 ParameterSetDescription const& value,
0209 bool isTracked,
0210 Comment const& iComment = Comment());
0211
0212 ~ParameterDescription() override;
0213
0214 ParameterSetDescription const* parameterSetDescription() const override;
0215 ParameterSetDescription* parameterSetDescription() override;
0216
0217 ParameterDescriptionNode* clone() const override { return new ParameterDescription(*this); }
0218
0219 private:
0220 void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, Modifier modifier) const override;
0221
0222 void printDefault_(std::ostream& os, bool writeToCfi, DocFormatHelper& dfh) const override;
0223
0224 bool hasNestedContent_() const override;
0225
0226 void printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const override;
0227
0228 bool exists_(ParameterSet const& pset) const override;
0229
0230 using ParameterDescriptionNode::writeCfi_;
0231 void writeCfi_(std::ostream& os, int indentation, CfiOptions&) const override;
0232
0233 void writeDoc_(std::ostream& os, int indentation) const override;
0234
0235 bool exists_(ParameterSet const& pset, bool isTracked) const override;
0236
0237 void insertDefault_(ParameterSet& pset) const override;
0238
0239 value_ptr<ParameterSetDescription> psetDesc_;
0240 };
0241
0242 template <>
0243 class ParameterDescription<std::vector<ParameterSet> > : public ParameterDescriptionBase {
0244 public:
0245 ParameterDescription(std::string const& iLabel,
0246 ParameterSetDescription const& psetDesc,
0247 bool isTracked,
0248 std::vector<ParameterSet> const& vPset,
0249 Comment const& iComment = Comment());
0250
0251 ParameterDescription(char const* iLabel,
0252 ParameterSetDescription const& psetDesc,
0253 bool isTracked,
0254 std::vector<ParameterSet> const& vPset,
0255 Comment const& iComment = Comment());
0256
0257 ParameterDescription(std::string const& iLabel,
0258 ParameterSetDescription const& psetDesc,
0259 bool isTracked,
0260 Comment const& iComment = Comment());
0261
0262 ParameterDescription(char const* iLabel,
0263 ParameterSetDescription const& psetDesc,
0264 bool isTracked,
0265 Comment const& iComment = Comment());
0266
0267 ~ParameterDescription() override;
0268
0269 ParameterSetDescription const* parameterSetDescription() const override;
0270 ParameterSetDescription* parameterSetDescription() override;
0271
0272 ParameterDescriptionNode* clone() const override { return new ParameterDescription(*this); }
0273
0274 void setPartOfDefaultOfVPSet(bool value) { partOfDefaultOfVPSet_ = value; }
0275
0276 private:
0277 void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, Modifier modifier) const override;
0278
0279 void printDefault_(std::ostream& os, bool writeToCfi, DocFormatHelper& dfh) const override;
0280
0281 bool hasNestedContent_() const override;
0282
0283 void printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const override;
0284
0285 bool exists_(ParameterSet const& pset) const override;
0286
0287 using ParameterDescriptionNode::writeCfi_;
0288 void writeCfi_(std::ostream& os, int indentation, CfiOptions&) const override;
0289
0290 void writeDoc_(std::ostream& os, int indentation) const override;
0291
0292 bool exists_(ParameterSet const& pset, bool isTracked) const override;
0293
0294 void insertDefault_(ParameterSet& pset) const override;
0295
0296 static void writeOneElementToCfi(
0297 ParameterSet const& pset, std::ostream& os, int indentation, CfiOptions&, bool& nextOneStartsWithAComma);
0298
0299 value_ptr<ParameterSetDescription> psetDesc_;
0300 std::vector<ParameterSet> vPset_;
0301 bool partOfDefaultOfVPSet_;
0302 };
0303 }
0304 #endif