19#include "MantidNexus/NexusFile.h"
23const std::array<std::string, 5> SUPPORTED_INSTRUMENTS = {{
"IN4",
"IN5",
"IN6",
"PANTHER",
"SHARP"}};
28using namespace Kernel;
31using namespace HistogramData;
46 if ((descriptor.isEntry(
"/entry0/wavelength") && descriptor.isEntry(
"/entry0/experiment_identifier") &&
47 descriptor.isEntry(
"/entry0/mode") && !descriptor.isEntry(
"/entry0/dataSD")
49 && !descriptor.isEntry(
"/entry0/instrument/VirtualChopper")
51 && !descriptor.isEntry(
"/entry0/instrument/Tx"))
52 || (descriptor.isEntry(
"/entry0/data_scan") &&
53 descriptor.isEntry(
"/entry0/instrument/Detector"))
68 "File path of the Data file to load");
71 "The name to use for the output workspace");
119 std::vector<std::string> monitorList;
124 monitorList.push_back(
"data_scan/scanned_variables/data");
126 for (std::vector<NXClassInfo>::const_iterator it = firstEntry.
groups().begin(); it != firstEntry.
groups().end();
128 if (it->nxclass ==
"NXmonitor" || it->nxname.starts_with(
"monitor")) {
129 monitorList.push_back(it->nxname +
"/data");
147 throw std::runtime_error(
"Cannot set the instrument name from the Nexus file!");
152 if (std::find(SUPPORTED_INSTRUMENTS.begin(), SUPPORTED_INSTRUMENTS.end(),
m_instrumentName) ==
153 SUPPORTED_INSTRUMENTS.end()) {
154 std::string message =
"The instrument " +
m_instrumentName +
" is not valid for this loader!";
155 throw std::runtime_error(message);
164 std::string message(
"Cannot find monitor[1] in the Nexus file!");
165 throw std::runtime_error(message);
180 const std::string dataName =
m_isScan ?
"data_scan/detector_data/data" :
"data";
191 size_t numberOfTubesInRosace = 0;
194 numberOfTubesInRosace +=
static_cast<size_t>(dataRosace.dim0());
216 m_localWorkspace->getAxis(0)->unit() = UnitFactory::Instance().create(
"TOF");
220 m_localWorkspace->getAxis(0)->unit() = UnitFactory::Instance().create(
"Wavelength");
240 time_of_flight_data.
load();
270 g_log.
debug() <<
"convertNexusToProperties: Error loading " << filename;
275 g_log.
debug() <<
"End parsing properties from : " << filename <<
'\n';
294 runDetails.
addProperty(
"Facility", std::string(
"ILL"));
302 double n_pulses = -1;
303 double fermiChopperSpeed = -1;
310 if (std::abs(bkgChopper1Speed - bkgChopper2Speed) > 1) {
311 throw std::invalid_argument(
"Background choppers 1 and 2 have different speeds");
314 n_pulses = fermiChopperSpeed / bkgChopper1Speed / 4;
319 n_pulses = fermiChopperSpeed / suppressorSpeed;
324 const double pulseInterval = 60.0 / (2 * fermiChopperSpeed) * n_pulses;
325 runDetails.
addProperty<
double>(
"pulse_interval", pulseInterval);
339 NXInt scannedAxis = entry.
openNXInt(
"data_scan/scanned_variables/variables_names/axis");
341 std::size_t scannedVarId = 0;
343 if (scannedAxis[
index] == 1) {
344 scannedVarId =
index;
363 xAxis[i] =
static_cast<double>(i);
386 g_log.
debug() <<
"Loading data into the workspace...\n";
393 std::vector<int> detectorIDs =
m_localWorkspace->getInstrument()->getDetectorIDs(
false);
403 g_log.
debug() <<
"Loading data into the workspace: IN4 Rosace!\n";
409 spec += dataRosace.dim0();
412 for (
const auto &monitorName : monitorList) {
413 detectorIDs[spec] =
static_cast<int>(spec) + 1;
433 const std::vector<int> detectorIDs =
m_localWorkspace->getInstrument()->getDetectorIDs(
false);
434 const std::tuple<int, int, int> dimOrder{1, 2, 0};
438 const std::vector<int> monitorIDs =
m_localWorkspace->getInstrument()->getMonitors();
439 const auto spectrumNo = data.dim1() * data.dim2();
445 const auto counts = monitorData(3,
index);
std::map< DeltaEMode::Type, std::string > index
#define DECLARE_NEXUS_FILELOADER_ALGORITHM(classname)
DECLARE_NEXUS_FILELOADER_ALGORITHM should be used in place of the standard DECLARE_ALGORITHM macro wh...
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.
@ Load
allowed here which will be passed to the algorithm
Defines an interface to an algorithm that loads a file so that it can take part in the automatic sele...
void addProperty(Kernel::Property *prop, bool overwrite=false)
Add data to the object in the form of a property.
double getPropertyAsSingleValue(const std::string &name, Kernel::Math::StatisticType statistic=Kernel::Math::Mean) const
Returns a property as a single double value from its name.
HeldType getPropertyValueAsType(const std::string &name) const
Get the value of a property as the given TYPE.
This class stores information regarding an experimental run as a series of log entries.
A property class for workspaces.
Loads an ILL IN4/5/6/Panther NeXus file into a Mantid workspace.
LoadILLTOF3()
Constructor.
void exec() override
Executes the algorithm.
void fillStaticWorkspace(const Nexus::NXEntry &entry, const std::vector< std::string > &monitorList, bool convertToTOF)
Fills the non-scan measurement data into the workspace, including that from the monitor.
void initWorkspace(const Nexus::NXEntry &entry)
Creates the workspace and initialises member variables with the corresponding values.
std::vector< std::string > getMonitorInfo(const Nexus::NXEntry &firstEntry)
Finds monitor data names and stores them in a vector.
void addFacility()
Adds facility info to the sample logs.
std::string m_instrumentName
Name of the instrument.
void fillScanWorkspace(const Nexus::NXEntry &entry, const std::vector< std::string > &monitorList)
Fills scan workspace with data and monitor data counts.
void loadTimeDetails(const Nexus::NXEntry &entry)
Load the time details from the nexus file.
void addAllNexusFieldsAsProperties(const std::string &filename)
Goes through all the fields of the NeXus file and adds them as parameters in the workspace.
size_t m_numberOfMonitors
std::string m_instrumentAddress
Name of the instrument address.
void addEnergyToRun()
Calculates the incident energy from the wavelength and adds it as sample log 'Ei'.
std::string m_monitorName
void loadInstrumentDetails(const Nexus::NXEntry &)
Sets the instrument name along with its address in the nexus file.
void init() override
Initialises the algorithm.
void addPulseInterval()
Calculates and adds the pulse intervals for the run.
std::vector< double > prepareAxis(const Nexus::NXEntry &entry, bool convertToTOF)
Prepares X axis for the workspace being loaded.
size_t m_numberOfChannels
size_t m_numberOfPixelsPerTube
API::MatrixWorkspace_sptr m_localWorkspace
double m_timeOfFlightDelay
size_t m_numberOfHistograms
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 debug(const std::string &msg)
Logs at debug 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.
The base class for a Nexus class (group).
float getFloat(const std::string &name) const
Returns a float.
bool containsGroup(const std::string &query) const
Returns whether an individual group (or group) is present.
NXFloat openNXFloat(const std::string &name) const
Creates and opens a float dataset.
std::vector< NXClassInfo > & groups() const
Returns a list of all classes (or groups) in this NXClass.
NXClass openNXGroup(const std::string &name) const
Creates and opens an arbitrary (non-standard) class (group).
NXInt openNXInt(const std::string &name) const
Creates and opens an integer dataset.
bool containsDataSet(const std::string &query) const
Returns whether an individual dataset is present.
Templated class implementation of NXDataSet.
void load()
Read all of the datablock in.
dimsize_t dim0() const
Returns the number of elements along the first dimension.
Implements NXentry Nexus class.
Implements NXroot Nexus class.
NXEntry openFirstEntry()
Open the first NXentry in the file.
std::string getStringFromNexusAddress(const Mantid::Nexus::NXEntry &, const std::string &)
void addNexusFieldsToWsRun(Nexus::File &filehandle, API::Run &runDetails, const std::string &entryName="", bool useFullAddress=false)
Add properties from a nexus file to the workspace run.
double calculateEnergy(double)
Calculate Neutron Energy from wavelength: .
Nexus::NXInt getIntDataset(const Nexus::NXEntry &, const std::string &)
Fetches NXInt data from the requested group name in the entry provided.
Nexus::NXDouble getDoubleDataset(const Nexus::NXEntry &, const std::string &)
Fetches NXDouble data from the requested group name in the entry provided.
void fillStaticWorkspace(const API::MatrixWorkspace_sptr &, const Mantid::Nexus::NXInt &, const std::vector< double > &xAxis, int64_t initialSpectrum=0, bool pointData=false, const std::vector< detid_t > &detectorIDs=std::vector< int >(), const std::set< detid_t > &acceptedID=std::set< int >(), const std::tuple< short, short, short > &axisOrder=std::tuple< short, short, short >(0, 1, 2))
Fills workspace with histogram data from provided data structure.
void loadEmptyInstrument(const API::MatrixWorkspace_sptr &ws, const std::string &instrumentName, const std::string &instrumentAddress="")
Loads empty instrument of chosen name into a provided workspace.
std::string findInstrumentNexusAddress(const Mantid::Nexus::NXEntry &)
Finds the address for the instrument name in the nexus file Usually of the form: entry0/<NXinstrument...
@ Input
An input workspace.
@ Output
An output workspace.