diff --git a/Code/Mantid/Framework/DataHandling/CMakeLists.txt b/Code/Mantid/Framework/DataHandling/CMakeLists.txt index 1645bc73c319e49af2e2eddc4e7b3bebeb08ea9b..f5fd052bfe041b80ef1d13676f1ade6293aa1aab 100644 --- a/Code/Mantid/Framework/DataHandling/CMakeLists.txt +++ b/Code/Mantid/Framework/DataHandling/CMakeLists.txt @@ -96,6 +96,7 @@ set ( SRC_FILES src/LoadSpec.cpp src/LoadSpice2D.cpp src/LoadSpiceAscii.cpp + src/LoadSpiceXML2DDet.cpp src/LoadTOFRawNexus.cpp src/LoadVulcanCalFile.cpp src/MaskDetectors.cpp @@ -141,8 +142,8 @@ set ( SRC_FILES src/SaveReflCustomAscii.cpp src/SaveReflTBL.cpp src/SaveReflThreeColumnAscii.cpp - src/SaveSavuTomoConfig.cpp src/SaveSPE.cpp + src/SaveSavuTomoConfig.cpp src/SaveToSNSHistogramNexus.cpp src/SaveVTK.cpp src/SetSampleMaterial.cpp @@ -244,6 +245,7 @@ set ( INC_FILES inc/MantidDataHandling/LoadSpec.h inc/MantidDataHandling/LoadSpice2D.h inc/MantidDataHandling/LoadSpiceAscii.h + inc/MantidDataHandling/LoadSpiceXML2DDet.h inc/MantidDataHandling/LoadTOFRawNexus.h inc/MantidDataHandling/LoadVulcanCalFile.h inc/MantidDataHandling/MaskDetectors.h @@ -289,8 +291,8 @@ set ( INC_FILES inc/MantidDataHandling/SaveReflCustomAscii.h inc/MantidDataHandling/SaveReflTBL.h inc/MantidDataHandling/SaveReflThreeColumnAscii.h - inc/MantidDataHandling/SaveSavuTomoConfig.h inc/MantidDataHandling/SaveSPE.h + inc/MantidDataHandling/SaveSavuTomoConfig.h inc/MantidDataHandling/SaveToSNSHistogramNexus.h inc/MantidDataHandling/SaveVTK.h inc/MantidDataHandling/SetSampleMaterial.h @@ -384,9 +386,10 @@ set ( TEST_FILES LoadSPETest.h LoadSassenaTest.h LoadSaveAsciiTest.h - LoadSavuTomoConfigTest.h + LoadSavuTomoConfigTest.h LoadSpice2dTest.h LoadSpiceAsciiTest.h + LoadSpiceXML2DDetTest.h LoadTOFRawNexusTest.h LoadTest.h LoadVulcanCalFileTest.h @@ -432,8 +435,8 @@ set ( TEST_FILES SaveReflCustomAsciiTest.h SaveReflTBLTest.h SaveReflThreeColumnAsciiTest.h - SaveSavuTomoConfigTest.h SaveSPETest.h + SaveSavuTomoConfigTest.h SaveToSNSHistogramNexusTest.h SetSampleMaterialTest.h SetScalingPSDTest.h diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadSpiceXML2DDet.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadSpiceXML2DDet.h new file mode 100644 index 0000000000000000000000000000000000000000..55c6008f634440d8d72828309d62c76ba9352472 --- /dev/null +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadSpiceXML2DDet.h @@ -0,0 +1,60 @@ +#ifndef MANTID_DATAHANDLING_LOADSPICEXML2DDET_H_ +#define MANTID_DATAHANDLING_LOADSPICEXML2DDET_H_ + +#include "MantidKernel/System.h" +#include "MantidAPI/Algorithm.h" +#include "MantidAPI/MatrixWorkspace.h" + +namespace Mantid { +namespace DataHandling { + +/** LoadSpiceXML2DDet : Load 2D detector data in XML format form SPICE + + Copyright © 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge + National Laboratory & European Spallation Source + + This file is part of Mantid. + + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + File change history is stored at: <https://github.com/mantidproject/mantid> + Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class DLLExport LoadSpiceXML2DDet : public API::Algorithm { +public: + LoadSpiceXML2DDet(); + virtual ~LoadSpiceXML2DDet(); + + virtual const std::string name() const { return "LoadSpiceXML2DDet"; } + virtual int version() const { return 1; } + virtual const std::string category() const { return "DataHandling"; } + virtual const std::string summary() const { + return "Load 2-dimensional detector data file in XML format from SPICE. "; + } + +private: + void init(); + void exec(); + + /// + void parseSpiceXML(const std::string &xmlfilename); + + /// + API::MatrixWorkspace_sptr createMatrixWorkspace(); +}; + +} // namespace DataHandling +} // namespace Mantid + +#endif /* MANTID_DATAHANDLING_LOADSPICEXML2DDET_H_ */ diff --git a/Code/Mantid/Framework/DataHandling/src/LoadSpiceXML2DDet.cpp b/Code/Mantid/Framework/DataHandling/src/LoadSpiceXML2DDet.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c96ae004403f0bc97bbcbf551cd6f0f2a67e74ae --- /dev/null +++ b/Code/Mantid/Framework/DataHandling/src/LoadSpiceXML2DDet.cpp @@ -0,0 +1,71 @@ +#include "MantidDataHandling/LoadSpiceXML2DDet.h" +#include "MantidAPI/FileProperty.h" +#include "MantidAPI/WorkspaceProperty.h" +#include "MantidAPI/WorkspaceFactory.h" + +#include <fstream> + +namespace Mantid { +namespace DataHandling { + +using namespace Mantid::API; +using namespace Mantid::Kernel; + +//---------------------------------------------------------------------------------------------- +/** Constructor + */ +LoadSpiceXML2DDet::LoadSpiceXML2DDet() {} + +//---------------------------------------------------------------------------------------------- +/** Destructor + */ +LoadSpiceXML2DDet::~LoadSpiceXML2DDet() {} + +//---------------------------------------------------------------------------------------------- +/** + * @brief LoadSpiceXML2DDet::init + */ +void LoadSpiceXML2DDet::init() { + std::vector<std::string> xmlext; + xmlext.push_back(".xml"); + declareProperty( + new FileProperty("Filename", "", FileProperty::FileAction::Load, xmlext), + "XML file name for one scan including 2D detectors counts from SPICE"); + + declareProperty(new WorkspaceProperty<MatrixWorkspace>("OutputWorkspace", "", + Direction::Output), + "Name of output matrix workspace. "); +} + +//---------------------------------------------------------------------------------------------- +/** + * @brief LoadSpiceXML2DDet::exec + */ +void LoadSpiceXML2DDet::exec() { + // Load input + const std::string xmlfilename = getProperty("Filename"); + + // Parse + parseSpiceXML(xmlfilename); + + // Create output workspace + MatrixWorkspace_sptr outws = createMatrixWorkspace(); + + setProperty("OutputWorkspace", outws); +} + +void LoadSpiceXML2DDet::parseSpiceXML(const std::string &xmlfilename) { + std::ifstream ifs; + ifs.open(xmlfilename.c_str()); +} + +MatrixWorkspace_sptr LoadSpiceXML2DDet::createMatrixWorkspace() { + + MatrixWorkspace_sptr outws = boost::dynamic_pointer_cast<MatrixWorkspace>( + WorkspaceFactory::Instance().create("Workspace2D", 1, 2, 1)); + + return outws; +} + +} // namespace DataHandling +} // namespace Mantid diff --git a/Code/Mantid/Framework/DataHandling/test/LoadSpiceXML2DDetTest.h b/Code/Mantid/Framework/DataHandling/test/LoadSpiceXML2DDetTest.h new file mode 100644 index 0000000000000000000000000000000000000000..8acbd50e65eae37f46c101f42f91c6c8042278c7 --- /dev/null +++ b/Code/Mantid/Framework/DataHandling/test/LoadSpiceXML2DDetTest.h @@ -0,0 +1,40 @@ +#ifndef MANTID_DATAHANDLING_LOADSPICEXML2DDETTEST_H_ +#define MANTID_DATAHANDLING_LOADSPICEXML2DDETTEST_H_ + +#include <cxxtest/TestSuite.h> + +#include "MantidDataHandling/LoadSpiceXML2DDet.h" + +using Mantid::DataHandling::LoadSpiceXML2DDet; +using namespace Mantid::API; + +class LoadSpiceXML2DDetTest : public CxxTest::TestSuite { +public: + // This pair of boilerplate methods prevent the suite being created statically + // This means the constructor isn't called when running other tests + static LoadSpiceXML2DDetTest *createSuite() { + return new LoadSpiceXML2DDetTest(); + } + static void destroySuite(LoadSpiceXML2DDetTest *suite) { delete suite; } + + void test_Init() { + LoadSpiceXML2DDet testalg; + testalg.initialize(); + TS_ASSERT(testalg.isInitialized()); + } + + void test_LoadHB3AXML() { + LoadSpiceXML2DDet loader; + loader.initialize(); + + const std::string filename("HB3A_exp355_scan0001_0522.xml"); + TS_ASSERT_THROWS_NOTHING(loader.setProperty("Filename", filename)); + TS_ASSERT_THROWS_NOTHING( + loader.setProperty("OutputWorkspace", "Exp0335_S0038")); + + loader.execute(); + TS_ASSERT(loader.isExecuted()); + } +}; + +#endif /* MANTID_DATAHANDLING_LOADSPICEXML2DDETTEST_H_ */ diff --git a/Code/Mantid/Testing/Data/UnitTest/HB3A_exp355_scan0001_0522.xml.md5 b/Code/Mantid/Testing/Data/UnitTest/HB3A_exp355_scan0001_0522.xml.md5 new file mode 100644 index 0000000000000000000000000000000000000000..65c1c445a5b7ec229495cdfd2ef996648afb58cc --- /dev/null +++ b/Code/Mantid/Testing/Data/UnitTest/HB3A_exp355_scan0001_0522.xml.md5 @@ -0,0 +1 @@ +85d0bfddb59ea2b77ea0f5e42cc87a46