Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-23 03:13:12

0001 #ifndef FWCore_ParameterSet_ParameterDescription_h
0002 #define FWCore_ParameterSet_ParameterDescription_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     ParameterSet
0006 // Class  :     ParameterDescription
0007 //
0008 /**\class ParameterDescription ParameterDescription.h FWCore/ParameterSet/interface/ParameterDescription.h
0009 
0010  Description: <one line class summary>
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Thu Aug  2 15:33:51 EDT 2007
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   }  // namespace writeParameterValue
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         :  // WARNING: the toEnum function is intentionally undefined if the template
0114           // parameter is ParameterSet or vector<ParameterSet>.  Both of these cases
0115           // are handled by full template specializations below.  In the first case.
0116           // ParameterSetDescription should be used instead of ParameterSet.
0117           // In the second case the function arguments are completely different.
0118           // Note that this template parameter is most often passed through from
0119           // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
0120           // use the addVPSet* versions of those functions.
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         :  // WARNING: the toEnum function is intentionally undefined if the template
0126           // parameter is ParameterSet or vector<ParameterSet>.  Both of these cases
0127           // are handled by full template specializations below.  In the first case.
0128           // ParameterSetDescription should be used instead of ParameterSet.
0129           // In the second case the function arguments are completely different.
0130           // Note that this template parameter is most often passed through from
0131           // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
0132           // use the addVPSet* versions of those functions.
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         :  // WARNING: the toEnum function is intentionally undefined if the template
0138           // parameter is ParameterSet or vector<ParameterSet>.  Both of these cases
0139           // are handled by full template specializations below.  In the first case.
0140           // ParameterSetDescription should be used instead of ParameterSet.
0141           // In the second case the function arguments are completely different.
0142           // Note that this template parameter is most often passed through from
0143           // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
0144           // use the addVPSet* versions of those functions.
0145           ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, false, iComment),
0146           value_() {}
0147 
0148     ParameterDescription(char const* iLabel, bool isTracked, Comment const& iComment = Comment())
0149         :  // WARNING: the toEnum function is intentionally undefined if the template
0150           // parameter is ParameterSet or vector<ParameterSet>.  Both of these cases
0151           // are handled by full template specializations below.  In the first case.
0152           // ParameterSetDescription should be used instead of ParameterSet.
0153           // In the second case the function arguments are completely different.
0154           // Note that this template parameter is most often passed through from
0155           // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
0156           // use the addVPSet* versions of those functions.
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, bool optional) 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, bool optional) 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 }  // namespace edm
0304 #endif