CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DbConnectionString.cc
Go to the documentation of this file.
3 #include "DbConnectionString.h"
4 //
8 
9 namespace cond {
10 
11  namespace persistency {
12 
13 
14  unsigned int
16  unsigned int count=0;
17  std::string::size_type slashpos( 0 );
18  while( slashpos!=std::string::npos){
19  slashpos = input.find('/', slashpos );
20  if ( slashpos != std::string::npos ){
21  ++count;
22  // start next search after this word
23  slashpos += 1;
24  }
25  }
26  return count;
27  }
28 
29  std::pair<std::string,std::string> getConnectionParams( const std::string& connectionString,
30  const std::string& transactionId ){
31  if( connectionString.empty() ) throwException( "The connection string is empty.","getConnectionParams");
32  std::string protocol = getConnectionProtocol( connectionString );
33  std::string finalConn = connectionString;
34  std::string refreshConn("");
35  if( protocol == "frontier" ){
36  std::string protocol("frontier://");
37  std::string::size_type fpos=connectionString.find(protocol);
38  unsigned int nslash=countslash(connectionString.substr(protocol.size(),connectionString.size()-fpos));
39  if(nslash==1){
40  edm::Service<edm::SiteLocalConfig> localconfservice;
41  if( !localconfservice.isAvailable() ){
42  throwException("edm::SiteLocalConfigService is not available","getConnectionParams");
43  }
44  finalConn=localconfservice->lookupCalibConnect(connectionString);
45  }
46  if (!transactionId.empty()) {
47  size_t l = finalConn.rfind('/');
48  finalConn.insert(l,"(freshkey="+transactionId+')');
49  }
50 
51  std::string::size_type startRefresh = finalConn.find("://");
52  if (startRefresh != std::string::npos){
53  startRefresh += 3;
54  }
55  std::string::size_type endRefresh=finalConn.rfind("/", std::string::npos);
56  if (endRefresh == std::string::npos){
57  refreshConn = finalConn;
58  } else{
59  refreshConn = finalConn.substr(startRefresh, endRefresh-startRefresh);
60  if(refreshConn.substr(0,1) != "("){
61  //if the connect string is not a complicated parenthesized string,
62  // an http:// needs to be at the beginning of it
63  refreshConn.insert(0, "http://");
64  }
65  }
66  } else if ( protocol == "sqlite_fip" ){
68  finalConn = parser.getRealConnect( connectionString );
69  }
70  return std::make_pair( finalConn, refreshConn );
71  }
72 
73  }
74 }
std::string getConnectionProtocol(const std::string &connectionString)
Definition: Utils.h:53
std::string getRealConnect(const std::string &fipConnect) const
virtual std::string const lookupCalibConnect(std::string const &input) const =0
uint16_t size_type
static std::string const input
Definition: EdmProvDump.cc:43
std::pair< std::string, std::string > getConnectionParams(const std::string &connectionString, const std::string &transactionId)
bool isAvailable() const
Definition: Service.h:46
string connectionString
Definition: autoCondHLT.py:4
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:11
unsigned int countslash(const std::string &input)