CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 // setProcess ( const ELstring & proc )
37 // setModule ( const ELstring & module )
38 // setSubroutine( const ELstring & subroutine )
39 // emitToken( const ELstring & txt )
40 // operator<<( void (* f)(ErrorLog &) )
41 //
42 // ----------------------------------------------------------------------
43 
44 
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 int ErrorObj::ourSerial( 0 );
72 const unsigned int maxIDlength( 200 ); // changed 4/28/06 from 20
73 
74 
75 // ----------------------------------------------------------------------
76 // Birth/death:
77 // ----------------------------------------------------------------------
78 
80  const ELstring & id,
81  bool verbat ) : verbatim(verbat) {
82 
83  #ifdef ErrorObjCONSTRUCTOR_TRACE
84  std::cerr << "Constructor for ErrorObj\n";
85  #endif
86 
87  clear();
88  set( sev, id );
89 
90 } // ErrorObj()
91 
92 
93 ErrorObj::ErrorObj( const ErrorObj & orig ) :
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 {
104 
105  #ifdef ErrorObjCONSTRUCTOR_TRACE
106  std::cerr << "Copy Constructor for ErrorObj\n";
107  #endif
108 
109 } // ErrorObj(ErrorObj)
110 
111 
113 
114  #ifdef ErrorObjCONSTRUCTOR_TRACE
115  std::cerr << "Destructor for ErrorObj\n";
116  #endif
117 
118 } // ~ErrorObj()
119 
120 
121 // ----------------------------------------------------------------------
122 // Accessors:
123 // ----------------------------------------------------------------------
124 
125 int ErrorObj::serial() const { return mySerial; }
126 const ELextendedID & ErrorObj::xid() const { return myXid; }
127 const ELstring & ErrorObj::idOverflow() const { return myIdOverflow; }
128 time_t ErrorObj::timestamp() const { return myTimestamp; }
129 const ELlist_string & ErrorObj::items() const { return myItems; }
130 bool ErrorObj::reactedTo() const { return myReactedTo; }
131 bool ErrorObj::is_verbatim()const { return verbatim; }
132 
134  return myContext;
135 }
136 
138 
140  for ( ELlist_string::const_iterator it = myItems.begin();
141  it != myItems.end();
142  ++it )
143  result += *it;
144  return result;
145 
146 } // fullText()
147 
148 
149 // ----------------------------------------------------------------------
150 // Mutators:
151 // ----------------------------------------------------------------------
152 
156  : sev
157  ;
158 }
159 
160 
161 void ErrorObj::setID( const ELstring & id ) {
162  myXid.id = ELstring( id, 0, maxIDlength );
163  if ( id.length() > maxIDlength )
164  myIdOverflow = ELstring( id, maxIDlength, id.length()-maxIDlength );
165 }
166 
167 
169 
170 void ErrorObj::setContext( const ELstring & c ) { myContext = c; }
171 
172 
173 void ErrorObj::setSubroutine( const ELstring & subroutine ) {
174  #ifdef ErrorObj_SUB_TRACE
175  std::cerr << "=:=:=: ErrorObj::setSubroutine(" << subroutine << ")\n";
176  #endif
177  myXid.subroutine = (subroutine[0] == ' ')
178  ? subroutine.substr(1)
179  : subroutine;
180 }
181 
182 
184  myXid.process = proc;
185  #if 0
186  std::cerr << "ErrorObj process set to \"" << proc << "\"\n";
187  #endif
188 }
189 
190 void ErrorObj::setReactedTo( bool r ) {
191  myReactedTo = r;
192 }
193 
194 
195 #ifdef ErrorObj_SUB_TRACE
196  static int subN = 0;
197 #endif
198 
199 
201 
202  #ifdef ErrorObj_EMIT_TRACE
203  std::cerr << "=:=:=: ErrorObj::emitToken( " << s << " )\n";
204  #endif
205 
206  #ifdef ErrorObj_SUB_TRACE
207  if ( subN > 0 ) {
208  std::cerr << "=:=:=: subN ErrorObj::emitToken( " << s << " )\n";
209  subN--;
210  }
211  #endif
212 
213  if ( eq_nocase(s.substr(0,5), "@SUB=" ) ) {
214  #ifdef ErrorObj_SUB_TRACE
215  std::cerr << "=:=:=: ErrorObj::@SUB s.substr(5) is: " << s.substr(5)
216  << '\n';
217  #endif
218  setSubroutine(s.substr(5));
219  }
220  else {
221  myItems.push_back( s );
222  }
223 
224  return * this;
225 
226 } // emitToken()
227 
228 
229 void ErrorObj::set( const ELseverityLevel & sev, const ELstring & id ) {
230 
231  clear();
232 
233  myTimestamp = time( 0 );
234  mySerial = ++ ourSerial;
235 
236  setID( id );
237  setSeverity( sev );
238 
239 } // set()
240 
241 
243 
244  mySerial = 0;
245  myXid.clear();
246  myIdOverflow = "";
247  myTimestamp = 0;
248  myItems.erase( myItems.begin(), myItems.end() ); // myItems.clear();
249  myReactedTo = false;
250 
251 } // clear()
252 
253 ErrorObj &
254 ErrorObj::opltlt ( const char s[] ) {
255  // Exactly equivalent to the general template.
256  // If this is not provided explicitly, then the template will
257  // be instantiated once for each length of string ever used.
258  myOs.str(emptyString);
259  myOs << s;
260 #ifdef OLD_STYLE_AUTOMATIC_SPACES
261  if ( ! myOs.str().empty() ) {
262  if ( !verbatim ) {
263  emitToken( myOs.str() + ' ' );
264  } else {
265  emitToken( myOs.str() );
266  }
267  }
268 #else
269  if ( ! myOs.str().empty() ) emitToken( myOs.str() );
270 #endif
271  return *this;
272 }
273 
274 ErrorObj & operator<<( ErrorObj & e, const char s[] ) {
275  return e.opltlt(s);
276 }
277 
278 } // end of namespace edm */
std::string emptyString
Definition: ErrorObj.h:116
ELseverityLevel severity
Definition: ELextendedID.h:36
time_t myTimestamp
Definition: ErrorObj.h:111
int module() const
Definition: HLTadd.h:12
const ELstring & idOverflow() const
Definition: ErrorObj.cc:127
virtual ~ErrorObj()
Definition: ErrorObj.cc:112
virtual void setSeverity(const ELseverityLevel &sev)
Definition: ErrorObj.cc:153
ELstring myIdOverflow
Definition: ErrorObj.h:110
virtual void clear()
Definition: ErrorObj.cc:242
virtual void set(const ELseverityLevel &sev, const ELstring &id)
Definition: ErrorObj.cc:229
ErrorObj(const ELseverityLevel &sev, const ELstring &id, bool verbatim=false)
Definition: ErrorObj.cc:79
TrainProcessor *const proc
Definition: MVATrainer.cc:101
time_t timestamp() const
Definition: ErrorObj.cc:128
virtual ErrorObj & emitToken(const ELstring &txt)
Definition: ErrorObj.cc:200
ELslProxy< ELfatalGen > const ELfatal
virtual void setSubroutine(const ELstring &subroutine)
Definition: ErrorObj.cc:173
ELslProxy< ELhighestSeverityGen > const ELhighestSeverity
ELlist_string myItems
Definition: ErrorObj.h:112
virtual void setContext(const ELstring &context)
Definition: ErrorObj.cc:170
virtual void setReactedTo(bool r)
Definition: ErrorObj.cc:190
const ELextendedID & xid() const
Definition: ErrorObj.cc:126
ELextendedID myXid
Definition: ErrorObj.h:109
ErrorObj & opltlt(const T &t)
ELslProxy< ELzeroSeverityGen > const ELzeroSeverity
ELslProxy< ELincidentalGen > const ELincidental
tuple result
Definition: query.py:137
std::ostringstream myOs
Definition: ErrorObj.h:115
const unsigned int maxIDlength(200)
int serial() const
Definition: ErrorObj.cc:125
ELstring fullText() const
Definition: ErrorObj.cc:137
ELstring subroutine
Definition: ELextendedID.h:38
bool reactedTo() const
Definition: ErrorObj.cc:130
bool verbatim
Definition: ErrorObj.h:117
const ELlist_string & items() const
Definition: ErrorObj.cc:129
virtual void setID(const ELstring &ID)
Definition: ErrorObj.cc:161
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:114
static std::string const emptyString("")
virtual void setProcess(const ELstring &proc)
Definition: ErrorObj.cc:183
bool myReactedTo
Definition: ErrorObj.h:113
static int ourSerial
Definition: ErrorObj.h:104
string s
Definition: asciidump.py:422
bool is_verbatim() const
Definition: ErrorObj.cc:131
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.
std::string ELstring
Definition: ELstring.h:26
Definition: vlib.h:209
ELstring context() const
Definition: ErrorObj.cc:133
virtual void setModule(const ELstring &module)
Definition: ErrorObj.cc:168