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 
45 
46 #ifndef IOSTREAM_INCLUDED
47 #endif
48 
49 
50 // ----------------------------------------------------------------------
51 
52 
53 // Possible Traces
54 // #define ErrorObjCONSTRUCTOR_TRACE
55 // #define ErrorObj_EMIT_TRACE
56 // #define ErrorObj_SUB_TRACE
57 
58 
59 // ----------------------------------------------------------------------
60 
61 
62 namespace edm
63 {
64 
65 
66 // ----------------------------------------------------------------------
67 // Class static and class-wide parameter:
68 // ----------------------------------------------------------------------
69 
70  // --- class-wide serial number stamper:
71  //
72 [[cms::thread_safe]] static std::atomic<int> ourSerial( 0 );
73 const unsigned int maxIDlength( 200 ); // changed 4/28/06 from 20
74 
75 
76 // ----------------------------------------------------------------------
77 // Birth/death:
78 // ----------------------------------------------------------------------
79 
81  const ELstring & id,
82  bool verbat ) : verbatim(verbat) {
83 
84  #ifdef ErrorObjCONSTRUCTOR_TRACE
85  std::cerr << "Constructor for ErrorObj\n";
86  #endif
87 
88  clear();
89  set( sev, id );
90 
91 } // ErrorObj()
92 
93 
94 ErrorObj::ErrorObj( const ErrorObj & orig ) :
95  mySerial ( orig.mySerial )
96  , myXid ( orig.myXid )
97  , myIdOverflow ( orig.myIdOverflow )
98  , myTimestamp ( orig.myTimestamp )
99  , myItems ( orig.myItems )
100  , myReactedTo ( orig.myReactedTo )
101  , myOs ( )
102  , emptyString ( )
103  , verbatim ( orig.verbatim )
104 {
105 
106  #ifdef ErrorObjCONSTRUCTOR_TRACE
107  std::cerr << "Copy Constructor for ErrorObj\n";
108  #endif
109 
110 } // ErrorObj(ErrorObj)
111 
112 
114 
115  #ifdef ErrorObjCONSTRUCTOR_TRACE
116  std::cerr << "Destructor for ErrorObj\n";
117  #endif
118 
119 } // ~ErrorObj()
120 
122  ErrorObj temp(other);
123  this->swap(temp);
124  return *this;
125 }
126 
128  std::swap(mySerial, other.mySerial);
129  std::swap(myXid, other.myXid);
130  myIdOverflow.swap(other.myIdOverflow);
132  myItems.swap(other.myItems);
134  myContext.swap(other.myContext);
135  std::string temp(other.myOs.str());
136  other.myOs.str(myOs.str());
137  myOs.str(temp);
138  emptyString.swap(other.emptyString);
139  std::swap(verbatim, other.verbatim);
140 }
141 
142 // ----------------------------------------------------------------------
143 // Accessors:
144 // ----------------------------------------------------------------------
145 
146 int ErrorObj::serial() const { return mySerial; }
147 const ELextendedID & ErrorObj::xid() const { return myXid; }
148 const ELstring & ErrorObj::idOverflow() const { return myIdOverflow; }
149 time_t ErrorObj::timestamp() const { return myTimestamp; }
150 const ELlist_string & ErrorObj::items() const { return myItems; }
151 bool ErrorObj::reactedTo() const { return myReactedTo; }
152 bool ErrorObj::is_verbatim()const { return verbatim; }
153 
155  return myContext;
156 }
157 
159 
161  for ( ELlist_string::const_iterator it = myItems.begin();
162  it != myItems.end();
163  ++it )
164  result += *it;
165  return result;
166 
167 } // fullText()
168 
169 
170 // ----------------------------------------------------------------------
171 // Mutators:
172 // ----------------------------------------------------------------------
173 
177  : sev
178  ;
179 }
180 
181 
182 void ErrorObj::setID( const ELstring & id ) {
183  myXid.id = ELstring( id, 0, maxIDlength );
184  if ( id.length() > maxIDlength )
185  myIdOverflow = ELstring( id, maxIDlength, id.length()-maxIDlength );
186 }
187 
188 
190 
191 void ErrorObj::setContext( const ELstring & c ) { myContext = c; }
192 
193 
194 void ErrorObj::setSubroutine( const ELstring & subroutine ) {
195  #ifdef ErrorObj_SUB_TRACE
196  std::cerr << "=:=:=: ErrorObj::setSubroutine(" << subroutine << ")\n";
197  #endif
198  myXid.subroutine = (subroutine[0] == ' ')
199  ? subroutine.substr(1)
200  : subroutine;
201 }
202 
203 
204 void ErrorObj::setReactedTo( bool r ) {
205  myReactedTo = r;
206 }
207 
208 
209 #ifdef ErrorObj_SUB_TRACE
210  static int subN = 0;
211 #endif
212 
213 
215 
216  #ifdef ErrorObj_EMIT_TRACE
217  std::cerr << "=:=:=: ErrorObj::emitToken( " << s << " )\n";
218  #endif
219 
220  #ifdef ErrorObj_SUB_TRACE
221  if ( subN > 0 ) {
222  std::cerr << "=:=:=: subN ErrorObj::emitToken( " << s << " )\n";
223  subN--;
224  }
225  #endif
226 
227  if ( eq_nocase(s.substr(0,5), "@SUB=" ) ) {
228  #ifdef ErrorObj_SUB_TRACE
229  std::cerr << "=:=:=: ErrorObj::@SUB s.substr(5) is: " << s.substr(5)
230  << '\n';
231  #endif
232  setSubroutine(s.substr(5));
233  }
234  else {
235  myItems.push_back( s );
236  }
237 
238  return * this;
239 
240 } // emitToken()
241 
242 
243 void ErrorObj::set( const ELseverityLevel & sev, const ELstring & id ) {
244 
245  clear();
246 
247  myTimestamp = time( nullptr );
248  mySerial = ++ ourSerial;
249 
250  setID( id );
251  setSeverity( sev );
252 
253 } // set()
254 
255 
257 
258  mySerial = 0;
259  myXid.clear();
260  myIdOverflow = "";
261  myTimestamp = 0;
262  myItems.erase( myItems.begin(), myItems.end() ); // myItems.clear();
263  myReactedTo = false;
264 
265 } // clear()
266 
267 ErrorObj &
268 ErrorObj::opltlt ( const char s[] ) {
269  // Exactly equivalent to the general template.
270  // If this is not provided explicitly, then the template will
271  // be instantiated once for each length of string ever used.
272  myOs.str(emptyString);
273  myOs << s;
274 #ifdef OLD_STYLE_AUTOMATIC_SPACES
275  if ( ! myOs.str().empty() ) {
276  if ( !verbatim ) {
277  emitToken( myOs.str() + ' ' );
278  } else {
279  emitToken( myOs.str() );
280  }
281  }
282 #else
283  if ( ! myOs.str().empty() ) emitToken( myOs.str() );
284 #endif
285  return *this;
286 }
287 
288 ErrorObj & operator<<( ErrorObj & e, const char s[] ) {
289  return e.opltlt(s);
290 }
291 
292 } // end of namespace edm */
ELslProxy< ELdebugGen > const ELdebug
std::string emptyString
Definition: ErrorObj.h:109
ELseverityLevel severity
Definition: ELextendedID.h:35
time_t myTimestamp
Definition: ErrorObj.h:104
const ELstring & idOverflow() const
Definition: ErrorObj.cc:148
virtual ~ErrorObj()
Definition: ErrorObj.cc:113
virtual void setSeverity(const ELseverityLevel &sev)
Definition: ErrorObj.cc:174
ELstring myIdOverflow
Definition: ErrorObj.h:103
virtual void clear()
Definition: ErrorObj.cc:256
virtual void set(const ELseverityLevel &sev, const ELstring &id)
Definition: ErrorObj.cc:243
ErrorObj(const ELseverityLevel &sev, const ELstring &id, bool verbatim=false)
Definition: ErrorObj.cc:80
time_t timestamp() const
Definition: ErrorObj.cc:149
virtual ErrorObj & emitToken(const ELstring &txt)
Definition: ErrorObj.cc:214
void swap(ErrorObj &other)
Definition: ErrorObj.cc:127
virtual void setSubroutine(const ELstring &subroutine)
Definition: ErrorObj.cc:194
ELslProxy< ELhighestSeverityGen > const ELhighestSeverity
ELlist_string myItems
Definition: ErrorObj.h:105
virtual void setContext(const ELstring &context)
Definition: ErrorObj.cc:191
virtual void setReactedTo(bool r)
Definition: ErrorObj.cc:204
const ELextendedID & xid() const
Definition: ErrorObj.cc:147
ELextendedID myXid
Definition: ErrorObj.h:102
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:108
const unsigned int maxIDlength(200)
int serial() const
Definition: ErrorObj.cc:146
ELstring fullText() const
Definition: ErrorObj.cc:158
ELstring subroutine
Definition: ELextendedID.h:37
bool reactedTo() const
Definition: ErrorObj.cc:151
bool verbatim
Definition: ErrorObj.h:110
static std::atomic< int > ourSerial(0)
const ELlist_string & items() const
Definition: ErrorObj.cc:150
virtual void setID(const ELstring &ID)
Definition: ErrorObj.cc:182
ELslProxy< ELsevereGen > const ELsevere
ErrorObj & operator=(const ErrorObj &other)
Definition: ErrorObj.cc:121
bool eq_nocase(const ELstring &s1, const char s2[])
Definition: ELstring.cc:24
std::list< ELstring > ELlist_string
Definition: ELlist.h:42
ELstring myContext
Definition: ErrorObj.h:107
HLT enums.
bool myReactedTo
Definition: ErrorObj.h:106
bool is_verbatim() const
Definition: ErrorObj.cc:152
std::string ELstring
Definition: ELstring.h:26
Definition: vlib.h:208
ELstring context() const
Definition: ErrorObj.cc:154
virtual void setModule(const ELstring &module)
Definition: ErrorObj.cc:189