21#include "MantidLegacyNexus/NeXusException.hpp"
22#include "MantidLegacyNexus/NeXusFile.hpp"
23#include "MantidLegacyNexus/NexusClasses.h"
36using namespace Kernel;
38using namespace DataObjects;
48 const std::vector<std::string> exts{
".nxs",
".nx5",
".xml",
".n*"};
50 "The name of the Nexus file to read, as a full or relative path.");
53 "The name of the workspace to be created as the output of "
54 "the algorithm. A workspace of this name will be created "
55 "and stored in the Analysis Data Service. For multiperiod "
56 "files, one workspace will be generated for each period.");
59 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
60 mustBePositive->setLower(0);
61 declareProperty(
"SpectrumMin", 1, mustBePositive,
"Number of first spectrum to read, only for single period data.");
63 "Number of last spectrum to read, only for single period data.");
65 "List of spectrum numbers to read, only for single period data.");
68 "0 indicates that every entry is loaded, into a separate "
69 "workspace within a group. "
70 "A positive number identifies one entry to be loaded, into "
87 std::vector<std::string> entryName, definition;
92 }
else if (
count == 0) {
98 }
else if (entryName[0] ==
"mantid_workspace_1") {
100 }
else if (entryName[0] ==
"raw_data_1") {
104 Mantid::LegacyNexus::NXEntry entry = root.openEntry(root.groups().front().nxname);
106 Mantid::LegacyNexus::NXChar nxc = entry.openNXChar(
"instrument/SNSdetector_calibration_id");
120 loadMuonNexus->setPropertyValue(
"Filename",
m_filename);
122 std::string outputWorkspace =
"OutputWorkspace";
123 loadMuonNexus->setPropertyValue(outputWorkspace,
m_workspace);
124 loadMuonNexus->setPropertyValue(
"DeadTimeTable",
m_workspace +
"_DeadTimeTable");
125 loadMuonNexus->setPropertyValue(
"DetectorGroupingTable",
m_workspace +
"DetectorGroupingTable");
126 loadMuonNexus->setPropertyValue(
"TimeZeroTable",
m_workspace +
"TimeZeroTable");
130 std::vector<int> specList =
getProperty(
"SpectrumList");
131 if (!specList.empty())
132 loadMuonNexus->setPropertyValue(
"SpectrumList",
getPropertyValue(
"SpectrumList"));
136 loadMuonNexus->setPropertyValue(
"SpectrumMax",
getPropertyValue(
"SpectrumMax"));
137 loadMuonNexus->setPropertyValue(
"SpectrumMin",
getPropertyValue(
"SpectrumMin"));
139 loadMuonNexus->setPropertyValue(
"EntryNumber",
getPropertyValue(
"EntryNumber"));
144 loadMuonNexus->execute();
150 if (!loadMuonNexus->isExecuted())
151 g_log.
error(
"Unable to successfully run LoadMuonNexus2 Child Algorithm");
159 loadNexusPro->setPropertyValue(
"Filename",
m_filename);
161 loadNexusPro->setPropertyValue(
"OutputWorkspace",
m_workspace);
163 loadNexusPro->setPropertyValue(
"SpectrumMin",
getPropertyValue(
"SpectrumMin"));
164 loadNexusPro->setPropertyValue(
"SpectrumMax",
getPropertyValue(
"SpectrumMax"));
165 loadNexusPro->setPropertyValue(
"SpectrumList",
getPropertyValue(
"SpectrumList"));
170 loadNexusPro->setPropertyValue(
"EntryNumber",
getPropertyValue(
"EntryNumber"));
172 loadNexusPro->execute();
173 if (!loadNexusPro->isExecuted())
174 g_log.
error(
"Unable to successfully run LoadNexusProcessed Child Algorithm");
182 loadNexusPro->setPropertyValue(
"Filename",
m_filename);
184 std::string outputWorkspace =
"OutputWorkspace";
185 loadNexusPro->setPropertyValue(outputWorkspace,
m_workspace);
188 std::vector<int> specList =
getProperty(
"SpectrumList");
189 if (!specList.empty())
190 loadNexusPro->setPropertyValue(
"SpectrumList",
getPropertyValue(
"SpectrumList"));
194 loadNexusPro->setPropertyValue(
"SpectrumMax",
getPropertyValue(
"SpectrumMax"));
195 loadNexusPro->setPropertyValue(
"SpectrumMin",
getPropertyValue(
"SpectrumMin"));
197 loadNexusPro->setPropertyValue(
"EntryNumber",
getPropertyValue(
"EntryNumber"));
199 loadNexusPro->execute();
201 if (!loadNexusPro->isExecuted())
202 g_log.
error(
"Unable to successfully run LoadISISNexus Child Algorithm");
210 loadNexusPro->setPropertyValue(
"Filename",
m_filename);
212 std::string outputWorkspace =
"OutputWorkspace";
213 loadNexusPro->setPropertyValue(outputWorkspace,
m_workspace);
216 std::vector<int> specList =
getProperty(
"SpectrumList");
217 if (!specList.empty())
218 loadNexusPro->setPropertyValue(
"SpectrumList",
getPropertyValue(
"SpectrumList"));
222 loadNexusPro->setPropertyValue(
"SpectrumMax",
getPropertyValue(
"SpectrumMax"));
223 loadNexusPro->setPropertyValue(
"SpectrumMin",
getPropertyValue(
"SpectrumMin"));
228 loadNexusPro->execute();
229 }
catch (std::runtime_error &) {
230 g_log.
error(
"Unable to successfully run LoadTOFRawNexus Child Algorithm");
232 if (!loadNexusPro->isExecuted())
233 g_log.
error(
"Unable to successfully run LoadTOFRawNexus Child Algorithm");
246 const std::vector<Property *> &loaderProps = loader->getProperties();
247 const size_t count = loader->propertyCount();
248 for (
size_t i = 0; i <
count; ++i) {
251 const std::string &propName = prop->
name();
276 std::vector<std::string> &definition) {
277 std::unique_ptr<Mantid::LegacyNexus::File> fileH;
280 fileH = std::make_unique<Mantid::LegacyNexus::File>(fileName);
281 }
catch (Mantid::LegacyNexus::Exception &) {
291 std::vector<std::string> entryList;
293 std::pair<std::string, std::string> entry;
295 entry = fileH->getNextEntry();
296 if (entry == LegacyNexus::EOD_ENTRY)
299 if (entry.second ==
"NXentry")
300 entryList.emplace_back(entry.first);
306 for (
auto &item : entryList) {
307 fileH->openGroup(item,
"NXentry");
310 entry = fileH->getNextEntry();
311 if (entry == LegacyNexus::EOD_ENTRY)
314 if (entry.second ==
"SDS") {
316 if (entry.first ==
"definition" || entry.first ==
"analysis") {
318 fileH->readData(entry.first,
value);
319 definition.emplace_back(
value);
320 entryName.emplace_back(item);
327 return (
static_cast<int>(entryName.size()));
#define DECLARE_ALGORITHM(classname)
double value
The value of the point.
Base class from which all concrete algorithm classes should be derived.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
bool existsProperty(const std::string &name) const override
Checks whether the named property is already in the list of managed property.
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.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
@ Load
allowed here which will be passed to the algorithm
An interface that is implemented by WorkspaceProperty.
A property class for workspaces.
std::string m_filename
The name and path of the input file.
void exec() override
Overwrites Algorithm method.
void runLoadIsisNexus()
run LoadIsisNexus
void runLoadNexusProcessed()
run LoadNexusProcessed
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.
void runLoadTOFRawNexus()
run LoadTOFRawNexus
std::string m_workspace
The name of the output workspace.
LoadNexus()
Default constructor.
static const std::string muonTD
void setOutputWorkspace(const API::IAlgorithm_sptr &loader)
set the output workspaces from the child algorithms
void runLoadMuonNexus()
run LoadMuonNexus
void init() override
Overwrites Algorithm method.
static const std::string pulsedTD
Support for a property that holds an array of values.
Records the filename and the description of failure.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void error(const std::string &msg)
Logs at error level.
Base class for properties.
unsigned int direction() const
returns the direction of the property
const std::string & name() const
Get the property's name.
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
@ Output
An output workspace.