| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# 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
    00009 // FIXME: missing in CORAL
    00010 #include <algorithm>
    00011
    00012 #include "GaudiPoolDb/PoolDbCacheSvc.h"
    00013 #include "GaudiKernel/ClassID.h"
    00014 #include "GaudiKernel/MsgStream.h"
    00015 #include "GaudiKernel/strcasecmp.h"
    00016 #include "GaudiKernel/SvcFactory.h"
    00017 #include "StorageSvc/DbPrint.h"
    00018 #include "StorageSvc/DbOption.h"
    00019 #include "StorageSvc/IDbOptionProxy.h"
    00020 #include "StorageSvc/DbInstanceCount.h"
    00021 #include "GaudiUtils/IFileCatalog.h"
    00022 #include "GaudiUtils/IIODataManager.h"
    00023
    00024 #include "Reflex/Reflex.h"
    00025
    00026 namespace GaudiPoolDb  {  bool patchStreamers(MsgStream& log);     }
    00027
    00028 static pool::DbInstanceCount::Counter* s_count =
    00029   pool::DbInstanceCount::getCounter(typeid(PoolDbCacheSvc));
    00030
    00031 DECLARE_SERVICE_FACTORY(PoolDbCacheSvc);
    00032
    00041 class PoolDbMsgReporter : public coral::MsgReporter  {
    00042 protected:
    00044   IMessageSvc* m_svc;
    00045   int m_lvl;
    00046 public:
    00048   PoolDbMsgReporter(IMessageSvc* s, int l) : coral::MsgReporter(), m_svc(s), m_lvl(l)  {}
    00050   virtual ~PoolDbMsgReporter()               { }
    00052   virtual void report(int lvl, const std::string& src, const std::string& msg) {
    00053     if ( lvl >= m_lvl ) m_svc->reportMessage(src,lvl,msg);
    00054   }
    00055 };
    00056
    00058 PoolDbCacheSvc::PoolDbCacheSvc(const std::string& nam, ISvcLocator* svc)
    00059   : Service(nam, svc), m_callbackHandler(0)
    00060 {
    00061   s_count->increment();
    00062   m_callbackHandler = this;
    00063   declareProperty("Dlls",               m_dlls);
    00064   declareProperty("DomainOpts",         m_domainOpts);
    00065   declareProperty("DatabaseOpts",       m_databaseOpts);
    00066   declareProperty("DatabaseOnOpenOpts", m_databaseOpenOpts);
    00067   declareProperty("ContainerOpts",      m_containerOpts);
    00068   declareProperty("ContainerOnOpenOpts",m_containerOpenOpts);
    00069 }
    00070
    00072 PoolDbCacheSvc::~PoolDbCacheSvc()
    00073 {
    00074   s_count->decrement();
    00075 }
    00076
    00078 StatusCode PoolDbCacheSvc::queryInterface(const InterfaceID& riid, void** ppvInterface)
    00079 {
    00080   if ( IPoolCacheSvc::interfaceID().versionMatch(riid) )  {
    00081     *ppvInterface = (IPoolCacheSvc*)this;
    00082     addRef();
    00083     return StatusCode::SUCCESS;
    00084   }
    00085   // Interface is not directly availible: try out a base class
    00086   return Service::queryInterface(riid, ppvInterface);
    00087 }
    00088
    00090 StatusCode PoolDbCacheSvc::initialize()  {
    00091   StatusCode status = Service::initialize();
    00092   MsgStream log(messageService(), name());
    00093   if ( !status.isSuccess() ) {
    00094     log << MSG::ERROR << "Failed to initialize Service base class."
    00095         << endmsg;
    00096     return status;
    00097   }
    00098   coral::MessageStream::installMsgReporter(new PoolDbMsgReporter(messageService(),m_outputLevel.value()));
    00099   coral::MessageStream::setMsgVerbosity(static_cast<coral::MsgLevel>(m_outputLevel.value()));
    00100
    00101   log << MSG::INFO << "POOL output threshold:" << m_outputLevel
    00102       << endmsg;
    00103   status = loadLibraries();
    00104   if ( !status.isSuccess() ) {
    00105     log << MSG::ERROR << "Failed to load POOL libraries."
    00106         << endmsg;
    00107     return status;
    00108   }
    00109   session().open(0);
    00110   // All dictionaries should be loaded. Let's patch the streamers
    00111   // for ContainedObject, DataObject and SmartRefbase
    00112   if ( !GaudiPoolDb::patchStreamers(log) )  {
    00113     log << MSG::ERROR << "Failed to install customized IO!" << endmsg;
    00114     return StatusCode::FAILURE;
    00115   }
    00116   return status;
    00117 }
    00118
    00120 StatusCode PoolDbCacheSvc::finalize()   {
    00121   MsgStream log(messageService(), name());
    00122   session().close();
    00124   std::vector<System::ImageHandle>::iterator i;
    00125   for(i=m_sharedHdls.begin(); i != m_sharedHdls.end(); ++i)  {
    00126     if ( *i ) {
    00127       // System::unloadDynamicLib(*i);
    00128     }
    00129   }
    00130   m_sharedHdls.clear();
    00131   coral::MessageStream::installMsgReporter(0);
    00132   return Service::finalize();
    00133 }
    00134
    00136 pool::DbStatus
    00137 PoolDbCacheSvc::setCallbackOptions( pool::IDbOptionProxy* pObj,
    00138                                     const std::vector<std::string>& v,
    00139                                     const std::string& obj)
    00140 {
    00141   std::string opt_nam, opt_val, opt_typ;
    00142   typedef std::vector<std::string> StringV;
    00143   for (StringV::const_iterator i=v.begin(); i!=v.end(); ++i)  {
    00144     const std::string& id = *i;
    00145     if ( id.length() > obj.length() )   {
    00146       if ( obj == id.substr(0, obj.length()) )  {
    00147         std::string n = id.substr(obj.length()+1);
    00148         size_t idx = n.find("=");
    00149         size_t idx2 = n.find("TYP=");
    00150         if ( idx != std::string::npos && idx2 != std::string::npos )  {
    00151           opt_nam = n.substr(0, idx);
    00152           opt_val = n.substr(idx+1, idx2-2-idx);
    00153           opt_typ = n.substr(idx2+4,1);
    00154           std::stringstream s(opt_val);
    00155           pool::DbOption opt(opt_nam);
    00156           float fval;
    00157           int   ival;
    00158           long long int lval;
    00159           switch(::toupper(opt_typ[0])) {
    00160             case 'I':
    00161               s >> ival;
    00162               opt._setValue(ival);
    00163               pObj->setOption(opt);
    00164               break;
    00165             case 'L':
    00166               s >> lval;
    00167               opt._setValue(lval);
    00168               pObj->setOption(opt);
    00169               break;
    00170             case 'F':
    00171               s >> fval;
    00172               opt._setValue(fval);
    00173               pObj->setOption(opt);
    00174               break;
    00175             case 'S':
    00176               opt._setValue(opt_val.c_str());
    00177               pObj->setOption(opt);
    00178               break;
    00179             default:
    00180               break;
    00181           }
    00182         }
    00183       }
    00184     }
    00185   }
    00186   return pool::Success;
    00187 }
    00188
    00190 pool::DbStatus
    00191 PoolDbCacheSvc::setMyOptions( pool::IDbOptionProxy* pObj,
    00192                               pool::DbOptionCallback::OptionType typ,
    00193                               const std::string& name)
    00194 {
    00195   switch (typ)  {
    00196     case pool::DbOptionCallback::_DOMAIN_OPT:
    00197       return setCallbackOptions(pObj, m_domainOpts, name);
    00198     case pool::DbOptionCallback::_DATABASE_OPT:
    00199       return setCallbackOptions(pObj, m_databaseOpts, name);
    00200     case pool::DbOptionCallback::_DATABASE_ONOPEN:
    00201       return setCallbackOptions(pObj, m_databaseOpenOpts, name);
    00202     case pool::DbOptionCallback::_CONTAINER_OPT:
    00203       return setCallbackOptions(pObj, m_containerOpts, name);
    00204     case pool::DbOptionCallback::_CONTAINER_ONOPEN:
    00205       return setCallbackOptions(pObj, m_containerOpenOpts, name);
    00206     default:
    00207       break;
    00208   }
    00209   return pool::Error;
    00210 }
    00211
    00212 // Load all required libraries
    00213 StatusCode PoolDbCacheSvc::loadLibraries()  {
    00214   StatusCode status = StatusCode::SUCCESS;
    00215   if ( !m_dlls.empty() )  {
    00216     std::vector<std::string>::const_iterator i;
    00217     for(i=m_dlls.begin(); i != m_dlls.end(); ++i)  {
    00218       StatusCode iret = loadDictionary(*i);
    00219       if ( !iret.isSuccess() )  {
    00220         status = iret;
    00221       }
    00222     }
    00223   }
    00224   return status;
    00225 }
    00226
    00228 StatusCode PoolDbCacheSvc::loadDictionary(const std::string& nam) {
    00229   System::ImageHandle hdl = 0;
    00230   StatusCode status = System::loadDynamicLib(nam, &hdl);
    00231   if ( !status.isSuccess() )  {
    00232     MsgStream log(messageService(), name());
    00233     log << MSG::ERROR << System::getLastErrorString() << endmsg
    00234         << "Failed to load POOL implementation library:"
    00235         << nam << endmsg;
    00236     return status;
    00237   }
    00238   m_sharedHdls.push_back(hdl);
    00239   return status;
    00240 }