CMS 3D CMS Logo

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 fwkJobReportPSets(ParameterSet const& pset);
85  void fwkJobReportPSet(ParameterSet const& pset, std::string const& psetName);
86  void categoryPSets(ParameterSet const& pset, std::string const& psetName);
87  void categoryPSet(ParameterSet const& pset, std::string const& OuterPsetName, std::string const& categoryName);
88  void catInts(ParameterSet const& pset, std::string const& psetName, std::string const& categoryName);
89  void catNoPSets(ParameterSet const& pset, std::string const& psetName, std::string const& categoryName);
90  void catBoolRestriction(ParameterSet const& pset,
91  std::string const& psetName,
92  std::string const& categoryName,
93  std::string const& type);
94 
95  template <typename T>
96  T check(ParameterSet const& pset, std::string const& psetName, std::string const& parameterLabel) {
97  T val = T();
98  try {
99  if (!pset.exists(parameterLabel))
100  return val;
101  if (pset.existsAs<T>(parameterLabel, false)) {
102  val = pset.getUntrackedParameter<T>(parameterLabel, val);
103  return val;
104  }
105  if (pset.existsAs<T>(parameterLabel, true)) {
106  flaws << psetName << " PSet: \n" << parameterLabel << " is declared as tracked - needs to be untracked \n";
107  val = pset.getParameter<T>(parameterLabel);
108  } else {
109  flaws << psetName << " PSet: \n" << parameterLabel << " is declared with incorrect type \n";
110  }
111  return val;
112  } catch (cms::Exception& e) {
113  flaws << psetName << " PSet: \n"
114  << parameterLabel << " is declared but causes an exception when processed: \n"
115  << e.what() << "\n";
116  return val;
117  }
118  } // check()
119 
120  template <typename T>
121  void disallowedParam(ParameterSet const& pset,
122  vString const& v,
123  std::string const& psetName,
124  std::string const& parameterLabel,
125  std::string const& type) {
126  vString params = pset.getParameterNamesForType<T>(true);
127  noBadParams(v, params, psetName, parameterLabel, type);
128  params = pset.getParameterNamesForType<T>(false);
129  noBadParams(v, params, psetName, parameterLabel, type);
130  } // disallowedParam()
131 
132  template <typename T>
133  void noneExcept(ParameterSet const& pset, std::string const& psetName, std::string const& type) {
134  vString x = pset.template getParameterNamesForType<T>(false);
135  vString::const_iterator end = x.end();
136  for (vString::const_iterator i = x.begin(); i != end; ++i) {
137  flaws << psetName << " PSet: \n"
138  << (*i) << " is used as a " << type << "\n"
139  << "Usage of " << type << " is not recognized here\n";
140  }
141  x = pset.template getParameterNamesForType<T>(true);
142  end = x.end();
143  for (vString::const_iterator i = x.begin(); i != end; ++i) {
144  if ((*i) == "@service_type")
145  continue;
146  flaws << psetName << " PSet: \n"
147  << (*i) << " is used as a tracked " << type << "\n"
148  << "Tracked parameters not allowed here, "
149  << " and even untracked it would not be recognized\n";
150  }
151  } // noneExcept()
152 
153  template <typename T>
154  void noneExcept(ParameterSet const& pset,
155  std::string const& psetName,
156  std::string const& type,
157  std::string const& ok) {
158  vString x = pset.template getParameterNamesForType<T>(false);
159  vString::const_iterator end = x.end();
160  for (vString::const_iterator i = x.begin(); i != end; ++i) {
161  std::string val = (*i);
162  if (val != ok) {
163  flaws << psetName << " PSet: \n"
164  << val << " is used as a " << type << "\n"
165  << "This usage is not recognized in this type of PSet\n";
166  }
167  }
168  x = pset.template getParameterNamesForType<T>(true);
169  end = x.end();
170  for (vString::const_iterator i = x.begin(); i != end; ++i) {
171  if ((*i) == "@service_type")
172  continue;
173  flaws << psetName << " PSet: \n"
174  << (*i) << " is used as a tracked " << type << "\n"
175  << "Tracked parameters not allowed here\n";
176  }
177  } // noneExcept(okValue)
178 
179  template <typename T>
181  ParameterSet const& pset, std::string const& psetName, std::string const& type, T const& ok1, T const& ok2) {
182  vString x = pset.template getParameterNamesForType<T>(false);
183  vString::const_iterator end = x.end();
184  for (vString::const_iterator i = x.begin(); i != end; ++i) {
185  std::string val = (*i);
186  if ((val != ok1) && (val != ok2)) {
187  flaws << psetName << " PSet: \n"
188  << val << " is used as a " << type << "\n"
189  << "This usage is not recognized in this type of PSet\n";
190  }
191  }
192  x = pset.template getParameterNamesForType<T>(true);
193  end = x.end();
194  for (vString::const_iterator i = x.begin(); i != end; ++i) {
195  if ((*i) == "@service_type")
196  continue;
197  flaws << psetName << " PSet: \n"
198  << (*i) << " is used as a tracked " << type << "\n"
199  << "Tracked parameters not allowed here\n";
200  }
201  } // noneExcept(okValue1, okValue2)
202 
203  template <typename T>
204  void noneExcept(ParameterSet const& pset,
205  std::string const& psetName,
206  std::string const& type,
207  vString const& vok) {
208  vString x = pset.template getParameterNamesForType<T>(false);
209  vString::const_iterator end = x.end();
210  vString::const_iterator vend = vok.end();
211  for (vString::const_iterator i = x.begin(); i != end; ++i) {
212  bool found = false;
213  for (vString::const_iterator vit = vok.begin(); vit != vend; ++vit) {
214  if (*i == *vit)
215  found = true;
216  }
217  if (!found) {
218  flaws << psetName << " PSet: \n"
219  << *i << " is used as a " << type << "\n"
220  << "This usage is not recognized in this type of PSet\n";
221  }
222  }
223  x = pset.template getParameterNamesForType<T>(true);
224  end = x.end();
225  for (vString::const_iterator i = x.begin(); i != end; ++i) {
226  if ((*i) == "@service_type")
227  continue;
228  flaws << psetName << " PSet: \n"
229  << (*i) << " is used as a tracked " << type << "\n"
230  << "Tracked parameters not allowed here\n";
231  }
232  } // noneExcept(vok)
233 
234  template <typename T>
235  void catNone(ParameterSet const& pset,
236  std::string const& psetName,
237  std::string const& categoryName,
238  std::string const& type) {
239  vString x = pset.template getParameterNamesForType<T>(false);
240  vString::const_iterator end = x.end();
241  for (vString::const_iterator i = x.begin(); i != end; ++i) {
242  flaws << categoryName << " category PSet nested in " << psetName << " PSet: \n"
243  << (*i) << " is used as a " << type << "\n"
244  << "Usage of " << type << " is not recognized here\n";
245  }
246  x = pset.template getParameterNamesForType<T>(true);
247  end = x.end();
248  for (vString::const_iterator i = x.begin(); i != end; ++i) {
249  flaws << categoryName << " category PSet nested in " << psetName << " PSet: \n"
250  << (*i) << " is used as a tracked " << type << "\n"
251  << "Tracked parameters not allowed here, "
252  << " and even untracked it would not be recognized\n";
253  }
254  } // catNone()
255 
256  // private data
257  std::ostringstream flaws;
258  std::vector<std::string> destinations;
259  std::vector<std::string> statistics;
260  std::vector<std::string> fwkJobReports;
261  std::vector<std::string> categories;
262  std::vector<std::string> messageIDs;
263  std::vector<std::string> debugModules;
264  std::vector<std::string> suppressInfo;
265  std::vector<std::string> suppressDebug;
266  std::vector<std::string> suppressWarning;
267  std::vector<std::string> suppressError;
268 
269  }; // MessageServicePSetValidation
270 
271  } // namespace service
272 
273 } // namespace edm
274 
275 #endif // FWCore_MessageService_MessageServicePSetValidation_h
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
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:161
bool lookForMatch(vString const &v, std::string const &s)
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
char const * what() const override
Definition: Exception.cc:103
#define vend()
Definition: vmac.h:43
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:169
void fwkJobReportPSet(ParameterSet const &pset, std::string const &psetName)
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)
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)
#define end
Definition: vmac.h:39
double p2[4]
Definition: TauolaWrapper.h:90
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)
bool validateThreshold(std::string const &thresh, std::string const &psetName)
void noNoncategoryPsets(ParameterSet const &pset, std::string const &psetName)
HLT enums.
double p1[4]
Definition: TauolaWrapper.h:89
void catBoolRestriction(ParameterSet const &pset, std::string const &psetName, std::string const &categoryName, std::string const &type)
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