CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/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   //table names for IOVSequence in the old POOL mapping
00035   m_refreshtablelist.push_back(cond::IOVNames::iovTableName());
00036   m_refreshtablelist.push_back(cond::IOVNames::iovDataTableName());
00037   //table names for IOVSequence in ORA
00038   //FIXME: do not use hard-coded names, ORA should provide them for a given container...
00039   m_refreshtablelist.push_back("ORA_C_COND_IOVSEQUENCE");
00040   m_refreshtablelist.push_back("ORA_C_COND_IOVSEQU_A0");
00041   m_refreshtablelist.push_back("ORA_C_COND_IOVSEQU_A1");
00042   // do not refesh tag table in production...
00043   // m_refreshtablelist.push_back(cond::MetaDataNames::metadataTable());
00044 }
00045 
00046 cond::FrontierProxy::~FrontierProxy(){
00047   m_refreshtablelist.clear();
00048 }
00049 
00050 std::string 
00051 cond::FrontierProxy::getRealConnectString() const{
00052   std::string result = m_userconnect;
00053   std::string proto("frontier://");
00054   std::string::size_type fpos=m_userconnect.find(proto);
00055   unsigned int nslash=this->countslash(m_userconnect.substr(proto.size(),m_userconnect.size()-fpos));
00056   if(nslash==1){
00057     edm::Service<edm::SiteLocalConfig> localconfservice;
00058     if( !localconfservice.isAvailable() ){
00059       throw cms::Exception("edm::SiteLocalConfigService is not available");       
00060     }
00061     result=localconfservice->lookupCalibConnect(m_userconnect);
00062   }
00063   if (!m_transactionId.empty()) {
00064     size_t l = result.rfind('/');
00065     result.insert(l,"(freshkey="+m_transactionId+')');
00066     
00067   }
00068   return result;
00069 }
00070 
00071 void 
00072 cond::FrontierProxy::initialize(const std::string&userconnect, const DbConnection& connection) {
00073   m_userconnect = userconnect;
00074   m_transactionId = connection.configuration().transactionId();
00075 
00076   std::string refreshConnect;
00077   std::string realconnect=this->getRealConnectString();
00078   std::string::size_type startRefresh = realconnect.find("://");
00079   if (startRefresh != std::string::npos){
00080     startRefresh += 3;
00081   }
00082   std::string::size_type endRefresh=realconnect.rfind("/", std::string::npos);
00083   if (endRefresh == std::string::npos){
00084     refreshConnect = realconnect;
00085   }else{
00086     refreshConnect = realconnect.substr(startRefresh, endRefresh-startRefresh);
00087     if(refreshConnect.substr(0,1) != "("){
00088       //if the connect string is not a complicated parenthesized string,
00089       // an https:// needs to be at the beginning of it
00090       refreshConnect.insert(0, "https://");
00091     }
00092   }
00093   std::vector<std::string>::iterator ibeg=m_refreshtablelist.begin();
00094   std::vector<std::string>::iterator iend=m_refreshtablelist.end();
00095   for(std::vector<std::string>::iterator it=ibeg; it!=iend; ++it){
00096     connection.webCacheControl().refreshTable(refreshConnect,*it );
00097   }
00098   
00099 }
00100 unsigned int
00101 cond::FrontierProxy::countslash(const std::string& input) {
00102   unsigned int count=0;
00103   std::string::size_type slashpos( 0 );
00104   while( slashpos!=std::string::npos){
00105     slashpos = input.find('/', slashpos );
00106     if ( slashpos != std::string::npos ){
00107       ++count;
00108       // start next search after this word
00109       slashpos += 1;
00110     }
00111   }
00112   return count;
00113 }
00114 
00115 #include "CondCore/DBCommon/interface/TechnologyProxyFactory.h"
00116 DEFINE_EDM_PLUGIN(cond::TechnologyProxyFactory,cond::FrontierProxy,"frontier");