CMS 3D CMS Logo

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;
112  attach(std::make_shared<ELoutput>(std::cerr));
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 
127 std::shared_ptr<ELdestination> ELadministrator::attach( std::shared_ptr<ELdestination> sink ) {
128 
129  sinks_.push_back( sink );
130  return sink;
131 
132 } // attach()
133 
135 
136  const ELseverityLevel retval( highSeverity_ );
138  return retval;
139 
140 } // checkSeverity()
141 
142 
144 
145  return severityCounts_[sev.getLevel()];
146 
147 } // severityCount()
148 
149 
151  const ELseverityLevel & from,
152  const ELseverityLevel & to
153 ) const {
154 
155  int k = from.getLevel();
156  int sum = severityCounts_[k];
157 
158  while ( ++k != to.getLevel() )
159  sum += severityCounts_[k];
160 
161  return sum;
162 
163 } // severityCount()
164 
165 
167 
168  severityCounts_[sev.getLevel()] = 0;
169 
170 } // resetSeverityCount()
171 
172 
174  const ELseverityLevel & to ) {
175 
176  for ( int k = from.getLevel(); k <= to.getLevel(); ++k )
177  severityCounts_[k] = 0;
178 
179 } // resetSeverityCount()
180 
181 
183 
185 
186 } // resetSeverityCount()
187 
188 
189 // ----------------------------------------------------------------------
190 // Accessors:
191 // ----------------------------------------------------------------------
192 
194  return highSeverity_;
195 }
196 
197 
198 int ELadministrator::severityCounts( const int lev ) const {
199  return severityCounts_[lev];
200 }
201 
202 
203 // ----------------------------------------------------------------------
204 // Message handling:
205 // ----------------------------------------------------------------------
206 
207 
208 // ----------------------------------------------------------------------
209 // The following do the indicated action to all attached destinations:
210 // ----------------------------------------------------------------------
211 
213 
214  for (auto& sink : sinks_)
215  sink->threshold = sev;
216 
217 } // setThresholds()
218 
219 
220 void ELadministrator::setLimits( const ELstring & id, int limit ) {
221 
222  for (auto& sink : sinks_)
223  sink->limits.setLimit( id, limit );
224 
225 } // setLimits()
226 
227 
229  ( const ELseverityLevel & sev, int interval ) {
230 
231  for (auto& sink : sinks_)
232  sink->limits.setInterval( sev, interval );
233 
234 } // setIntervals()
235 
236 void ELadministrator::setIntervals( const ELstring & id, int interval ) {
237 
238  for (auto& sink : sinks_)
239  sink->limits.setInterval( id, interval );
240 
241 } // setIntervals()
242 
243 
245 
246  for (auto& sink : sinks_)
247  sink->limits.setLimit( sev, limit );
248 
249 } // setLimits()
250 
251 
253 
254  for (auto& sink : sinks_)
255  sink->limits.setTimespan( id, seconds );
256 
257 } // setTimespans()
258 
259 
261 
262  for (auto& sink : sinks_)
263  sink->limits.setTimespan( sev, seconds );
264 
265 } // setTimespans()
266 
267 
269 
270  for (auto& sink : sinks_)
271  sink->limits.wipe();
272 
273 } // wipe()
274 
276 
277  for (auto& sink : sinks_)
278  sink->finish();
279 
280 } // wipe()
281 
282 
284 : sinks_ ( )
285 , highSeverity_ ( ELseverityLevel (ELseverityLevel::ELsev_zeroSeverity) )
286 {
287 
288  #ifdef ELadministratorCONSTRUCTOR_TRACE
289  std::cerr << "ELadminstrator constructor\n";
290  #endif
291 
292  for ( int lev = 0; lev < ELseverityLevel::nLevels; ++lev )
293  severityCounts_[lev] = 0;
294 
295 }
296 //-*****************************
297 // The ELadminstrator destructor
298 //-*****************************
299 
301 
302  #ifdef ELadministratorCONSTRUCTOR_TRACE
303  std::cerr << "ELadministrator Destructor\n";
304  #endif
305 
306  sinks_.clear();
307 
308 } // ~ELadministrator()
309 
310 
311 
312 // ----------------------------------------------------------------------
313 
314 
315 } // end of namespace service
316 } // end of namespace edm
const ELseverityLevel & highSeverity() const
void log(edm::ErrorObj &msg)
ELseverityLevel severity
Definition: ELextendedID.h:35
int severityCounts_[ELseverityLevel::nLevels]
std::shared_ptr< ELdestination > attach(std::shared_ptr< ELdestination > sink)
double seconds()
void setThresholds(const ELseverityLevel &sev)
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)
int k[5][pyjets_maxn]
std::list< edm::propagate_const< std::shared_ptr< ELdestination > > > sinks_
tuple msg
Definition: mps_check.py:277
int severityCounts(int lev) const
int severityCount(const ELseverityLevel &sev) const
HLT enums.
std::string ELstring
Definition: ELstring.h:26