Gaudi Framework, version v22r2

Home   Generated: Tue May 10 2011

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

Generated at Tue May 10 2011 18:54:08 for Gaudi Framework, version v22r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004