Commit 78ca36c3 authored by Mathieu Tillet's avatar Mathieu Tillet
Browse files

Check for property before adding it

When loading metadata, check if a property is already present before
trying to add it, so that the loading can carry on with a simple warning
instead of failing altogether.
parent d230da7d
......@@ -19,8 +19,14 @@
#include <boost/algorithm/string/predicate.hpp> //assert(boost::algorithm::ends_with("mystring", "ing"));
namespace Mantid::DataHandling {
namespace Mantid {
namespace {
/// static logger
Kernel::Logger g_log("LoadHelper");
} // namespace
namespace DataHandling {
using namespace Kernel;
using namespace API;
......@@ -241,7 +247,12 @@ void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &ru
else
runDetails.addProperty(property_name, property_value);
} else {
runDetails.addProperty(property_name, property_value);
if (!runDetails.hasProperty(property_name)) {
runDetails.addProperty(property_name, property_value);
} else {
g_log.warning() << "Property " << property_name
<< " was set twice. Please check the Nexus file and your inputs." << std::endl;
}
}
} else if ((type == NX_FLOAT32) || (type == NX_FLOAT64) || (type == NX_INT16) || (type == NX_INT32) ||
......@@ -266,10 +277,16 @@ void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &ru
} else if (type == NX_FLOAT64) {
property_double_value = *(reinterpret_cast<double *>(dataBuffer));
}
if (units_status != NX_ERROR)
runDetails.addProperty(property_name, property_double_value, std::string(units_sbuf));
else
runDetails.addProperty(property_name, property_double_value);
if (!runDetails.hasProperty(property_name)) {
if (units_status != NX_ERROR)
runDetails.addProperty(property_name, property_double_value, std::string(units_sbuf));
else
runDetails.addProperty(property_name, property_double_value);
} else {
g_log.warning() << "Property " << property_name
<< " was set twice. Please check the Nexus file and your inputs." << std::endl;
}
} else if (build_small_float_array) {
// An array, converted to "name_index", with index < 10
// (see
......@@ -282,10 +299,18 @@ void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &ru
}
std::string indexed_property_name =
property_name + std::string("_") + std::to_string(dim_index);
if (units_status != NX_ERROR)
runDetails.addProperty(indexed_property_name, property_double_value, std::string(units_sbuf));
else
runDetails.addProperty(indexed_property_name, property_double_value);
if (!runDetails.hasProperty(property_name)) {
if (units_status != NX_ERROR)
runDetails.addProperty(indexed_property_name, property_double_value,
std::string(units_sbuf));
else
runDetails.addProperty(indexed_property_name, property_double_value);
} else {
g_log.warning()
<< "Property " << property_name
<< " was set twice. Please check the Nexus file and your inputs." << std::endl;
}
}
}
......@@ -300,10 +325,15 @@ void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &ru
property_int_value = *(reinterpret_cast<short unsigned int *>(dataBuffer));
}
if (units_status != NX_ERROR)
runDetails.addProperty(property_name, property_int_value, std::string(units_sbuf));
else
runDetails.addProperty(property_name, property_int_value);
if (!runDetails.hasProperty(property_name)) {
if (units_status != NX_ERROR)
runDetails.addProperty(property_name, property_int_value, std::string(units_sbuf));
else
runDetails.addProperty(property_name, property_int_value);
} else {
g_log.warning() << "Property " << property_name
<< " was set twice. Please check the Nexus file and your inputs." << std::endl;
}
} // if (type==...
}
......@@ -469,4 +499,5 @@ V3D LoadHelper::getComponentPosition(const API::MatrixWorkspace_sptr &ws, const
return pos;
}
} // namespace Mantid::DataHandling
} // namespace DataHandling
} // namespace Mantid
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment