PoolDbCacheSvc.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
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 : base_class(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::initialize() {
00079 StatusCode status = Service::initialize();
00080 MsgStream log(msgSvc(), name());
00081 if ( !status.isSuccess() ) {
00082 log << MSG::ERROR << "Failed to initialize Service base class."
00083 << endmsg;
00084 return status;
00085 }
00086 coral::MessageStream::installMsgReporter(new PoolDbMsgReporter(msgSvc(),m_outputLevel.value()));
00087 coral::MessageStream::setMsgVerbosity(static_cast<coral::MsgLevel>(m_outputLevel.value()));
00088
00089 log << MSG::INFO << "POOL output threshold:" << m_outputLevel
00090 << endmsg;
00091 status = loadLibraries();
00092 if ( !status.isSuccess() ) {
00093 log << MSG::ERROR << "Failed to load POOL libraries."
00094 << endmsg;
00095 return status;
00096 }
00097 session().open(0);
00098
00099
00100 if ( !GaudiPoolDb::patchStreamers(log) ) {
00101 log << MSG::ERROR << "Failed to install customized IO!" << endmsg;
00102 return StatusCode::FAILURE;
00103 }
00104 return status;
00105 }
00106
00108 StatusCode PoolDbCacheSvc::finalize() {
00109 MsgStream log(msgSvc(), name());
00110 session().close();
00112 std::vector<System::ImageHandle>::iterator i;
00113 for(i=m_sharedHdls.begin(); i != m_sharedHdls.end(); ++i) {
00114 if ( *i ) {
00115
00116 }
00117 }
00118 m_sharedHdls.clear();
00119 coral::MessageStream::installMsgReporter(0);
00120 return Service::finalize();
00121 }
00122
00124 pool::DbStatus
00125 PoolDbCacheSvc::setCallbackOptions( pool::IDbOptionProxy* pObj,
00126 const std::vector<std::string>& v,
00127 const std::string& obj)
00128 {
00129 std::string opt_nam, opt_val, opt_typ;
00130 typedef std::vector<std::string> StringV;
00131 for (StringV::const_iterator i=v.begin(); i!=v.end(); ++i) {
00132 const std::string& id = *i;
00133 if ( id.length() > obj.length() ) {
00134 if ( obj == id.substr(0, obj.length()) ) {
00135 std::string n = id.substr(obj.length()+1);
00136 size_t idx = n.find("=");
00137 size_t idx2 = n.find("TYP=");
00138 if ( idx != std::string::npos && idx2 != std::string::npos ) {
00139 opt_nam = n.substr(0, idx);
00140 opt_val = n.substr(idx+1, idx2-2-idx);
00141 opt_typ = n.substr(idx2+4,1);
00142 std::stringstream s(opt_val);
00143 pool::DbOption opt(opt_nam);
00144 float fval;
00145 int ival;
00146 long long int lval;
00147 switch(::toupper(opt_typ[0])) {
00148 case 'I':
00149 s >> ival;
00150 opt._setValue(ival);
00151 pObj->setOption(opt);
00152 break;
00153 case 'L':
00154 s >> lval;
00155 opt._setValue(lval);
00156 pObj->setOption(opt);
00157 break;
00158 case 'F':
00159 s >> fval;
00160 opt._setValue(fval);
00161 pObj->setOption(opt);
00162 break;
00163 case 'S':
00164 opt._setValue(opt_val.c_str());
00165 pObj->setOption(opt);
00166 break;
00167 default:
00168 break;
00169 }
00170 }
00171 }
00172 }
00173 }
00174 return pool::Success;
00175 }
00176
00178 pool::DbStatus
00179 PoolDbCacheSvc::setMyOptions( pool::IDbOptionProxy* pObj,
00180 pool::DbOptionCallback::OptionType typ,
00181 const std::string& name)
00182 {
00183 switch (typ) {
00184 case pool::DbOptionCallback::_DOMAIN_OPT:
00185 return setCallbackOptions(pObj, m_domainOpts, name);
00186 case pool::DbOptionCallback::_DATABASE_OPT:
00187 return setCallbackOptions(pObj, m_databaseOpts, name);
00188 case pool::DbOptionCallback::_DATABASE_ONOPEN:
00189 return setCallbackOptions(pObj, m_databaseOpenOpts, name);
00190 case pool::DbOptionCallback::_CONTAINER_OPT:
00191 return setCallbackOptions(pObj, m_containerOpts, name);
00192 case pool::DbOptionCallback::_CONTAINER_ONOPEN:
00193 return setCallbackOptions(pObj, m_containerOpenOpts, name);
00194 default:
00195 break;
00196 }
00197 return pool::Error;
00198 }
00199
00200
00201 StatusCode PoolDbCacheSvc::loadLibraries() {
00202 StatusCode status = StatusCode::SUCCESS;
00203 if ( !m_dlls.empty() ) {
00204 std::vector<std::string>::const_iterator i;
00205 for(i=m_dlls.begin(); i != m_dlls.end(); ++i) {
00206 StatusCode iret = loadDictionary(*i);
00207 if ( !iret.isSuccess() ) {
00208 status = iret;
00209 }
00210 }
00211 }
00212 return status;
00213 }
00214
00216 StatusCode PoolDbCacheSvc::loadDictionary(const std::string& nam) {
00217 System::ImageHandle hdl = 0;
00218 StatusCode status = System::loadDynamicLib(nam, &hdl);
00219 if ( !status.isSuccess() ) {
00220 MsgStream log(msgSvc(), name());
00221 log << MSG::ERROR << System::getLastErrorString() << endmsg
00222 << "Failed to load POOL implementation library:"
00223 << nam << endmsg;
00224 return status;
00225 }
00226 m_sharedHdls.push_back(hdl);
00227 return status;
00228 }