Commit 39d27228 authored by Edward Moyse's avatar Edward Moyse
Browse files

Merge branch 'fillchain' into 'master'

Database: String optimizations

See merge request atlas/athena!46588
parents fd642f9d aaab95d0
......@@ -431,15 +431,15 @@ bool AtlCoolCopy::addFolder(const std::string& folder,const bool onlyTags) {
// for leading part matches, next char in folder name must be '/'
// so /CALO/SetA matches /CALO/SetA/X but not /CALO/SetAB
if (*nodeitr==folder || folder=="/" ||
(nodeitr->substr(0,folder.size())==folder &&
nodeitr->size()>folder.size() && nodeitr->substr(folder.size(),1)=='/')) {
(nodeitr->compare(0,folder.size(),folder)==0 &&
nodeitr->size()>folder.size() && nodeitr->compare(folder.size(),1,"/")==0)) {
// check if folder on exclude list
bool exclude=false;
for (std::vector<std::string>::const_iterator iexcl=m_folderexcl.begin();
iexcl!=m_folderexcl.end();++iexcl) {
if (iexcl->substr(0,1)=="/") {
if (iexcl->compare(0,1,"/")==0) {
// exclude pattern starting / matches folder path (/SCT or /SCT/DCS)
exclude=(exclude || nodeitr->substr(0,iexcl->size())==*iexcl);
exclude=(exclude || nodeitr->compare(0,iexcl->size(),*iexcl)==0);
} else {
// exclude pattern without leading / matches anywhere in folder
exclude=(exclude || (nodeitr->find(*iexcl)!=std::string::npos));
......@@ -2097,9 +2097,9 @@ bool AtlCoolCopy::procOptVector(const int argc, const char* argv[],
bool error=false;
while (ic<argc) {
int ir=argc-ic;
std::string par0=argv[ic];
std::string_view par0=argv[ic];
// strip double "--" to achieve compatability with python-style options
if (par0.substr(0,2)=="--") par0=par0.substr(1);
if (par0.compare(0,2,"--")==0) par0=par0.substr(1);
if ((par0=="-f" || par0=="-folder") && ir>1) {
folders.emplace_back(argv[ic+1]);
++ic;
......
......@@ -90,7 +90,7 @@ LisToCool::LisToCool(const std::string& lisdb, const std::string& lisfolder,
m_lisfolder << std::endl;
std::cout << "Write to COOL DB: " << m_cooldbstr << " folder " <<
m_coolfolder << std::endl;
std::string smode="Undefined";
std::string_view smode="Undefined";
if (m_mode==1) smode="CondDBTable";
if (m_mode==11) smode="CondDBTable compressed";
if (m_mode==2) smode="Blob with Tags";
......@@ -275,16 +275,18 @@ void LisToCool::copyCondTable(bool compress) {
// from each folder)
std::vector<std::string> newcolname;
// set folder description string for single channel folder in Athena
std::string timestr;
std::string_view timestr;
if (m_runevent) {
timestr="<timeStamp>run-event</timeStamp>";
} else {
timestr="<timeStamp>time</timeStamp>";
}
if (m_channel==-1) {
m_cooldesc=timestr+"<addrHeader><address_header service_type=\"71\" clid=\"40774348\" /></addrHeader><typeName>AthenaAttributeList</typeName>";
m_cooldesc=std::string(timestr);
m_cooldesc+="<addrHeader><address_header service_type=\"71\" clid=\"40774348\" /></addrHeader><typeName>AthenaAttributeList</typeName>";
} else {
m_cooldesc=timestr+"<addrHeader><address_header service_type=\"71\" clid=\"1238547719\" /></addrHeader><typeName>CondAttrListCollection</typeName>";
m_cooldesc=std::string(timestr);
m_cooldesc+="<addrHeader><address_header service_type=\"71\" clid=\"1238547719\" /></addrHeader><typeName>CondAttrListCollection</typeName>";
std::cout << "Data will be written in COOL channel " << m_channel
<< std::endl;
// setup list of column names from tagprefix string (reused)
......
......@@ -31,7 +31,7 @@ void ReplicaSorter::sort(std::vector<
std::string::size_type ipos1=conn.find("://");
std::string::size_type ipos2=conn.find('/',ipos1+3);
if (ipos1!=std::string::npos && ipos2!=std::string::npos) {
const std::string server=conn.substr(ipos1+3,ipos2-ipos1-3);
const std::string_view server=std::string_view(conn).substr(ipos1+3,ipos2-ipos1-3);
// check if this server is on list of replicas to use for domain
// if so, add it with its associated priority
for (ServerMap::const_iterator sitr=m_servermap.begin();
......@@ -178,7 +178,9 @@ FILE* ReplicaSorter::findFile(const std::string& filename,
while (!fptr && iofs1<len) {
iofs2=pathvar.find(':',iofs1);
if (iofs2==std::string::npos) iofs2=len;
name=pathvar.substr(iofs1,iofs2-iofs1)+"/"+filename;
name=pathvar.substr(iofs1,iofs2-iofs1);
name+='/';
name+=filename;
fptr=fopen(name.c_str(),"r");
iofs1=iofs2+1;
}
......
......@@ -80,7 +80,7 @@ class CoraCoolDatabase {
bool deleteFolder(const std::string& coolfolder);
private:
bool extractCoralConStr(const std::string& coolstr);
bool extractCoralConStr(std::string_view coolstr);
std::string encodeAttrSpec(const cool::IRecordSpecification& spec);
bool storeSpec(const std::string& tablename,const std::string& spec);
......
......@@ -79,13 +79,13 @@ bool CoraCoolDatabase::disconnect() {
return m_connected;
}
bool CoraCoolDatabase::extractCoralConStr(const std::string& coolstr) {
bool CoraCoolDatabase::extractCoralConStr(const std::string_view coolstr) {
// extract CORAL database string from COOL one
bool dbok=false;
// first check for initial colon - if so, technology-specific string
std::string::size_type c1=coolstr.find(':');
if (c1!=std::string::npos) {
std::string techno,server,schema,user,passwd;
std::string_view techno,server,schema;
techno=coolstr.substr(0,c1);
std::string::size_type c2;
c2=coolstr.find(';');
......@@ -101,25 +101,30 @@ bool CoraCoolDatabase::extractCoralConStr(const std::string& coolstr) {
if (c1!=std::string::npos) {
c2=coolstr.find(';',c1+7);
if (c2==std::string::npos) c2=coolstr.size();
m_dbname=coolstr.substr(c1+7,c2-c1-7);
m_dbname=std::string(coolstr.substr(c1+7,c2-c1-7));
}
// construct the connection string
if (techno=="oracle" || techno=="mysql" || techno=="frontier") {
if (!server.empty() && !schema.empty()) {
m_dbconn=techno+"://"+server+"/"+schema;
m_dbconn=std::string(techno);
m_dbconn+= "://";
m_dbconn+=server;
m_dbconn+='/';
m_dbconn+=schema;
dbok=true;
}
} else if (techno=="sqlite") {
if (!schema.empty()) {
m_dbconn="sqlite_file:"+schema;
m_dbconn="sqlite_file:";
m_dbconn+=schema;
dbok=true;
}
}
} else {
c1=coolstr.find('/');
if (c1!=std::string::npos) {
m_dbconn=coolstr.substr(0,c1);
m_dbname=coolstr.substr(c1+1);
m_dbconn=std::string(coolstr.substr(0,c1));
m_dbname=std::string(coolstr.substr(c1+1));
dbok=true;
}
}
......@@ -136,8 +141,10 @@ std::string CoraCoolDatabase::encodeAttrSpec(
unsigned int n=spec.size();
for (unsigned int i=0;i<n;++i) {
const cool::IFieldSpecification& field=spec[i];
result+=field.name()+":"+field.storageType().name();
if (i<n-1) result+=",";
result+=field.name();
result+=':';
result+=field.storageType().name();
if (i<n-1) result+=',';
}
return result;
}
......@@ -210,12 +217,19 @@ CoraCoolFolderPtr CoraCoolDatabase::createFolder(const std::string& coolpath,
p1=description.find("<coracool>");
p2=description.find("</coracool>");
if (p1!=std::string::npos && p2!=std::string::npos) {
newdesc=description.substr(0,p1)+description.substr(p2+11);
newdesc=description.substr(0,p1);
newdesc.append(description, p2+11);
}
// COOL foreign key column is name of COOL payload attribute
newdesc=newdesc+"<coracool>"+coraltable+":"+
fkspec[0].name()+":"+
coralfk+":"+coralpk+"</coracool>";
newdesc+="<coracool>";
newdesc+=coraltable;
newdesc+=':';
newdesc+=fkspec[0].name();
newdesc+=':';
newdesc+= coralfk;
newdesc+=':';
newdesc+=coralpk;
newdesc+="</coracool>";
m_log << coral::Debug << "Created new description: " << newdesc <<
coral::MessageStream::endmsg;
......@@ -335,7 +349,9 @@ bool CoraCoolDatabase::parseFolderDescription(const std::string& folderdesc,
c2=folderdesc.find(':',c1+1);
if (c2==std::string::npos) return false;
tablename=m_dbname+"_"+folderdesc.substr(p1+10,c1-p1-10);
tablename=m_dbname;
tablename+= '_';
tablename.append(folderdesc,p1+10,c1-p1-10);
keycolcool=folderdesc.substr(c1+1,c2-c1-1);
fkeycolcoral=folderdesc.substr(c2+1,p2-c2-1);
// check for third colon to specify separate primary key
......
......@@ -461,8 +461,7 @@ bool CoraCoolFolder::decodeAttrSpec() {
iofs3=spec.size();
last=true;
}
m_attrvec.push_back(std::pair<std::string,std::string> (
spec.substr(iofs1,iofs2-iofs1),spec.substr(iofs2+1,iofs3-iofs2-1)));
m_attrvec.emplace_back(spec.substr(iofs1,iofs2-iofs1),spec.substr(iofs2+1,iofs3-iofs2-1));
if (!last) iofs1=iofs3+1;
}
bres=true;
......
......@@ -18,6 +18,7 @@
#include "CoraCool/CoraCoolObject.h"
#include "CoraCool/CoraCoolException.h"
#include "CoraCool/CoraCoolObjectIter.h"
#include <unordered_map>
// performance tuning parameters
// maximum number of ranges and query terms to use for CORAL query
......@@ -73,7 +74,7 @@ void CoraCoolObjectIter::readDataToBuffer(){
std::string fktypestr;
// keep map of FKvalue to list of associated COOL channels
typedef std::vector<unsigned int> KeyVec;
typedef std::map<long long,KeyVec > KeyMap;
typedef std::unordered_map<long long,KeyVec > KeyMap;
KeyMap keymap;
while (m_inbuf<m_buflen && iHasNext() &&
......@@ -328,13 +329,23 @@ void CoraCoolObjectIter::QueryBuilder::getQuery(std::string& where,
if (m_lower[i]==m_upper[i]) {
// bounds are equal - simple equivalence term
std::string keyname=addKey(ikey,fkeys,spec,m_lower[i]);
where+=coralkey+"=:"+keyname;
where+=coralkey;
where+="=:";
where+=keyname;
} else {
// bounds are not equal - need A>=B and A<=C
std::string keyname=addKey(ikey,fkeys,spec,m_lower[i]);
where+="("+coralkey+">=:"+keyname+" AND "+coralkey+"<=:";
where+='(';
where+=coralkey;
where+=">=:";
where+=keyname;
where+=" AND ";
where+=coralkey;
where+="<=:";
keyname=addKey(ikey,fkeys,spec,m_upper[i]);
where+=keyname+")";
where+=keyname;
where+=')';
}
}
}
......
......@@ -163,7 +163,7 @@ namespace Crest {
*
*/
std::string performRequest(const std::string& current_path, Action action, nlohmann::json& js,
const std::string& method_name);
const char* method_name);
/**
......@@ -209,7 +209,7 @@ namespace Crest {
* It was used to throw an exception if the library method not implemented for file system.
* @param method_name - method name.
*/
void checkFsException(std::string& method_name);
void checkFsException(const char* method_name);
/**
......@@ -224,14 +224,14 @@ namespace Crest {
* </pre>
* @param method - method name, where was the error.
*/
int checkErrors(const nlohmann::json& js, const std::string& method);
int checkErrors(const nlohmann::json& js, const char* method);
/**
* This method removes all XML/HTML tags from a string.
* (It is an auxillary method to clear the CREST Server response.)
* @param xmlBuffer - the text (a std::string ) to be cleared.
*/
std::string ParseXMLOutput(std::string xmlBuffer);
std::string ParseXMLOutput(std::string_view xmlBuffer);
/**
* This method removes all end of line and carriage return symbols from a string.
......@@ -249,7 +249,7 @@ namespace Crest {
* @param st - the CURL response,
* @param method_name - the name on a method which calls one of the perform request methods.
*/
void checkResult(CURLcode res, long response_code, const std::string& st, const std::string& method_name);
void checkResult(CURLcode res, long response_code, const std::string& st, const char* method_name);
public:
// ===================================
// CONSTRUCTORS
......@@ -283,7 +283,7 @@ namespace Crest {
* CrestClient myCrestClient = CrestClient(url);
* </pre>
*/
CrestClient(const std::string& url);
CrestClient(std::string_view url);
~CrestClient();
......@@ -308,7 +308,7 @@ namespace Crest {
* @return - JSON object as nlohmann::json
*
*/
nlohmann::json getJson(const std::string& str, const std::string& method); // string to json
nlohmann::json getJson(const std::string& str, const char* method); // string to json
/**
* Auxillary method to get a file as a string.
......@@ -1065,7 +1065,7 @@ namespace Crest {
* myCrestClient.storeBatchPayloadsFs(name39, str39);
* </pre>
*/
void storeBatchPayloadsFs(std::string tag_name, std::string& iovsetupload);
void storeBatchPayloadsFs(const std::string &tag_name, std::string& iovsetupload);
/**
* This auxillary method stores several payloads in batch mode in the file storage.
......@@ -1080,7 +1080,7 @@ namespace Crest {
* myCrestClient.storeBatchPayloadsFs(name39, js39);
* </pre>
*/
void storeBatchPayloadsFs(std::string tag_name, nlohmann::json& js);
void storeBatchPayloadsFs(const std::string &tag_name, nlohmann::json& js);
/**
......@@ -1094,7 +1094,7 @@ namespace Crest {
*
* @param varname - a variable name.
*/
std::string getEnvA(const std::string& varname);
std::string getEnvA(const char* varname);
/**
* Auxillary method to get an environment variable DAT_PATH.
......@@ -1275,7 +1275,7 @@ namespace Crest {
* @param str - a string to split.
* @param delim - a deliminator.
*/
std::vector<std::string> split(const std::string& str, const std::string& delim);
std::vector<std::string> split(std::string_view str, char delim);
/**
* This method gets a tag meta info from the CREST database in IOVDbSvc format.
......@@ -1394,7 +1394,7 @@ namespace Crest {
* This method uses SHA256 algorithm (PicoSHA2 C++ library)
* @param str - a string
*/
std::string getHash(std::string str);
std::string getHash(std::string_view str);
/**
* The auxillary method to get a current data and time.
......
This diff is collapsed.
......@@ -492,8 +492,8 @@ StatusCode HLTMonTool::fillForChain(const std::string& chain){
// christos (Nov-14): is there a reason to still check these flags???
unsigned int cond = isHLTChain ? TrigDefs::EF_passedRaw : TrigDefs::L2_passedRaw;
results["RAW"] = getTDT()->isPassed(chain, cond);
results["PS"] = results["RAW"] && (getTDT()->getPrescale(chain) != 1);
bool raw = results["RAW"] = getTDT()->isPassed(chain, cond);
results["PS"] = raw && (getTDT()->getPrescale(chain) != 1);
results["PT"] = getTDT()->isPassed(chain, TrigDefs::eventAccepted);
//set up iterators and such
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment