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 &&
116  (lib.compare(lib.length()-7, 7, "Dict.so") == 0 ||
117  lib.compare(lib.length()-8, 8, "Cling.so") == 0)) {
118  return;
119  }
120  // this appears only with gcc 4.9...
121  if (fnc == "_PyObject_GC_Malloc") return;
122  // GAUDI-1036
123  if (fnc == "PyThread_get_thread_ident") return;
124  if (fnc == "local") return;
125 
126  {
127  const string rlib = lib.substr(lib.rfind("/") + 1);
128 
129  if (m_filterfnc.find(fnc) != m_filterfnc.end() ||
130  m_filterlib.find(rlib) != m_filterlib.end() ) {
131  return;
132  }
133  }
134 
135  if (m_abort) {
136  MsgStream log( msgSvc(), name() );
137  log << MSG::FATAL << "Unchecked StatusCode in " << fnc << " from lib "
138  << lib << endmsg;
139  abort();
140  }
141 
142  string key = fnc + lib;
143 
144  map<string,StatCodeDat>::iterator itr = m_dat.find(key);
145 
146  if (itr != m_dat.end()) {
147  itr->second.count += 1;
148  } else {
149 
150  const string rlib = lib.substr(lib.rfind("/") + 1);
151 
152  StatCodeDat dat;
153  dat.fnc = fnc;
154  dat.lib = rlib;
155  dat.count = 1;
156 
157  m_dat[key] = dat;
158  }
159 
160 }
161 
162 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
163 
164 void
166 
167  MsgStream log( msgSvc(), name() );
168  log << MSG::INFO << endl;
169 
170  map<string,StatCodeDat>::const_iterator itr;
171 
172 #if defined (__GNUC__) && ( __GNUC__ <= 2 )
173  std::ostrstream os;
174 #else
175  std::ostringstream os;
176 #endif
177 
178  os << "Num | Function | Source Library" << endl;
179  os << "----+--------------------------------+-------------------"
180  << "-----------------------" << endl;
181 
182 
183  for(itr = m_dat.begin(); itr != m_dat.end(); ++itr ) {
184  StatCodeDat dat = itr->second;
185 
186  os.width(3);
187  os.setf(ios_base::right,ios_base::adjustfield);
188  os << dat.count;
189 
190  os << " | ";
191  os.width(30);
192  os.setf(ios_base::left,ios_base::adjustfield);
193  os << dat.fnc;
194 
195  os << " | ";
196  os.setf(ios_base::left,ios_base::adjustfield);
197  os << dat.lib;
198 
199  os << endl;
200 
201  }
202 
203 
204  log << os.str() << endmsg;
205 
206 }
207 
208 
209 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
210 void
211 StatusCodeSvc::filterFnc(const std::string& str) {
212 
213  std::map<std::string, StatCodeDat>::iterator itr;
214  for (itr = m_dat.begin(); itr != m_dat.end(); ++itr ) {
215  if (itr->second.fnc == str) {
216  m_dat.erase(itr);
217  return;
218  }
219 
220  }
221 
222 }
223 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
224 
225 void
226 StatusCodeSvc::filterLib(const std::string& str) {
227 
228  std::map<std::string, StatCodeDat>::iterator itr;
229  for (itr = m_dat.begin(); itr != m_dat.end(); ++itr ) {
230  if (itr->second.lib == str) {
231  m_dat.erase(itr);
232  return;
233  }
234 
235  }
236 
237 }
238 
239 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
240 
241 void
242 StatusCodeSvc::parseFilter(const string& str, string& fnc, string& lib) {
243 
244 
245  string::size_type loc = str.find("=");
246  if (loc == std::string::npos) {
247  fnc = str;
248  lib = "";
249  } else {
250  string key,val;
251  key = str.substr(0,loc);
252  val = str.substr(loc+1,str.length()-loc-1);
253 
254  toupper(key);
255 
256  if (key == "FCN" || key == "FNC") {
257  fnc = val;
258  lib = "";
259  } else if (key == "LIB") {
260  fnc = "";
261  lib = val;
262  } else {
263  fnc = "";
264  lib = "";
265 
266  MsgStream log( msgSvc(), name() );
267  log << MSG::WARNING << "ignoring unknown token in Filter: " << str
268  << endmsg;
269  }
270  }
271 
272 }
273 
274 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
275 
BooleanProperty m_abort
Definition: StatusCodeSvc.h:42
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual void regFnc(const std::string &func, const std::string &lib)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
Gaudi::StateMachine::State m_state
Service state.
Definition: Service.h:246
BooleanProperty m_dict
Definition: StatusCodeSvc.h:42
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
STL namespace.
virtual void list() const
std::map< std::string, StatCodeDat > m_dat
Definition: StatusCodeSvc.h:44
BooleanProperty m_suppress
Definition: StatusCodeSvc.h:42
virtual ~StatusCodeSvc()
void parseFilter(const std::string &str, std::string &fnc, std::string &lib)
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
std::set< std::string > m_filterfnc
Definition: StatusCodeSvc.h:45
const TYPE & value() const
explicit conversion
Definition: Property.h:355
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:329
StringArrayProperty m_pFilter
Definition: StatusCodeSvc.h:41
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
Definition: Service.cpp:72
virtual StatusCode reinitialize()
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
StatusCodeSvc(const std::string &name, ISvcLocator *svc)
void filterLib(const std::string &)
string s
Definition: gaudirun.py:244
Templated class to add the standard messaging functionalities.
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:212
void toupper(std::string &s)
void filterFnc(const std::string &)
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
std::set< std::string > m_filterlib
Definition: StatusCodeSvc.h:45