17Kernel::Logger
g_log(
"TableWorkspace");
20struct SortIterationRecord {
21 SortIterationRecord(
size_t ki,
size_t is,
size_t ie) :
keyIndex(ki),
iStart(is),
iEnd(ie) {}
39 auto it = other.m_columns.cbegin();
40 while (it != other.m_columns.cend()) {
41 addColumn(std::shared_ptr<API::Column>((*it)->clone()));
45 m_LogManager = std::make_shared<API::LogManager>(*(other.m_LogManager));
49 size_t data_size = std::accumulate(
m_columns.cbegin(),
m_columns.cend(),
static_cast<size_t>(0),
50 [](
size_t sum,
const auto &column) { return sum = column->sizeOfData(); });
62 throw std::invalid_argument(
"Empty string passed as type argument of addColumn.");
65 throw std::invalid_argument(
"Empty string passed as name argument of addColumn.");
71 ss <<
"Column with name " << name <<
" already exists.\n";
72 throw std::invalid_argument(ss.str());
81 ss <<
"Column of type " << type <<
" and name " << name <<
" has not been added.\n";
82 ss << e.
what() <<
'\n';
83 throw std::invalid_argument(ss.str());
106 std::string str =
"Column " + name +
" does not exist.\n";
107 throw std::runtime_error(str);
114 [&name](
const auto &column) { return column->name() == name; });
116 throw std::runtime_error(
"Column " + name +
" does not exist.");
124 std::stringstream ss;
125 ss <<
"Column index is out of range: " <<
index <<
"(" <<
columnCount() <<
")\n";
126 throw std::range_error(ss.str());
134 std::stringstream ss;
135 ss <<
"Column index is out of range: " <<
index <<
"(" <<
columnCount() <<
")\n";
136 throw std::range_error(ss.str());
145 g_log.
error() <<
"Deleting column in use (" << name <<
").\n";
169 std::stringstream ss;
170 ss <<
"Attempt to delete a non-existing row (" <<
index <<
")\n";
171 throw std::range_error(ss.str());
180 std::vector<std::string> nameList;
183 [](
const auto &column) { return column->name(); });
190 std::stringstream ss;
191 ss <<
"Column with name " << column->name() <<
" already exists.\n";
192 throw std::invalid_argument(ss.str());
205 if (criteria.empty())
209 throw std::runtime_error(
"Too many column names given.");
219 std::vector<size_t> indexVec(nRows);
221 for (
auto i = indexVec.begin() + 1; i != indexVec.end(); ++i) {
227 std::queue<SortIterationRecord> sortRecords;
229 sortRecords.push(SortIterationRecord(0, 0, nRows));
232 const size_t maxNLoops = criteria.size() * nRows / 2;
234 for (
size_t counter = 0; counter < maxNLoops; ++counter) {
236 SortIterationRecord record = sortRecords.front();
239 auto &crt = criteria[record.keyIndex];
240 const std::string columnName = crt.first;
241 const bool ascending = crt.second;
243 std::vector<std::pair<size_t, size_t>> equalRanges;
246 column.sortIndex(ascending, record.iStart, record.iEnd, indexVec, equalRanges);
251 if (record.keyIndex < criteria.size() - 1) {
252 size_t keyIndex = record.keyIndex + 1;
253 for (
auto &equalRange : equalRanges) {
254 sortRecords.push(SortIterationRecord(
keyIndex, equalRange.first, equalRange.second));
258 if (sortRecords.empty()) {
266 for (
size_t i = 0; i < nCols; ++i) {
275 if (colNames.empty()) {
282 if (colNames.end() != std::find(colNames.begin(), colNames.end(), (**it).name())) {
283 ws->addColumn(std::shared_ptr<API::Column>((*it)->clone()));
288 ws->m_LogManager = std::make_shared<API::LogManager>(*(
m_LogManager));
304IPropertyManager::getValue<DataObjects::TableWorkspace_sptr>(
const std::string &name)
const {
309 std::string message =
310 "Attempt to assign property " + name +
" to incorrect type. Expected shared_ptr<TableWorkspace>.";
311 throw std::runtime_error(message);
317IPropertyManager::getValue<DataObjects::TableWorkspace_const_sptr>(
const std::string &name)
const {
318 auto *prop =
dynamic_cast<PropertyWithValue<DataObjects::TableWorkspace_sptr> *
>(getPointerToProperty(name));
320 return prop->operator()();
322 std::string message =
323 "Attempt to assign property " + name +
" to incorrect type. Expected const shared_ptr<TableWorkspace>.";
324 throw std::runtime_error(message);
std::map< DeltaEMode::Type, std::string > index
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
#define DECLARE_WORKSPACE(classname)
ITableWorkspace is an implementation of Workspace in which the data are organised in columns of same ...
void removeFromColumn(Column *c, size_t index)
Remove an element from a column.
void modified()
If the workspace is the AnalysisDataService sends AfterReplaceNotification.
void insertInColumn(Column *c, size_t index)
Insert a new element into a column.
void resizeColumn(Column *c, size_t size)
Resize a column.
This class contains the information about the log entries.
Used in std::find_if algorithm to find a Column with name name.
TableWorkspace is an implementation of Workspace in which the data are organised in columns of same s...
size_t columnCount() const override
Number of columns in the workspace.
std::vector< std::string > getColumnNames() const override
Returns a vector of all column names.
API::LogManager_sptr m_LogManager
shared pointer to the logManager, responsible for the workspace properties.
size_t insertRow(size_t index) override
Inserts a row before row pointed to by index and fills it with default vales.
size_t rowCount() const override
Number of rows in the workspace.
void setRowCount(size_t count) override
Resizes the workspace.
API::Column_sptr addColumn(const std::string &type, const std::string &name) override
Creates a new column.
TableWorkspace * doCloneColumns(const std::vector< std::string > &colNames) const override
Clone the workspace keeping only selected columns.
size_t getMemorySize() const override
Get the footprint in memory in KB.
void removeColumn(const std::string &name) override
Removes a column.
void removeRow(size_t index) override
Delets a row if it exists.
TableWorkspace(size_t nrows=0)
Constructor.
size_t m_rowCount
row count
API::Column_sptr getColumn(const std::string &name) override
Gets the shared pointer to a column.
std::vector< std::shared_ptr< API::Column > > m_columns
Shared pointers to the columns.
void sort(std::vector< std::pair< std::string, bool > > &criteria) override
Sort this table.
Exception for when an item is not found in a collection.
const char * what() const noexcept override
Writes out the range and limits.
void error(const std::string &msg)
Logs at error level.
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< Column > Column_sptr
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< const Column > Column_const_sptr
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace
std::shared_ptr< const TableWorkspace > TableWorkspace_const_sptr
shared pointer to Mantid::DataObjects::TableWorkspace (const version)