Skip to content
Snippets Groups Projects
Commit 49b93c1b authored by Matthew D Jones's avatar Matthew D Jones
Browse files

Re #14178 Made Owen's suggested changes

parent d09c500a
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,17 @@ ...@@ -10,6 +10,17 @@
#include "MantidKernel/PropertyWithValue.h" #include "MantidKernel/PropertyWithValue.h"
#include <string> #include <string>
namespace {
static const std::string intTypeOption = "Int";
static const std::string doubleTypeOption = "Double";
static const std::string autoTypeOption = "AutoDetect";
static const std::string stringLogOption = "String";
static const std::string numberLogOption = "Number";
static const std::string numberSeriesLogOption = "Number Series";
}
namespace Mantid { namespace Mantid {
namespace Algorithms { namespace Algorithms {
...@@ -30,19 +41,19 @@ void AddSampleLog::init() { ...@@ -30,19 +41,19 @@ void AddSampleLog::init() {
declareProperty("LogText", "", "The content of the log"); declareProperty("LogText", "", "The content of the log");
std::vector<std::string> propOptions; std::vector<std::string> propOptions;
propOptions.push_back("String"); propOptions.push_back(stringLogOption);
propOptions.push_back("Number"); propOptions.push_back(numberLogOption);
propOptions.push_back("Number Series"); propOptions.push_back(numberSeriesLogOption);
declareProperty("LogType", "String", declareProperty("LogType", stringLogOption,
boost::make_shared<StringListValidator>(propOptions), boost::make_shared<StringListValidator>(propOptions),
"The type that the log data will be."); "The type that the log data will be.");
declareProperty("LogUnit", "", "The units of the log"); declareProperty("LogUnit", "", "The units of the log");
std::vector<std::string> typeOptions; std::vector<std::string> typeOptions;
typeOptions.push_back("Int"); typeOptions.push_back(intTypeOption);
typeOptions.push_back("Double"); typeOptions.push_back(doubleTypeOption);
typeOptions.push_back(""); typeOptions.push_back(autoTypeOption);
declareProperty("NumberType", "", declareProperty("NumberType", autoTypeOption,
boost::make_shared<StringListValidator>(typeOptions), boost::make_shared<StringListValidator>(typeOptions),
"Force LogText to be interpreted as a number of type 'int' " "Force LogText to be interpreted as a number of type 'int' "
"or 'double'."); "or 'double'.");
...@@ -62,10 +73,11 @@ void AddSampleLog::exec() { ...@@ -62,10 +73,11 @@ void AddSampleLog::exec() {
std::string propType = getPropertyValue("LogType"); std::string propType = getPropertyValue("LogType");
std::string propNumberType = getPropertyValue("NumberType"); std::string propNumberType = getPropertyValue("NumberType");
if (!propNumberType.empty() && if ((propNumberType != autoTypeOption) &&
((propType != "Number") && (propType != "Number Series"))) { ((propType != numberLogOption) && (propType != numberSeriesLogOption))) {
throw std::invalid_argument("You may only use NumberType property if " throw std::invalid_argument(
"LogType is 'Number' or 'Number Series'"); "You may only use NumberType 'Int' or 'Double' options if "
"LogType is 'Number' or 'Number Series'");
} }
// Remove any existing log // Remove any existing log
...@@ -73,7 +85,7 @@ void AddSampleLog::exec() { ...@@ -73,7 +85,7 @@ void AddSampleLog::exec() {
theRun.removeLogData(propName); theRun.removeLogData(propName);
} }
if (propType == "String") { if (propType == stringLogOption) {
theRun.addLogData(new PropertyWithValue<std::string>(propName, propValue)); theRun.addLogData(new PropertyWithValue<std::string>(propName, propValue));
theRun.getProperty(propName)->setUnits(propUnit); theRun.getProperty(propName)->setUnits(propUnit);
return; return;
...@@ -83,8 +95,8 @@ void AddSampleLog::exec() { ...@@ -83,8 +95,8 @@ void AddSampleLog::exec() {
double dblVal; double dblVal;
bool value_is_int = false; bool value_is_int = false;
if (!propNumberType.empty()) { if (propNumberType != autoTypeOption) {
value_is_int = (propNumberType == "Int"); value_is_int = (propNumberType == intTypeOption);
if (value_is_int) { if (value_is_int) {
if (!Strings::convert(propValue, intVal)) { if (!Strings::convert(propValue, intVal)) {
throw std::invalid_argument("Error interpreting string '" + propValue + throw std::invalid_argument("Error interpreting string '" + propValue +
...@@ -103,12 +115,12 @@ void AddSampleLog::exec() { ...@@ -103,12 +115,12 @@ void AddSampleLog::exec() {
} }
} }
if (propType == "Number") { if (propType == numberLogOption) {
if (value_is_int) if (value_is_int)
theRun.addLogData(new PropertyWithValue<int>(propName, intVal)); theRun.addLogData(new PropertyWithValue<int>(propName, intVal));
else else
theRun.addLogData(new PropertyWithValue<double>(propName, dblVal)); theRun.addLogData(new PropertyWithValue<double>(propName, dblVal));
} else if (propType == "Number Series") { } else if (propType == numberSeriesLogOption) {
Kernel::DateAndTime startTime; Kernel::DateAndTime startTime;
try { try {
startTime = theRun.startTime(); startTime = theRun.startTime();
......
...@@ -105,11 +105,11 @@ public: ...@@ -105,11 +105,11 @@ public:
} }
template <typename T> template <typename T>
void ExecuteAlgorithm(MatrixWorkspace_sptr testWS, std::string LogName, void
std::string LogType, std::string LogText, ExecuteAlgorithm(MatrixWorkspace_sptr testWS, std::string LogName,
T expectedValue, bool fails = false, std::string LogType, std::string LogText, T expectedValue,
std::string LogUnit = "", std::string NumberType = "", bool fails = false, std::string LogUnit = "",
bool throws = false) { std::string NumberType = "AutoDetect", bool throws = false) {
// add the workspace to the ADS // add the workspace to the ADS
AnalysisDataService::Instance().addOrReplace("AddSampleLogTest_Temporary", AnalysisDataService::Instance().addOrReplace("AddSampleLogTest_Temporary",
testWS); testWS);
......
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