20#include <boost/algorithm/string/predicate.hpp>
24const std::array<std::string, 5> SUPPORTED_INSTRUMENTS = {{
"IN4",
"IN5",
"IN6",
"PANTHER",
"SHARP"}};
29using namespace Kernel;
32using namespace HistogramData;
47 if (descriptor.pathExists(
"/entry0/wavelength") && descriptor.pathExists(
"/entry0/experiment_identifier") &&
48 descriptor.pathExists(
"/entry0/mode") && !descriptor.pathExists(
"/entry0/dataSD")
50 && !descriptor.pathExists(
"/entry0/instrument/VirtualChopper")
52 && !descriptor.pathExists(
"/entry0/data_scan")
53 && !descriptor.pathExists(
"/entry0/instrument/Tx")
68 "File path of the Data file to load");
71 "The name to use for the output workspace");
120 std::vector<std::vector<int>> monitorList;
122 for (std::vector<NXClassInfo>::const_iterator it = firstEntry.
groups().begin(); it != firstEntry.
groups().end();
125 if (it->nxclass ==
"NXmonitor" || boost::starts_with(it->nxname,
"monitor")) {
127 g_log.
debug() <<
"Load monitor data from " + it->nxname;
134 std::vector<int> thisMonitor(data(), data() + data.
size());
135 monitorList.emplace_back(thisMonitor);
151 throw std::runtime_error(
"Cannot set the instrument name from the Nexus file!");
156 if (std::find(SUPPORTED_INSTRUMENTS.begin(), SUPPORTED_INSTRUMENTS.end(),
m_instrumentName) ==
157 SUPPORTED_INSTRUMENTS.end()) {
158 std::string message =
"The instrument " +
m_instrumentName +
" is not valid for this loader!";
159 throw std::runtime_error(message);
168 std::string message(
"Cannot find monitor[1] in the Nexus file!");
169 throw std::runtime_error(message);
191 const size_t numberOfMonitors = monitors.size();
196 size_t numberOfTubesInRosace = 0;
198 NXData dataGroupRosace = entry.
openNXData(
"instrument/Detector_Rosace/data");
200 numberOfTubesInRosace +=
static_cast<size_t>(dataRosace.
dim0());
242 time_of_flight_data.
load();
269 NXstatus stat = NXopen(filename.c_str(), NXACC_READ, &nxfileID);
271 g_log.
debug() <<
"Starting parsing properties from : " << filename <<
'\n';
272 if (stat == NX_ERROR) {
273 g_log.
debug() <<
"convertNexusToProperties: Error loading " << filename;
279 g_log.
debug() <<
"End parsing properties from : " << filename <<
'\n';
298 runDetails.
addProperty(
"Facility", std::string(
"ILL"));
306 double n_pulses = -1;
307 double fermiChopperSpeed = -1;
314 if (std::abs(bkgChopper1Speed - bkgChopper2Speed) > 1) {
315 throw std::invalid_argument(
"Background choppers 1 and 2 have different speeds");
318 n_pulses = fermiChopperSpeed / bkgChopper1Speed / 4;
323 n_pulses = fermiChopperSpeed / suppressorSpeed;
328 const double pulseInterval = 60.0 / (2 * fermiChopperSpeed) * n_pulses;
329 runDetails.
addProperty<
double>(
"pulse_interval", pulseInterval);
343 g_log.
debug() <<
"Loading data into the workspace...\n";
362 X0[i] =
static_cast<double>(i);
375 const std::vector<detid_t> detectorIDs = instrument->getDetectorIDs(
true);
381 g_log.
debug() <<
"Loading detector data into the workspace: DONE!\n";
387 g_log.
debug() <<
"Loading data into the workspace: IN4 Rosace!\n";
389 NXData dataGroupRosace = entry.
openNXData(
"instrument/Detector_Rosace/data");
391 auto numberOfTubes =
static_cast<size_t>(dataRosace.
dim0());
397 loadSpectra(spec, numberOfTubes, detectorIDs, dataRosace, progressRosace);
400 const auto monitorIDs = instrument->getMonitors();
402 for (
size_t i = 0; i < monitors.size(); ++i) {
403 const auto &monitor = monitors[i];
423 for (
int i = 0; i < static_cast<int>(numberOfTubes); ++i) {
425 const int *data_p = &data(
static_cast<int>(i),
static_cast<int>(j), 0);
429 m_localWorkspace->getSpectrum(currentSpectrum).setDetectorID(detectorIDs[currentSpectrum]);
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#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.
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.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
@ 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.
Helper class for reporting progress from algorithms.
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.
API::MatrixWorkspace_sptr m_localWorkspace
void loadTimeDetails(const NeXus::NXEntry &entry)
Load the time details from the nexus file.
void init() override
Initialises the algorithm.
size_t m_numberOfPixelsPerTube
void addEnergyToRun()
Calculates the incident energy from the wavelength and adds it as sample log 'Ei'.
void initWorkSpace(NeXus::NXEntry &entry, const std::vector< std::vector< int > > &)
Creates the workspace and initialises member variables with the corresponding values.
double m_timeOfFlightDelay
void loadInstrumentDetails(const NeXus::NXEntry &)
Sets the instrument name along with its path in the nexus file.
std::string m_instrumentPath
Name of the instrument path.
std::vector< std::vector< int > > getMonitorInfo(const NeXus::NXEntry &firstEntry)
Loads Monitor data into an vector of monitor data.
void loadDataIntoTheWorkSpace(NeXus::NXEntry &entry, const std::vector< std::vector< int > > &, bool convertToTOF)
Loads all the spectra into the workspace, including that from the monitor.
LoadILLTOF2()
Constructor.
std::string m_instrumentName
Name of the instrument.
std::string m_monitorName
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_numberOfChannels
void loadSpectra(size_t &spec, const size_t numberOfTubes, const std::vector< Mantid::detid_t > &detectorIDs, const NeXus::NXInt &data, Mantid::API::Progress &progress)
Loops over all the pixels and loads the correct spectra.
void addPulseInterval()
Calculates and adds the pulse intervals for the run.
void addFacility()
Adds facility info to the sample logs.
void exec() override
Executes the algorithm.
size_t m_numberOfHistograms
void runLoadInstrument()
Runs LoadInstrument to attach the instrument to the workspace.
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.
Defines a wrapper around a file whose internal structure can be accessed using the NeXus API.
OptionalBool : Tri-state bool.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
The base class for a Nexus class (group).
NXClass openNXGroup(const std::string &name) const
Creates and opens an arbitrary (non-standard) class (group).
bool containsGroup(const std::string &query) const
Returns whether an individual group (or group) is present.
std::vector< NXClassInfo > & groups() const
Returns a list of all classes (or groups) in this NXClass.
bool containsDataSet(const std::string &query) const
Returns whether an individual dataset is present.
float getFloat(const std::string &name) const
Returns a float.
NXFloat openNXFloat(const std::string &name) const
Creates and opens a float dataset.
Templated class implementation of NXDataSet.
void load(const int blocksize=1, int i=-1, int j=-1, int k=-1, int l=-1) override
Implementation of the virtual NXDataSet::load(...) method.
int size() const
Returns the size of the data buffer.
int dim2() const
Returns the number of elements along the third dimension.
int dim0() const
Returns the number of elements along the first dimension.
int dim1() const
Returns the number of elements along the second dimension.
Implements NXdata Nexus class.
NXInt openIntData()
Opens data of int type.
Implements NXentry Nexus class.
NXData openNXData(const std::string &name) const
Opens a NXData.
Implements NXroot Nexus class.
NXEntry openFirstEntry()
Open the first NXentry in the file.
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
double calculateEnergy(double)
Calculate Neutron Energy from wavelength: .
std::string getStringFromNexusPath(const Mantid::NeXus::NXEntry &, const std::string &)
void addNexusFieldsToWsRun(NXhandle nxfileID, API::Run &runDetails, const std::string &entryName="", bool useFullPath=false)
Add properties from a nexus file to the workspace run.
std::string findInstrumentNexusPath(const Mantid::NeXus::NXEntry &)
Finds the path for the instrument name in the nexus file Usually of the form: entry0/<NXinstrument cl...
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
@ Input
An input workspace.
@ Output
An output workspace.