Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:52

0001 #ifndef FWCore_ParameterSet_ParameterWildcard_h
0002 #define FWCore_ParameterSet_ParameterWildcard_h
0003 
0004 #include "FWCore/ParameterSet/interface/ParameterWildcardBase.h"
0005 #include "FWCore/ParameterSet/interface/ParameterDescriptionNode.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSetDescriptionTraits.h"
0008 #include "FWCore/Utilities/interface/value_ptr.h"
0009 
0010 #include <string>
0011 #include <set>
0012 #include <iosfwd>
0013 #include <vector>
0014 
0015 namespace edm {
0016 
0017   class ParameterSet;
0018   class VParameterSetEntry;
0019   class ParameterSetDescription;
0020   class DocFormatHelper;
0021 
0022   template <class T>
0023   class ParameterWildcard : public ParameterWildcardBase {
0024   public:
0025     ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked)
0026         : ParameterWildcardBase(ParameterTypeToEnum::toEnum<T>(), isTracked, criteria) {
0027       throwIfInvalidPattern(pattern);
0028     }
0029 
0030     ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked)
0031         : ParameterWildcardBase(ParameterTypeToEnum::toEnum<T>(), isTracked, criteria) {
0032       throwIfInvalidPattern(pattern);
0033     }
0034 
0035     ~ParameterWildcard() override {}
0036 
0037     ParameterDescriptionNode* clone() const override { return new ParameterWildcard(*this); }
0038 
0039   private:
0040     void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const override {
0041       std::vector<std::string> parameterNames = pset.getParameterNamesForType<T>(isTracked());
0042       validateMatchingNames(parameterNames, validatedLabels, optional);
0043     }
0044 
0045     bool exists_(ParameterSet const& pset) const override {
0046       if (criteria() == RequireZeroOrMore)
0047         return true;
0048 
0049       std::vector<std::string> parameterNames = pset.getParameterNamesForType<T>(isTracked());
0050 
0051       if (criteria() == RequireAtLeastOne)
0052         return !parameterNames.empty();
0053       return parameterNames.size() == 1U;
0054     }
0055 
0056     // In the future may need to add a data member of type T to hold a default value
0057   };
0058 
0059   template <>
0060   class ParameterWildcard<ParameterSetDescription> : public ParameterWildcardBase {
0061   public:
0062     ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked);
0063     ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked);
0064 
0065     ParameterWildcard(std::string const& pattern,
0066                       WildcardValidationCriteria criteria,
0067                       bool isTracked,
0068                       ParameterSetDescription const& desc);
0069     ParameterWildcard(char const* pattern,
0070                       WildcardValidationCriteria criteria,
0071                       bool isTracked,
0072                       ParameterSetDescription const& desc);
0073 
0074     ~ParameterWildcard() override;
0075 
0076     ParameterDescriptionNode* clone() const override;
0077 
0078   private:
0079     void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const override;
0080 
0081     bool hasNestedContent_() const override;
0082 
0083     void printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& helper) const override;
0084 
0085     bool exists_(ParameterSet const& pset) const override;
0086 
0087     void validateDescription(std::string const& parameterName, ParameterSet& pset) const;
0088 
0089     value_ptr<ParameterSetDescription> psetDesc_;
0090   };
0091 
0092   template <>
0093   class ParameterWildcard<std::vector<ParameterSet> > : public ParameterWildcardBase {
0094   public:
0095     ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked);
0096     ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked);
0097 
0098     ParameterWildcard(std::string const& pattern,
0099                       WildcardValidationCriteria criteria,
0100                       bool isTracked,
0101                       ParameterSetDescription const& desc);
0102     ParameterWildcard(char const* pattern,
0103                       WildcardValidationCriteria criteria,
0104                       bool isTracked,
0105                       ParameterSetDescription const& desc);
0106 
0107     ~ParameterWildcard() override;
0108 
0109     ParameterDescriptionNode* clone() const override;
0110 
0111   private:
0112     void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const override;
0113 
0114     bool hasNestedContent_() const override;
0115 
0116     void printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const override;
0117 
0118     bool exists_(ParameterSet const& pset) const override;
0119 
0120     void validatePSetVector(std::string const& parameterName, ParameterSet& pset) const;
0121 
0122     value_ptr<ParameterSetDescription> psetDesc_;
0123   };
0124 }  // namespace edm
0125 #endif