Skip to content

Commit

Permalink
Re #10123. Save and load V3D columns.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Nov 28, 2014
1 parent 229e5f3 commit 5a18c11
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 126 deletions.
28 changes: 26 additions & 2 deletions Code/Mantid/Framework/API/inc/MantidAPI/ITableWorkspace.h
Expand Up @@ -332,7 +332,19 @@ class ColumnVector
{
if (!m_column->isType<T>())
{
throw std::runtime_error("Type mismatch when creating a ColumnVector.");
std::stringstream mess;
mess << "Type mismatch when creating a ColumnVector<" << typeid(T).name() << ">.";
throw std::runtime_error( mess.str() );
}
}
/// Construct directly from column
ColumnVector(Column_sptr column):m_column(column)
{
if (!m_column->isType<T>())
{
std::stringstream mess;
mess << "Type mismatch when creating a ColumnVector<" << typeid(T).name() << ">.";
throw std::runtime_error( mess.str() );
}
}
/** Get the element
Expand All @@ -359,7 +371,19 @@ class ConstColumnVector
{
if (!m_column->isType<T>())
{
throw std::runtime_error("Type mismatch when creating a ColumnVector.");
std::stringstream mess;
mess << "Type mismatch when creating a ColumnVector<" << typeid(T).name() << ">.";
throw std::runtime_error( mess.str() );
}
}
/// Construct directly from column
ConstColumnVector(Column_const_sptr column):m_column(column)
{
if (!m_column->isType<T>())
{
std::stringstream mess;
mess << "Type mismatch when creating a ColumnVector<" << typeid(T).name() << ">.";
throw std::runtime_error( mess.str() );
}
}
/** Get the const reference to element
Expand Down
Expand Up @@ -111,6 +111,9 @@ namespace Mantid
const API::ITableWorkspace_sptr& tableWs,
const std::string& columnType);

/// Loads a V3D column to the TableWorkspace.
void loadV3DColumn(Mantid::NeXus::NXDouble& data, const API::ITableWorkspace_sptr& tableWs);

API::Workspace_sptr loadPeaksEntry(Mantid::NeXus::NXEntry & entry);

API::MatrixWorkspace_sptr loadEventEntry(Mantid::NeXus::NXData & wksp_cls,Mantid::NeXus::NXDouble & xbins,
Expand Down
60 changes: 45 additions & 15 deletions Code/Mantid/Framework/DataHandling/src/LoadNexusProcessed.cpp
Expand Up @@ -805,9 +805,6 @@ int64_t index_start = indices[wi];

NXData nx_tw = entry.openNXData("table_workspace");

bool hasNumberOfRowBeenSet = false;
//int numberOfRows = 0;

int columnNumber = 1;
do
{
Expand Down Expand Up @@ -861,11 +858,7 @@ int64_t index_start = indices[wi];
{
workspace->addColumn("str", columnTitle);
int nRows = info.dims[0];
if (!hasNumberOfRowBeenSet)
{
workspace->setRowCount(nRows);
hasNumberOfRowBeenSet = true;
}
workspace->setRowCount(nRows);

const int maxStr = info.dims[1];
data.load();
Expand All @@ -878,13 +871,22 @@ int64_t index_start = indices[wi];
}
}
}
#define IF_VECTOR_COLUMN(Type, ColumnTypeName, NexusType) \
else if ( info.type == NexusType ) \
{ \
loadVectorColumn<Type>(nx_tw, dataSetName, workspace, #ColumnTypeName); \
}
IF_VECTOR_COLUMN(int, vector_int, NX_INT32)
IF_VECTOR_COLUMN(double, vector_double, NX_FLOAT64)
else if ( info.type == NX_INT32 )
{
loadVectorColumn<int>(nx_tw, dataSetName, workspace, "vector_int");
}
else if ( info.type == NX_FLOAT64 )
{
auto data = nx_tw.openNXDouble(dataSetName.c_str());
if ( data.attributes("interpret_as") == "V3D" )
{
loadV3DColumn( data, workspace );
}
else
{
loadVectorColumn<double>(nx_tw, dataSetName, workspace, "vector_double");
}
}

}

Expand Down Expand Up @@ -943,6 +945,34 @@ int64_t index_start = indices[wi];
}
}

/**
* Loads a V3D column to the TableWorkspace.
* @param data :: Table data to load from
* @param tableWs :: Workspace to add column to
*/
void LoadNexusProcessed::loadV3DColumn(Mantid::NeXus::NXDouble& data,
const API::ITableWorkspace_sptr& tableWs)
{
std::string columnTitle = data.attributes("name");
if (!columnTitle.empty())
{
ColumnVector<V3D> col = tableWs->addColumn("V3D", columnTitle);

const size_t rowCount = data.dim0();

// This might've been done already, but doing it twice should't do any harm
tableWs->setRowCount(rowCount);

data.load();

for (size_t i = 0; i < rowCount; ++i)
{
auto& cell = col[i];
cell( data(i,0), data(i,1), data(i,2) );
}
}
}

//-------------------------------------------------------------------------------------------------
/**
* Load peaks
Expand Down
Expand Up @@ -547,7 +547,7 @@ class LoadNexusProcessedTest: public CxxTest::TestSuite
TS_ASSERT( alg.execute());

TableWorkspace_const_sptr ws = AnalysisDataService::Instance().retrieveWS<TableWorkspace>(wsName);
TS_ASSERT_EQUALS( ws->columnCount(), 8);
TS_ASSERT_EQUALS( ws->columnCount(), 9);
TS_ASSERT_EQUALS( ws->rowCount(), 4);

try
Expand Down Expand Up @@ -609,6 +609,13 @@ class LoadNexusProcessedTest: public CxxTest::TestSuite
TS_ASSERT( !column[2] );
TS_ASSERT( column[3] );
}
{
ConstColumnVector<Mantid::Kernel::V3D> column = ws->getVector("3DVector");
TS_ASSERT_EQUALS( column[0], Mantid::Kernel::V3D(1,2,3));
TS_ASSERT_EQUALS( column[1], Mantid::Kernel::V3D(4,5,6));
TS_ASSERT_EQUALS( column[2], Mantid::Kernel::V3D(7,8,9));
TS_ASSERT_EQUALS( column[3], Mantid::Kernel::V3D(11,12,13));
}
}
catch(std::exception& e)
{
Expand Down

0 comments on commit 5a18c11

Please sign in to comment.