File indexing completed on 2024-04-06 12:12:45
0001 #ifndef FWCore_MessageService_MessageServicePSetValidation_h
0002 #define FWCore_MessageService_MessageServicePSetValidation_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #include <string>
0029 #include <sstream>
0030 #include <vector>
0031
0032
0033
0034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0035 #include "FWCore/Utilities/interface/Exception.h"
0036
0037
0038
0039 namespace edm {
0040 namespace service {
0041
0042 class MessageServicePSetValidation {
0043 public:
0044 std::string operator()(ParameterSet const& pset);
0045
0046 private:
0047 typedef std::string String;
0048 typedef std::vector<String> vString;
0049
0050 void messageLoggerPSet(ParameterSet const& pset);
0051 void psetLists(ParameterSet const& pset);
0052 void suppressionLists(ParameterSet const& pset);
0053 bool validateThreshold(std::string const& thresh, std::string const& psetName);
0054 bool checkThreshold(std::string const& thresh);
0055 void noDuplicates(vString const& v, std::string const& psetName, std::string const& parameterLabel);
0056 void noDuplicates(vString const& v1,
0057 vString const& v2,
0058 std::string const& psetName,
0059 std::string const& p1,
0060 std::string const& p2);
0061 void noCoutCerrClash(vString const& v, std::string const& psetName, std::string const& parameterLabel);
0062 void noKeywords(vString const& v, std::string const& psetName, std::string const& parameterLabel);
0063 bool keywordCheck(std::string const& word);
0064 void noNonPSetUsage(ParameterSet const& pset,
0065 vString const& v,
0066 std::string const& psetName,
0067 std::string const& parameterLabel);
0068 void noBadParams(vString const& v,
0069 vString const& params,
0070 std::string const& psetName,
0071 std::string const& parameterLabel,
0072 std::string const& type);
0073 void vStringsCheck(ParameterSet const& pset, std::string const& psetName);
0074 bool wildcard(vString const& v);
0075 bool allowedVstring(std::string const& s);
0076 void noOtherPsets(ParameterSet const& pset);
0077 void noNoncategoryPsets(ParameterSet const& pset, std::string const& psetName);
0078 bool lookForMatch(vString const& v, std::string const& s);
0079 void destinationPSets(ParameterSet const& pset);
0080 void destinationPSet(ParameterSet const& pset, std::string const& psetName);
0081 void defaultPSet(ParameterSet const& main_pset);
0082 void statisticsPSets(ParameterSet const& pset);
0083 void statisticsPSet(ParameterSet const& pset, std::string const& psetName);
0084 void categoryPSets(ParameterSet const& pset, std::string const& psetName);
0085 void categoryPSet(ParameterSet const& pset, std::string const& OuterPsetName, std::string const& categoryName);
0086 void catInts(ParameterSet const& pset, std::string const& psetName, std::string const& categoryName);
0087 void catNoPSets(ParameterSet const& pset, std::string const& psetName, std::string const& categoryName);
0088 void catBoolRestriction(ParameterSet const& pset,
0089 std::string const& psetName,
0090 std::string const& categoryName,
0091 std::string const& type);
0092
0093 template <typename T>
0094 T check(ParameterSet const& pset, std::string const& psetName, std::string const& parameterLabel) {
0095 T val = T();
0096 try {
0097 if (!pset.exists(parameterLabel))
0098 return val;
0099 if (pset.existsAs<T>(parameterLabel, false)) {
0100 val = pset.getUntrackedParameter<T>(parameterLabel, val);
0101 return val;
0102 }
0103 if (pset.existsAs<T>(parameterLabel, true)) {
0104 flaws_ << psetName << " PSet: \n" << parameterLabel << " is declared as tracked - needs to be untracked \n";
0105 val = pset.getParameter<T>(parameterLabel);
0106 } else {
0107 flaws_ << psetName << " PSet: \n" << parameterLabel << " is declared with incorrect type \n";
0108 }
0109 return val;
0110 } catch (cms::Exception& e) {
0111 flaws_ << psetName << " PSet: \n"
0112 << parameterLabel << " is declared but causes an exception when processed: \n"
0113 << e.what() << "\n";
0114 return val;
0115 }
0116 }
0117
0118 template <typename T>
0119 void disallowedParam(ParameterSet const& pset,
0120 vString const& v,
0121 std::string const& psetName,
0122 std::string const& parameterLabel,
0123 std::string const& type) {
0124 vString params = pset.getParameterNamesForType<T>(true);
0125 noBadParams(v, params, psetName, parameterLabel, type);
0126 params = pset.getParameterNamesForType<T>(false);
0127 noBadParams(v, params, psetName, parameterLabel, type);
0128 }
0129
0130 template <typename T>
0131 void noneExcept(ParameterSet const& pset, std::string const& psetName, std::string const& type) {
0132 vString x = pset.template getParameterNamesForType<T>(false);
0133 vString::const_iterator end = x.end();
0134 for (vString::const_iterator i = x.begin(); i != end; ++i) {
0135 flaws_ << psetName << " PSet: \n"
0136 << (*i) << " is used as a " << type << "\n"
0137 << "Usage of " << type << " is not recognized here\n";
0138 }
0139 x = pset.template getParameterNamesForType<T>(true);
0140 end = x.end();
0141 for (vString::const_iterator i = x.begin(); i != end; ++i) {
0142 if ((*i) == "@service_type")
0143 continue;
0144 flaws_ << psetName << " PSet: \n"
0145 << (*i) << " is used as a tracked " << type << "\n"
0146 << "Tracked parameters not allowed here, "
0147 << " and even untracked it would not be recognized\n";
0148 }
0149 }
0150
0151 template <typename T>
0152 void noneExcept(ParameterSet const& pset,
0153 std::string const& psetName,
0154 std::string const& type,
0155 std::string const& ok) {
0156 vString x = pset.template getParameterNamesForType<T>(false);
0157 vString::const_iterator end = x.end();
0158 for (vString::const_iterator i = x.begin(); i != end; ++i) {
0159 const std::string& val = (*i);
0160 if (val != ok) {
0161 flaws_ << psetName << " PSet: \n"
0162 << val << " is used as a " << type << "\n"
0163 << "This usage is not recognized in this type of PSet\n";
0164 }
0165 }
0166 x = pset.template getParameterNamesForType<T>(true);
0167 end = x.end();
0168 for (vString::const_iterator i = x.begin(); i != end; ++i) {
0169 if ((*i) == "@service_type")
0170 continue;
0171 flaws_ << psetName << " PSet: \n"
0172 << (*i) << " is used as a tracked " << type << "\n"
0173 << "Tracked parameters not allowed here\n";
0174 }
0175 }
0176
0177 template <typename T>
0178 void noneExcept(
0179 ParameterSet const& pset, std::string const& psetName, std::string const& type, T const& ok1, T const& ok2) {
0180 vString x = pset.template getParameterNamesForType<T>(false);
0181 vString::const_iterator end = x.end();
0182 for (vString::const_iterator i = x.begin(); i != end; ++i) {
0183 const std::string& val = (*i);
0184 if ((val != ok1) && (val != ok2)) {
0185 flaws_ << psetName << " PSet: \n"
0186 << val << " is used as a " << type << "\n"
0187 << "This usage is not recognized in this type of PSet\n";
0188 }
0189 }
0190 x = pset.template getParameterNamesForType<T>(true);
0191 end = x.end();
0192 for (vString::const_iterator i = x.begin(); i != end; ++i) {
0193 if ((*i) == "@service_type")
0194 continue;
0195 flaws_ << psetName << " PSet: \n"
0196 << (*i) << " is used as a tracked " << type << "\n"
0197 << "Tracked parameters not allowed here\n";
0198 }
0199 }
0200
0201 template <typename T>
0202 void noneExcept(ParameterSet const& pset,
0203 std::string const& psetName,
0204 std::string const& type,
0205 vString const& vok) {
0206 vString x = pset.template getParameterNamesForType<T>(false);
0207 vString::const_iterator end = x.end();
0208 vString::const_iterator vend = vok.end();
0209 for (vString::const_iterator i = x.begin(); i != end; ++i) {
0210 bool found = false;
0211 for (vString::const_iterator vit = vok.begin(); vit != vend; ++vit) {
0212 if (*i == *vit)
0213 found = true;
0214 }
0215 if (!found) {
0216 flaws_ << psetName << " PSet: \n"
0217 << *i << " is used as a " << type << "\n"
0218 << "This usage is not recognized in this type of PSet\n";
0219 }
0220 }
0221 x = pset.template getParameterNamesForType<T>(true);
0222 end = x.end();
0223 for (vString::const_iterator i = x.begin(); i != end; ++i) {
0224 if ((*i) == "@service_type")
0225 continue;
0226 flaws_ << psetName << " PSet: \n"
0227 << (*i) << " is used as a tracked " << type << "\n"
0228 << "Tracked parameters not allowed here\n";
0229 }
0230 }
0231
0232 template <typename T>
0233 void catNone(ParameterSet const& pset,
0234 std::string const& psetName,
0235 std::string const& categoryName,
0236 std::string const& type) {
0237 vString x = pset.template getParameterNamesForType<T>(false);
0238 vString::const_iterator end = x.end();
0239 for (vString::const_iterator i = x.begin(); i != end; ++i) {
0240 flaws_ << categoryName << " category PSet nested in " << psetName << " PSet: \n"
0241 << (*i) << " is used as a " << type << "\n"
0242 << "Usage of " << type << " is not recognized here\n";
0243 }
0244 x = pset.template getParameterNamesForType<T>(true);
0245 end = x.end();
0246 for (vString::const_iterator i = x.begin(); i != end; ++i) {
0247 flaws_ << categoryName << " category PSet nested in " << psetName << " PSet: \n"
0248 << (*i) << " is used as a tracked " << type << "\n"
0249 << "Tracked parameters not allowed here, "
0250 << " and even untracked it would not be recognized\n";
0251 }
0252 }
0253
0254
0255 std::ostringstream flaws_;
0256 std::vector<std::string> destinations_;
0257 std::vector<std::string> statistics_;
0258 std::vector<std::string> categories_;
0259 std::vector<std::string> debugModules_;
0260 std::vector<std::string> suppressInfo_;
0261 std::vector<std::string> suppressFwkInfo_;
0262 std::vector<std::string> suppressDebug_;
0263 std::vector<std::string> suppressWarning_;
0264 std::vector<std::string> suppressError_;
0265
0266 };
0267
0268 }
0269
0270 }
0271
0272 #endif