From 1326bc1bca07d18d6f2ccfc1940ae2eb3a062818 Mon Sep 17 00:00:00 2001
From: Riccardo Maria Bianchi <riccardo.maria.bianchi@cern.ch>
Date: Thu, 6 Jun 2024 02:12:26 +0200
Subject: [PATCH] move to global helpers

---
 .../GeoModelCppHelpers/GMCppHelpers.h         | 10 ++++-----
 .../GeoModelRead/GeoModelRead/ReadGeoModel.h  |  5 ++---
 GeoModelIO/GeoModelRead/src/ReadGeoModel.cpp  | 21 ++++++++++---------
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/GeoModelIO/GeoModelCppHelpers/GeoModelCppHelpers/GMCppHelpers.h b/GeoModelIO/GeoModelCppHelpers/GeoModelCppHelpers/GMCppHelpers.h
index f928076a2..e5bd75521 100644
--- a/GeoModelIO/GeoModelCppHelpers/GeoModelCppHelpers/GMCppHelpers.h
+++ b/GeoModelIO/GeoModelCppHelpers/GeoModelCppHelpers/GMCppHelpers.h
@@ -72,11 +72,11 @@ 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 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)
         // {
diff --git a/GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.h b/GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.h
index b1cf2ffe9..e1476035d 100644
--- a/GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.h
+++ b/GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.h
@@ -351,10 +351,9 @@ class ReadGeoModel {
     GeoSerialTransformer* getBuiltSerialTransformer(const unsigned int id);
 
     // Utility functions
-    std::string getEnvVar(std::string const& key) const;
-    std::vector<std::string> splitString(const std::string& s, char delimiter);
+    std::vector<std::string> splitString(const std::string& s, char delimiter); // TODO: move to global helpers
     void printStdVectorStrings(
-        std::vector<std::string> vec);  // TODO: move it to utility class
+        std::vector<std::string> vec);  // TODO: move it to utility class or move to global helpers
 
     // void printTransformationValues(QStringList t); // TODO: move to a Qt
     // utility class QList<double> convertQstringListToDouble(QStringList
diff --git a/GeoModelIO/GeoModelRead/src/ReadGeoModel.cpp b/GeoModelIO/GeoModelRead/src/ReadGeoModel.cpp
index e846708aa..26ce1de48 100644
--- a/GeoModelIO/GeoModelRead/src/ReadGeoModel.cpp
+++ b/GeoModelIO/GeoModelRead/src/ReadGeoModel.cpp
@@ -87,6 +87,7 @@
 
 #include "GeoModelHelpers/variantHelpers.h"
 #include "GeoModelHelpers/throwExcept.h"
+#include "GeoModelHelpers/StringUtils.h"
 
 // Units
 #include "GeoModelKernel/Units.h"
@@ -145,21 +146,21 @@ ReadGeoModel::ReadGeoModel(GMDBManager* db, unsigned long* progress)
       m_runMultithreaded_nThreads(0),
       m_progress(nullptr) {
     // Check if the user asked for debug messages
-    if ("" != getEnvVar("GEOMODEL_ENV_IO_LOGLEVEL_1")) {
+    if ("" != GeoStrUtils::getEnvVar("GEOMODEL_ENV_IO_LOGLEVEL_1")) {
         m_loglevel = 1;
         std::cout << "You defined the GEOMODEL_ENV_IO_DEBUG variable, so you "
                      "will see a verbose output."
                   << std::endl;
     }
     // Check if the user asked for verbose debug messages
-    if ("" != getEnvVar("GEOMODEL_ENV_IO_LOGLEVEL_2")) {
+    if ("" != GeoStrUtils::getEnvVar("GEOMODEL_ENV_IO_LOGLEVEL_2")) {
         m_loglevel = 2;
         std::cout << "You defined the GEOMODEL_ENV_IO_READ_DEBUG_VERBOSE "
                      "variable, so you will see a verbose output."
                   << std::endl;
     }
     // Check if the user asked for timing output
-    if ("" != getEnvVar("GEOMODEL_ENV_IO_READ_TIMING")) {
+    if ("" != GeoStrUtils::getEnvVar("GEOMODEL_ENV_IO_READ_TIMING")) {
         m_timing = true;
         std::cout << "You defined the GEOMODEL_ENV_IO_READ_TIMING variable, so "
                      "you will see a timing measurement in the output."
@@ -186,8 +187,8 @@ ReadGeoModel::ReadGeoModel(GMDBManager* db, unsigned long* progress)
     // m_builderShape_Box = std::make_unique<BuildGeoShapes_Box>();
 
     // Check if the user asked for running in serial or multi-threading mode
-    if ("" != getEnvVar("GEOMODEL_ENV_IO_NTHREADS")) {
-        int nThreads = std::stoi(getEnvVar("GEOMODEL_ENV_IO_NTHREADS"));
+    if ("" != GeoStrUtils::getEnvVar("GEOMODEL_ENV_IO_NTHREADS")) {
+        int nThreads = std::stoi(GeoStrUtils::getEnvVar("GEOMODEL_ENV_IO_NTHREADS"));
         if (nThreads == 0) {
             std::cout << "Info: You set the GEOMODEL_ENV_IO_NTHREADS to '"
                       << nThreads
@@ -248,11 +249,11 @@ ReadGeoModel::~ReadGeoModel() {
     m_builderShape_UnidentifiedShape = nullptr;
 }
 
-// FIXME: TODO: move to an utility class
-std::string ReadGeoModel::getEnvVar(std::string const& key) const {
-    char* val = std::getenv(key.c_str());
-    return val == NULL ? std::string("") : std::string(val);
-}
+// // FIXME: TODO: move to an utility class
+// std::string ReadGeoModel::getEnvVar(std::string const& key) const {
+//     char* val = std::getenv(key.c_str());
+//     return val == NULL ? std::string("") : std::string(val);
+// }
 
 const GeoVPhysVol* ReadGeoModel::buildGeoModel() {
     if (m_loglevel >= 2)
-- 
GitLab