diff --git a/source/framework/core/inc/TRestMetadata.h b/source/framework/core/inc/TRestMetadata.h index e1e1910ef..59d5cf19e 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(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 f847d0f43..fd7b50dcd 100644 --- a/source/framework/core/src/TRestMetadata.cxx +++ b/source/framework/core/src/TRestMetadata.cxx @@ -1548,14 +1548,15 @@ 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(const string& parName, const TiXmlElement* e, + const string& defaultValue) const { 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; 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) {