1 #ifndef CondCore_CondDB_Utils_h 2 #define CondCore_CondDB_Utils_h 16 #include <boost/regex.hpp> 22 inline std::string demangledName(
const std::type_info& typeInfo ){
25 char* realname = abi::__cxa_demangle( typeInfo.name(),
nullptr,
nullptr, &
status);
26 if( status == 0 && realname ){
31 ret.erase(
std::remove( ret.begin(), ret.end(),
' ' ), ret.end() );
37 const char* envVersion = ::getenv(
"CMSSW_VERSION" );
46 const char* archEnv = ::getenv(
"SCRAM_ARCH" );
54 struct passwd* user_creds = getpwuid(getuid());
62 if( retcode )
return "";
69 std::ifstream comm(
"/proc/self/cmdline");
70 std::getline(comm,commName);
71 size_t ind = commName.find(
'\0');
72 while( ind != std::string::npos ){
73 commName.replace(ind,1,1,
' ');
74 ind = commName.find(
'\0');
76 }
catch ( std::ifstream::failure
const& ){
83 namespace persistency {
86 size_t techEnd = connectionString.find(
':' );
87 if( techEnd == std::string::npos )
throwException(
"Could not resolve the connection protocol on "+connectionString+
".",
88 "getConnectionProtocol" );
89 std::string technology = connectionString.substr(0,techEnd);
97 if( protocol ==
"sqlite" || protocol ==
"sqlite_file" || protocol ==
"sqlite_fip" ){
98 databaseName = connectionString.substr( protocol.size()+1 );
99 }
else if ( protocol ==
"oracle" || protocol ==
"frontier" ){
100 size_t ptr = protocol.size()+1;
101 if( connectionString.substr( ptr,2 )!=
"//" )
throwException(
"Connection string "+connectionString+
102 " is invalid format for technology \""+
103 protocol+
"\".",
"parseConnectionString" );
105 size_t serviceEnd = connectionString.find(
'/', ptr );
106 if( serviceEnd == std::string::npos )
throwException(
"Connection string "+connectionString+
" is invalid.",
107 "parseConnectionString" );
108 serviceName = connectionString.substr( ptr, serviceEnd-ptr );
110 databaseName = connectionString.substr( ptr );
111 }
else throwException(
"Technology "+protocol+
" is not known.",
"parseConnectionString" );
113 return std::make_tuple( protocol, serviceName, databaseName );
119 if( input.find(
"sqlite") == 0 || input.find(
"oracle") == 0)
return input;
122 static const boost::regex short_frontier(
"frontier://([[:alnum:]]+?)/([_[:alnum:]]+?)");
123 static const boost::regex long_frontier(
"frontier://((\\([-[:alnum:]]+?=[^\\)]+?\\))+)/([_[:alnum:]]+?)");
124 static const boost::regex long_frontier_serverurl(
"\\(serverurl=[^\\)]+?/([[:alnum:]]+?)\\)");
126 static const std::map<std::string, std::string> frontierMap = {
127 {
"PromptProd",
"cms_orcon_adg"},
128 {
"FrontierProd",
"cms_orcon_adg"},
129 {
"FrontierArc",
"cms_orcon_adg"},
130 {
"FrontierOnProd",
"cms_orcon_adg"},
131 {
"FrontierPrep",
"cms_orcoff_prep"},
141 if (boost::regex_match(input, matches, short_frontier)){
142 service = matches[1];
143 account = matches[2];
147 if (boost::regex_match(input, matches, long_frontier)) {
149 boost::smatch matches2;
150 if (not boost::regex_search(frontier_config, matches2, long_frontier_serverurl))
151 throwException(
"No serverurl in matched long frontier",
"convertoToOracleConnection");
152 service = matches2[1];
153 account = matches[3];
157 if( !match )
throwException(
"Connection string "+input+
" can't be converted to oracle connection.",
"convertoToOracleConnection");
159 if( service ==
"FrontierArc" ){
160 size_t len = account.size()-5;
161 account = account.substr(0,len);
164 auto it = frontierMap.find( service );
165 if( it == frontierMap.end() )
throwException(
"Connection string can't be converted.",
"convertoToOracleConnection");
166 service = it->second;
168 return technology+service+
"/"+account;
std::string getConnectionProtocol(const std::string &connectionString)
static const std::string serviceName
static std::string const input
std::tuple< std::string, std::string, std::string > parseConnectionString(const std::string &connectionString)
std::string convertoToOracleConnection(const std::string &input)
def remove(d, key, TELL=False)
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)