12#include "MantidNexus/NexusFile.h"
20enum class NexusType { Muon, Processed, ISIS, TofRaw };
21enum class TimeType { StartTime, EndTime };
23Mantid::Types::Core::DateAndTime getValue(
const std::string &filename,
const std::string &absAddress) {
25 nxfile.openAddress(absAddress);
26 const auto valueStr = nxfile.getStrData();
27 g_log.
debug(valueStr +
" from " + absAddress +
" in " + filename);
28 return Mantid::Types::Core::DateAndTime(valueStr);
34NexusType whichNexusType(
const std::string &filename) {
35 std::vector<std::string> entryName;
36 std::vector<std::string> definition;
43 }
else if (
count == 0) {
44 g_log.
error(
"Error no entries found in " + filename);
50 nexusType = NexusType::Muon;
51 }
else if (entryName[0] ==
"mantid_workspace_1") {
52 nexusType = NexusType::Processed;
54 }
else if (entryName[0] ==
"raw_data_1") {
55 nexusType = NexusType::ISIS;
58 const auto entries = nxfile.getEntries();
59 const auto firstEntryName = entries.begin()->first;
61 nxfile.openAddress(
"/" + firstEntryName +
"/instrument/SNSdetector_calibration_id");
63 g_log.
error(
"File " + filename +
" is a currently unsupported type of NeXus file");
66 nexusType = NexusType::TofRaw;
75std::string getDataFieldAddress(
const NexusType nexusType,
const TimeType type) {
76 std::string datafieldaddress;
79 if (type == TimeType::StartTime) {
80 datafieldaddress =
"/run/start_time";
82 datafieldaddress =
"/run/stop_time";
86 if (type == TimeType::StartTime) {
87 datafieldaddress =
"/raw_data_1/start_time";
89 datafieldaddress =
"/raw_data_1/end_time";
92 case NexusType::Processed:
93 if (type == TimeType::StartTime) {
94 datafieldaddress =
"/mantid_workspace_1/logs/run_start/value";
96 datafieldaddress =
"/mantid_workspace_1/logs/run_end/value";
99 case NexusType::TofRaw:
100 if (type == TimeType::StartTime) {
101 datafieldaddress =
"/entry/start_time";
103 datafieldaddress =
"/entry/end_time";
107 throw std::runtime_error(
"Unkown Nexus format. Not able to extract a date and time.");
110 return datafieldaddress;
116Mantid::Types::Core::DateAndTime extractDateAndTime(TimeType type,
const std::string &filename) {
118 auto fullFileName = Mantid::API::FileFinder::Instance().getFullPath(filename);
121 auto nexusType = whichNexusType(fullFileName);
123 const auto dataAddress = getDataFieldAddress(nexusType, type);
125 return getValue(fullFileName, dataAddress);
136 return extractDateAndTime(TimeType::StartTime, filename);
146 return extractDateAndTime(TimeType::EndTime, filename);
static 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.
static const std::string muonTD
static const std::string pulsedTD
Records the filename and the description of failure.
The Logger class is in charge of the publishing messages from the framework through various channels.
void debug(const std::string &msg)
Logs at debug level.
void error(const std::string &msg)
Logs at error level.
Kernel::Logger g_log("ExperimentInfo")
static logger object
Mantid::Types::Core::DateAndTime DLLExport extractEndTime(const std::string &filename)
Gets the start time from the nexus file.
Mantid::Types::Core::DateAndTime DLLExport extractStartTime(const std::string &filename)
Extracts the start and the end time from a Nexus file.