CMS 3D CMS Logo

ELlimitsTable.cc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------
2 //
3 // ELlimitsTable.cc
4 //
5 // History:
6 // 7/6/98 mf Created
7 // 6/10/99 jvr Corrected initialization for severityLimits and
8 // timespans to -1 instead of 0.
9 // 6/17/99 jvr setLimit(id,n) works w/ setTimespan(sev||"*",n)
10 // and setTimespan(id,n) w/ setLimit(sev||"*",n)
11 // 6/15/00 web using -> USING
12 // 11/01/01 web Fixed mixed-type comparisons
13 // 5/18/06 mf setInterval
14 // 11/2/07 mf add: Changed ivl = wildcardLimit to wildcardInterval.
15 // Probably moot and never reached, but a clear correction.
16 // 9/29/10 mf,ql Fix savanah bug 65284 where two messages of same
17 // category but different severity, if limits were not
18 // take from category, first severity sets the limit
19 // for both of those xid's.
20 //
21 // ----------------------------------------------------------------------
22 
24 
25 // Posible traces
26 //#include <iostream>
27 //using std::cerr;
28 //#define ELlimitsTableCONSTRUCTOR_TRACE
29 //#define ELlimitsTableATRACE
30 
31 namespace edm {
32  namespace service {
33 
34  // ----------------------------------------------------------------------
35  // Constructor, destructor:
36  // ----------------------------------------------------------------------
37 
39  : wildcardLimit(-1), wildcardInterval(-1), wildcardTimespan(-1), tableLimit(-1), limits(), counts() {
40 #ifdef ELlimitsTableCONSTRUCTOR_TRACE
41  std::cerr << "Constructor for ELlimitsTable\n";
42 #endif
43 
44  for (int k = 0; k < ELseverityLevel::nLevels; ++k) {
45  severityLimits[k] = -1; // JvR 99-06-10
46  severityIntervals[k] = -1;
47  severityTimespans[k] = -1;
48  }
49 
50  } // ELlimitsTable()
51 
53 #ifdef ELlimitsTableCONSTRUCTOR_TRACE
54  std::cerr << "Destructor for ELlimitsTable\n";
55 #endif
56 
57  } // ~ELlimitsTable()
58 
59  // ----------------------------------------------------------------------
60  // Methods invoked by the logger:
61  // ----------------------------------------------------------------------
62 
64 
65  bool ELlimitsTable::add(const ELextendedID& xid) {
66 #ifdef ELlimitsTableATRACE
67  std::cerr << "&&&--- adding to limits table: " << xid.id << '\n';
68 #endif
69 
70  ELmap_counts::iterator c = counts.find(xid);
71 
72  if (c == counts.end()) { // no such entry yet
73 
74 #ifdef ELlimitsTableATRACE
75  std::cerr << "&&& no such entry yet in counts \n";
76 #endif
77 
78  // if the counts table is "full", then this will never be rejected
79  // and info will not be kept so why go through significant work:
80  if (tableLimit > 0 && static_cast<int>(counts.size()) >= tableLimit) {
81  return true;
82  }
83  int lim;
84  int ivl;
85  int ts;
86  ELmap_limits::iterator l = limits.find(xid.id);
87 
88  if (l != limits.end()) { // use limits previously established for this id
89  lim = (*l).second.limit;
90  ivl = (*l).second.interval;
91  ts = (*l).second.timespan;
92  if (lim < 0) { // jvr 6/17/99
93  lim = severityLimits[xid.severity.getLevel()];
94  if (lim < 0) {
95  lim = wildcardLimit;
96  }
97  }
98  if (ivl < 0) {
99  ivl = severityIntervals[xid.severity.getLevel()];
100  if (ivl < 0) {
101  ivl = wildcardInterval; // mf 11/02/07
102  }
103  }
104  if (ts < 0) {
105  ts = severityTimespans[xid.severity.getLevel()];
106  if (ts < 0) {
107  ts = wildcardTimespan;
108  }
109  limits[xid.id] = LimitAndTimespan(lim, ts);
110  }
111 #ifdef ELlimitsTableATRACE
112  std::cerr << "&&& Entry found in limits: limit = " << lim << " interval = " << ivl << " timespan = " << ts
113  << '\n';
114 #endif
115  // change log 9/29/10: Do not put this into limits table
116  } else { // establish and use limits new to this id
117  lim = severityLimits[xid.severity.getLevel()];
118  ivl = severityIntervals[xid.severity.getLevel()];
119  ts = severityTimespans[xid.severity.getLevel()];
120 #ifdef ELlimitsTableATRACE
121  std::cerr << "&&& Limit taken from severityLimits: " << lim << '\n'
122  << "&&& Interval taken from severityLimits: " << ivl << '\n';
123 #endif
124  if (lim < 0) {
125  lim = wildcardLimit;
126 #ifdef ELlimitsTableATRACE
127  std::cerr << "&&& Limit reset to wildcard limit: " << lim << '\n';
128 #endif
129  }
130  if (ivl < 0) {
131  ivl = wildcardInterval;
132 #ifdef ELlimitsTableATRACE
133  std::cerr << "&&& Interval reset to wildcard interval: " << ivl << '\n';
134 #endif
135  }
136 #ifdef ELlimitsTableATRACE
137  std::cerr << "&&& Timespan taken from severityTimespans: " << ts << '\n';
138 #endif
139  if (ts < 0) {
140  ts = wildcardTimespan;
141 #ifdef ELlimitsTableATRACE
142  std::cerr << "&&& timespan reset to wildcard timespan: " << ts << '\n';
143 #endif
144  }
145 
146  // change log 9/29/10 DO not save id's future limits:
147  }
148 
149  // save, if possible, this xid's initial entry:
150  if (tableLimit < 0 || static_cast<int>(counts.size()) < tableLimit)
151  counts[xid] = CountAndLimit(lim, ts, ivl);
152  c = counts.find(xid);
153  }
154 
155  return (c == counts.end()) ? true // no limit filtering can be applied
156  : (*c).second.add() // apply limit filtering
157  ;
158 
159  } // add()
160 
161  // ----------------------------------------------------------------------
162  // Control methods invoked by the framework:
163  // ----------------------------------------------------------------------
164 
166  // This clears everything -- counts and aggregate counts for severity levels
167  // and for individual ID's, as well as any limits established, the limit
168  // for "*" all messages, and the collection of severity defaults. wipe()
169  // does not not affect thresholds.
170 
171  limits.erase(limits.begin(), limits.end());
172  ELmap_counts::iterator i;
173  for (i = counts.begin(); i != counts.end(); ++i) {
174  (*i).second.limit = -1;
175  (*i).second.n = (*i).second.aggregateN = 0;
176  }
177 
178  wildcardLimit = -1;
179  wildcardTimespan = -1;
180  for (int lev = 0; lev < ELseverityLevel::nLevels; ++lev) {
181  severityLimits[lev] = -1;
182  severityIntervals[lev] = -1;
183  severityTimespans[lev] = -1;
184  }
185  }
186 
188  // This clears counts but not aggregate counts for severity levels
189  // and for individual ID's.
190 
191  ELmap_counts::iterator i;
192  for (i = counts.begin(); i != counts.end(); ++i)
193  (*i).second.n = 0;
194  }
195 
196  void ELlimitsTable::setLimit(const ELstring& id, int n) {
197  if (id[0] == '*')
198  wildcardLimit = n;
199  else
200  limits[id].limit = n;
201  }
202 
203  void ELlimitsTable::setLimit(const ELseverityLevel& sev, int n) { severityLimits[sev.getLevel()] = n; }
204 
205  void ELlimitsTable::setInterval(const ELstring& id, int interval) {
206  if (id[0] == '*')
207  wildcardInterval = interval;
208  else
209  limits[id].interval = interval;
210  }
211 
212  void ELlimitsTable::setInterval(const ELseverityLevel& sev, int interval) {
213  severityIntervals[sev.getLevel()] = interval;
214  }
215 
216  void ELlimitsTable::setTimespan(const ELstring& id, int n) {
217  if (id[0] == '*')
219  else
220  limits[id].timespan = n;
221  }
222 
224 
225  // ----------------------------------------------------------------------
226  // Support for internal operations:
227  // ----------------------------------------------------------------------
228 
230  if (this == &t) {
231  return *this; // self assignment
232  }
233  limits = t.limits; // The non-trivial operator= for a map!
234 
235  for (int lev = 0; lev < ELseverityLevel::nLevels; ++lev) {
236  severityTimespans[lev] = t.severityTimespans[lev];
237  severityTimespans[lev] = t.severityTimespans[lev];
238  }
239 
242 
243  return *this;
244 
245  } // operator=()
246 
247  // ----------------------------------------------------------------------
248 
249  } // end of namespace service
250 } // end of namespace edm
ELseverityLevel severity
Definition: ELextendedID.h:29
int severityTimespans[ELseverityLevel::nLevels]
Definition: ELlimitsTable.h:89
bool add(const ELextendedID &xid)
int severityLimits[ELseverityLevel::nLevels]
Definition: ELlimitsTable.h:88
ELlimitsTable & operator=(const ELlimitsTable &t)
int k[5][pyjets_maxn]
void setInterval(const ELstring &id, int interval)
int severityIntervals[ELseverityLevel::nLevels]
Definition: ELlimitsTable.h:90
HLT enums.
void setTimespan(const ELstring &id, int n)
std::string ELstring
Definition: ELstring.h:21
void setLimit(const ELstring &id, int n)