diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed.h index 5f7a6ed48a04..b5860a9cad90 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed.h @@ -5,6 +5,7 @@ // Includes //---------------------------------------------------------------------- #include "MantidAPI/IFileLoader.h" +#include "MantidAPI/ITableWorkspace.h" #include "MantidNexus/NexusClasses.h" #include @@ -92,6 +93,13 @@ namespace Mantid API::Workspace_sptr loadTableEntry(Mantid::NeXus::NXEntry& entry); + /// Loads a vector column to the TableWorkspace. + template + void loadVectorColumn(const Mantid::NeXus::NXData& tableData, + const std::string& dataSetName, + const API::ITableWorkspace_sptr& tableWs, + const std::string& columnType); + API::Workspace_sptr loadPeaksEntry(Mantid::NeXus::NXEntry & entry); API::MatrixWorkspace_sptr loadEventEntry(Mantid::NeXus::NXData & wksp_cls,Mantid::NeXus::NXDouble & xbins, diff --git a/Code/Mantid/Framework/DataHandling/src/LoadNexusProcessed.cpp b/Code/Mantid/Framework/DataHandling/src/LoadNexusProcessed.cpp index 3cceae3c32e0..2931ab5e2afb 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadNexusProcessed.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadNexusProcessed.cpp @@ -576,45 +576,63 @@ API::Workspace_sptr LoadNexusProcessed::loadTableEntry(NXEntry & entry) } else if ( info.type == NX_INT32 ) // A vector_int column { - NXDataSetTyped data = nx_tw.openNXDataSet(str.c_str()); - std::string columnTitle = data.attributes("name"); - if ( ! columnTitle.empty() ) - { - workspace->addColumn("vector_int", columnTitle); + loadVectorColumn(nx_tw, str, workspace, "vector_int"); + } + } - const size_t rowCount = info.dims[0]; - const size_t blockSize = info.dims[1]; + columnNumber++; + + } while ( 1 ); - workspace->setRowCount(rowCount); + return boost::static_pointer_cast(workspace); +} - data.load(); +/** + * Loads a vector column to the TableWorkspace. + * @param tableData :: Table data to load from + * @param dataSetName :: Name of the data set to use to get column data + * @param tableWs :: Workspace to add column to + * @param columnType :: Name of the column type to create + */ +template +void LoadNexusProcessed::loadVectorColumn(const NXData& tableData, + const std::string& dataSetName, + const ITableWorkspace_sptr& tableWs, + const std::string& columnType) +{ + NXDataSetTyped data = tableData.openNXDataSet(dataSetName.c_str()); + std::string columnTitle = data.attributes("name"); + if ( ! columnTitle.empty() ) + { + tableWs->addColumn(columnType, columnTitle); - for ( size_t i = 0; i < rowCount; ++i ) - { - auto& cell = workspace->cell< std::vector >(i, workspace->columnCount() - 1); + NXInfo info = tableData.getDataSetInfo(dataSetName.c_str()); + const size_t rowCount = info.dims[0]; + const size_t blockSize = info.dims[1]; - int* from = data() + blockSize * i; + // This might've been done already, but doing it twice should't do any harm + tableWs->setRowCount(rowCount); - cell.assign(from, from + blockSize); + data.load(); - std::ostringstream rowSizeAttrName; rowSizeAttrName << "row_size_" << i; + for ( size_t i = 0; i < rowCount; ++i ) + { + auto& cell = tableWs->cell< std::vector >(i, tableWs->columnCount() - 1); - // This is ugly, but I can only get attribute as a string using the API - std::istringstream rowSizeStr( data.attributes(rowSizeAttrName.str()) ); + Type* from = data() + blockSize * i; - int rowSize; rowSizeStr >> rowSize; + cell.assign(from, from + blockSize); - cell.resize(rowSize); - } - } - } - } + std::ostringstream rowSizeAttrName; rowSizeAttrName << "row_size_" << i; - columnNumber++; - - } while ( 1 ); + // This is ugly, but I can only get attribute as a string using the API + std::istringstream rowSizeStr( data.attributes(rowSizeAttrName.str()) ); - return boost::static_pointer_cast(workspace); + int rowSize; rowSizeStr >> rowSize; + + cell.resize(rowSize); + } + } } //-------------------------------------------------------------------------------------------------