Skip to content

Commit

Permalink
Refs #8570. Mode vector column loading code to a function.
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbekasov committed Jan 29, 2014
1 parent 0023843 commit a1fc162
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 27 deletions.
Expand Up @@ -5,6 +5,7 @@
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/IFileLoader.h"
#include "MantidAPI/ITableWorkspace.h"

#include "MantidNexus/NexusClasses.h"
#include <nexus/NeXusFile.hpp>
Expand Down Expand Up @@ -92,6 +93,13 @@ namespace Mantid

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

/// Loads a vector column to the TableWorkspace.
template<typename Type>
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,
Expand Down
72 changes: 45 additions & 27 deletions Code/Mantid/Framework/DataHandling/src/LoadNexusProcessed.cpp
Expand Up @@ -576,45 +576,63 @@ API::Workspace_sptr LoadNexusProcessed::loadTableEntry(NXEntry & entry)
}
else if ( info.type == NX_INT32 ) // A vector_int column
{
NXDataSetTyped<int> data = nx_tw.openNXDataSet<int>(str.c_str());
std::string columnTitle = data.attributes("name");
if ( ! columnTitle.empty() )
{
workspace->addColumn("vector_int", columnTitle);
loadVectorColumn<int>(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<API::Workspace>(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<typename Type>
void LoadNexusProcessed::loadVectorColumn(const NXData& tableData,
const std::string& dataSetName,
const ITableWorkspace_sptr& tableWs,
const std::string& columnType)
{
NXDataSetTyped<Type> data = tableData.openNXDataSet<Type>(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<int> >(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<Type> >(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<API::Workspace>(workspace);
int rowSize; rowSizeStr >> rowSize;

cell.resize(rowSize);
}
}
}

//-------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit a1fc162

Please sign in to comment.