CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FrontierProxy.cc
Go to the documentation of this file.
3 #include "RelationalAccess/IWebCacheControl.h"
8 
10 #include <string>
11 #include <vector>
12 
13 namespace cond{
15  public:
16  FrontierProxy();
18  void initialize(const std::string&userconnect,const DbConnection& connection);
19  std::string getRealConnectString() const;
20  bool isTransactional() const { return false;}
21 
22  private:
23  static unsigned int countslash(const std::string& input);
24  private:
25  std::string m_userconnect;
26  std::string m_transactionId;
27  std::vector<std::string> m_refreshtablelist;
28  };
29 }//ns cond
30 
31 
33  m_refreshtablelist.reserve(10);
36  // do not refesh tag table in production...
37  // m_refreshtablelist.push_back(cond::MetaDataNames::metadataTable());
38 }
39 
41  m_refreshtablelist.clear();
42 }
43 
44 std::string
46  std::string result = m_userconnect;
47  std::string proto("frontier://");
48  std::string::size_type fpos=m_userconnect.find(proto);
49  unsigned int nslash=this->countslash(m_userconnect.substr(proto.size(),m_userconnect.size()-fpos));
50  if(nslash==1){
51  edm::Service<edm::SiteLocalConfig> localconfservice;
52  if( !localconfservice.isAvailable() ){
53  throw cms::Exception("edm::SiteLocalConfigService is not available");
54  }
55  result=localconfservice->lookupCalibConnect(m_userconnect);
56  }
57  if (!m_transactionId.empty()) {
58  size_t l = result.rfind('/');
59  result.insert(l,"(freshkey="+m_transactionId+')');
60 
61  }
62  return result;
63 }
64 
65 void
66 cond::FrontierProxy::initialize(const std::string&userconnect, const DbConnection& connection) {
67  m_userconnect = userconnect;
68  m_transactionId = connection.configuration().transactionId();
69 
70  std::string refreshConnect;
71  std::string realconnect=this->getRealConnectString();
72  std::string::size_type startRefresh = realconnect.find("://");
73  if (startRefresh != std::string::npos){
74  startRefresh += 3;
75  }
76  std::string::size_type endRefresh=realconnect.rfind("/", std::string::npos);
77  if (endRefresh == std::string::npos){
78  refreshConnect = realconnect;
79  }else{
80  refreshConnect = realconnect.substr(startRefresh, endRefresh-startRefresh);
81  if(refreshConnect.substr(0,1) != "("){
82  //if the connect string is not a complicated parenthesized string,
83  // an http:// needs to be at the beginning of it
84  refreshConnect.insert(0, "http://");
85  }
86  }
87  std::vector<std::string>::iterator ibeg=m_refreshtablelist.begin();
88  std::vector<std::string>::iterator iend=m_refreshtablelist.end();
89  for(std::vector<std::string>::iterator it=ibeg; it!=iend; ++it){
90  connection.webCacheControl().refreshTable(refreshConnect,*it );
91  }
92 
93 }
94 unsigned int
96  unsigned int count=0;
97  std::string::size_type slashpos( 0 );
98  while( slashpos!=std::string::npos){
99  slashpos = input.find('/', slashpos );
100  if ( slashpos != std::string::npos ){
101  ++count;
102  // start next search after this word
103  slashpos += 1;
104  }
105  }
106  return count;
107 }
108 
const std::string & transactionId() const
DbConnectionConfiguration & configuration()
Definition: DbConnection.cc:89
virtual std::string const lookupCalibConnect(std::string const &input) const =0
void initialize(const std::string &userconnect, const DbConnection &connection)
uint16_t size_type
coral::IWebCacheControl & webCacheControl() const
std::vector< std::string > m_refreshtablelist
std::string m_userconnect
static unsigned int countslash(const std::string &input)
tuple result
Definition: query.py:137
bool isAvailable() const
Definition: Service.h:47
static std::string iovDataTableName()
std::string getRealConnectString() const
tuple input
Definition: collect_tpl.py:10
static std::string iovTableName()
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::string m_transactionId
bool isTransactional() const