CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/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 "CondCore/DBCommon/interface/Exception.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 
00010 #include "CondCore/DBCommon/interface/TechnologyProxy.h"
00011 #include <string>
00012 #include <vector>
00013 
00014 namespace cond{
00015   class FrontierProxy: public TechnologyProxy{
00016   public:
00017     FrontierProxy();
00018     ~FrontierProxy();
00019     void initialize( const DbConnection& connection);
00020     std::string getRealConnectString( const std::string&userconnect ) const;
00021     std::string getRealConnectString( const std::string&userconnect, const std::string& transactionId ) const;
00022     bool isTransactional() const { return false;}
00023 
00024   private:
00025     //static unsigned int countslash(const std::string& input);
00026     std::string makeRealConnectString( const std::string& initialConnection, const std::string& transactionId ) const ;
00027   private:
00028     const DbConnection* m_dbConnection;
00029     std::vector<std::string> m_refreshtablelist;
00030   };
00031 }//ns cond
00032 
00033 
00034 cond::FrontierProxy::FrontierProxy():
00035   m_dbConnection(0),
00036   m_refreshtablelist(){
00037   m_refreshtablelist.reserve(10);
00038   //table names for IOVSequence in the old POOL mapping
00039   m_refreshtablelist.push_back(cond::IOVNames::iovTableName());
00040   m_refreshtablelist.push_back(cond::IOVNames::iovDataTableName());
00041   //table names for IOVSequence in ORA
00042   //FIXME: do not use hard-coded names, ORA should provide them for a given container...
00043   m_refreshtablelist.push_back("ORA_C_COND_IOVSEQUENCE");
00044   m_refreshtablelist.push_back("ORA_C_COND_IOVSEQU_A0");
00045   m_refreshtablelist.push_back("ORA_C_COND_IOVSEQU_A1");
00046   // do not refesh tag table in production...
00047   // m_refreshtablelist.push_back(cond::MetaDataNames::metadataTable());
00048 }
00049 
00050 cond::FrontierProxy::~FrontierProxy(){
00051   m_refreshtablelist.clear();
00052 }
00053 
00054 namespace cond {
00055 
00056   unsigned int
00057   countslash(const std::string& input) {
00058     unsigned int count=0;
00059     std::string::size_type slashpos( 0 );
00060     while( slashpos!=std::string::npos){
00061       slashpos = input.find('/', slashpos );
00062       if ( slashpos != std::string::npos ){
00063         ++count;
00064         // start next search after this word
00065         slashpos += 1;
00066       }
00067     }
00068     return count;
00069   }
00070 
00071   std::string 
00072   cond::FrontierProxy::makeRealConnectString( const std::string& initialConnection, 
00073                                               const std::string& transactionId ) const {
00074     std::string realConn = initialConnection;
00075     // for testing
00076     //std::string res = initialConnection;
00077     std::string proto("frontier://");
00078     std::string::size_type fpos=initialConnection.find(proto);
00079     unsigned int nslash=countslash(initialConnection.substr(proto.size(),initialConnection.size()-fpos));
00080     if(nslash==1){
00081       edm::Service<edm::SiteLocalConfig> localconfservice;
00082       if( !localconfservice.isAvailable() ){
00083         throw cms::Exception("edm::SiteLocalConfigService is not available");       
00084       }
00085       realConn=localconfservice->lookupCalibConnect(initialConnection);
00086       //res=localconfservice->lookupCalibConnect(initialConnection);
00087     }
00088     if (!transactionId.empty()) {
00089       size_t l = realConn.rfind('/');
00090       realConn.insert(l,"(freshkey="+transactionId+')');
00091       //size_t l = res.rfind('/');
00092       //res.insert(l,"(freshkey="+transactionId+')');
00093     }
00094 
00095     std::string refreshConnect;
00096     std::string::size_type startRefresh = realConn.find("://");
00097     if (startRefresh != std::string::npos){
00098       startRefresh += 3;
00099     }
00100     std::string::size_type endRefresh=realConn.rfind("/", std::string::npos);
00101     if (endRefresh == std::string::npos){
00102       refreshConnect = realConn;
00103     }else{
00104       refreshConnect = realConn.substr(startRefresh, endRefresh-startRefresh);
00105       if(refreshConnect.substr(0,1) != "("){
00106         //if the connect string is not a complicated parenthesized string,
00107         // an http:// needs to be at the beginning of it
00108         refreshConnect.insert(0, "http://");
00109       }
00110     }
00111     std::vector<std::string>::const_iterator ibeg=m_refreshtablelist.begin();
00112     std::vector<std::string>::const_iterator iend=m_refreshtablelist.end();
00113     for(std::vector<std::string>::const_iterator it=ibeg; it!=iend; ++it){
00114       m_dbConnection->webCacheControl().refreshTable(refreshConnect,*it );
00115     }
00116 
00117     //std::cout << "***** frontier connection string " << std::endl;
00118     //std::cout << res << std::endl;
00119     return realConn;
00120   }
00121 
00122 }
00123 
00124 std::string 
00125 cond::FrontierProxy::getRealConnectString( const std::string&userconnect ) const {
00126   if( ! m_dbConnection ){
00127     throwException("The Technology Proxy has not been initialized.","FrontierProxy::getRealConnectString");
00128   }
00129   return makeRealConnectString(  userconnect, m_dbConnection->configuration().transactionId() );
00130 }
00131 
00132 std::string 
00133 cond::FrontierProxy::getRealConnectString( const std::string&userconnect, const std::string& transId ) const{
00134   if( ! m_dbConnection ){
00135     throwException("The Technology Proxy has not been initialized.","FrontierProxy::getRealConnectString");
00136   }
00137   const std::string* tId = &transId;
00138   if( transId.empty() ) tId = &m_dbConnection->configuration().transactionId();
00139   return makeRealConnectString(  userconnect, *tId );
00140 }
00141 
00142 void 
00143 cond::FrontierProxy::initialize( const DbConnection& connection ) {
00144   m_dbConnection = &connection;  
00145 }
00146 
00147 #include "CondCore/DBCommon/interface/TechnologyProxyFactory.h"
00148 DEFINE_EDM_PLUGIN(cond::TechnologyProxyFactory,cond::FrontierProxy,"frontier");