From a180da2196d15369cdd5edfe1d0b627e08aa6240 Mon Sep 17 00:00:00 2001 From: jgalan Date: Fri, 15 Apr 2022 11:37:05 +0200 Subject: [PATCH 1/5] TRestMetadata::LoadConfigFromFile. Now it will try to find the RML on the default paths, if not found on the specified location --- 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 1f4253806..95163f482 100644 --- a/source/framework/core/src/TRestMetadata.cxx +++ b/source/framework/core/src/TRestMetadata.cxx @@ -525,6 +525,8 @@ TRestMetadata::~TRestMetadata() { /// Int_t TRestMetadata::LoadConfigFromFile(string cfgFileName, string sectionName) { fConfigFileName = cfgFileName; + if (!TRestTools::fileExists(fConfigFileName)) fConfigFileName = SearchFile(fConfigFileName); + if (TRestTools::fileExists(fConfigFileName)) { if (sectionName == "") { sectionName = this->ClassName(); From 74cf411afdfdefa21a5647d2afbac3b83039275e Mon Sep 17 00:00:00 2001 From: jgalan Date: Wed, 20 Apr 2022 21:45:20 +0200 Subject: [PATCH 2/5] TRestTools::GetFileNameRoot method added --- source/framework/tools/inc/TRestTools.h | 1 + source/framework/tools/src/TRestTools.cxx | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/source/framework/tools/inc/TRestTools.h b/source/framework/tools/inc/TRestTools.h index 7c80306af..c499e9ecf 100644 --- a/source/framework/tools/inc/TRestTools.h +++ b/source/framework/tools/inc/TRestTools.h @@ -59,6 +59,7 @@ class TRestTools { static Bool_t IsBinaryFile(std::string fname); static std::string GetFileNameExtension(std::string fullname); + static std::string GetFileNameRoot(std::string fullname); static int GetBinaryFileColumns(std::string fname); diff --git a/source/framework/tools/src/TRestTools.cxx b/source/framework/tools/src/TRestTools.cxx index c82fe1bd1..99519ccb2 100644 --- a/source/framework/tools/src/TRestTools.cxx +++ b/source/framework/tools/src/TRestTools.cxx @@ -268,8 +268,6 @@ Bool_t TRestTools::IsBinaryFile(string fname) { int TRestTools::GetBinaryFileColumns(string fname) { string extension = GetFileNameExtension(fname); if (extension.find("N") != 0) { - ferr << "Wrong filename extension." << endl; - ferr << "Cannot guess the number of columns" << endl; return -1; } @@ -606,6 +604,22 @@ string TRestTools::GetFileNameExtension(string fullname) { return fullname; } +/////////////////////////////////////////////// +/// \brief Gets the filename root as the substring found before the lastest "." +/// +/// Input: "/home/jgalan/abc.txt" Output: "abc" +/// +string TRestTools::GetFileNameRoot(string fullname) { + int pos1 = fullname.find_last_of('/', -1); + int pos2 = fullname.find_last_of('.', -1); + + if (pos1 != string::npos && pos2 != string::npos) return fullname.substr(pos1 + 1, pos2 - pos1 - 1); + + if (pos1 == string::npos && pos2 != string::npos) return fullname.substr(0, pos2); + + return fullname; +} + /////////////////////////////////////////////// /// \brief Returns the input string but without multiple slashes ("/") /// From 4b63ce820f6640abd492e6345fa46d7a7469e259 Mon Sep 17 00:00:00 2001 From: jgalan Date: Thu, 21 Apr 2022 12:09:54 +0200 Subject: [PATCH 3/5] TRestTools::TransposeTable method added --- source/framework/tools/inc/TRestTools.h | 3 +++ source/framework/tools/src/TRestTools.cxx | 24 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/source/framework/tools/inc/TRestTools.h b/source/framework/tools/inc/TRestTools.h index c499e9ecf..5eccac51a 100644 --- a/source/framework/tools/inc/TRestTools.h +++ b/source/framework/tools/inc/TRestTools.h @@ -53,6 +53,9 @@ class TRestTools { static int ReadASCIITable(std::string fName, std::vector>& data, Int_t skipLines = 0); + template + static void TransposeTable(std::vector>& data); + template static int ReadBinaryTable(std::string fName, std::vector>& data, Int_t columns = -1); diff --git a/source/framework/tools/src/TRestTools.cxx b/source/framework/tools/src/TRestTools.cxx index 99519ccb2..3fe1aac20 100644 --- a/source/framework/tools/src/TRestTools.cxx +++ b/source/framework/tools/src/TRestTools.cxx @@ -260,7 +260,7 @@ Bool_t TRestTools::IsBinaryFile(string fname) { /////////////////////////////////////////////// /// \brief It extracts the number of columns from the filename extension given by argument. -/// The file will containing a binary formatted table with a fixed number of rows and columns. +/// The file should contain a binary formatted table with a fixed number of rows and columns. /// /// The filename extension will be : ".Nxyzf", where the number of columns is `xyz`, and the /// last character is the type of data (f/d/i), float, double and integer respectively. @@ -290,6 +290,28 @@ int TRestTools::GetBinaryFileColumns(string fname) { return -1; } +/////////////////////////////////////////////// +/// \brief It transposes the std::vector table given in the argument. +/// It will transform rows in columns. +/// +template +void TRestTools::TransposeTable(std::vector>& data) { + if (data.size() == 0) return; + + std::vector> trans_vec(data[0].size(), std::vector()); + + for (int i = 0; i < data.size(); i++) + for (int j = 0; j < data[i].size(); j++) trans_vec[j].push_back(data[i][j]); + + data = trans_vec; +} + +template void TRestTools::TransposeTable(std::vector>& data); + +template void TRestTools::TransposeTable(std::vector>& data); + +template void TRestTools::TransposeTable(std::vector>& data); + /////////////////////////////////////////////// /// \brief It returns the maximum value for a particular `column` from the table given by /// argument. If no column is specified in the arguments, then it gets the maximum from the From 51a2b6cd29e841d17044d6d8d8ad451e64b23cc8 Mon Sep 17 00:00:00 2001 From: jgalan Date: Fri, 6 May 2022 07:48:56 +0200 Subject: [PATCH 4/5] TRestTools::GetIntegralFromTable method added --- source/framework/tools/inc/TRestTools.h | 3 +++ source/framework/tools/src/TRestTools.cxx | 25 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/source/framework/tools/inc/TRestTools.h b/source/framework/tools/inc/TRestTools.h index 5eccac51a..e6385b97f 100644 --- a/source/framework/tools/inc/TRestTools.h +++ b/source/framework/tools/inc/TRestTools.h @@ -75,6 +75,9 @@ class TRestTools { template static T GetLowestIncreaseFromTable(std::vector> data, Int_t column); + template + static T GetIntegralFromTable(const std::vector>& data); + template static int PrintTable(std::vector> data, Int_t start = 0, Int_t end = 0); diff --git a/source/framework/tools/src/TRestTools.cxx b/source/framework/tools/src/TRestTools.cxx index 3fe1aac20..4d7f23085 100644 --- a/source/framework/tools/src/TRestTools.cxx +++ b/source/framework/tools/src/TRestTools.cxx @@ -412,6 +412,31 @@ template Float_t TRestTools::GetLowestIncreaseFromTable(std::vector(std::vector> data, Int_t column); +/////////////////////////////////////////////// +/// \brief It returns the lowest increase, different from zero, between the elements of a +/// particular `column` from the table given by argument. +/// +/// This method is available for tables of type Float_t, Double_t and Int_t. +/// +/// \warning This method will not check every possible column element difference. It will only +/// look for consecutive elements steps. +/// +template +T TRestTools::GetIntegralFromTable(const std::vector>& data) { + if (data.size() == 0) return 0; + T sum = 0; + for (int n = 0; n < data.size(); n++) { + for (int m = 0; m < data[n].size(); m++) sum += data[n][m]; + } + return sum; +} + +template Int_t TRestTools::GetIntegralFromTable(const std::vector>& data); + +template Float_t TRestTools::GetIntegralFromTable(const std::vector>& data); + +template Double_t TRestTools::GetIntegralFromTable(const std::vector>& data); + /////////////////////////////////////////////// /// \brief Reads an ASCII file containing a table with values /// From 59eecc2072dc952a81bcd4a5e9fde3ac2719c1d3 Mon Sep 17 00:00:00 2001 From: Javier Galan Date: Fri, 6 May 2022 09:35:49 +0200 Subject: [PATCH 5/5] Update source/framework/tools/src/TRestTools.cxx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Juan Antonio GarcĂ­a <80903717+juanangp@users.noreply.github.com> --- 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 4d7f23085..3c88ef340 100644 --- a/source/framework/tools/src/TRestTools.cxx +++ b/source/framework/tools/src/TRestTools.cxx @@ -657,8 +657,8 @@ string TRestTools::GetFileNameExtension(string fullname) { /// Input: "/home/jgalan/abc.txt" Output: "abc" /// string TRestTools::GetFileNameRoot(string fullname) { - int pos1 = fullname.find_last_of('/', -1); - int pos2 = fullname.find_last_of('.', -1); + size_t pos1 = fullname.find_last_of('/', -1); + size_t pos2 = fullname.find_last_of('.', -1); if (pos1 != string::npos && pos2 != string::npos) return fullname.substr(pos1 + 1, pos2 - pos1 - 1);