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 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 
164  : (sev >= ELhighestSeverity) ? (ELseverityLevel)ELsevere : sev;
165  }
166 
167  void ErrorObj::setID(std::string_view id) {
168  myXid.id = id.substr(0, maxIDlength);
169  if (id.length() > maxIDlength)
170  myIdOverflow = id.substr(maxIDlength, id.length() - maxIDlength);
171  }
172 
173  void ErrorObj::setModule(std::string_view module) { myXid.module = module; }
174 
175  void ErrorObj::setContext(std::string_view c) { myContext = c; }
176 
177  void ErrorObj::setSubroutine(std::string_view subroutine) {
178 #ifdef ErrorObj_SUB_TRACE
179  std::cerr << "=:=:=: ErrorObj::setSubroutine(" << subroutine << ")\n";
180 #endif
181  myXid.subroutine = (subroutine[0] == ' ') ? subroutine.substr(1) : subroutine;
182  }
183 
185 
186 #ifdef ErrorObj_SUB_TRACE
187  static int subN = 0;
188 #endif
189 
190  ErrorObj& ErrorObj::emitToken(std::string_view s) {
191 #ifdef ErrorObj_EMIT_TRACE
192  std::cerr << "=:=:=: ErrorObj::emitToken( " << s << " )\n";
193 #endif
194 
195 #ifdef ErrorObj_SUB_TRACE
196  if (subN > 0) {
197  std::cerr << "=:=:=: subN ErrorObj::emitToken( " << s << " )\n";
198  subN--;
199  }
200 #endif
201 
202  if (eq_nocase(s.substr(0, 5), "@SUB=")) {
203 #ifdef ErrorObj_SUB_TRACE
204  std::cerr << "=:=:=: ErrorObj::@SUB s.substr(5) is: " << s.substr(5) << '\n';
205 #endif
206  setSubroutine(s.substr(5));
207  } else {
208  myItems.emplace_back(s);
209  }
210 
211  return *this;
212 
213  } // emitToken()
214 
215  void ErrorObj::set(const ELseverityLevel& sev, std::string_view id) {
216  clear();
217 
218  myTimestamp = time(nullptr);
219  mySerial = ++ourSerial;
220 
221  setID(id);
222  setSeverity(sev);
223 
224  } // set()
225 
227  mySerial = 0;
228  myXid.clear();
229  myIdOverflow = "";
230  myTimestamp = 0;
231  myItems.erase(myItems.begin(), myItems.end()); // myItems.clear();
232  myReactedTo = false;
233 
234  } // clear()
235 
236  ErrorObj& ErrorObj::opltlt(const char s[]) {
237  // Exactly equivalent to the general template.
238  // If this is not provided explicitly, then the template will
239  // be instantiated once for each length of string ever used.
240  myOs.str(emptyString);
241  myOs << s;
242 #ifdef OLD_STYLE_AUTOMATIC_SPACES
243  if (!myOs.str().empty()) {
244  if (!verbatim) {
245  emitToken(myOs.str() + ' ');
246  } else {
247  emitToken(myOs.str());
248  }
249  }
250 #else
251  if (!myOs.str().empty())
252  emitToken(myOs.str());
253 #endif
254  return *this;
255  }
256 
257  ErrorObj& operator<<(ErrorObj& e, const char s[]) { return e.opltlt(s); }
258 
259 } // end of namespace edm */
edm::ErrorObj::setReactedTo
virtual void setReactedTo(bool r)
Definition: ErrorObj.cc:184
edm::ErrorObj::serial
int serial() const
Definition: ErrorObj.cc:141
edm::ErrorObj::set
virtual void set(const ELseverityLevel &sev, std::string_view id)
Definition: ErrorObj.cc:215
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:190
edm::ELhighestSeverity
constexpr const ELseverityLevel ELhighestSeverity
Definition: ELseverityLevel.h:108
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
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::ELlist_string
std::list< std::string > ELlist_string
Definition: ELlist.h:33
edm::ErrorObj::myContext
std::string myContext
Definition: ErrorObj.h:100
edm::operator<<
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.
Definition: HLTGlobalStatus.h:106
edm::ErrorObj::fullText
std::string fullText() const
Definition: ErrorObj.cc:151
alignCSCRings.s
s
Definition: alignCSCRings.py:92
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
edm::ErrorObj::setSeverity
virtual void setSeverity(const ELseverityLevel &sev)
Definition: ErrorObj.cc:162
trackingPlots.other
other
Definition: trackingPlots.py:1467
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:167
b
double b
Definition: hdecay.h:118
edm::ErrorObj::xid
const ELextendedID & xid() const
Definition: ErrorObj.cc:142
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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:106
edm::maxIDlength
const unsigned int maxIDlength(200)
thread_safety_macros.h
edm::ErrorObj::ErrorObj
ErrorObj(const ELseverityLevel &sev, std::string_view id, bool verbatim=false)
Definition: ErrorObj.cc:83
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:226
edm::ErrorObj::emptyString
std::string emptyString
Definition: ErrorObj.h:102
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
edm::ErrorObj::myXid
ELextendedID myXid
Definition: ErrorObj.h:95
edm::ELdebug
constexpr const ELseverityLevel ELdebug
Definition: ELseverityLevel.h:94
alignCSCRings.r
r
Definition: alignCSCRings.py:93
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:175
edm::ELextendedID::clear
void clear()
Definition: ELextendedID.cc:46
edm::ELextendedID::id
std::string id
Definition: ELextendedID.h:29
edm::ELseverityLevel
Definition: ELseverityLevel.h:26
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:12
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
edm::ErrorObj::~ErrorObj
virtual ~ErrorObj()
Definition: ErrorObj.cc:109
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::ELextendedID::severity
ELseverityLevel severity
Definition: ELextendedID.h:30
edm::ErrorObj::setModule
virtual void setModule(std::string_view module)
Definition: ErrorObj.cc:173
edm::ErrorObj::opltlt
ErrorObj & opltlt(const T &t)
ntuplemaker.time
time
Definition: ntuplemaker.py:310
edm::ErrorObj::setSubroutine
virtual void setSubroutine(std::string_view subroutine)
Definition: ErrorObj.cc:177
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:92
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::ErrorObj::is_verbatim
bool is_verbatim() const
Definition: ErrorObj.cc:147