Mantid
|
Utility method for saving NeXus format of Mantid Workspace This class interfaces to the C Nexus API. More...
#include <NeXus/NexusFileIO.h>
Public Types | |
using | optional_size_t = boost::optional< size_t > |
Public Member Functions | |
void | closeGroup () |
Close the group. More... | |
void | closeNexusFile () |
close the nexus file More... | |
int | getSpectra (MantidVec &values, MantidVec &errors, const int &spectra) const |
read values and errors for spectra More... | |
int | getWorkspaceSize (int &numberOfSpectra, int &numberOfChannels, int &numberOfXpoints, bool &uniformBounds, std::string &axesUnits, std::string &yUnits) const |
find size of open entry data section More... | |
int | getXValues (MantidVec &xValues, const int &spectra) const |
read X values for one (or the generic if uniform) spectra More... | |
NexusFileIO () | |
Default constructor. More... | |
NexusFileIO (API::Progress *prog) | |
Contructor with Progress supplied. More... | |
void | NXwritedata (const char *name, int datatype, int rank, int *dims_array, void *data, bool compress=false) const |
Write out an array to the open file. More... | |
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 More... | |
void | resetProgress (Mantid::API::Progress *prog) |
Reset the pointer to the progress object. More... | |
int | writeEventList (const DataObjects::EventList &el, const std::string &group_name) const |
Write out an event list into an already-opened group. More... | |
template<class T > | |
void | writeEventListData (std::vector< T > events, bool writeTOF, bool writePulsetime, bool writeWeight, bool writeError) const |
Write out the event list data, no matter what the underlying event type is. More... | |
bool | writeNexusBinMasking (const API::MatrixWorkspace_const_sptr &ws) const |
write bin masking information More... | |
int | writeNexusProcessedData2D (const API::MatrixWorkspace_const_sptr &localworkspace, const bool &uniformSpectra, const std::vector< int > &indices, const char *group_name, bool write2Ddata) const |
write the workspace data More... | |
int | writeNexusProcessedDataEvent (const DataObjects::EventWorkspace_const_sptr &ws) |
Write out all of the event lists in the given workspace. More... | |
int | writeNexusProcessedDataEventCombined (const DataObjects::EventWorkspace_const_sptr &ws, std::vector< int64_t > &indices, double *tofs, float *weights, float *errorSquareds, int64_t *pulsetimes, bool compress) const |
Write out a combined chunk of event data. More... | |
int | writeNexusProcessedHeader (const std::string &title, const std::string &wsName="") const |
write the header ifon for the Mantid workspace format More... | |
int | writeNexusSampleLogs (const Mantid::API::Run &runProperties) const |
Write a lgos section. More... | |
int | writeNexusTableWorkspace (const API::ITableWorkspace_const_sptr &itableworkspace, const char *group_name) const |
write table workspace More... | |
template<> | |
bool | writeNxValue (const std::string &name, const std::string &value, const int nxType, const std::vector< std::string > &attributes, const std::vector< std::string > &avalues) const |
Write a single valued entry to the Nexus file (specialization for a string) More... | |
template<> | |
bool | writeSingleValueNXLog (const std::string &name, const std::string &value, const int nxType, const std::vector< std::string > &attributes, const std::vector< std::string > &avalues) const |
Write a single valued NXLog entry to the Nexus file (specialization for a string) More... | |
~NexusFileIO () | |
Destructor. More... | |
Public Attributes | |
NXhandle | fileID |
Nexus file handle. More... | |
Private Member Functions | |
bool | checkAttributeName (const std::string &target) const |
check if given attribute name is in currently opened entry More... | |
bool | checkEntryAtLevel (const std::string &item) const |
check if the gievn item exists in the current level More... | |
bool | checkEntryAtLevelByAttribute (const std::string &attribute, std::string &entry) const |
Look for entry with given attribute (eg "signal") More... | |
int | findMantidWSEntries () const |
search for exisiting MantidWorkpace_n entries in opened file More... | |
bool | isTimeSeries (Kernel::Property *prop) const |
Returns true if the given property is a time series property. More... | |
template<class T > | |
std::string | logValueType () const |
Return the log value type as string. More... | |
template<> | |
std::string | logValueType () const |
template<> | |
std::string | logValueType () const |
template<> | |
std::string | logValueType () const |
std::time_t | to_time_t (const boost::posix_time::ptime &t) |
convert posix time to time_t More... | |
template<class T > | |
void | writeNexusTimeLog (const Kernel::TimeSeriesProperty< T > *timeSeries) const |
Writes a numeric log to the Nexus file. More... | |
template<typename VecType , typename ElemType > | |
void | writeNexusVectorColumn (const API::Column_const_sptr &col, const std::string &columnName, int nexusType, const std::string &interpret_as) const |
Writes given vector column to the currently open Nexus file. More... | |
template<class T > | |
void | writeNumericTimeLog (const Kernel::TimeSeriesProperty< T > *timeSeries) const |
Writes a numeric log to the Nexus file. More... | |
void | writeNumericTimeLog_String (const Kernel::TimeSeriesProperty< std::string > *s_timeSeries) const |
Write NXlog data for given string TimeSeriesProperty. More... | |
void | writeNxFloatArray (const std::string &name, const std::vector< double > &values, const std::vector< std::string > &attributes, const std::vector< std::string > &avalues) const |
write a float array along with any defined attributes More... | |
bool | writeNxNote (const std::string ¬eName, const std::string &author, const std::string &date, const std::string &description, const std::string &pairValues) const |
write an NXnote with standard fields (but NX_CHAR rather than NX_BINARY data) More... | |
bool | writeNxStringArray (const std::string &name, const std::vector< std::string > &values, const std::vector< std::string > &attributes, const std::vector< std::string > &avalues) const |
write a char array along with any defined attributes More... | |
template<class TYPE > | |
bool | writeNxValue (const std::string &name, const TYPE &value, const int nxType, const std::vector< std::string > &attributes, const std::vector< std::string > &avalues) const |
Write a simple value plus possible attributes. More... | |
bool | writeSingleValueLog (Kernel::Property *prop) const |
Write a single value log entry. More... | |
template<class TYPE > | |
bool | writeSingleValueNXLog (const std::string &name, const TYPE &value, const int nxType, const std::vector< std::string > &attributes, const std::vector< std::string > &avalues) const |
Write a single valued NXLog entry to the Nexus file. More... | |
template<typename ColumnT , typename NexusT > | |
void | writeTableColumn (int 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. More... | |
bool | writeTimeSeriesLog (Kernel::Property *prop) const |
Write a time series log entry. More... | |
Private Attributes | |
std::shared_ptr< ::NeXus::File > | m_filehandle |
C++ API file handle. More... | |
std::string | m_filename |
nexus file name More... | |
int | m_nexuscompression |
Nexus compression method. More... | |
API::Progress * | m_progress |
Allow an externally supplied progress object to be used. More... | |
Utility method for saving NeXus format of Mantid Workspace 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 38 of file NexusFileIO.h.
using Mantid::NeXus::NexusFileIO::optional_size_t = boost::optional<size_t> |
Definition at line 42 of file NexusFileIO.h.
Mantid::NeXus::NexusFileIO::NexusFileIO | ( | ) |
Mantid::NeXus::NexusFileIO::NexusFileIO | ( | API::Progress * | prog | ) |
Contructor with Progress supplied.
Constructor that supplies a progress object.
Definition at line 49 of file NexusFileIO.cpp.
Mantid::NeXus::NexusFileIO::~NexusFileIO | ( | ) |
Destructor.
Definition at line 1229 of file NexusFileIO.cpp.
|
private |
check if given attribute name is in currently opened entry
Definition at line 963 of file NexusFileIO.cpp.
References m_filehandle.
Referenced by checkEntryAtLevelByAttribute(), and getWorkspaceSize().
|
private |
check if the gievn item exists in the current level
Definition at line 1057 of file NexusFileIO.cpp.
References m_filehandle.
|
private |
Look for entry with given attribute (eg "signal")
Definition at line 1063 of file NexusFileIO.cpp.
References checkAttributeName(), and m_filehandle.
Referenced by getSpectra(), and getWorkspaceSize().
void Mantid::NeXus::NexusFileIO::closeGroup | ( | ) |
void Mantid::NeXus::NexusFileIO::closeNexusFile | ( | ) |
|
private |
search for exisiting MantidWorkpace_n entries in opened file
Definition at line 1042 of file NexusFileIO.cpp.
References count, and m_filehandle.
Referenced by openNexusWrite().
int Mantid::NeXus::NexusFileIO::getSpectra | ( | MantidVec & | values, |
MantidVec & | errors, | ||
const int & | spectra | ||
) | const |
read values and errors for spectra
Definition at line 999 of file NexusFileIO.cpp.
References checkEntryAtLevelByAttribute(), and fileID.
int Mantid::NeXus::NexusFileIO::getWorkspaceSize | ( | int & | numberOfSpectra, |
int & | numberOfChannels, | ||
int & | numberOfXpoints, | ||
bool & | uniformBounds, | ||
std::string & | axesUnits, | ||
std::string & | yUnits | ||
) | const |
find size of open entry data section
Read the size of the data section in a mantid_workspace_entry and also get the names of axes.
Definition at line 896 of file NexusFileIO.cpp.
References checkAttributeName(), checkEntryAtLevelByAttribute(), and fileID.
int Mantid::NeXus::NexusFileIO::getXValues | ( | MantidVec & | xValues, |
const int & | spectra | ||
) | const |
read X values for one (or the generic if uniform) spectra
Definition at line 972 of file NexusFileIO.cpp.
References fileID.
|
private |
Returns true if the given property is a time series property.
|
inlineprivate |
Return the log value type as string.
Definition at line 173 of file NexusFileIO.h.
|
private |
Definition at line 1144 of file NexusFileIO.cpp.
|
private |
Definition at line 1146 of file NexusFileIO.cpp.
|
private |
Definition at line 1148 of file NexusFileIO.cpp.
void Mantid::NeXus::NexusFileIO::NXwritedata | ( | const char * | name, |
int | datatype, | ||
int | rank, | ||
int * | dims_array, | ||
void * | data, | ||
bool | compress = false |
||
) | const |
Write out an array to the open file.
Definition at line 754 of file NexusFileIO.cpp.
References fileID, and m_nexuscompression.
Referenced by writeEventList(), writeEventListData(), writeNexusProcessedDataEventCombined(), writeNexusVectorColumn(), and writeTableColumn().
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 80 of file NexusFileIO.cpp.
References count, Mantid::Kernel::Logger::error(), Mantid::DataHandling::exists(), fileID, findMantidWSEntries(), Mantid::API::g_log, m_filehandle, m_filename, and m_nexuscompression.
void Mantid::NeXus::NexusFileIO::resetProgress | ( | Mantid::API::Progress * | prog | ) |
Reset the pointer to the progress object.
Definition at line 52 of file NexusFileIO.cpp.
References m_progress.
|
inlineprivate |
convert posix time to time_t
Take the input Posix time, subtract the unix epoch, and return the seconds as a std::time_t value.
t | :: time of interest as ptime |
t | convert posix time to time_t |
Definition at line 147 of file NexusFileIO.h.
int Mantid::NeXus::NexusFileIO::writeEventList | ( | const DataObjects::EventList & | el, |
const std::string & | group_name | ||
) | const |
Write out an event list into an already-opened group.
el | :: reference to the EventList to write. |
group_name | :: group_name to create. |
Definition at line 830 of file NexusFileIO.cpp.
References fileID, Mantid::API::ISpectrum::getDetectorIDs(), Mantid::DataObjects::EventList::getEvents(), Mantid::DataObjects::EventList::getEventType(), Mantid::DataObjects::EventList::getNumberEvents(), Mantid::DataObjects::EventList::getSortType(), Mantid::DataObjects::EventList::getWeightedEvents(), Mantid::DataObjects::EventList::getWeightedEventsNoTime(), NXwritedata(), Mantid::DataObjects::PULSETIME_SORT, Mantid::API::TOF, Mantid::DataObjects::TOF_SORT, Mantid::DataObjects::UNSORTED, Mantid::API::WEIGHTED, Mantid::API::WEIGHTED_NOTIME, and writeEventListData().
Referenced by writeNexusProcessedDataEvent().
void Mantid::NeXus::NexusFileIO::writeEventListData | ( | std::vector< T > | events, |
bool | writeTOF, | ||
bool | writePulsetime, | ||
bool | writeWeight, | ||
bool | writeError | ||
) | const |
Write out the event list data, no matter what the underlying event type is.
events | :: vector of TofEvent or WeightedEvent, etc. |
writeTOF | :: if true, write the TOF values |
writePulsetime | :: if true, write the pulse time values |
writeWeight | :: if true, write the event weights |
writeError | :: if true, write the errors |
Definition at line 778 of file NexusFileIO.cpp.
References NXwritedata().
Referenced by writeEventList().
bool Mantid::NeXus::NexusFileIO::writeNexusBinMasking | ( | const API::MatrixWorkspace_const_sptr & | ws | ) | const |
write bin masking information
Write bin masking information.
ws | :: The workspace |
Definition at line 1087 of file NexusFileIO.cpp.
References fileID.
Referenced by writeNexusProcessedData2D().
int Mantid::NeXus::NexusFileIO::writeNexusProcessedData2D | ( | const API::MatrixWorkspace_const_sptr & | localworkspace, |
const bool & | uniformSpectra, | ||
const std::vector< int > & | indices, | ||
const char * | group_name, | ||
bool | write2Ddata | ||
) | const |
write the workspace data
Write out a MatrixWorkspace's data as a 2D matrix.
Use writeNexusProcessedDataEvent if writing an EventWorkspace.
Definition at line 280 of file NexusFileIO.cpp.
References fileID, Mantid::API::Axis::isSpectra(), Mantid::API::Axis::isText(), Mantid::API::Axis::label(), Mantid::API::Axis::length(), m_nexuscompression, m_progress, Mantid::Kernel::ProgressBase::reportIncrement(), Mantid::API::Axis::unit(), and writeNexusBinMasking().
Referenced by Mantid::DataHandling::SaveNexusProcessed::execEvent().
int Mantid::NeXus::NexusFileIO::writeNexusProcessedDataEvent | ( | const DataObjects::EventWorkspace_const_sptr & | ws | ) |
Write out all of the event lists in the given workspace.
ws | :: an EventWorkspace |
Definition at line 734 of file NexusFileIO.cpp.
References fileID, and writeEventList().
int Mantid::NeXus::NexusFileIO::writeNexusProcessedDataEventCombined | ( | const DataObjects::EventWorkspace_const_sptr & | ws, |
std::vector< int64_t > & | indices, | ||
double * | tofs, | ||
float * | weights, | ||
float * | errorSquareds, | ||
int64_t * | pulsetimes, | ||
bool | compress | ||
) | const |
Write out a combined chunk of event data.
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 694 of file NexusFileIO.cpp.
References fileID, m_nexuscompression, and NXwritedata().
Referenced by Mantid::DataHandling::SaveNexusProcessed::execEvent().
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.
title | :: title field. |
wsName | :: workspace name. |
Definition at line 176 of file NexusFileIO.cpp.
int Mantid::NeXus::NexusFileIO::writeNexusSampleLogs | ( | const Mantid::API::Run & | runProperties | ) | const |
Write a lgos section.
int Mantid::NeXus::NexusFileIO::writeNexusTableWorkspace | ( | const API::ITableWorkspace_const_sptr & | itableworkspace, |
const char * | group_name | ||
) | const |
write table workspace
Write out a table Workspace's.
Definition at line 590 of file NexusFileIO.cpp.
References fileID, and std::to_string().
|
private |
Writes a numeric log to the Nexus file.
T | A numeric type (double, int, bool) |
timeSeries | :: A pointer to the log property |
|
private |
Writes given vector column to the currently open Nexus file.
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 530 of file NexusFileIO.cpp.
References fileID, NXwritedata(), and Mantid::API::ConstColumnVector< T >::size().
|
private |
Writes a numeric log to the Nexus file.
T | A numeric type (double, int, bool) |
timeSeries | :: A pointer to the log property |
Definition at line 324 of file NexusFileIO.h.
References fileID, Mantid::Kernel::Property::name(), Mantid::Kernel::TimeSeriesProperty< TYPE >::valueAsMap(), and writeNxFloatArray().
|
private |
Write NXlog data for given string TimeSeriesProperty.
|
private |
write a float array along with any defined attributes
Definition at line 210 of file NexusFileIO.cpp.
References m_filehandle.
Referenced by writeNumericTimeLog().
|
private |
write an NXnote with standard fields (but NX_CHAR rather than NX_BINARY data)
Definition at line 253 of file NexusFileIO.cpp.
References m_filehandle.
|
private |
write a char array along with any defined attributes
Definition at line 224 of file NexusFileIO.cpp.
|
inline |
Write a single valued entry to the Nexus file (specialization for a string)
name | :: The name of the entry |
value | :: The value of the entry |
nxType | :: The nxType 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 |
Definition at line 227 of file NexusFileIO.h.
|
private |
Write a simple value plus possible attributes.
Write a single valued entry to the Nexus file.
name | :: The name of the entry |
value | :: The value of the entry |
nxType | :: The nxType 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 |
Definition at line 198 of file NexusFileIO.h.
|
private |
Write a single value log entry.
|
inline |
Write a single valued NXLog entry to the Nexus file (specialization for a string)
name | :: The name of the entry |
value | :: The value of the entry |
nxType | :: The nxType 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 |
Definition at line 294 of file NexusFileIO.h.
|
private |
Write a single valued NXLog entry to the Nexus file.
name | :: The name of the entry |
value | :: The value of the entry |
nxType | :: The nxType 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 |
Definition at line 260 of file NexusFileIO.h.
|
private |
Save a numeric columns of a TableWorkspace to currently open nexus file.
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 493 of file NexusFileIO.cpp.
References Mantid::API::Column::cell(), fileID, NXwritedata(), and Mantid::API::Column::size().
|
private |
Write a time series log entry.
NXhandle Mantid::NeXus::NexusFileIO::fileID |
Nexus file handle.
Definition at line 99 of file NexusFileIO.h.
Referenced by getSpectra(), getWorkspaceSize(), getXValues(), NXwritedata(), openNexusWrite(), writeEventList(), writeNexusBinMasking(), writeNexusProcessedData2D(), writeNexusProcessedDataEvent(), writeNexusProcessedDataEventCombined(), writeNexusTableWorkspace(), writeNexusVectorColumn(), writeNumericTimeLog(), writeNxStringArray(), writeNxValue(), writeSingleValueNXLog(), and writeTableColumn().
|
private |
C++ API file handle.
Definition at line 104 of file NexusFileIO.h.
Referenced by checkAttributeName(), checkEntryAtLevel(), checkEntryAtLevelByAttribute(), closeGroup(), closeNexusFile(), findMantidWSEntries(), openNexusWrite(), writeNxFloatArray(), and writeNxNote().
|
private |
|
private |
Nexus compression method.
Definition at line 107 of file NexusFileIO.h.
Referenced by NXwritedata(), openNexusWrite(), writeNexusProcessedData2D(), and writeNexusProcessedDataEventCombined().
|
private |
Allow an externally supplied progress object to be used.
Definition at line 109 of file NexusFileIO.h.
Referenced by resetProgress(), and writeNexusProcessedData2D().