Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-02-24 03:08:28

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 writeTemplate(std::ostream& os, int indentation) const override;
0080     void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const override;
0081 
0082     bool hasNestedContent_() const override;
0083 
0084     void printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& helper) const override;
0085 
0086     bool exists_(ParameterSet const& pset) const override;
0087 
0088     void validateDescription(std::string const& parameterName, ParameterSet& pset) const;
0089 
0090     value_ptr<ParameterSetDescription> psetDesc_;
0091   };
0092 
0093   template <>
0094   class ParameterWildcard<std::vector<ParameterSet> > : public ParameterWildcardBase {
0095   public:
0096     ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked);
0097     ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked);
0098 
0099     ParameterWildcard(std::string const& pattern,
0100                       WildcardValidationCriteria criteria,
0101                       bool isTracked,
0102                       ParameterSetDescription const& desc);
0103     ParameterWildcard(char const* pattern,
0104                       WildcardValidationCriteria criteria,
0105                       bool isTracked,
0106                       ParameterSetDescription const& desc);
0107 
0108     ~ParameterWildcard() override;
0109 
0110     ParameterDescriptionNode* clone() const override;
0111 
0112   private:
0113     void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const override;
0114 
0115     bool hasNestedContent_() const override;
0116 
0117     void printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const override;
0118 
0119     bool exists_(ParameterSet const& pset) const override;
0120 
0121     void validatePSetVector(std::string const& parameterName, ParameterSet& pset) const;
0122 
0123     value_ptr<ParameterSetDescription> psetDesc_;
0124   };
0125 }  // namespace edm
0126 #endif