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 <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),
89  myItems(orig.myItems),
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 
108  ErrorObj temp(other);
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);
118  myItems.swap(other.myItems);
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 
165  void ErrorObj::setModule(const ELstring& module) { myXid.module = module; }
166 
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 */
ELslProxy< ELdebugGen > const ELdebug
std::string emptyString
Definition: ErrorObj.h:101
ELseverityLevel severity
Definition: ELextendedID.h:29
time_t myTimestamp
Definition: ErrorObj.h:96
const ELstring & idOverflow() const
Definition: ErrorObj.cc:134
virtual ~ErrorObj()
Definition: ErrorObj.cc:100
virtual void setSeverity(const ELseverityLevel &sev)
Definition: ErrorObj.cc:154
ELstring myIdOverflow
Definition: ErrorObj.h:95
virtual void clear()
Definition: ErrorObj.cc:218
virtual void set(const ELseverityLevel &sev, const ELstring &id)
Definition: ErrorObj.cc:207
ErrorObj(const ELseverityLevel &sev, const ELstring &id, bool verbatim=false)
Definition: ErrorObj.cc:74
time_t timestamp() const
Definition: ErrorObj.cc:135
virtual ErrorObj & emitToken(const ELstring &txt)
Definition: ErrorObj.cc:182
void swap(ErrorObj &other)
Definition: ErrorObj.cc:113
virtual void setSubroutine(const ELstring &subroutine)
Definition: ErrorObj.cc:169
ELslProxy< ELhighestSeverityGen > const ELhighestSeverity
ELlist_string myItems
Definition: ErrorObj.h:97
virtual void setContext(const ELstring &context)
Definition: ErrorObj.cc:167
virtual void setReactedTo(bool r)
Definition: ErrorObj.cc:176
const ELextendedID & xid() const
Definition: ErrorObj.cc:133
ELextendedID myXid
Definition: ErrorObj.h:94
ErrorObj & opltlt(const T &t)
ELslProxy< ELzeroSeverityGen > const ELzeroSeverity
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
ErrorObj & operator<<(std::ostream &(*f)(std::ostream &))
std::ostringstream myOs
Definition: ErrorObj.h:100
#define CMS_THREAD_SAFE
const unsigned int maxIDlength(200)
int serial() const
Definition: ErrorObj.cc:132
ELstring fullText() const
Definition: ErrorObj.cc:142
ELstring subroutine
Definition: ELextendedID.h:31
bool reactedTo() const
Definition: ErrorObj.cc:137
bool verbatim
Definition: ErrorObj.h:102
static std::atomic< int > ourSerial(0)
const ELlist_string & items() const
Definition: ErrorObj.cc:136
virtual void setID(const ELstring &ID)
Definition: ErrorObj.cc:159
ELslProxy< ELsevereGen > const ELsevere
ErrorObj & operator=(const ErrorObj &other)
Definition: ErrorObj.cc:107
bool eq_nocase(const ELstring &s1, const char s2[])
Definition: ELstring.cc:21
ELstring myContext
Definition: ErrorObj.h:99
HLT enums.
bool myReactedTo
Definition: ErrorObj.h:98
std::list< ELstring > ELlist_string
Definition: ELlist.h:36
bool is_verbatim() const
Definition: ErrorObj.cc:138
std::string ELstring
Definition: ELstring.h:21
Definition: vlib.h:208
ELstring context() const
Definition: ErrorObj.cc:140
int mySerial
Definition: ErrorObj.h:93
virtual void setModule(const ELstring &module)
Definition: ErrorObj.cc:165