All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StatusCodeSvc.cpp
Go to the documentation of this file.
1 #include "StatusCodeSvc.h"
2 #include "GaudiKernel/MsgStream.h"
3 #include "GaudiKernel/StatusCode.h"
4 
5 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
6 
7 using namespace std;
8 //
10 //
11 inline void toupper(std::string &s)
12 {
13  std::transform(s.begin(), s.end(), s.begin(),
14  (int(*)(int)) toupper);
15 }
16 
17 StatusCodeSvc::StatusCodeSvc(const std::string& name, ISvcLocator* svc )
18  : base_class( name, svc )
19 {
20 
21  declareProperty("Filter",m_pFilter);
22  declareProperty("AbortOnError",m_abort=false);
23  declareProperty("SuppressCheck", m_suppress=false);
24  declareProperty("IgnoreDicts",m_dict=true);
25 
26 }
27 
28 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
29 
31 
32 }
33 
34 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
35 
36 
39 
41  if (!sc.isSuccess()) return sc;
42 
43  MsgStream log( msgSvc(), name() );
44  log << MSG::INFO << "initialize" << endmsg;
45 
46  std::vector<std::string>::const_iterator itr;
47  for (itr = m_pFilter.value().begin(); itr != m_pFilter.value().end(); ++itr) {
48  // we need to do this if someone has gotten to regFnc before initialize
49 
50  string fnc,lib;
51  parseFilter(*itr,fnc,lib);
52 
53  if (fnc != "") {
54  filterFnc(fnc);
55  m_filterfnc.insert(fnc);
56  }
57 
58  if (lib != "") {
59  filterLib(lib);
60  m_filterlib.insert(lib);
61  }
62 
63  }
64 
65  return StatusCode::SUCCESS;
66 
67 }
68 
69 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
70 
73 
74  MsgStream log( msgSvc(), name() );
75  log << MSG::INFO << "reinitialize" << endmsg;
76 
77  return StatusCode::SUCCESS;
78 
79 }
80 
81 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
84  MsgStream log( msgSvc(), name() );
85 
86  if (m_dat.size() > 0) {
87 
88  log << MSG::INFO << "listing all unchecked return codes:" << endmsg;
89 
90  list();
91 
92  } else {
93 
94  if (msgLevel(MSG::DEBUG))
95  log << MSG::DEBUG << "all StatusCode instances where checked" << endmsg;
96 
97  }
98 
99  return StatusCode::SUCCESS;
100 
101 }
102 
103 
104 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
105 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
106 
107 void
108 StatusCodeSvc::regFnc(const std::string& fnc, const std::string& lib) {
109 
112  return;
113  }
114 
115  if (m_dict && lib.rfind("Dict.so") == (lib.length()-7) ) {
116  return;
117  }
118  // this appears only with gcc 4.9...
119  if (fnc == "_PyObject_GC_Malloc") return;
120 
121  {
122  const string rlib = lib.substr(lib.rfind("/") + 1);
123 
124  if (m_filterfnc.find(fnc) != m_filterfnc.end() ||
125  m_filterlib.find(rlib) != m_filterlib.end() ) {
126  return;
127  }
128  }
129 
130  if (m_abort) {
131  MsgStream log( msgSvc(), name() );
132  log << MSG::FATAL << "Unchecked StatusCode in " << fnc << " from lib "
133  << lib << endmsg;
134  abort();
135  }
136 
137  string key = fnc + lib;
138 
139  map<string,StatCodeDat>::iterator itr = m_dat.find(key);
140 
141  if (itr != m_dat.end()) {
142  itr->second.count += 1;
143  } else {
144 
145  const string rlib = lib.substr(lib.rfind("/") + 1);
146 
147  StatCodeDat dat;
148  dat.fnc = fnc;
149  dat.lib = rlib;
150  dat.count = 1;
151 
152  m_dat[key] = dat;
153  }
154 
155 }
156 
157 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
158 
159 void
161 
162  MsgStream log( msgSvc(), name() );
163  log << MSG::INFO << endl;
164 
165  map<string,StatCodeDat>::const_iterator itr;
166 
167 #if defined (__GNUC__) && ( __GNUC__ <= 2 )
168  std::ostrstream os;
169 #else
170  std::ostringstream os;
171 #endif
172 
173  os << "Num | Function | Source Library" << endl;
174  os << "----+--------------------------------+-------------------"
175  << "-----------------------" << endl;
176 
177 
178  for(itr = m_dat.begin(); itr != m_dat.end(); ++itr ) {
179  StatCodeDat dat = itr->second;
180 
181  os.width(3);
182  os.setf(ios_base::right,ios_base::adjustfield);
183  os << dat.count;
184 
185  os << " | ";
186  os.width(30);
187  os.setf(ios_base::left,ios_base::adjustfield);
188  os << dat.fnc;
189 
190  os << " | ";
191  os.setf(ios_base::left,ios_base::adjustfield);
192  os << dat.lib;
193 
194  os << endl;
195 
196  }
197 
198 
199  log << os.str() << endmsg;
200 
201 }
202 
203 
204 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
205 void
206 StatusCodeSvc::filterFnc(const std::string& str) {
207 
208  std::map<std::string, StatCodeDat>::iterator itr;
209  for (itr = m_dat.begin(); itr != m_dat.end(); ++itr ) {
210  if (itr->second.fnc == str) {
211  m_dat.erase(itr);
212  return;
213  }
214 
215  }
216 
217 }
218 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
219 
220 void
221 StatusCodeSvc::filterLib(const std::string& str) {
222 
223  std::map<std::string, StatCodeDat>::iterator itr;
224  for (itr = m_dat.begin(); itr != m_dat.end(); ++itr ) {
225  if (itr->second.lib == str) {
226  m_dat.erase(itr);
227  return;
228  }
229 
230  }
231 
232 }
233 
234 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
235 
236 void
237 StatusCodeSvc::parseFilter(const string& str, string& fnc, string& lib) {
238 
239 
240  string::size_type loc = str.find("=");
241  if (loc == std::string::npos) {
242  fnc = str;
243  lib = "";
244  } else {
245  string key,val;
246  key = str.substr(0,loc);
247  val = str.substr(loc+1,str.length()-loc-1);
248 
249  toupper(key);
250 
251  if (key == "FCN" || key == "FNC") {
252  fnc = val;
253  lib = "";
254  } else if (key == "LIB") {
255  fnc = "";
256  lib = val;
257  } else {
258  fnc = "";
259  lib = "";
260 
261  MsgStream log( msgSvc(), name() );
262  log << MSG::WARNING << "ignoring unknown token in Filter: " << str
263  << endmsg;
264  }
265  }
266 
267 }
268 
269 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
270