CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MessageServicePSetValidation.h
Go to the documentation of this file.
1 #ifndef FWCore_MessageService_MessageServicePSetValidation_h
2 #define FWCore_MessageService_MessageServicePSetValidation_h
3 
4 // -*- C++ -*-
5 //
6 // Package: Services
7 // Class : MessageServicePSetValidation_h
8 //
21 //
22 // Original Author: M. Fischler
23 // Created: Tue May 19 2009
24 //
25 
26 // system include files
27 
28 #include <string>
29 #include <sstream>
30 #include <vector>
31 
32 // user include files
33 
36 
37 // forward declarations
38 
39 namespace edm {
40  namespace service {
41 
43  public:
45 
46  private:
48  typedef std::vector<String> vString;
49 
50  void messageLoggerPSet(ParameterSet const& pset);
51  void psetLists(ParameterSet const& pset);
52  void suppressionLists(ParameterSet const& pset);
53  bool validateThreshold(std::string const& thresh, std::string const& psetName);
54  bool checkThreshold(std::string const& thresh);
55  void noDuplicates(vString const& v, std::string const& psetName, std::string const& parameterLabel);
56  void noDuplicates(vString const& v1,
57  vString const& v2,
58  std::string const& psetName,
59  std::string const& p1,
60  std::string const& p2);
61  void noCoutCerrClash(vString const& v, std::string const& psetName, std::string const& parameterLabel);
62  void noKeywords(vString const& v, std::string const& psetName, std::string const& parameterLabel);
63  bool keywordCheck(std::string const& word);
64  void noNonPSetUsage(ParameterSet const& pset,
65  vString const& v,
66  std::string const& psetName,
67  std::string const& parameterLabel);
68  void noBadParams(vString const& v,
69  vString const& params,
70  std::string const& psetName,
71  std::string const& parameterLabel,
72  std::string const& type);
73  void vStringsCheck(ParameterSet const& pset, std::string const& psetName);
74  bool wildcard(vString const& v);
75  bool allowedVstring(std::string const& s);
76  void noOtherPsets(ParameterSet const& pset);
77  void noNoncategoryPsets(ParameterSet const& pset, std::string const& psetName);
78  bool lookForMatch(vString const& v, std::string const& s);
79  void destinationPSets(ParameterSet const& pset);
80  void destinationPSet(ParameterSet const& pset, std::string const& psetName);
81  void defaultPSet(ParameterSet const& main_pset);
82  void statisticsPSets(ParameterSet const& pset);
83  void statisticsPSet(ParameterSet const& pset, std::string const& psetName);
84  void categoryPSets(ParameterSet const& pset, std::string const& psetName);
85  void categoryPSet(ParameterSet const& pset, std::string const& OuterPsetName, std::string const& categoryName);
86  void catInts(ParameterSet const& pset, std::string const& psetName, std::string const& categoryName);
87  void catNoPSets(ParameterSet const& pset, std::string const& psetName, std::string const& categoryName);
88  void catBoolRestriction(ParameterSet const& pset,
89  std::string const& psetName,
90  std::string const& categoryName,
91  std::string const& type);
92 
93  template <typename T>
94  T check(ParameterSet const& pset, std::string const& psetName, std::string const& parameterLabel) {
95  T val = T();
96  try {
97  if (!pset.exists(parameterLabel))
98  return val;
99  if (pset.existsAs<T>(parameterLabel, false)) {
100  val = pset.getUntrackedParameter<T>(parameterLabel, val);
101  return val;
102  }
103  if (pset.existsAs<T>(parameterLabel, true)) {
104  flaws_ << psetName << " PSet: \n" << parameterLabel << " is declared as tracked - needs to be untracked \n";
105  val = pset.getParameter<T>(parameterLabel);
106  } else {
107  flaws_ << psetName << " PSet: \n" << parameterLabel << " is declared with incorrect type \n";
108  }
109  return val;
110  } catch (cms::Exception& e) {
111  flaws_ << psetName << " PSet: \n"
112  << parameterLabel << " is declared but causes an exception when processed: \n"
113  << e.what() << "\n";
114  return val;
115  }
116  } // check()
117 
118  template <typename T>
119  void disallowedParam(ParameterSet const& pset,
120  vString const& v,
121  std::string const& psetName,
122  std::string const& parameterLabel,
123  std::string const& type) {
125  noBadParams(v, params, psetName, parameterLabel, type);
126  params = pset.getParameterNamesForType<T>(false);
127  noBadParams(v, params, psetName, parameterLabel, type);
128  } // disallowedParam()
129 
130  template <typename T>
131  void noneExcept(ParameterSet const& pset, std::string const& psetName, std::string const& type) {
132  vString x = pset.template getParameterNamesForType<T>(false);
133  vString::const_iterator end = x.end();
134  for (vString::const_iterator i = x.begin(); i != end; ++i) {
135  flaws_ << psetName << " PSet: \n"
136  << (*i) << " is used as a " << type << "\n"
137  << "Usage of " << type << " is not recognized here\n";
138  }
139  x = pset.template getParameterNamesForType<T>(true);
140  end = x.end();
141  for (vString::const_iterator i = x.begin(); i != end; ++i) {
142  if ((*i) == "@service_type")
143  continue;
144  flaws_ << psetName << " PSet: \n"
145  << (*i) << " is used as a tracked " << type << "\n"
146  << "Tracked parameters not allowed here, "
147  << " and even untracked it would not be recognized\n";
148  }
149  } // noneExcept()
150 
151  template <typename T>
152  void noneExcept(ParameterSet const& pset,
153  std::string const& psetName,
154  std::string const& type,
155  std::string const& ok) {
156  vString x = pset.template getParameterNamesForType<T>(false);
157  vString::const_iterator end = x.end();
158  for (vString::const_iterator i = x.begin(); i != end; ++i) {
159  std::string val = (*i);
160  if (val != ok) {
161  flaws_ << psetName << " PSet: \n"
162  << val << " is used as a " << type << "\n"
163  << "This usage is not recognized in this type of PSet\n";
164  }
165  }
166  x = pset.template getParameterNamesForType<T>(true);
167  end = x.end();
168  for (vString::const_iterator i = x.begin(); i != end; ++i) {
169  if ((*i) == "@service_type")
170  continue;
171  flaws_ << psetName << " PSet: \n"
172  << (*i) << " is used as a tracked " << type << "\n"
173  << "Tracked parameters not allowed here\n";
174  }
175  } // noneExcept(okValue)
176 
177  template <typename T>
179  ParameterSet const& pset, std::string const& psetName, std::string const& type, T const& ok1, T const& ok2) {
180  vString x = pset.template getParameterNamesForType<T>(false);
181  vString::const_iterator end = x.end();
182  for (vString::const_iterator i = x.begin(); i != end; ++i) {
183  std::string val = (*i);
184  if ((val != ok1) && (val != ok2)) {
185  flaws_ << psetName << " PSet: \n"
186  << val << " is used as a " << type << "\n"
187  << "This usage is not recognized in this type of PSet\n";
188  }
189  }
190  x = pset.template getParameterNamesForType<T>(true);
191  end = x.end();
192  for (vString::const_iterator i = x.begin(); i != end; ++i) {
193  if ((*i) == "@service_type")
194  continue;
195  flaws_ << psetName << " PSet: \n"
196  << (*i) << " is used as a tracked " << type << "\n"
197  << "Tracked parameters not allowed here\n";
198  }
199  } // noneExcept(okValue1, okValue2)
200 
201  template <typename T>
202  void noneExcept(ParameterSet const& pset,
203  std::string const& psetName,
204  std::string const& type,
205  vString const& vok) {
206  vString x = pset.template getParameterNamesForType<T>(false);
207  vString::const_iterator end = x.end();
208  vString::const_iterator vend = vok.end();
209  for (vString::const_iterator i = x.begin(); i != end; ++i) {
210  bool found = false;
211  for (vString::const_iterator vit = vok.begin(); vit != vend; ++vit) {
212  if (*i == *vit)
213  found = true;
214  }
215  if (!found) {
216  flaws_ << psetName << " PSet: \n"
217  << *i << " is used as a " << type << "\n"
218  << "This usage is not recognized in this type of PSet\n";
219  }
220  }
221  x = pset.template getParameterNamesForType<T>(true);
222  end = x.end();
223  for (vString::const_iterator i = x.begin(); i != end; ++i) {
224  if ((*i) == "@service_type")
225  continue;
226  flaws_ << psetName << " PSet: \n"
227  << (*i) << " is used as a tracked " << type << "\n"
228  << "Tracked parameters not allowed here\n";
229  }
230  } // noneExcept(vok)
231 
232  template <typename T>
233  void catNone(ParameterSet const& pset,
234  std::string const& psetName,
235  std::string const& categoryName,
236  std::string const& type) {
237  vString x = pset.template getParameterNamesForType<T>(false);
238  vString::const_iterator end = x.end();
239  for (vString::const_iterator i = x.begin(); i != end; ++i) {
240  flaws_ << categoryName << " category PSet nested in " << psetName << " PSet: \n"
241  << (*i) << " is used as a " << type << "\n"
242  << "Usage of " << type << " is not recognized here\n";
243  }
244  x = pset.template getParameterNamesForType<T>(true);
245  end = x.end();
246  for (vString::const_iterator i = x.begin(); i != end; ++i) {
247  flaws_ << categoryName << " category PSet nested in " << psetName << " PSet: \n"
248  << (*i) << " is used as a tracked " << type << "\n"
249  << "Tracked parameters not allowed here, "
250  << " and even untracked it would not be recognized\n";
251  }
252  } // catNone()
253 
254  // private data
255  std::ostringstream flaws_;
256  std::vector<std::string> destinations_;
257  std::vector<std::string> statistics_;
258  std::vector<std::string> categories_;
259  std::vector<std::string> debugModules_;
260  std::vector<std::string> suppressInfo_;
261  std::vector<std::string> suppressFwkInfo_;
262  std::vector<std::string> suppressDebug_;
263  std::vector<std::string> suppressWarning_;
264  std::vector<std::string> suppressError_;
265 
266  }; // MessageServicePSetValidation
267 
268  } // namespace service
269 
270 } // namespace edm
271 
272 #endif // FWCore_MessageService_MessageServicePSetValidation_h
T getUntrackedParameter(std::string const &, T const &) const
void statisticsPSet(ParameterSet const &pset, std::string const &psetName)
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
bool lookForMatch(vString const &v, std::string const &s)
const TString p2
Definition: fwPaths.cc:13
void categoryPSets(ParameterSet const &pset, std::string const &psetName)
void destinationPSet(ParameterSet const &pset, std::string const &psetName)
void disallowedParam(ParameterSet const &pset, vString const &v, std::string const &psetName, std::string const &parameterLabel, std::string const &type)
void vStringsCheck(ParameterSet const &pset, std::string const &psetName)
bool exists(std::string const &parameterName) const
checks if a parameter exists
void noCoutCerrClash(vString const &v, std::string const &psetName, std::string const &parameterLabel)
void noneExcept(ParameterSet const &pset, std::string const &psetName, std::string const &type, std::string const &ok)
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:179
uint64_t word
void noneExcept(ParameterSet const &pset, std::string const &psetName, std::string const &type, vString const &vok)
T check(ParameterSet const &pset, std::string const &psetName, std::string const &parameterLabel)
void noneExcept(ParameterSet const &pset, std::string const &psetName, std::string const &type, T const &ok1, T const &ok2)
void noKeywords(vString const &v, std::string const &psetName, std::string const &parameterLabel)
char const * what() const noexceptoverride
Definition: Exception.cc:103
const TString p1
Definition: fwPaths.cc:12
void catNone(ParameterSet const &pset, std::string const &psetName, std::string const &categoryName, std::string const &type)
void noneExcept(ParameterSet const &pset, std::string const &psetName, std::string const &type)
void noDuplicates(vString const &v, std::string const &psetName, std::string const &parameterLabel)
void catNoPSets(ParameterSet const &pset, std::string const &psetName, std::string const &categoryName)
void noBadParams(vString const &v, vString const &params, std::string const &psetName, std::string const &parameterLabel, std::string const &type)
void noNonPSetUsage(ParameterSet const &pset, vString const &v, std::string const &psetName, std::string const &parameterLabel)
std::string operator()(ParameterSet const &pset)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
bool validateThreshold(std::string const &thresh, std::string const &psetName)
void noNoncategoryPsets(ParameterSet const &pset, std::string const &psetName)
void catBoolRestriction(ParameterSet const &pset, std::string const &psetName, std::string const &categoryName, std::string const &type)
string end
Definition: dataset.py:937
float x
void categoryPSet(ParameterSet const &pset, std::string const &OuterPsetName, std::string const &categoryName)
void catInts(ParameterSet const &pset, std::string const &psetName, std::string const &categoryName)
long double T