![]() |
|
|
Generated: 24 Nov 2008 |
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 00015 StatusCodeSvc::StatusCodeSvc(const std::string& name, ISvcLocator* svc ) 00016 : Service( name, svc ) 00017 { 00018 00019 declareProperty("Filter",m_pFilter); 00020 declareProperty("AbortOnError",m_abort=false); 00021 declareProperty("SuppressCheck", m_suppress=false); 00022 00023 } 00024 00025 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00026 00027 StatusCodeSvc::~StatusCodeSvc() { 00028 00029 } 00030 00031 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00032 00033 StatusCode StatusCodeSvc::queryInterface(const InterfaceID& riid, 00034 void** ppvInterface) 00035 { 00036 StatusCode sc = StatusCode::FAILURE; 00037 if ( ppvInterface ) { 00038 *ppvInterface = 0; 00039 00040 if ( IStatusCodeSvc::interfaceID().versionMatch(riid) ) { 00041 // if ( riid == IID_StatusCodeSvc ) { 00042 *ppvInterface = static_cast<IStatusCodeSvc*>(this); 00043 sc = StatusCode::SUCCESS; 00044 addRef(); 00045 } 00046 else 00047 sc = Service::queryInterface( riid, ppvInterface ); 00048 } 00049 return sc; 00050 } 00051 00052 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00053 00054 00055 StatusCode 00056 StatusCodeSvc::initialize() { 00057 00058 StatusCode sc = Service::initialize(); 00059 if (!sc.isSuccess()) return sc; 00060 00061 MsgStream log( msgSvc(), name() ); 00062 log << MSG::INFO << "initialize" << endreq; 00063 00064 std::vector<std::string>::const_iterator itr; 00065 for (itr = m_pFilter.value().begin(); itr != m_pFilter.value().end(); ++itr) { 00066 // we need to do this if someone has gotten to regFnc before initialize 00067 filterFnc(*itr); 00068 00069 m_filter.insert(*itr); 00070 } 00071 00072 return StatusCode::SUCCESS; 00073 00074 } 00075 00076 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00077 00078 StatusCode 00079 StatusCodeSvc::reinitialize() { 00080 00081 MsgStream log( msgSvc(), name() ); 00082 log << MSG::INFO << "reinitialize" << endreq; 00083 00084 return StatusCode::SUCCESS; 00085 00086 } 00087 00088 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00089 StatusCode 00090 StatusCodeSvc::finalize() { 00091 00092 if (m_dat.size() > 0) { 00093 MsgStream log( msgSvc(), name() ); 00094 00095 log << MSG::INFO << "listing all unchecked return codes:" << endreq; 00096 00097 list(); 00098 00099 } 00100 00101 return StatusCode::SUCCESS; 00102 00103 } 00104 00105 00106 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00107 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00108 00109 void 00110 StatusCodeSvc::regFnc(const std::string& fnc, const std::string& lib) { 00111 00112 if (m_filter.find(fnc) != m_filter.end()) { 00113 return; 00114 } 00115 00116 if (m_abort) { 00117 MsgStream log( msgSvc(), name() ); 00118 log << MSG::FATAL << "Unchecked StatusCode in " << fnc << " from lib " 00119 << lib << endreq; 00120 abort(); 00121 } 00122 00123 string key = fnc + lib; 00124 00125 map<string,StatCodeDat>::iterator itr = m_dat.find(key); 00126 00127 if (itr != m_dat.end()) { 00128 itr->second.count += 1; 00129 } else { 00130 00131 int i1 = lib.rfind("/",lib.length()); 00132 string rlib = lib.substr(i1+1,lib.length()-i1-1); 00133 00134 StatCodeDat dat; 00135 dat.fnc = fnc; 00136 dat.lib = rlib; 00137 dat.count = 1; 00138 00139 m_dat[key] = dat; 00140 } 00141 00142 } 00143 00144 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00145 00146 void 00147 StatusCodeSvc::list() const { 00148 00149 MsgStream log( msgSvc(), name() ); 00150 log << MSG::INFO << endl; 00151 00152 map<string,StatCodeDat>::const_iterator itr; 00153 00154 #if defined (__GNUC__) && ( __GNUC__ <= 2 ) 00155 std::ostrstream os; 00156 #else 00157 std::ostringstream os; 00158 #endif 00159 00160 os << "Num | Function | Source Library" << endl; 00161 os << "----+--------------------------------+-------------------" 00162 << "-----------------------" << endl; 00163 00164 00165 for(itr = m_dat.begin(); itr != m_dat.end(); ++itr ) { 00166 StatCodeDat dat = itr->second; 00167 00168 os.width(3); 00169 os.setf(ios_base::right,ios_base::adjustfield); 00170 os << dat.count; 00171 00172 os << " | "; 00173 os.width(30); 00174 os.setf(ios_base::left,ios_base::adjustfield); 00175 os << dat.fnc; 00176 00177 os << " | "; 00178 os.setf(ios_base::left,ios_base::adjustfield); 00179 os << dat.lib; 00180 00181 os << endl; 00182 00183 } 00184 00185 00186 log << os.str() << endreq; 00187 00188 } 00189 00190 00191 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00192 void 00193 StatusCodeSvc::filterFnc(std::string str) { 00194 00195 std::map<std::string, StatCodeDat>::iterator itr; 00196 for (itr = m_dat.begin(); itr != m_dat.end(); ++itr ) { 00197 if (itr->second.fnc == str) { 00198 m_dat.erase(itr); 00199 return; 00200 } 00201 00202 } 00203 00204 }