1 #ifndef CondCore_CondDB_Utils_h
2 #define CondCore_CondDB_Utils_h
12 #include <boost/regex.hpp>
21 char* realname = abi::__cxa_demangle( typeInfo.name(), 0, 0, &
status);
22 if( status == 0 && realname ){
33 const char* envVersion = ::getenv(
"CMSSW_VERSION" );
42 const char* archEnv = ::getenv(
"SCRAM_ARCH" );
51 namespace persistency {
54 size_t techEnd = connectionString.find(
':' );
55 if( techEnd == std::string::npos )
throwException(
"Could not resolve the connection protocol on "+connectionString+
".",
56 "getConnectionProtocol" );
57 std::string technology = connectionString.substr(0,techEnd);
65 if( protocol ==
"sqlite" || protocol ==
"sqlite_file" || protocol ==
"sqlite_fip" ){
66 databaseName = connectionString.substr( protocol.size()+1 );
67 }
else if ( protocol ==
"oracle" || protocol ==
"frontier" ){
68 size_t ptr = protocol.size()+1;
69 if( connectionString.substr( ptr,2 )!=
"//" )
throwException(
"Connection string "+connectionString+
70 " is invalid format for technology \""+
71 protocol+
"\".",
"parseConnectionString" );
73 size_t serviceEnd = connectionString.find(
'/', ptr );
74 if( serviceEnd == std::string::npos )
throwException(
"Connection string "+connectionString+
" is invalid.",
75 "parseConnectionString" );
76 serviceName = connectionString.substr( ptr, serviceEnd-ptr );
78 databaseName = connectionString.substr( ptr );
79 }
else throwException(
"Technology "+protocol+
" is not known.",
"parseConnectionString" );
81 return std::make_tuple( protocol, serviceName, databaseName );
87 if( input.find(
"sqlite") == 0 || input.find(
"oracle") == 0)
return input;
90 static const boost::regex short_frontier(
"frontier://([[:alnum:]]+?)/([_[:alnum:]]+?)");
91 static const boost::regex long_frontier(
"frontier://((\\([-[:alnum:]]+?=[^\\)]+?\\))+)/([_[:alnum:]]+?)");
92 static const boost::regex long_frontier_serverurl(
"\\(serverurl=[^\\)]+?/([[:alnum:]]+?)\\)");
94 static const std::map<std::string, std::string> frontierMap = {
95 {
"PromptProd",
"cms_orcon_adg"},
96 {
"FrontierProd",
"cms_orcon_adg"},
97 {
"FrontierArc",
"cms_orcon_adg"},
98 {
"FrontierOnProd",
"cms_orcon_adg"},
99 {
"FrontierPrep",
"cms_orcoff_prep"},
109 if (boost::regex_match(input, matches, short_frontier)){
110 service = matches[1];
111 account = matches[2];
115 if (boost::regex_match(input, matches, long_frontier)) {
117 boost::smatch matches2;
118 if (not boost::regex_search(frontier_config, matches2, long_frontier_serverurl))
119 throwException(
"No serverurl in matched long frontier",
"convertoToOracleConnection");
120 service = matches2[1];
121 account = matches[3];
125 if( !match )
throwException(
"Connection string "+input+
" can't be converted to oracle connection.",
"convertoToOracleConnection");
127 if( service ==
"FrontierArc" ){
128 size_t len = account.size()-5;
129 account = account.substr(0,len);
132 auto it = frontierMap.find( service );
133 if( it == frontierMap.end() )
throwException(
"Connection string can't be converted.",
"convertoToOracleConnection");
134 service = it->second;
136 return technology+service+
"/"+
account;
std::string getConnectionProtocol(const std::string &connectionString)
static const std::string serviceName
static std::string const input
std::string demangledName(const std::type_info &typeInfo)
std::tuple< std::string, std::string, std::string > parseConnectionString(const std::string &connectionString)
std::string convertoToOracleConnection(const std::string &input)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
void throwException(const std::string &message, const std::string &methodName)