Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-03 00:59:03

0001 // ----------------------------------------------------------------------
0002 //
0003 // ELseverityLevel.cc - implement objects that encode a message's urgency
0004 //
0005 //      Both frameworker and user will often pass one of the
0006 //      instantiated severity levels to logger methods.
0007 //
0008 //      The only other methods of ELseverityLevel a frameworker
0009 //      might use is to check the relative level of two severities
0010 //      using operator<() or the like.
0011 //
0012 // ----------------------------------------------------------------------
0013 
0014 #include <array>
0015 #include <cassert>
0016 #include <ostream>
0017 
0018 #include "FWCore/MessageLogger/interface/ELseverityLevel.h"
0019 #include "FWCore/MessageLogger/interface/ELmap.h"
0020 
0021 namespace {
0022   using namespace edm::messagelogger;
0023   // ----------------------------------------------------------------------
0024   // Helper to construct the string->ELsev_ map on demand:
0025   // ----------------------------------------------------------------------
0026 
0027   typedef std::map<std::string const, ELseverityLevel::ELsev_, std::less<>> ELmap;
0028 
0029   ELmap const& loadMap() {
0030     static const ELmap m = {{ELzeroSeverity.getSymbol(), ELseverityLevel::ELsev_zeroSeverity},
0031                             {ELzeroSeverity.getName(), ELseverityLevel::ELsev_zeroSeverity},
0032                             {ELzeroSeverity.getInputStr(), ELseverityLevel::ELsev_zeroSeverity},
0033                             {ELzeroSeverity.getVarName(), ELseverityLevel::ELsev_zeroSeverity},
0034                             {ELdebug.getSymbol(), ELseverityLevel::ELsev_success},
0035                             {ELdebug.getName(), ELseverityLevel::ELsev_success},
0036                             {ELdebug.getInputStr(), ELseverityLevel::ELsev_success},
0037                             {ELdebug.getVarName(), ELseverityLevel::ELsev_success},
0038                             {ELinfo.getSymbol(), ELseverityLevel::ELsev_info},
0039                             {ELinfo.getName(), ELseverityLevel::ELsev_info},
0040                             {ELinfo.getInputStr(), ELseverityLevel::ELsev_info},
0041                             {ELinfo.getVarName(), ELseverityLevel::ELsev_info},
0042                             {ELfwkInfo.getSymbol(), ELseverityLevel::ELsev_fwkInfo},
0043                             {ELfwkInfo.getName(), ELseverityLevel::ELsev_fwkInfo},
0044                             {ELfwkInfo.getInputStr(), ELseverityLevel::ELsev_fwkInfo},
0045                             {ELfwkInfo.getVarName(), ELseverityLevel::ELsev_fwkInfo},
0046                             {ELwarning.getSymbol(), ELseverityLevel::ELsev_warning},
0047                             {ELwarning.getName(), ELseverityLevel::ELsev_warning},
0048                             {ELwarning.getInputStr(), ELseverityLevel::ELsev_warning},
0049                             {ELwarning.getVarName(), ELseverityLevel::ELsev_warning},
0050                             {ELerror.getSymbol(), ELseverityLevel::ELsev_error},
0051                             {ELerror.getName(), ELseverityLevel::ELsev_error},
0052                             {ELerror.getInputStr(), ELseverityLevel::ELsev_error},
0053                             {ELerror.getVarName(), ELseverityLevel::ELsev_error},
0054                             {ELunspecified.getSymbol(), ELseverityLevel::ELsev_unspecified},
0055                             {ELunspecified.getName(), ELseverityLevel::ELsev_unspecified},
0056                             {ELunspecified.getInputStr(), ELseverityLevel::ELsev_unspecified},
0057                             {ELunspecified.getVarName(), ELseverityLevel::ELsev_unspecified},
0058                             {ELsevere.getSymbol(), ELseverityLevel::ELsev_severe},
0059                             {ELsevere.getName(), ELseverityLevel::ELsev_severe},
0060                             {ELsevere.getInputStr(), ELseverityLevel::ELsev_severe},
0061                             {ELsevere.getVarName(), ELseverityLevel::ELsev_severe},
0062                             {ELhighestSeverity.getSymbol(), ELseverityLevel::ELsev_highestSeverity},
0063                             {ELhighestSeverity.getName(), ELseverityLevel::ELsev_highestSeverity},
0064                             {ELhighestSeverity.getInputStr(), ELseverityLevel::ELsev_highestSeverity},
0065                             {ELhighestSeverity.getVarName(), ELseverityLevel::ELsev_highestSeverity}};
0066 
0067     return m;
0068   }
0069 }  // namespace
0070 
0071 namespace edm::messagelogger {
0072 
0073   // ----------------------------------------------------------------------
0074   // Birth/death:
0075   // ----------------------------------------------------------------------
0076 
0077   ELseverityLevel::ELseverityLevel(std::string_view s) {
0078     static ELmap const& m = loadMap();
0079 
0080     ELmap::const_iterator i = m.find(s);
0081     myLevel = (i == m.end()) ? ELsev_unspecified : i->second;
0082   }
0083 
0084   // ----------------------------------------------------------------------
0085   // Accessors:
0086   // ----------------------------------------------------------------------
0087 
0088   const std::string& ELseverityLevel::getSymbol() const {
0089     static const auto symbols = []() {
0090       std::array<std::string, nLevels> ret;
0091       ret[ELsev_noValueAssigned] = "0";
0092       ret[ELsev_zeroSeverity] = "--";
0093       ret[ELsev_success] = "-d";
0094       ret[ELsev_info] = "-i";
0095       ret[ELsev_fwkInfo] = "-f";
0096       ret[ELsev_warning] = "-w";
0097       ret[ELsev_error] = "-e";
0098       ret[ELsev_unspecified] = "??";
0099       ret[ELsev_severe] = "-s";
0100       ret[ELsev_highestSeverity] = "!!";
0101       return ret;
0102     }();
0103 
0104     assert(myLevel < nLevels);
0105     return symbols[myLevel];
0106   }
0107 
0108   const std::string& ELseverityLevel::getName() const {
0109     static const auto names = []() {
0110       std::array<std::string, nLevels> ret;
0111       ret[ELsev_noValueAssigned] = "?no value?";
0112       ret[ELsev_zeroSeverity] = "--";
0113       ret[ELsev_success] = "Debug";
0114       ret[ELsev_info] = "Info";
0115       ret[ELsev_fwkInfo] = "FwkInfo";
0116       ret[ELsev_warning] = "Warning";
0117       ret[ELsev_error] = "Error";
0118       ret[ELsev_unspecified] = "??";
0119       ret[ELsev_severe] = "System";
0120       ret[ELsev_highestSeverity] = "!!";
0121       return ret;
0122     }();
0123 
0124     assert(myLevel < nLevels);
0125     return names[myLevel];
0126   }
0127 
0128   const std::string& ELseverityLevel::getInputStr() const {
0129     static const auto inputs = []() {
0130       std::array<std::string, nLevels> ret;
0131       ret[ELsev_noValueAssigned] = "?no value?";
0132       ret[ELsev_zeroSeverity] = "ZERO";
0133       ret[ELsev_success] = "DEBUG";
0134       ret[ELsev_info] = "INFO";
0135       ret[ELsev_fwkInfo] = "FWKINFO";
0136       ret[ELsev_warning] = "WARNING";
0137       ret[ELsev_error] = "ERROR";
0138       ret[ELsev_unspecified] = "UNSPECIFIED";
0139       ret[ELsev_severe] = "SYSTEM";
0140       ret[ELsev_highestSeverity] = "HIGHEST";
0141       return ret;
0142     }();
0143 
0144     assert(myLevel < nLevels);
0145     return inputs[myLevel];
0146   }
0147 
0148   const std::string& ELseverityLevel::getVarName() const {
0149     static const auto varNames = []() {
0150       std::array<std::string, nLevels> ret;
0151       ret[ELsev_noValueAssigned] = "?no value?";
0152       ret[ELsev_zeroSeverity] = "ELzeroSeverity   ";
0153       ret[ELsev_success] = "ELdebug          ";
0154       ret[ELsev_info] = "ELinfo           ";
0155       ret[ELsev_fwkInfo] = "ELfwkInfo        ";
0156       ret[ELsev_warning] = "ELwarning        ";
0157       ret[ELsev_error] = "ELerror          ";
0158       ret[ELsev_unspecified] = "ELunspecified    ";
0159       ret[ELsev_severe] = "ELsystem         ";
0160       ret[ELsev_highestSeverity] = "ELhighestSeverity";
0161       return ret;
0162     }();
0163 
0164     assert(myLevel < nLevels);
0165     return varNames[myLevel];
0166   }
0167 
0168   // ----------------------------------------------------------------------
0169   // Emitter:
0170   // ----------------------------------------------------------------------
0171 
0172   std::ostream& operator<<(std::ostream& os, const ELseverityLevel& sev) { return os << " -" << sev.getName() << "- "; }
0173 
0174 }  // namespace edm::messagelogger