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"
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 
119  {
120  const string rlib = lib.substr(lib.rfind("/") + 1);
121 
122  if (m_filterfnc.find(fnc) != m_filterfnc.end() ||
123  m_filterlib.find(rlib) != m_filterlib.end() ) {
124  return;
125  }
126  }
127 
128  if (m_abort) {
129  MsgStream log( msgSvc(), name() );
130  log << MSG::FATAL << "Unchecked StatusCode in " << fnc << " from lib "
131  << lib << endmsg;
132  abort();
133  }
134 
135  string key = fnc + lib;
136 
137  map<string,StatCodeDat>::iterator itr = m_dat.find(key);
138 
139  if (itr != m_dat.end()) {
140  itr->second.count += 1;
141  } else {
142 
143  const string rlib = lib.substr(lib.rfind("/") + 1);
144 
145  StatCodeDat dat;
146  dat.fnc = fnc;
147  dat.lib = rlib;
148  dat.count = 1;
149 
150  m_dat[key] = dat;
151  }
152 
153 }
154 
155 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
156 
157 void
159 
160  MsgStream log( msgSvc(), name() );
161  log << MSG::INFO << endl;
162 
163  map<string,StatCodeDat>::const_iterator itr;
164 
165 #if defined (__GNUC__) && ( __GNUC__ <= 2 )
166  std::ostrstream os;
167 #else
168  std::ostringstream os;
169 #endif
170 
171  os << "Num | Function | Source Library" << endl;
172  os << "----+--------------------------------+-------------------"
173  << "-----------------------" << endl;
174 
175 
176  for(itr = m_dat.begin(); itr != m_dat.end(); ++itr ) {
177  StatCodeDat dat = itr->second;
178 
179  os.width(3);
180  os.setf(ios_base::right,ios_base::adjustfield);
181  os << dat.count;
182 
183  os << " | ";
184  os.width(30);
185  os.setf(ios_base::left,ios_base::adjustfield);
186  os << dat.fnc;
187 
188  os << " | ";
189  os.setf(ios_base::left,ios_base::adjustfield);
190  os << dat.lib;
191 
192  os << endl;
193 
194  }
195 
196 
197  log << os.str() << endmsg;
198 
199 }
200 
201 
202 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
203 void
204 StatusCodeSvc::filterFnc(const std::string& str) {
205 
206  std::map<std::string, StatCodeDat>::iterator itr;
207  for (itr = m_dat.begin(); itr != m_dat.end(); ++itr ) {
208  if (itr->second.fnc == str) {
209  m_dat.erase(itr);
210  return;
211  }
212 
213  }
214 
215 }
216 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
217 
218 void
219 StatusCodeSvc::filterLib(const std::string& str) {
220 
221  std::map<std::string, StatCodeDat>::iterator itr;
222  for (itr = m_dat.begin(); itr != m_dat.end(); ++itr ) {
223  if (itr->second.lib == str) {
224  m_dat.erase(itr);
225  return;
226  }
227 
228  }
229 
230 }
231 
232 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
233 
234 void
235 StatusCodeSvc::parseFilter(const string& str, string& fnc, string& lib) {
236 
237 
238  string::size_type loc = str.find("=");
239  if (loc == std::string::npos) {
240  fnc = str;
241  lib = "";
242  } else {
243  string key,val;
244  key = str.substr(0,loc);
245  val = str.substr(loc+1,str.length()-loc-1);
246 
247  toupper(key);
248 
249  if (key == "FCN" || key == "FNC") {
250  fnc = val;
251  lib = "";
252  } else if (key == "LIB") {
253  fnc = "";
254  lib = val;
255  } else {
256  fnc = "";
257  lib = "";
258 
259  MsgStream log( msgSvc(), name() );
260  log << MSG::WARNING << "ignoring unknown token in Filter: " << str
261  << endmsg;
262  }
263  }
264 
265 }
266 
267 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
268 
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:245
BooleanProperty m_dict
Definition: StatusCodeSvc.h:42
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
virtual void list() const
std::map< std::string, StatCodeDat > m_dat
Definition: StatusCodeSvc.h:44
BooleanProperty m_suppress
Definition: StatusCodeSvc.h:42
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
virtual ~StatusCodeSvc()
void parseFilter(const std::string &str, std::string &fnc, std::string &lib)
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:331
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:74
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:210
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:211
void toupper(std::string &s)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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