CMS 3D CMS Logo

ELseverityLevel.cc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------
2 //
3 // ELseverityLevel.cc - implement objects that encode a message's urgency
4 //
5 // Both frameworker and user will often pass one of the
6 // instantiated severity levels to logger methods.
7 //
8 // The only other methods of ELseverityLevel a frameworker
9 // might use is to check the relative level of two severities
10 // using operator<() or the like.
11 //
12 // 29-Jun-1998 mf Created file.
13 // 26-Aug-1998 WEB Made ELseverityLevel object less weighty.
14 // 16-Jun-1999 mf Added constructor from string, plus two lists
15 // of names to match. Also added default constructor,
16 // more streamlined than default lev on original.
17 // 23-Jun-1999 mf Modifications to properly handle pre-main order
18 // of initialization issues:
19 // Instantiation ofthe 14 const ELseverity &'s
20 // Instantiation of objectsInitialized as false
21 // Constructor of ELinitializeGlobalSeverityObjects
22 // Removed guarantor function in favor of the
23 // constructor.
24 // 30-Jun-1999 mf Modifications to eliminate propblems with order of
25 // globals initializations:
26 // Constructor from lev calls translate()
27 // Constructor from string uses translate()
28 // translate() method
29 // List of strings for names in side getname() etc.
30 // Immediate initilization of ELsevLevGlobals
31 // Mods involving ELinitializeGlobalSeverityObjects
32 // 12-Jun-2000 web Final fix to global static initialization problem
33 // 27-Jun-2000 web Fix order-of-static-destruction problem
34 // 24-Aug-2000 web Fix defective C++ switch generation
35 // 13-Jun-2007 mf Change (requested by CMS) the name Severe to System
36 // (since that his how MessageLogger uses that level)
37 // 21-Apr-2009 mf Change the symbol for ELsev_success (which is used
38 // by CMS for LogDebug) from -! to -d.
39 // ----------------------------------------------------------------------
40 
41 #include <ostream>
42 
45 
46 // Possible Traces
47 // #define ELsevConTRACE
48 
49 namespace edm {
50 
51  // ----------------------------------------------------------------------
52  // Helper to construct the string->ELsev_ map on demand:
53  // ----------------------------------------------------------------------
54 
55  typedef std::map<ELstring const, ELseverityLevel::ELsev_> ELmap;
56 
57  static ELmap const& loadMap() {
58  static const ELmap m = {{ELzeroSeverity.getSymbol(), ELseverityLevel::ELsev_zeroSeverity},
64  {ELdebug.getInputStr(), ELseverityLevel::ELsev_success},
66  {ELinfo.getSymbol(), ELseverityLevel::ELsev_info},
68  {ELinfo.getInputStr(), ELseverityLevel::ELsev_info},
69  {ELinfo.getVarName(), ELseverityLevel::ELsev_info},
76  {ELerror.getInputStr(), ELseverityLevel::ELsev_error},
77  {ELerror.getVarName(), ELseverityLevel::ELsev_error},
84  {ELsevere.getInputStr(), ELseverityLevel::ELsev_severe},
90 
91  return m;
92  }
93 
94  // ----------------------------------------------------------------------
95  // Birth/death:
96  // ----------------------------------------------------------------------
97 
98  ELseverityLevel::ELseverityLevel(enum ELsev_ lev) : myLevel(lev) {
99 #ifdef ELsevConTRACE
100  std::cerr << "--- ELseverityLevel " << lev << " (" << getName() << ")\n" << std::flush;
101 #endif
102  }
103 
105  static ELmap const& m = loadMap();
106 
107  ELmap::const_iterator i = m.find(s);
108  myLevel = (i == m.end()) ? ELsev_unspecified : i->second;
109  }
110 
112 
113  // ----------------------------------------------------------------------
114  // Comparator:
115  // ----------------------------------------------------------------------
116 
117  int ELseverityLevel::cmp(ELseverityLevel const& e) const { return myLevel - e.myLevel; }
118 
119  // ----------------------------------------------------------------------
120  // Accessors:
121  // ----------------------------------------------------------------------
122 
123  int ELseverityLevel::getLevel() const { return myLevel; }
124 
127 
128  switch (myLevel) {
129  default:
130  result = "0";
131  break;
132  case ELsev_zeroSeverity:
133  result = "--";
134  break;
135  case ELsev_success:
136  result = "-d";
137  break; // 4/21/09 mf
138  case ELsev_info:
139  result = "-i";
140  break;
141  case ELsev_warning:
142  result = "-w";
143  break;
144  case ELsev_error:
145  result = "-e";
146  break;
147  case ELsev_unspecified:
148  result = "??";
149  break;
150  case ELsev_severe:
151  result = "-s";
152  break;
154  result = "!!";
155  break;
156  }; // switch
157 
158  return result;
159  }
160 
163 
164  switch (myLevel) {
165  default:
166  result = "?no value?";
167  break;
168  case ELsev_zeroSeverity:
169  result = "--";
170  break;
171  case ELsev_success:
172  result = "Debug";
173  break; // 4/21/09 mf
174  case ELsev_info:
175  result = "Info";
176  break;
177  case ELsev_warning:
178  result = "Warning";
179  break;
180  case ELsev_error:
181  result = "Error";
182  break;
183  case ELsev_unspecified:
184  result = "??";
185  break;
186  case ELsev_severe:
187  result = "System";
188  break; // 6/13/07 mf
190  result = "!!";
191  break;
192  }; // switch
193 
194  return result;
195  }
196 
199 
200  switch (myLevel) {
201  default:
202  result = "?no value?";
203  break;
204  case ELsev_zeroSeverity:
205  result = "ZERO";
206  break;
207  case ELsev_success:
208  result = "DEBUG";
209  break;
210  case ELsev_info:
211  result = "INFO";
212  break;
213  case ELsev_warning:
214  result = "WARNING";
215  break;
216  case ELsev_error:
217  result = "ERROR";
218  break;
219  case ELsev_unspecified:
220  result = "UNSPECIFIED";
221  break;
222  case ELsev_severe:
223  result = "SYSTEM";
224  break; // 6/13/07 mf
226  result = "HIGHEST";
227  break;
228  }; // switch
229 
230  return result;
231  }
232 
235 
236  switch (myLevel) {
237  default:
238  result = "?no value? ";
239  break;
240  case ELsev_zeroSeverity:
241  result = "ELzeroSeverity ";
242  break;
243  case ELsev_success:
244  result = "ELdebug ";
245  break; // 4/21/09
246  case ELsev_info:
247  result = "ELinfo ";
248  break;
249  case ELsev_warning:
250  result = "ELwarning ";
251  break;
252  case ELsev_error:
253  result = "ELerror ";
254  break;
255  case ELsev_unspecified:
256  result = "ELunspecified ";
257  break;
258  case ELsev_severe:
259  result = "ELsystem ";
260  break; // 6/13/07
262  result = "ELhighestSeverity";
263  break;
264  }; // switch
265 
266  return result;
267  }
268 
269  // ----------------------------------------------------------------------
270  // Emitter:
271  // ----------------------------------------------------------------------
272 
273  std::ostream& operator<<(std::ostream& os, const ELseverityLevel& sev) { return os << " -" << sev.getName() << "- "; }
274 
275  // ----------------------------------------------------------------------
276  // Declare the globally available severity objects,
277  // one generator function and one proxy per non-default ELsev_:
278  // ----------------------------------------------------------------------
279 
282  return e;
283  }
285 
288  return e;
289  }
291 
294  return e;
295  }
297 
300  return e;
301  }
303 
306  return e;
307  }
309 
312  return e;
313  }
315 
318  return e;
319  }
321 
324  return e;
325  }
327 
328  // ----------------------------------------------------------------------
329 
330 } // end of namespace edm */
ELslGen ELinfoGen
ELslProxy< ELdebugGen > const ELdebug
ELslGen ELzeroSeverityGen
std::map< ELstring const, ELseverityLevel::ELsev_ > ELmap
int cmp(ELseverityLevel const &e) const
ELslGen ELerrorGen
ELslProxy< ELunspecifiedGen > const ELunspecified
ELseverityLevel(ELsev_ lev=ELsev_unspecified)
const ELstring getVarName() const
ELslProxy< ELwarningGen > const ELwarning
ELslProxy< ELhighestSeverityGen > const ELhighestSeverity
ELslGen ELdebugGen
static ELmap const & loadMap()
const ELstring getSymbol() const
ELslProxy< ELzeroSeverityGen > const ELzeroSeverity
ELslProxy< ELerrorGen > const ELerror
ELslGen ELwarningGen
const ELstring getName() const
const ELstring getInputStr() const
ELslGen ELhighestSeverityGen
ELslProxy< ELinfoGen > const ELinfo
ELslProxy< ELsevereGen > const ELsevere
friend std::ostream & operator<<(std::ostream &os, const ELseverityLevel &sev)
HLT enums.
ELslGen ELunspecifiedGen
ELslGen ELsevereGen
std::string ELstring
Definition: ELstring.h:21