Mantid
Loading...
Searching...
No Matches
LogValueFinder.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
10#include "MantidAPI/Run.h"
11
12#include <algorithm>
13#include <ostream>
14#include <utility>
15
18
24LogValueFinder::LogValueFinder(QStringList wsNames) : m_wsNames(std::move(wsNames)) {}
25
33std::vector<std::string> LogValueFinder::getLogNames() const {
34 std::vector<std::string> logNames;
35 if (m_wsNames.empty()) { // no workspaces = no logs
36 return logNames;
37 }
38
40 const auto &wsName = m_wsNames.first().toStdString();
41 if (ads.doesExist(wsName)) {
42 const auto &workspace = ads.retrieveWS<MatrixWorkspace>(wsName);
43 const auto &logs = workspace->run().getLogData();
44 logNames.reserve(logs.size());
45 std::transform(logs.cbegin(), logs.cend(), std::back_inserter(logNames),
46 [](const auto &log) { return log->name(); });
47 }
48 return logNames;
49}
50
60double LogValueFinder::getLogValue(const QString &logName, const Mantid::Kernel::Math::StatisticType &function,
61 int index) const {
62 if (index > m_wsNames.size() - 1 || index < 0) {
63 std::ostringstream message;
64 message << "Index " << index << " out of range: number of workspaces = " << m_wsNames.size();
65 throw std::invalid_argument(message.str());
66 }
67
68 return getLogValue(logName, function, m_wsNames.at(index));
69}
70
80double LogValueFinder::getLogValue(const QString &logName, const Mantid::Kernel::Math::StatisticType &function,
81 const QString &wsName) const {
83 const auto &workspace = wsName.toStdString();
84 if (ads.doesExist(workspace)) {
85 const auto &ws = ads.retrieveWS<MatrixWorkspace>(workspace);
86 return ws->run().getLogAsSingleValue(logName.toStdString(), function);
87 } else {
88 throw std::invalid_argument("Workspace not found: " + workspace);
89 }
90}
91
92} // namespace MantidQt::MantidWidgets
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
std::vector< std::string > getLogNames() const
Get log names from workspaces.
double getLogValue(const QString &logName, const Mantid::Kernel::Math::StatisticType &function, int index) const
Get log value from workspace position in list.
const QStringList m_wsNames
Workspace names.
LogValueFinder(QStringList wsNames)
Constructor.
const Run & run() const
Run details object access.
double getLogAsSingleValue(const std::string &name, Kernel::Math::StatisticType statistic=Kernel::Math::Mean) const
Definition: LogManager.h:149
Base MatrixWorkspace Abstract Class.
virtual std::size_t size() const =0
Returns the number of single indexable items in the workspace.
Manage the lifetime of a class intended to be a singleton.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
StatisticType
Maps a "statistic" to a number.
Definition: Statistics.h:18
STL namespace.