Commit 1c21c454 authored by Nick Draper's avatar Nick Draper
Browse files

Merge remote-tracking branch 'origin' into 15450_specid_t_to_specnum_t

re #15450
# Conflicts:
#	Framework/API/inc/MantidAPI/MatrixWorkspace.h
#	Framework/API/src/MatrixWorkspace.cpp
#	Framework/Algorithms/src/GeneratePeaks.cpp
#	Framework/Algorithms/src/GetEi.cpp
#	Framework/DataHandling/inc/MantidDataHandling/EventWorkspaceCollection.h
#	Framework/DataHandling/src/EventWorkspaceCollection.cpp
#	Framework/DataHandling/test/LoadISISNexusTest.h
parents 4be4e5a6 377089d0
......@@ -5,7 +5,7 @@
// Includes
//----------------------------------------------------------------------
#include <vector>
#include <set>
#include <unordered_set>
#include <sstream>
#include "MantidAPI/DllConfig.h"
#include "MantidKernel/DynamicFactory.h"
......@@ -57,7 +57,7 @@ class Algorithm;
File change history is stored at: <https://github.com/mantidproject/mantid>
*/
class MANTID_API_DLL AlgorithmFactoryImpl
class MANTID_API_DLL AlgorithmFactoryImpl final
: public Kernel::DynamicFactory<Algorithm> {
public:
// Unhide the base class version (to satisfy the intel compiler)
......@@ -126,7 +126,8 @@ public:
int highestVersion(const std::string &algorithmName) const;
/// Get the algorithm categories
const std::set<std::string> getCategories(bool includeHidden = false) const;
const std::unordered_set<std::string>
getCategories(bool includeHidden = false) const;
/// Get the algorithm categories
const std::map<std::string, bool> getCategoriesWithState() const;
......@@ -162,7 +163,7 @@ private:
/// creates an algorithm name convolved from an name and version
std::string createName(const std::string &, const int &) const;
/// fills a set with the hidden categories
void fillHiddenCategories(std::set<std::string> *categorySet) const;
void fillHiddenCategories(std::unordered_set<std::string> *categorySet) const;
/// A typedef for the map of algorithm versions
typedef std::map<std::string, int> VersionMap;
......
......@@ -60,7 +60,7 @@ typedef std::set<AlgorithmHistory_sptr,
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_API_DLL AlgorithmHistory {
class MANTID_API_DLL AlgorithmHistory final {
public:
/// History container
......
......@@ -56,7 +56,7 @@ class WorkspaceGroup;
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport AnalysisDataServiceImpl
class DLLExport AnalysisDataServiceImpl final
: public Kernel::DataService<API::Workspace> {
public:
/** @name Extra notifications only applicable to the ADS */
......
......@@ -51,7 +51,7 @@ class Expression;
File change history is stored at: <https://github.com/mantidproject/mantid>
*/
class MANTID_API_DLL ConstraintFactoryImpl
class MANTID_API_DLL ConstraintFactoryImpl final
: public Kernel::DynamicFactory<IConstraint> {
public:
/// Creates an instance of a Constraint
......
......@@ -10,7 +10,7 @@
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
namespace Mantid {
namespace API {
......@@ -56,7 +56,7 @@ public:
Expression(const std::vector<std::string> &ops);
/// contructor
Expression(const std::vector<std::string> &binary,
const std::set<std::string> &unary);
const std::unordered_set<std::string> &unary);
/// copy contructor
Expression(const Expression &expr);
/// Assignment operator
......@@ -104,7 +104,7 @@ public:
/// This method returns first sub-expression without brackets
const Expression &bracketsRemoved() const;
/// Return a list of all variable names in this expression
std::set<std::string> getVariables() const;
std::unordered_set<std::string> getVariables() const;
/**
* Rename all variables with a given name
* @param oldName :: The old name
......@@ -192,10 +192,10 @@ private:
struct Operators {
std::vector<std::string>
binary; ///< Binary operators in reverse precedence order
std::set<std::string> unary; ///< Unary operators
std::unordered_set<std::string> unary; ///< Unary operators
std::map<std::string, size_t>
precedence; ///< Map of the operator precedence order
std::set<char>
std::unordered_set<char>
symbols; ///< All the symbols that are used in the binary operators
std::map<std::string, char> op_number; ///< map of operators
};
......@@ -215,7 +215,7 @@ private:
* Adds new unary operators to the expression
* @param ops :: A vector with unary operators
*/
void add_unary(const std::set<std::string> &ops);
void add_unary(const std::unordered_set<std::string> &ops);
/**
* Check if a string is a unary operator
* @param op :: The string to check
......
......@@ -52,7 +52,7 @@ class Expression;
File change history is stored at: <https://github.com/mantidproject/mantid>
*/
class MANTID_API_DLL FunctionFactoryImpl
class MANTID_API_DLL FunctionFactoryImpl final
: public Kernel::DynamicFactory<IFunction> {
public:
/**Creates an instance of a function
......
......@@ -91,11 +91,9 @@ public:
virtual size_t getLinearIndex(size_t index1, size_t index2, size_t index3,
size_t index4) const = 0;
virtual void getLineData(const Mantid::Kernel::VMD &start,
const Mantid::Kernel::VMD &end,
Mantid::API::MDNormalization normalize,
std::vector<coord_t> &x, std::vector<signal_t> &y,
std::vector<signal_t> &e) const = 0;
virtual LinePlot
getLineData(const Mantid::Kernel::VMD &start, const Mantid::Kernel::VMD &end,
Mantid::API::MDNormalization normalize) const = 0;
virtual double &operator[](const size_t &index) = 0;
......
......@@ -74,6 +74,15 @@ public:
IMDWorkspace();
~IMDWorkspace() override;
/**
* Holds X, Y, E for a line plot
*/
struct LinePlot {
std::vector<coord_t> x;
std::vector<signal_t> y;
std::vector<signal_t> e;
};
/// Returns a clone of the workspace
std::unique_ptr<IMDWorkspace> clone() const {
return std::unique_ptr<IMDWorkspace>(doClone());
......@@ -110,11 +119,9 @@ public:
const Mantid::API::MDNormalization &normalization) const = 0;
/// Method to generate a line plot through a MD-workspace
virtual void getLinePlot(const Mantid::Kernel::VMD &start,
const Mantid::Kernel::VMD &end,
Mantid::API::MDNormalization normalize,
std::vector<coord_t> &x, std::vector<signal_t> &y,
std::vector<signal_t> &e) const;
virtual LinePlot getLinePlot(const Mantid::Kernel::VMD &start,
const Mantid::Kernel::VMD &end,
Mantid::API::MDNormalization normalize) const;
IMDIterator *createIterator(
Mantid::Geometry::MDImplicitFunction *function = nullptr) const;
......
......@@ -127,18 +127,20 @@ public:
spec2index_map getSpectrumToWorkspaceIndexMap() const;
detid2index_map
getDetectorIDToWorkspaceIndexMap(bool throwIfMultipleDets = false) const;
virtual void
getDetectorIDToWorkspaceIndexVector(std::vector<size_t> &out, detid_t &offset,
virtual std::vector<size_t>
getDetectorIDToWorkspaceIndexVector(detid_t &offset,
bool throwIfMultipleDets = false) const;
virtual void getSpectrumToWorkspaceIndexVector(std::vector<size_t> &out,
specnum_t &offset) const;
void getIndicesFromSpectra(const std::vector<specnum_t> &spectraList,
std::vector<size_t> &indexList) const;
std::vector<specnum_t> &spectraList) const;
virtual std::vector<size_t>
getSpectrumToWorkspaceIndexVector(specnum_t &offset) const;
std::vector<size_t>
getIndicesFromSpectra(const std::vector<specnum_t> &spectraList) const;
size_t getIndexFromSpectrumNumber(const specnum_t specNo) const;
void getIndicesFromDetectorIDs(const std::vector<detid_t> &detIdList,
std::vector<size_t> &indexList) const;
void getSpectraFromDetectorIDs(const std::vector<detid_t> &detIdList,
std::vector<specnum_t> &spectraList) const;
std::vector<size_t>
getIndicesFromDetectorIDs(const std::vector<detid_t> &detIdList) const;
std::vector<specnum_t>
getSpectraFromDetectorIDs(const std::vector<detid_t> &detIdList) const;
bool hasGroupedDetectors() const;
......@@ -405,11 +407,9 @@ public:
/// Dimensin id for y-dimension.
static const std::string yDimensionId;
/// Generate a line plot through the matrix workspace.
void getLinePlot(const Mantid::Kernel::VMD &start,
const Mantid::Kernel::VMD &end,
Mantid::API::MDNormalization normalize,
std::vector<coord_t> &x, std::vector<signal_t> &y,
std::vector<signal_t> &e) const override;
LinePlot getLinePlot(const Mantid::Kernel::VMD &start,
const Mantid::Kernel::VMD &end,
Mantid::API::MDNormalization normalize) const override;
/// Get the signal at a coordinate in the workspace.
signal_t getSignalAtCoord(
const coord_t *coords,
......
......@@ -45,7 +45,7 @@ namespace API {
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_API_DLL ParameterTie : public ParameterReference {
class MANTID_API_DLL ParameterTie final : public ParameterReference {
public:
/// Constructor
ParameterTie(IFunction *funct, const std::string &parName,
......
......@@ -38,7 +38,7 @@ class Algorithm;
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_API_DLL Progress : public Mantid::Kernel::ProgressBase {
class MANTID_API_DLL Progress final : public Mantid::Kernel::ProgressBase {
public:
Progress();
Progress(Algorithm *alg, double start, double end, int numSteps);
......
......@@ -30,7 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_API_DLL PropertyManagerDataServiceImpl
class MANTID_API_DLL PropertyManagerDataServiceImpl final
: public Mantid::Kernel::DataService<Mantid::Kernel::PropertyManager> {
private:
friend struct Mantid::Kernel::CreateUsingNew<PropertyManagerDataServiceImpl>;
......
......@@ -63,8 +63,8 @@ public:
specnum_t spectraNo(const std::size_t &index) const override;
// Get a map that contains the spectra index as the key and the index in the
// array as teh value
void getSpectraIndexMap(spec2index_map &) const;
// array as the value
spec2index_map getSpectraIndexMap() const;
double getMin() const override;
double getMax() const override;
......
......@@ -322,8 +322,7 @@ public:
if (this->direction() == Kernel::Direction::Input ||
this->direction() == Kernel::Direction::InOut) {
// If an input workspace, get the list of workspaces currently in the ADS
std::set<std::string> vals =
AnalysisDataService::Instance().getObjectNames();
auto vals = AnalysisDataService::Instance().getObjectNames();
if (isOptional()) // Insert an empty option
{
vals.insert("");
......@@ -331,8 +330,7 @@ public:
// Copy-construct a temporary workspace property to test the validity of
// each workspace
WorkspaceProperty<TYPE> tester(*this);
std::set<std::string>::iterator it;
for (it = vals.begin(); it != vals.end();) {
for (auto it = vals.begin(); it != vals.end();) {
// Remove any workspace that's not valid for this algorithm
if (!tester.setValue(*it).empty()) {
vals.erase(
......
......@@ -178,7 +178,7 @@ AlgorithmFactoryImpl::getKeys(bool includeHidden) const {
return names;
} else {
// hidden categories
std::set<std::string> hiddenCategories;
std::unordered_set<std::string> hiddenCategories;
fillHiddenCategories(&hiddenCategories);
// strip out any algorithms names where all of the categories are hidden
......@@ -245,7 +245,7 @@ AlgorithmFactoryImpl::getCategoriesWithState() const {
std::map<std::string, bool> resultCategories;
// hidden categories - empty initially
std::set<std::string> hiddenCategories;
std::unordered_set<std::string> hiddenCategories;
fillHiddenCategories(&hiddenCategories);
// get all of the algorithm keys, including the hidden ones for speed purposes
......@@ -287,20 +287,18 @@ AlgorithmFactoryImpl::getCategoriesWithState() const {
* the default is false
* @returns The category strings
*/
const std::set<std::string>
const std::unordered_set<std::string>
AlgorithmFactoryImpl::getCategories(bool includeHidden) const {
std::set<std::string> validCategories;
std::unordered_set<std::string> validCategories;
// get all of the information we need
std::map<std::string, bool> categoryMap = getCategoriesWithState();
auto categoryMap = getCategoriesWithState();
// iterate around the map
std::map<std::string, bool>::const_iterator it_end = categoryMap.end();
for (std::map<std::string, bool>::const_iterator it = categoryMap.begin();
it != it_end; ++it) {
bool isHidden = (*it).second;
for (auto const &category : categoryMap) {
bool isHidden = (category).second;
if (includeHidden || (!isHidden)) {
validCategories.insert((*it).first);
validCategories.insert((category).first);
}
}
......@@ -319,20 +317,18 @@ AlgorithmFactoryImpl::getCategories(bool includeHidden) const {
std::vector<Algorithm_descriptor>
AlgorithmFactoryImpl::getDescriptors(bool includeHidden) const {
// algorithm names
std::vector<std::string> sv;
sv = getKeys(true);
auto sv = getKeys(true);
// hidden categories
std::set<std::string> hiddenCategories;
if (includeHidden == false) {
std::unordered_set<std::string> hiddenCategories;
if (!includeHidden) {
fillHiddenCategories(&hiddenCategories);
}
// results vector
std::vector<Algorithm_descriptor> res;
for (std::vector<std::string>::const_iterator s = sv.begin(); s != sv.end();
++s) {
for (auto s = sv.cbegin(); s != sv.cend(); ++s) {
if (s->empty())
continue;
Algorithm_descriptor desc;
......@@ -348,7 +344,7 @@ AlgorithmFactoryImpl::getDescriptors(bool includeHidden) const {
continue;
boost::shared_ptr<IAlgorithm> alg = create(desc.name, desc.version);
std::vector<std::string> categories = alg->categories();
auto categories = alg->categories();
desc.alias = alg->alias();
// For each category
......@@ -387,7 +383,7 @@ AlgorithmFactoryImpl::getDescriptors(bool includeHidden) const {
}
void AlgorithmFactoryImpl::fillHiddenCategories(
std::set<std::string> *categorySet) const {
std::unordered_set<std::string> *categorySet) const {
std::string categoryString = Kernel::ConfigService::Instance().getString(
"algorithms.categories.hidden");
Mantid::Kernel::StringTokenizer tokenizer(
......
......@@ -790,18 +790,14 @@ std::string ExperimentInfo::getAvailableWorkspaceEndDate() const {
//---------------------------------------------------------------------------------------
/** A given instrument may have multiple IDFs associated with it. This method
*return an
* identifier which identify a given IDF for a given instrument. An IDF filename
*is
* required to be of the form IDFname + _Definition + Identifier + .xml, the
*identifier
* then is the part of a filename that identifies the IDF valid at a given date.
*return an identifier which identify a given IDF for a given instrument.
* An IDF filename is required to be of the form IDFname + _Definition +
*Identifier + .xml, the identifier then is the part of a filename that
*identifies the IDF valid at a given date.
*
* If several IDF files are valid at the given date the file with the most
*recent from
* date is selected. If no such files are found the file with the latest from
*date is
* selected.
*recent from date is selected. If no such files are found the file with the
*latest from date is selected.
*
* If no file is found for the given instrument, an empty string is returned.
*
......
......@@ -24,7 +24,7 @@ Expression::Expression() {
add_operators(ops);
// Define unary operators
std::set<std::string> unary;
std::unordered_set<std::string> unary;
unary.insert("+");
unary.insert("-");
......@@ -39,7 +39,7 @@ Expression::Expression(const std::vector<std::string> &ops) {
/// contructor
Expression::Expression(const std::vector<std::string> &binary,
const std::set<std::string> &unary) {
const std::unordered_set<std::string> &unary) {
m_operators.reset(new Operators());
add_operators(binary);
add_unary(unary);
......@@ -86,7 +86,7 @@ void Expression::add_operators(const std::vector<std::string> &ops) {
}
}
void Expression::add_unary(const std::set<std::string> &ops) {
void Expression::add_unary(const std::unordered_set<std::string> &ops) {
m_operators->unary = ops;
for (const auto &op : ops) {
m_operators->symbols.insert(op.cbegin(), op.cend());
......@@ -479,8 +479,8 @@ const Expression &Expression::bracketsRemoved() const {
/**
* Return a list of all variable names in this expression
*/
std::set<std::string> Expression::getVariables() const {
std::set<std::string> out;
std::unordered_set<std::string> Expression::getVariables() const {
std::unordered_set<std::string> out;
if (!isFunct()) {
std::string s = name();
if (!s.empty() && !isdigit(s[0])) {
......@@ -489,7 +489,7 @@ std::set<std::string> Expression::getVariables() const {
} else {
for (const auto &e : *this) {
if (e.isFunct()) {
std::set<std::string> tout = e.getVariables();
std::unordered_set<std::string> tout = e.getVariables();
out.insert(tout.begin(), tout.end());
} else {
std::string s = e.name();
......
......@@ -134,41 +134,36 @@ const std::string IMDWorkspace::toString() const {
* @param start :: coordinates of the start point of the line
* @param end :: coordinates of the end point of the line
* @param normalize :: how to normalize the signal
* @param x :: is set to the boundaries of the bins, relative to start of the
*line.
* @param y :: is set to the normalized signal for each bin. Length = length(x)
*- 1
* @param e :: is set to the normalized errors for each bin. Length = length(x)
*- 1
* @returns :: a LinePlot in which x is set to the boundaries of the bins,
* relative to start of the line, y is set to the normalized signal for
* each bin with Length = length(x) - 1 and e is set to the normalized
* errors for each bin with Length = length(x) - 1.
*/
void IMDWorkspace::getLinePlot(const Mantid::Kernel::VMD &start,
const Mantid::Kernel::VMD &end,
Mantid::API::MDNormalization normalize,
std::vector<coord_t> &x,
std::vector<signal_t> &y,
std::vector<signal_t> &e) const {
IMDWorkspace::LinePlot
IMDWorkspace::getLinePlot(const Mantid::Kernel::VMD &start,
const Mantid::Kernel::VMD &end,
Mantid::API::MDNormalization normalize) const {
// TODO: Don't use a fixed number of points later
size_t numPoints = 200;
VMD step = (end - start) / double(numPoints);
double stepLength = step.norm();
// These will be the curve as plotted
x.clear();
y.clear();
e.clear();
// This will be the curve as plotted
LinePlot line;
for (size_t i = 0; i < numPoints; i++) {
// Coordinate along the line
VMD coord = start + step * double(i);
// Record the position along the line
x.push_back(static_cast<coord_t>(stepLength * double(i)));
line.x.push_back(static_cast<coord_t>(stepLength * double(i)));
signal_t yVal = this->getSignalAtCoord(coord.getBareArray(), normalize);
y.push_back(yVal);
e.push_back(0.0);
line.y.push_back(yVal);
line.e.push_back(0.0);
}
// And the last point
x.push_back((end - start).norm());
line.x.push_back((end - start).norm());
return line;
}
/**
......
......@@ -296,9 +296,8 @@ MatrixWorkspace::getNeighbours(const Geometry::IDetector *comp,
buildNearestNeighbours(ignoreMaskedDetectors);
}
// Find the spectrum number
std::vector<specnum_t> spectra;
this->getSpectraFromDetectorIDs(std::vector<detid_t>(1, comp->getID()),
spectra);
std::vector<specnum_t> spectra =
this->getSpectraFromDetectorIDs(std::vector<detid_t>(1, comp->getID()));
if (spectra.empty()) {
throw Kernel::Exception::NotFoundError("MatrixWorkspace::getNeighbours - "
"Cannot find spectrum number for "
......@@ -363,14 +362,13 @@ spec2index_map MatrixWorkspace::getSpectrumToWorkspaceIndexMap() const {
throw std::runtime_error("MatrixWorkspace::getSpectrumToWorkspaceIndexMap: "
"axis[1] is not a SpectraAxis, so I cannot "
"generate a map.");
spec2index_map map;
try {
ax->getSpectraIndexMap(map);
return ax->getSpectraIndexMap();
} catch (std::runtime_error &) {
throw std::runtime_error(
"MatrixWorkspace::getSpectrumToWorkspaceIndexMap: no elements!");
g_log.error()
<< "MatrixWorkspace::getSpectrumToWorkspaceIndexMap: no elements!";
throw;
}
return map;
}
//---------------------------------------------------------------------------------------
......@@ -378,12 +376,12 @@ spec2index_map MatrixWorkspace::getSpectrumToWorkspaceIndexMap() const {
* The index into the vector = spectrum number + offset
* The value at that index = the corresponding Workspace Index
*
* @param out :: vector set to above definition
* @returns :: vector set to above definition
* @param offset :: add this to the detector ID to get the index into the
*vector.
*/
void MatrixWorkspace::getSpectrumToWorkspaceIndexVector(
std::vector<size_t> &out, specnum_t &offset) const {
std::vector<size_t>
MatrixWorkspace::getSpectrumToWorkspaceIndexVector(specnum_t &offset) const {
SpectraAxis *ax = dynamic_cast<SpectraAxis *>(this->m_axes[1]);
if (!ax)
throw std::runtime_error("MatrixWorkspace::getSpectrumToWorkspaceIndexMap: "
......@@ -408,14 +406,16 @@ void MatrixWorkspace::getSpectrumToWorkspaceIndexVector(
// Offset so that the "min" value goes to index 0
offset = -min;
// Resize correctly
out.resize(max - min + 1, 0);
// Size correctly
std::vector<size_t> out(max - min + 1, 0);
// Make the vector
for (size_t i = 0; i < length; i++) {
specnum_t spec = ax->spectraNo(i);
out[spec + offset] = i;
}
return out;
}
//---------------------------------------------------------------------------------------
......@@ -486,19 +486,18 @@ detid2index_map MatrixWorkspace::getDetectorIDToWorkspaceIndexMap(
* The index into the vector = DetectorID (pixel ID) + offset
* The value at that index = the corresponding Workspace Index
*
* @param out :: vector set to above definition
* @param offset :: add this to the detector ID to get the index into the
*vector.
* @param throwIfMultipleDets :: set to true to make the algorithm throw an
*error
* if there is more than one detector for a specific workspace index.
*error if there is more than one detector for a specific workspace index.
* @throw runtime_error if there is more than one detector per spectrum (if
*throwIfMultipleDets is true)
* @returns :: vector set to above definition
*/
void MatrixWorkspace::getDetectorIDToWorkspaceIndexVector(
std::vector<size_t> &out, detid_t &offset, bool throwIfMultipleDets) const {
std::vector<size_t> MatrixWorkspace::getDetectorIDToWorkspaceIndexVector(
detid_t &offset, bool throwIfMultipleDets) const {
// Make a correct initial size
out.clear();
std::vector<size_t> out;
detid_t minId = 0;
detid_t maxId = 0;
this->getInstrument()->getMinMaxDetectorIDs(minId, maxId);
......@@ -534,6 +533,7 @@ void MatrixWorkspace::getDetectorIDToWorkspaceIndexVector(
}
} // (for each workspace index)
return out;
}
//---------------------------------------------------------------------------------------
......@@ -541,14 +541,12 @@ void MatrixWorkspace::getDetectorIDToWorkspaceIndexVector(
* Not a very efficient operation, but unfortunately it's sometimes required.
*