16#include <boost/algorithm/string.hpp>
24double roundToPrecision(
double value,
double precision) {
return value - std::remainder(
value, precision); }
26std::pair<double, double> roundRangeToPrecision(
double rangeStart,
double rangeEnd,
double precision) {
27 return std::pair<double, double>(roundToPrecision(rangeStart, precision) + precision,
28 roundToPrecision(rangeEnd, precision) - precision);
31auto const regDigits = std::regex(
"\\d+");
34namespace MantidWidgets {
35namespace WorkspaceUtils {
46 const auto numberOfHistograms =
workspace->getNumberHistograms();
47 if (numberOfHistograms > 0)
48 return numberOfHistograms - 1;
69 auto const lastUnderscoreIndex = wsName.find_last_of(
"_");
70 if (lastUnderscoreIndex == wsName.npos)
72 return wsName.substr(lastUnderscoreIndex + 1);
85 auto lastUnderscoreIndex = wsName.find_last_of(
"_");
86 if (lastUnderscoreIndex == wsName.npos)
89 return wsName.substr(0, lastUnderscoreIndex);
100 const size_t &axisIndex) {
103 return std::unordered_map<std::string, size_t>();
105 auto *textAxis =
static_cast<TextAxis *
>(axis);
106 std::unordered_map<std::string, size_t> labels;
108 for (
size_t i = 0; i < textAxis->length(); ++i)
109 labels[textAxis->label(i)] = i;
124 std::string xUnitName = xUnit->caption();
126 g_log.
debug() <<
"X unit name is: " << xUnitName <<
'\n';
127 if (boost::algorithm::find_first(xUnitName,
"d-Spacing"))
145 if (inst->hasParameter(
"analyser")) {
146 auto const analyserName = inst->getStringParameter(
"analyser")[0];
147 auto const analyserComp = inst->getComponentByName(analyserName !=
"fmica" ? analyserName :
"mica");
149 if (analyserComp && analyserComp->hasParameter(
"Efixed"))
150 return analyserComp->getNumberParameter(
"Efixed")[0];
154 if (inst->hasParameter(
"Efixed"))
155 return inst->getNumberParameter(
"Efixed")[0];
181 std::pair<double, double> &res) {
183 auto const instrument =
workspace->getInstrument();
184 if (instrument && instrument->hasParameter(
"analyser")) {
185 auto const analyser = instrument->getStringParameter(
"analyser");
186 if (analyser.size() > 0) {
187 auto comp = instrument->getComponentByName(analyser[0]);
189 auto params = comp->getNumberParameter(
"resolution",
true);
192 if (params.size() > 0) {
193 res = std::pair(-params[0], params[0]);
204 auto const &ads = AnalysisDataService::Instance();
205 if (ads.doesExist(workspaceName))
207 return std::pair<double, double>(0.0, 0.0);
211 double precision, std::size_t wsIndex) {
213 if (wsIndex >=
workspace->getNumberHistograms())
215 auto const &xValues =
workspace->x(wsIndex);
216 return roundRangeToPrecision(xValues.front(), xValues.back(), precision);
220 return AnalysisDataService::Instance().doesExist(workspaceName);
224 return AnalysisDataService::Instance().doAllWsExist(workspaceNames);
229 AnalysisDataService::Instance().remove(workspaceName);
253 auto const &axis = ws->getAxis(1);
254 if (!axis->isNumeric()) {
255 auto numericAxis = std::make_unique<NumericAxis>(ws->getNumberHistograms());
256 for (
size_t i = 0; i < ws->getNumberHistograms(); ++i) {
257 numericAxis->setValue(i, axis->getValue(i));
259 ws->replaceAxis(1, std::move(numericAxis));
262 auto const unitID = ws->getAxis(1)->unit()->unitID();
263 if (unitID ==
"Empty" || unitID ==
"Label") {
264 ws->getAxis(1)->setUnit(
"MomentumTransfer");
268std::vector<std::string>
attachPrefix(std::vector<std::string>
const &strings, std::string
const &prefix) {
269 return transformElements(strings.begin(), strings.end(), [&prefix](std::string
const &str) { return prefix + str; });
283 [](
auto &
name) { return name.substr(0, name.find_first_of(
'_')); });
285 std::vector<int> runNumbers;
287 if (workspaceNames.empty()) {
288 return std::string(
"");
290 std::string suffix = workspaceNames[0].substr(workspaceNames[0].find_first_of(
'_'));
291 for (
auto const &
name : names)
292 if (std::regex_search(
name, match, regDigits)) {
293 runNumbers.push_back(std::stoi(match.str(0)));
295 prefix = match.prefix().str();
297 if (runNumbers.empty() || runNumbers.size() == 1)
298 return workspaceNames[0];
300 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)