CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ELfwkJobReport.cc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------
2 //
3 // ELfwkJobReport.cc
4 //
5 //
6 // 1/10/06 mf, de Created
7 //
8 // Changes:
9 //
10 // 1 - 3/22/06 mf - in configure_dest()
11 // Repaired the fact that destination limits for categories
12 // were not being effective:
13 // a) use values from the destination specific default PSet
14 // rather than the overall default PSet to set these
15 // b) when an explicit value has been set - either by overall default or
16 // by a destination specific default PSet - set that limit or
17 // timespan for that dest_ctrl via a "*" msgId.
18 //
19 // ----------------------------------------------------------------------
20 
21 
25 
26 // Possible Traces:
27 // #define ELfwkJobReportCONSTRUCTOR_TRACE
28 // #define ELfwkJobReportTRACE_LOG
29 // #define ELfwkJobReport_EMIT_TRACE
30 
31 #include <iostream>
32 #include <fstream>
33 
34 namespace edm {
35 namespace service {
36 
37 // ----------------------------------------------------------------------
38 // Constructors:
39 // ----------------------------------------------------------------------
40 
42 : ELdestination ( )
43 , os ( &std::cerr, do_nothing_deleter() )
44 , charsOnLine ( 0 )
45 , xid ( )
46 , wantTimestamp ( true )
47 , wantModule ( true )
48 , wantSubroutine ( true )
49 , wantText ( true )
50 , wantSomeContext ( true )
51 , wantSerial ( false )
52 , wantFullContext ( false )
53 , wantTimeSeparate ( false )
54 , wantEpilogueSeparate( false )
55 {
56 
57  #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
58  std::cerr << "Constructor for ELfwkJobReport()\n";
59  #endif
60 
61  // Opening xml tag
62  emitToken( "<FrameworkJobReport>\n", true );
63 
64 } // ELfwkJobReport()
65 
66 
67 ELfwkJobReport::ELfwkJobReport( std::ostream & os_ , bool /*emitAtStart*/ )
68 : ELdestination ( )
69 , os ( &os_, do_nothing_deleter() )
70 , charsOnLine ( 0 )
71 , xid ( )
72 , wantTimestamp ( true )
73 , wantModule ( true )
74 , wantSubroutine ( true )
75 , wantText ( true )
76 , wantSomeContext ( true )
77 , wantSerial ( false )
78 , wantFullContext ( false )
79 , wantTimeSeparate ( false )
80 , wantEpilogueSeparate( false )
81 {
82 
83  #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
84  std::cerr << "Constructor for ELfwkJobReport( os )\n";
85  #endif
86 
87  // Opening xml tag
88  emitToken( "<FrameworkJobReport>\n\n", true );
89 
90 } // ELfwkJobReport()
91 
92 
93 ELfwkJobReport::ELfwkJobReport( const ELstring & fileName, bool /*emitAtStart*/ )
94 : ELdestination ( )
95 , os ( new std::ofstream( fileName.c_str() , std::ios/*_base*/::app), close_and_delete())
96 , charsOnLine ( 0 )
97 , xid ( )
98 , wantTimestamp ( true )
99 , wantModule ( true )
100 , wantSubroutine ( true )
101 , wantText ( true )
102 , wantSomeContext ( true )
103 , wantSerial ( false )
104 , wantFullContext ( false )
105 , wantTimeSeparate ( false )
106 , wantEpilogueSeparate( false )
107 {
108 
109  #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
110  std::cerr << "Constructor for ELfwkJobReport( " << fileName << " )\n";
111  #endif
112 
113  if ( os && *os ) {
114  #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
115  std::cerr << " Testing if os is owned\n";
116  #endif
117  #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
118  std::cerr << " About to do first emit\n";
119  #endif
120  // Opening xml tag
121  emitToken( "<FrameworkJobReport>\n");
122  } else {
123  #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
124  std::cerr << " Deleting os\n";
125  #endif
126  os.reset(&std::cerr, do_nothing_deleter());
127  #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
128  std::cerr << " about to emit to cerr\n";
129  #endif
130  // Opening xml tag
131  emitToken( "<FrameworkJobReport>\n\n" );
132  }
133 
134  #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
135  std::cerr << "Constructor for ELfwkJobReport completed.\n";
136  #endif
137 
138 } // ELfwkJobReport()
139 
140 
142 : ELdestination ( )
143 , os ( orig.os )
144 , charsOnLine ( orig.charsOnLine )
145 , xid ( orig.xid )
146 , wantTimestamp ( orig.wantTimestamp )
147 , wantModule ( orig.wantModule )
148 , wantSubroutine ( orig.wantSubroutine )
149 , wantText ( orig.wantText )
150 , wantSomeContext ( orig.wantSomeContext )
151 , wantSerial ( orig.wantSerial )
152 , wantFullContext ( orig.wantFullContext )
153 , wantTimeSeparate ( orig.wantTimeSeparate )
154 , wantEpilogueSeparate( orig.wantEpilogueSeparate )
155 {
156 
157  #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
158  std::cerr << "Copy constructor for ELfwkJobReport\n";
159  #endif
160 
161  // mf 6/15/01 fix of Bug 005
162  threshold = orig.threshold;
164  limits = orig.limits;
165  preamble = orig.preamble;
166  newline = orig.newline;
167  indent = orig.indent;
168  lineLength = orig.lineLength;
169 
173  ignoreThese = orig.ignoreThese;
174 
175 } // ELfwkJobReport()
176 
177 
179 
180  #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
181  std::cerr << "Destructor for ELfwkJobReport\n";
182  #endif
183 } // ~ELfwkJobReport()
184 
185 
186 // ----------------------------------------------------------------------
187 // Methods invoked by the ELadministrator:
188 // ----------------------------------------------------------------------
189 
192 
193  return new ELfwkJobReport( *this );
194 
195 } // clone()
196 
197 
199 
200  #ifdef ELfwkJobReportTRACE_LOG
201  std::cerr << " =:=:=: Log to an ELfwkJobReport \n";
202  #endif
203 
204  xid = msg.xid(); // Save the xid.
205 
206  // Change log 1: React ONLY to category FwkJob
207  if (xid.id != "FwkJob") return false;
208 
209  // See if this message is to be acted upon
210  // (this is redundant if we are reacting only to FwkJob)
211  // and add it to limits table if it was not already present:
212  //
213  if ( msg.xid().severity < threshold ) return false;
214 
215  if ( (xid.id == "BeginningJob") ||
216  (xid.id == "postBeginJob") ||
217  (xid.id == "preEventProcessing") ||
218  (xid.id == "preModule") ||
219  (xid.id == "postModule") ||
220  (xid.id == "postEventProcessing") ||
221  (xid.id == "postEndJob") ) return false;
222  if ( thisShouldBeIgnored(xid.module) ) return false;
223  if ( ! limits.add( msg.xid() ) ) return false;
224 
225  #ifdef ELfwkJobReportTRACE_LOG
226  std::cerr << " =:=:=: Limits table work done \n";
227  #endif
228 
229  // Output the prologue:
230  //
231  //emitToken( " <Report>\n" );
232  //emitToken( " <Severity> " );
233  //emitToken(xid.severity.getSymbol());
234  //emitToken(" </Severity>\n");
235  //emitToken( " <Category> ");
236  //emitToken(xid.id);
237  //emitToken( " </Category>\n");
238  //emitToken( " <Message> \n");
239 
240  // emitToken( msg.idOverflow() ); this is how to get the rest of the category
241 
242  #ifdef ELfwkJobReportTRACE_LOG
243  std::cerr << " =:=:=: Prologue done \n";
244  #endif
245 
246  // Output each item in the message:
247  //
248  if ( wantText ) {
249  ELlist_string::const_iterator it;
250  for ( it = msg.items().begin(); it != msg.items().end(); ++it ) {
251  #ifdef ELfwkJobReportTRACE_LOG
252  std::cerr << " =:=:=: Item: " << *it << '\n';
253  #endif
254  // emitToken( " <Item> " );
255  emitToken( *it);
256  emitToken( "\n" );
257  //emitToken( " </Item>\n" );
258  }
259  }
260 
261  // Close the body of the message
262  //emitToken(" </Message>\n");
263 
264  // Provide further identification: Module
265  //
266  //emitToken(" <Module> ");
267  //emitToken( xid.module );
268  //emitToken(" </Module>\n");
269 
270  #ifdef ELfwkJobReportTRACE_LOG
271  std::cerr << " =:=:=: Module done \n";
272  #endif
273 
274  // close report
275  //
276  //emitToken(" </Report>\n\n");
277 
278  #ifdef ELfwkJobReportTRACE_LOG
279  std::cerr << " =:=:=: log(msg) done: \n";
280  #endif
281 
282  return true;
283 
284 } // log()
285 
287  // closing xml tag
288  (*os) << "</FrameworkJobReport>\n";
289 }
290 
291 // Remainder are from base class.
292 
293 
294 // ----------------------------------------------------------------------
295 // Output methods:
296 // ----------------------------------------------------------------------
297 
298 void ELfwkJobReport::emitToken( const ELstring & s, bool /*nl*/ ) {
299 
300  #ifdef ELfwkJobReport_EMIT_TRACE
301  std::cerr << "[][][] in emit: charsOnLine is " << charsOnLine << '\n';
302  std::cerr << "[][][] in emit: s.length() " << s.length() << '\n';
303  std::cerr << "[][][] in emit: lineLength is " << lineLength << '\n';
304  #endif
305 
306  if (s.length() == 0) {
307  return;
308  }
309 
310  #ifdef ELfwkJobReport_EMIT_TRACE
311  std::cerr << "[][][] in emit: about to << s to *os: " << s << " \n";
312  #endif
313 
314  (*os) << s;
315 
316  #ifdef ELfwkJobReport_EMIT_TRACE
317  std::cerr << "[][][] in emit: completed \n";
318  #endif
319 
320 } // emitToken()
321 
322 
323 // ----------------------------------------------------------------------
324 // Methods controlling message formatting:
325 // ----------------------------------------------------------------------
326 
329 
332 
335 
338 
341 
344 
347 
350 
353 
354 
355 // ----------------------------------------------------------------------
356 // Summary output:
357 // ----------------------------------------------------------------------
358 
360  const ELstring & fullTitle
361 , const ELstring & sumLines
362 ) {
363  const int titleMaxLength( 40 );
364 
365  // title:
366  //
367  ELstring title( fullTitle, 0, titleMaxLength );
368  int q = (lineLength - title.length() - 2) / 2;
369  ELstring line(q, '=');
370  emitToken( "", true );
371  emitToken( line );
372  emitToken( " " );
373  emitToken( title );
374  emitToken( " " );
375  emitToken( line, true );
376 
377  // body:
378  //
379  *os << sumLines;
380 
381  // finish:
382  //
383  emitToken( "", true );
384  emitToken( ELstring(lineLength, '='), true );
385 
386 } // summarization()
387 
388 
389 // ----------------------------------------------------------------------
390 // Changing ostream:
391 // ----------------------------------------------------------------------
392 
393 void ELfwkJobReport::changeFile (std::ostream & os_) {
394  os.reset(&os_, do_nothing_deleter());
395  emitToken( "\n=======================================================", true );
396  emitToken( "\nError Log changed to this stream\n" );
397  emitToken( "\n=======================================================\n", true );
398 }
399 
401  os.reset(new std::ofstream( filename.c_str(), std::ios/*_base*/::app ), close_and_delete());
402  emitToken( "\n=======================================================", true );
403  emitToken( "\nError Log changed to this file\n" );
404  emitToken( "\n=======================================================\n", true );
405 }
406 
408  os->flush();
409 }
410 
411 
412 // ----------------------------------------------------------------------
413 
414 
415 } // end of namespace service
416 } // end of namespace edm
ELseverityLevel traceThreshold
ELseverityLevel severity
Definition: ELextendedID.h:36
virtual bool thisShouldBeIgnored(const ELstring &s) const
virtual bool log(const ErrorObj &msg)
boost::shared_ptr< std::ostream > os
virtual ELfwkJobReport * clone() const
const ELextendedID & xid() const
Definition: ErrorObj.cc:146
virtual void emitToken(const ELstring &s, bool nl=false)
bool add(const ELextendedID &xid)
const ELlist_string & items() const
Definition: ErrorObj.cc:149
virtual void changeFile(std::ostream &os)
virtual void summarization(const ELstring &fullTitle, const ELstring &sumLines)
tuple filename
Definition: lut2db_cfg.py:20
std::string ELstring
Definition: ELstring.h:26