Skip to content
Snippets Groups Projects
Commit 97d07ecc authored by Raquel Alvarez Banos's avatar Raquel Alvarez Banos
Browse files

Re #14010 Make ParameterEstimator thread safe

parent d996b9a7
No related merge requests found
......@@ -7,6 +7,8 @@
#include "MantidKernel/Logger.h"
#include <Poco/Timer.h>
#include <cmath>
namespace Mantid {
......@@ -18,20 +20,42 @@ using namespace Functions;
/// The logger.
Kernel::Logger g_log("ParameterEstimator");
/// Mutex to prevent simultaneous access to functionMap
static Poco::Mutex mutex;
enum Function { None, Gaussian, Lorentzian, BackToBackExponential };
typedef std::map<std::string, std::pair<size_t, Function>> FunctionMapType;
//----------------------------------------------------------------------------------------------
/// Initializes a FunctionMapType object
/// @param functionMapType :: the function map to initialize
void initFunctionLookup(FunctionMapType &functionMapType) {
assert(functionMapType.empty());
functionMapType["Gaussian"] = std::make_pair(2, Gaussian);
functionMapType["Lorentzian"] = std::make_pair(2, Lorentzian);
functionMapType["BackToBackExponential"] =
std::make_pair(4, BackToBackExponential);
}
/// Returns a reference to the static functionMapType
/// @returns :: a const reference to the functionMapType
const FunctionMapType &getFunctionMapType() {
Poco::Mutex::ScopedLock lock(mutex);
static FunctionMapType functionMapType;
if (functionMapType.empty())
initFunctionLookup(functionMapType);
return functionMapType;
}
/// Return a function code for a function if it needs setting values or None
/// otherwise.
Function whichFunction(const API::IFunction &function) {
static FunctionMapType functionMap;
if (functionMap.empty()) {
functionMap["Gaussian"] = std::make_pair(2, Gaussian);
functionMap["Lorentzian"] = std::make_pair(2, Lorentzian);
functionMap["BackToBackExponential"] =
std::make_pair(4, BackToBackExponential);
}
const FunctionMapType &functionMap = getFunctionMapType();
auto index = functionMap.find(function.name());
if (index != functionMap.end()) {
if (!function.isExplicitlySet(index->second.first))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment