Gaudi Framework, version v21r9

Home   Generated: 3 May 2010

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

Generated at Mon May 3 12:14:53 2010 for Gaudi Framework, version v21r9 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004