CMS 3D CMS Logo

ErrorObj.cc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------
2 //
3 // ErrorObj.cc
4 //
5 // History:
6 //
7 // Created 7/8/98 mf
8 // 6/16/99 mf, jvr ErrorObj::operator<<( void (* f)(ErrorLog &) )
9 // allows an "ErrorObj << endmsg;"
10 // 7/16/99 jvr Added setSeverity() and setID functions
11 // 6/7/00 web Forbid setting extreme severities; guard against
12 // too-long ID's
13 // 9/21/00 mf Added copy constructor for use by ELerrorList
14 // 5/7/01 mf operator<< (const char[])
15 // 6/5/01 mf setReactedTo
16 // 11/01/01 web maxIDlength now unsigned
17 //
18 // 2/14/06 mf Removed oerator<<(endmsg) which is not needed for
19 // MessageLogger for CMS
20 //
21 // 3/13/06 mf Instrumented for automatic suppression of spaces.
22 // 3/20/06 mf Instrumented for universal suppression of spaces
23 // (that is, items no longer contain any space added
24 // by the MessageLogger stack)
25 //
26 // 4/28/06 mf maxIDlength changed from 20 to 200
27 // If a category name exceeds that, then the
28 // limit not taking effect bug will occur again...
29 //
30 // 6/6/06 mf verbatim
31 //
32 // ErrorObj( const ELseverityLevel & sev, const ELstring & id )
33 // ~ErrorObj()
34 // set( const ELseverityLevel & sev, const ELstring & id )
35 // clear()
36 // setModule ( const ELstring & module )
37 // setSubroutine( const ELstring & subroutine )
38 // emitToken( const ELstring & txt )
39 //
40 // ----------------------------------------------------------------------
41 
42 #include <algorithm>
43 #include <atomic>
44 #include <cctype>
45 
48 
49 #ifndef IOSTREAM_INCLUDED
50 #endif
51 
52 // ----------------------------------------------------------------------
53 
54 // Possible Traces
55 // #define ErrorObjCONSTRUCTOR_TRACE
56 // #define ErrorObj_EMIT_TRACE
57 // #define ErrorObj_SUB_TRACE
58 
59 // ----------------------------------------------------------------------
60 
61 namespace {
62  bool eq_nocase(std::string_view a, std::string_view b) {
63  return std::equal(
64  a.begin(), a.end(), b.begin(), b.end(), [](char x, char y) { return std::toupper(x) == std::toupper(y); });
65  }
66 } // namespace
67 
68 namespace edm {
69 
70  // ----------------------------------------------------------------------
71  // Class static and class-wide parameter:
72  // ----------------------------------------------------------------------
73 
74  // --- class-wide serial number stamper:
75  //
76  CMS_THREAD_SAFE static std::atomic<int> ourSerial(0);
77  const unsigned int maxIDlength(200); // changed 4/28/06 from 20
78 
79  // ----------------------------------------------------------------------
80  // Birth/death:
81  // ----------------------------------------------------------------------
82 
83  ErrorObj::ErrorObj(const messagelogger::ELseverityLevel& sev, std::string_view id, bool verbat) : verbatim(verbat) {
84 #ifdef ErrorObjCONSTRUCTOR_TRACE
85  std::cerr << "Constructor for ErrorObj\n";
86 #endif
87 
88  clear();
89  set(sev, id);
90 
91  } // ErrorObj()
92 
94  : mySerial(orig.mySerial),
95  myXid(orig.myXid),
96  myIdOverflow(orig.myIdOverflow),
97  myTimestamp(orig.myTimestamp),
98  myItems(orig.myItems),
99  myReactedTo(orig.myReactedTo),
100  myOs(),
101  emptyString(),
102  verbatim(orig.verbatim) {
103 #ifdef ErrorObjCONSTRUCTOR_TRACE
104  std::cerr << "Copy Constructor for ErrorObj\n";
105 #endif
106 
107  } // ErrorObj(ErrorObj)
108 
110 #ifdef ErrorObjCONSTRUCTOR_TRACE
111  std::cerr << "Destructor for ErrorObj\n";
112 #endif
113 
114  } // ~ErrorObj()
115 
118  this->swap(temp);
119  return *this;
120  }
121 
123  std::swap(mySerial, other.mySerial);
124  std::swap(myXid, other.myXid);
125  myIdOverflow.swap(other.myIdOverflow);
126  std::swap(myTimestamp, other.myTimestamp);
127  myItems.swap(other.myItems);
128  std::swap(myReactedTo, other.myReactedTo);
129  myContext.swap(other.myContext);
130  std::string temp(other.myOs.str());
131  other.myOs.str(myOs.str());
132  myOs.str(temp);
133  emptyString.swap(other.emptyString);
134  std::swap(verbatim, other.verbatim);
135  }
136 
137  // ----------------------------------------------------------------------
138  // Accessors:
139  // ----------------------------------------------------------------------
140 
141  int ErrorObj::serial() const { return mySerial; }
142  const ELextendedID& ErrorObj::xid() const { return myXid; }
143  const std::string& ErrorObj::idOverflow() const { return myIdOverflow; }
144  time_t ErrorObj::timestamp() const { return myTimestamp; }
145  const ELlist_string& ErrorObj::items() const { return myItems; }
146  bool ErrorObj::reactedTo() const { return myReactedTo; }
147  bool ErrorObj::is_verbatim() const { return verbatim; }
148 
149  const std::string& ErrorObj::context() const { return myContext; }
150 
153  for (auto const& it : myItems)
154  result += it;
155  return result;
156  } // fullText()
157 
158  // ----------------------------------------------------------------------
159  // Mutators:
160  // ----------------------------------------------------------------------
161 
163  using namespace edm::messagelogger;
166  : sev;
167  }
168 
169  void ErrorObj::setID(std::string_view id) {
170  myXid.id = id.substr(0, maxIDlength);
171  if (id.length() > maxIDlength)
172  myIdOverflow = id.substr(maxIDlength, id.length() - maxIDlength);
173  }
174 
175  void ErrorObj::setModule(std::string_view module) { myXid.module = module; }
176 
177  void ErrorObj::setContext(std::string_view c) { myContext = c; }
178 
179  void ErrorObj::setSubroutine(std::string_view subroutine) {
180 #ifdef ErrorObj_SUB_TRACE
181  std::cerr << "=:=:=: ErrorObj::setSubroutine(" << subroutine << ")\n";
182 #endif
183  myXid.subroutine = (subroutine[0] == ' ') ? subroutine.substr(1) : subroutine;
184  }
185 
187 
188 #ifdef ErrorObj_SUB_TRACE
189  static int subN = 0;
190 #endif
191 
192  ErrorObj& ErrorObj::emitToken(std::string_view s) {
193 #ifdef ErrorObj_EMIT_TRACE
194  std::cerr << "=:=:=: ErrorObj::emitToken( " << s << " )\n";
195 #endif
196 
197 #ifdef ErrorObj_SUB_TRACE
198  if (subN > 0) {
199  std::cerr << "=:=:=: subN ErrorObj::emitToken( " << s << " )\n";
200  subN--;
201  }
202 #endif
203 
204  if (eq_nocase(s.substr(0, 5), "@SUB=")) {
205 #ifdef ErrorObj_SUB_TRACE
206  std::cerr << "=:=:=: ErrorObj::@SUB s.substr(5) is: " << s.substr(5) << '\n';
207 #endif
208  setSubroutine(s.substr(5));
209  } else {
210  myItems.emplace_back(s);
211  }
212 
213  return *this;
214 
215  } // emitToken()
216 
217  void ErrorObj::set(const messagelogger::ELseverityLevel& sev, std::string_view id) {
218  clear();
219 
220  myTimestamp = time(nullptr);
221  mySerial = ++ourSerial;
222 
223  setID(id);
224  setSeverity(sev);
225 
226  } // set()
227 
229  mySerial = 0;
230  myXid.clear();
231  myIdOverflow = "";
232  myTimestamp = 0;
233  myItems.erase(myItems.begin(), myItems.end()); // myItems.clear();
234  myReactedTo = false;
235 
236  } // clear()
237 
238  ErrorObj& ErrorObj::opltlt(const char s[]) {
239  // Exactly equivalent to the general template.
240  // If this is not provided explicitly, then the template will
241  // be instantiated once for each length of string ever used.
242  myOs.str(emptyString);
243  myOs << s;
244 #ifdef OLD_STYLE_AUTOMATIC_SPACES
245  if (!myOs.str().empty()) {
246  if (!verbatim) {
247  emitToken(myOs.str() + ' ');
248  } else {
249  emitToken(myOs.str());
250  }
251  }
252 #else
253  if (!myOs.str().empty())
254  emitToken(myOs.str());
255 #endif
256  return *this;
257  }
258 
259  ErrorObj& operator<<(ErrorObj& e, const char s[]) { return e.opltlt(s); }
260 
261 } // end of namespace edm */
edm::ErrorObj::setReactedTo
virtual void setReactedTo(bool r)
Definition: ErrorObj.cc:186
edm::ErrorObj::serial
int serial() const
Definition: ErrorObj.cc:141
edm::ELextendedID::module
std::string module
Definition: ELextendedID.h:31
edm::ErrorObj::context
const std::string & context() const
Definition: ErrorObj.cc:149
edm::ErrorObj::emitToken
virtual ErrorObj & emitToken(std::string_view txt)
Definition: ErrorObj.cc:192
edm::ELhighestSeverity
constexpr const ELseverityLevel ELhighestSeverity
Definition: ELseverityLevel.h:96
edm::ErrorObj::reactedTo
bool reactedTo() const
Definition: ErrorObj.cc:146
edm::ourSerial
static std::atomic< int > ourSerial(0)
edm::ErrorObj::mySerial
int mySerial
Definition: ErrorObj.h:94
edm::ErrorObj::myIdOverflow
std::string myIdOverflow
Definition: ErrorObj.h:96
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ErrorObj
Definition: ErrorObj.h:43
edm::ELextendedID
Definition: ELextendedID.h:25
edm::friendlyname::emptyString
static const std::string emptyString("")
edm::ErrorObj::myItems
ELlist_string myItems
Definition: ErrorObj.h:98
ErrorObj.h
protons_cff.time
time
Definition: protons_cff.py:35
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::ELlist_string
std::list< std::string > ELlist_string
Definition: ELlist.h:33
edm::ErrorObj::setSeverity
virtual void setSeverity(const messagelogger::ELseverityLevel &sev)
Definition: ErrorObj.cc:162
edm::ErrorObj::myContext
std::string myContext
Definition: ErrorObj.h:100
edm::ErrorObj::fullText
std::string fullText() const
Definition: ErrorObj.cc:151
alignCSCRings.s
s
Definition: alignCSCRings.py:92
edm::ELextendedID::severity
messagelogger::ELseverityLevel severity
Definition: ELextendedID.h:30
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
edm::ErrorObj::timestamp
time_t timestamp() const
Definition: ErrorObj.cc:144
trackingPlots.other
other
Definition: trackingPlots.py:1464
CMS_THREAD_SAFE
#define CMS_THREAD_SAFE
Definition: thread_safety_macros.h:4
edm::ErrorObj::setID
virtual void setID(std::string_view ID)
Definition: ErrorObj.cc:169
b
double b
Definition: hdecay.h:118
edm::ErrorObj::xid
const ELextendedID & xid() const
Definition: ErrorObj.cc:142
edm::ErrorObj::idOverflow
const std::string & idOverflow() const
Definition: ErrorObj.cc:143
a
double a
Definition: hdecay.h:119
edm::ELsevere
constexpr const ELseverityLevel ELsevere
Definition: ELseverityLevel.h:94
edm::maxIDlength
const unsigned int maxIDlength(200)
thread_safety_macros.h
edm::ErrorObj::items
const ELlist_string & items() const
Definition: ErrorObj.cc:145
edm::ErrorObj::myReactedTo
bool myReactedTo
Definition: ErrorObj.h:99
edm::ErrorObj::clear
virtual void clear()
Definition: ErrorObj.cc:228
edm::ErrorObj::emptyString
std::string emptyString
Definition: ErrorObj.h:102
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ErrorObj::myXid
ELextendedID myXid
Definition: ErrorObj.h:95
edm::ELdebug
constexpr const ELseverityLevel ELdebug
Definition: ELseverityLevel.h:82
alignCSCRings.r
r
Definition: alignCSCRings.py:93
callgraph.module
module
Definition: callgraph.py:61
edm::ErrorObj::operator=
ErrorObj & operator=(const ErrorObj &other)
Definition: ErrorObj.cc:116
edm::ErrorObj::myOs
std::ostringstream myOs
Definition: ErrorObj.h:101
edm::ErrorObj::setContext
virtual void setContext(std::string_view context)
Definition: ErrorObj.cc:177
edm::ELextendedID::clear
void clear()
Definition: ELextendedID.cc:41
edm::ELextendedID::id
std::string id
Definition: ELextendedID.h:29
edm::ELseverityLevel
Definition: ELseverityLevel.h:26
edm::ErrorObj::ErrorObj
ErrorObj(const messagelogger::ELseverityLevel &sev, std::string_view id, bool verbatim=false)
Definition: ErrorObj.cc:83
edm::ErrorObj::verbatim
bool verbatim
Definition: ErrorObj.h:103
edm::ErrorObj::myTimestamp
time_t myTimestamp
Definition: ErrorObj.h:97
genVertex_cff.x
x
Definition: genVertex_cff.py:13
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
edm::ErrorObj::~ErrorObj
virtual ~ErrorObj()
Definition: ErrorObj.cc:109
edm::messagelogger::ELseverityLevel
Definition: ELseverityLevel.h:26
edm::ErrorObj::swap
void swap(ErrorObj &other)
Definition: ErrorObj.cc:122
mps_fire.result
result
Definition: mps_fire.py:311
edm::ELextendedID::subroutine
std::string subroutine
Definition: ELextendedID.h:32
edm::ErrorObj::set
virtual void set(const messagelogger::ELseverityLevel &sev, std::string_view id)
Definition: ErrorObj.cc:217
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
edm::ErrorObj::setModule
virtual void setModule(std::string_view module)
Definition: ErrorObj.cc:175
edm::ErrorObj::opltlt
ErrorObj & opltlt(const T &t)
edm::ErrorObj::setSubroutine
virtual void setSubroutine(std::string_view subroutine)
Definition: ErrorObj.cc:179
cond::serialization::equal
bool equal(const T &first, const T &second)
Definition: Equal.h:32
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
edm::ELzeroSeverity
constexpr const ELseverityLevel ELzeroSeverity
Definition: ELseverityLevel.h:80
edm::messagelogger
Definition: ELseverityLevel.h:21
edm::ErrorObj::operator<<
ErrorObj & operator<<(std::ostream &(*f)(std::ostream &))
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::ErrorObj::is_verbatim
bool is_verbatim() const
Definition: ErrorObj.cc:147