Skip to content
Snippets Groups Projects
Commit 24a2a910 authored by Riccardo Maria Bianchi's avatar Riccardo Maria Bianchi :sunny: Committed by Johannes Junggeburth
Browse files

Move helpers to the Core pacakge

parent 6d1ac09a
No related branches found
No related tags found
1 merge request!327New schema for the GeoModel SQLite database and updated I/O
......@@ -63,6 +63,10 @@ namespace GeoStrUtils{
template <class ObjType> std::string chainUp(const std::vector<ObjType>& vector,
const std::string_view glue =";");
/// Function to set the precision of the conversion from double to string
std::string to_string_with_precision(const double a_value, const unsigned n = 16);
void printStdVectorStrings(const std::vector<std::string> vec);
}
#include "GeoModelHelpers/StringUtils.icc"
#endif
\ No newline at end of file
......@@ -143,4 +143,22 @@ namespace GeoStrUtils {
convertToNumber(str, result);
return result;
}
std::string to_string_with_precision(const double a_value, const unsigned n)
{
std::ostringstream out;
out.precision(n);
out << std::fixed << a_value;
return out.str();
}
void printStdVectorStrings(const std::vector<std::string> vec)
{
for (const auto &str : vec)
{
std::cout << str << " ";
}
std::cout << std::endl;
return;
}
}
......@@ -8,11 +8,6 @@
#include <stdlib.h>
using namespace GeoStrUtils;
// namespace {
// std::string getEnvVar(const std::string& varName){
// return std::getenv(varName.c_str()) ? std::string{std::getenv(varName.c_str())} : std::string{};
// }
// }
int main() {
if (resolveEnviromentVariables("${PWD}") != getEnvVar("PWD")) {
......
......
......@@ -31,26 +31,6 @@ namespace GeoModelIO {
// dummy constructor
CppHelper(){};
// Function to increase the precision of the conversion from double to string -
// used in the write operation
static std::string to_string_with_precision(const double a_value, const int n = 16)
{
std::ostringstream out;
out.precision(n);
out << std::fixed << a_value;
return out.str();
}
static void printStdVectorStrings(std::vector<std::string> vec)
{
for (const auto &str : vec)
{
std::cout << str << " ";
}
std::cout << std::endl;
return;
}
// FIXME: should go to an utility class
static std::string joinVectorStrings(std::vector<std::string> vec,
std::string sep = "")
......@@ -72,103 +52,6 @@ namespace GeoModelIO {
return s;
}
// static std::string getEnvVar(std::string const &key)
// {
// char *val = std::getenv(key.c_str());
// return val == NULL ? std::string("") : std::string(val);
// }
// static void printStdVectorVariants(const std::vector<std::variant<int, long, float, double, std::string>> vec)
// {
// for (const auto &item : vec)
// {
// if (std::holds_alternative<int>(item))
// std::cout << std::get<int>(item); // INT
// else if (std::holds_alternative<long>(item))
// std::cout << std::get<long>(item);
// else if (std::holds_alternative<float>(item))
// std::cout << std::get<float>(item);
// else if (std::holds_alternative<double>(item))
// std::cout << std::get<double>(item);
// else if (std::holds_alternative<std::string>(item))
// std::cout << std::get<std::string>(item);
// std::cout << ", ";
// }
// std::cout << std::endl;
// }
// static std::string getFromVariant_String(const std::variant<int, long, float, double, std::string> &record, std::string_view logMsg = "")
// {
// std::string_view type{"string"};
// std::string ret;
// try
// {
// ret = std::get<std::string>(record);
// }
// catch (std::bad_variant_access const &ex)
// {
// std::cout << ex.what() << ": '" << logMsg << "' is not a 'string'!\n";
// }
// return ret;
// }
// static int getFromVariant_Int(const std::variant<int, long, float, double, std::string> &record, std::string_view logMsg = "")
// {
// std::string_view type{"int"};
// int ret;
// try
// {
// ret = std::get<int>(record);
// }
// catch (std::bad_variant_access const &ex)
// {
// std::cout << ex.what() << ": '" << logMsg << "' is not a '" << type << "'!\n";
// }
// return ret;
// }
// static int getFromVariant_Double(const std::variant<int, long, float, double, std::string> &record, std::string_view logMsg = "")
// {
// std::string_view type{"double"};
// double ret;
// try
// {
// ret = std::get<double>(record);
// }
// catch (std::bad_variant_access const &ex)
// {
// std::cout << ex.what() << ": '" << logMsg << "' is not a '" << type << "'!\n";
// }
// return ret;
// }
// static std::string getFromVariant_Type(const std::variant<int, long, float, double, std::string> &record)
// {
// std::string type;
// if (std::holds_alternative<int>(record))
// {
// type = "int";
// }
// else if (std::holds_alternative<long>(record))
// {
// type = "long";
// }
// else if (std::holds_alternative<float>(record))
// {
// type = "float";
// }
// else if (std::holds_alternative<double>(record))
// {
// type = "double";
// }
// else if (std::holds_alternative<std::string>(record))
// {
// type = "string";
// } else {
// type = "UNKOWN";
// }
// std::cout << "Variant is of type '" << type << "'" << std::endl;
// return type;
// }
};
} // namespace GeoModelIO
......
......
/*
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/
/*
......@@ -10,6 +10,9 @@
* AlignableTransform nodes
* - Jun 2022 - Riccardo Maria Bianchi, <riccardo.maria.bianchi@cern.ch>,
* Added support for "Verbose" output
* - May 2024 - Riccardo Maria Bianchi, <riccardo.maria.bianchi@cern.ch>,
* Major change: moving to a new DB schema where we use REAL values
* for numeric data instead of TEXT.
*/
#ifndef GMDBManager_H
......
......
......@@ -655,7 +655,7 @@ std::vector<double> GMDBManager::getTableFromTableName_VectorDouble(std::string
{
try
{
// std::cout << "variant data: " << GeoModelIO::CppHelper::to_string_with_precision(std::get<double>(rec)) << '\n';
// std::cout << "variant data: " << GeoStrUtils::to_string_with_precision(std::get<double>(rec)) << '\n';
outRecords.push_back(std::get<double>(rec));
}
catch (std::bad_variant_access const &ex)
......@@ -881,9 +881,9 @@ bool GMDBManager::addListOfRecordsToTable(
else if (std::holds_alternative<long>(item))
items.push_back(std::to_string(std::get<long>(item))); // INT
else if (std::holds_alternative<float>(item))
items.push_back(GeoModelIO::CppHelper::to_string_with_precision(std::get<float>(item)));
items.push_back(GeoStrUtils::to_string_with_precision(std::get<float>(item)));
else if (std::holds_alternative<double>(item))
items.push_back(GeoModelIO::CppHelper::to_string_with_precision(std::get<double>(item)));
items.push_back(GeoStrUtils::to_string_with_precision(std::get<double>(item)));
else if (std::holds_alternative<std::string>(item)) {
std::string str = std::get<std::string>(item);
// NOTE: if item is a "NULL" string, we don't encapsulate it
......@@ -958,9 +958,9 @@ bool GMDBManager::addRecordsToTable(
else if (std::holds_alternative<long>(item))
items.push_back(std::to_string(std::get<long>(item))); // INT
else if (std::holds_alternative<float>(item))
items.push_back(GeoModelIO::CppHelper::to_string_with_precision(std::get<float>(item)));
items.push_back(GeoStrUtils::to_string_with_precision(std::get<float>(item)));
else if (std::holds_alternative<double>(item))
items.push_back(GeoModelIO::CppHelper::to_string_with_precision(std::get<double>(item)));
items.push_back(GeoStrUtils::to_string_with_precision(std::get<double>(item)));
else if (std::holds_alternative<std::string>(item))
{
std::string str = std::get<std::string>(item);
......
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment