| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

StatusCodeSvc.cpp
Go to the documentation of this file.
1 #include "StatusCodeSvc.h"
2 #include "GaudiKernel/StatusCode.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
18 StatusCode
19 StatusCodeSvc::initialize() {
20
21 StatusCode sc = Service::initialize();
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
50 StatusCode
51 StatusCodeSvc::reinitialize() {
52
53 info() << "reinitialize" << endmsg;
54
55 return StatusCode::SUCCESS;
56
57 }
58
59 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
60 StatusCode
61 StatusCodeSvc::finalize() {
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
85 StatusCodeSvc::regFnc(const std::string& fnc, const std::string& lib) {
86
87 if (m_state == Gaudi::StateMachine::OFFLINE ||
88 m_state == Gaudi::StateMachine::CONFIGURED) {
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
145 StatusCodeSvc::list() const {
146
147
148
149 std::ostringstream os;
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
181 StatusCodeSvc::filterFnc(const std::string& str) {
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
193 StatusCodeSvc::filterLib(const std::string& str) {
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
237 DECLARE_COMPONENT(StatusCodeSvc)
std::ostringstream::setf
T setf(T...args)
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:64
StatusCode::SUCCESS
Definition: StatusCode.h:30
std::string::empty
T empty(T...args)
Gaudi::StateMachine::CONFIGURED
Definition: StateMachine.h:14
StatusCodeSvc::StatCodeDat::fnc
std::string fnc
Definition: StatusCodeSvc.h:31
StatusCodeSvc::reinitialize
StatusCode reinitialize() override
Definition: StatusCodeSvc.cpp:51
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
std::string::rfind
T rfind(T...args)
MSG::DEBUG
Definition: IMessageSvc.h:18
std::endl
T endl(T...args)
std
STL namespace.
std::string::end
T end(T...args)
StatusCodeSvc::StatCodeDat::lib
std::string lib
Definition: StatusCodeSvc.h:32
StatusCodeSvc.h
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
std::string
STL class.
StatusCodeSvc::parseFilter
void parseFilter(const std::string &str, std::string &fnc, std::string &lib)
Definition: StatusCodeSvc.cpp:205
StatusCodeSvc::initialize
StatusCode initialize() override
Definition: StatusCodeSvc.cpp:19
std::toupper
T toupper(T...args)
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::ostringstream
STL class.
std::ostringstream::width
T width(T...args)
StatusCodeSvc::StatCodeDat::count
int count
Definition: StatusCodeSvc.h:33
std::ostringstream::str
T str(T...args)
std::string::clear
T clear(T...args)
std::list
STL class.
StatusCodeSvc::regFnc
void regFnc(const std::string &func, const std::string &lib) override
Definition: StatusCodeSvc.cpp:85
std::pair
std::string::find
T find(T...args)
std::string::length
T length(T...args)
std::string::begin
T begin(T...args)
StatusCodeSvc::filterLib
void filterLib(const std::string &)
Definition: StatusCodeSvc.cpp:193
gaudirun.s
string s
Definition: gaudirun.py:245
std::string::substr
T substr(T...args)
std::abort
T abort(T...args)
std::transform
T transform(T...args)
StatusCode.h
Gaudi::StateMachine::OFFLINE
Definition: StateMachine.h:13
StatusCodeSvc
Definition: StatusCodeSvc.h:12
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCodeSvc::StatCodeDat
Definition: StatusCodeSvc.h:30
std::string::compare
T compare(T...args)
StatusCodeSvc::filterFnc
void filterFnc(const std::string &)
Definition: StatusCodeSvc.cpp:181
StatusCodeSvc::list
void list() const override
Definition: StatusCodeSvc.cpp:145
StatusCodeSvc::finalize
StatusCode finalize() override
Definition: StatusCodeSvc.cpp:61