17#include "MantidNexus/NexusFile.h"
33const std::vector<std::string>
EVENT_NEXUS_EXT = {
"_event.nxs",
".nxs",
".nxs.h5"};
37const std::vector<std::string>
RAW_EXT = {
".raw"};
43constexpr double BYTES_TO_GiB = 1. / 1024. / 1024. / 1024.;
60 std::set<std::string> exts_set;
64 std::vector<std::string> exts(exts_set.begin(), exts_set.end());
66 "The name of the event nexus, raw, or histo nexus file to "
67 "read, including its full or relative path. The Event NeXus file name is "
68 "typically of the form INST_####_event.nxs (N.B. case sensitive if "
69 "running on Linux).");
71 auto mustBePositive = std::make_shared<BoundedValidator<double>>();
72 mustBePositive->setLower(0.0);
74 "Get chunking strategy for chunks with this number of "
75 "Gbytes. File will not be loaded if this option is set.");
78 "An output workspace.");
85 double maxChunk = this->
getProperty(
"MaxChunkSize");
87 g_log.
debug() <<
"Converting maxChunk=0 to maxChunk=EMPTY_DBL\n";
92 int m_numberOfSpectra = 0;
99 strategy->addColumn(
"int",
"ChunkNumber");
100 strategy->addColumn(
"int",
"TotalChunks");
102 strategy->addColumn(
"int",
"SpectrumMin");
103 strategy->addColumn(
"int",
"SpectrumMax");
107 if (maxChunk == 0 ||
isEmpty(maxChunk)) {
111 std::filesystem::path fileinfo(filename);
112 const double fileSizeGiB =
static_cast<double>(std::filesystem::file_size(fileinfo)) * BYTES_TO_GiB;
115 if (6. * fileSizeGiB < maxChunk)
119 double wkspSizeGiB = 0;
124 Nexus::File file(filename);
128 file.openGroup(m_top_entry_name,
"NXentry");
131 map<string, string> entries = file.getEntries();
132 map<string, string>::const_iterator it = entries.begin();
133 std::string classType =
"NXevent_data";
134 size_t total_events = 0;
135 for (; it != entries.end(); ++it) {
136 const std::string entry_class(it->second);
137 if (entry_class == classType) {
140 const std::string entry_name(it->first);
142 file.openGroup(entry_name, entry_class);
143 file.openData(
"total_counts");
145 std::vector<uint64_t> bank_events;
146 file.getData(bank_events);
147 total_events += bank_events[0];
149 std::vector<int> bank_events;
150 file.getDataCoerce(bank_events);
151 total_events += bank_events[0];
156 g_log.
error() <<
"Unable to find total counts to determine "
157 "chunking strategy.\n";
167 wkspSizeGiB =
static_cast<double>(total_events) * 48.0 * BYTES_TO_GiB;
170 wkspSizeGiB = fileSizeGiB * 24.0;
171 g_log.
notice() <<
"Wksp size is " << wkspSizeGiB <<
" GB\n";
176 iraw.
ioRAW(file,
true);
179 m_numberOfSpectra = iraw.
t_nsp1;
180 g_log.
notice() <<
"Spectra size is " << m_numberOfSpectra <<
" spectra\n";
186 wkspSizeGiB = fileSizeGiB * 144.0;
187 g_log.
notice() <<
"Wksp size is " << wkspSizeGiB <<
" GB\n";
192 std::vector<std::string> bankNames;
194 m_numberOfSpectra =
static_cast<int>(lp.
m_numPixels);
195 g_log.
notice() <<
"Spectra size is " << m_numberOfSpectra <<
" spectra\n";
197 throw(std::invalid_argument(
"unsupported file type"));
203 numChunks =
static_cast<int>(wkspSizeGiB / maxChunk);
207 if (numChunks <= 1 ||
isEmpty(maxChunk)) {
208 g_log.
information() <<
"Everything can be done in a single chunk returning empty table\n";
213 for (
int i = 1; i <= numChunks; i++) {
216 row << i << numChunks;
218 int spectraPerChunk = m_numberOfSpectra / numChunks;
219 int first = (i - 1) * spectraPerChunk + 1;
220 int last = first + spectraPerChunk - 1;
222 last = m_numberOfSpectra;
223 row << first << last;
230 std::string top_entry_name;
231 using string_map_t = std::map<std::string, std::string>;
233 string_map_t::const_iterator it;
234 Nexus::File file = Nexus::File(filename);
235 string_map_t entries = file.getEntries();
238 top_entry_name = entries.begin()->first;
240 for (it = entries.begin(); it != entries.end(); ++it) {
241 if (((it->first ==
"entry") || (it->first ==
"raw_data_1")) && (it->second ==
"NXentry")) {
242 top_entry_name = it->first;
246 }
catch (
const std::exception &) {
247 g_log.
error() <<
"Unable to determine name of top level NXentry - assuming "
249 top_entry_name =
"entry";
251 return top_entry_name;
264 g_log.
information() <<
"Determined \'" << filename <<
"\' is a histogram nexus file\n";
270 g_log.
information() <<
"Determined \'" << filename <<
"\' is an event nexus file\n";
276 g_log.
information() <<
"Determined \'" << filename <<
"\' is an ISIS raw file\n";
280 throw std::invalid_argument(
"Unsupported file type");
284 const std::vector<std::string> &fileExtensions) {
285 return std::any_of(fileExtensions.cbegin(), fileExtensions.cend(),
286 [&filename](
const auto &extension) { return filename.find(extension) != std::string::npos; });
#define DECLARE_ALGORITHM(classname)
int t_nsp1
number of spectra in time regime 1
virtual int ioRAW(FILE *file, bool from_file, bool read_data=true)
stuff
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
static bool isEmpty(const NumT toCheck)
checks that the value was not set by users, uses the value in empty double/int.
@ Load
allowed here which will be passed to the algorithm
TableRow represents a row in a TableWorkspace.
A property class for workspaces.
void init() override
Virtual method - must be overridden by concrete algorithm.
int version() const override
function to return a version of the algorithm, must be overridden in all algorithms
void exec() override
Virtual method - must be overridden by concrete algorithm.
const std::string name() const override
function to return a name of the algorithm, must be overridden in all algorithms
FileType getFileType(const std::string &filename)
Determine the file type using the filename.
const std::string category() const override
function to return a category of the algorithm.
std::string setTopEntryName(const std::string &filename)
set the name of the top level NXentry m_top_entry_name
bool filenameHasExtension(const std::string &filename, const std::vector< std::string > &fileExtensions)
Helper class for LoadRaw algorithms.
FILE * openRawFile(const std::string &fileName)
Opens Raw File.
Loads a NeXus file that conforms to the TOFRaw instrument definition format and stores it in a 2D wor...
int m_signalNo
Signal # to load. Default 1.
static std::string getEntryName(const std::string &filename)
void countPixels(const std::string &nexusfilename, const std::string &entry_name, std::vector< std::string > &bankNames)
Goes thoguh a histogram NXS file and counts the number of pixels.
size_t m_numPixels
Number of pixels.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
void notice(const std::string &msg)
Logs at notice level.
void error(const std::string &msg)
Logs at error level.
void information(const std::string &msg)
Logs at information level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Class that provides for a standard Nexus exception.
static unsigned short constexpr UINT64
ISIS VMS raw file definitions.
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
const std::vector< std::string > RAW_EXT
Valid extensions for ISIS raw files.
FileType
DetermineChunking : Workflow algorithm to determine chunking.
@ RAW_FILE
ISIS raw files.
@ HISTO_NEXUS_FILE
Histogram NeXus files.
@ EVENT_NEXUS_FILE
Event NeXus files.
const std::vector< std::string > HISTO_NEXUS_EXT
Valid extensions for histogram nexus files.
const std::vector< std::string > EVENT_NEXUS_EXT
Valid extensions for event nexus files.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Output
An output workspace.