17#include <boost/algorithm/string.hpp>
25double roundToPrecision(
double value,
double precision) {
return value - std::remainder(
value, precision); }
27std::pair<double, double> roundRangeToPrecision(
double rangeStart,
double rangeEnd,
double precision) {
28 return std::pair<double, double>(roundToPrecision(rangeStart, precision) + precision,
29 roundToPrecision(rangeEnd, precision) - precision);
32auto const regDigits = std::regex(
"\\d+");
35namespace MantidWidgets {
36namespace WorkspaceUtils {
47 const auto numberOfHistograms =
workspace->getNumberHistograms();
48 if (numberOfHistograms > 0)
49 return numberOfHistograms - 1;
70 auto const lastUnderscoreIndex = wsName.find_last_of(
"_");
71 if (lastUnderscoreIndex == wsName.npos)
73 return wsName.substr(lastUnderscoreIndex + 1);
86 auto lastUnderscoreIndex = wsName.find_last_of(
"_");
87 if (lastUnderscoreIndex == wsName.npos)
90 return wsName.substr(0, lastUnderscoreIndex);
101 const size_t &axisIndex) {
104 return std::unordered_map<std::string, size_t>();
106 auto *textAxis =
static_cast<TextAxis *
>(axis);
107 std::unordered_map<std::string, size_t> labels;
109 for (
size_t i = 0; i < textAxis->length(); ++i)
110 labels[textAxis->label(i)] = i;
125 std::string xUnitName = xUnit->caption();
127 g_log.
debug() <<
"X unit name is: " << xUnitName <<
'\n';
128 if (boost::algorithm::find_first(xUnitName,
"d-Spacing"))
146 if (inst->hasParameter(
"analyser")) {
147 auto const analyserName = inst->getStringParameter(
"analyser")[0];
148 auto const analyserComp = inst->getComponentByName(analyserName !=
"fmica" ? analyserName :
"mica");
150 if (analyserComp && analyserComp->hasParameter(
"Efixed"))
151 return analyserComp->getNumberParameter(
"Efixed")[0];
155 if (inst->hasParameter(
"Efixed"))
156 return inst->getNumberParameter(
"Efixed")[0];
182 std::pair<double, double> &res) {
184 auto const instrument =
workspace->getInstrument();
185 if (instrument && instrument->hasParameter(
"analyser")) {
186 auto const analyser = instrument->getStringParameter(
"analyser");
187 if (analyser.size() > 0) {
188 auto comp = instrument->getComponentByName(analyser[0]);
190 auto params = comp->getNumberParameter(
"resolution",
true);
193 if (params.size() > 0) {
194 res = std::pair(-params[0], params[0]);
205 auto const &ads = AnalysisDataService::Instance();
206 if (ads.doesExist(workspaceName))
208 return std::pair<double, double>(0.0, 0.0);
212 double precision, std::size_t wsIndex) {
214 if (wsIndex >=
workspace->getNumberHistograms())
216 auto const &xValues =
workspace->x(wsIndex);
217 return roundRangeToPrecision(xValues.front(), xValues.back(), precision);
221 return AnalysisDataService::Instance().doesExist(workspaceName);
225 return AnalysisDataService::Instance().doAllWsExist(workspaceNames);
230 AnalysisDataService::Instance().remove(workspaceName);
254 auto const &axis = ws->getAxis(1);
255 if (!axis->isNumeric()) {
256 auto numericAxis = std::make_unique<NumericAxis>(ws->getNumberHistograms());
257 for (
size_t i = 0; i < ws->getNumberHistograms(); ++i) {
258 numericAxis->setValue(i, axis->getValue(i));
260 ws->replaceAxis(1, std::move(numericAxis));
263 auto const unitID = ws->getAxis(1)->unit()->unitID();
264 if (unitID ==
"Empty" || unitID ==
"Label") {
265 ws->getAxis(1)->setUnit(
"MomentumTransfer");
269std::vector<std::string>
attachPrefix(std::vector<std::string>
const &strings, std::string
const &prefix) {
270 return transformElements(strings.begin(), strings.end(), [&prefix](std::string
const &str) { return prefix + str; });
284 [](
auto &
name) { return name.substr(0, name.find_first_of(
'_')); });
286 std::vector<int> runNumbers;
288 if (workspaceNames.empty()) {
289 return std::string(
"");
291 std::string suffix = workspaceNames[0].substr(workspaceNames[0].find_first_of(
'_'));
292 for (
auto const &
name : names)
293 if (std::regex_search(
name, match, regDigits)) {
294 runNumbers.push_back(std::stoi(match.str(0)));
296 prefix = match.prefix().str();
298 if (runNumbers.empty() || runNumbers.size() == 1)
299 return workspaceNames[0];
301 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 Kernel::Unit_sptr & 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)