Mantid
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Mantid::Nexus::NexusFileIO Class Reference

Utility methods for saving Mantid Workspaces in NeXus format. More...

#include <NeXus/SaveNexusProcessedHelper.h>

Public Types

using optional_size_t = std::optional< size_t >
 

Public Member Functions

void closeGroup ()
 Close the group.
 
void closeNexusFile ()
 close the nexus file
 
std::shared_ptr< Nexus::File > filehandle () const
 Nexus file handle.
 
 NexusFileIO ()
 Default constructor.
 
 NexusFileIO (API::Progress *prog)
 Contructor with Progress supplied.
 
void openNexusWrite (const std::string &fileName, optional_size_t entryNumber=optional_size_t(), const bool append_to_file=true)
 open the nexus file for writing
 
void resetProgress (Mantid::API::Progress *prog)
 Reset the pointer to the progress object.
 
template<typename NumT >
void writeData (const char *name, NXnumtype datatype, Nexus::DimVector dims_array, NumT const *data, bool compress=false) const
 Write out an array to the open file.
 
bool writeNexusBinMasking (const API::MatrixWorkspace_const_sptr &ws) const
 write bin masking information
 
int writeNexusProcessedData2D (const API::MatrixWorkspace_const_sptr &localworkspace, const bool &uniformSpectra, const bool &raggedSpectra, const std::vector< int > &indices, const std::string &group_name, bool write2Ddata) const
 write the workspace data
 
int writeNexusProcessedDataEventCombined (const DataObjects::EventWorkspace_const_sptr &ws, std::vector< int64_t > const &indices, double const *tofs, float const *weights, float const *errorSquareds, int64_t const *pulsetimes, bool compress) const
 Write out a combined chunk of event data.
 
int writeNexusProcessedHeader (const std::string &title, const std::string &wsName="") const
 write the header ifon for the Mantid workspace format
 
int writeNexusTableWorkspace (const API::ITableWorkspace_const_sptr &itableworkspace, const char *group_name) const
 write table workspace
 
 ~NexusFileIO ()
 Destructor.
 

Private Member Functions

int findMantidWSEntries () const
 search for exisiting MantidWorkpace_n entries in opened file
 
template<typename VecType , typename ElemType >
void writeNexusVectorColumn (const API::Column_const_sptr &col, const std::string &columnName, NXnumtype nexusType, const std::string &interpret_as) const
 Writes given vector column to the currently open Nexus file.
 
bool writeNxValue (const std::string &name, const std::string &value, const std::vector< std::string > &attributes, const std::vector< std::string > &avalues) const
 Write a simple value plus possible attributes.
 
template<typename ColumnT , typename NexusT >
void writeTableColumn (NXnumtype type, const std::string &interpret_as, const API::Column &col, const std::string &columnName) const
 Save a numeric columns of a TableWorkspace to currently open nexus file.
 

Private Attributes

std::shared_ptr< Nexus::File > m_filehandle
 C++ API file handle.
 
std::string m_filename
 nexus file name
 
NXcompression m_nexuscompression
 Nexus compression method.
 
API::Progressm_progress
 Allow an externally supplied progress object to be used.
 

Detailed Description

Utility methods for saving Mantid Workspaces in NeXus format.

This class interfaces to the C Nexus API. This is written for use by Save and Load NexusProcessed classes, though it could be extended to other Nexus formats. It might be replaced in future by methods using the new Nexus C++ API.

Definition at line 39 of file SaveNexusProcessedHelper.h.

Member Typedef Documentation

◆ optional_size_t

using Mantid::Nexus::NexusFileIO::optional_size_t = std::optional<size_t>

Definition at line 43 of file SaveNexusProcessedHelper.h.

Constructor & Destructor Documentation

◆ NexusFileIO() [1/2]

Mantid::Nexus::NexusFileIO::NexusFileIO ( )

Default constructor.

Empty default constructor.

Definition at line 47 of file SaveNexusProcessedHelper.cpp.

◆ NexusFileIO() [2/2]

Mantid::Nexus::NexusFileIO::NexusFileIO ( API::Progress prog)

Contructor with Progress supplied.

Constructor that supplies a progress object.

