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

Remove workspace history workaround from binaryOpertaions #38037

Merged
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -130,34 +130,13 @@ ResultType performBinaryOp(const LHSType lhs, const RHSType rhs, const std::stri
template <typename LHSType, typename ResultType>
ResultType performBinaryOpWithDouble(const LHSType inputWS, const double value, const std::string &op,
const std::string &name, bool inplace, bool reverse) {
// RAII struct to add/remove workspace from ADS
struct ScopedADSEntry {
ScopedADSEntry(const std::string &entryName, const MatrixWorkspace_sptr &value) : name(entryName) {
ads.addOrReplace(entryName, value);
}
~ScopedADSEntry() { ads.remove(name); }

const std::string &name;
API::AnalysisDataServiceImpl &ads = API::AnalysisDataService::Instance();
};

// In order to recreate a history record of the final binary operation
// there must be a record of the creation of the single value workspace used
// on the RHS here. This is achieved by running CreateSingleValuedWorkspace
// algorithm and adding the output workspace to the ADS. Adding the output
// to the ADS is critical so that workspace.name() is updated, by the ADS, to
// return the same string. WorkspaceProperty<TYPE>::createHistory() then
// records the correct workspace name for input into the final binary
// operation rather than creating a temporary name.

auto alg = API::AlgorithmManager::Instance().createUnmanaged("CreateSingleValuedWorkspace");
alg->setChild(false);
// we manually store the workspace as it's easier to retrieve the correct
// type from alg->getProperty rather than calling the ADS again and casting
alg->setAlwaysStoreInADS(false);
alg->initialize();
alg->setProperty<double>("DataValue", value);
const std::string tmpName("__python_binary_op_single_value");
alg->setPropertyValue("OutputWorkspace", tmpName);
alg->setPropertyValue("OutputWorkspace", "python_binary_op_single_value");
{ // instantiate releaseGIL in limited scope to allow for repeat in 'performBinaryOp'
ReleaseGlobalInterpreterLock releaseGIL;
alg->execute();
Expand All @@ -170,7 +149,6 @@ ResultType performBinaryOpWithDouble(const LHSType inputWS, const double value,
throw std::runtime_error("performBinaryOp: Error in execution of "
"CreateSingleValuedWorkspace");
}
ScopedADSEntry removeOnExit(tmpName, singleValue);
ResultType result =
performBinaryOp<LHSType, MatrixWorkspace_sptr, ResultType>(inputWS, singleValue, op, name, inplace, reverse);
return result;
Expand Down
Loading