StatusCodeSvc.cpp
Go to the documentation of this file.00001 #include "StatusCodeSvc.h"
00002 #include "GaudiKernel/MsgStream.h"
00003 #include "GaudiKernel/SvcFactory.h"
00004 #include "GaudiKernel/StatusCode.h"
00005
00006
00007
00008 DECLARE_SERVICE_FACTORY(StatusCodeSvc)
00009
00010 using namespace std;
00011
00013
00014 inline void toupper(std::string &s)
00015 {
00016 std::string::iterator it=s.begin();
00017 while(it != s.end())
00018 {
00019 *it = toupper(*it);
00020 it++;
00021 }
00022 }
00023
00024
00025 StatusCodeSvc::StatusCodeSvc(const std::string& name, ISvcLocator* svc )
00026 : base_class( name, svc )
00027 {
00028
00029 declareProperty("Filter",m_pFilter);
00030 declareProperty("AbortOnError",m_abort=false);
00031 declareProperty("SuppressCheck", m_suppress=false);
00032 declareProperty("IgnoreDicts",m_dict=true);
00033
00034 }
00035
00036
00037
00038 StatusCodeSvc::~StatusCodeSvc() {
00039
00040 }
00041
00042
00043
00044
00045 StatusCode
00046 StatusCodeSvc::initialize() {
00047
00048 StatusCode sc = Service::initialize();
00049 if (!sc.isSuccess()) return sc;
00050
00051 MsgStream log( msgSvc(), name() );
00052 log << MSG::INFO << "initialize" << endmsg;
00053
00054 std::vector<std::string>::const_iterator itr;
00055 for (itr = m_pFilter.value().begin(); itr != m_pFilter.value().end(); ++itr) {
00056
00057
00058 string fnc,lib;
00059 parseFilter(*itr,fnc,lib);
00060
00061 if (fnc != "") {
00062 filterFnc(fnc);
00063 m_filterfnc.insert(fnc);
00064 }
00065
00066 if (lib != "") {
00067 filterLib(lib);
00068 m_filterlib.insert(lib);
00069 }
00070
00071 }
00072
00073 return StatusCode::SUCCESS;
00074
00075 }
00076
00077
00078
00079 StatusCode
00080 StatusCodeSvc::reinitialize() {
00081
00082 MsgStream log( msgSvc(), name() );
00083 log << MSG::INFO << "reinitialize" << endmsg;
00084
00085 return StatusCode::SUCCESS;
00086
00087 }
00088
00089
00090 StatusCode
00091 StatusCodeSvc::finalize() {
00092
00093 if (m_dat.size() > 0) {
00094 MsgStream log( msgSvc(), name() );
00095
00096 log << MSG::INFO << "listing all unchecked return codes:" << endmsg;
00097
00098 list();
00099
00100 }
00101
00102 return StatusCode::SUCCESS;
00103
00104 }
00105
00106
00107
00108
00109
00110 void
00111 StatusCodeSvc::regFnc(const std::string& fnc, const std::string& lib) {
00112
00113 if (m_state == Gaudi::StateMachine::OFFLINE ||
00114 m_state == Gaudi::StateMachine::CONFIGURED) {
00115 return;
00116 }
00117
00118 if (m_dict && lib.rfind("Dict.so") == (lib.length()-7) ) {
00119 return;
00120 }
00121
00122 int i1 = lib.rfind("/",lib.length());
00123 string rlib = lib.substr(i1+1,lib.length()-i1-1);
00124
00125
00126 if (m_filterfnc.find(fnc) != m_filterfnc.end() ||
00127 m_filterlib.find(rlib) != m_filterlib.end() ) {
00128 return;
00129 }
00130
00131 if (m_abort) {
00132 MsgStream log( msgSvc(), name() );
00133 log << MSG::FATAL << "Unchecked StatusCode in " << fnc << " from lib "
00134 << lib << endmsg;
00135 abort();
00136 }
00137
00138 string key = fnc + lib;
00139
00140 map<string,StatCodeDat>::iterator itr = m_dat.find(key);
00141
00142 if (itr != m_dat.end()) {
00143 itr->second.count += 1;
00144 } else {
00145
00146 int i1 = lib.rfind("/",lib.length());
00147 string rlib = lib.substr(i1+1,lib.length()-i1-1);
00148
00149 StatCodeDat dat;
00150 dat.fnc = fnc;
00151 dat.lib = rlib;
00152 dat.count = 1;
00153
00154 m_dat[key] = dat;
00155 }
00156
00157 }
00158
00159
00160
00161 void
00162 StatusCodeSvc::list() const {
00163
00164 MsgStream log( msgSvc(), name() );
00165 log << MSG::INFO << endl;
00166
00167 map<string,StatCodeDat>::const_iterator itr;
00168
00169 #if defined (__GNUC__) && ( __GNUC__ <= 2 )
00170 std::ostrstream os;
00171 #else
00172 std::ostringstream os;
00173 #endif
00174
00175 os << "Num | Function | Source Library" << endl;
00176 os << "----+--------------------------------+-------------------"
00177 << "-----------------------" << endl;
00178
00179
00180 for(itr = m_dat.begin(); itr != m_dat.end(); ++itr ) {
00181 StatCodeDat dat = itr->second;
00182
00183 os.width(3);
00184 os.setf(ios_base::right,ios_base::adjustfield);
00185 os << dat.count;
00186
00187 os << " | ";
00188 os.width(30);
00189 os.setf(ios_base::left,ios_base::adjustfield);
00190 os << dat.fnc;
00191
00192 os << " | ";
00193 os.setf(ios_base::left,ios_base::adjustfield);
00194 os << dat.lib;
00195
00196 os << endl;
00197
00198 }
00199
00200
00201 log << os.str() << endmsg;
00202
00203 }
00204
00205
00206
00207 void
00208 StatusCodeSvc::filterFnc(const std::string& str) {
00209
00210 std::map<std::string, StatCodeDat>::iterator itr;
00211 for (itr = m_dat.begin(); itr != m_dat.end(); ++itr ) {
00212 if (itr->second.fnc == str) {
00213 m_dat.erase(itr);
00214 return;
00215 }
00216
00217 }
00218
00219 }
00220
00221
00222 void
00223 StatusCodeSvc::filterLib(const std::string& str) {
00224
00225 std::map<std::string, StatCodeDat>::iterator itr;
00226 for (itr = m_dat.begin(); itr != m_dat.end(); ++itr ) {
00227 if (itr->second.lib == str) {
00228 m_dat.erase(itr);
00229 return;
00230 }
00231
00232 }
00233
00234 }
00235
00236
00237
00238 void
00239 StatusCodeSvc::parseFilter(const string& str, string& fnc, string& lib) {
00240
00241
00242 string::size_type loc = str.find("=");
00243 if (loc == std::string::npos) {
00244 fnc = str;
00245 lib = "";
00246 } else {
00247 string key,val;
00248 key = str.substr(0,loc);
00249 val = str.substr(loc+1,str.length()-loc-1);
00250
00251 toupper(key);
00252
00253 if (key == "FCN" || key == "FNC") {
00254 fnc = val;
00255 lib = "";
00256 } else if (key == "LIB") {
00257 fnc = "";
00258 lib = val;
00259 } else {
00260 fnc = "";
00261 lib = "";
00262
00263 MsgStream log( msgSvc(), name() );
00264 log << MSG::WARNING << "ignoring unknown token in Filter: " << str
00265 << endmsg;
00266 }
00267 }
00268
00269 }