Mantid
Loading...
Searching...
No Matches
WorkspaceUtils.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8#include "DllOption.h"
13#include <optional>
14#include <string>
15#include <utility>
16
17namespace MantidQt {
18namespace MantidWidgets {
19namespace WorkspaceUtils {
20
21EXPORT_OPT_MANTIDQT_COMMON std::string getWorkspaceSuffix(const std::string &wsName);
22EXPORT_OPT_MANTIDQT_COMMON std::string getWorkspaceBasename(const std::string &wsName);
23EXPORT_OPT_MANTIDQT_COMMON std::unordered_map<std::string, size_t>
25
26EXPORT_OPT_MANTIDQT_COMMON void setNumericQAxis(std::string const &workspaceName);
27
30
31EXPORT_OPT_MANTIDQT_COMMON bool getResolutionRangeFromWs(const std::string &workspace, std::pair<double, double> &res);
33 std::pair<double, double> &res);
34
35EXPORT_OPT_MANTIDQT_COMMON std::pair<double, double>
37 std::size_t wsIndex = 0);
38EXPORT_OPT_MANTIDQT_COMMON std::pair<double, double> getXRangeFromWorkspace(std::string const &workspaceName,
39 double precision = 0.000001);
40
42EXPORT_OPT_MANTIDQT_COMMON std::string getIndexString(const std::string &workspaceName);
43
44EXPORT_OPT_MANTIDQT_COMMON bool doesExistInADS(std::string const &workspaceName);
45EXPORT_OPT_MANTIDQT_COMMON bool doAllWsExistInADS(std::vector<std::string> const &workspaceNames);
46
47template <typename T = Mantid::API::MatrixWorkspace>
48std::shared_ptr<T> getADSWorkspace(std::string const &workspaceName) {
49 return Mantid::API::AnalysisDataService::Instance().retrieveWS<T>(workspaceName);
50}
51
52template EXPORT_OPT_MANTIDQT_COMMON std::shared_ptr<Mantid::API::MatrixWorkspace_sptr>
53getADSWorkspace(std::string const &workspaceName);
54template EXPORT_OPT_MANTIDQT_COMMON std::shared_ptr<Mantid::API::WorkspaceGroup_sptr>
55getADSWorkspace(std::string const &workspaceName);
56template EXPORT_OPT_MANTIDQT_COMMON std::shared_ptr<Mantid::API::ITableWorkspace_sptr>
57getADSWorkspace(std::string const &workspaceName);
58
59EXPORT_OPT_MANTIDQT_COMMON void removeADSWorkspace(std::string const &workspaceName);
60
61template <typename Iterator, typename Functor>
62std::vector<std::string> transformElements(Iterator const fromIter, Iterator const toIter, Functor const &functor) {
63 std::vector<std::string> newVector;
64 newVector.reserve(toIter - fromIter);
65 std::transform(fromIter, toIter, std::back_inserter(newVector), functor);
66 return newVector;
67}
68
69template <typename T, typename Predicate> void removeElementsIf(std::vector<T> &vector, Predicate const &filter) {
70 auto const iter = std::remove_if(vector.begin(), vector.end(), filter);
71 if (iter != vector.end())
72 vector.erase(iter, vector.end());
73}
74
75EXPORT_OPT_MANTIDQT_COMMON std::vector<std::string> attachPrefix(std::vector<std::string> const &strings,
76 std::string const &prefix);
77
78EXPORT_OPT_MANTIDQT_COMMON std::string parseRunNumbers(std::vector<std::string> const &workspaceNames);
79} // namespace WorkspaceUtils
80} // namespace MantidWidgets
81} // namespace MantidQt
#define EXPORT_OPT_MANTIDQT_COMMON
Definition DllOption.h:15
IPeaksWorkspace_sptr workspace
EXPORT_OPT_MANTIDQT_COMMON std::string getIndexString(const std::string &workspaceName)
EXPORT_OPT_MANTIDQT_COMMON std::string getWorkspaceBasename(const std::string &wsName)
Returns the basename of a workspace (i.e.
EXPORT_OPT_MANTIDQT_COMMON std::optional< std::size_t > maximumIndex(const Mantid::API::MatrixWorkspace_sptr &workspace)
Gets the maximum number of histograms for a 2D Workspace.
EXPORT_OPT_MANTIDQT_COMMON bool getResolutionRangeFromWs(const std::string &workspace, std::pair< double, double > &res)
Checks the workspace's instrument for a resolution parameter to use as a default for the energy range...
std::shared_ptr< T > getADSWorkspace(std::string const &workspaceName)
EXPORT_OPT_MANTIDQT_COMMON bool doesExistInADS(std::string const &workspaceName)
EXPORT_OPT_MANTIDQT_COMMON std::string getEMode(const Mantid::API::MatrixWorkspace_sptr &ws)
Gets the energy mode from a workspace based on the X unit.
EXPORT_OPT_MANTIDQT_COMMON std::string parseRunNumbers(std::vector< std::string > const &workspaceNames)
Checks the name of the input workspace against a regexp for prefixes in the form instrName\#runNumber...
EXPORT_OPT_MANTIDQT_COMMON std::string getWorkspaceSuffix(const std::string &wsName)
Gets the suffix of a workspace (i.e.
EXPORT_OPT_MANTIDQT_COMMON std::pair< double, double > getXRangeFromWorkspace(const Mantid::API::MatrixWorkspace_const_sptr &workspace, double precision=0.00001, std::size_t wsIndex=0)
EXPORT_OPT_MANTIDQT_COMMON void removeADSWorkspace(std::string const &workspaceName)
EXPORT_OPT_MANTIDQT_COMMON void setNumericQAxis(std::string const &workspaceName)
Ensures the vertical (spectrum) axis of the named workspace is a numeric axis, and labels it with the...
EXPORT_OPT_MANTIDQT_COMMON std::optional< double > getEFixed(const Mantid::API::MatrixWorkspace_sptr &ws)
Gets the eFixed value from the workspace using the instrument parameters.
EXPORT_OPT_MANTIDQT_COMMON std::unordered_map< std::string, size_t > extractAxisLabels(const Mantid::API::MatrixWorkspace_const_sptr &workspace, const size_t &axisIndex)
std::vector< std::string > transformElements(Iterator const fromIter, Iterator const toIter, Functor const &functor)
EXPORT_OPT_MANTIDQT_COMMON bool doAllWsExistInADS(std::vector< std::string > const &workspaceNames)
EXPORT_OPT_MANTIDQT_COMMON std::vector< std::string > attachPrefix(std::vector< std::string > const &strings, std::string const &prefix)
void removeElementsIf(std::vector< T > &vector, Predicate const &filter)
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class