CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/FWCore/MessageLogger/src/ELseverityLevel.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 //
00003 // ELseverityLevel.cc - implement objects that encode a message's urgency
00004 //
00005 //      Both frameworker and user will often pass one of the
00006 //      instantiated severity levels to logger methods.
00007 //
00008 //      The only other methods of ELseverityLevel a frameworker
00009 //      might use is to check the relative level of two severities
00010 //      using operator<() or the like.
00011 //
00012 // 29-Jun-1998 mf       Created file.
00013 // 26-Aug-1998 WEB      Made ELseverityLevel object less weighty.
00014 // 16-Jun-1999 mf       Added constructor from string, plus two lists
00015 //                      of names to match.  Also added default constructor,
00016 //                      more streamlined than default lev on original.
00017 // 23-Jun-1999 mf       Modifications to properly handle pre-main order
00018 //                      of initialization issues:
00019 //                              Instantiation ofthe 14 const ELseverity &'s
00020 //                              Instantiation of objectsInitialized as false
00021 //                              Constructor of ELinitializeGlobalSeverityObjects
00022 //                              Removed guarantor function in favor of the
00023 //                              constructor.
00024 // 30-Jun-1999 mf       Modifications to eliminate propblems with order of
00025 //                      globals initializations:
00026 //                              Constructor from lev calls translate()
00027 //                              Constructor from string uses translate()
00028 //                              translate() method
00029 //                              List of strings for names in side getname() etc.
00030 //                              Immediate initilization of ELsevLevGlobals
00031 //                              Mods involving ELinitializeGlobalSeverityObjects
00032 // 12-Jun-2000 web      Final fix to global static initialization problem
00033 // 27-Jun-2000 web      Fix order-of-static-destruction problem
00034 // 24-Aug-2000 web      Fix defective C++ switch generation
00035 // 13-Jun-2007 mf       Change (requested by CMS) the name Severe to System
00036 //                      (since that his how MessageLogger uses that level)
00037 // 21-Apr-2009 mf       Change the symbol for ELsev_success (which is used
00038 //                      by CMS for LogDebug) from -! to -d.  
00039 // ----------------------------------------------------------------------
00040 
00041 #include <ostream>
00042 
00043 #include "FWCore/MessageLogger/interface/ELseverityLevel.h"
00044 #include "FWCore/MessageLogger/interface/ELmap.h"
00045 
00046 
00047 // Possible Traces
00048 // #define ELsevConTRACE
00049 
00050 
00051 namespace edm
00052 {
00053 
00054 
00055 // ----------------------------------------------------------------------
00056 // Helper to construct the string->ELsev_ map on demand:
00057 // ----------------------------------------------------------------------
00058 
00059 typedef std::map< ELstring const, ELseverityLevel::ELsev_ > ELmap;
00060 
00061 static
00062 ELmap const &  loadMap()  {
00063 
00064   static ELmap  m;
00065 
00066 
00067     m[ ELzeroSeverity.getSymbol()   ] = ELseverityLevel::ELsev_zeroSeverity
00068   , m[ ELzeroSeverity.getName()     ] = ELseverityLevel::ELsev_zeroSeverity
00069   , m[ ELzeroSeverity.getInputStr() ] = ELseverityLevel::ELsev_zeroSeverity
00070   , m[ ELzeroSeverity.getVarName()  ] = ELseverityLevel::ELsev_zeroSeverity
00071   ;
00072 
00073     m[ ELincidental.getSymbol()   ] = ELseverityLevel::ELsev_incidental
00074   , m[ ELincidental.getName()     ] = ELseverityLevel::ELsev_incidental
00075   , m[ ELincidental.getInputStr() ] = ELseverityLevel::ELsev_incidental
00076   , m[ ELincidental.getVarName()  ] = ELseverityLevel::ELsev_incidental
00077   ;
00078 
00079     m[ ELsuccess.getSymbol()   ] = ELseverityLevel::ELsev_success
00080   , m[ ELsuccess.getName()     ] = ELseverityLevel::ELsev_success
00081   , m[ ELsuccess.getInputStr() ] = ELseverityLevel::ELsev_success
00082   , m[ ELsuccess.getVarName()  ] = ELseverityLevel::ELsev_success
00083   ;
00084 
00085     m[ ELinfo.getSymbol()   ] = ELseverityLevel::ELsev_info
00086   , m[ ELinfo.getName()     ] = ELseverityLevel::ELsev_info
00087   , m[ ELinfo.getInputStr() ] = ELseverityLevel::ELsev_info
00088   , m[ ELinfo.getVarName()  ] = ELseverityLevel::ELsev_info
00089   ;
00090 
00091     m[ ELwarning.getSymbol()   ] = ELseverityLevel::ELsev_warning
00092   , m[ ELwarning.getName()     ] = ELseverityLevel::ELsev_warning
00093   , m[ ELwarning.getInputStr() ] = ELseverityLevel::ELsev_warning
00094   , m[ ELwarning.getVarName()  ] = ELseverityLevel::ELsev_warning
00095   ;
00096 
00097     m[ ELwarning2.getSymbol()   ] = ELseverityLevel::ELsev_warning2
00098   , m[ ELwarning2.getName()     ] = ELseverityLevel::ELsev_warning2
00099   , m[ ELwarning2.getInputStr() ] = ELseverityLevel::ELsev_warning2
00100   , m[ ELwarning2.getVarName()  ] = ELseverityLevel::ELsev_warning2
00101   ;
00102 
00103     m[ ELerror.getSymbol()   ] = ELseverityLevel::ELsev_error
00104   , m[ ELerror.getName()     ] = ELseverityLevel::ELsev_error
00105   , m[ ELerror.getInputStr() ] = ELseverityLevel::ELsev_error
00106   , m[ ELerror.getVarName()  ] = ELseverityLevel::ELsev_error
00107   ;
00108 
00109     m[ ELerror2.getSymbol()   ] = ELseverityLevel::ELsev_error2
00110   , m[ ELerror2.getName()     ] = ELseverityLevel::ELsev_error2
00111   , m[ ELerror2.getInputStr() ] = ELseverityLevel::ELsev_error2
00112   , m[ ELerror2.getVarName()  ] = ELseverityLevel::ELsev_error2
00113   ;
00114 
00115     m[ ELnextEvent.getSymbol()   ] = ELseverityLevel::ELsev_next
00116   , m[ ELnextEvent.getName()     ] = ELseverityLevel::ELsev_next
00117   , m[ ELnextEvent.getInputStr() ] = ELseverityLevel::ELsev_next
00118   , m[ ELnextEvent.getVarName()  ] = ELseverityLevel::ELsev_next
00119   ;
00120 
00121     m[ ELunspecified.getSymbol()   ] = ELseverityLevel::ELsev_unspecified
00122   , m[ ELunspecified.getName()     ] = ELseverityLevel::ELsev_unspecified
00123   , m[ ELunspecified.getInputStr() ] = ELseverityLevel::ELsev_unspecified
00124   , m[ ELunspecified.getVarName()  ] = ELseverityLevel::ELsev_unspecified
00125   ;
00126 
00127     m[ ELsevere.getSymbol()   ] = ELseverityLevel::ELsev_severe
00128   , m[ ELsevere.getName()     ] = ELseverityLevel::ELsev_severe
00129   , m[ ELsevere.getInputStr() ] = ELseverityLevel::ELsev_severe
00130   , m[ ELsevere.getVarName()  ] = ELseverityLevel::ELsev_severe
00131   ;
00132 
00133     m[ ELsevere2.getSymbol()   ] = ELseverityLevel::ELsev_severe2
00134   , m[ ELsevere2.getName()     ] = ELseverityLevel::ELsev_severe2
00135   , m[ ELsevere2.getInputStr() ] = ELseverityLevel::ELsev_severe2
00136   , m[ ELsevere2.getVarName()  ] = ELseverityLevel::ELsev_severe2
00137   ;
00138 
00139     m[ ELabort.getSymbol()   ] = ELseverityLevel::ELsev_abort
00140   , m[ ELabort.getName()     ] = ELseverityLevel::ELsev_abort
00141   , m[ ELabort.getInputStr() ] = ELseverityLevel::ELsev_abort
00142   , m[ ELabort.getVarName()  ] = ELseverityLevel::ELsev_abort
00143   ;
00144 
00145     m[ ELfatal.getSymbol()   ] = ELseverityLevel::ELsev_fatal
00146   , m[ ELfatal.getName()     ] = ELseverityLevel::ELsev_fatal
00147   , m[ ELfatal.getInputStr() ] = ELseverityLevel::ELsev_fatal
00148   , m[ ELfatal.getVarName()  ] = ELseverityLevel::ELsev_fatal
00149   ;
00150 
00151     m[ ELhighestSeverity.getSymbol()   ] = ELseverityLevel::ELsev_highestSeverity
00152   , m[ ELhighestSeverity.getName()     ] = ELseverityLevel::ELsev_highestSeverity
00153   , m[ ELhighestSeverity.getInputStr() ] = ELseverityLevel::ELsev_highestSeverity
00154   , m[ ELhighestSeverity.getVarName()  ] = ELseverityLevel::ELsev_highestSeverity
00155   ;
00156 
00157   return m;
00158 
00159 }
00160 
00161 
00162 // ----------------------------------------------------------------------
00163 // Birth/death:
00164 // ----------------------------------------------------------------------
00165 
00166 ELseverityLevel::ELseverityLevel( enum ELsev_ lev ) : myLevel( lev )  {
00167 
00168   #ifdef ELsevConTRACE
00169     std::cerr << "--- ELseverityLevel " << lev
00170               << " (" << getName() << ")\n"
00171               << std::flush;
00172   #endif
00173 
00174 }
00175 
00176 
00177 ELseverityLevel::ELseverityLevel( ELstring const & s )  {
00178 
00179   static ELmap const & m = loadMap();
00180 
00181   ELmap::const_iterator  i = m.find( s );
00182   myLevel = ( i == m.end() ) ? ELsev_unspecified : i->second;
00183 
00184 }
00185 
00186 
00187 ELseverityLevel::~ELseverityLevel()  { ; }
00188 
00189 
00190 // ----------------------------------------------------------------------
00191 // Comparator:
00192 // ----------------------------------------------------------------------
00193 
00194 int  ELseverityLevel::cmp( ELseverityLevel const & e ) const  {
00195   return myLevel - e.myLevel;
00196 }
00197 
00198 
00199 // ----------------------------------------------------------------------
00200 // Accessors:
00201 // ----------------------------------------------------------------------
00202 
00203 int  ELseverityLevel::getLevel()  const  {
00204   return  myLevel;
00205 }
00206 
00207 
00208 const ELstring  ELseverityLevel::getSymbol() const  {
00209   ELstring  result;
00210 
00211   switch ( myLevel )  {
00212     default                   :  result =  "0" ; break;
00213     case ELsev_zeroSeverity   :  result =  "--"; break;
00214     case ELsev_incidental     :  result =  ".."; break;
00215     case ELsev_success        :  result =  "-d"; break;         // 4/21/09 mf
00216     case ELsev_info           :  result =  "-i"; break;
00217     case ELsev_warning        :  result =  "-w"; break;
00218     case ELsev_warning2       :  result =  "-W"; break;
00219     case ELsev_error          :  result =  "-e"; break;
00220     case ELsev_error2         :  result =  "-E"; break;
00221     case ELsev_next           :  result =  "-n"; break;
00222     case ELsev_unspecified    :  result =  "??"; break;
00223     case ELsev_severe         :  result =  "-s"; break;
00224     case ELsev_severe2        :  result =  "-S"; break;
00225     case ELsev_abort          :  result =  "-A"; break;
00226     case ELsev_fatal          :  result =  "-F"; break;
00227     case ELsev_highestSeverity:  result =  "!!"; break;
00228   };  // switch
00229 
00230   return result;
00231 }
00232 
00233 
00234 const ELstring  ELseverityLevel::getName() const  {
00235   ELstring  result;
00236 
00237   switch ( myLevel )  {
00238     default                   :  result =  "?no value?"; break;
00239     case ELsev_zeroSeverity   :  result =  "--"        ; break;
00240     case ELsev_incidental     :  result =  ".."        ; break;
00241     case ELsev_success        :  result =  "Debug"     ; break; // 4/21/09 mf
00242     case ELsev_info           :  result =  "Info"      ; break;
00243     case ELsev_warning        :  result =  "Warning"   ; break;
00244     case ELsev_warning2       :  result =  "Warning!"  ; break;
00245     case ELsev_error          :  result =  "Error"     ; break;
00246     case ELsev_error2         :  result =  "Error!"    ; break;
00247     case ELsev_next           :  result =  "Next"      ; break;
00248     case ELsev_unspecified    :  result =  "??"        ; break;
00249     case ELsev_severe         :  result =  "System"    ; break; // 6/13/07 mf
00250     case ELsev_severe2        :  result =  "Severe!"   ; break;
00251     case ELsev_abort          :  result =  "Abort!"    ; break;
00252     case ELsev_fatal          :  result =  "Fatal!"    ; break;
00253     case ELsev_highestSeverity:  result =  "!!"        ; break;
00254   };  // switch
00255 
00256   return result;
00257 }
00258 
00259 
00260 const ELstring  ELseverityLevel::getInputStr() const  {
00261   ELstring  result;
00262 
00263   switch ( myLevel )  {
00264     default                   : result =  "?no value?" ; break;
00265     case ELsev_zeroSeverity   : result =  "ZERO"       ; break;
00266     case ELsev_incidental     : result =  "INCIDENTAL" ; break;
00267     case ELsev_success        : result =  "DEBUG"      ; break;
00268     case ELsev_info           : result =  "INFO"       ; break;
00269     case ELsev_warning        : result =  "WARNING"    ; break;
00270     case ELsev_warning2       : result =  "WARNING2"   ; break;
00271     case ELsev_error          : result =  "ERROR"      ; break;
00272     case ELsev_error2         : result =  "ERROR2"     ; break;
00273     case ELsev_next           : result =  "NEXT"       ; break;
00274     case ELsev_unspecified    : result =  "UNSPECIFIED"; break;
00275     case ELsev_severe         : result =  "SYSTEM"     ; break;  // 6/13/07 mf
00276     case ELsev_severe2        : result =  "SEVERE2"    ; break;
00277     case ELsev_abort          : result =  "ABORT"      ; break;
00278     case ELsev_fatal          : result =  "FATAL"      ; break;
00279     case ELsev_highestSeverity: result =  "HIGHEST"    ; break;
00280   };  // switch
00281 
00282   return result;
00283 }
00284 
00285 
00286 const ELstring  ELseverityLevel::getVarName() const  {
00287   ELstring  result;
00288 
00289   switch ( myLevel )  {
00290     default                   : result =  "?no value?       "; break;
00291     case ELsev_zeroSeverity   : result =  "ELzeroSeverity   "; break;
00292     case ELsev_incidental     : result =  "ELincidental     "; break;
00293     case ELsev_success        : result =  "ELdebug          "; break;// 4/21/09
00294     case ELsev_info           : result =  "ELinfo           "; break;
00295     case ELsev_warning        : result =  "ELwarning        "; break;
00296     case ELsev_warning2       : result =  "ELwarning2       "; break;
00297     case ELsev_error          : result =  "ELerror          "; break;
00298     case ELsev_error2         : result =  "ELerror2         "; break;
00299     case ELsev_next           : result =  "ELnextEvent      "; break;
00300     case ELsev_unspecified    : result =  "ELunspecified    "; break;
00301     case ELsev_severe         : result =  "ELsystem         "; break;// 6/13/07
00302     case ELsev_severe2        : result =  "ELsevere2        "; break;
00303     case ELsev_abort          : result =  "ELabort          "; break;
00304     case ELsev_fatal          : result =  "ELfatal          "; break;
00305     case ELsev_highestSeverity: result =  "ELhighestSeverity"; break;
00306   };  // switch
00307 
00308   return result;
00309 }
00310 
00311 
00312 // ----------------------------------------------------------------------
00313 // Emitter:
00314 // ----------------------------------------------------------------------
00315 
00316 std::ostream & operator<<( std::ostream & os, const ELseverityLevel & sev )  {
00317   return os << " -" << sev.getName() << "- ";
00318 }
00319 
00320 
00321 // ----------------------------------------------------------------------
00322 // Declare the globally available severity objects,
00323 // one generator function and one proxy per non-default ELsev_:
00324 // ----------------------------------------------------------------------
00325 
00326 ELseverityLevel const  ELzeroSeverityGen()  {
00327   static ELseverityLevel const  e( ELseverityLevel::ELsev_zeroSeverity );
00328   return e;
00329 }
00330 ELslProxy< ELzeroSeverityGen    > const  ELzeroSeverity;
00331 
00332 ELseverityLevel const  ELincidentalGen()  {
00333   static ELseverityLevel const  e( ELseverityLevel::ELsev_incidental );
00334   return e;
00335 }
00336 ELslProxy< ELincidentalGen      > const  ELincidental;
00337 
00338 ELseverityLevel const  ELsuccessGen()  {
00339   static ELseverityLevel const  e( ELseverityLevel::ELsev_success );
00340   return e;
00341 }
00342 ELslProxy< ELsuccessGen         > const  ELsuccess;
00343 
00344 ELseverityLevel const  ELinfoGen()  {
00345   static ELseverityLevel const  e( ELseverityLevel::ELsev_info );
00346   return e;
00347 }
00348 ELslProxy< ELinfoGen            > const  ELinfo;
00349 
00350 ELseverityLevel const  ELwarningGen()  {
00351   static ELseverityLevel const  e( ELseverityLevel::ELsev_warning );
00352   return e;
00353 }
00354 ELslProxy< ELwarningGen         > const  ELwarning;
00355 
00356 ELseverityLevel const  ELwarning2Gen()  {
00357   static ELseverityLevel const  e( ELseverityLevel::ELsev_warning2 );
00358   return e;
00359 }
00360 ELslProxy< ELwarning2Gen        > const  ELwarning2;
00361 
00362 ELseverityLevel const  ELerrorGen()  {
00363   static ELseverityLevel const  e( ELseverityLevel::ELsev_error );
00364   return e;
00365 }
00366 ELslProxy< ELerrorGen           > const  ELerror;
00367 
00368 ELseverityLevel const  ELerror2Gen()  {
00369   static ELseverityLevel const  e( ELseverityLevel::ELsev_error2 );
00370   return e;
00371 }
00372 ELslProxy< ELerror2Gen          > const  ELerror2;
00373 
00374 ELseverityLevel const  ELnextEventGen()  {
00375   static ELseverityLevel const  e( ELseverityLevel::ELsev_next );
00376   return e;
00377 }
00378 ELslProxy< ELnextEventGen       > const  ELnextEvent;
00379 
00380 ELseverityLevel const  ELunspecifiedGen()  {
00381   static ELseverityLevel const  e( ELseverityLevel::ELsev_unspecified );
00382   return e;
00383 }
00384 ELslProxy< ELunspecifiedGen     > const  ELunspecified;
00385 
00386 ELseverityLevel const  ELsevereGen()  {
00387   static ELseverityLevel const  e( ELseverityLevel::ELsev_severe );
00388   return e;
00389 }
00390 ELslProxy< ELsevereGen          > const  ELsevere;
00391 
00392 ELseverityLevel const  ELsevere2Gen()  {
00393   static ELseverityLevel const  e( ELseverityLevel::ELsev_severe2 );
00394   return e;
00395 }
00396 ELslProxy< ELsevere2Gen         > const  ELsevere2;
00397 
00398 ELseverityLevel const  ELabortGen()  {
00399   static ELseverityLevel const  e( ELseverityLevel::ELsev_abort );
00400   return e;
00401 }
00402 ELslProxy< ELabortGen           > const  ELabort;
00403 
00404 ELseverityLevel const  ELfatalGen()  {
00405   static ELseverityLevel const  e( ELseverityLevel::ELsev_fatal );
00406   return e;
00407 }
00408 ELslProxy< ELfatalGen           > const  ELfatal;
00409 
00410 ELseverityLevel const  ELhighestSeverityGen()  {
00411   static ELseverityLevel const  e( ELseverityLevel::ELsev_highestSeverity );
00412   return e;
00413 }
00414 ELslProxy< ELhighestSeverityGen > const  ELhighestSeverity;
00415 
00416 // ----------------------------------------------------------------------
00417 
00418 
00419 } // end of namespace edm  */