| # Gaudi Framework, version v21r10p1 |

Home |  | Generated: 29 Jul 2010

# PoolDbCacheSvc.cpp

Go to the documentation of this file.

    00001 // $Id: PoolDbCacheSvc.cpp,v 1.21 2008/10/27 16:41:33 marcocle Exp $
    00002 //====================================================================
    00003 //      PoolDbCacheSvc implementation
    00004 //--------------------------------------------------------------------
    00005 //      Author     : M.Frank
    00006 //
    00007 //====================================================================
    00008 #ifdef __ICC
    00009 // disable icc remark #2259: non-pointer conversion from "X" to "Y" may lose significant bits
    00010 //   TODO: To be removed, coming from CORAL
    00011 #pragma warning(disable:2259)
    00012 #endif
    00013
    00014 // FIXME: missing in CORAL
    00015 #include <algorithm>
    00016
    00017 #include "GaudiPoolDb/PoolDbCacheSvc.h"
    00018 #include "GaudiKernel/ClassID.h"
    00019 #include "GaudiKernel/MsgStream.h"
    00020 #include "GaudiKernel/strcasecmp.h"
    00021 #include "GaudiKernel/SvcFactory.h"
    00022 #include "StorageSvc/DbPrint.h"
    00023 #include "StorageSvc/DbOption.h"
    00024 #include "StorageSvc/IDbOptionProxy.h"
    00025 #include "StorageSvc/DbInstanceCount.h"
    00026 #include "GaudiUtils/IFileCatalog.h"
    00027 #include "GaudiUtils/IIODataManager.h"
    00028
    00029 #include "Reflex/Reflex.h"
    00030
    00031 namespace GaudiPoolDb  {  bool patchStreamers(MsgStream& log);     }
    00032
    00033 static pool::DbInstanceCount::Counter* s_count =
    00034   pool::DbInstanceCount::getCounter(typeid(PoolDbCacheSvc));
    00035
    00036 DECLARE_SERVICE_FACTORY(PoolDbCacheSvc)
    00037
    00038
    00046 class PoolDbMsgReporter : public coral::MsgReporter  {
    00047 protected:
    00049   IMessageSvc* m_svc;
    00050   int m_lvl;
    00051 public:
    00053   PoolDbMsgReporter(IMessageSvc* s, int l) : coral::MsgReporter(), m_svc(s), m_lvl(l)  {}
    00055   virtual ~PoolDbMsgReporter()               { }
    00057   virtual void report(int lvl, const std::string& src, const std::string& msg) {
    00058     if ( lvl >= m_lvl ) m_svc->reportMessage(src,lvl,msg);
    00059   }
    00060 };
    00061
    00063 PoolDbCacheSvc::PoolDbCacheSvc(const std::string& nam, ISvcLocator* svc)
    00064   : base_class(nam, svc), m_callbackHandler(0)
    00065 {
    00066   s_count->increment();
    00067   m_callbackHandler = this;
    00068   declareProperty("Dlls",               m_dlls);
    00069   declareProperty("DomainOpts",         m_domainOpts);
    00070   declareProperty("DatabaseOpts",       m_databaseOpts);
    00071   declareProperty("DatabaseOnOpenOpts", m_databaseOpenOpts);
    00072   declareProperty("ContainerOpts",      m_containerOpts);
    00073   declareProperty("ContainerOnOpenOpts",m_containerOpenOpts);
    00074 }
    00075
    00077 PoolDbCacheSvc::~PoolDbCacheSvc()
    00078 {
    00079   s_count->decrement();
    00080 }
    00081
    00083 StatusCode PoolDbCacheSvc::initialize()  {
    00084   StatusCode status = Service::initialize();
    00085   MsgStream log(msgSvc(), name());
    00086   if ( !status.isSuccess() ) {
    00087     log << MSG::ERROR << "Failed to initialize Service base class."
    00088         << endmsg;
    00089     return status;
    00090   }
    00091   coral::MessageStream::installMsgReporter(new PoolDbMsgReporter(msgSvc(),m_outputLevel.value()));
    00092   coral::MessageStream::setMsgVerbosity(static_cast<coral::MsgLevel>(m_outputLevel.value()));
    00093
    00094   log << MSG::INFO << "POOL output threshold:" << m_outputLevel
    00095       << endmsg;
    00096   status = loadLibraries();
    00097   if ( !status.isSuccess() ) {
    00098     log << MSG::ERROR << "Failed to load POOL libraries."
    00099         << endmsg;
    00100     return status;
    00101   }
    00102   session().open(0);
    00103   // All dictionaries should be loaded. Let's patch the streamers
    00104   // for ContainedObject, DataObject and SmartRefbase
    00105   if ( !GaudiPoolDb::patchStreamers(log) )  {
    00106     log << MSG::ERROR << "Failed to install customized IO!" << endmsg;
    00107     return StatusCode::FAILURE;
    00108   }
    00109   return status;
    00110 }
    00111
    00113 StatusCode PoolDbCacheSvc::finalize()   {
    00114   MsgStream log(msgSvc(), name());
    00115   session().close();
    00117   std::vector<System::ImageHandle>::iterator i;
    00118   for(i=m_sharedHdls.begin(); i != m_sharedHdls.end(); ++i)  {
    00119     if ( *i ) {
    00120       // System::unloadDynamicLib(*i);
    00121     }
    00122   }
    00123   m_sharedHdls.clear();
    00124   coral::MessageStream::installMsgReporter(0);
    00125   return Service::finalize();
    00126 }
    00127
    00129 pool::DbStatus
    00130 PoolDbCacheSvc::setCallbackOptions( pool::IDbOptionProxy* pObj,
    00131                                     const std::vector<std::string>& v,
    00132                                     const std::string& obj)
    00133 {
    00134   std::string opt_nam, opt_val, opt_typ;
    00135   typedef std::vector<std::string> StringV;
    00136   for (StringV::const_iterator i=v.begin(); i!=v.end(); ++i)  {
    00137     const std::string& id = *i;
    00138     if ( id.length() > obj.length() )   {
    00139       if ( obj == id.substr(0, obj.length()) )  {
    00140         std::string n = id.substr(obj.length()+1);
    00141         size_t idx = n.find("=");
    00142         size_t idx2 = n.find("TYP=");
    00143         if ( idx != std::string::npos && idx2 != std::string::npos )  {
    00144           opt_nam = n.substr(0, idx);
    00145           opt_val = n.substr(idx+1, idx2-2-idx);
    00146           opt_typ = n.substr(idx2+4,1);
    00147           std::stringstream s(opt_val);
    00148           pool::DbOption opt(opt_nam);
    00149           float fval;
    00150           int   ival;
    00151           long long int lval;
    00152           switch(::toupper(opt_typ[0])) {
    00153             case 'I':
    00154               s >> ival;
    00155               opt._setValue(ival);
    00156               pObj->setOption(opt);
    00157               break;
    00158             case 'L':
    00159               s >> lval;
    00160               opt._setValue(lval);
    00161               pObj->setOption(opt);
    00162               break;
    00163             case 'F':
    00164               s >> fval;
    00165               opt._setValue(fval);
    00166               pObj->setOption(opt);
    00167               break;
    00168             case 'S':
    00169               opt._setValue(opt_val.c_str());
    00170               pObj->setOption(opt);
    00171               break;
    00172             default:
    00173               break;
    00174           }
    00175         }
    00176       }
    00177     }
    00178   }
    00179   return pool::Success;
    00180 }
    00181
    00183 pool::DbStatus
    00184 PoolDbCacheSvc::setMyOptions( pool::IDbOptionProxy* pObj,
    00185                               pool::DbOptionCallback::OptionType typ,
    00186                               const std::string& name)
    00187 {
    00188   switch (typ)  {
    00189     case pool::DbOptionCallback::_DOMAIN_OPT:
    00190       return setCallbackOptions(pObj, m_domainOpts, name);
    00191     case pool::DbOptionCallback::_DATABASE_OPT:
    00192       return setCallbackOptions(pObj, m_databaseOpts, name);
    00193     case pool::DbOptionCallback::_DATABASE_ONOPEN:
    00194       return setCallbackOptions(pObj, m_databaseOpenOpts, name);
    00195     case pool::DbOptionCallback::_CONTAINER_OPT:
    00196       return setCallbackOptions(pObj, m_containerOpts, name);
    00197     case pool::DbOptionCallback::_CONTAINER_ONOPEN:
    00198       return setCallbackOptions(pObj, m_containerOpenOpts, name);
    00199     default:
    00200       break;
    00201   }
    00202   return pool::Error;
    00203 }
    00204
    00205 // Load all required libraries
    00206 StatusCode PoolDbCacheSvc::loadLibraries()  {
    00207   StatusCode status = StatusCode::SUCCESS;
    00208   if ( !m_dlls.empty() )  {
    00209     std::vector<std::string>::const_iterator i;
    00210     for(i=m_dlls.begin(); i != m_dlls.end(); ++i)  {
    00211       StatusCode iret = loadDictionary(*i);
    00212       if ( !iret.isSuccess() )  {
    00213         status = iret;
    00214       }
    00215     }
    00216   }
    00217   return status;
    00218 }
    00219
    00221 StatusCode PoolDbCacheSvc::loadDictionary(const std::string& nam) {
    00222   System::ImageHandle hdl = 0;
    00223   StatusCode status = System::loadDynamicLib(nam, &hdl);
    00224   if ( !status.isSuccess() )  {
    00225     MsgStream log(msgSvc(), name());
    00226     log << MSG::ERROR << System::getLastErrorString() << endmsg
    00227         << "Failed to load POOL implementation library:"
    00228         << nam << endmsg;
    00229     return status;
    00230   }
    00231   m_sharedHdls.push_back(hdl);
    00232   return status;
    00233 }