CMS 3D CMS Logo

FrontierProxy.cc

Go to the documentation of this file.
00001 #include "FrontierProxy.h"
00002 #include "CondCore/DBCommon/interface/TechnologyProxyFactory.h"
00003 #include "CondCore/DBCommon/interface/DBSession.h"
00004 #include "RelationalAccess/IWebCacheControl.h"
00005 #include "FWCore/Catalog/interface/SiteLocalConfig.h"
00006 #include "FWCore/ServiceRegistry/interface/Service.h"
00007 #include "CondCore/MetaDataService/interface/MetaDataNames.h"
00008 #include "CondCore/IOVService/interface/IOVNames.h"
00009 cond::FrontierProxy::FrontierProxy( const std::string& userconnect ):cond::TechnologyProxy(userconnect){
00010   m_refreshtablelist.reserve(10);
00011   m_refreshtablelist.push_back(cond::IOVNames::iovTableName());
00012   m_refreshtablelist.push_back(cond::IOVNames::iovDataTableName());
00013   m_refreshtablelist.push_back(cond::MetaDataNames::metadataTable());
00014 }
00015 cond::FrontierProxy::~FrontierProxy(){
00016   m_refreshtablelist.clear();
00017 }
00018 std::string 
00019 cond::FrontierProxy::getRealConnectString() const{
00020   std::string result(m_userconnect);
00021   std::string proto("frontier://");
00022   std::string::size_type fpos=m_userconnect.find(proto);
00023   unsigned int nslash=this->countslash(m_userconnect.substr(proto.size(),m_userconnect.size()-fpos));
00024   if(nslash==1){
00025     edm::Service<edm::SiteLocalConfig> localconfservice;
00026     if( !localconfservice.isAvailable() ){
00027       throw cms::Exception("edm::SiteLocalConfigService is not available");       
00028     }
00029     result=localconfservice->lookupCalibConnect(m_userconnect);
00030   }
00031   return result;
00032 }
00033 void 
00034 cond::FrontierProxy::setupSession(cond::DBSession& session){
00035   std::string refreshConnect;
00036   std::string realconnect=this->getRealConnectString();
00037   std::string::size_type startRefresh = realconnect.find("://");
00038   if (startRefresh != std::string::npos){
00039     startRefresh += 3;
00040   }
00041   std::string::size_type endRefresh=realconnect.rfind("/", std::string::npos);
00042   if (endRefresh == std::string::npos){
00043     refreshConnect = realconnect;
00044   }else{
00045     refreshConnect = realconnect.substr(startRefresh, endRefresh-startRefresh);
00046     if(refreshConnect.substr(0,1) != "("){
00047       //if the connect string is not a complicated parenthesized string,
00048       // an https:// needs to be at the beginning of it
00049       refreshConnect.insert(0, "https://");
00050     }
00051   }
00052   std::vector<std::string>::iterator ibeg=m_refreshtablelist.begin();
00053   std::vector<std::string>::iterator iend=m_refreshtablelist.end();
00054   for(std::vector<std::string>::iterator it=ibeg; it!=iend; ++it){
00055     session.webCacheControl().refreshTable(refreshConnect,*it );
00056   }
00057 }
00058 unsigned int
00059 cond::FrontierProxy::countslash(const std::string& input)const{
00060   unsigned int count=0;
00061   std::string::size_type slashpos( 0 );
00062   while( slashpos!=std::string::npos){
00063     slashpos = input.find('/', slashpos );
00064     if ( slashpos != std::string::npos ){
00065       ++count;
00066       // start next search after this word
00067       slashpos += 1;
00068     }
00069   }
00070   return count;
00071 }
00072 DEFINE_EDM_PLUGIN(cond::TechnologyProxyFactory,cond::FrontierProxy,"frontier");

Generated on Tue Jun 9 17:26:05 2009 for CMSSW by  doxygen 1.5.4