File indexing completed on 2024-04-06 12:12:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 #include <algorithm>
0043 #include <atomic>
0044 #include <cctype>
0045
0046 #include "FWCore/MessageLogger/interface/ErrorObj.h"
0047 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0048
0049 #ifndef IOSTREAM_INCLUDED
0050 #endif
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 namespace {
0062 bool eq_nocase(std::string_view a, std::string_view b) {
0063 return std::equal(
0064 a.begin(), a.end(), b.begin(), b.end(), [](char x, char y) { return std::toupper(x) == std::toupper(y); });
0065 }
0066 }
0067
0068 namespace edm {
0069
0070
0071
0072
0073
0074
0075
0076 CMS_THREAD_SAFE static std::atomic<int> ourSerial(0);
0077 const unsigned int maxIDlength(200);
0078
0079
0080
0081
0082
0083 ErrorObj::ErrorObj(const messagelogger::ELseverityLevel& sev, std::string_view id, bool verbat) : verbatim(verbat) {
0084 #ifdef ErrorObjCONSTRUCTOR_TRACE
0085 std::cerr << "Constructor for ErrorObj\n";
0086 #endif
0087
0088 clear();
0089 set(sev, id);
0090
0091 }
0092
0093 ErrorObj::ErrorObj(const ErrorObj& orig)
0094 : mySerial(orig.mySerial),
0095 myXid(orig.myXid),
0096 myIdOverflow(orig.myIdOverflow),
0097 myTimestamp(orig.myTimestamp),
0098 myItems(orig.myItems),
0099 myReactedTo(orig.myReactedTo),
0100 myOs(),
0101 emptyString(),
0102 verbatim(orig.verbatim) {
0103 #ifdef ErrorObjCONSTRUCTOR_TRACE
0104 std::cerr << "Copy Constructor for ErrorObj\n";
0105 #endif
0106
0107 }
0108
0109 ErrorObj::~ErrorObj() {
0110 #ifdef ErrorObjCONSTRUCTOR_TRACE
0111 std::cerr << "Destructor for ErrorObj\n";
0112 #endif
0113
0114 }
0115
0116 ErrorObj& ErrorObj::operator=(const ErrorObj& other) {
0117 ErrorObj temp(other);
0118 this->swap(temp);
0119 return *this;
0120 }
0121
0122 void ErrorObj::swap(ErrorObj& other) {
0123 std::swap(mySerial, other.mySerial);
0124 std::swap(myXid, other.myXid);
0125 myIdOverflow.swap(other.myIdOverflow);
0126 std::swap(myTimestamp, other.myTimestamp);
0127 myItems.swap(other.myItems);
0128 std::swap(myReactedTo, other.myReactedTo);
0129 myContext.swap(other.myContext);
0130 std::string temp(other.myOs.str());
0131 other.myOs.str(myOs.str());
0132 myOs.str(temp);
0133 emptyString.swap(other.emptyString);
0134 std::swap(verbatim, other.verbatim);
0135 }
0136
0137
0138
0139
0140
0141 int ErrorObj::serial() const { return mySerial; }
0142 const ELextendedID& ErrorObj::xid() const { return myXid; }
0143 const std::string& ErrorObj::idOverflow() const { return myIdOverflow; }
0144 time_t ErrorObj::timestamp() const { return myTimestamp; }
0145 const ELlist_string& ErrorObj::items() const { return myItems; }
0146 bool ErrorObj::reactedTo() const { return myReactedTo; }
0147 bool ErrorObj::is_verbatim() const { return verbatim; }
0148
0149 const std::string& ErrorObj::context() const { return myContext; }
0150
0151 std::string ErrorObj::fullText() const {
0152 std::string result;
0153 for (auto const& it : myItems)
0154 result += it;
0155 return result;
0156 }
0157
0158
0159
0160
0161
0162 void ErrorObj::setSeverity(const messagelogger::ELseverityLevel& sev) {
0163 using namespace edm::messagelogger;
0164 myXid.severity = (sev <= ELzeroSeverity) ? (ELseverityLevel)ELdebug
0165 : (sev >= ELhighestSeverity) ? (ELseverityLevel)ELsevere
0166 : sev;
0167 }
0168
0169 void ErrorObj::setID(std::string_view id) {
0170 myXid.id = id.substr(0, maxIDlength);
0171 if (id.length() > maxIDlength)
0172 myIdOverflow = id.substr(maxIDlength, id.length() - maxIDlength);
0173 }
0174
0175 void ErrorObj::setModule(std::string_view module) { myXid.module = module; }
0176
0177 void ErrorObj::setContext(std::string_view c) { myContext = c; }
0178
0179 void ErrorObj::setSubroutine(std::string_view subroutine) {
0180 #ifdef ErrorObj_SUB_TRACE
0181 std::cerr << "=:=:=: ErrorObj::setSubroutine(" << subroutine << ")\n";
0182 #endif
0183 myXid.subroutine = (subroutine[0] == ' ') ? subroutine.substr(1) : subroutine;
0184 }
0185
0186 void ErrorObj::setReactedTo(bool r) { myReactedTo = r; }
0187
0188 #ifdef ErrorObj_SUB_TRACE
0189 static int subN = 0;
0190 #endif
0191
0192 ErrorObj& ErrorObj::emitToken(std::string_view s) {
0193 #ifdef ErrorObj_EMIT_TRACE
0194 std::cerr << "=:=:=: ErrorObj::emitToken( " << s << " )\n";
0195 #endif
0196
0197 #ifdef ErrorObj_SUB_TRACE
0198 if (subN > 0) {
0199 std::cerr << "=:=:=: subN ErrorObj::emitToken( " << s << " )\n";
0200 subN--;
0201 }
0202 #endif
0203
0204 if (eq_nocase(s.substr(0, 5), "@SUB=")) {
0205 #ifdef ErrorObj_SUB_TRACE
0206 std::cerr << "=:=:=: ErrorObj::@SUB s.substr(5) is: " << s.substr(5) << '\n';
0207 #endif
0208 setSubroutine(s.substr(5));
0209 } else {
0210 myItems.emplace_back(s);
0211 }
0212
0213 return *this;
0214
0215 }
0216
0217 void ErrorObj::set(const messagelogger::ELseverityLevel& sev, std::string_view id) {
0218 clear();
0219
0220 myTimestamp = time(nullptr);
0221 mySerial = ++ourSerial;
0222
0223 setID(id);
0224 setSeverity(sev);
0225
0226 }
0227
0228 void ErrorObj::clear() {
0229 mySerial = 0;
0230 myXid.clear();
0231 myIdOverflow = "";
0232 myTimestamp = 0;
0233 myItems.erase(myItems.begin(), myItems.end());
0234 myReactedTo = false;
0235
0236 }
0237
0238 ErrorObj& ErrorObj::opltlt(const char s[]) {
0239
0240
0241
0242 myOs.str(emptyString);
0243 myOs << s;
0244 #ifdef OLD_STYLE_AUTOMATIC_SPACES
0245 if (!myOs.str().empty()) {
0246 if (!verbatim) {
0247 emitToken(myOs.str() + ' ');
0248 } else {
0249 emitToken(myOs.str());
0250 }
0251 }
0252 #else
0253 if (!myOs.str().empty())
0254 emitToken(myOs.str());
0255 #endif
0256 return *this;
0257 }
0258
0259 ErrorObj& operator<<(ErrorObj& e, const char s[]) { return e.opltlt(s); }
0260
0261 }