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 
121  ErrorObj temp(other);
122  this->swap(temp);
123  return *this;
124 }
125 
126 void ErrorObj::swap( ErrorObj& other ) {
127  std::swap(mySerial, other.mySerial);
128  std::swap(myXid, other.myXid);
129  myIdOverflow.swap(other.myIdOverflow);
131  myItems.swap(other.myItems);
133  myContext.swap(other.myContext);
134  std::string temp(other.myOs.str());
135  other.myOs.str(myOs.str());
136  myOs.str(temp);
137  emptyString.swap(other.emptyString);
138  std::swap(verbatim, other.verbatim);
139 }
140 
141 // ----------------------------------------------------------------------
142 // Accessors:
143 // ----------------------------------------------------------------------
144 
145 int ErrorObj::serial() const { return mySerial; }
146 const ELextendedID & ErrorObj::xid() const { return myXid; }
147 const ELstring & ErrorObj::idOverflow() const { return myIdOverflow; }
148 time_t ErrorObj::timestamp() const { return myTimestamp; }
149 const ELlist_string & ErrorObj::items() const { return myItems; }
150 bool ErrorObj::reactedTo() const { return myReactedTo; }
151 bool ErrorObj::is_verbatim()const { return verbatim; }
152 
154  return myContext;
155 }
156 
158 
160  for ( ELlist_string::const_iterator it = myItems.begin();
161  it != myItems.end();
162  ++it )
163  result += *it;
164  return result;
165 
166 } // fullText()
167 
168 
169 // ----------------------------------------------------------------------
170 // Mutators:
171 // ----------------------------------------------------------------------
172 
176  : sev
177  ;
178 }
179 
180 
181 void ErrorObj::setID( const ELstring & id ) {
182  myXid.id = ELstring( id, 0, maxIDlength );
183  if ( id.length() > maxIDlength )
184  myIdOverflow = ELstring( id, maxIDlength, id.length()-maxIDlength );
185 }
186 
187 
189 
190 void ErrorObj::setContext( const ELstring & c ) { myContext = c; }
191 
192 
193 void ErrorObj::setSubroutine( const ELstring & subroutine ) {
194  #ifdef ErrorObj_SUB_TRACE
195  std::cerr << "=:=:=: ErrorObj::setSubroutine(" << subroutine << ")\n";
196  #endif
197  myXid.subroutine = (subroutine[0] == ' ')
198  ? subroutine.substr(1)
199  : subroutine;
200 }
201 
202 
204  myXid.process = proc;
205  #if 0
206  std::cerr << "ErrorObj process set to \"" << proc << "\"\n";
207  #endif
208 }
209 
210 void ErrorObj::setReactedTo( bool r ) {
211  myReactedTo = r;
212 }
213 
214 
215 #ifdef ErrorObj_SUB_TRACE
216  static int subN = 0;
217 #endif
218 
219 
221 
222  #ifdef ErrorObj_EMIT_TRACE
223  std::cerr << "=:=:=: ErrorObj::emitToken( " << s << " )\n";
224  #endif
225 
226  #ifdef ErrorObj_SUB_TRACE
227  if ( subN > 0 ) {
228  std::cerr << "=:=:=: subN ErrorObj::emitToken( " << s << " )\n";
229  subN--;
230  }
231  #endif
232 
233  if ( eq_nocase(s.substr(0,5), "@SUB=" ) ) {
234  #ifdef ErrorObj_SUB_TRACE
235  std::cerr << "=:=:=: ErrorObj::@SUB s.substr(5) is: " << s.substr(5)
236  << '\n';
237  #endif
238  setSubroutine(s.substr(5));
239  }
240  else {
241  myItems.push_back( s );
242  }
243 
244  return * this;
245 
246 } // emitToken()
247 
248 
249 void ErrorObj::set( const ELseverityLevel & sev, const ELstring & id ) {
250 
251  clear();
252 
253  myTimestamp = time( 0 );
254  mySerial = ++ ourSerial;
255 
256  setID( id );
257  setSeverity( sev );
258 
259 } // set()
260 
261 
263 
264  mySerial = 0;
265  myXid.clear();
266  myIdOverflow = "";
267  myTimestamp = 0;
268  myItems.erase( myItems.begin(), myItems.end() ); // myItems.clear();
269  myReactedTo = false;
270 
271 } // clear()
272 
273 ErrorObj &
274 ErrorObj::opltlt ( const char s[] ) {
275  // Exactly equivalent to the general template.
276  // If this is not provided explicitly, then the template will
277  // be instantiated once for each length of string ever used.
278  myOs.str(emptyString);
279  myOs << s;
280 #ifdef OLD_STYLE_AUTOMATIC_SPACES
281  if ( ! myOs.str().empty() ) {
282  if ( !verbatim ) {
283  emitToken( myOs.str() + ' ' );
284  } else {
285  emitToken( myOs.str() );
286  }
287  }
288 #else
289  if ( ! myOs.str().empty() ) emitToken( myOs.str() );
290 #endif
291  return *this;
292 }
293 
294 ErrorObj & operator<<( ErrorObj & e, const char s[] ) {
295  return e.opltlt(s);
296 }
297 
298 } // end of namespace edm */
std::string emptyString
Definition: ErrorObj.h:118
ELseverityLevel severity
Definition: ELextendedID.h:36
time_t myTimestamp
Definition: ErrorObj.h:113
const ELstring & idOverflow() const
Definition: ErrorObj.cc:147
virtual ~ErrorObj()
Definition: ErrorObj.cc:112
virtual void setSeverity(const ELseverityLevel &sev)
Definition: ErrorObj.cc:173
ELstring myIdOverflow
Definition: ErrorObj.h:112
virtual void clear()
Definition: ErrorObj.cc:262
virtual void set(const ELseverityLevel &sev, const ELstring &id)
Definition: ErrorObj.cc:249
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:148
virtual ErrorObj & emitToken(const ELstring &txt)
Definition: ErrorObj.cc:220
void swap(ErrorObj &other)
Definition: ErrorObj.cc:126
ELslProxy< ELfatalGen > const ELfatal
virtual void setSubroutine(const ELstring &subroutine)
Definition: ErrorObj.cc:193
ELslProxy< ELhighestSeverityGen > const ELhighestSeverity
ELlist_string myItems
Definition: ErrorObj.h:114
virtual void setContext(const ELstring &context)
Definition: ErrorObj.cc:190
virtual void setReactedTo(bool r)
Definition: ErrorObj.cc:210
const ELextendedID & xid() const
Definition: ErrorObj.cc:146
ELextendedID myXid
Definition: ErrorObj.h:111
ErrorObj & opltlt(const T &t)
ELslProxy< ELzeroSeverityGen > const ELzeroSeverity
ELslProxy< ELincidentalGen > const ELincidental
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
tuple result
Definition: query.py:137
std::ostringstream myOs
Definition: ErrorObj.h:117
const unsigned int maxIDlength(200)
int serial() const
Definition: ErrorObj.cc:145
ELstring fullText() const
Definition: ErrorObj.cc:157
ELstring subroutine
Definition: ELextendedID.h:38
bool reactedTo() const
Definition: ErrorObj.cc:150
bool verbatim
Definition: ErrorObj.h:119
const ELlist_string & items() const
Definition: ErrorObj.cc:149
virtual void setID(const ELstring &ID)
Definition: ErrorObj.cc:181
ErrorObj & operator=(const ErrorObj &other)
Definition: ErrorObj.cc:120
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:116
static std::string const emptyString("")
virtual void setProcess(const ELstring &proc)
Definition: ErrorObj.cc:203
bool myReactedTo
Definition: ErrorObj.h:115
static int ourSerial
Definition: ErrorObj.h:106
bool is_verbatim() const
Definition: ErrorObj.cc:151
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:153
virtual void setModule(const ELstring &module)
Definition: ErrorObj.cc:188