15#include <boost/algorithm/string.hpp>
23double roundToPrecision(
double value,
double precision) {
return value - std::remainder(
value, precision); }
25std::pair<double, double> roundRangeToPrecision(
double rangeStart,
double rangeEnd,
double precision) {
26 return std::pair<double, double>(roundToPrecision(rangeStart, precision) + precision,
27 roundToPrecision(rangeEnd, precision) - precision);
30auto const regDigits = std::regex(
"\\d+");
33namespace MantidWidgets {
34namespace WorkspaceUtils {
45 const auto numberOfHistograms =
workspace->getNumberHistograms();
46 if (numberOfHistograms > 0)
47 return numberOfHistograms - 1;
68 auto const lastUnderscoreIndex = wsName.find_last_of(
"_");
69 if (lastUnderscoreIndex == wsName.npos)
71 return wsName.substr(lastUnderscoreIndex + 1);
84 auto lastUnderscoreIndex = wsName.find_last_of(
"_");
85 if (lastUnderscoreIndex == wsName.npos)
88 return wsName.substr(0, lastUnderscoreIndex);
99 const size_t &axisIndex) {
102 return std::unordered_map<std::string, size_t>();
104 auto *textAxis =
static_cast<TextAxis *
>(axis);
105 std::unordered_map<std::string, size_t> labels;
107 for (
size_t i = 0; i < textAxis->length(); ++i)
108 labels[textAxis->label(i)] = i;
123 std::string xUnitName = xUnit->caption();
125 g_log.
debug() <<
"X unit name is: " << xUnitName <<
'\n';
126 if (boost::algorithm::find_first(xUnitName,
"d-Spacing"))
144 if (inst->hasParameter(
"analyser")) {
145 auto const analyserName = inst->getStringParameter(
"analyser")[0];
146 auto const analyserComp = inst->getComponentByName(analyserName !=
"fmica" ? analyserName :
"mica");
148 if (analyserComp && analyserComp->hasParameter(
"Efixed"))
149 return analyserComp->getNumberParameter(
"Efixed")[0];
153 if (inst->hasParameter(
"Efixed"))
154 return inst->getNumberParameter(
"Efixed")[0];
180 std::pair<double, double> &res) {
182 auto const instrument =
workspace->getInstrument();
183 if (instrument && instrument->hasParameter(
"analyser")) {
184 auto const analyser = instrument->getStringParameter(
"analyser");
185 if (analyser.size() > 0) {
186 auto comp = instrument->getComponentByName(analyser[0]);
188 auto params = comp->getNumberParameter(
"resolution",
true);
191 if (params.size() > 0) {
192 res = std::pair(-params[0], params[0]);
203 auto const &ads = AnalysisDataService::Instance();
204 if (ads.doesExist(workspaceName))
206 return std::pair<double, double>(0.0, 0.0);
213 return roundRangeToPrecision(xValues.front(), xValues.back(), precision);
217 return AnalysisDataService::Instance().doesExist(workspaceName);
221 return AnalysisDataService::Instance().doAllWsExist(workspaceNames);
224std::vector<std::string>
attachPrefix(std::vector<std::string>
const &strings, std::string
const &prefix) {
225 return transformElements(strings.begin(), strings.end(), [&prefix](std::string
const &str) { return prefix + str; });
239 [](
auto &
name) { return name.substr(0, name.find_first_of(
'_')); });
241 std::vector<int> runNumbers;
243 if (workspaceNames.empty()) {
244 return std::string(
"");
246 std::string suffix = workspaceNames[0].substr(workspaceNames[0].find_first_of(
'_'));
247 for (
auto const &
name : names)
248 if (std::regex_search(
name, match, regDigits)) {
249 runNumbers.push_back(std::stoi(match.str(0)));
251 prefix = match.prefix().str();
253 if (runNumbers.empty() || runNumbers.size() == 1)
254 return workspaceNames[0];
256 auto [min, max] = std::minmax_element(runNumbers.cbegin(), runNumbers.cend());
double value
The value of the point.
IPeaksWorkspace_sptr workspace
Class to represent the axis of a workspace.
virtual bool isText() const
Returns true if the axis is Text.
const std::shared_ptr< Kernel::Unit > & unit() const
The unit for this axis.
Base MatrixWorkspace Abstract Class.
Class to represent a text axis of a workspace.
The Logger class is in charge of the publishing messages from the framework through various channels.
void debug(const std::string &msg)
Logs at debug level.
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
Kernel::Logger g_log("ExperimentInfo")
static logger object
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
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
std::shared_ptr< Unit > Unit_sptr
Shared pointer to the Unit base class.
std::string to_string(const wide_integer< Bits, Signed > &n)