Definition at line 51 of file SaveNexusProcessedHelper.cpp.

◆ ~NexusFileIO()

Mantid::Nexus::NexusFileIO::~NexusFileIO ( )

Destructor.

Definition at line 775 of file SaveNexusProcessedHelper.cpp.

Member Function Documentation

◆ closeGroup()

void Mantid::Nexus::NexusFileIO::closeGroup ( )

Close the group.

Definition at line 152 of file SaveNexusProcessedHelper.cpp.

References m_filehandle.

◆ closeNexusFile()

void Mantid::Nexus::NexusFileIO::closeNexusFile ( )

close the nexus file

Definition at line 155 of file SaveNexusProcessedHelper.cpp.

References m_filehandle.

◆ filehandle()

std::shared_ptr< Nexus::File > Mantid::Nexus::NexusFileIO::filehandle ( ) const
inline

Nexus file handle.

Definition at line 87 of file SaveNexusProcessedHelper.h.

◆ findMantidWSEntries()

int Mantid::Nexus::NexusFileIO::findMantidWSEntries ( ) const
private

search for exisiting MantidWorkpace_n entries in opened file

Definition at line 706 of file SaveNexusProcessedHelper.cpp.

References count, and m_filehandle.

Referenced by openNexusWrite().

◆ openNexusWrite()

void Mantid::Nexus::NexusFileIO::openNexusWrite ( const std::string &  fileName,
NexusFileIO::optional_size_t  entryNumber = optional_size_t(),
const bool  append_to_file = true 
)

open the nexus file for writing

Definition at line 82 of file SaveNexusProcessedHelper.cpp.

References count, CREATE5, findMantidWSEntries(), m_filehandle, m_filename, and RDWR.

◆ resetProgress()

void Mantid::Nexus::NexusFileIO::resetProgress ( Mantid::API::Progress prog)

Reset the pointer to the progress object.

Definition at line 54 of file SaveNexusProcessedHelper.cpp.

References m_progress.

◆ writeData()

template<typename NumT >
void Mantid::Nexus::NexusFileIO::writeData ( const char *  name,
NXnumtype  datatype,
Nexus::DimVector  dims_array,
NumT const *  data,
bool  compress = false 
) const

Write out an array to the open file.

Definition at line 691 of file SaveNexusProcessedHelper.cpp.

References m_filehandle, m_nexuscompression, and name.

Referenced by writeNexusProcessedDataEventCombined(), writeNexusVectorColumn(), and writeTableColumn().

◆ writeNexusBinMasking()

bool Mantid::Nexus::NexusFileIO::writeNexusBinMasking ( const API::MatrixWorkspace_const_sptr ws) const

write bin masking information

Write bin masking information.

Parameters
ws:: The workspace
Returns
true for OK, false for error

Definition at line 726 of file SaveNexusProcessedHelper.cpp.

References NXnumtype::FLOAT64, NXnumtype::INT32, m_filehandle, and NXnumtype::UINT64.

Referenced by writeNexusProcessedData2D().

◆ writeNexusProcessedData2D()

int Mantid::Nexus::NexusFileIO::writeNexusProcessedData2D ( const API::MatrixWorkspace_const_sptr localworkspace,
const bool &  uniformSpectra,
const bool &  raggedSpectra,
const std::vector< int > &  indices,
const std::string &  group_name,
bool  write2Ddata 
) const

◆ writeNexusProcessedDataEventCombined()

int Mantid::Nexus::NexusFileIO::writeNexusProcessedDataEventCombined ( const DataObjects::EventWorkspace_const_sptr ws,
std::vector< int64_t > const &  indices,
double const *  tofs,
float const *  weights,
float const *  errorSquareds,
int64_t const *  pulsetimes,
bool  compress 
) const

Write out a combined chunk of event data.

Parameters
ws:: an EventWorkspace
indices:: array of event list indexes
tofs:: array of TOFs
weights:: array of event weights
errorSquareds:: array of event squared errors
pulsetimes:: array of pulsetimes
compress:: if true, compress the entry

Definition at line 652 of file SaveNexusProcessedHelper.cpp.

