test
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  for (auto& sink : sinks_)
115  if ( sink->log( msg ) )
116  msg.setReactedTo ( true );
117 
118  return;
119 
120 }
121 
122 
123 // ----------------------------------------------------------------------
124 // ELadministrator functionality:
125 // ----------------------------------------------------------------------
126 
128 
129  std::shared_ptr<ELdestination> dest(sink.clone());
130  sinks_.push_back( dest );
131  return ELdestControl( dest );
132 
133 } // attach()
134 
136  const ELstring & name ) {
137  std::shared_ptr<ELdestination> dest(sink.clone());
139  sinks_.push_back( dest );
140  return ELdestControl( dest );
141 } // attach()
142 
143 
145 
146  const ELseverityLevel retval( highSeverity_ );
148  return retval;
149 
150 } // checkSeverity()
151 
152 
154 
155  return severityCounts_[sev.getLevel()];
156 
157 } // severityCount()
158 
159 
161  const ELseverityLevel & from,
162  const ELseverityLevel & to
163 ) const {
164 
165  int k = from.getLevel();
166  int sum = severityCounts_[k];
167 
168  while ( ++k != to.getLevel() )
169  sum += severityCounts_[k];
170 
171  return sum;
172 
173 } // severityCount()
174 
175 
177 
178  severityCounts_[sev.getLevel()] = 0;
179 
180 } // resetSeverityCount()
181 
182 
184  const ELseverityLevel & to ) {
185 
186  for ( int k = from.getLevel(); k <= to.getLevel(); ++k )
187  severityCounts_[k] = 0;
188 
189 } // resetSeverityCount()
190 
191 
193 
195 
196 } // resetSeverityCount()
197 
198 
199 // ----------------------------------------------------------------------
200 // Accessors:
201 // ----------------------------------------------------------------------
202 
204  return highSeverity_;
205 }
206 
207 
208 int ELadministrator::severityCounts( const int lev ) const {
209  return severityCounts_[lev];
210 }
211 
212 
213 // ----------------------------------------------------------------------
214 // Message handling:
215 // ----------------------------------------------------------------------
216 
217 
218 // ----------------------------------------------------------------------
219 // The following do the indicated action to all attached destinations:
220 // ----------------------------------------------------------------------
221 
223 
224  for (auto& sink : sinks_)
225  sink->threshold = sev;
226 
227 } // setThresholds()
228 
229 
230 void ELadministrator::setLimits( const ELstring & id, int limit ) {
231 
232  for (auto& sink : sinks_)
233  sink->limits.setLimit( id, limit );
234 
235 } // setLimits()
236 
237 
239  ( const ELseverityLevel & sev, int interval ) {
240 
241  for (auto& sink : sinks_)
242  sink->limits.setInterval( sev, interval );
243 
244 } // setIntervals()
245 
246 void ELadministrator::setIntervals( const ELstring & id, int interval ) {
247 
248  for (auto& sink : sinks_)
249  sink->limits.setInterval( id, interval );
250 
251 } // setIntervals()
252 
253 
255 
256  for (auto& sink : sinks_)
257  sink->limits.setLimit( sev, limit );
258 
259 } // setLimits()
260 
261 
263 
264  for (auto& sink : sinks_)
265  sink->limits.setTimespan( id, seconds );
266 
267 } // setTimespans()
268 
269 
271 
272  for (auto& sink : sinks_)
273  sink->limits.setTimespan( sev, seconds );
274 
275 } // setTimespans()
276 
277 
279 
280  for (auto& sink : sinks_)
281  sink->limits.wipe();
282 
283 } // wipe()
284 
286 
287  for (auto& sink : sinks_)
288  sink->finish();
289 
290 } // wipe()
291 
292 
294 : sinks_ ( )
295 , highSeverity_ ( ELseverityLevel (ELseverityLevel::ELsev_zeroSeverity) )
296 {
297 
298  #ifdef ELadministratorCONSTRUCTOR_TRACE
299  std::cerr << "ELadminstrator constructor\n";
300  #endif
301 
302  for ( int lev = 0; lev < ELseverityLevel::nLevels; ++lev )
303  severityCounts_[lev] = 0;
304 
305 }
306 //-*****************************
307 // The ELadminstrator destructor
308 //-*****************************
309 
311 
312  #ifdef ELadministratorCONSTRUCTOR_TRACE
313  std::cerr << "ELadministrator Destructor\n";
314  #endif
315 
316  sinks_.clear();
317 
318 } // ~ELadministrator()
319 
320 
321 
322 // ----------------------------------------------------------------------
323 
324 
325 } // end of namespace service
326 } // 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)
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)
virtual ELdestination * clone() const =0
std::list< edm::propagate_const< std::shared_ptr< ELdestination > > > sinks_
int severityCounts(int lev) const
int severityCount(const ELseverityLevel &sev) const
ELdestControl attach(const ELdestination &sink)
std::string ELstring
Definition: ELstring.h:26
std::map< ELstring, edm::propagate_const< std::shared_ptr< ELdestination > > > attachedDestinations_