CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 <atomic>
43 
46 
47 #ifndef IOSTREAM_INCLUDED
48 #endif
49 
50 // ----------------------------------------------------------------------
51 
52 // Possible Traces
53 // #define ErrorObjCONSTRUCTOR_TRACE
54 // #define ErrorObj_EMIT_TRACE
55 // #define ErrorObj_SUB_TRACE
56 
57 // ----------------------------------------------------------------------
58 
59 namespace edm {
60 
61  // ----------------------------------------------------------------------
62  // Class static and class-wide parameter:
63  // ----------------------------------------------------------------------
64 
65  // --- class-wide serial number stamper:
66  //
67  CMS_THREAD_SAFE static std::atomic<int> ourSerial(0);
68  const unsigned int maxIDlength(200); // changed 4/28/06 from 20
69 
70  // ----------------------------------------------------------------------
71  // Birth/death:
72  // ----------------------------------------------------------------------
73 
74  ErrorObj::ErrorObj(const ELseverityLevel& sev, const ELstring& id, bool verbat) : verbatim(verbat) {
75 #ifdef ErrorObjCONSTRUCTOR_TRACE
76  std::cerr << "Constructor for ErrorObj\n";
77 #endif
78 
79  clear();
80  set(sev, id);
81 
82  } // ErrorObj()
83 
85  : mySerial(orig.mySerial),
86  myXid(orig.myXid),
87  myIdOverflow(orig.myIdOverflow),
88  myTimestamp(orig.myTimestamp),
89  myItems(orig.myItems),
90  myReactedTo(orig.myReactedTo),
91  myOs(),
92  emptyString(),
93  verbatim(orig.verbatim) {
94 #ifdef ErrorObjCONSTRUCTOR_TRACE
95  std::cerr << "Copy Constructor for ErrorObj\n";
96 #endif
97 
98  } // ErrorObj(ErrorObj)
99 
101 #ifdef ErrorObjCONSTRUCTOR_TRACE
102  std::cerr << "Destructor for ErrorObj\n";
103 #endif
104 
105  } // ~ErrorObj()
106 
109  this->swap(temp);
110  return *this;
111  }
112 
114  std::swap(mySerial, other.mySerial);
115  std::swap(myXid, other.myXid);
116  myIdOverflow.swap(other.myIdOverflow);
117  std::swap(myTimestamp, other.myTimestamp);
118  myItems.swap(other.myItems);
119  std::swap(myReactedTo, other.myReactedTo);
120  myContext.swap(other.myContext);
121  std::string temp(other.myOs.str());
122  other.myOs.str(myOs.str());
123  myOs.str(temp);
124  emptyString.swap(other.emptyString);
125  std::swap(verbatim, other.verbatim);
126  }
127 
128  // ----------------------------------------------------------------------
129  // Accessors:
130  // ----------------------------------------------------------------------
131 
132  int ErrorObj::serial() const { return mySerial; }
133  const ELextendedID& ErrorObj::xid() const { return myXid; }
134  const ELstring& ErrorObj::idOverflow() const { return myIdOverflow; }
135  time_t ErrorObj::timestamp() const { return myTimestamp; }
136  const ELlist_string& ErrorObj::items() const { return myItems; }
137  bool ErrorObj::reactedTo() const { return myReactedTo; }
138  bool ErrorObj::is_verbatim() const { return verbatim; }
139 
141 
144  for (ELlist_string::const_iterator it = myItems.begin(); it != myItems.end(); ++it)
145  result += *it;
146  return result;
147 
148  } // fullText()
149 
150  // ----------------------------------------------------------------------
151  // Mutators:
152  // ----------------------------------------------------------------------
153 
156  : (sev >= ELhighestSeverity) ? (ELseverityLevel)ELsevere : sev;
157  }
158 
159  void ErrorObj::setID(const ELstring& id) {
160  myXid.id = ELstring(id, 0, maxIDlength);
161  if (id.length() > maxIDlength)
162  myIdOverflow = ELstring(id, maxIDlength, id.length() - maxIDlength);
163  }
164 
166 
167  void ErrorObj::setContext(const std::string_view& c) { myContext = c; }
168 
169  void ErrorObj::setSubroutine(const ELstring& subroutine) {
170 #ifdef ErrorObj_SUB_TRACE
171  std::cerr << "=:=:=: ErrorObj::setSubroutine(" << subroutine << ")\n";
172 #endif
173  myXid.subroutine = (subroutine[0] == ' ') ? subroutine.substr(1) : subroutine;
174  }
175 
177 
178 #ifdef ErrorObj_SUB_TRACE
179  static int subN = 0;
180 #endif
181 
183 #ifdef ErrorObj_EMIT_TRACE
184  std::cerr << "=:=:=: ErrorObj::emitToken( " << s << " )\n";
185 #endif
186 
187 #ifdef ErrorObj_SUB_TRACE
188  if (subN > 0) {
189  std::cerr << "=:=:=: subN ErrorObj::emitToken( " << s << " )\n";
190  subN--;
191  }
192 #endif
193 
194  if (eq_nocase(s.substr(0, 5), "@SUB=")) {
195 #ifdef ErrorObj_SUB_TRACE
196  std::cerr << "=:=:=: ErrorObj::@SUB s.substr(5) is: " << s.substr(5) << '\n';
197 #endif
198  setSubroutine(s.substr(5));
199  } else {
200  myItems.push_back(s);
201  }
202 
203  return *this;
204 
205  } // emitToken()
206 
207  void ErrorObj::set(const ELseverityLevel& sev, const ELstring& id) {
208  clear();
209 
210  myTimestamp = time(nullptr);
211  mySerial = ++ourSerial;
212 
213  setID(id);
214  setSeverity(sev);
215 
216  } // set()
217 
219  mySerial = 0;
220  myXid.clear();
221  myIdOverflow = "";
222  myTimestamp = 0;
223  myItems.erase(myItems.begin(), myItems.end()); // myItems.clear();
224  myReactedTo = false;
225 
226  } // clear()
227 
228  ErrorObj& ErrorObj::opltlt(const char s[]) {
229  // Exactly equivalent to the general template.
230  // If this is not provided explicitly, then the template will
231  // be instantiated once for each length of string ever used.
232  myOs.str(emptyString);
233  myOs << s;
234 #ifdef OLD_STYLE_AUTOMATIC_SPACES
235  if (!myOs.str().empty()) {
236  if (!verbatim) {
237  emitToken(myOs.str() + ' ');
238  } else {
239  emitToken(myOs.str());
240  }
241  }
242 #else
243  if (!myOs.str().empty())
244  emitToken(myOs.str());
245 #endif
246  return *this;
247  }
248 
249  ErrorObj& operator<<(ErrorObj& e, const char s[]) { return e.opltlt(s); }
250 
251 } // end of namespace edm */
edm::ErrorObj::setReactedTo
virtual void setReactedTo(bool r)
Definition: ErrorObj.cc:176
edm::ELlist_string
std::list< ELstring > ELlist_string
Definition: ELlist.h:36
edm::ErrorObj::serial
int serial() const
Definition: ErrorObj.cc:132
edm::ErrorObj::reactedTo
bool reactedTo() const
Definition: ErrorObj.cc:137
edm::ourSerial
static std::atomic< int > ourSerial(0)
edm::ErrorObj::mySerial
int mySerial
Definition: ErrorObj.h:93
edm::ELextendedID::id
ELstring id
Definition: ELextendedID.h:28
edm::ELzeroSeverity
const ELslProxy< ELzeroSeverityGen > ELzeroSeverity
Definition: ELseverityLevel.cc:284
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ErrorObj
Definition: ErrorObj.h:44
edm::ELextendedID
Definition: ELextendedID.h:24
edm::ErrorObj::ErrorObj
ErrorObj(const ELseverityLevel &sev, const ELstring &id, bool verbatim=false)
Definition: ErrorObj.cc:74
edm::friendlyname::emptyString
static const std::string emptyString("")
edm::ErrorObj::myContext
ELstring myContext
Definition: ErrorObj.h:99
edm::ErrorObj::myItems
ELlist_string myItems
Definition: ErrorObj.h:97
ErrorObj.h
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::ELextendedID::module
ELstring module
Definition: ELextendedID.h:30
edm::operator<<
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.
Definition: HLTGlobalStatus.h:106
alignCSCRings.s
s
Definition: alignCSCRings.py:92
edm::ELstring
std::string ELstring
Definition: ELstring.h:21
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
edm::ErrorObj::timestamp
time_t timestamp() const
Definition: ErrorObj.cc:135
edm::ErrorObj::setSeverity
virtual void setSeverity(const ELseverityLevel &sev)
Definition: ErrorObj.cc:154
trackingPlots.other
other
Definition: trackingPlots.py:1465
CMS_THREAD_SAFE
#define CMS_THREAD_SAFE
Definition: thread_safety_macros.h:4
edm::ErrorObj::xid
const ELextendedID & xid() const
Definition: ErrorObj.cc:133
edm::ELextendedID::subroutine
ELstring subroutine
Definition: ELextendedID.h:31
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ErrorObj::setSubroutine
virtual void setSubroutine(const ELstring &subroutine)
Definition: ErrorObj.cc:169
edm::ELsevere
const ELslProxy< ELsevereGen > ELsevere
Definition: ELseverityLevel.cc:320
edm::ELdebug
const ELslProxy< ELdebugGen > ELdebug
Definition: ELseverityLevel.cc:290
edm::ELhighestSeverity
const ELslProxy< ELhighestSeverityGen > ELhighestSeverity
Definition: ELseverityLevel.cc:326
edm::ErrorObj::myIdOverflow
ELstring myIdOverflow
Definition: ErrorObj.h:95
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
edm::maxIDlength
const unsigned int maxIDlength(200)
thread_safety_macros.h
edm::ErrorObj::items
const ELlist_string & items() const
Definition: ErrorObj.cc:136
edm::ErrorObj::myReactedTo
bool myReactedTo
Definition: ErrorObj.h:98
edm::ErrorObj::clear
virtual void clear()
Definition: ErrorObj.cc:218
edm::ErrorObj::emptyString
std::string emptyString
Definition: ErrorObj.h:101
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
module
Definition: vlib.h:198
edm::ErrorObj::idOverflow
const ELstring & idOverflow() const
Definition: ErrorObj.cc:134
edm::ErrorObj::myXid
ELextendedID myXid
Definition: ErrorObj.h:94
alignCSCRings.r
r
Definition: alignCSCRings.py:93
edm::ErrorObj::set
virtual void set(const ELseverityLevel &sev, const ELstring &id)
Definition: ErrorObj.cc:207
edm::ErrorObj::operator=
ErrorObj & operator=(const ErrorObj &other)
Definition: ErrorObj.cc:107
edm::ErrorObj::myOs
std::ostringstream myOs
Definition: ErrorObj.h:100
edm::eq_nocase
bool eq_nocase(const ELstring &s1, const char s2[])
Definition: ELstring.cc:21
edm::ELextendedID::clear
void clear()
Definition: ELextendedID.cc:46
edm::ELseverityLevel
Definition: ELseverityLevel.h:96
edm::ErrorObj::verbatim
bool verbatim
Definition: ErrorObj.h:102
edm::ErrorObj::myTimestamp
time_t myTimestamp
Definition: ErrorObj.h:96
edm::ErrorObj::setContext
virtual void setContext(const std::string_view &context)
Definition: ErrorObj.cc:167
edm::ErrorObj::~ErrorObj
virtual ~ErrorObj()
Definition: ErrorObj.cc:100
edm::ErrorObj::context
ELstring context() const
Definition: ErrorObj.cc:140
edm::ErrorObj::swap
void swap(ErrorObj &other)
Definition: ErrorObj.cc:113
edm::ErrorObj::setID
virtual void setID(const ELstring &ID)
Definition: ErrorObj.cc:159
edm::ErrorObj::emitToken
virtual ErrorObj & emitToken(const ELstring &txt)
Definition: ErrorObj.cc:182
edm::ErrorObj::setModule
virtual void setModule(const ELstring &module)
Definition: ErrorObj.cc:165
mps_fire.result
result
Definition: mps_fire.py:303
edm::ELextendedID::severity
ELseverityLevel severity
Definition: ELextendedID.h:29
edm::ErrorObj::opltlt
ErrorObj & opltlt(const T &t)
ntuplemaker.time
time
Definition: ntuplemaker.py:310
edm::ErrorObj::fullText
ELstring fullText() const
Definition: ErrorObj.cc:142
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::ErrorObj::is_verbatim
bool is_verbatim() const
Definition: ErrorObj.cc:138