CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 messagelogger::ELseverityLevel & sev ) const
46 // ELadministrator::severityCount( const messagelogger::ELseverityLevel & from,
47 // const messagelogger::ELseverityLevel & to ) const
48 // ELadministrator::resetSeverityCount( const messagelogger::ELseverityLevel & sev )
49 // ELadministrator::resetSeverityCount( const messagelogger::ELseverityLevel & from,
50 // const messagelogger::ELseverityLevel & to )
51 // ELadministrator::resetSeverityCount()
52 // ELadministrator::setThresholds( const messagelogger::ELseverityLevel & sev )
53 // ELadministrator::setLimits( const ELstring & id, int limit )
54 // ELadministrator::setLimits( const messagelogger::ELseverityLevel & sev, int limit )
55 // ELadministrator::setIntervals( const ELstring & id, int interval )
56 // ELadministrator::setIntervals( const messagelogger::ELseverityLevel & sev, int interval )
57 // ELadministrator::setTimespans( const ELstring & id, int seconds )
58 // ELadministrator::setTimespans( const messagelogger::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 
78 
80 
81 #include <iostream>
82 #include <sstream>
83 #include <list>
84 using std::cerr;
85 using namespace edm::messagelogger;
86 
87 namespace edm {
88  namespace service {
89 
90  // Possible Traces:
91  // #define ELadministratorCONSTRUCTOR_TRACE
92  // #define ELadTRACE_FINISH
93 
95  // severity level statistics keeping: // $$ mf 6/7/01
96  int lev = msg.xid().severity.getLevel();
97  ++severityCounts_[lev];
98  if (lev > highSeverity_.getLevel())
99  highSeverity_ = msg.xid().severity;
100 
101  // ----- send the message to each destination:
102  //
103  if (sinks_.begin() == sinks_.end()) {
104  std::cerr << "\nERROR LOGGED WITHOUT DESTINATION!\n";
105  std::cerr << "Attaching destination \"cerr\" to ELadministrator by default\n" << std::endl;
106  attach(std::make_shared<ELoutput>(std::cerr));
107  }
108  for (auto& sink : sinks_)
109  if (sink->log(msg))
110  msg.setReactedTo(true);
111 
112  return;
113  }
114 
115  // ----------------------------------------------------------------------
116  // ELadministrator functionality:
117  // ----------------------------------------------------------------------
118 
119  std::shared_ptr<ELdestination> ELadministrator::attach(std::shared_ptr<ELdestination> sink) {
120  sinks_.push_back(sink);
121  return sink;
122 
123  } // attach()
124 
125  ELseverityLevel ELadministrator::checkSeverity() {
126  const ELseverityLevel retval(highSeverity_);
127  highSeverity_ = ELzeroSeverity;
128  return retval;
129 
130  } // checkSeverity()
131 
132  int ELadministrator::severityCount(const ELseverityLevel& sev) const {
133  return severityCounts_[sev.getLevel()];
134 
135  } // severityCount()
136 
137  int ELadministrator::severityCount(const ELseverityLevel& from, const ELseverityLevel& to) const {
138  int k = from.getLevel();
139  int sum = severityCounts_[k];
140 
141  while (++k != to.getLevel())
142  sum += severityCounts_[k];
143 
144  return sum;
145 
146  } // severityCount()
147 
148  void ELadministrator::resetSeverityCount(const ELseverityLevel& sev) {
149  severityCounts_[sev.getLevel()] = 0;
150 
151  } // resetSeverityCount()
152 
153  void ELadministrator::resetSeverityCount(const ELseverityLevel& from, const ELseverityLevel& to) {
154  for (int k = from.getLevel(); k <= to.getLevel(); ++k)
155  severityCounts_[k] = 0;
156 
157  } // resetSeverityCount()
158 
159  void ELadministrator::resetSeverityCount() {
160  resetSeverityCount(ELzeroSeverity, ELhighestSeverity);
161 
162  } // resetSeverityCount()
163 
164  // ----------------------------------------------------------------------
165  // Accessors:
166  // ----------------------------------------------------------------------
167 
168  const ELseverityLevel& ELadministrator::highSeverity() const { return highSeverity_; }
169 
170  int ELadministrator::severityCounts(const int lev) const { return severityCounts_[lev]; }
171 
172  // ----------------------------------------------------------------------
173  // Message handling:
174  // ----------------------------------------------------------------------
175 
176  // ----------------------------------------------------------------------
177  // The following do the indicated action to all attached destinations:
178  // ----------------------------------------------------------------------
179 
180  void ELadministrator::setThresholds(const ELseverityLevel& sev) {
181  for (auto& sink : sinks_)
182  sink->threshold = sev;
183 
184  } // setThresholds()
185 
186  void ELadministrator::setLimits(const std::string& id, int limit) {
187  for (auto& sink : sinks_)
188  sink->limits.setLimit(id, limit);
189 
190  } // setLimits()
191 
192  void ELadministrator::setIntervals(const ELseverityLevel& sev, int interval) {
193  for (auto& sink : sinks_)
194  sink->limits.setInterval(sev, interval);
195 
196  } // setIntervals()
197 
198  void ELadministrator::setIntervals(const std::string& id, int interval) {
199  for (auto& sink : sinks_)
200  sink->limits.setInterval(id, interval);
201 
202  } // setIntervals()
203 
204  void ELadministrator::setLimits(const ELseverityLevel& sev, int limit) {
205  for (auto& sink : sinks_)
206  sink->limits.setLimit(sev, limit);
207 
208  } // setLimits()
209 
210  void ELadministrator::setTimespans(const std::string& id, int seconds) {
211  for (auto& sink : sinks_)
212  sink->limits.setTimespan(id, seconds);
213 
214  } // setTimespans()
215 
216  void ELadministrator::setTimespans(const ELseverityLevel& sev, int seconds) {
217  for (auto& sink : sinks_)
218  sink->limits.setTimespan(sev, seconds);
219 
220  } // setTimespans()
221 
222  void ELadministrator::wipe() {
223  for (auto& sink : sinks_)
224  sink->limits.wipe();
225 
226  } // wipe()
227 
228  void ELadministrator::finish() {
229  for (auto& sink : sinks_)
230  sink->finish();
231 
232  } // wipe()
233 
234  ELadministrator::ELadministrator() : sinks_(), highSeverity_(ELseverityLevel(ELseverityLevel::ELsev_zeroSeverity)) {
235 #ifdef ELadministratorCONSTRUCTOR_TRACE
236  std::cerr << "ELadminstrator constructor\n";
237 #endif
238 
239  for (int lev = 0; lev < ELseverityLevel::nLevels; ++lev)
240  severityCounts_[lev] = 0;
241  }
242  //-*****************************
243  // The ELadminstrator destructor
244  //-*****************************
245 
247 #ifdef ELadministratorCONSTRUCTOR_TRACE
248  std::cerr << "ELadministrator Destructor\n";
249 #endif
250 
251  sinks_.clear();
252 
253  } // ~ELadministrator()
254 
255  // ----------------------------------------------------------------------
256 
257  } // end of namespace service
258 } // end of namespace edm
messagelogger::ELseverityLevel severity
Definition: ELextendedID.h:30
static std::vector< std::string > checklist log
constexpr const ELseverityLevel ELzeroSeverity
double seconds()
tuple interval
Definition: MergeJob_cfg.py:20
virtual void setReactedTo(bool r)
Definition: ErrorObj.cc:186
constexpr int getLevel() const noexcept
const ELextendedID & xid() const
Definition: ErrorObj.cc:142
constexpr int getLevel() const noexcept
int severityCounts_[messagelogger::ELseverityLevel::nLevels]
tuple msg
Definition: mps_check.py:285
constexpr const ELseverityLevel ELhighestSeverity