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 "QPair"
14#include <optional>
15#include <string>
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
28
29EXPORT_OPT_MANTIDQT_COMMON bool getResolutionRangeFromWs(const std::string &workspace, std::pair<double, double> &res);
31 std::pair<double, double> &res);
32
33EXPORT_OPT_MANTIDQT_COMMON std::pair<double, double>
35EXPORT_OPT_MANTIDQT_COMMON std::pair<double, double> getXRangeFromWorkspace(std::string const &workspaceName,
36 double precision = 0.000001);
37
39EXPORT_OPT_MANTIDQT_COMMON std::string getIndexString(const std::string &workspaceName);
40
41EXPORT_OPT_MANTIDQT_COMMON bool doesExistInADS(std::string const &workspaceName);
42EXPORT_OPT_MANTIDQT_COMMON bool doAllWsExistInADS(std::vector<std::string> const &workspaceNames);
43
44template <typename T = Mantid::API::MatrixWorkspace>
45std::shared_ptr<T> getADSWorkspace(std::string const &workspaceName) {
46 return Mantid::API::AnalysisDataService::Instance().retrieveWS<T>(workspaceName);
47}
48
49template EXPORT_OPT_MANTIDQT_COMMON std::shared_ptr<Mantid::API::MatrixWorkspace_sptr>
50getADSWorkspace(std::string const &workspaceName);
51template EXPORT_OPT_MANTIDQT_COMMON std::shared_ptr<Mantid::API::WorkspaceGroup_sptr>
52getADSWorkspace(std::string const &workspaceName);
53template EXPORT_OPT_MANTIDQT_COMMON std::shared_ptr<Mantid::API::ITableWorkspace_sptr>
54getADSWorkspace(std::string const &workspaceName);
55
56template <typename Iterator, typename Functor>
57std::vector<std::string> transformElements(Iterator const fromIter, Iterator const toIter, Functor const &functor) {
58 std::vector<std::string> newVector;
59 newVector.reserve(toIter - fromIter);
60 std::transform(fromIter, toIter, std::back_inserter(newVector), functor);
61 return newVector;
62}
63
64template <typename T, typename Predicate> void removeElementsIf(std::vector<T> &vector, Predicate const &filter) {
65 auto const iter = std::remove_if(vector.begin(), vector.end(), filter);
66 if (iter != vector.end())
67 vector.erase(iter, vector.end());
68}
69
70EXPORT_OPT_MANTIDQT_COMMON std::vector<std::string> attachPrefix(std::vector<std::string> const &strings,
71 std::string const &prefix);
72
73EXPORT_OPT_MANTIDQT_COMMON std::string parseRunNumbers(std::vector<std::string> const &workspaceNames);
74} // namespace WorkspaceUtils
75} // namespace MantidWidgets
76} // 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::pair< double, double > getXRangeFromWorkspace(const Mantid::API::MatrixWorkspace_const_sptr &workspace, double precision=0.00001)
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::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