CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ELadministrator.cc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------
2 //
3 // ELadministrator.cc
4 //
5 // Methods of ELadministrator.
6 //
7 // History:
8 //
9 // 7/2/98 mf Created
10 // 7/6/98 mf Added ELadministratorX knowledge
11 // 6/16/99 jvr Attaches a destination when an error is logged and
12 // no destinations are attached $$ JV:1
13 // 6/18/99 jvr/mf Constructor for ELadministratorX uses explcitly
14 // constructed ELseverityLevels in its init list, rather
15 // than objectslike ELabort, which may not yet have
16 // been fully constructed. Repairs a problem with ELcout.
17 // 6/23/99 mf Made emptyContextSUpplier static to this comp unit.
18 // 12/20/99 mf Added virtual destructor to ELemptyContextSupplier.
19 // 2/29/00 mf swapContextSupplier.
20 // 4/05/00 mf swapProcess.
21 // 5/03/00 mf When aborting, changed exit() to abort() so that dump
22 // will reflect true condition without unwinding things.
23 // 6/6/00 web Consolidated ELadministrator/X.
24 // 6/7/00 web Reflect consolidation of ELdestination/X.
25 // 6/12/00 web Attach cerr, rather than cout, in case of no previously-
26 // attached destination; using -> USING.
27 // 3/6/00 mf Attach taking name to id the destination, getELdestControl()
28 // 3/14/01 mf exitThreshold
29 // 1/10/06 mf finish()
30 //
31 // ---- CMS version
32 //
33 // 12/12/05 mf change exit() to throw edm::exception
34 //
35 //-----------------------------------------------------------------------
36 
37 // Directory of methods:
38 //----------------------
39 
40 // ELadministrator::setProcess( const ELstring & process )
41 // ELadministrator::swapProcess( const ELstring & process )
42 // ELadministrator::setContextSupplier( const ELcontextSupplier & supplier )
43 // ELadministrator::getContextSupplier() const
44 // ELadministrator::swapContextSupplier( ELcontextSupplier & supplier )
45 // ELadministrator::setAbortThreshold( const ELseverityLevel & sev )
46 // ELadministrator::setExitThreshold( const ELseverityLevel & sev )
47 // ELadministrator::attach( const ELdestination & sink )
48 // ELadministrator::attach( const ELdestination & sink, const ELstring & name )
49 // ELadministrator::getELdestControl ( const ELstring & name,
50 // ELdestControl & theDestControl )
51 // ELadministrator::checkSeverity()
52 // ELadministrator::severityCount( const ELseverityLevel & sev ) const
53 // ELadministrator::severityCount( const ELseverityLevel & from,
54 // const ELseverityLevel & to ) const
55 // ELadministrator::resetSeverityCount( const ELseverityLevel & sev )
56 // ELadministrator::resetSeverityCount( const ELseverityLevel & from,
57 // const ELseverityLevel & to )
58 // ELadministrator::resetSeverityCount()
59 // ELadministrator::setThresholds( const ELseverityLevel & sev )
60 // ELadministrator::setLimits( const ELstring & id, int limit )
61 // ELadministrator::setLimits( const ELseverityLevel & sev, int limit )
62 // ELadministrator::setIntervals( const ELstring & id, int interval )
63 // ELadministrator::setIntervals( const ELseverityLevel & sev, int interval )
64 // ELadministrator::setTimespans( const ELstring & id, int seconds )
65 // ELadministrator::setTimespans( const ELseverityLevel & sev, int seconds )
66 // ELadministrator::wipe()
67 // ELadministrator::finish()
68 //
69 // ELadministrator::process() const
70 // ELadministrator::context() const
71 // ELadministrator::abortThreshold() const
72 // ELadministrator::exitThreshold() const
73 // ELadministrator::sinks()
74 // ELadministrator::highSeverity() const
75 // ELadministrator::severityCounts( const int lev ) const
76 // ELadministrator::finishMsg()
77 // ELadministrator::clearMsg()
78 //
79 // class ELemptyContextSupplier : public ELcontextSupplier
80 //
81 // ----------------------------------------------------------------------
82 
83 
88 
90 
91 #include <iostream>
92 #include <sstream>
93 #include <list>
94 using std::cerr;
95 
96 
97 namespace edm {
98 namespace service {
99 
100 
101 // Possible Traces:
102 // #define ELadministratorCONSTRUCTOR_TRACE
103 // #define ELadTRACE_FINISH
104 
105 
106 // ----------------------------------------------------------------------
107 // ELadministrator functionality:
108 // ----------------------------------------------------------------------
109 
111 
112  process_ = process;
113  #if 0
114  std::cerr << "Administrator process set to \"" << process << "\"\n";
115  #endif
116 
117 } // setProcess()
118 
119 
121 
123  process_ = process;
124  return temp;
125 
126 } // swapProcess()
127 
128 
130 
131  context_.reset(supplier.clone());
132 
133 } // setContextSupplier()
134 
135 
137 
138  return *(context_);
139 
140 } // getContextSupplier()
141 
144  ELcontextSupplier & save = *(context_);
145  context_.reset(&cs);
146  return save;
147 } // swapContextSupplier
148 
149 
151 
152  abortThreshold_ = sev;
153 
154 } // setAbortThreshold()
155 
157 
158  exitThreshold_ = sev;
159 
160 } // setExitThreshold()
161 
163 
164  boost::shared_ptr<ELdestination> dest(sink.clone());
165  sinks().push_back( dest );
166  return ELdestControl( dest );
167 
168 } // attach()
169 
171  const ELstring & name ) {
172  boost::shared_ptr<ELdestination> dest(sink.clone());
174  sinks().push_back( dest );
175  return ELdestControl( dest );
176 } // attach()
177 
178 
180  ELdestControl & theDestControl ) {
181 
182  if ( attachedDestinations.find(name) != attachedDestinations.end() ) {
183  theDestControl = ELdestControl ( attachedDestinations[name] );
184  return true;
185  } else {
186  return false;
187  }
188 
189 } // getDestControl
190 
192 
193  const ELseverityLevel retval( highSeverity_ );
195  return retval;
196 
197 } // checkSeverity()
198 
199 
201 
202  return severityCounts_[sev.getLevel()];
203 
204 } // severityCount()
205 
206 
208  const ELseverityLevel & from,
209  const ELseverityLevel & to
210 ) const {
211 
212  int k = from.getLevel();
213  int sum = severityCounts_[k];
214 
215  while ( ++k <= to.getLevel() )
216  sum += severityCounts_[k];
217 
218  return sum;
219 
220 } // severityCount()
221 
222 
224 
225  severityCounts_[sev.getLevel()] = 0;
226 
227 } // resetSeverityCount()
228 
229 
231  const ELseverityLevel & to ) {
232 
233  for ( int k = from.getLevel(); k <= to.getLevel(); ++k )
234  severityCounts_[k] = 0;
235 
236 } // resetSeverityCount()
237 
238 
240 
242 
243 } // resetSeverityCount()
244 
245 
246 // ----------------------------------------------------------------------
247 // Accessors:
248 // ----------------------------------------------------------------------
249 
250 const ELstring & ELadministrator::process() const { return process_; }
251 
252 
254 
255 
257  return abortThreshold_;
258 }
259 
261  return exitThreshold_;
262 }
263 
264 std::list<boost::shared_ptr<ELdestination> > & ELadministrator::sinks() { return sinks_; }
265 
266 
268  return highSeverity_;
269 }
270 
271 
272 int ELadministrator::severityCounts( const int lev ) const {
273  return severityCounts_[lev];
274 }
275 
276 
277 // ----------------------------------------------------------------------
278 // Message handling:
279 // ----------------------------------------------------------------------
280 
281 static inline void msgexit(int s) {
282  std::ostringstream os;
283  os << "msgexit - MessageLogger requested to exit with status " << s;
285  throw e;
286 }
287 
288 static inline void msgabort() {
289  std::ostringstream os;
290  os << "msgabort - MessageLogger requested to abort";
292  throw e;
293 }
294 
295 static inline void possiblyAbortOrExit (int s, int a, int e) {
296  if (s < a && s < e) return;
297  if (a < e) {
298  if ( s < e ) msgabort();
299  msgexit(s);
300  } else {
301  if ( s < a ) msgexit(s);
302  msgabort();
303  }
304 }
305 
307 
308  if ( ! msgIsActive )
309  return;
310 
311  int lev = msg.xid().severity.getLevel();
312  ++ severityCounts_[lev];
313  if ( lev > highSeverity_.getLevel() )
315 
316  #ifdef ELadTRACE_FINISH
317  std::cerr << "=:=:=: finshMsg() - lev = " << lev << "\n";
318  #endif
319 
320  context_->editErrorObj( msg );
321 
322  #ifdef ELadTRACE_FINISH
323  std::cerr << "=:=:=: finshMsg() returns from editErrorObj( msg ) \n";
324  #endif
325 
326  std::list<boost::shared_ptr<ELdestination> >::iterator d;
327  bool mrt;
328  #ifdef ELadTRACE_FINISH
329  int destCounter = 0;
330  #endif
331  if ( sinks().begin() == sinks().end() ) { // $$ JV:1
332  std::cerr << "\nERROR LOGGED WITHOUT DESTINATION!\n";
333  std::cerr << "Attaching destination \"cerr\" to ELadministrator by default\n\n";
334  boost::shared_ptr<ELdestination> dest(new ELoutput(cerr));
335  this->sinks().push_back(dest);
336  }
337  for ( d = sinks().begin(); d != sinks().end(); ++d ) {
338  #ifdef ELadTRACE_FINISH
339  std::cerr << " =:=:=: log(msg) for a destination number "
340  << ++destCounter << " called ... \n";
341  #endif
342  mrt = (*d)->log( msg );
343  #ifdef ELadTRACE_FINISH
344  std::cerr << " =:=:=: log(msg) for a destination returned " << mrt << "\n";
345  #endif
346  if ( mrt )
347  msg.setReactedTo(true);
348  }
349 
350  msgIsActive = false;
351 
352  possiblyAbortOrExit ( lev,
353  abortThreshold().getLevel(),
354  exitThreshold().getLevel() ); // $$ mf 3/17/04
355 
356 } // finishMsg()
357 
358 
360 
361  msgIsActive = false;
362  msg.clear();
363 
364 } // clearMsg()
365 
366 
367 // ----------------------------------------------------------------------
368 // The following do the indicated action to all attached destinations:
369 // ----------------------------------------------------------------------
370 
372 
373  std::list<boost::shared_ptr<ELdestination> >::iterator d;
374  for ( d = sinks().begin(); d != sinks().end(); ++d )
375  (*d)->threshold = sev;
376 
377 } // setThresholds()
378 
379 
380 void ELadministrator::setLimits( const ELstring & id, int limit ) {
381 
382  std::list<boost::shared_ptr<ELdestination> >::iterator d;
383  for ( d = sinks().begin(); d != sinks().end(); ++d )
384  (*d)->limits.setLimit( id, limit );
385 
386 } // setLimits()
387 
388 
390  ( const ELseverityLevel & sev, int interval ) {
391 
392  std::list<boost::shared_ptr<ELdestination> >::iterator d;
393  for ( d = sinks().begin(); d != sinks().end(); ++d )
394  (*d)->limits.setInterval( sev, interval );
395 
396 } // setIntervals()
397 
398 void ELadministrator::setIntervals( const ELstring & id, int interval ) {
399 
400  std::list<boost::shared_ptr<ELdestination> >::iterator d;
401  for ( d = sinks().begin(); d != sinks().end(); ++d )
402  (*d)->limits.setInterval( id, interval );
403 
404 } // setIntervals()
405 
406 
408 
409  std::list<boost::shared_ptr<ELdestination> >::iterator d;
410  for ( d = sinks().begin(); d != sinks().end(); ++d )
411  (*d)->limits.setLimit( sev, limit );
412 
413 } // setLimits()
414 
415 
417 
418  std::list<boost::shared_ptr<ELdestination> >::iterator d;
419  for ( d = sinks().begin(); d != sinks().end(); ++d )
420  (*d)->limits.setTimespan( id, seconds );
421 
422 } // setTimespans()
423 
424 
426 
427  std::list<boost::shared_ptr<ELdestination> >::iterator d;
428  for ( d = sinks().begin(); d != sinks().end(); ++d )
429  (*d)->limits.setTimespan( sev, seconds );
430 
431 } // setTimespans()
432 
433 
435 
436  std::list<boost::shared_ptr<ELdestination> >::iterator d;
437  for ( d = sinks().begin(); d != sinks().end(); ++d )
438  (*d)->limits.wipe();
439 
440 } // wipe()
441 
443 
444  std::list<boost::shared_ptr<ELdestination> >::iterator d;
445  for ( d = sinks().begin(); d != sinks().end(); ++d )
446  (*d)->finish();
447 
448 } // wipe()
449 
450 
451 // ----------------------------------------------------------------------
452 // ELemptyContextSupplier (dummy default ELcontextSupplier):
453 // ----------------------------------------------------------------------
454 
456 
457 public:
458 
459  virtual
461  clone() const {
462  return new ELemptyContextSupplier( *this );
463  }
464  virtual ELstring context() const { return ""; }
465  virtual ELstring summaryContext() const { return ""; }
466  virtual ELstring fullContext() const { return ""; }
467 
469 
470 }; // ELemptyContextSupplier
471 
472 
474 
475 
476 // ----------------------------------------------------------------------
477 // The Destructable Singleton pattern
478 // (see "To Kill a Singleton," Vlissides, C++ Report):
479 // ----------------------------------------------------------------------
480 
481 
483 
484 
486 
487  static ELadminDestroyer destroyer_;
488  // This deviates from Vlissides' pattern where destroyer_ was a static
489  // instance in the ELadministrator class. This construct should be
490  // equivalent, but the original did not call the destructor under KCC.
491 
492  if ( !instance_ ) {
494  destroyer_.setELadmin( instance_ );
495  }
496  return instance_;
497 
498 } // instance()
499 
500 
502 : process_ ( "" )
503 , context_ ( emptyContext.clone() )
504 , abortThreshold_( ELseverityLevel (ELseverityLevel::ELsev_abort) )
505 , exitThreshold_ ( ELseverityLevel (ELseverityLevel::ELsev_highestSeverity ) )
506 , sinks_ ( )
507 , highSeverity_ ( ELseverityLevel (ELseverityLevel::ELsev_zeroSeverity) )
508 , msg ( ELseverityLevel (ELseverityLevel::ELsev_unspecified), "" )
509 , msgIsActive ( false )
510 {
511 
512  #ifdef ELadministratorCONSTRUCTOR_TRACE
513  std::cerr << "ELadminstrator constructor\n";
514  #endif
515 
516  for ( int lev = 0; lev < ELseverityLevel::nLevels; ++lev )
517  severityCounts_[lev] = 0;
518 
519 } // ELadministrator()
520 
521 
523 
524 
526 
527  #ifdef ELadministratorCONSTRUCTOR_TRACE
528  std::cerr << "~ELadminDestroyer: Deleting admin_\n";
529  #endif
530 
531  delete admin_;
532 
533 } // ~ELadminDestroyer()
534 
535 
537 
538 
539 //-*****************************
540 // The ELadminstrator destructor
541 //-*****************************
542 
544 
545  #ifdef ELadministratorCONSTRUCTOR_TRACE
546  std::cerr << "ELadministrator Destructor\n";
547  #endif
548 
549  finishMsg();
550 
551  sinks().clear();
552 
553 } // ~ELadministrator()
554 
555 
556 
557 // ----------------------------------------------------------------------
558 
559 
560 } // end of namespace service
561 } // end of namespace edm
const ELseverityLevel & highSeverity() const
void setProcess(const ELstring &process)
const ELcontextSupplier & getContextSupplier() const
ELstring swapProcess(const ELstring &process)
virtual ELstring context() const
ELseverityLevel severity
Definition: ELextendedID.h:36
std::list< boost::shared_ptr< ELdestination > > & sinks()
int severityCounts_[ELseverityLevel::nLevels]
double seconds()
virtual void clear()
Definition: ErrorObj.cc:242
void setThresholds(const ELseverityLevel &sev)
tuple interval
Definition: MergeJob_cfg.py:20
std::map< ELstring, boost::shared_ptr< ELdestination > > attachedDestinations
ELadminDestroyer(ELadministrator *ad=0)
static ELemptyContextSupplier emptyContext
static void msgabort()
void setExitThreshold(const ELseverityLevel &sev)
ELslProxy< ELhighestSeverityGen > const ELhighestSeverity
const ELstring & process() const
void setIntervals(const ELstring &id, int interval)
void setLimits(const ELstring &id, int limit)
virtual void setReactedTo(bool r)
Definition: ErrorObj.cc:190
static ELadministrator * instance_
const ELextendedID & xid() const
Definition: ErrorObj.cc:126
ELslProxy< ELzeroSeverityGen > const ELzeroSeverity
virtual ELemptyContextSupplier * clone() const
ELcontextSupplier & swapContextSupplier(ELcontextSupplier &cs)
void setTimespans(const ELstring &id, int seconds)
#define end
Definition: vmac.h:38
bool getELdestControl(const ELstring &name, ELdestControl &theControl)
boost::shared_ptr< ELcontextSupplier > context_
virtual ELstring summaryContext() const
std::list< boost::shared_ptr< ELdestination > > sinks_
int k[5][pyjets_maxn]
virtual ELdestination * clone() const =0
static std::string from(" from ")
void setAbortThreshold(const ELseverityLevel &sev)
static ELadministrator * instance()
T * clone(const T *tp)
Definition: Ptr.h:42
static void possiblyAbortOrExit(int s, int a, int e)
void setContextSupplier(const ELcontextSupplier &supplier)
virtual ELcontextSupplier * clone() const =0
int severityCounts(int lev) const
int severityCount(const ELseverityLevel &sev) const
tuple process
Definition: align_tpl.py:3
#define begin
Definition: vmac.h:31
double a
Definition: hdecay.h:121
ELcontextSupplier & context() const
virtual ELstring fullContext() const
void setELadmin(ELadministrator *ad)
string s
Definition: asciidump.py:422
static void msgexit(int s)
ELdestControl attach(const ELdestination &sink)
const ELseverityLevel & exitThreshold() const
std::string ELstring
Definition: ELstring.h:26
const ELseverityLevel & abortThreshold() const