From 4343376c4ccce012b3f27075cb75c1afb7139cca Mon Sep 17 00:00:00 2001 From: Ian Bush <bush@ill.fr> Date: Thu, 2 Nov 2017 17:16:54 +0100 Subject: [PATCH] Refs #20881 Load raw or calibrated data --- .../MantidDataHandling/LoadILLDiffraction.h | 2 ++ .../DataHandling/src/LoadILLDiffraction.cpp | 28 ++++++++++++++++++- .../test/LoadILLDiffractionTest.h | 24 ++++++++-------- Framework/Kernel/src/NexusDescriptor.cpp | 7 +++-- Testing/Data/UnitTest/ILL/D20/000017.nxs.md5 | 2 +- 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/Framework/DataHandling/inc/MantidDataHandling/LoadILLDiffraction.h b/Framework/DataHandling/inc/MantidDataHandling/LoadILLDiffraction.h index e1a0c84ccb1..7719a39d79f 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/LoadILLDiffraction.h +++ b/Framework/DataHandling/inc/MantidDataHandling/LoadILLDiffraction.h @@ -64,6 +64,7 @@ private: }; void init() override; + std::map<std::string, std::string> validateInputs() override; void exec() override; std::vector<Types::Core::DateAndTime> @@ -72,6 +73,7 @@ private: std::vector<double> getDurations(const NeXus::NXDouble &) const; std::vector<double> getMonitor(const NeXus::NXDouble &) const; std::string getInstrumentFilePath(const std::string &) const; + bool containsCalibratedData(const std::string &filename) const; void fillDataScanMetaData(const NeXus::NXDouble &); std::vector<double> diff --git a/Framework/DataHandling/src/LoadILLDiffraction.cpp b/Framework/DataHandling/src/LoadILLDiffraction.cpp index 8176e63740f..df1ac556b1f 100644 --- a/Framework/DataHandling/src/LoadILLDiffraction.cpp +++ b/Framework/DataHandling/src/LoadILLDiffraction.cpp @@ -100,6 +100,16 @@ void LoadILLDiffraction::init() { "Type of data, with or without calibration already applied."); } +std::map<std::string, std::string> LoadILLDiffraction::validateInputs() { + std::map<std::string, std::string> issues; + if (getPropertyValue("DataType") == "Calibrated" && + !containsCalibratedData(getPropertyValue("Filename"))) { + issues["DataType"] = "Calibrated data requested, but only raw data exists " + "in this NeXus file."; + } + return issues; +} + /** * Executes the algorithm. */ @@ -138,7 +148,8 @@ void LoadILLDiffraction::loadDataScan() { // read the detector data std::string dataName; - if (getPropertyValue("DataType") == "Calibrated") + if (getPropertyValue("DataType") == "Calibrated" || + !containsCalibratedData(m_fileName)) dataName = "data_scan/detector_data/data"; else dataName = "data_scan/detector_data/raw_data"; @@ -710,5 +721,20 @@ LoadILLDiffraction::getInstrumentFilePath(const std::string &instName) const { return fullPath.toString(); } +/** + * Returns true if the file contains calibrated data + * + * @param filename The filename to check + * @return True if the file contains calibrated data, false otherwise + */ +bool LoadILLDiffraction::containsCalibratedData( + const std::string &filename) const { + NexusDescriptor descriptor(filename); + // This is unintuitive, but if the file has calibrated data there are entries + // for 'data' and 'raw_data'. If there is no calibrated data only 'data' is + // present. + return descriptor.pathExists("/entry0/data_scan/detector_data/raw_data"); +} + } // namespace DataHandling } // namespace Mantid diff --git a/Framework/DataHandling/test/LoadILLDiffractionTest.h b/Framework/DataHandling/test/LoadILLDiffractionTest.h index 5bed2ede23d..6f1315be53c 100644 --- a/Framework/DataHandling/test/LoadILLDiffractionTest.h +++ b/Framework/DataHandling/test/LoadILLDiffractionTest.h @@ -78,13 +78,13 @@ public: TS_ASSERT_EQUALS(outputWS->y(3072)[0], 0.) TS_ASSERT_EQUALS(outputWS->e(3072)[0], 0.) - TS_ASSERT(outputWS->run().hasProperty("simulated_d20")) - TS_ASSERT(outputWS->run().hasProperty("AcquisitionSpy")) - TS_ASSERT(outputWS->run().hasProperty("SampleSettings")) + TS_ASSERT(outputWS->run().hasProperty("simulated_d20.TotalCount")) + TS_ASSERT(outputWS->run().hasProperty("AcquisitionSpy.Time")) + TS_ASSERT(outputWS->run().hasProperty("SampleSettings.SampleTemp")) - const auto sim = outputWS->run().getLogData("simulated_d20"); - const auto spy = outputWS->run().getLogData("AcquisitionSpy"); - const auto sample = outputWS->run().getLogData("SampleSettings"); + const auto sim = outputWS->run().getLogData("simulated_d20.TotalCount"); + const auto spy = outputWS->run().getLogData("AcquisitionSpy.Time"); + const auto sample = outputWS->run().getLogData("SampleSettings.SampleTemp"); TS_ASSERT_EQUALS(sim->size(), 1) TS_ASSERT_EQUALS(spy->size(), 1) @@ -131,13 +131,13 @@ public: } } - TS_ASSERT(outputWS->run().hasProperty("Omega")) - TS_ASSERT(outputWS->run().hasProperty("Detector")) - TS_ASSERT(outputWS->run().hasProperty("AcquisitionSpy")) - TS_ASSERT(outputWS->run().hasProperty("SampleSettings")) - TS_ASSERT(outputWS->run().hasProperty("MagneticField")) + TS_ASSERT(outputWS->run().hasProperty("Omega.Position")) + TS_ASSERT(outputWS->run().hasProperty("Detector.TotalCount")) + TS_ASSERT(outputWS->run().hasProperty("AcquisitionSpy.Time")) + TS_ASSERT(outputWS->run().hasProperty("SampleSettings.SampleTemp")) + TS_ASSERT(outputWS->run().hasProperty("MagneticField.field")) - const auto omega = outputWS->run().getLogData("Omega"); + const auto omega = outputWS->run().getLogData("Omega.Position"); TS_ASSERT_EQUALS(omega->size(), 21) diff --git a/Framework/Kernel/src/NexusDescriptor.cpp b/Framework/Kernel/src/NexusDescriptor.cpp index a2e41cb63ce..4602b60679d 100644 --- a/Framework/Kernel/src/NexusDescriptor.cpp +++ b/Framework/Kernel/src/NexusDescriptor.cpp @@ -125,9 +125,10 @@ NexusDescriptor::NexusDescriptor(const std::string &filename) } try { initialize(filename); - } catch (::NeXus::Exception &) { - throw std::invalid_argument("NexusDescriptor::initialize - File '" + - filename + "' does not look like a HDF file."); + } catch (::NeXus::Exception &e) { + throw std::invalid_argument( + "NexusDescriptor::initialize - File '" + filename + + "' does not look like a HDF file.\n Error was: " + e.what()); } } diff --git a/Testing/Data/UnitTest/ILL/D20/000017.nxs.md5 b/Testing/Data/UnitTest/ILL/D20/000017.nxs.md5 index 128f8c9be8b..1c3a6f8128e 100644 --- a/Testing/Data/UnitTest/ILL/D20/000017.nxs.md5 +++ b/Testing/Data/UnitTest/ILL/D20/000017.nxs.md5 @@ -1 +1 @@ -65d8027268f1cf53eb20ef076fbb3655 +cc3a75118e65e22546c52629cf4812fd -- GitLab