From f68012fed63a80deeb765f1e8176a28d7ba1ee15 Mon Sep 17 00:00:00 2001 From: AyanRoy16 Date: Fri, 20 Oct 2023 13:06:31 -0400 Subject: [PATCH 1/4] Removing duplicate copying into input vector in SetDefaultParameter --- src/libraries/JANA/Services/JParameterManager.h | 5 +++-- src/programs/tests/JParameterManagerTests.cc | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libraries/JANA/Services/JParameterManager.h b/src/libraries/JANA/Services/JParameterManager.h index 70255898d..bca7e6684 100644 --- a/src/libraries/JANA/Services/JParameterManager.h +++ b/src/libraries/JANA/Services/JParameterManager.h @@ -237,6 +237,7 @@ JParameter* JParameterManager::SetDefaultParameter(std::string name, T& val, std std::lock_guard lock(m_mutex); JParameter* param = nullptr; T t; + T t1; auto result = m_parameters.find(ToLower(name)); if (result != m_parameters.end()) { // We already have a value stored for this parameter @@ -284,8 +285,8 @@ JParameter* JParameterManager::SetDefaultParameter(std::string name, T& val, std // Always put val through the stringification/parsing cycle to be consistent with // values passed in from config file, accesses from other threads - Parse(param->GetValue(),t); - val = t; + Parse(param->GetValue(),t1); + val = t1; param->SetIsUsed(true); return param; } diff --git a/src/programs/tests/JParameterManagerTests.cc b/src/programs/tests/JParameterManagerTests.cc index b509d6eda..a8e5e23ff 100644 --- a/src/programs/tests/JParameterManagerTests.cc +++ b/src/programs/tests/JParameterManagerTests.cc @@ -192,9 +192,11 @@ TEST_CASE("JParameterManager_VectorParams") { inputs.emplace_back(" third one "); jpm.SetDefaultParameter("test", inputs); + std::cout << " Size of the vector after calling the SetDefaultParameter" << inputs.size() << std::endl; std::vector outputs; auto param = jpm.GetParameter("test", outputs); REQUIRE(param->GetValue() == "first,second one, third one "); + REQUIRE(inputs.size()==3); // an additional test to see that the size of the input vector remains the same: Issue #256 } SECTION("Reading a vector of ints") { jpm.SetParameter("test", "1,2, 3 "); From db8a0e3f75df802d0504d95edd4db4d50f10c78c Mon Sep 17 00:00:00 2001 From: AyanRoy16 Date: Fri, 20 Oct 2023 13:09:07 -0400 Subject: [PATCH 2/4] Removing a debug comment --- src/programs/tests/JParameterManagerTests.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/programs/tests/JParameterManagerTests.cc b/src/programs/tests/JParameterManagerTests.cc index a8e5e23ff..89c3c8ea0 100644 --- a/src/programs/tests/JParameterManagerTests.cc +++ b/src/programs/tests/JParameterManagerTests.cc @@ -192,7 +192,6 @@ TEST_CASE("JParameterManager_VectorParams") { inputs.emplace_back(" third one "); jpm.SetDefaultParameter("test", inputs); - std::cout << " Size of the vector after calling the SetDefaultParameter" << inputs.size() << std::endl; std::vector outputs; auto param = jpm.GetParameter("test", outputs); REQUIRE(param->GetValue() == "first,second one, third one "); From 7ab399846a3b0ef4813284fad8e523986f87d402 Mon Sep 17 00:00:00 2001 From: AyanRoy16 Date: Fri, 20 Oct 2023 13:45:01 -0400 Subject: [PATCH 3/4] Clearning the vector input before copying in vector specialization for Parse --- src/libraries/JANA/Services/JParameterManager.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libraries/JANA/Services/JParameterManager.h b/src/libraries/JANA/Services/JParameterManager.h index bca7e6684..16f3c1980 100644 --- a/src/libraries/JANA/Services/JParameterManager.h +++ b/src/libraries/JANA/Services/JParameterManager.h @@ -285,8 +285,8 @@ JParameter* JParameterManager::SetDefaultParameter(std::string name, T& val, std // Always put val through the stringification/parsing cycle to be consistent with // values passed in from config file, accesses from other threads - Parse(param->GetValue(),t1); - val = t1; + Parse(param->GetValue(),t); + val = t; param->SetIsUsed(true); return param; } @@ -367,6 +367,7 @@ template inline void JParameterManager::Parse(const std::string& value, std::vector &val) { std::stringstream ss(value); std::string s; + val.clear(); // clearing the input vector to make remove dulication which can be caused due to val.push_back(t); while (getline(ss, s, ',')) { T t; Parse(s, t); From 571dc36b63398207700542beec3805d667ab8e0e Mon Sep 17 00:00:00 2001 From: AyanRoy16 Date: Fri, 20 Oct 2023 13:48:33 -0400 Subject: [PATCH 4/4] Removing an unnecessary variable and fixing a comment --- src/libraries/JANA/Services/JParameterManager.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libraries/JANA/Services/JParameterManager.h b/src/libraries/JANA/Services/JParameterManager.h index 16f3c1980..291407974 100644 --- a/src/libraries/JANA/Services/JParameterManager.h +++ b/src/libraries/JANA/Services/JParameterManager.h @@ -237,7 +237,6 @@ JParameter* JParameterManager::SetDefaultParameter(std::string name, T& val, std std::lock_guard lock(m_mutex); JParameter* param = nullptr; T t; - T t1; auto result = m_parameters.find(ToLower(name)); if (result != m_parameters.end()) { // We already have a value stored for this parameter @@ -367,7 +366,7 @@ template inline void JParameterManager::Parse(const std::string& value, std::vector &val) { std::stringstream ss(value); std::string s; - val.clear(); // clearing the input vector to make remove dulication which can be caused due to val.push_back(t); + val.clear(); // clearing the input vector to ensure no dulication which can be caused due to val.push_back(t); while (getline(ss, s, ',')) { T t; Parse(s, t);