From deebdcb79cf9b8b00858d0842c448c01eb8e4e79 Mon Sep 17 00:00:00 2001 From: Neil Vaytet <neil.vaytet@esss.se> Date: Thu, 1 Nov 2018 16:17:39 +0100 Subject: [PATCH] Refs #23755 : added test for Nexus instrument loading --- .../inc/MantidDataHandling/LoadGeometry.h | 28 ++--------- Framework/DataHandling/src/LoadInstrument.cpp | 1 - .../DataHandling/test/LoadInstrumentTest.h | 49 +++++++++++++++++++ 3 files changed, 52 insertions(+), 26 deletions(-) diff --git a/Framework/DataHandling/inc/MantidDataHandling/LoadGeometry.h b/Framework/DataHandling/inc/MantidDataHandling/LoadGeometry.h index e01e4d07e46..f85f517c4f6 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/LoadGeometry.h +++ b/Framework/DataHandling/inc/MantidDataHandling/LoadGeometry.h @@ -12,32 +12,10 @@ namespace Mantid { namespace DataHandling { /** -Loads an instrument definition file into a workspace, with the purpose of being -able to visualise an instrument without requiring to read in a ISIS raw datafile -first. -The name of the algorithm refers to the fact that an instrument -is loaded into a workspace but without any real data - hence the reason for -referring to -it as an 'empty' instrument. +Common methods for LoadInstrument.cpp and LoadEmptyInstrument.cpp -Required Properties: -<UL> -<LI> Filename - The name of an instrument definition file </LI> -<LI> OutputWorkspace - The name of the workspace in which to store the imported -instrument</LI> -</UL> - -Optional Properties: (note that these options are not available if reading a -multiperiod file) -<UL> -<LI> detector_value - This value affect the colour of the detectorss in the -instrument display window</LI> -<LI> monitor_value - This value affect the colour of the monitors in the -instrument display window</LI> -</UL> - -@author Anders Markvardsen, ISIS, RAL -@date 31/10/2008 +@author Neil Vaytet, ESS +@date 01/11/2018 */ namespace LoadGeometry { diff --git a/Framework/DataHandling/src/LoadInstrument.cpp b/Framework/DataHandling/src/LoadInstrument.cpp index 60dd2bf54bc..7e498333efe 100644 --- a/Framework/DataHandling/src/LoadInstrument.cpp +++ b/Framework/DataHandling/src/LoadInstrument.cpp @@ -28,7 +28,6 @@ #include <Poco/File.h> #include <Poco/Path.h> #include <fstream> -#include <iostream> #include <sstream> namespace Mantid { diff --git a/Framework/DataHandling/test/LoadInstrumentTest.h b/Framework/DataHandling/test/LoadInstrumentTest.h index fca50f95c64..9f694d8e9a8 100644 --- a/Framework/DataHandling/test/LoadInstrumentTest.h +++ b/Framework/DataHandling/test/LoadInstrumentTest.h @@ -16,6 +16,7 @@ #include "MantidDataHandling/LoadInstrument.h" #include "MantidDataObjects/Workspace2D.h" #include "MantidGeometry/Instrument.h" +#include "MantidGeometry/Instrument/ComponentInfo.h" #include "MantidGeometry/Instrument/DetectorInfo.h" #include "MantidGeometry/Instrument/FitParameter.h" #include "MantidHistogramData/LinearGenerator.h" @@ -293,6 +294,54 @@ public: AnalysisDataService::Instance().remove(wsName); } + void testExecLOKI() { + LoadInstrument loaderLOKI; + + TS_ASSERT_THROWS_NOTHING(loaderLOKI.initialize()); + + // // create a workspace with some sample data + wsName = "LoadInstrumentTestLOKI"; + Workspace_sptr ws = + WorkspaceFactory::Instance().create("Workspace2D", 1, 1, 1); + Workspace2D_sptr ws2D = boost::dynamic_pointer_cast<Workspace2D>(ws); + + // put this workspace in the data service + TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(wsName, ws2D)); + + const std::string definitionFile = "LOKI_Definition.hdf5"; + loaderLOKI.setPropertyValue("Filename", definitionFile); + loaderLOKI.setPropertyValue("Workspace", wsName); + loaderLOKI.setProperty("RewriteSpectraMap", OptionalBool(true)); + inputFile = loaderLOKI.getPropertyValue("Filename"); + + std::string result; + TS_ASSERT_THROWS_NOTHING(result = + loaderLOKI.getPropertyValue("Filename")); + TS_ASSERT(!result.compare(inputFile)); + + TS_ASSERT_THROWS_NOTHING(result = + loaderLOKI.getPropertyValue("Workspace")); + TS_ASSERT(!result.compare(wsName)); + + TS_ASSERT_THROWS_NOTHING(loaderLOKI.execute()); + + TS_ASSERT(loaderLOKI.isExecuted()); + + // Get back the saved workspace + MatrixWorkspace_sptr outputWs; + TS_ASSERT_THROWS_NOTHING( + outputWs = loaderLOKI.getProperty("Workspace")); + + auto &componentInfo = outputWs->componentInfo(); + auto &detectorInfo = outputWs->detectorInfo(); + TS_ASSERT_EQUALS(componentInfo.name(componentInfo.root()), "LOKI"); + TS_ASSERT_EQUALS(detectorInfo.size(), 8000); + + TS_ASSERT_EQUALS(0, detectorInfo.detectorIDs()[0]) + TS_ASSERT_EQUALS(1, detectorInfo.detectorIDs()[1]) + + } + void testExecHRP2() { // Test Parameter file in instrument folder is used by an IDF file not in // the instrument folder -- GitLab