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 
42 
44 {
45 public:
47 private:
49  typedef std::vector<String> vString;
50 
51  void messageLoggerPSet ( ParameterSet const & pset );
52  void psetLists ( ParameterSet const & pset );
53  void suppressionLists ( ParameterSet const & pset );
54  bool validateThreshold (std::string const & thresh,
55  std::string const & psetName);
56  bool checkThreshold (std::string const & thresh);
57  void noDuplicates(vString const & v, std::string const & psetName,
58  std::string const & parameterLabel );
59  void noDuplicates(vString const & v1, vString const & v2,
60  std::string const & psetName,
61  std::string const & p1, std::string const & p2 );
62  void noCoutCerrClash(vString const & v, std::string const & psetName,
63  std::string const & parameterLabel );
64  void noKeywords(vString const & v, std::string const & psetName,
65  std::string const & parameterLabel );
66  bool keywordCheck(std::string const & word);
67  void noNonPSetUsage( ParameterSet const & pset,
68  vString const & v, std::string const & psetName,
69  std::string const & parameterLabel );
70  void noBadParams(vString const & v, vString const & params,
71  std::string const & psetName,
72  std::string const & parameterLabel,
73  std::string const & type);
74  void vStringsCheck(ParameterSet const & pset,std::string const & psetName);
75  bool wildcard(vString const & v);
76  bool allowedVstring (std::string const & s);
77  void noOtherPsets(ParameterSet const & pset);
78  void noNoncategoryPsets(ParameterSet const & pset,
79  std::string const & psetName);
80  bool lookForMatch(vString const & v, std::string const & s);
81  void destinationPSets(ParameterSet const & pset);
82  void destinationPSet(ParameterSet const & pset, std::string const & psetName);
83  void defaultPSet(ParameterSet const & main_pset);
84  void statisticsPSets(ParameterSet const & pset);
85  void statisticsPSet(ParameterSet const & pset, std::string const & psetName);
86  void fwkJobReportPSets(ParameterSet const & pset);
87  void fwkJobReportPSet(ParameterSet const & pset,std::string const & psetName);
88  void categoryPSets(ParameterSet const & pset, std::string const & psetName);
89  void categoryPSet (ParameterSet const & pset,
90  std::string const & OuterPsetName,
91  std::string const & categoryName);
92  void catInts (ParameterSet const & pset,
93  std::string const & psetName,
94  std::string const & categoryName);
95  void catNoPSets (ParameterSet const & pset,
96  std::string const & psetName,
97  std::string const & categoryName);
98  void catBoolRestriction (ParameterSet const & pset,
99  std::string const & psetName,
100  std::string const & categoryName,
101  std::string const & type);
102 
103  template <typename T>
104  T check
105  ( ParameterSet const & pset,
106  std::string const & psetName,
107  std::string const & parameterLabel )
108  {
109  T val = T();
110  try {
111  if (!pset.exists(parameterLabel)) return val;
112  if ( pset.existsAs<T> (parameterLabel, false) ) {
113  val = pset.getUntrackedParameter<T>(parameterLabel, val);
114  return val;
115  }
116  if ( pset.existsAs<T> (parameterLabel, true) ) {
117  flaws << psetName << " PSet: \n"
118  << parameterLabel
119  << " is declared as tracked - needs to be untracked \n";
120  val = pset.getParameter<T>(parameterLabel);
121  } else {
122  flaws << psetName << " PSet: \n"
123  << parameterLabel
124  << " is declared with incorrect type \n";
125  }
126  return val;
127  } catch (cms::Exception& e) {
128  flaws << psetName << " PSet: \n"
129  << parameterLabel
130  << " is declared but causes an exception when processed: \n"
131  << e.what() << "\n";
132  return val;
133  }
134  } // check()
135 
136  template <typename T>
137  void disallowedParam
138  ( ParameterSet const & pset,
139  vString const & v,
140  std::string const & psetName,
141  std::string const & parameterLabel,
142  std::string const & type )
143  {
144  vString params = pset.getParameterNamesForType <T> (true);
145  noBadParams(v, params, psetName, parameterLabel, type);
146  params = pset.getParameterNamesForType <T> (false);
147  noBadParams(v, params, psetName, parameterLabel, type);
148  } // disallowedParam()
149 
150  template <typename T>
151  void noneExcept (ParameterSet const & pset,
152  std::string const & psetName, std::string const & type)
153  {
154  vString x = pset.template getParameterNamesForType <T> (false);
155  vString::const_iterator end = x.end();
156  for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
157  flaws << psetName << " PSet: \n"
158  << (*i) << " is used as a " << type << "\n"
159  << "Usage of " << type << " is not recognized here\n";
160  }
161  x = pset.template getParameterNamesForType <T> (true);
162  end = x.end();
163  for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
164  if ( (*i) == "@service_type" ) continue;
165  flaws << psetName << " PSet: \n"
166  << (*i) << " is used as a tracked " << type << "\n"
167  << "Tracked parameters not allowed here, "
168  <<" and even untracked it would not be recognized\n";
169  }
170  } // noneExcept()
171 
172  template <typename T>
173  void noneExcept (ParameterSet const & pset,
174  std::string const & psetName, std::string const & type,
175  std::string const & ok)
176  {
177  vString x = pset.template getParameterNamesForType <T> (false);
178  vString::const_iterator end = x.end();
179  for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
180  std::string val = (*i);
181  if ( val != ok ) {
182  flaws << psetName << " PSet: \n"
183  << val << " is used as a " << type << "\n"
184  << "This usage is not recognized in this type of PSet\n";
185  }
186  }
187  x = pset.template getParameterNamesForType <T> (true);
188  end = x.end();
189  for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
190  if ( (*i) == "@service_type" ) continue;
191  flaws << psetName << " PSet: \n"
192  << (*i) << " is used as a tracked " << type << "\n"
193  << "Tracked parameters not allowed here\n";
194  }
195  } // noneExcept(okValue)
196 
197  template <typename T>
198  void noneExcept (ParameterSet const & pset,
199  std::string const & psetName, std::string const & type,
200  T const & ok1, T const & ok2 )
201  {
202  vString x = pset.template getParameterNamesForType <T> (false);
203  vString::const_iterator end = x.end();
204  for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
205  std::string val = (*i);
206  if ( (val != ok1) && (val != ok2) ) {
207  flaws << psetName << " PSet: \n"
208  << val << " is used as a " << type << "\n"
209  << "This usage is not recognized in this type of PSet\n";
210  }
211  }
212  x = pset.template getParameterNamesForType <T> (true);
213  end = x.end();
214  for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
215  if ( (*i) == "@service_type" ) continue;
216  flaws << psetName << " PSet: \n"
217  << (*i) << " is used as a tracked " << type << "\n"
218  << "Tracked parameters not allowed here\n";
219  }
220  } // noneExcept(okValue1, okValue2)
221 
222  template <typename T>
223  void noneExcept (ParameterSet const & pset,
224  std::string const & psetName, std::string const & type,
225  vString const & vok )
226  {
227  vString x = pset.template getParameterNamesForType <T> (false);
228  vString::const_iterator end = x.end();
229  vString::const_iterator vend = vok.end();
230  for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
231  bool found = false;
232  for (vString::const_iterator vit = vok.begin(); vit!=vend; ++vit) {
233  if ( *i == *vit ) found = true;
234  }
235  if ( !found ) {
236  flaws << psetName << " PSet: \n"
237  << *i << " is used as a " << type << "\n"
238  << "This usage is not recognized in this type of PSet\n";
239  }
240  }
241  x = pset.template getParameterNamesForType <T> (true);
242  end = x.end();
243  for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
244  if ( (*i) == "@service_type" ) continue;
245  flaws << psetName << " PSet: \n"
246  << (*i) << " is used as a tracked " << type << "\n"
247  << "Tracked parameters not allowed here\n";
248  }
249  } // noneExcept(vok)
250 
251  template <typename T>
252  void catNone (ParameterSet const & pset,
253  std::string const & psetName,
254  std::string const & categoryName,
255  std::string const & type)
256  {
257  vString x = pset.template getParameterNamesForType <T> (false);
258  vString::const_iterator end = x.end();
259  for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
260  flaws << categoryName << " category PSet nested in "
261  << psetName << " PSet: \n"
262  << (*i) << " is used as a " << type << "\n"
263  << "Usage of " << type << " is not recognized here\n";
264  }
265  x = pset.template getParameterNamesForType <T> (true);
266  end = x.end();
267  for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
268  flaws << categoryName << " category PSet nested in "
269  << psetName << " PSet: \n"
270  << (*i) << " is used as a tracked " << type << "\n"
271  << "Tracked parameters not allowed here, "
272  <<" and even untracked it would not be recognized\n";
273  }
274  } // catNone()
275 
276 
277 
278  // private data
279  std::ostringstream flaws;
280  std::vector<std::string> destinations;
281  std::vector<std::string> statistics;
282  std::vector<std::string> fwkJobReports;
283  std::vector<std::string> categories;
284  std::vector<std::string> messageIDs;
285  std::vector<std::string> debugModules;
286  std::vector<std::string> suppressInfo;
287  std::vector<std::string> suppressDebug;
288  std::vector<std::string> suppressWarning;
289  std::vector<std::string> suppressError;
290 
291 
292 }; // MessageServicePSetValidation
293 
294 
295 } // namespace service
296 
297 } // namespace edm
298 
299 
300 
301 #endif // FWCore_MessageService_MessageServicePSetValidation_h
302 
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:186
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:141
#define vend()
Definition: vmac.h:41
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:194
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:37
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