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