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::attach( const ELdestination & sink )
43 // ELadministrator::attach( const ELdestination & sink, const ELstring & name )
44 // ELadministrator::checkSeverity()
45 // ELadministrator::severityCount( const ELseverityLevel & sev ) const
46 // ELadministrator::severityCount( const ELseverityLevel & from,
47 // const ELseverityLevel & to ) const
48 // ELadministrator::resetSeverityCount( const ELseverityLevel & sev )
49 // ELadministrator::resetSeverityCount( const ELseverityLevel & from,
50 // const ELseverityLevel & to )
51 // ELadministrator::resetSeverityCount()
52 // ELadministrator::setThresholds( const ELseverityLevel & sev )
53 // ELadministrator::setLimits( const ELstring & id, int limit )
54 // ELadministrator::setLimits( const ELseverityLevel & sev, int limit )
55 // ELadministrator::setIntervals( const ELstring & id, int interval )
56 // ELadministrator::setIntervals( const ELseverityLevel & sev, int interval )
57 // ELadministrator::setTimespans( const ELstring & id, int seconds )
58 // ELadministrator::setTimespans( const ELseverityLevel & sev, int seconds )
59 // ELadministrator::wipe()
60 // ELadministrator::finish()
61 //
62 // ELadministrator::process() const
63 // ELadministrator::context() const
64 // ELadministrator::abortThreshold() const
65 // ELadministrator::exitThreshold() const
66 // ELadministrator::sinks()
67 // ELadministrator::highSeverity() const
68 // ELadministrator::severityCounts( const int lev ) const
69 // ELadministrator::finishMsg()
70 // ELadministrator::clearMsg()
71 //
72 //
73 // ----------------------------------------------------------------------
74 
75 
79 
81 
82 #include <iostream>
83 #include <sstream>
84 #include <list>
85 using std::cerr;
86 
87 
88 namespace edm {
89 namespace service {
90 
91 
92 // Possible Traces:
93 // #define ELadministratorCONSTRUCTOR_TRACE
94 // #define ELadTRACE_FINISH
95 
96 
98 
99 
100  // severity level statistics keeping: // $$ mf 6/7/01
101  int lev = msg.xid().severity.getLevel();
102  ++ severityCounts_[lev];
103  if ( lev > highSeverity_.getLevel() )
104  highSeverity_ = msg.xid().severity;
105 
106  // ----- send the message to each destination:
107  //
108  if (sinks().begin() == sinks().end()) {
109  std::cerr << "\nERROR LOGGED WITHOUT DESTINATION!\n";
110  std::cerr << "Attaching destination \"cerr\" to ELadministrator by default\n"
111  << std::endl;
113  }
114  std::list<std::shared_ptr<ELdestination> >::iterator d;
115  for ( d = sinks().begin(); d != sinks().end(); ++d )
116  if ( (*d)->log( msg ) )
117  msg.setReactedTo ( true );
118 
119  return;
120 
121 }
122 
123 
124 // ----------------------------------------------------------------------
125 // ELadministrator functionality:
126 // ----------------------------------------------------------------------
127 
129 
130  std::shared_ptr<ELdestination> dest(sink.clone());
131  sinks().push_back( dest );
132  return ELdestControl( dest );
133 
134 } // attach()
135 
137  const ELstring & name ) {
138  std::shared_ptr<ELdestination> dest(sink.clone());
140  sinks().push_back( dest );
141  return ELdestControl( dest );
142 } // attach()
143 
144 
146 
147  const ELseverityLevel retval( highSeverity_ );
149  return retval;
150 
151 } // checkSeverity()
152 
153 
155 
156  return severityCounts_[sev.getLevel()];
157 
158 } // severityCount()
159 
160 
162  const ELseverityLevel & from,
163  const ELseverityLevel & to
164 ) const {
165 
166  int k = from.getLevel();
167  int sum = severityCounts_[k];
168 
169  while ( ++k != to.getLevel() )
170  sum += severityCounts_[k];
171 
172  return sum;
173 
174 } // severityCount()
175 
176 
178 
179  severityCounts_[sev.getLevel()] = 0;
180 
181 } // resetSeverityCount()
182 
183 
185  const ELseverityLevel & to ) {
186 
187  for ( int k = from.getLevel(); k <= to.getLevel(); ++k )
188  severityCounts_[k] = 0;
189 
190 } // resetSeverityCount()
191 
192 
194 
196 
197 } // resetSeverityCount()
198 
199 
200 // ----------------------------------------------------------------------
201 // Accessors:
202 // ----------------------------------------------------------------------
203 
204 std::list<std::shared_ptr<ELdestination> > & ELadministrator::sinks() { return sinks_; }
205 
206 
208  return highSeverity_;
209 }
210 
211 
212 int ELadministrator::severityCounts( const int lev ) const {
213  return severityCounts_[lev];
214 }
215 
216 
217 // ----------------------------------------------------------------------
218 // Message handling:
219 // ----------------------------------------------------------------------
220 
221 
222 // ----------------------------------------------------------------------
223 // The following do the indicated action to all attached destinations:
224 // ----------------------------------------------------------------------
225 
227 
228  std::list<std::shared_ptr<ELdestination> >::iterator d;
229  for ( d = sinks().begin(); d != sinks().end(); ++d )
230  (*d)->threshold = sev;
231 
232 } // setThresholds()
233 
234 
235 void ELadministrator::setLimits( const ELstring & id, int limit ) {
236 
237  std::list<std::shared_ptr<ELdestination> >::iterator d;
238  for ( d = sinks().begin(); d != sinks().end(); ++d )
239  (*d)->limits.setLimit( id, limit );
240 
241 } // setLimits()
242 
243 
245  ( const ELseverityLevel & sev, int interval ) {
246 
247  std::list<std::shared_ptr<ELdestination> >::iterator d;
248  for ( d = sinks().begin(); d != sinks().end(); ++d )
249  (*d)->limits.setInterval( sev, interval );
250 
251 } // setIntervals()
252 
253 void ELadministrator::setIntervals( const ELstring & id, int interval ) {
254 
255  std::list<std::shared_ptr<ELdestination> >::iterator d;
256  for ( d = sinks().begin(); d != sinks().end(); ++d )
257  (*d)->limits.setInterval( id, interval );
258 
259 } // setIntervals()
260 
261 
263 
264  std::list<std::shared_ptr<ELdestination> >::iterator d;
265  for ( d = sinks().begin(); d != sinks().end(); ++d )
266  (*d)->limits.setLimit( sev, limit );
267 
268 } // setLimits()
269 
270 
272 
273  std::list<std::shared_ptr<ELdestination> >::iterator d;
274  for ( d = sinks().begin(); d != sinks().end(); ++d )
275  (*d)->limits.setTimespan( id, seconds );
276 
277 } // setTimespans()
278 
279 
281 
282  std::list<std::shared_ptr<ELdestination> >::iterator d;
283  for ( d = sinks().begin(); d != sinks().end(); ++d )
284  (*d)->limits.setTimespan( sev, seconds );
285 
286 } // setTimespans()
287 
288 
290 
291  std::list<std::shared_ptr<ELdestination> >::iterator d;
292  for ( d = sinks().begin(); d != sinks().end(); ++d )
293  (*d)->limits.wipe();
294 
295 } // wipe()
296 
298 
299  std::list<std::shared_ptr<ELdestination> >::iterator d;
300  for ( d = sinks().begin(); d != sinks().end(); ++d )
301  (*d)->finish();
302 
303 } // wipe()
304 
305 
307 : sinks_ ( )
308 , highSeverity_ ( ELseverityLevel (ELseverityLevel::ELsev_zeroSeverity) )
309 {
310 
311  #ifdef ELadministratorCONSTRUCTOR_TRACE
312  std::cerr << "ELadminstrator constructor\n";
313  #endif
314 
315  for ( int lev = 0; lev < ELseverityLevel::nLevels; ++lev )
316  severityCounts_[lev] = 0;
317 
318 }
319 //-*****************************
320 // The ELadminstrator destructor
321 //-*****************************
322 
324 
325  #ifdef ELadministratorCONSTRUCTOR_TRACE
326  std::cerr << "ELadministrator Destructor\n";
327  #endif
328 
329  sinks().clear();
330 
331 } // ~ELadministrator()
332 
333 
334 
335 // ----------------------------------------------------------------------
336 
337 
338 } // end of namespace service
339 } // end of namespace edm
const ELseverityLevel & highSeverity() const
void log(edm::ErrorObj &msg)
ELseverityLevel severity
Definition: ELextendedID.h:35
int severityCounts_[ELseverityLevel::nLevels]
double seconds()
void setThresholds(const ELseverityLevel &sev)
tuple interval
Definition: MergeJob_cfg.py:20
ELslProxy< ELhighestSeverityGen > const ELhighestSeverity
void setIntervals(const ELstring &id, int interval)
void setLimits(const ELstring &id, int limit)
std::map< ELstring, std::shared_ptr< ELdestination > > attachedDestinations_
virtual void setReactedTo(bool r)
Definition: ErrorObj.cc:204
const ELextendedID & xid() const
Definition: ErrorObj.cc:147
ELslProxy< ELzeroSeverityGen > const ELzeroSeverity
void setTimespans(const ELstring &id, int seconds)
#define end
Definition: vmac.h:37
virtual ELdestination * clone() const =0
int severityCounts(int lev) const
int severityCount(const ELseverityLevel &sev) const
std::list< std::shared_ptr< ELdestination > > sinks_
#define begin
Definition: vmac.h:30
std::list< std::shared_ptr< ELdestination > > & sinks()
ELdestControl attach(const ELdestination &sink)
std::string ELstring
Definition: ELstring.h:26