CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/CondCore/DBCommon/plugins/FrontierProxy.cc

Go to the documentation of this file.
00001 #include "CondCore/DBCommon/interface/DbSession.h"
00002 #include "CondCore/DBCommon/interface/DbConnection.h"
00003 #include "RelationalAccess/IWebCacheControl.h"
00004 #include "FWCore/Catalog/interface/SiteLocalConfig.h"
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "CondCore/MetaDataService/interface/MetaDataNames.h"
00007 #include "CondCore/IOVService/interface/IOVNames.h"
00008 
00009 #include "CondCore/DBCommon/interface/TechnologyProxy.h"
00010 #include <string>
00011 #include <vector>
00012 
00013 namespace cond{
00014   class FrontierProxy: public TechnologyProxy{
00015   public:
00016     FrontierProxy();
00017     ~FrontierProxy();
00018     void initialize(const std::string&userconnect,const DbConnection& connection);
00019     std::string getRealConnectString() const;
00020     bool isTransactional() const { return false;}
00021 
00022   private:
00023     static unsigned int countslash(const std::string& input);
00024   private:
00025     std::string m_userconnect;
00026     std::string m_transactionId;
00027   std::vector<std::string> m_refreshtablelist;
00028   };
00029 }//ns cond
00030 
00031 
00032 cond::FrontierProxy::FrontierProxy(){
00033   m_refreshtablelist.reserve(10);
00034   m_refreshtablelist.push_back(cond::IOVNames::iovTableName());
00035   m_refreshtablelist.push_back(cond::IOVNames::iovDataTableName());
00036   // do not refesh tag table in production...
00037   // m_refreshtablelist.push_back(cond::MetaDataNames::metadataTable());
00038 }
00039 
00040 cond::FrontierProxy::~FrontierProxy(){
00041   m_refreshtablelist.clear();
00042 }
00043 
00044 std::string 
00045 cond::FrontierProxy::getRealConnectString() const{
00046   std::string result = m_userconnect;
00047   std::string proto("frontier://");
00048   std::string::size_type fpos=m_userconnect.find(proto);
00049   unsigned int nslash=this->countslash(m_userconnect.substr(proto.size(),m_userconnect.size()-fpos));
00050   if(nslash==1){
00051     edm::Service<edm::SiteLocalConfig> localconfservice;
00052     if( !localconfservice.isAvailable() ){
00053       throw cms::Exception("edm::SiteLocalConfigService is not available");       
00054     }
00055     result=localconfservice->lookupCalibConnect(m_userconnect);
00056   }
00057   if (!m_transactionId.empty()) {
00058     size_t l = result.rfind('/');
00059     result.insert(l,"(freshkey="+m_transactionId+')');
00060     
00061   }
00062   return result;
00063 }
00064 
00065 void 
00066 cond::FrontierProxy::initialize(const std::string&userconnect, const DbConnection& connection) {
00067   m_userconnect = userconnect;
00068   m_transactionId = connection.configuration().transactionId();
00069 
00070   std::string refreshConnect;
00071   std::string realconnect=this->getRealConnectString();
00072   std::string::size_type startRefresh = realconnect.find("://");
00073   if (startRefresh != std::string::npos){
00074     startRefresh += 3;
00075   }
00076   std::string::size_type endRefresh=realconnect.rfind("/", std::string::npos);
00077   if (endRefresh == std::string::npos){
00078     refreshConnect = realconnect;
00079   }else{
00080     refreshConnect = realconnect.substr(startRefresh, endRefresh-startRefresh);
00081     if(refreshConnect.substr(0,1) != "("){
00082       //if the connect string is not a complicated parenthesized string,
00083       // an http:// needs to be at the beginning of it
00084       refreshConnect.insert(0, "http://");
00085     }
00086   }
00087   std::vector<std::string>::iterator ibeg=m_refreshtablelist.begin();
00088   std::vector<std::string>::iterator iend=m_refreshtablelist.end();
00089   for(std::vector<std::string>::iterator it=ibeg; it!=iend; ++it){
00090     connection.webCacheControl().refreshTable(refreshConnect,*it );
00091   }
00092   
00093 }
00094 unsigned int
00095 cond::FrontierProxy::countslash(const std::string& input) {
00096   unsigned int count=0;
00097   std::string::size_type slashpos( 0 );
00098   while( slashpos!=std::string::npos){
00099     slashpos = input.find('/', slashpos );
00100     if ( slashpos != std::string::npos ){
00101       ++count;
00102       // start next search after this word
00103       slashpos += 1;
00104     }
00105   }
00106   return count;
00107 }
00108 
00109 #include "CondCore/DBCommon/interface/TechnologyProxyFactory.h"
00110 DEFINE_EDM_PLUGIN(cond::TechnologyProxyFactory,cond::FrontierProxy,"frontier");