CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/FWCore/MessageService/interface/MessageServicePSetValidation.h

Go to the documentation of this file.
00001 #ifndef FWCore_MessageService_MessageServicePSetValidation_h
00002 #define FWCore_MessageService_MessageServicePSetValidation_h
00003 
00004 // -*- C++ -*-
00005 //
00006 // Package:     Services
00007 // Class  :     MessageServicePSetValidation_h
00008 //
00021 //
00022 // Original Author:  M. Fischler
00023 //         Created:  Tue May 19  2009
00024 //
00025 
00026 // system include files
00027 
00028 #include <string>
00029 #include <sstream>
00030 #include <vector>
00031 
00032 // user include files
00033 
00034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00035 #include "FWCore/Utilities/interface/Exception.h"
00036 
00037 // forward declarations
00038 
00039 namespace edm  {
00040 namespace service  {
00041 
00042 
00043 class MessageServicePSetValidation
00044 {
00045 public:
00046   std::string operator() ( ParameterSet const & pset ); 
00047 private:
00048   typedef std::string          String;
00049   typedef std::vector<String>  vString;
00050 
00051   void messageLoggerPSet ( ParameterSet const & pset ); 
00052   void psetLists ( ParameterSet const & pset ); 
00053   void suppressionLists ( ParameterSet const & pset ); 
00054   bool validateThreshold (std::string const & thresh, 
00055                           std::string const & psetName);
00056   bool checkThreshold (std::string const & thresh);
00057   void noDuplicates(vString const & v, std::string const & psetName,
00058                     std::string  const & parameterLabel );
00059   void noDuplicates(vString const & v1, vString const & v2, 
00060                     std::string const & psetName,
00061                     std::string  const & p1, std::string  const & p2 );
00062   void noCoutCerrClash(vString const & v, std::string const & psetName,
00063                        std::string  const & parameterLabel );
00064   void noKeywords(vString const & v, std::string const & psetName,
00065                   std::string  const & parameterLabel );
00066   bool keywordCheck(std::string const & word);
00067   void noNonPSetUsage( ParameterSet const & pset, 
00068                       vString const & v, std::string const & psetName,
00069                       std::string const & parameterLabel );
00070   void noBadParams(vString const & v, vString const & params, 
00071                    std::string const & psetName, 
00072                    std::string const & parameterLabel, 
00073                    std::string const & type);
00074   void vStringsCheck(ParameterSet const & pset,std::string const & psetName); 
00075   bool wildcard(vString const & v);
00076   bool allowedVstring (std::string const & s);
00077   void noOtherPsets(ParameterSet const & pset); 
00078   void noNoncategoryPsets(ParameterSet const & pset,
00079                           std::string const & psetName);  
00080   bool lookForMatch(vString const & v, std::string const & s);
00081   void destinationPSets(ParameterSet const & pset);
00082   void destinationPSet(ParameterSet const & pset, std::string const & psetName);
00083   void defaultPSet(ParameterSet const & main_pset);
00084   void statisticsPSets(ParameterSet const & pset);
00085   void statisticsPSet(ParameterSet const & pset, std::string const & psetName);
00086   void fwkJobReportPSets(ParameterSet const & pset);
00087   void fwkJobReportPSet(ParameterSet const & pset,std::string const & psetName);
00088   void categoryPSets(ParameterSet const & pset, std::string const & psetName); 
00089   void categoryPSet (ParameterSet const & pset, 
00090                      std::string const & OuterPsetName,
00091                      std::string const & categoryName); 
00092   void catInts (ParameterSet const & pset, 
00093                 std::string const & psetName,
00094                 std::string const & categoryName); 
00095   void catNoPSets (ParameterSet const & pset, 
00096                    std::string const & psetName,
00097                    std::string const & categoryName); 
00098   void catBoolRestriction (ParameterSet const & pset, 
00099                            std::string  const & psetName, 
00100                            std::string  const & categoryName, 
00101                            std::string const & type);
00102 
00103   template <typename T>
00104   T check 
00105       ( ParameterSet const & pset, 
00106         std::string  const & psetName,
00107         std::string  const & parameterLabel ) 
00108   {
00109     T val = T();
00110     try {
00111       if (!pset.exists(parameterLabel)) return val;
00112       if ( pset.existsAs<T> (parameterLabel, false) ) {
00113         val = pset.getUntrackedParameter<T>(parameterLabel, val);
00114         return val;
00115       }
00116       if ( pset.existsAs<T> (parameterLabel, true) )   {
00117         flaws << psetName << " PSet: \n"
00118               << parameterLabel
00119               << " is declared as tracked - needs to be untracked \n";
00120         val = pset.getParameter<T>(parameterLabel);
00121       } else {
00122         flaws << psetName << " PSet: \n"
00123               << parameterLabel 
00124               << " is declared with incorrect type \n";
00125       }
00126       return val;
00127     } catch (cms::Exception& e) {
00128       flaws << psetName << " PSet: \n"
00129             << parameterLabel 
00130             << " is declared but causes an exception when processed: \n"
00131             << e.what() << "\n";
00132       return val;
00133     }
00134   }  // check()
00135 
00136   template <typename T>
00137   void disallowedParam 
00138       ( ParameterSet const & pset,
00139         vString      const & v,
00140         std::string  const & psetName,
00141         std::string  const & parameterLabel,    
00142         std::string  const & type ) 
00143   {
00144     vString params = pset.getParameterNamesForType <T> (true);
00145     noBadParams(v, params, psetName, parameterLabel, type);
00146     params = pset.getParameterNamesForType <T> (false);
00147     noBadParams(v, params, psetName, parameterLabel, type);
00148   }  // disallowedParam()
00149 
00150   template <typename T>
00151   void noneExcept (ParameterSet const & pset, 
00152                 std::string  const & psetName, std::string const & type)
00153   {
00154     vString x = pset.template getParameterNamesForType <T> (false);
00155     vString::const_iterator end = x.end();
00156     for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
00157       flaws << psetName << " PSet: \n"
00158             << (*i) << " is used as a " << type << "\n"
00159             << "Usage of " << type << " is not recognized here\n"; 
00160     }
00161     x = pset.template getParameterNamesForType <T> (true);
00162     end = x.end();
00163     for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
00164       if  ( (*i) == "@service_type" ) continue;    
00165       flaws << psetName << " PSet: \n"
00166             << (*i) << " is used as a tracked " << type << "\n"
00167             << "Tracked parameters not allowed here, "
00168             <<" and even untracked it would not be recognized\n";
00169     }
00170   } // noneExcept()
00171 
00172   template <typename T>
00173   void noneExcept (ParameterSet const & pset, 
00174                 std::string  const & psetName, std::string const & type,
00175                 std::string  const & ok)
00176   {
00177     vString x = pset.template getParameterNamesForType <T> (false);
00178     vString::const_iterator end = x.end();
00179     for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
00180       std::string val = (*i);
00181       if ( val != ok ) {
00182         flaws << psetName << " PSet: \n"
00183               << val << " is used as a " << type << "\n"
00184               << "This usage is not recognized in this type of PSet\n"; 
00185       }
00186     }
00187     x = pset.template getParameterNamesForType <T> (true);
00188     end = x.end();
00189     for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
00190       if  ( (*i) == "@service_type" ) continue;    
00191       flaws << psetName << " PSet: \n"
00192             << (*i) << " is used as a tracked " << type << "\n"
00193             << "Tracked parameters not allowed here\n";
00194     }
00195   } // noneExcept(okValue)
00196 
00197   template <typename T>
00198   void noneExcept (ParameterSet const & pset, 
00199                 std::string  const & psetName, std::string const & type,
00200                 T const & ok1, T const & ok2 )
00201   {
00202     vString x = pset.template getParameterNamesForType <T> (false);
00203     vString::const_iterator end = x.end();
00204     for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
00205       std::string val = (*i);
00206       if ( (val != ok1) && (val != ok2) ) {
00207         flaws << psetName << " PSet: \n"
00208               << val << " is used as a " << type << "\n"
00209               << "This usage is not recognized in this type of PSet\n"; 
00210       }
00211     }
00212     x = pset.template getParameterNamesForType <T> (true);
00213     end = x.end();
00214     for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
00215       if  ( (*i) == "@service_type" ) continue;    
00216       flaws << psetName << " PSet: \n"
00217             << (*i) << " is used as a tracked " << type << "\n"
00218             << "Tracked parameters not allowed here\n";
00219     }
00220   } // noneExcept(okValue1, okValue2)
00221 
00222   template <typename T>
00223   void noneExcept (ParameterSet const & pset, 
00224                 std::string  const & psetName, std::string const & type,
00225                 vString const & vok )
00226   {
00227     vString x = pset.template getParameterNamesForType <T> (false);
00228     vString::const_iterator end = x.end();
00229     vString::const_iterator vend = vok.end();
00230     for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
00231       bool found = false;    
00232       for (vString::const_iterator vit = vok.begin(); vit!=vend; ++vit) {
00233         if ( *i == *vit ) found = true;
00234       }
00235       if ( !found ) {
00236           flaws << psetName << " PSet: \n"
00237                 << *i << " is used as a " << type << "\n"
00238                 << "This usage is not recognized in this type of PSet\n"; 
00239       }
00240     }
00241     x = pset.template getParameterNamesForType <T> (true);
00242     end = x.end();
00243     for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
00244       if  ( (*i) == "@service_type" ) continue;    
00245       flaws << psetName << " PSet: \n"
00246             << (*i) << " is used as a tracked " << type << "\n"
00247             << "Tracked parameters not allowed here\n";
00248     }
00249   } // noneExcept(vok)
00250 
00251   template <typename T>
00252   void catNone (ParameterSet const & pset, 
00253                 std::string  const & psetName, 
00254                 std::string  const & categoryName, 
00255                 std::string const & type)
00256   {
00257     vString x = pset.template getParameterNamesForType <T> (false);
00258     vString::const_iterator end = x.end();
00259     for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
00260       flaws << categoryName << " category PSet nested in "
00261             << psetName << " PSet: \n"
00262             << (*i) << " is used as a " << type << "\n"
00263             << "Usage of " << type << " is not recognized here\n"; 
00264     }
00265     x = pset.template getParameterNamesForType <T> (true);
00266     end = x.end();
00267     for ( vString::const_iterator i = x.begin(); i != end; ++i ) {
00268       flaws << categoryName << " category PSet nested in "
00269             << psetName << " PSet: \n"
00270             << (*i) << " is used as a tracked " << type << "\n"
00271             << "Tracked parameters not allowed here, "
00272             <<" and even untracked it would not be recognized\n";
00273     }
00274   } // catNone()
00275 
00276 
00277 
00278   // private data  
00279   std::ostringstream flaws; 
00280   std::vector<std::string> destinations;
00281   std::vector<std::string> statistics;
00282   std::vector<std::string> fwkJobReports;
00283   std::vector<std::string> categories;
00284   std::vector<std::string> messageIDs;
00285   std::vector<std::string> debugModules;
00286   std::vector<std::string> suppressInfo;
00287   std::vector<std::string> suppressDebug;
00288   std::vector<std::string> suppressWarning;
00289   std::vector<std::string> suppressError;
00290 
00291   
00292 };  // MessageServicePSetValidation
00293 
00294 
00295 }  // namespace service
00296 
00297 }  // namespace edm
00298 
00299 
00300 
00301 #endif  // FWCore_MessageService_MessageServicePSetValidation_h
00302