![]() |
|
|
Generated: 8 Jan 2009 |
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_state == Gaudi::StateMachine::OFFLINE || 00113 m_state == Gaudi::StateMachine::CONFIGURED) { 00114 return; 00115 } 00116 00117 if (m_filter.find(fnc) != m_filter.end()) { 00118 return; 00119 } 00120 00121 if (m_abort) { 00122 MsgStream log( msgSvc(), name() ); 00123 log << MSG::FATAL << "Unchecked StatusCode in " << fnc << " from lib " 00124 << lib << endreq; 00125 abort(); 00126 } 00127 00128 string key = fnc + lib; 00129 00130 map<string,StatCodeDat>::iterator itr = m_dat.find(key); 00131 00132 if (itr != m_dat.end()) { 00133 itr->second.count += 1; 00134 } else { 00135 00136 int i1 = lib.rfind("/",lib.length()); 00137 string rlib = lib.substr(i1+1,lib.length()-i1-1); 00138 00139 StatCodeDat dat; 00140 dat.fnc = fnc; 00141 dat.lib = rlib; 00142 dat.count = 1; 00143 00144 m_dat[key] = dat; 00145 } 00146 00147 } 00148 00149 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00150 00151 void 00152 StatusCodeSvc::list() const { 00153 00154 MsgStream log( msgSvc(), name() ); 00155 log << MSG::INFO << endl; 00156 00157 map<string,StatCodeDat>::const_iterator itr; 00158 00159 #if defined (__GNUC__) && ( __GNUC__ <= 2 ) 00160 std::ostrstream os; 00161 #else 00162 std::ostringstream os; 00163 #endif 00164 00165 os << "Num | Function | Source Library" << endl; 00166 os << "----+--------------------------------+-------------------" 00167 << "-----------------------" << endl; 00168 00169 00170 for(itr = m_dat.begin(); itr != m_dat.end(); ++itr ) { 00171 StatCodeDat dat = itr->second; 00172 00173 os.width(3); 00174 os.setf(ios_base::right,ios_base::adjustfield); 00175 os << dat.count; 00176 00177 os << " | "; 00178 os.width(30); 00179 os.setf(ios_base::left,ios_base::adjustfield); 00180 os << dat.fnc; 00181 00182 os << " | "; 00183 os.setf(ios_base::left,ios_base::adjustfield); 00184 os << dat.lib; 00185 00186 os << endl; 00187 00188 } 00189 00190 00191 log << os.str() << endreq; 00192 00193 } 00194 00195 00196 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00197 void 00198 StatusCodeSvc::filterFnc(std::string str) { 00199 00200 std::map<std::string, StatCodeDat>::iterator itr; 00201 for (itr = m_dat.begin(); itr != m_dat.end(); ++itr ) { 00202 if (itr->second.fnc == str) { 00203 m_dat.erase(itr); 00204 return; 00205 } 00206 00207 } 00208 00209 }