From 962e0f956f4c3f43bb978322077d919227fe340a Mon Sep 17 00:00:00 2001 From: lobis Date: Fri, 29 Jul 2022 21:15:55 +0200 Subject: [PATCH 1/3] Updated TRestMetadata::GetFieldValue to allow for default value --- source/framework/core/inc/TRestMetadata.h | 3 ++- source/framework/core/src/TRestMetadata.cxx | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/source/framework/core/inc/TRestMetadata.h b/source/framework/core/inc/TRestMetadata.h index e1e1910ef..8d841d8ef 100644 --- a/source/framework/core/inc/TRestMetadata.h +++ b/source/framework/core/inc/TRestMetadata.h @@ -91,7 +91,8 @@ class TRestMetadata : public TNamed { protected: // new xml utilities - std::string GetFieldValue(std::string parName, TiXmlElement* e); + std::string GetFieldValue(std::string parName, TiXmlElement* e, + std::string defaultValue = "Not defined") const; std::string GetParameter(std::string parName, TiXmlElement* e, TString defaultValue = PARAMETER_NOT_FOUND_STR); Double_t GetDblParameterWithUnits(std::string parName, TiXmlElement* e, diff --git a/source/framework/core/src/TRestMetadata.cxx b/source/framework/core/src/TRestMetadata.cxx index f847d0f43..6f0743147 100644 --- a/source/framework/core/src/TRestMetadata.cxx +++ b/source/framework/core/src/TRestMetadata.cxx @@ -1548,14 +1548,14 @@ TVector3 TRestMetadata::Get3DVectorParameterWithUnits(std::string parName, TiXml /// A version of GetParameter() but only find parameter in the fields of xml /// element. If not found, the returned string is "Not defined" /// -std::string TRestMetadata::GetFieldValue(std::string parName, TiXmlElement* e) { +string TRestMetadata::GetFieldValue(string parName, TiXmlElement* e, string defaultValue) { if (e == nullptr) { RESTDebug << "Element is null" << RESTendl; - return "Not defined"; + return defaultValue; } const char* val = e->Attribute(parName.c_str()); if (val == nullptr) { - return "Not defined"; + return defaultValue; } string result = (string)val; From f372ab4eed2a2599b0132b0988f7a427e78dbd6f Mon Sep 17 00:00:00 2001 From: lobis Date: Fri, 29 Jul 2022 21:24:47 +0200 Subject: [PATCH 2/3] TRestStringHelper::StringToBool - now also returns the result of `std::to_string(true)` (1) as `true` --- source/framework/tools/inc/TRestStringHelper.h | 2 +- source/framework/tools/src/TRestStringHelper.cxx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/framework/tools/inc/TRestStringHelper.h b/source/framework/tools/inc/TRestStringHelper.h index 81eeecd48..91e98d86e 100644 --- a/source/framework/tools/inc/TRestStringHelper.h +++ b/source/framework/tools/inc/TRestStringHelper.h @@ -36,7 +36,7 @@ Double_t StringToDouble(std::string in); Int_t StringToInteger(std::string in); std::string IntegerToString(Int_t n, std::string format = "%d"); std::string DoubleToString(Double_t d, std::string format = "%4.2lf"); -Bool_t StringToBool(std::string in); +Bool_t StringToBool(const std::string& in); Long64_t StringToLong(std::string in); TVector3 StringTo3DVector(std::string in); TVector2 StringTo2DVector(std::string in); diff --git a/source/framework/tools/src/TRestStringHelper.cxx b/source/framework/tools/src/TRestStringHelper.cxx index 52c878af6..8c734acb5 100644 --- a/source/framework/tools/src/TRestStringHelper.cxx +++ b/source/framework/tools/src/TRestStringHelper.cxx @@ -625,8 +625,8 @@ string REST_StringHelper::IntegerToString(Int_t n, std::string format) { return /// string REST_StringHelper::DoubleToString(Double_t d, std::string format) { return Form(format.c_str(), d); } -Bool_t REST_StringHelper::StringToBool(std::string in) { - return (ToUpper(in) == "TRUE" || ToUpper(in) == "ON"); +Bool_t REST_StringHelper::StringToBool(const std::string& in) { + return (ToUpper(in) == "TRUE" || ToUpper(in) == "ON" || ToUpper(in) == "1"); } Long64_t REST_StringHelper::StringToLong(std::string in) { From 38fae37543d266533a2c88109bc7a1a4174ff17c Mon Sep 17 00:00:00 2001 From: lobis Date: Fri, 29 Jul 2022 21:35:50 +0200 Subject: [PATCH 3/3] TRestMetadata - fixed bad const --- source/framework/core/inc/TRestMetadata.h | 4 ++-- source/framework/core/src/TRestMetadata.cxx | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/source/framework/core/inc/TRestMetadata.h b/source/framework/core/inc/TRestMetadata.h index 8d841d8ef..59d5cf19e 100644 --- a/source/framework/core/inc/TRestMetadata.h +++ b/source/framework/core/inc/TRestMetadata.h @@ -91,8 +91,8 @@ class TRestMetadata : public TNamed { protected: // new xml utilities - std::string GetFieldValue(std::string parName, TiXmlElement* e, - std::string defaultValue = "Not defined") const; + std::string GetFieldValue(const std::string& parName, const TiXmlElement* e, + const std::string& defaultValue = "Not defined") const; std::string GetParameter(std::string parName, TiXmlElement* e, TString defaultValue = PARAMETER_NOT_FOUND_STR); Double_t GetDblParameterWithUnits(std::string parName, TiXmlElement* e, diff --git a/source/framework/core/src/TRestMetadata.cxx b/source/framework/core/src/TRestMetadata.cxx index 6f0743147..fd7b50dcd 100644 --- a/source/framework/core/src/TRestMetadata.cxx +++ b/source/framework/core/src/TRestMetadata.cxx @@ -1548,7 +1548,8 @@ TVector3 TRestMetadata::Get3DVectorParameterWithUnits(std::string parName, TiXml /// A version of GetParameter() but only find parameter in the fields of xml /// element. If not found, the returned string is "Not defined" /// -string TRestMetadata::GetFieldValue(string parName, TiXmlElement* e, string defaultValue) { +string TRestMetadata::GetFieldValue(const string& parName, const TiXmlElement* e, + const string& defaultValue) const { if (e == nullptr) { RESTDebug << "Element is null" << RESTendl; return defaultValue;