All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
StatusCodeSvc.cpp
Go to the documentation of this file.
1 #include "StatusCodeSvc.h"
3 
4 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5 
6 using namespace std;
7 //
9 //
10 inline void toupper(std::string &s)
11 {
12  std::transform(s.begin(), s.end(), s.begin(),
13  (int(*)(int)) toupper);
14 }
15 
16 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
17 
20 
22  if (!sc.isSuccess()) return sc;
23 
24  info() << "initialize" << endmsg;
25 
26  for (const auto& itr : m_pFilter.value()) {
27  // we need to do this if someone has gotten to regFnc before initialize
28 
29  string fnc,lib;
30  parseFilter(itr,fnc,lib);
31 
32  if (!fnc.empty()) {
33  filterFnc(fnc);
34  m_filterfnc.insert(fnc);
35  }
36 
37  if (!lib.empty()) {
38  filterLib(lib);
39  m_filterlib.insert(lib);
40  }
41 
42  }
43 
44  return StatusCode::SUCCESS;
45 
46 }
47 
48 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 
52 
53  info() << "reinitialize" << endmsg;
54 
55  return StatusCode::SUCCESS;
56 
57 }
58 
59 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
62 
63  if (!m_dat.empty()) {
64 
65  info() << "listing all unchecked return codes:" << endmsg;
66 
67  list();
68 
69  } else {
70 
71  if (msgLevel(MSG::DEBUG))
72  debug() << "all StatusCode instances where checked" << endmsg;
73 
74  }
75 
76  return StatusCode::SUCCESS;
77 
78 }
79 
80 
81 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
82 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
83 
84 void
86 
87  if (m_state == Gaudi::StateMachine::OFFLINE ||
89  return;
90  }
91 
92  // A StatusCode instance may be create internally by ROOT dictionaries and,
93  // of course, it's not checked, so here we whitelist a few library names
94  // that are known to produce spurious reports.
95  if (m_dict &&
96  (lib.compare(lib.length()-7, 7, "Dict.so") == 0 ||
97  lib.compare(lib.length()-8, 8, "Cling.so") == 0 ||
98  lib.compare(lib.length()-7, 7, "Core.so") == 0)) {
99  return;
100  }
101  // this appears only with gcc 4.9...
102  if (fnc == "_PyObject_GC_Malloc") return;
103  // GAUDI-1036
104  if (fnc == "PyThread_get_thread_ident") return;
105  if (fnc == "local") return;
106 
107  {
108  const string rlib = lib.substr(lib.rfind("/") + 1);
109 
110  if (m_filterfnc.find(fnc) != m_filterfnc.end() ||
111  m_filterlib.find(rlib) != m_filterlib.end() ) {
112  return;
113  }
114  }
115 
116  if (m_abort) {
117  fatal() << "Unchecked StatusCode in " << fnc << " from lib "
118  << lib << endmsg;
119  abort();
120  }
121 
122  string key = fnc + lib;
123 
124  auto itr = m_dat.find(key);
125 
126  if (itr != m_dat.end()) {
127  itr->second.count += 1;
128  } else {
129 
130  const string rlib = lib.substr(lib.rfind("/") + 1);
131 
132  StatCodeDat dat;
133  dat.fnc = fnc;
134  dat.lib = rlib;
135  dat.count = 1;
136 
137  m_dat[key] = dat;
138  }
139 
140 }
141 
142 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
143 
144 void
146 
147 
148 
150  os << "Num | Function | Source Library" << endl;
151  os << "----+--------------------------------+-------------------"
152  << "-----------------------" << endl;
153 
154  for(const auto& itr : m_dat) {
155  const auto& dat = itr.second;
156 
157  os.width(3);
158  os.setf(ios_base::right,ios_base::adjustfield);
159  os << dat.count;
160 
161  os << " | ";
162  os.width(30);
163  os.setf(ios_base::left,ios_base::adjustfield);
164  os << dat.fnc;
165 
166  os << " | ";
167  os.setf(ios_base::left,ios_base::adjustfield);
168  os << dat.lib;
169 
170  os << endl;
171 
172  }
173 
174  info() << endl << os.str() << endmsg;
175 
176 }
177 
178 
179 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
180 void
182 
183  auto itr = std::find_if(m_dat.begin(),m_dat.end(),
184  [&](const std::pair<std::string,StatCodeDat>& d) {
185  return d.second.fnc == str;
186  });
187  if (itr!=std::end(m_dat)) m_dat.erase(itr);
188 
189 }
190 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
191 
192 void
194 
195  auto itr = std::find_if(m_dat.begin(),m_dat.end(),
196  [&](const std::pair<std::string,StatCodeDat>& d) {
197  return d.second.lib == str;
198  });
199  if (itr!=std::end(m_dat)) m_dat.erase(itr);
200 }
201 
202 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
203 
204 void
205 StatusCodeSvc::parseFilter(const string& str, string& fnc, string& lib) {
206 
207 
208  auto loc = str.find("=");
209  if (loc == std::string::npos) {
210  fnc = str;
211  lib = "";
212  } else {
213  string key = str.substr(0,loc);
214  string val = str.substr(loc+1);
215 
216  toupper(key);
217 
218  if (key == "FCN" || key == "FNC") {
219  fnc = val;
220  lib.clear();
221  } else if (key == "LIB") {
222  fnc.clear();
223  lib = val;
224  } else {
225  fnc.clear();
226  lib.clear();
227 
228  warning() << "ignoring unknown token in Filter: " << str
229  << endmsg;
230  }
231  }
232 
233 }
234 
235 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
236 
T setf(T...args)
StatusCode initialize() override
Definition: Service.cpp:64
T empty(T...args)
StatusCode reinitialize() override
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
T rfind(T...args)
T endl(T...args)
STL namespace.
T end(T...args)
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
STL class.
void parseFilter(const std::string &str, std::string &fnc, std::string &lib)
StatusCode initialize() override
T toupper(T...args)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
T width(T...args)
T clear(T...args)
STL class.
void regFnc(const std::string &func, const std::string &lib) override
T find(T...args)
T length(T...args)
T begin(T...args)
void filterLib(const std::string &)
string s
Definition: gaudirun.py:245
T substr(T...args)
T abort(T...args)
T transform(T...args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
T compare(T...args)
void filterFnc(const std::string &)
void list() const override
StatusCode finalize() override