14#include "MantidNexus/DllConfig.h"
15#include <boost/date_time/c_local_time_adjustor.hpp>
16#include <boost/date_time/local_time_adjustor.hpp>
17#include <boost/date_time/posix_time/posix_time.hpp>
18#include <boost/scoped_array.hpp>
20#include <boost/optional.hpp>
23#include <nexus/NeXusFile.hpp>
27MANTID_NEXUS_DLL
int getNexusEntryTypes(
const std::string &fileName, std::vector<std::string> &entryName,
28 std::vector<std::string> &definition);
55 const bool append_to_file =
true);
57 int writeNexusProcessedHeader(
const std::string &title,
const std::string &wsName =
"")
const;
59 void closeNexusFile();
66 const std::vector<int> &indices,
const char *group_name,
bool write2Ddata)
const;
74 std::vector<int64_t> &indices,
double *tofs,
float *weights,
75 float *errorSquareds, int64_t *pulsetimes,
bool compress)
const;
80 void writeEventListData(std::vector<T> events,
bool writeTOF,
bool writePulsetime,
bool writeWeight,
81 bool writeError)
const;
82 void NXwritedata(
const char *name,
int datatype,
int rank,
int *dims_array,
void *data,
bool compress =
false)
const;
85 int getWorkspaceSize(
int &numberOfSpectra,
int &numberOfChannels,
int &numberOfXpoints,
bool &uniformBounds,
86 std::string &axesUnits, std::string &yUnits)
const;
88 int getXValues(
MantidVec &xValues,
const int &spectra)
const;
111 template <
class TYPE>
112 bool writeNxValue(
const std::string &name,
const TYPE &
value,
const int nxType,
113 const std::vector<std::string> &attributes,
const std::vector<std::string> &avalues)
const;
123 template <
class TYPE>
124 bool writeSingleValueNXLog(
const std::string &name,
const TYPE &
value,
const int nxType,
125 const std::vector<std::string> &attributes,
const std::vector<std::string> &avalues)
const;
128 bool writeNxNote(
const std::string ¬eName,
const std::string &author,
const std::string &date,
129 const std::string &description,
const std::string &pairValues)
const;
131 void writeNxFloatArray(
const std::string &name,
const std::vector<double> &values,
132 const std::vector<std::string> &attributes,
const std::vector<std::string> &avalues)
const;
134 bool writeNxStringArray(
const std::string &name,
const std::vector<std::string> &values,
135 const std::vector<std::string> &attributes,
const std::vector<std::string> &avalues)
const;
139 bool checkEntryAtLevel(
const std::string &item)
const;
141 bool checkAttributeName(
const std::string &target)
const;
143 bool checkEntryAtLevelByAttribute(
const std::string &attribute, std::string &entry)
const;
145 int findMantidWSEntries()
const;
147 std::time_t
to_time_t(
const boost::posix_time::ptime &t)
155 if (t == boost::posix_time::neg_infin)
157 else if (t == boost::posix_time::pos_infin)
159 boost::posix_time::ptime start(boost::gregorian::date(1970, 1, 1));
160 return (t - start).total_seconds();
173 template <
class T> std::string
logValueType()
const {
return "unknown"; }
176 template <
typename VecType,
typename ElemType>
177 void writeNexusVectorColumn(
const API::Column_const_sptr &col,
const std::string &columnName,
int nexusType,
178 const std::string &interpret_as)
const;
181 template <
typename ColumnT,
typename NexusT>
182 void writeTableColumn(
int type,
const std::string &interpret_as,
const API::Column &col,
183 const std::string &columnName)
const;
199 const std::vector<std::string> &attributes,
200 const std::vector<std::string> &avalues)
const {
201 int dimensions[1] = {1};
202 if (NXmakedata(
fileID, name.c_str(), nxType, 1, dimensions) == NX_ERROR)
204 if (NXopendata(
fileID, name.c_str()) == NX_ERROR)
206 for (
unsigned int it = 0; it < attributes.size(); ++it) {
207 NXputattr(
fileID, attributes[it].c_str(), (
void *)avalues[it].c_str(),
static_cast<int>(avalues[it].size() + 1),
228 const std::vector<std::string> &attributes,
229 const std::vector<std::string> &avalues)
const {
231 int dimensions[1] = {0};
232 std::string nxstr =
value;
235 dimensions[0] =
static_cast<int>(nxstr.size() + 1);
236 if (NXmakedata(
fileID, name.c_str(), nxType, 1, dimensions) == NX_ERROR)
238 if (NXopendata(
fileID, name.c_str()) == NX_ERROR)
240 for (
unsigned int it = 0; it < attributes.size(); ++it) {
241 NXputattr(
fileID, attributes[it].c_str(), avalues[it].c_str(),
static_cast<int>(avalues[it].size() + 1), NX_CHAR);
243 NXputdata(
fileID,
reinterpret_cast<void *
>(
const_cast<char *
>(nxstr.c_str())));
261 const std::vector<std::string> &attributes,
262 const std::vector<std::string> &avalues)
const {
263 if (NXmakegroup(
fileID, name.c_str(),
"NXlog") == NX_ERROR)
265 NXopengroup(
fileID, name.c_str(),
"NXlog");
266 int dimensions[1] = {1};
267 if (NXmakedata(
fileID,
"value", nxType, 1, dimensions) == NX_ERROR)
269 if (NXopendata(
fileID,
"value") == NX_ERROR)
271 for (
unsigned int it = 0; it < attributes.size(); ++it) {
272 NXputattr(
fileID, attributes[it].c_str(), (
void *)avalues[it].c_str(),
static_cast<int>(avalues[it].size() + 1),
295 const std::vector<std::string> &attributes,
296 const std::vector<std::string> &avalues)
const {
298 if (NXmakegroup(
fileID, name.c_str(),
"NXlog") == NX_ERROR)
300 NXopengroup(
fileID, name.c_str(),
"NXlog");
301 int dimensions[1] = {0};
302 std::string nxstr =
value;
305 dimensions[0] =
static_cast<int>(nxstr.size() + 1);
306 if (NXmakedata(
fileID,
"value", NX_CHAR, 1, dimensions) == NX_ERROR)
308 if (NXopendata(
fileID,
"value") == NX_ERROR)
310 for (
unsigned int it = 0; it < attributes.size(); ++it) {
311 NXputattr(
fileID, attributes[it].c_str(),
reinterpret_cast<void *
>(
const_cast<char *
>(avalues[it].c_str())),
312 static_cast<int>(avalues[it].size() + 1), NX_CHAR);
314 NXputdata(
fileID,
reinterpret_cast<void *
>(
const_cast<char *
>(nxstr.c_str())));
328 std::string logName = timeSeries->
name();
329 size_t ipos = logName.find_last_of(
"/\\");
330 if (ipos != std::string::npos)
331 logName = logName.substr(ipos + 1);
333 std::map<Types::Core::DateAndTime, T> dV = timeSeries->
valueAsMap();
334 std::vector<double> values;
335 std::vector<double> times;
336 Types::Core::DateAndTime t0;
338 for (
typename std::map<Types::Core::DateAndTime, T>::const_iterator dv = dV.begin(); dv != dV.end(); ++dv) {
340 Types::Core::DateAndTime time = dv->first;
341 values.emplace_back(val);
346 times.emplace_back(Types::Core::DateAndTime::secondsFromDuration(time - t0));
349 status = NXmakegroup(
fileID, logName.c_str(),
"NXlog");
350 if (status == NX_ERROR)
353 NXopengroup(
fileID, logName.c_str(),
"NXlog");
355 std::vector<std::string> attributes, avalues;
356 attributes.emplace_back(
"type");
357 avalues.emplace_back(logValueType<T>());
362 attributes.emplace_back(
"start");
363 avalues.emplace_back(t0.toISO8601String());
double value
The value of the point.
Column is the base class for columns of TableWorkspace.
Helper class for reporting progress from algorithms.
This class stores information regarding an experimental run as a series of log entries.
Base class for properties.
const std::string & name() const
Get the property's name.
A specialised Property class for holding a series of time-value pairs.
std::map< Types::Core::DateAndTime, TYPE > valueAsMap() const
Return the time series as a C++ map<DateAndTime, TYPE>
Utility method for saving NeXus format of Mantid Workspace This class interfaces to the C Nexus API.
bool writeSingleValueLog(Kernel::Property *prop) const
Write a single value log entry.
void writeNexusTimeLog(const Kernel::TimeSeriesProperty< T > *timeSeries) const
Writes a numeric log to the Nexus file.
API::Progress * m_progress
Allow an externally supplied progress object to be used.
boost::optional< size_t > optional_size_t
std::string m_filename
nexus file name
std::shared_ptr< ::NeXus::File > m_filehandle
C++ API file handle.
int writeNexusSampleLogs(const Mantid::API::Run &runProperties) const
Write a lgos section.
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.
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
std::time_t to_time_t(const boost::posix_time::ptime &t)
convert posix time to time_t
std::string logValueType() const
Return the log value type as string.
int m_nexuscompression
Nexus compression method.
void writeNumericTimeLog(const Kernel::TimeSeriesProperty< T > *timeSeries) const
Writes a numeric log to the Nexus file.
bool writeTimeSeriesLog(Kernel::Property *prop) const
Write a time series log entry.
NXhandle fileID
Nexus file handle.
void writeNumericTimeLog_String(const Kernel::TimeSeriesProperty< std::string > *s_timeSeries) const
Write NXlog data for given string TimeSeriesProperty.
bool isTimeSeries(Kernel::Property *prop) const
Returns true if the given property is a time series property.
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.
std::shared_ptr< const ITableWorkspace > ITableWorkspace_const_sptr
shared pointer to Mantid::API::ITableWorkspace (const version)
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< const Column > Column_const_sptr
std::shared_ptr< const EventWorkspace > EventWorkspace_const_sptr
shared pointer to a const Workspace2D
MANTID_NEXUS_DLL int getNexusEntryTypes(const std::string &fileName, std::vector< std::string > &entryName, std::vector< std::string > &definition)
Get all the Nexus entry types for a file.
std::shared_ptr< NexusFileIO > NexusFileIO_sptr
Helper typedef for a shared pointer of a NexusFileIO.
Helper class which provides the Collimation Length for SANS instruments.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces