Commit 43a7ec91 authored by Nick Draper's avatar Nick Draper
Browse files

LoadNexusLogs now loads the validity data

Adds warning to log for any invalid data.
Nothing is stored yet.
Includes a basic unit test using an editted file
parent c640291c
......@@ -195,6 +195,47 @@ std::unique_ptr<Kernel::Property> createTimeSeries(::NeXus::File &file,
std::transform(time_double.begin(), time_double.end(), time_double.begin(),
std::bind(std::multiplies<double>(), _1, 60.0));
}
// Now the the validity of the values
// this should be a match int array to the data values (or times)
// If not present assume all data is valid
try {
file.openData("value_valid");
// Now the validity data
::NeXus::Info info = file.getInfo();
// Check the size
if (size_t(info.dims[0]) != time_double.size()) {
throw ::NeXus::Exception("Invalid value entry for validity data");
}
if (file.isDataInt()) // Int type
{
std::vector<int> values;
try {
file.getDataCoerce(values);
for (auto validity : values) {
if (validity != 0) {
log.warning() << "Some \"" << propName
<< "\" log data is invalid!\n";
break;
}
}
} catch (::NeXus::Exception &) {
throw;
}
} else {
throw ::NeXus::Exception(
"Invalid value type for validity data. Only int is supported");
}
} catch (::NeXus::Exception &ex) {
std::string error_msg = ex.what();
if (error_msg != "NXopendata(value_valid) failed") {
log.warning() << error_msg << "\n";
file.closeData();
}
}
// Now the values: Could be a string, int or double
file.openData("value");
// Get the units of the property
......
......@@ -292,6 +292,17 @@ public:
TS_ASSERT_EQUALS(endTime.totalNanoseconds(), lastTime.totalNanoseconds());
}
void test_load_file_with_invalid_log_entries() {
LoadNexusLogs ld;
ld.initialize();
ld.setPropertyValue("Filename", "ENGINX00228061_log_alarm_data.nxs");
MatrixWorkspace_sptr ws = createTestWorkspace();
// Put it in the object.
ld.setProperty("Workspace", ws);
ld.execute();
TS_ASSERT(ld.isExecuted());
}
private:
API::MatrixWorkspace_sptr createTestWorkspace() {
return WorkspaceFactory::Instance().create("Workspace2D", 1, 1, 1);
......
Supports Markdown
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