From 540f0f55db6812165bdedad20ef7903207415025 Mon Sep 17 00:00:00 2001 From: jgalan Date: Thu, 31 Mar 2022 01:31:43 +0200 Subject: [PATCH 01/12] TRestTools::POSTRequest method added --- source/framework/tools/inc/TRestTools.h | 14 ++-- source/framework/tools/src/TRestTools.cxx | 97 ++++++++++++++++++----- 2 files changed, 84 insertions(+), 27 deletions(-) diff --git a/source/framework/tools/inc/TRestTools.h b/source/framework/tools/inc/TRestTools.h index c71ffd40a..ee7f971b3 100644 --- a/source/framework/tools/inc/TRestTools.h +++ b/source/framework/tools/inc/TRestTools.h @@ -87,12 +87,14 @@ class TRestTools { static std::string Execute(string cmd); - static std::string DownloadRemoteFile(string remoteFile); - static int DownloadRemoteFile(string remoteFile, string localFile); - static int UploadToServer(string localfile, string remotefile, string methodurl = ""); + static std::string DownloadRemoteFile(std::string remoteFile); + static int DownloadRemoteFile(std::string remoteFile, std::string localFile); + static int UploadToServer(std::string localfile, std::string remotefile, std::string methodurl = ""); + static int POSTRequest(std::string& file_content, std::vector keys, + std::vector values); - static void ChangeDirectory( string toDirectory ); - static void ReturnToPreviousDirectory( ); + static void ChangeDirectory(string toDirectory); + static void ReturnToPreviousDirectory(); /// Rest tools class ClassDef(TRestTools, 1); @@ -124,7 +126,7 @@ inline void SetInitLevel(T* name, int level) { struct __##classname##_Init { \ __##classname##_Init() { \ REST_ARGS[#objname] = #classname; \ - if (objname != nullptr) { \ + if (objname != nullptr) { \ if (REST_InitTools::CanOverwrite(objname, level)) { \ delete objname; \ objname = new classname(); \ diff --git a/source/framework/tools/src/TRestTools.cxx b/source/framework/tools/src/TRestTools.cxx index 4f49376c9..9e10f6eab 100644 --- a/source/framework/tools/src/TRestTools.cxx +++ b/source/framework/tools/src/TRestTools.cxx @@ -55,6 +55,8 @@ #include "TSystem.h" #include "TUrl.h" +#include + ClassImp(TRestTools); /////////////////////////////////////////////// @@ -729,6 +731,7 @@ std::string TRestTools::DownloadRemoteFile(string url) { /// /// The file name is given in url format, and is parsed by TUrl. Various methods /// will be used, including scp, wget. returns 0 if succeed. +/// int TRestTools::DownloadRemoteFile(string remoteFile, string localFile) { TUrl url(remoteFile.c_str()); @@ -771,6 +774,60 @@ int TRestTools::DownloadRemoteFile(string remoteFile, string localFile) { return -1; } +/////////////////////////////////////////////// +/// \brief It performs a POST web protocol request using a set of keys and values given +/// by argument, and places the result inside `content`. +/// +int TRestTools::POSTRequest(std::string& file_content, std::vector keys, + std::vector values) { + if (keys.size() != values.size()) { + ferr << "The number of keys and values does not match!" << endl; + return 1; + } + + CURL* curl; + CURLcode res; + + string filename = REST_USER_PATH + "/download/curl.out"; + + /* In windows, this will init the winsock stuff */ + curl_global_init(CURL_GLOBAL_ALL); + + FILE* f = fopen(filename.c_str(), "wt"); + + std::string request = ""; + for (unsigned int n = 0; n < keys.size(); n++) { + if (n > 0) request += "&"; + request += keys[n] + "=" + values[n]; + } + cout << request << endl; + /* get a curl handle */ + curl = curl_easy_init(); + if (curl) { + /* First set the URL that is about to receive our POST. This URL can + just as well be a https:// URL if that is what should receive the + data. */ + curl_easy_setopt(curl, CURLOPT_URL, "https://henke.lbl.gov/cgi-bin/laymir.pl"); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)f); + /* Now specify the POST data */ + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request.c_str()); + + /* Perform the request, res will get the return code */ + res = curl_easy_perform(curl); + /* Check for errors */ + if (res != CURLE_OK) ferr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << endl; + + /* always cleanup */ + curl_easy_cleanup(curl); + } + fclose(f); + curl_global_cleanup(); + + std::getline(std::ifstream(filename), file_content, '\0'); + + return 0; +} + /////////////////////////////////////////////// /// Upload the local file to remote file, method url will overwrite the login information /// inside remotefile. @@ -815,32 +872,30 @@ int TRestTools::UploadToServer(string filelocal, string remotefile, string metho return 0; } -void TRestTools::ChangeDirectory( string toDirectory ) { - - char originDirectory[256]; - sprintf(originDirectory, "%s", getenv("PWD")); - chdir(toDirectory.c_str()); +void TRestTools::ChangeDirectory(string toDirectory) { + char originDirectory[256]; + sprintf(originDirectory, "%s", getenv("PWD")); + chdir(toDirectory.c_str()); - string fullPath = ""; - if( toDirectory[0] == '/' ) - fullPath = toDirectory; - else - fullPath = (string) originDirectory + "/" + toDirectory; + string fullPath = ""; + if (toDirectory[0] == '/') + fullPath = toDirectory; + else + fullPath = (string)originDirectory + "/" + toDirectory; - setenv ( "PWD", fullPath.c_str(), 1 ); - setenv ( "OLDPWD", originDirectory, 1 ); + setenv("PWD", fullPath.c_str(), 1); + setenv("OLDPWD", originDirectory, 1); } -void TRestTools::ReturnToPreviousDirectory( ) { - - char originDirectory[256]; - sprintf(originDirectory, "%s", getenv("PWD")); +void TRestTools::ReturnToPreviousDirectory() { + char originDirectory[256]; + sprintf(originDirectory, "%s", getenv("PWD")); - char newDirectory[256]; - sprintf(newDirectory, "%s", getenv("OLDPWD")); + char newDirectory[256]; + sprintf(newDirectory, "%s", getenv("OLDPWD")); - setenv ( "PWD", newDirectory, 1 ); - setenv ( "OLDPWD", originDirectory, 1 ); + setenv("PWD", newDirectory, 1); + setenv("OLDPWD", originDirectory, 1); - chdir( newDirectory ); + chdir(newDirectory); } From 10651a50dd625b83ab47170f96d8c00323624cb2 Mon Sep 17 00:00:00 2001 From: jgalan Date: Thu, 31 Mar 2022 01:32:05 +0200 Subject: [PATCH 02/12] CMakeLists.txt now links to -lcurl --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 956b88d35..b122d96f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,7 +75,7 @@ find_package(ROOT REQUIRED COMPONENTS ${ROOT_REQUIRED_LIBRARIES}) message(STATUS "ROOT LIBRARIES: ${ROOT_LIBRARIES}") -set(external_libs "${external_libs};${ROOT_LIBRARIES}") +set(external_libs "${external_libs};${ROOT_LIBRARIES};-lcurl") set(ROOTCINT_EXECUTABLE ${ROOT_rootcint_CMD}) From 433477d8352a0a24e432c9765f29711eb93f39a4 Mon Sep 17 00:00:00 2001 From: Luis Obis <35803280+lobis@users.noreply.github.com> Date: Thu, 31 Mar 2022 09:39:20 +0200 Subject: [PATCH 03/12] .gitlab-ci.yml - updated docker image to fixed tag for pipeline that can be externally updated --- .gitlab-ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 045ea92ed..6b159fcfd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,4 @@ -image: ghcr.io/lobis/root-geant4-garfield:cpp17_ROOT-v6-26-00_Geant4-v10.4.3_Garfield-af4a1451 -#image: nkx1231/root6-geant4-garfield:0.6 +image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics variables: # GIT_SUBMODULE_STRATEGY: recursive From 9215f32a4c4e27922d8013a8a2465f3964cb252e Mon Sep 17 00:00:00 2001 From: jgalan Date: Thu, 31 Mar 2022 11:54:57 +0200 Subject: [PATCH 04/12] TRestTools::POSTRequest simplified --- source/framework/tools/inc/TRestTools.h | 3 +-- source/framework/tools/src/TRestTools.cxx | 20 ++++++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/source/framework/tools/inc/TRestTools.h b/source/framework/tools/inc/TRestTools.h index ee7f971b3..2cbcf602b 100644 --- a/source/framework/tools/inc/TRestTools.h +++ b/source/framework/tools/inc/TRestTools.h @@ -90,8 +90,7 @@ class TRestTools { static std::string DownloadRemoteFile(std::string remoteFile); static int DownloadRemoteFile(std::string remoteFile, std::string localFile); static int UploadToServer(std::string localfile, std::string remotefile, std::string methodurl = ""); - static int POSTRequest(std::string& file_content, std::vector keys, - std::vector values); + static std::string POSTRequest(const std::map& keys); static void ChangeDirectory(string toDirectory); static void ReturnToPreviousDirectory(); diff --git a/source/framework/tools/src/TRestTools.cxx b/source/framework/tools/src/TRestTools.cxx index 9e10f6eab..afe0b548e 100644 --- a/source/framework/tools/src/TRestTools.cxx +++ b/source/framework/tools/src/TRestTools.cxx @@ -776,15 +776,9 @@ int TRestTools::DownloadRemoteFile(string remoteFile, string localFile) { /////////////////////////////////////////////// /// \brief It performs a POST web protocol request using a set of keys and values given -/// by argument, and places the result inside `content`. +/// by argument, and returns the result as a string. /// -int TRestTools::POSTRequest(std::string& file_content, std::vector keys, - std::vector values) { - if (keys.size() != values.size()) { - ferr << "The number of keys and values does not match!" << endl; - return 1; - } - +std::string TRestTools::POSTRequest(const std::map& keys) { CURL* curl; CURLcode res; @@ -796,11 +790,12 @@ int TRestTools::POSTRequest(std::string& file_content, std::vector FILE* f = fopen(filename.c_str(), "wt"); std::string request = ""; - for (unsigned int n = 0; n < keys.size(); n++) { + int n = 0; + for (auto const& [key, val] : symbolTable) { if (n > 0) request += "&"; - request += keys[n] + "=" + values[n]; + request += key + "=" + val; + n++; } - cout << request << endl; /* get a curl handle */ curl = curl_easy_init(); if (curl) { @@ -823,9 +818,10 @@ int TRestTools::POSTRequest(std::string& file_content, std::vector fclose(f); curl_global_cleanup(); + std::string file_content = ""; std::getline(std::ifstream(filename), file_content, '\0'); - return 0; + return file_content; } /////////////////////////////////////////////// From cd42ce4160c6628d159d9716f1efdc76d6de4fc0 Mon Sep 17 00:00:00 2001 From: jgalan Date: Thu, 31 Mar 2022 13:34:49 +0200 Subject: [PATCH 05/12] TRestTools::POSTRequest adding url and making it c++14 compatible --- source/framework/tools/inc/TRestTools.h | 2 +- source/framework/tools/src/TRestTools.cxx | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/framework/tools/inc/TRestTools.h b/source/framework/tools/inc/TRestTools.h index 2cbcf602b..a04565daa 100644 --- a/source/framework/tools/inc/TRestTools.h +++ b/source/framework/tools/inc/TRestTools.h @@ -90,7 +90,7 @@ class TRestTools { static std::string DownloadRemoteFile(std::string remoteFile); static int DownloadRemoteFile(std::string remoteFile, std::string localFile); static int UploadToServer(std::string localfile, std::string remotefile, std::string methodurl = ""); - static std::string POSTRequest(const std::map& keys); + static std::string POSTRequest(const std::string& url, const std::map& keys); static void ChangeDirectory(string toDirectory); static void ReturnToPreviousDirectory(); diff --git a/source/framework/tools/src/TRestTools.cxx b/source/framework/tools/src/TRestTools.cxx index afe0b548e..64c43e6f7 100644 --- a/source/framework/tools/src/TRestTools.cxx +++ b/source/framework/tools/src/TRestTools.cxx @@ -778,7 +778,7 @@ int TRestTools::DownloadRemoteFile(string remoteFile, string localFile) { /// \brief It performs a POST web protocol request using a set of keys and values given /// by argument, and returns the result as a string. /// -std::string TRestTools::POSTRequest(const std::map& keys) { +std::string TRestTools::POSTRequest(const std::string& url, const std::map& keys) { CURL* curl; CURLcode res; @@ -791,9 +791,9 @@ std::string TRestTools::POSTRequest(const std::map& ke std::string request = ""; int n = 0; - for (auto const& [key, val] : symbolTable) { + for (auto const& x : keys) { if (n > 0) request += "&"; - request += key + "=" + val; + request += x.first + "=" + x.second; n++; } /* get a curl handle */ @@ -802,7 +802,7 @@ std::string TRestTools::POSTRequest(const std::map& ke /* First set the URL that is about to receive our POST. This URL can just as well be a https:// URL if that is what should receive the data. */ - curl_easy_setopt(curl, CURLOPT_URL, "https://henke.lbl.gov/cgi-bin/laymir.pl"); + curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)f); /* Now specify the POST data */ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request.c_str()); From 6f7e3f807bc7c24807566495121505dab2056356 Mon Sep 17 00:00:00 2001 From: jgalan Date: Fri, 1 Apr 2022 07:34:50 +0200 Subject: [PATCH 06/12] TRestTools::ReadASCIITable added an argument to skip header lines --- source/framework/tools/inc/TRestTools.h | 4 ++-- source/framework/tools/src/TRestTools.cxx | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/source/framework/tools/inc/TRestTools.h b/source/framework/tools/inc/TRestTools.h index c71ffd40a..125ab8e7b 100644 --- a/source/framework/tools/inc/TRestTools.h +++ b/source/framework/tools/inc/TRestTools.h @@ -50,8 +50,8 @@ class TRestTools { static void LoadRESTLibrary(bool silent = false); - static int ReadASCIITable(string fName, std::vector>& data); - static int ReadASCIITable(string fName, std::vector>& data); + static int ReadASCIITable(string fName, std::vector>& data, Int_t skipLines = 0); + static int ReadASCIITable(string fName, std::vector>& data, Int_t skipLines = 0); template static int ReadBinaryTable(string fName, std::vector>& data, Int_t columns); diff --git a/source/framework/tools/src/TRestTools.cxx b/source/framework/tools/src/TRestTools.cxx index 4f49376c9..f82836686 100644 --- a/source/framework/tools/src/TRestTools.cxx +++ b/source/framework/tools/src/TRestTools.cxx @@ -261,7 +261,7 @@ template Double_t TRestTools::GetLowestIncreaseFromTable(std::vector>& data) { +int TRestTools::ReadASCIITable(string fName, std::vector>& data, Int_t skipLines) { if (!TRestTools::isValidFile((string)fName)) { cout << "TRestTools::ReadASCIITable. Error" << endl; cout << "Cannot open file : " << fName << endl; @@ -276,6 +276,11 @@ int TRestTools::ReadASCIITable(string fName, std::vector>& std::vector> values; for (string line; std::getline(fin, line);) { + if (skipLines > 0) { + skipLines--; + continue + } + if (line.find("#") == string::npos) { std::istringstream in(line); values.push_back( @@ -307,7 +312,7 @@ int TRestTools::ReadASCIITable(string fName, std::vector>& /// /// This version works with Float_t vector since we use StringToFloat method. /// -int TRestTools::ReadASCIITable(string fName, std::vector>& data) { +int TRestTools::ReadASCIITable(string fName, std::vector>& data, Int_t skipLines) { if (!TRestTools::isValidFile((string)fName)) { cout << "TRestTools::ReadASCIITable. Error" << endl; cout << "Cannot open file : " << fName << endl; @@ -322,6 +327,11 @@ int TRestTools::ReadASCIITable(string fName, std::vector>& std::vector> values; for (string line; std::getline(fin, line);) { + if (skipLines > 0) { + skipLines--; + continue + } + if (line.find("#") == string::npos) { std::istringstream in(line); values.push_back( From c7b7dd5300dcb1ba7ac323fb4931c67054401dc7 Mon Sep 17 00:00:00 2001 From: jgalan Date: Fri, 1 Apr 2022 07:45:33 +0200 Subject: [PATCH 07/12] TRestTools. Fixing compilation error --- source/framework/tools/src/TRestTools.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/framework/tools/src/TRestTools.cxx b/source/framework/tools/src/TRestTools.cxx index b11a65225..48e67456d 100644 --- a/source/framework/tools/src/TRestTools.cxx +++ b/source/framework/tools/src/TRestTools.cxx @@ -280,7 +280,7 @@ int TRestTools::ReadASCIITable(string fName, std::vector>& for (string line; std::getline(fin, line);) { if (skipLines > 0) { skipLines--; - continue + continue; } if (line.find("#") == string::npos) { @@ -331,7 +331,7 @@ int TRestTools::ReadASCIITable(string fName, std::vector>& for (string line; std::getline(fin, line);) { if (skipLines > 0) { skipLines--; - continue + continue; } if (line.find("#") == string::npos) { From 407dd8a15f0cfe6975b41dc729c0f1dc64419584 Mon Sep 17 00:00:00 2001 From: jgalan Date: Fri, 1 Apr 2022 12:33:18 +0200 Subject: [PATCH 08/12] TRestMetadata::GetSearchPath. User path has been added to the default list --- source/framework/core/src/TRestMetadata.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/framework/core/src/TRestMetadata.cxx b/source/framework/core/src/TRestMetadata.cxx index 3e48ed19f..e721c1ece 100644 --- a/source/framework/core/src/TRestMetadata.cxx +++ b/source/framework/core/src/TRestMetadata.cxx @@ -2216,6 +2216,8 @@ TString TRestMetadata::GetSearchPath() { if (getenv("configPath")) result += getenv("configPath") + (string) ":"; result += REST_PATH + "/data/:"; + // We give priority to the official /data/ path. + result += REST_USER_PATH + ":"; if (result.back() == ':') result.erase(result.size() - 1); return ReplaceConstants(ReplaceVariables(result)); From 0f5c998639d9a134c7dfcdeccf5f886e41c7ac02 Mon Sep 17 00:00:00 2001 From: jgalan Date: Fri, 1 Apr 2022 12:36:28 +0200 Subject: [PATCH 09/12] TRestTools::ExportASCIITable method added --- source/framework/tools/inc/TRestTools.h | 3 ++ source/framework/tools/src/TRestTools.cxx | 46 +++++++++++++++++++---- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/source/framework/tools/inc/TRestTools.h b/source/framework/tools/inc/TRestTools.h index e2e35c19c..bde8d5a5d 100644 --- a/source/framework/tools/inc/TRestTools.h +++ b/source/framework/tools/inc/TRestTools.h @@ -68,6 +68,9 @@ class TRestTools { template static int PrintTable(std::vector> data, Int_t start = 0, Int_t end = 0); + template + static int ExportASCIITable(std::string fname, std::vector> data); + static Int_t isValidFile(const string& path); static bool fileExists(const std::string& filename); static bool isRootFile(const std::string& filename); diff --git a/source/framework/tools/src/TRestTools.cxx b/source/framework/tools/src/TRestTools.cxx index 48e67456d..9d752b854 100644 --- a/source/framework/tools/src/TRestTools.cxx +++ b/source/framework/tools/src/TRestTools.cxx @@ -127,6 +127,34 @@ template int TRestTools::PrintTable(std::vector> d template int TRestTools::PrintTable(std::vector> data, Int_t start, Int_t end); +/////////////////////////////////////////////// +/// \brief Writes the contents of the vector table given as argument to `fname`. +/// Allowed types are Int_t, Float_t and Double_t. +/// +template +int TRestTools::ExportASCIITable(std::string fname, std::vector> data) { + ofstream file(fname); + if (!file.is_open()) { + ferr << "Unable to open file for writting : " << fname << endl; + return 1; + } + + for (int n = 0; n < data.size(); n++) + for (int m = 0; m < data[n].size(); m++) { + file << data[n][m]; + if (m + 1 < data[n].size()) file << "\t"; + if (m + 1 == data[n].size()) file << "\n"; + } + file.close(); + + return 0; +} + +template int TRestTools::ExportASCIITable(std::string fname, std::vector> data); +template int TRestTools::ExportASCIITable(std::string fname, std::vector> data); +template int TRestTools::ExportASCIITable(std::string fname, + std::vector> data); + /////////////////////////////////////////////// /// \brief Reads a binary file containning a fixed-columns table with values /// @@ -180,7 +208,8 @@ template int TRestTools::ReadBinaryTable(string fName, std::vector(std::vector(std::vector T TRestTools::GetLowestIncreaseFromTable(std::vector> data, Int_t column) { @@ -839,8 +869,8 @@ std::string TRestTools::POSTRequest(const std::string& url, const std::map Date: Fri, 1 Apr 2022 15:13:48 +0200 Subject: [PATCH 10/12] TRestTools::DownloadRemoteFile. Retrying few attempts in case of issues with connection --- source/framework/tools/src/TRestTools.cxx | 25 +++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/source/framework/tools/src/TRestTools.cxx b/source/framework/tools/src/TRestTools.cxx index 9d752b854..399207b7a 100644 --- a/source/framework/tools/src/TRestTools.cxx +++ b/source/framework/tools/src/TRestTools.cxx @@ -740,7 +740,8 @@ std::istream& TRestTools::GetLine(std::istream& is, std::string& t) { /// /// The file name is given in url format, and is parsed by TUrl. Various methods /// will be used, including scp, wget. Downloads to REST_USER_PATH + "/download/" + filename -/// by default +/// by default. +/// std::string TRestTools::DownloadRemoteFile(string url) { string purename = TRestTools::GetPureFileName(url); if (purename == "") { @@ -754,8 +755,18 @@ std::string TRestTools::DownloadRemoteFile(string url) { return Replace(url, "local:", ""); } else { string fullpath = REST_USER_PATH + "/download/" + purename; + int out; + int attempts = 10; + do { + out = TRestTools::DownloadRemoteFile(url, fullpath); + if (out == 1024) { + warning << "Retrying download in 5 seconds" << endl; + sleep(5); + } + attempts--; + } while (out == 1024 && attempts > 0); - if (TRestTools::DownloadRemoteFile(url, fullpath) == 0) { + if (out == 0) { return fullpath; } else if (TRestTools::fileExists(fullpath)) { return fullpath; @@ -795,8 +806,14 @@ int TRestTools::DownloadRemoteFile(string remoteFile, string localFile) { return 0; } else { ferr << "download failed! (" << remoteFile << ")" << endl; - if (a == 1024) ferr << "Network connection problem?" << endl; - if (a == 2048) ferr << "File does NOT exist in remotely?" << endl; + if (a == 1024) { + ferr << "Network connection problem?" << endl; + return 1024; + } + if (a == 2048) { + ferr << "File does NOT exist in remotely?" << endl; + return 2048; + } } } else if ((string)url.GetProtocol() == "ssh") { string cmd = "scp -P " + ToString(url.GetPort() == 0 ? 22 : url.GetPort()) + " " + url.GetUser() + From c7e6e4d48b0b5165e076077fa0914cc9783bc602 Mon Sep 17 00:00:00 2001 From: jgalan Date: Fri, 1 Apr 2022 17:36:27 +0200 Subject: [PATCH 11/12] TRestTools::ExportASCIITable table by reference --- source/framework/tools/inc/TRestTools.h | 2 +- source/framework/tools/src/TRestTools.cxx | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source/framework/tools/inc/TRestTools.h b/source/framework/tools/inc/TRestTools.h index bde8d5a5d..c1065b17e 100644 --- a/source/framework/tools/inc/TRestTools.h +++ b/source/framework/tools/inc/TRestTools.h @@ -69,7 +69,7 @@ class TRestTools { static int PrintTable(std::vector> data, Int_t start = 0, Int_t end = 0); template - static int ExportASCIITable(std::string fname, std::vector> data); + static int ExportASCIITable(std::string fname, std::vector>& data); static Int_t isValidFile(const string& path); static bool fileExists(const std::string& filename); diff --git a/source/framework/tools/src/TRestTools.cxx b/source/framework/tools/src/TRestTools.cxx index 399207b7a..a51ae43a8 100644 --- a/source/framework/tools/src/TRestTools.cxx +++ b/source/framework/tools/src/TRestTools.cxx @@ -132,7 +132,7 @@ template int TRestTools::PrintTable(std::vector> /// Allowed types are Int_t, Float_t and Double_t. /// template -int TRestTools::ExportASCIITable(std::string fname, std::vector> data) { +int TRestTools::ExportASCIITable(std::string fname, std::vector>& data) { ofstream file(fname); if (!file.is_open()) { ferr << "Unable to open file for writting : " << fname << endl; @@ -150,10 +150,11 @@ int TRestTools::ExportASCIITable(std::string fname, std::vector> return 0; } -template int TRestTools::ExportASCIITable(std::string fname, std::vector> data); -template int TRestTools::ExportASCIITable(std::string fname, std::vector> data); +template int TRestTools::ExportASCIITable(std::string fname, std::vector>& data); +template int TRestTools::ExportASCIITable(std::string fname, + std::vector>& data); template int TRestTools::ExportASCIITable(std::string fname, - std::vector> data); + std::vector>& data); /////////////////////////////////////////////// /// \brief Reads a binary file containning a fixed-columns table with values From 5f53737227266232813bd451e667b8c10bda9963 Mon Sep 17 00:00:00 2001 From: jgalan Date: Fri, 1 Apr 2022 17:42:05 +0200 Subject: [PATCH 12/12] TRestTools::DownloadRemoteFile replacing sleep function --- source/framework/tools/src/TRestTools.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/framework/tools/src/TRestTools.cxx b/source/framework/tools/src/TRestTools.cxx index a51ae43a8..270c002c3 100644 --- a/source/framework/tools/src/TRestTools.cxx +++ b/source/framework/tools/src/TRestTools.cxx @@ -45,9 +45,11 @@ #include +#include #include #include #include +#include #include "TClass.h" #include "TRestStringHelper.h" @@ -762,7 +764,7 @@ std::string TRestTools::DownloadRemoteFile(string url) { out = TRestTools::DownloadRemoteFile(url, fullpath); if (out == 1024) { warning << "Retrying download in 5 seconds" << endl; - sleep(5); + std::this_thread::sleep_for(std::chrono::seconds(5)); } attempts--; } while (out == 1024 && attempts > 0);