References NXnumtype::FLOAT32, NXnumtype::FLOAT64, NXnumtype::INT64, m_filehandle, m_nexuscompression, and writeData().

Referenced by Mantid::DataHandling::SaveNexusProcessed::execEvent().

◆ writeNexusProcessedHeader()

int Mantid::Nexus::NexusFileIO::writeNexusProcessedHeader ( const std::string &  title,
const std::string &  wsName = "" 
) const

write the header ifon for the Mantid workspace format

Write Nexus mantid workspace header fields for the NXentry/IXmantid/NXprocessed field.

The URLs are not correct as they do not exist presently, but follow the format for other Nexus specs.

Parameters
title:: title field.
wsName:: workspace name.
Returns
zero on success, a non-zero value on failure.

Definition at line 170 of file SaveNexusProcessedHelper.cpp.

References writeNxValue().

◆ writeNexusTableWorkspace()

int Mantid::Nexus::NexusFileIO::writeNexusTableWorkspace ( const API::ITableWorkspace_const_sptr itableworkspace,
const char *  group_name 
) const

◆ writeNexusVectorColumn()

template<typename VecType , typename ElemType >
void Mantid::Nexus::NexusFileIO::writeNexusVectorColumn ( const API::Column_const_sptr col,
const std::string &  columnName,
NXnumtype  nexusType,
const std::string &  interpret_as 
) const
private

Writes given vector column to the currently open Nexus file.

Parameters
col:: Column to write
columnName:: Name of NXdata to write to
nexusType:: Nexus type to use to store data
interpret_as:: Name of the type to use for "interpret_as" attribute

Definition at line 484 of file SaveNexusProcessedHelper.cpp.

References m_filehandle, Mantid::API::ConstColumnVector< T >::size(), and writeData().

◆ writeNxValue()

bool Mantid::Nexus::NexusFileIO::writeNxValue ( const std::string &  name,
const std::string &  value,
const std::vector< std::string > &  attributes,
const std::vector< std::string > &  avalues 
) const
inlineprivate

Write a simple value plus possible attributes.

Write a single valued entry to the Nexus file (specialization for a string)

Parameters
name:: The name of the entry
value:: The value of the entry
attributes:: A list of attributes 1:1 mapped to their values in the avalues argument
avalues:: A list of attribute values in the same order as the attributes argument
Returns
A boolean indicating success or failure

Definition at line 126 of file SaveNexusProcessedHelper.h.

References m_filehandle, name, and value.

Referenced by writeNexusProcessedHeader().

◆ writeTableColumn()

template<typename ColumnT , typename NexusT >
void Mantid::Nexus::NexusFileIO::writeTableColumn ( NXnumtype  type,
const std::string &  interpret_as,
const API::Column col,
const std::string &  columnName 
) const
private

Save a numeric columns of a TableWorkspace to currently open nexus file.

Parameters
type:: Nexus code for the element data type.
interpret_as:: Value of the interpret_as attribute.
col:: Reference to the column being svaed.
columnName:: Name of the nexus data set in which the column values are saved.

Definition at line 447 of file SaveNexusProcessedHelper.cpp.

References Mantid::API::Column::cell(), m_filehandle, Mantid::API::Column::size(), and writeData().

Member Data Documentation

◆ m_filehandle

std::shared_ptr<Nexus::File> Mantid::Nexus::NexusFileIO::m_filehandle
private

◆ m_filename

std::string Mantid::Nexus::NexusFileIO::m_filename
private

nexus file name

Definition at line 103 of file SaveNexusProcessedHelper.h.

Referenced by openNexusWrite().

◆ m_nexuscompression

NXcompression Mantid::Nexus::NexusFileIO::m_nexuscompression
private

Nexus compression method.

Definition at line 93 of file SaveNexusProcessedHelper.h.

Referenced by writeData(), writeNexusProcessedData2D(), and writeNexusProcessedDataEventCombined().

◆ m_progress

API::Progress* Mantid::Nexus::NexusFileIO::m_progress
private

Allow an externally supplied progress object to be used.

Definition at line 95 of file SaveNexusProcessedHelper.h.

Referenced by resetProgress(), and writeNexusProcessedData2D().


The documentation for this class was generated from the following files: