Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: SetDefaultParameter no longer puts duplicate copies in vector #257

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/libraries/JANA/Services/JParameterManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ JParameter* JParameterManager::SetDefaultParameter(std::string name, T& val, std
std::lock_guard<std::mutex> 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
Expand Down Expand Up @@ -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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should fix the bug, but I think it misses the root cause, which is that the vector version of Parse() is appending to t without clearing it first.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might run into other bugs with Parse<std::string, std::vector<T> val>() down the road if we don't clear val

param->SetIsUsed(true);
return param;
}
Expand Down
1 change: 1 addition & 0 deletions src/programs/tests/JParameterManagerTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ TEST_CASE("JParameterManager_VectorParams") {
std::vector<std::string> 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
nathanwbrei marked this conversation as resolved.
Show resolved Hide resolved
}
SECTION("Reading a vector of ints") {
jpm.SetParameter("test", "1,2, 3 ");
Expand Down