CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
23 
25 
26 // Posible traces
27 //#include <iostream>
28 //using std::cerr;
29 //#define ELlimitsTableCONSTRUCTOR_TRACE
30 //#define ELlimitsTableATRACE
31 
32 
33 namespace edm {
34 namespace service {
35 
36 // ----------------------------------------------------------------------
37 // Constructor, destructor:
38 // ----------------------------------------------------------------------
39 
40 
42 : wildcardLimit ( -1 )
43 , wildcardInterval( -1 )
44 , wildcardTimespan( -1 )
45 , tableLimit ( -1 )
46 , limits ( )
47 , counts ( )
48 {
49 
50 #ifdef ELlimitsTableCONSTRUCTOR_TRACE
51  std::cerr << "Constructor for ELlimitsTable\n";
52 #endif
53 
54  for ( int k = 0; k < ELseverityLevel::nLevels; ++k ) {
55  severityLimits[k] = -1; // JvR 99-06-10
56  severityIntervals[k] = -1;
57  severityTimespans[k] = -1;
58  }
59 
60 } // ELlimitsTable()
61 
62 
64 
65 #ifdef ELlimitsTableCONSTRUCTOR_TRACE
66  std::cerr << "Destructor for ELlimitsTable\n";
67 #endif
68 
69 } // ~ELlimitsTable()
70 
71 
72 // ----------------------------------------------------------------------
73 // Methods invoked by the logger:
74 // ----------------------------------------------------------------------
75 
77 
78 
79 bool ELlimitsTable::add( const ELextendedID & xid ) {
80 
81 #ifdef ELlimitsTableATRACE
82  std::cerr << "&&&--- adding to limits table: " << xid.id << '\n';
83 #endif
84 
85  ELmap_counts::iterator c = counts.find( xid );
86 
87  if ( c == counts.end() ) { // no such entry yet
88 
89  #ifdef ELlimitsTableATRACE
90  std::cerr << "&&& no such entry yet in counts \n";
91  #endif
92 
93  // if the counts table is "full", then this will never be rejected
94  // and info will not be kept so why go through significant work:
95  if ( tableLimit > 0 && static_cast<int>(counts.size()) >= tableLimit ) {
96  return true;
97  }
98  int lim;
99  int ivl;
100  int ts;
101  ELmap_limits::iterator l = limits.find( xid.id );
102 
103  if ( l != limits.end() ) { // use limits previously established for this id
104  lim = (*l).second.limit;
105  ivl = (*l).second.interval;
106  ts = (*l).second.timespan;
107  if ( lim < 0 ) { // jvr 6/17/99
108  lim = severityLimits[xid.severity.getLevel()];
109  if ( lim < 0 ) {
110  lim = wildcardLimit;
111  }
112  }
113  if ( ivl < 0 ) {
114  ivl = severityIntervals[xid.severity.getLevel()];
115  if ( ivl < 0 ) {
116  ivl = wildcardInterval; // mf 11/02/07
117  }
118  }
119  if ( ts < 0 ) {
120  ts = severityTimespans[xid.severity.getLevel()];
121  if (ts < 0 ) {
122  ts = wildcardTimespan;
123  }
124  limits[xid.id] = LimitAndTimespan( lim, ts );
125  }
126  #ifdef ELlimitsTableATRACE
127  std::cerr << "&&& Entry found in limits: limit = " << lim
128  << " interval = " << ivl
129  << " timespan = " << ts << '\n';
130  #endif
131  // change log 9/29/10: Do not put this into limits table
132  } else { // establish and use limits new to this id
133  lim = severityLimits [xid.severity.getLevel()];
134  ivl = severityIntervals[xid.severity.getLevel()];
135  ts = severityTimespans[xid.severity.getLevel()];
136  #ifdef ELlimitsTableATRACE
137  std::cerr << "&&& Limit taken from severityLimits: " << lim << '\n'
138  << "&&& Interval taken from severityLimits: " << ivl << '\n';
139  #endif
140  if ( lim < 0 ) {
141  lim = wildcardLimit;
142  #ifdef ELlimitsTableATRACE
143  std::cerr << "&&& Limit reset to wildcard limit: " << lim << '\n';
144  #endif
145  }
146  if ( ivl < 0 ) {
147  ivl = wildcardInterval;
148  #ifdef ELlimitsTableATRACE
149  std::cerr << "&&& Interval reset to wildcard interval: " << ivl << '\n';
150  #endif
151  }
152  #ifdef ELlimitsTableATRACE
153  std::cerr << "&&& Timespan taken from severityTimespans: " << ts << '\n';
154  #endif
155  if ( ts < 0 ) {
156  ts = wildcardTimespan;
157  #ifdef ELlimitsTableATRACE
158  std::cerr << "&&& timespan reset to wildcard timespan: " << ts << '\n';
159  #endif
160  }
161 
162  // change log 9/29/10 DO not save id's future limits:
163  }
164 
165  // save, if possible, this xid's initial entry:
166  if ( tableLimit < 0 || static_cast<int>(counts.size()) < tableLimit )
167  counts[xid] = CountAndLimit( lim, ts, ivl );
168  c = counts.find( xid );
169  }
170 
171  return ( c == counts.end() )
172  ? true // no limit filtering can be applied
173  : (*c).second.add() // apply limit filtering
174  ;
175 
176 } // add()
177 
178 
179 // ----------------------------------------------------------------------
180 // Control methods invoked by the framework:
181 // ----------------------------------------------------------------------
182 
184  // This clears everything -- counts and aggregate counts for severity levels
185  // and for individual ID's, as well as any limits established, the limit
186  // for "*" all messages, and the collection of severity defaults. wipe()
187  // does not not affect thresholds.
188 
189  limits.erase( limits.begin(), limits.end() );
190  ELmap_counts::iterator i;
191  for ( i = counts.begin(); i != counts.end(); ++i ) {
192  (*i).second.limit = -1;
193  (*i).second.n = (*i).second.aggregateN = 0;
194  }
195 
196  wildcardLimit = -1;
197  wildcardTimespan = -1;
198  for ( int lev = 0; lev < ELseverityLevel::nLevels; ++lev ) {
199  severityLimits [lev] = -1;
200  severityIntervals[lev] = -1;
201  severityTimespans[lev] = -1;
202  }
203 
204 }
205 
206 
208  // This clears counts but not aggregate counts for severity levels
209  // and for individual ID's.
210 
211  ELmap_counts::iterator i;
212  for ( i = counts.begin(); i != counts.end(); ++i )
213  (*i).second.n = 0;
214 }
215 
216 
217 void ELlimitsTable::setLimit( const ELstring & id, int n ) {
218  if ( id[0] == '*' ) wildcardLimit = n;
219  else limits[id].limit = n;
220 }
221 
222 
223 void ELlimitsTable::setLimit( const ELseverityLevel & sev, int n ) {
224  severityLimits[sev.getLevel()] = n;
225 }
226 
228  if ( id[0] == '*' ) wildcardInterval = interval;
229  else limits[id].interval = interval;
230 }
231 
232 
235 }
236 
237 
238 void ELlimitsTable::setTimespan( const ELstring & id, int n ) {
239  if ( id[0] == '*' ) wildcardTimespan = n;
240  else limits[id].timespan = n;
241 }
242 
243 
244 void ELlimitsTable::setTimespan( const ELseverityLevel & sev, int n ) {
245  severityTimespans[sev.getLevel()] = n;
246 }
247 
248 
249 // ----------------------------------------------------------------------
250 // Support for internal operations:
251 // ----------------------------------------------------------------------
252 
254 
255  if(this == &t) {
256  return *this; // self assignment
257  }
258  limits = t.limits; // The non-trivial operator= for a map!
259 
260  for ( int lev = 0; lev < ELseverityLevel::nLevels; ++lev ) {
261  severityTimespans[lev] = t.severityTimespans[lev];
262  severityTimespans[lev] = t.severityTimespans[lev];
263  }
264 
267 
268  return *this;
269 
270 } // operator=()
271 
272 
273 // ----------------------------------------------------------------------
274 
275 
276 } // end of namespace service
277 } // end of namespace edm
int i
Definition: DBlmapReader.cc:9
ELseverityLevel severity
Definition: ELextendedID.h:36
tuple interval
Definition: MergeJob_cfg.py:20
int severityTimespans[ELseverityLevel::nLevels]
Definition: ELlimitsTable.h:99
bool add(const ELextendedID &xid)
int severityLimits[ELseverityLevel::nLevels]
Definition: ELlimitsTable.h:98
ELlimitsTable & operator=(const ELlimitsTable &t)
int k[5][pyjets_maxn]
void setInterval(const ELstring &id, int interval)
int severityIntervals[ELseverityLevel::nLevels]
void setTimespan(const ELstring &id, int n)
std::string ELstring
Definition: ELstring.h:26
void setLimit(const ELstring &id, int n)