Mantid
Loading...
Searching...
No Matches
DeleteTableRows.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 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
15
16#include <functional>
17#include <set>
18
19namespace Mantid::DataHandling {
20// Register the algorithm into the algorithm factory
21DECLARE_ALGORITHM(DeleteTableRows)
22
23using namespace Kernel;
24using namespace API;
25
28 declareProperty(std::make_unique<WorkspaceProperty<API::ITableWorkspace>>("TableWorkspace", "", Direction::InOut),
29 "The name of the workspace that will be modified.");
30 declareProperty(std::make_unique<ArrayProperty<size_t>>("Rows"),
31 "A comma-separated list of row numbers. Row numbering starts with 0.");
32}
33
38 API::ITableWorkspace_sptr tw = getProperty("TableWorkspace");
39 API::IPeaksWorkspace_sptr pw = std::dynamic_pointer_cast<API::IPeaksWorkspace>(tw);
40 std::vector<size_t> rows = getProperty("Rows");
41 // sort the row indices in reverse order
42 std::set<size_t, std::greater<size_t>> sortedRows(rows.begin(), rows.end());
43 auto it = sortedRows.begin();
44 for (; it != sortedRows.end(); ++it) {
45 if (*it >= tw->rowCount())
46 continue;
47 if (pw) {
48 pw->removePeak(static_cast<int>(*it));
49 } else {
50 tw->removeRow(*it);
51 }
52 }
53 setProperty("TableWorkspace", tw);
54}
55
56} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
A property class for workspaces.
void init() override
Initialize the static base properties.
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
std::shared_ptr< IPeaksWorkspace > IPeaksWorkspace_sptr
shared pointer to Mantid::API::IPeaksWorkspace
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
@ InOut
Both an input & output workspace.
Definition: Property.h:55