From a364b1fa690a0036e0924c26e20a8aeb504d0a69 Mon Sep 17 00:00:00 2001 From: Simon Heybrock <simon.heybrock@esss.se> Date: Mon, 11 Dec 2017 09:43:38 +0100 Subject: [PATCH] Re #21181. MPI support for (Find|Mask)DetectorsInShape. --- .../MantidDataHandling/FindDetectorsInShape.h | 7 ++--- .../MantidDataHandling/MaskDetectorsInShape.h | 9 +++---- .../DataHandling/src/MaskDetectorsInShape.cpp | 26 ++++++++++++++----- .../development/AlgorithmMPISupport.rst | 2 ++ 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Framework/DataHandling/inc/MantidDataHandling/FindDetectorsInShape.h b/Framework/DataHandling/inc/MantidDataHandling/FindDetectorsInShape.h index 01c3be19234..492bbdf0e1f 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/FindDetectorsInShape.h +++ b/Framework/DataHandling/inc/MantidDataHandling/FindDetectorsInShape.h @@ -1,10 +1,7 @@ #ifndef MANTID_DATAHANDLING_FINDDETECTORSINSHAPE_H_ #define MANTID_DATAHANDLING_FINDDETECTORSINSHAPE_H_ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/Algorithm.h" +#include "MantidAPI/DistributedAlgorithm.h" namespace Mantid { namespace DataHandling { @@ -55,7 +52,7 @@ namespace DataHandling { File change history is stored at: <https://github.com/mantidproject/mantid>. Code Documentation is available at: <http://doxygen.mantidproject.org> */ -class DLLExport FindDetectorsInShape : public API::Algorithm { +class DLLExport FindDetectorsInShape : public API::DistributedAlgorithm { public: /// Algorithm's name for identification overriding a virtual method const std::string name() const override { return "FindDetectorsInShape"; }; diff --git a/Framework/DataHandling/inc/MantidDataHandling/MaskDetectorsInShape.h b/Framework/DataHandling/inc/MantidDataHandling/MaskDetectorsInShape.h index c16eec1b13f..533fe235fe9 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/MaskDetectorsInShape.h +++ b/Framework/DataHandling/inc/MantidDataHandling/MaskDetectorsInShape.h @@ -1,10 +1,7 @@ #ifndef MANTID_DATAHANDLING_MASKDETECTORSINSHAPE_H_ #define MANTID_DATAHANDLING_MASKDETECTORSINSHAPE_H_ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/Algorithm.h" +#include "MantidAPI/DistributedAlgorithm.h" namespace Mantid { namespace DataHandling { @@ -55,7 +52,7 @@ namespace DataHandling { File change history is stored at: <https://github.com/mantidproject/mantid>. Code Documentation is available at: <http://doxygen.mantidproject.org> */ -class DLLExport MaskDetectorsInShape : public API::Algorithm { +class DLLExport MaskDetectorsInShape : public API::DistributedAlgorithm { public: /// Algorithm's name for identification overriding a virtual method const std::string name() const override { return "MaskDetectorsInShape"; }; @@ -79,7 +76,7 @@ private: const bool includeMonitors); /// Calls MaskDetectors as a Child Algorithm void runMaskDetectors(API::MatrixWorkspace_sptr workspace, - const std::vector<int> detectorIds); + const std::vector<int> &detectorIds); }; } // namespace DataHandling diff --git a/Framework/DataHandling/src/MaskDetectorsInShape.cpp b/Framework/DataHandling/src/MaskDetectorsInShape.cpp index 5d35600abd8..7818ac68eb3 100644 --- a/Framework/DataHandling/src/MaskDetectorsInShape.cpp +++ b/Framework/DataHandling/src/MaskDetectorsInShape.cpp @@ -1,11 +1,14 @@ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- #include "MantidDataHandling/MaskDetectorsInShape.h" +#include "MantidDataHandling/MaskSpectra.h" +#include "MantidAPI/Algorithm.tcc" #include "MantidAPI/MatrixWorkspace.h" +#include "MantidGeometry/Instrument/DetectorInfo.h" #include "MantidKernel/ArrayProperty.h" #include "MantidKernel/MandatoryValidator.h" +#include "MantidIndexing/Conversion.h" +#include "MantidIndexing/GlobalSpectrumIndex.h" +#include "MantidIndexing/IndexInfo.h" namespace Mantid { namespace DataHandling { @@ -70,10 +73,19 @@ std::vector<int> MaskDetectorsInShape::runFindDetectorsInShape( } void MaskDetectorsInShape::runMaskDetectors( - API::MatrixWorkspace_sptr workspace, const std::vector<int> detectorIds) { - IAlgorithm_sptr alg = createChildAlgorithm("MaskDetectors", 0.85, 1.0); - alg->setProperty<std::vector<int>>("DetectorList", detectorIds); - alg->setProperty<MatrixWorkspace_sptr>("Workspace", workspace); + API::MatrixWorkspace_sptr workspace, const std::vector<int> &detectorIds) { + auto alg = createChildAlgorithm("MaskSpectra", 0.85, 1.0); + const auto &detInfo = workspace->detectorInfo(); + std::vector<size_t> detectorIndices; + for (const auto id : detectorIds) + detectorIndices.push_back(detInfo.indexOf(id)); + const auto &globalSpectrumIndices = + workspace->indexInfo().globalSpectrumIndicesFromDetectorIndices( + detectorIndices); + alg->setWorkspaceInputProperties( + "InputWorkspace", workspace, IndexType::WorkspaceIndex, + Indexing::castVector<int64_t>(globalSpectrumIndices)); + alg->setProperty("OutputWorkspace", workspace); try { if (!alg->execute()) { throw std::runtime_error( diff --git a/docs/source/development/AlgorithmMPISupport.rst b/docs/source/development/AlgorithmMPISupport.rst index 3aabbe799e4..52b5f901369 100644 --- a/docs/source/development/AlgorithmMPISupport.rst +++ b/docs/source/development/AlgorithmMPISupport.rst @@ -476,6 +476,7 @@ FilterBadPulses all FilterByLogValue all FilterByTime all FilterEventsByLogValuePreNexus Identical see ``IFileLoader`` +FindDetectorsInShape all Fit MasterOnly, Identical see ``IFittingAlgorithm`` IFileLoader Identical implicitly adds support for many load-algorithms inheriting from this IFittingAlgorithm MasterOnly, Identical implicitly adds support for several fit-algorithms inheriting from this @@ -526,6 +527,7 @@ LoadSwans Identical see ``IFileLoader`` LoadTBL Identical see ``IFileLoader`` LoadTOFRawNexus Identical see ``IFileLoader`` MaskBins all +MaskDetectorsInShape all MaskSpectra all Minus all see ``BinaryOperation`` MoveInstrumentComponent all -- GitLab