From fda84a9731aff3f1c7c809dbc0af81afd79b212a Mon Sep 17 00:00:00 2001 From: Simon Heybrock <simon.heybrock@esss.se> Date: Thu, 22 Jun 2017 12:19:24 +0200 Subject: [PATCH] Re #0. Removed include of NeXusFile from V3D.h and MatrixWorkspace.h. --- Framework/API/inc/MantidAPI/MatrixWorkspace.h | 3 - .../API/src/FileBackedExperimentInfo.cpp | 2 +- Framework/API/src/FrameworkManager.cpp | 2 + Framework/API/src/MatrixWorkspace.cpp | 116 ----------------- Framework/API/test/MatrixWorkspaceTest.h | 15 --- .../MantidAlgorithms/DetectorEfficiencyCor.h | 2 + .../src/ReflectometryReductionOne2.cpp | 1 + .../MantidDataHandling/SaveNexusProcessed.h | 5 + .../SaveToSNSHistogramNexus.h | 5 +- .../DataHandling/src/LoadIDFFromNexus.cpp | 1 + .../DataHandling/src/LoadMcStasNexus.cpp | 2 +- Framework/DataHandling/src/LoadMuonNexus2.cpp | 2 +- Framework/DataHandling/src/LoadNXSPE.cpp | 2 +- Framework/DataHandling/src/LoadNXcanSAS.cpp | 1 + Framework/DataHandling/src/SaveNXSPE.cpp | 1 + Framework/DataHandling/src/SaveNXTomo.cpp | 2 +- .../DataHandling/src/SaveNexusProcessed.cpp | 119 +++++++++++++++++- Framework/DataHandling/test/CMakeLists.txt | 1 + .../DataHandling/test/LoadDetectorInfoTest.h | 1 + Framework/DataHandling/test/SaveNXTomoTest.h | 1 + .../test/SaveNexusProcessedTest.h | 86 ++++++++++--- .../inc/MantidDataObjects/PeakColumn.h | 1 + .../Crystal/MatrixVectorPairParser.h | 1 + .../inc/MantidGeometry/Crystal/PointGroup.h | 1 + .../Crystal/SymmetryElementFactory.h | 1 + .../Geometry/inc/MantidGeometry/IComponent.h | 7 +- .../inc/MantidGeometry/Surfaces/Line.h | 1 + Framework/Geometry/src/Instrument.cpp | 1 + .../Geometry/src/Instrument/ParameterMap.cpp | 1 + Framework/Kernel/inc/MantidKernel/V3D.h | 6 +- Framework/Kernel/src/V3D.cpp | 1 + Framework/MDAlgorithms/src/LoadILLAscii.cpp | 1 + 32 files changed, 222 insertions(+), 170 deletions(-) diff --git a/Framework/API/inc/MantidAPI/MatrixWorkspace.h b/Framework/API/inc/MantidAPI/MatrixWorkspace.h index 55e11fd5fc0..d0065c7351b 100644 --- a/Framework/API/inc/MantidAPI/MatrixWorkspace.h +++ b/Framework/API/inc/MantidAPI/MatrixWorkspace.h @@ -455,9 +455,6 @@ public: void saveInstrumentNexus(::NeXus::File *file) const; void loadInstrumentNexus(::NeXus::File *file); - void saveSpectraMapNexus( - ::NeXus::File *file, const std::vector<int> &spec, - const ::NeXus::NXcompression compression = ::NeXus::LZW) const; //===================================================================================== // MD Geometry methods diff --git a/Framework/API/src/FileBackedExperimentInfo.cpp b/Framework/API/src/FileBackedExperimentInfo.cpp index 69aa290c4c6..c0ae4a0a4b4 100644 --- a/Framework/API/src/FileBackedExperimentInfo.cpp +++ b/Framework/API/src/FileBackedExperimentInfo.cpp @@ -3,8 +3,8 @@ #include <sstream> -#include <nexus/NeXusException.hpp> #include <nexus/NeXusFile.hpp> +#include <nexus/NeXusException.hpp> namespace Mantid { namespace API { diff --git a/Framework/API/src/FrameworkManager.cpp b/Framework/API/src/FrameworkManager.cpp index 0206b3c52f9..d9bb34fd738 100644 --- a/Framework/API/src/FrameworkManager.cpp +++ b/Framework/API/src/FrameworkManager.cpp @@ -11,6 +11,8 @@ #include "MantidKernel/PropertyManagerDataService.h" #include "MantidKernel/UsageService.h" +#include <nexus/NeXusFile.hpp> + #include <Poco/ActiveResult.h> #include <clocale> diff --git a/Framework/API/src/MatrixWorkspace.cpp b/Framework/API/src/MatrixWorkspace.cpp index e9e2aa541c7..a5e36f6477a 100644 --- a/Framework/API/src/MatrixWorkspace.cpp +++ b/Framework/API/src/MatrixWorkspace.cpp @@ -29,7 +29,6 @@ using Mantid::Kernel::DateAndTime; using Mantid::Kernel::TimeSeriesProperty; -using NeXus::NXcompression; using Mantid::Kernel::Strings::toString; namespace Mantid { @@ -1571,121 +1570,6 @@ signal_t MatrixWorkspace::getSignalWithMaskAtCoord( return getSignalAtCoord(coords, normalization); } -/** Save the spectra detector map to an open NeXus file. -* @param file :: open NeXus file -* @param spec :: list of the Workspace Indices to save. -* @param compression :: NXcompression int to indicate how to compress -*/ -void MatrixWorkspace::saveSpectraMapNexus( - ::NeXus::File *file, const std::vector<int> &spec, - const ::NeXus::NXcompression compression) const { - // Count the total number of detectors - std::size_t nDetectors = 0; - for (auto index : spec) { - nDetectors += - this->getSpectrum(static_cast<size_t>(index)).getDetectorIDs().size(); - } - - if (nDetectors < 1) { - // No data in spectraMap to write - g_log.warning("No spectramap data to write"); - return; - } - - // Start the detector group - file->makeGroup("detector", "NXdetector", 1); - file->putAttr("version", 1); - - int numberSpec = int(spec.size()); - // allocate space for the Nexus Muon format of spctra-detector mapping - std::vector<int32_t> detector_index( - numberSpec + 1, 0); // allow for writing one more than required - std::vector<int32_t> detector_count(numberSpec, 0); - std::vector<int32_t> detector_list(nDetectors, 0); - std::vector<int32_t> spectra(numberSpec, 0); - std::vector<double> detPos(nDetectors * 3); - detector_index[0] = 0; - int id = 0; - - int ndet = 0; - // get data from map into Nexus Muon format - for (int i = 0; i < numberSpec; i++) { - // Workspace index - int si = spec[i]; - // Spectrum there - const auto &spectrum = this->getSpectrum(si); - spectra[i] = int32_t(spectrum.getSpectrumNo()); - - // The detectors in this spectrum - const auto &detectorgroup = spectrum.getDetectorIDs(); - const int ndet1 = static_cast<int>(detectorgroup.size()); - - detector_index[i + 1] = int32_t( - detector_index[i] + - ndet1); // points to start of detector list for the next spectrum - detector_count[i] = int32_t(ndet1); - ndet += ndet1; - - std::set<detid_t>::const_iterator it; - for (it = detectorgroup.begin(); it != detectorgroup.end(); ++it) { - detector_list[id++] = int32_t(*it); - } - } - // Cut the extra entry at the end of detector_index - detector_index.resize(numberSpec); - - // write data as Nexus sections detector{index,count,list} - std::vector<int> dims(1, numberSpec); - file->writeCompData("detector_index", detector_index, dims, compression, - dims); - file->writeCompData("detector_count", detector_count, dims, compression, - dims); - dims[0] = ndet; - file->writeCompData("detector_list", detector_list, dims, compression, dims); - dims[0] = numberSpec; - file->writeCompData("spectra", spectra, dims, compression, dims); - - // Get all the positions - try { - Geometry::Instrument_const_sptr inst = this->getInstrument(); - Geometry::IComponent_const_sptr sample = inst->getSample(); - if (sample) { - Kernel::V3D sample_pos = sample->getPos(); - for (int i = 0; i < ndet; i++) { - double R, Theta, Phi; - try { - Geometry::IDetector_const_sptr det = - inst->getDetector(detector_list[i]); - Kernel::V3D pos = det->getPos() - sample_pos; - pos.getSpherical(R, Theta, Phi); - R = det->getDistance(*sample); - Theta = this->detectorTwoTheta(*det) * rad2deg; - } catch (...) { - R = 0.; - Theta = 0.; - Phi = 0.; - } - // Need to get R & Theta through these methods to be correct for grouped - // detectors - detPos[3 * i] = R; - detPos[3 * i + 1] = Theta; - detPos[3 * i + 2] = Phi; - } - } else - for (int i = 0; i < 3 * ndet; i++) - detPos[i] = 0.; - - dims[0] = ndet; - dims.push_back(3); - dims[1] = 3; - file->writeCompData("detector_positions", detPos, dims, compression, dims); - } catch (...) { - g_log.error("Unknown error caught when saving detector positions."); - } - - file->closeGroup(); -} - /* MDMasking for a Matrix Workspace has not been implemented. @param : diff --git a/Framework/API/test/MatrixWorkspaceTest.h b/Framework/API/test/MatrixWorkspaceTest.h index 3b984074a19..00b73f8761a 100644 --- a/Framework/API/test/MatrixWorkspaceTest.h +++ b/Framework/API/test/MatrixWorkspaceTest.h @@ -803,21 +803,6 @@ public: TS_ASSERT_THROWS(wkspace.binIndexOf(0.), std::out_of_range); } - void test_nexus_spectraMap() { - NexusTestHelper th(true); - th.createFile("MatrixWorkspaceTest.nxs"); - auto ws = makeWorkspaceWithDetectors(100, 50); - std::vector<int> spec; - for (int i = 0; i < 100; i++) { - // Give some funny numbers, so it is not the default - ws->getSpectrum(size_t(i)).setSpectrumNo(i * 11); - ws->getSpectrum(size_t(i)).setDetectorID(99 - i); - spec.push_back(i); - } - // Save that to the NXS file - TS_ASSERT_THROWS_NOTHING(ws->saveSpectraMapNexus(th.file, spec);); - } - void test_hasGroupedDetectors() { auto ws = makeWorkspaceWithDetectors(5, 1); TS_ASSERT_EQUALS(ws->hasGroupedDetectors(), false); diff --git a/Framework/Algorithms/inc/MantidAlgorithms/DetectorEfficiencyCor.h b/Framework/Algorithms/inc/MantidAlgorithms/DetectorEfficiencyCor.h index 9bdfd7a2db4..32fb36d812f 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/DetectorEfficiencyCor.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/DetectorEfficiencyCor.h @@ -6,6 +6,8 @@ #include "MantidKernel/V3D.h" #include "MantidGeometry/IDetector.h" +#include <list> + namespace Mantid { namespace Algorithms { /** diff --git a/Framework/Algorithms/src/ReflectometryReductionOne2.cpp b/Framework/Algorithms/src/ReflectometryReductionOne2.cpp index ad729a1c504..7725eb4f199 100644 --- a/Framework/Algorithms/src/ReflectometryReductionOne2.cpp +++ b/Framework/Algorithms/src/ReflectometryReductionOne2.cpp @@ -8,6 +8,7 @@ #include "MantidKernel/MandatoryValidator.h" #include "MantidKernel/StringTokenizer.h" #include "MantidKernel/Unit.h" +#include "MantidGeometry/IDetector.h" #include <algorithm> #include <boost/lexical_cast.hpp> diff --git a/Framework/DataHandling/inc/MantidDataHandling/SaveNexusProcessed.h b/Framework/DataHandling/inc/MantidDataHandling/SaveNexusProcessed.h index 0c9139a92c8..00519e38145 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/SaveNexusProcessed.h +++ b/Framework/DataHandling/inc/MantidDataHandling/SaveNexusProcessed.h @@ -66,6 +66,11 @@ public: /// Algorithm's category for identification overriding a virtual method const std::string category() const override { return "DataHandling\\Nexus"; } + void saveSpectraMapNexus( + const API::MatrixWorkspace &ws, ::NeXus::File *file, + const std::vector<int> &spec, + const ::NeXus::NXcompression compression = ::NeXus::LZW) const; + protected: /// Override process groups bool processGroups() override; diff --git a/Framework/DataHandling/inc/MantidDataHandling/SaveToSNSHistogramNexus.h b/Framework/DataHandling/inc/MantidDataHandling/SaveToSNSHistogramNexus.h index e8dc0396f6f..dc53024f175 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/SaveToSNSHistogramNexus.h +++ b/Framework/DataHandling/inc/MantidDataHandling/SaveToSNSHistogramNexus.h @@ -1,9 +1,6 @@ #ifndef MANTID_DATAHANDLING_SAVESNSNEXUS_H_ #define MANTID_DATAHANDLING_SAVESNSNEXUS_H_ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- #include "MantidAPI/Algorithm.h" #include "MantidAPI/MatrixWorkspace_fwd.h" #include "MantidAPI/Progress.h" @@ -12,8 +9,8 @@ #include "MantidDataObjects/Workspace2D.h" #include "MantidGeometry/Instrument/RectangularDetector.h" #include <climits> -#include <nexus/NeXusException.hpp> #include <nexus/NeXusFile.hpp> +#include <nexus/NeXusException.hpp> namespace Mantid { namespace DataHandling { diff --git a/Framework/DataHandling/src/LoadIDFFromNexus.cpp b/Framework/DataHandling/src/LoadIDFFromNexus.cpp index ab9e7484b49..f68ae54eb58 100644 --- a/Framework/DataHandling/src/LoadIDFFromNexus.cpp +++ b/Framework/DataHandling/src/LoadIDFFromNexus.cpp @@ -12,6 +12,7 @@ #include <Poco/DOM/NodeIterator.h> #include <Poco/File.h> #include <Poco/Path.h> +#include <nexus/NeXusFile.hpp> using Poco::XML::DOMParser; using Poco::XML::Document; diff --git a/Framework/DataHandling/src/LoadMcStasNexus.cpp b/Framework/DataHandling/src/LoadMcStasNexus.cpp index cb42ae556e7..ec1aebbaf44 100644 --- a/Framework/DataHandling/src/LoadMcStasNexus.cpp +++ b/Framework/DataHandling/src/LoadMcStasNexus.cpp @@ -6,8 +6,8 @@ #include "MantidAPI/WorkspaceFactory.h" #include "MantidAPI/WorkspaceGroup.h" #include "MantidKernel/Unit.h" -#include <nexus/NeXusException.hpp> #include <nexus/NeXusFile.hpp> +#include <nexus/NeXusException.hpp> #include <boost/algorithm/string.hpp> diff --git a/Framework/DataHandling/src/LoadMuonNexus2.cpp b/Framework/DataHandling/src/LoadMuonNexus2.cpp index 608162ee272..0d649146403 100644 --- a/Framework/DataHandling/src/LoadMuonNexus2.cpp +++ b/Framework/DataHandling/src/LoadMuonNexus2.cpp @@ -16,8 +16,8 @@ #include "MantidKernel/UnitFactory.h" #include "MantidKernel/UnitLabelTypes.h" #include "MantidNexus/NexusClasses.h" -#include <nexus/NeXusException.hpp> #include <nexus/NeXusFile.hpp> +#include <nexus/NeXusException.hpp> #include <Poco/Path.h> #include <boost/lexical_cast.hpp> diff --git a/Framework/DataHandling/src/LoadNXSPE.cpp b/Framework/DataHandling/src/LoadNXSPE.cpp index 9f5e0dcfddd..43eb55b4b9a 100644 --- a/Framework/DataHandling/src/LoadNXSPE.cpp +++ b/Framework/DataHandling/src/LoadNXSPE.cpp @@ -11,8 +11,8 @@ #include "MantidKernel/UnitFactory.h" #include "MantidNexus/NexusClasses.h" -#include <nexus/NeXusException.hpp> #include <nexus/NeXusFile.hpp> +#include <nexus/NeXusException.hpp> #include "MantidGeometry/Instrument.h" #include "MantidGeometry/Instrument/Detector.h" diff --git a/Framework/DataHandling/src/LoadNXcanSAS.cpp b/Framework/DataHandling/src/LoadNXcanSAS.cpp index 191c24c271a..54bf55f6623 100644 --- a/Framework/DataHandling/src/LoadNXcanSAS.cpp +++ b/Framework/DataHandling/src/LoadNXcanSAS.cpp @@ -20,6 +20,7 @@ #include <H5Cpp.h> #include <Poco/DirectoryIterator.h> #include <Poco/Path.h> +#include <nexus/NeXusFile.hpp> #include <type_traits> using namespace Mantid::Kernel; diff --git a/Framework/DataHandling/src/SaveNXSPE.cpp b/Framework/DataHandling/src/SaveNXSPE.cpp index 1a4f80f53a3..b76d875c136 100644 --- a/Framework/DataHandling/src/SaveNXSPE.cpp +++ b/Framework/DataHandling/src/SaveNXSPE.cpp @@ -16,6 +16,7 @@ #include <Poco/File.h> #include <Poco/Path.h> +#include <nexus/NeXusFile.hpp> #include <boost/scoped_array.hpp> #include <limits> diff --git a/Framework/DataHandling/src/SaveNXTomo.cpp b/Framework/DataHandling/src/SaveNXTomo.cpp index 2cdb0e63512..3b82c5aa249 100644 --- a/Framework/DataHandling/src/SaveNXTomo.cpp +++ b/Framework/DataHandling/src/SaveNXTomo.cpp @@ -14,8 +14,8 @@ #include "MantidKernel/CompositeValidator.h" #include "MantidKernel/MantidVersion.h" -#include <nexus/NeXusException.hpp> #include <nexus/NeXusFile.hpp> +#include <nexus/NeXusException.hpp> namespace Mantid { namespace DataHandling { diff --git a/Framework/DataHandling/src/SaveNexusProcessed.cpp b/Framework/DataHandling/src/SaveNexusProcessed.cpp index 154d8a8a20b..7908617397a 100644 --- a/Framework/DataHandling/src/SaveNexusProcessed.cpp +++ b/Framework/DataHandling/src/SaveNexusProcessed.cpp @@ -10,6 +10,7 @@ #include "MantidDataObjects/EventWorkspace.h" #include "MantidDataObjects/OffsetsWorkspace.h" #include "MantidDataObjects/PeaksWorkspace.h" +#include "MantidGeometry/Crystal/AngleUnits.h" #include "MantidKernel/ArrayProperty.h" #include "MantidKernel/BoundedValidator.h" #include "MantidNexus/NexusFileIO.h" @@ -261,7 +262,7 @@ void SaveNexusProcessed::doExec(Workspace_sptr inputWorkspace, } cppFile->openGroup("instrument", "NXinstrument"); - matrixWorkspace->saveSpectraMapNexus(cppFile, spec, ::NeXus::LZW); + saveSpectraMapNexus(*matrixWorkspace, cppFile, spec, ::NeXus::LZW); cppFile->closeGroup(); } // finish matrix workspace specifics @@ -523,5 +524,121 @@ bool SaveNexusProcessed::processGroups() { return true; } +/** Save the spectra detector map to an open NeXus file. +* @param file :: open NeXus file +* @param spec :: list of the Workspace Indices to save. +* @param compression :: NXcompression int to indicate how to compress +*/ +void SaveNexusProcessed::saveSpectraMapNexus( + const MatrixWorkspace &ws, ::NeXus::File *file, + const std::vector<int> &spec, + const ::NeXus::NXcompression compression) const { + // Count the total number of detectors + std::size_t nDetectors = 0; + for (auto index : spec) { + nDetectors += + ws.getSpectrum(static_cast<size_t>(index)).getDetectorIDs().size(); + } + + if (nDetectors < 1) { + // No data in spectraMap to write + g_log.warning("No spectramap data to write"); + return; + } + + // Start the detector group + file->makeGroup("detector", "NXdetector", 1); + file->putAttr("version", 1); + + int numberSpec = int(spec.size()); + // allocate space for the Nexus Muon format of spctra-detector mapping + std::vector<int32_t> detector_index( + numberSpec + 1, 0); // allow for writing one more than required + std::vector<int32_t> detector_count(numberSpec, 0); + std::vector<int32_t> detector_list(nDetectors, 0); + std::vector<int32_t> spectra(numberSpec, 0); + std::vector<double> detPos(nDetectors * 3); + detector_index[0] = 0; + int id = 0; + + int ndet = 0; + // get data from map into Nexus Muon format + for (int i = 0; i < numberSpec; i++) { + // Workspace index + int si = spec[i]; + // Spectrum there + const auto &spectrum = ws.getSpectrum(si); + spectra[i] = int32_t(spectrum.getSpectrumNo()); + + // The detectors in this spectrum + const auto &detectorgroup = spectrum.getDetectorIDs(); + const int ndet1 = static_cast<int>(detectorgroup.size()); + + detector_index[i + 1] = int32_t( + detector_index[i] + + ndet1); // points to start of detector list for the next spectrum + detector_count[i] = int32_t(ndet1); + ndet += ndet1; + + std::set<detid_t>::const_iterator it; + for (it = detectorgroup.begin(); it != detectorgroup.end(); ++it) { + detector_list[id++] = int32_t(*it); + } + } + // Cut the extra entry at the end of detector_index + detector_index.resize(numberSpec); + + // write data as Nexus sections detector{index,count,list} + std::vector<int> dims(1, numberSpec); + file->writeCompData("detector_index", detector_index, dims, compression, + dims); + file->writeCompData("detector_count", detector_count, dims, compression, + dims); + dims[0] = ndet; + file->writeCompData("detector_list", detector_list, dims, compression, dims); + dims[0] = numberSpec; + file->writeCompData("spectra", spectra, dims, compression, dims); + + // Get all the positions + try { + Geometry::Instrument_const_sptr inst = ws.getInstrument(); + Geometry::IComponent_const_sptr sample = inst->getSample(); + if (sample) { + Kernel::V3D sample_pos = sample->getPos(); + for (int i = 0; i < ndet; i++) { + double R, Theta, Phi; + try { + Geometry::IDetector_const_sptr det = + inst->getDetector(detector_list[i]); + Kernel::V3D pos = det->getPos() - sample_pos; + pos.getSpherical(R, Theta, Phi); + R = det->getDistance(*sample); + Theta = ws.detectorTwoTheta(*det) * Geometry::rad2deg; + } catch (...) { + R = 0.; + Theta = 0.; + Phi = 0.; + } + // Need to get R & Theta through these methods to be correct for grouped + // detectors + detPos[3 * i] = R; + detPos[3 * i + 1] = Theta; + detPos[3 * i + 2] = Phi; + } + } else + for (int i = 0; i < 3 * ndet; i++) + detPos[i] = 0.; + + dims[0] = ndet; + dims.push_back(3); + dims[1] = 3; + file->writeCompData("detector_positions", detPos, dims, compression, dims); + } catch (...) { + g_log.error("Unknown error caught when saving detector positions."); + } + + file->closeGroup(); +} + } // namespace DataHandling } // namespace Mantid diff --git a/Framework/DataHandling/test/CMakeLists.txt b/Framework/DataHandling/test/CMakeLists.txt index 76b892c2683..0cfd3daaa25 100644 --- a/Framework/DataHandling/test/CMakeLists.txt +++ b/Framework/DataHandling/test/CMakeLists.txt @@ -11,6 +11,7 @@ if ( CXXTEST_FOUND ) ../../TestHelpers/src/StartFrameworkManager.cpp ../../TestHelpers/src/TearDownWorld.cpp ../../TestHelpers/src/WorkspaceCreationHelper.cpp + ../../TestHelpers/src/NexusTestHelper.cpp NXcanSASTestHelper.cpp ) diff --git a/Framework/DataHandling/test/LoadDetectorInfoTest.h b/Framework/DataHandling/test/LoadDetectorInfoTest.h index c41a65134db..31be49186dd 100644 --- a/Framework/DataHandling/test/LoadDetectorInfoTest.h +++ b/Framework/DataHandling/test/LoadDetectorInfoTest.h @@ -17,6 +17,7 @@ #include "MantidKernel/UnitFactory.h" #include <Poco/File.h> +#include <nexus/NeXusFile.hpp> #include <boost/lexical_cast.hpp> #include <vector> diff --git a/Framework/DataHandling/test/SaveNXTomoTest.h b/Framework/DataHandling/test/SaveNXTomoTest.h index d96d7e9fb57..c2632ae035c 100644 --- a/Framework/DataHandling/test/SaveNXTomoTest.h +++ b/Framework/DataHandling/test/SaveNXTomoTest.h @@ -8,6 +8,7 @@ #include "MantidAPI/WorkspaceGroup.h" #include "MantidTestHelpers/WorkspaceCreationHelper.h" #include <Poco/File.h> +#include <nexus/NeXusFile.hpp> using namespace Mantid::API; using namespace Mantid::Kernel; diff --git a/Framework/DataHandling/test/SaveNexusProcessedTest.h b/Framework/DataHandling/test/SaveNexusProcessedTest.h index b0e10668043..3e0a7673695 100644 --- a/Framework/DataHandling/test/SaveNexusProcessedTest.h +++ b/Framework/DataHandling/test/SaveNexusProcessedTest.h @@ -24,6 +24,10 @@ #include "MantidKernel/Unit.h" #include "MantidKernel/UnitFactory.h" #include "MantidDataHandling/LoadRaw3.h" +#include "MantidGeometry/Instrument.h" +#include "MantidTestHelpers/FakeObjects.h" +#include "MantidTestHelpers/ComponentCreationHelper.h" +#include "MantidTestHelpers/NexusTestHelper.h" #include "MantidTestHelpers/WorkspaceCreationHelper.h" #include <Poco/File.h> #include <Poco/Path.h> @@ -38,6 +42,7 @@ using namespace Mantid::API; using namespace Mantid::Kernel; using namespace Mantid::DataHandling; using namespace Mantid::DataObjects; +using namespace Mantid::Geometry; using namespace Mantid::NeXus; using Mantid::HistogramData::HistogramDx; @@ -84,7 +89,7 @@ public: outputFile = doExec(outputFile, useXErrors); // Assert XError correctness - NeXus::File savedNexus(outputFile); + ::NeXus::File savedNexus(outputFile); savedNexus.openGroup("mantid_workspace_1", "NXentry"); savedNexus.openGroup("workspace", "NXdata"); @@ -462,7 +467,7 @@ public: outputFileName = alg.getPropertyValue("Filename"); try { - NeXus::File savedNexus(outputFileName); + ::NeXus::File savedNexus(outputFileName); savedNexus.openGroup("mantid_workspace_1", "NXentry"); savedNexus.openGroup("table_workspace", "NXdata"); @@ -471,7 +476,7 @@ public: savedNexus.openData("column_1"); - NeXus::Info columnInfo1 = savedNexus.getInfo(); + ::NeXus::Info columnInfo1 = savedNexus.getInfo(); TS_ASSERT_EQUALS(columnInfo1.dims.size(), 2); TS_ASSERT_EQUALS(columnInfo1.dims[0], 3); TS_ASSERT_EQUALS(columnInfo1.dims[1], 4); @@ -487,7 +492,7 @@ public: TS_ASSERT_EQUALS(data1[8], 4); TS_ASSERT_EQUALS(data1[11], 7); - std::vector<NeXus::AttrInfo> attrInfos1 = savedNexus.getAttrInfos(); + std::vector<::NeXus::AttrInfo> attrInfos1 = savedNexus.getAttrInfos(); TS_ASSERT_EQUALS(attrInfos1.size(), 6); if (attrInfos1.size() == 6) { @@ -509,7 +514,7 @@ public: savedNexus.openData("column_2"); - NeXus::Info columnInfo2 = savedNexus.getInfo(); + ::NeXus::Info columnInfo2 = savedNexus.getInfo(); TS_ASSERT_EQUALS(columnInfo2.dims.size(), 2); TS_ASSERT_EQUALS(columnInfo2.dims[0], 3); TS_ASSERT_EQUALS(columnInfo2.dims[1], 2); @@ -523,7 +528,7 @@ public: TS_ASSERT_EQUALS(data2[3], 2.5); TS_ASSERT_EQUALS(data2[5], 0.0); - std::vector<NeXus::AttrInfo> attrInfos2 = savedNexus.getAttrInfos(); + std::vector<::NeXus::AttrInfo> attrInfos2 = savedNexus.getAttrInfos(); TS_ASSERT_EQUALS(attrInfos2.size(), 6); if (attrInfos2.size() == 6) { @@ -633,7 +638,7 @@ public: // Get full output file path outputFileName = alg.getPropertyValue("Filename"); - NeXus::File savedNexus(outputFileName); + ::NeXus::File savedNexus(outputFileName); savedNexus.openGroup("mantid_workspace_1", "NXentry"); savedNexus.openGroup("table_workspace", "NXdata"); @@ -697,13 +702,13 @@ public: { savedNexus.openData("column_9"); - NeXus::Info columnInfo = savedNexus.getInfo(); + ::NeXus::Info columnInfo = savedNexus.getInfo(); TS_ASSERT_EQUALS(columnInfo.dims.size(), 2); TS_ASSERT_EQUALS(columnInfo.dims[0], 3); TS_ASSERT_EQUALS(columnInfo.dims[1], 9); TS_ASSERT_EQUALS(columnInfo.type, NX_CHAR); - std::vector<NeXus::AttrInfo> attrInfos = savedNexus.getAttrInfos(); + std::vector<::NeXus::AttrInfo> attrInfos = savedNexus.getAttrInfos(); TS_ASSERT_EQUALS(attrInfos.size(), 3); if (attrInfos.size() == 3) { @@ -767,7 +772,7 @@ public: // Get full output file path outputFileName = alg.getPropertyValue("Filename"); - NeXus::File savedNexus(outputFileName); + ::NeXus::File savedNexus(outputFileName); savedNexus.openGroup("mantid_workspace_1", "NXentry"); savedNexus.openGroup("table_workspace", "NXdata"); @@ -782,13 +787,13 @@ public: { savedNexus.openData("column_2"); - NeXus::Info columnInfo = savedNexus.getInfo(); + ::NeXus::Info columnInfo = savedNexus.getInfo(); TS_ASSERT_EQUALS(columnInfo.dims.size(), 2); TS_ASSERT_EQUALS(columnInfo.dims[0], 3); TS_ASSERT_EQUALS(columnInfo.dims[1], 1); TS_ASSERT_EQUALS(columnInfo.type, NX_CHAR); - std::vector<NeXus::AttrInfo> attrInfos = savedNexus.getAttrInfos(); + std::vector<::NeXus::AttrInfo> attrInfos = savedNexus.getAttrInfos(); TS_ASSERT_EQUALS(attrInfos.size(), 3); if (attrInfos.size() == 3) { @@ -856,16 +861,31 @@ public: AnalysisDataService::Instance().remove("testSpace"); } + void test_nexus_spectraMap() { + NexusTestHelper th(true); + th.createFile("MatrixWorkspaceTest.nxs"); + auto ws = makeWorkspaceWithDetectors(100, 50); + std::vector<int> spec; + for (int i = 0; i < 100; i++) { + // Give some funny numbers, so it is not the default + ws->getSpectrum(size_t(i)).setSpectrumNo(i * 11); + ws->getSpectrum(size_t(i)).setDetectorID(99 - i); + spec.push_back(i); + } + SaveNexusProcessed alg; + TS_ASSERT_THROWS_NOTHING(alg.saveSpectraMapNexus(*ws, th.file, spec);); + } + private: - void doTestColumnInfo(NeXus::File &file, int type, + void doTestColumnInfo(::NeXus::File &file, int type, const std::string &interpret_as, const std::string &name) { - NeXus::Info columnInfo = file.getInfo(); + ::NeXus::Info columnInfo = file.getInfo(); TSM_ASSERT_EQUALS(name, columnInfo.dims.size(), 1); TSM_ASSERT_EQUALS(name, columnInfo.dims[0], 3); TSM_ASSERT_EQUALS(name, columnInfo.type, type); - std::vector<NeXus::AttrInfo> attrInfos = file.getAttrInfos(); + std::vector<::NeXus::AttrInfo> attrInfos = file.getAttrInfos(); TSM_ASSERT_EQUALS(name, attrInfos.size(), 3); if (attrInfos.size() == 3) { @@ -880,16 +900,16 @@ private: } } - void doTestColumnInfo2(NeXus::File &file, int type, + void doTestColumnInfo2(::NeXus::File &file, int type, const std::string &interpret_as, const std::string &name, int dim1) { - NeXus::Info columnInfo = file.getInfo(); + ::NeXus::Info columnInfo = file.getInfo(); TSM_ASSERT_EQUALS(name, columnInfo.dims.size(), 2); TSM_ASSERT_EQUALS(name, columnInfo.dims[0], 3); TSM_ASSERT_EQUALS(name, columnInfo.dims[1], dim1); TSM_ASSERT_EQUALS(name, columnInfo.type, type); - std::vector<NeXus::AttrInfo> attrInfos = file.getAttrInfos(); + std::vector<::NeXus::AttrInfo> attrInfos = file.getAttrInfos(); TSM_ASSERT_EQUALS(name, attrInfos.size(), 6); if (attrInfos.size() == 6) { @@ -905,7 +925,7 @@ private: } template <typename T> - void doTestColumnData(const std::string &name, NeXus::File &file, + void doTestColumnData(const std::string &name, ::NeXus::File &file, const T expectedData[], size_t len = 3) { std::vector<T> data; file.getData(data); @@ -977,6 +997,34 @@ private: return outputFile; } + /** Create a workspace with numSpectra, with + * each spectrum having one detector, at id = workspace index. + * @param numSpectra + * @return + */ + boost::shared_ptr<MatrixWorkspace> + makeWorkspaceWithDetectors(size_t numSpectra, size_t numBins) const { + boost::shared_ptr<MatrixWorkspace> ws2 = + boost::make_shared<WorkspaceTester>(); + ws2->initialize(numSpectra, numBins, numBins); + + auto inst = boost::make_shared<Instrument>("TestInstrument"); + // We get a 1:1 map by default so the detector ID should match the spectrum + // number + for (size_t i = 0; i < ws2->getNumberHistograms(); ++i) { + // Create a detector for each spectra + Detector *det = + new Detector("pixel", static_cast<detid_t>(i), inst.get()); + det->setShape( + ComponentCreationHelper::createSphere(0.01, V3D(0, 0, 0), "1")); + inst->add(det); + inst->markAsDetector(det); + ws2->getSpectrum(i).addDetectorID(static_cast<detid_t>(i)); + } + ws2->setInstrument(inst); + return ws2; + } + std::string outputFile; std::string entryName; std::string dataName; diff --git a/Framework/DataObjects/inc/MantidDataObjects/PeakColumn.h b/Framework/DataObjects/inc/MantidDataObjects/PeakColumn.h index 3079799086a..33fd493ebb0 100644 --- a/Framework/DataObjects/inc/MantidDataObjects/PeakColumn.h +++ b/Framework/DataObjects/inc/MantidDataObjects/PeakColumn.h @@ -5,6 +5,7 @@ #include "MantidDataObjects/Peak.h" #include <boost/variant.hpp> +#include <list> namespace Mantid { namespace DataObjects { diff --git a/Framework/Geometry/inc/MantidGeometry/Crystal/MatrixVectorPairParser.h b/Framework/Geometry/inc/MantidGeometry/Crystal/MatrixVectorPairParser.h index abb01237fd5..6b18d347000 100644 --- a/Framework/Geometry/inc/MantidGeometry/Crystal/MatrixVectorPairParser.h +++ b/Framework/Geometry/inc/MantidGeometry/Crystal/MatrixVectorPairParser.h @@ -7,6 +7,7 @@ #include "MantidKernel/Exception.h" #include <functional> +#include <map> #include <boost/spirit/include/qi.hpp> namespace Mantid { diff --git a/Framework/Geometry/inc/MantidGeometry/Crystal/PointGroup.h b/Framework/Geometry/inc/MantidGeometry/Crystal/PointGroup.h index 2032ca0603b..0de5373f0a9 100644 --- a/Framework/Geometry/inc/MantidGeometry/Crystal/PointGroup.h +++ b/Framework/Geometry/inc/MantidGeometry/Crystal/PointGroup.h @@ -10,6 +10,7 @@ #include <vector> #include <string> #include <set> +#include <map> #include "MantidGeometry/Crystal/SymmetryOperation.h" #include "MantidGeometry/Crystal/Group.h" diff --git a/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryElementFactory.h b/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryElementFactory.h index 30dd5b1603e..b0e3c5c1195 100644 --- a/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryElementFactory.h +++ b/Framework/Geometry/inc/MantidGeometry/Crystal/SymmetryElementFactory.h @@ -8,6 +8,7 @@ #include "MantidKernel/RegistrationHelper.h" #include <boost/make_shared.hpp> +#include <map> #include <unordered_set> namespace Mantid { diff --git a/Framework/Geometry/inc/MantidGeometry/IComponent.h b/Framework/Geometry/inc/MantidGeometry/IComponent.h index 0c00673b5bc..7da1732bd2b 100644 --- a/Framework/Geometry/inc/MantidGeometry/IComponent.h +++ b/Framework/Geometry/inc/MantidGeometry/IComponent.h @@ -1,12 +1,10 @@ #ifndef MANTID_GEOMETRY_ICOMPONENT_H_ #define MANTID_GEOMETRY_ICOMPONENT_H_ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- #include "MantidGeometry/DllConfig.h" #include "MantidKernel/V3D.h" +#include <map> #include <string> #include <vector> #include <set> @@ -22,9 +20,6 @@ class Quat; } namespace Geometry { -//--------------------------------------------------------- -// Forward declarations -//--------------------------------------------------------- class IComponent; class BoundingBox; class ParameterMap; diff --git a/Framework/Geometry/inc/MantidGeometry/Surfaces/Line.h b/Framework/Geometry/inc/MantidGeometry/Surfaces/Line.h index dd57786c636..e22c9417180 100644 --- a/Framework/Geometry/inc/MantidGeometry/Surfaces/Line.h +++ b/Framework/Geometry/inc/MantidGeometry/Surfaces/Line.h @@ -4,6 +4,7 @@ #include "MantidGeometry/DllConfig.h" #include "MantidKernel/V3D.h" #include <complex> +#include <list> namespace Mantid { diff --git a/Framework/Geometry/src/Instrument.cpp b/Framework/Geometry/src/Instrument.cpp index 963aea28060..712e7f331fe 100644 --- a/Framework/Geometry/src/Instrument.cpp +++ b/Framework/Geometry/src/Instrument.cpp @@ -12,6 +12,7 @@ #include "MantidKernel/PhysicalConstants.h" #include "MantidKernel/make_unique.h" +#include <nexus/NeXusFile.hpp> #include <boost/make_shared.hpp> #include <queue> diff --git a/Framework/Geometry/src/Instrument/ParameterMap.cpp b/Framework/Geometry/src/Instrument/ParameterMap.cpp index 64b6b0e49cd..50bcb188e01 100644 --- a/Framework/Geometry/src/Instrument/ParameterMap.cpp +++ b/Framework/Geometry/src/Instrument/ParameterMap.cpp @@ -7,6 +7,7 @@ #include "MantidGeometry/Instrument.h" #include "MantidGeometry/Instrument/ParameterFactory.h" #include <cstring> +#include <nexus/NeXusFile.hpp> #include <boost/algorithm/string.hpp> #ifdef _WIN32 diff --git a/Framework/Kernel/inc/MantidKernel/V3D.h b/Framework/Kernel/inc/MantidKernel/V3D.h index 938c88d012b..36547602a3c 100644 --- a/Framework/Kernel/inc/MantidKernel/V3D.h +++ b/Framework/Kernel/inc/MantidKernel/V3D.h @@ -2,9 +2,13 @@ #define MANTID_KERNEL_V3D_H_ #include <cmath> +#include <iosfwd> #include <vector> #include "MantidKernel/DllConfig.h" -#include <nexus/NeXusFile.hpp> + +namespace NeXus { +class File; +} namespace Mantid { namespace Kernel { diff --git a/Framework/Kernel/src/V3D.cpp b/Framework/Kernel/src/V3D.cpp index a3f5c4f8cec..1a95a402e68 100644 --- a/Framework/Kernel/src/V3D.cpp +++ b/Framework/Kernel/src/V3D.cpp @@ -9,6 +9,7 @@ #include "MantidKernel/Exception.h" #include "MantidKernel/Quat.h" #include <boost/math/common_factor.hpp> +#include <nexus/NeXusFile.hpp> namespace Mantid { namespace Kernel { diff --git a/Framework/MDAlgorithms/src/LoadILLAscii.cpp b/Framework/MDAlgorithms/src/LoadILLAscii.cpp index 572e7af1de8..a33d44958c8 100644 --- a/Framework/MDAlgorithms/src/LoadILLAscii.cpp +++ b/Framework/MDAlgorithms/src/LoadILLAscii.cpp @@ -21,6 +21,7 @@ #include "MantidKernel/TimeSeriesProperty.h" #include "MantidKernel/UnitFactory.h" #include "MantidMDAlgorithms/LoadILLAsciiHelper.h" +#include "MantidGeometry/IDetector.h" #include <Poco/TemporaryFile.h> #include <boost/shared_ptr.hpp> -- GitLab