CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/FWCore/ParameterSet/interface/ParameterWildcard.h

Go to the documentation of this file.
00001 #ifndef FWCore_ParameterSet_ParameterWildcard_h
00002 #define FWCore_ParameterSet_ParameterWildcard_h
00003 
00004 #include "FWCore/ParameterSet/interface/ParameterWildcardBase.h"
00005 #include "FWCore/ParameterSet/interface/ParameterDescriptionNode.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/Utilities/interface/value_ptr.h"
00008 
00009 #include <string>
00010 #include <set>
00011 #include <iosfwd>
00012 #include <vector>
00013 
00014 namespace edm {
00015 
00016   class ParameterSet;
00017   class VParameterSetEntry;
00018   class ParameterSetDescription;
00019   class DocFormatHelper;
00020 
00021   template<class T>
00022   class ParameterWildcard : public ParameterWildcardBase {
00023 
00024   public:
00025 
00026     ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked) :
00027       ParameterWildcardBase(ParameterTypeToEnum::toEnum<T>(), isTracked, criteria) {
00028       throwIfInvalidPattern(pattern);
00029     }
00030 
00031     ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked) :
00032       ParameterWildcardBase(ParameterTypeToEnum::toEnum<T>(), isTracked, criteria) {
00033       throwIfInvalidPattern(pattern);
00034     }
00035 
00036     virtual ~ParameterWildcard() { }
00037 
00038     virtual ParameterDescriptionNode* clone() const {
00039       return new ParameterWildcard(*this);
00040     }
00041 
00042   private:
00043    
00044     virtual void validate_(ParameterSet & pset,
00045                            std::set<std::string> & validatedLabels,
00046                            bool optional) const {
00047 
00048       std::vector<std::string> parameterNames  = pset.getParameterNamesForType<T>(isTracked());
00049       validateMatchingNames(parameterNames, validatedLabels, optional);
00050 
00051     }
00052 
00053     virtual bool exists_(ParameterSet const& pset) const {
00054 
00055       if (criteria() == RequireZeroOrMore) return true;
00056 
00057       std::vector<std::string> parameterNames  = pset.getParameterNamesForType<T>(isTracked());
00058 
00059       if (criteria() == RequireAtLeastOne) return parameterNames.size() >= 1U;
00060       return parameterNames.size() == 1U;
00061     }
00062 
00063     // In the future may need to add a data member of type T to hold a default value
00064   };
00065 
00066   template<>
00067   class ParameterWildcard<ParameterSetDescription> : public ParameterWildcardBase {
00068 
00069   public:
00070 
00071     ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked);
00072     ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked);
00073 
00074     ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked,
00075                       ParameterSetDescription const& desc);
00076     ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked,
00077                       ParameterSetDescription const& desc);
00078 
00079     virtual ~ParameterWildcard();
00080 
00081     virtual ParameterDescriptionNode* clone() const;
00082 
00083   private:
00084    
00085     virtual void validate_(ParameterSet & pset,
00086                            std::set<std::string> & validatedLabels,
00087                            bool optional) const;
00088 
00089     virtual bool hasNestedContent_();
00090 
00091     virtual void printNestedContent_(std::ostream & os,
00092                                      bool optional,
00093                                      DocFormatHelper & helper);
00094 
00095     virtual bool exists_(ParameterSet const& pset) const;
00096 
00097     void validateDescription(std::string const& parameterName, ParameterSet & pset) const;
00098 
00099     value_ptr<ParameterSetDescription> psetDesc_;
00100   };
00101 
00102   template<>
00103   class ParameterWildcard<std::vector<ParameterSet> > : public ParameterWildcardBase {
00104 
00105   public:
00106 
00107     ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked);
00108     ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked);
00109 
00110     ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked,
00111                       ParameterSetDescription const& desc);
00112     ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked,
00113                       ParameterSetDescription const& desc);
00114 
00115     virtual ~ParameterWildcard();
00116 
00117     virtual ParameterDescriptionNode* clone() const;
00118 
00119   private:
00120    
00121     virtual void validate_(ParameterSet & pset,
00122                            std::set<std::string> & validatedLabels,
00123                            bool optional) const;
00124 
00125     virtual bool hasNestedContent_();
00126 
00127     virtual void printNestedContent_(std::ostream & os,
00128                                      bool optional,
00129                                      DocFormatHelper & dfh);
00130 
00131     virtual bool exists_(ParameterSet const& pset) const;
00132 
00133     void validatePSetVector(std::string const& parameterName, ParameterSet & pset) const;
00134 
00135     value_ptr<ParameterSetDescription> psetDesc_;
00136   };
00137 }
00138 #endif