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 
85  if (m_dat.size() > 0) {
86  MsgStream log( msgSvc(), name() );
87 
88  log << MSG::INFO << "listing all unchecked return codes:" << endmsg;
89 
90  list();
91 
92  }
93 
94  return StatusCode::SUCCESS;
95 
96 }
97 
98 
99 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
100 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
101 
102 void
103 StatusCodeSvc::regFnc(const std::string& fnc, const std::string& lib) {
104 
107  return;
108  }
109 
110  if (m_dict && lib.rfind("Dict.so") == (lib.length()-7) ) {
111  return;
112  }
113 
114  {
115  const string rlib = lib.substr(lib.rfind("/") + 1);
116 
117  if (m_filterfnc.find(fnc) != m_filterfnc.end() ||
118  m_filterlib.find(rlib) != m_filterlib.end() ) {
119  return;
120  }
121  }
122 
123  if (m_abort) {
124  MsgStream log( msgSvc(), name() );
125  log << MSG::FATAL << "Unchecked StatusCode in " << fnc << " from lib "
126  << lib << endmsg;
127  abort();
128  }
129 
130  string key = fnc + lib;
131 
132  map<string,StatCodeDat>::iterator itr = m_dat.find(key);
133 
134  if (itr != m_dat.end()) {
135  itr->second.count += 1;
136  } else {
137 
138  const string rlib = lib.substr(lib.rfind("/") + 1);
139 
140  StatCodeDat dat;
141  dat.fnc = fnc;
142  dat.lib = rlib;
143  dat.count = 1;
144 
145  m_dat[key] = dat;
146  }
147 
148 }
149 
150 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
151 
152 void
154 
155  MsgStream log( msgSvc(), name() );
156  log << MSG::INFO << endl;
157 
158  map<string,StatCodeDat>::const_iterator itr;
159 
160 #if defined (__GNUC__) && ( __GNUC__ <= 2 )
161  std::ostrstream os;
162 #else
163  std::ostringstream os;
164 #endif
165 
166  os << "Num | Function | Source Library" << endl;
167  os << "----+--------------------------------+-------------------"
168  << "-----------------------" << endl;
169 
170 
171  for(itr = m_dat.begin(); itr != m_dat.end(); ++itr ) {
172  StatCodeDat dat = itr->second;
173 
174  os.width(3);
175  os.setf(ios_base::right,ios_base::adjustfield);
176  os << dat.count;
177 
178  os << " | ";
179  os.width(30);
180  os.setf(ios_base::left,ios_base::adjustfield);
181  os << dat.fnc;
182 
183  os << " | ";
184  os.setf(ios_base::left,ios_base::adjustfield);
185  os << dat.lib;
186 
187  os << endl;
188 
189  }
190 
191 
192  log << os.str() << endmsg;
193 
194 }
195 
196 
197 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
198 void
199 StatusCodeSvc::filterFnc(const std::string& str) {
200 
201  std::map<std::string, StatCodeDat>::iterator itr;
202  for (itr = m_dat.begin(); itr != m_dat.end(); ++itr ) {
203  if (itr->second.fnc == str) {
204  m_dat.erase(itr);
205  return;
206  }
207 
208  }
209 
210 }
211 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
212 
213 void
214 StatusCodeSvc::filterLib(const std::string& str) {
215 
216  std::map<std::string, StatCodeDat>::iterator itr;
217  for (itr = m_dat.begin(); itr != m_dat.end(); ++itr ) {
218  if (itr->second.lib == str) {
219  m_dat.erase(itr);
220  return;
221  }
222 
223  }
224 
225 }
226 
227 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
228 
229 void
230 StatusCodeSvc::parseFilter(const string& str, string& fnc, string& lib) {
231 
232 
233  string::size_type loc = str.find("=");
234  if (loc == std::string::npos) {
235  fnc = str;
236  lib = "";
237  } else {
238  string key,val;
239  key = str.substr(0,loc);
240  val = str.substr(loc+1,str.length()-loc-1);
241 
242  toupper(key);
243 
244  if (key == "FCN" || key == "FNC") {
245  fnc = val;
246  lib = "";
247  } else if (key == "LIB") {
248  fnc = "";
249  lib = val;
250  } else {
251  fnc = "";
252  lib = "";
253 
254  MsgStream log( msgSvc(), name() );
255  log << MSG::WARNING << "ignoring unknown token in Filter: " << str
256  << endmsg;
257  }
258  }
259 
260 }
261 
262 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
263 
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:243
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:62
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:35
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 &)
std
AIDA -> ROTO converter.
Definition: GaudiAlgs.py:73
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:209
void toupper(std::string &s)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
void filterFnc(const std::string &)
std::set< std::string > m_filterlib
Definition: StatusCodeSvc.h:45