18#include "MantidHistogramData/LinearGenerator.h"
25#include <boost/algorithm/string.hpp>
26#include <boost/format.hpp>
28#include <nexus/napi.h>
32using namespace Kernel;
43 : m_numberOfTubes{16}, m_numberOfChannels{1024}, m_numberOfSimpleDetectors{8}, m_numberOfMonitors{1}, m_bats{
false},
44 m_firstTubeAngleRounded{251}, m_supportedInstruments{
"IN16B"} {}
64 if (descriptor.
pathExists(
"/entry0/wavelength")
65 && descriptor.
pathExists(
"/entry0/experiment_identifier")
67 && ((descriptor.
pathExists(
"/entry0/instrument/Doppler/mirror_sense") &&
68 descriptor.
pathExists(
"/entry0/dataSD/SingleD_data"))
69 || (descriptor.
pathExists(
"/entry0/instrument/Doppler/doppler_frequency") &&
70 descriptor.
pathExists(
"/entry0/dataSD/dataSD"))
83 "File path of the Data file to load");
86 "The name to use for the output workspace");
88 std::vector<std::string> loadingOptions{
"Spectrometer",
"Diffractometer"};
89 declareProperty(
"LoadDetectors",
"Spectrometer", std::make_shared<StringListValidator>(loadingOptions),
90 "Select the type of data to load from IN16B.");
103 size_t progressSteps =
m_loadOption ==
"Diffractometer" ? 5 : 7;
118 progress.report(
"Initialised the workspace");
121 progress.report(
"Loaded data details");
131 progress.report(
"Loaded the instrument");
135 progress.report(
"Loaded the single detectors");
138 progress.report(
"Rotating tubes if necessary");
150 if (instrumentNamePath.empty()) {
151 std::string message(
"Cannot set the instrument name from the Nexus file!");
153 throw std::runtime_error(message);
165 return "instrument/DiffDet/data";
167 return "dataDiffDet/DiffDet_data";
169 throw std::runtime_error(
"Cannot find diffraction detector data in the Nexus file. Make sure "
170 "they exist or load the spectrometer data instead.");
207 for (
int i = 1; i <= dataSD.
dim0(); ++i) {
209 std::string entryNameFlagSD = boost::str(boost::format(
"instrument/SingleD/tubes%i_function") % i);
213 if (flagSD[0] == 1.0)
227 firstTubeAngle.
load();
246 const auto timeChannels =
247 make_cow<HistogramData::HistogramX>(
m_numberOfChannels + 1, HistogramData::LinearGenerator(0.0, 1.0));
248 for (
size_t i = 0; i < nHistograms; ++i) {
275 int *monitor_p = &dataMon(0, 0);
279 std::transform(monitor_p, monitor_p +
m_numberOfChannels, dataE.begin(), [](
const double v) { return std::sqrt(v); });
286 int *data_p = &data(
static_cast<int>(i),
static_cast<int>(j), 0);
290 std::transform(data_p, data_p +
m_numberOfChannels, E.begin(), [](
const double v) { return std::sqrt(v); });
297 int *dataSD_p = &dataSD(
index - 1, 0, 0);
301 std::transform(dataSD_p, dataSD_p +
m_numberOfChannels, E.begin(), [](
const double v) { return std::sqrt(v); });
331 int *monitor_p = &dataMon(0, 0);
335 std::transform(monitor_p, monitor_p +
m_numberOfChannels, dataE.begin(), [](
const double v) { return std::sqrt(v); });
343 if (i == 2 || i == 3) {
353 int *data_p = &data(
static_cast<int>(i),
static_cast<int>(j), 0);
357 std::transform(data_p, data_p +
m_numberOfChannels, E.begin(), [](
const double v) { return std::sqrt(v); });
370 NXstatus stat = NXopen(nexusfilename.c_str(), NXACC_READ, &nxfileID);
371 if (stat == NX_ERROR) {
372 g_log.
debug() <<
"convertNexusToProperties: Error loading " << nexusfilename;
376 runDetails.
addProperty(
"Facility", std::string(
"ILL"));
407 Poco::Path file(idf +
"_Definition.xml");
408 Poco::Path fullPath(directory, file);
409 return fullPath.toString();
420 double r, theta, phi;
421 V3D oldPos = component->getPos();
425 g_log.
debug() << componentName <<
" : t = " << theta <<
" ==> t = " <<
twoTheta <<
"\n";
427 const auto componentIndex = compInfo.indexOf(component->getComponentID());
428 compInfo.setPosition(componentIndex, newPos);
437 std::string prefix(
"single_tube_");
440 std::string angleEntry = boost::str(boost::format(
"instrument/SingleD/SD%i angle") % i);
457 <<
" degrees. Check your instrument configuration. "
458 "Assuming 25.1 degrees instead.";
462 rotator->setProperty(
"RelativeRotation",
false);
463 rotator->setPropertyValue(
"ComponentName",
"psds");
464 rotator->setProperty(
"Y", 1.);
465 rotator->setProperty(
"Angle", -8.);
std::map< DeltaEMode::Type, std::string > index
#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.
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
void addProperty(Kernel::Property *prop, bool overwrite=false)
Add data to the object in the form of a property.
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 IN16B nexus file into a Mantid workspace.
const std::string category() const override
Algorithm's category for identification.
void loadDiffractionData(NeXus::NXEntry &entry)
LoadILLIndirect2::loadDiffractionData Load IN16B diffraction data from the Nexus file when requested.
void moveComponent(const std::string &, double)
Moves the component to the given 2theta.
std::string m_instrumentName
Name of the instrument.
void initWorkSpace()
Creates the workspace and initialises member variables with the corresponding values.
std::set< int > m_activeSDIndices
void loadDataIntoTheWorkSpace(NeXus::NXEntry &entry)
Load data found in nexus file in general, indirect mode.
void loadDataDetails(NeXus::NXEntry &entry)
Load Data details (number of tubes, channels, etc)
const std::string name() const override
Algorithm's name for identification.
size_t m_numberOfPixelsPerTube
std::string getDataPath(const NeXus::NXEntry &entry)
void setInstrumentName(const NeXus::NXEntry &firstEntry, const std::string &instrumentNamePath)
Set member variable with the instrument name.
void runLoadInstrument()
Run the Child Algorithm LoadInstrument.
size_t m_numberOfSimpleDetectors
size_t m_numberOfChannels
API::MatrixWorkspace_sptr m_localWorkspace
void rotateTubes()
The detector has two positions.
int confidence(Kernel::NexusDescriptor &descriptor) const override
Returns a confidence value that this algorithm can load a file.
std::string getInstrumentFilePath()
Makes up the full path of the relevant IDF dependent on first tube angle and mode.
void exec() override
Execute the algorithm.
void init() override
Initialize the algorithm's properties.
void loadNexusEntriesIntoProperties(const std::string &nexusfilename)
Loads the sample logs.
void moveSingleDetectors(const NeXus::NXEntry &entry)
IN16B has a few single detectors that are place around the sample.
size_t m_firstTubeAngleRounded
size_t m_numberOfMonitors
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.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
Defines a wrapper around a file whose internal structure can be accessed using the NeXus API.
bool pathExists(const std::string &path) const
Query if a path exists.
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...
void spherical(const double R, const double theta, const double phi) noexcept
Sets the vector position based on spherical coordinates.
void getSpherical(double &R, double &theta, double &phi) const noexcept
Return the vector's position in spherical coordinates.
The base class for a Nexus class (group).
NXInt openNXInt(const std::string &name) const
Creates and opens an integer dataset.
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.
bool containsDataSet(const std::string &query) const
Returns whether an individual dataset is present.
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 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
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::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
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.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Output
An output workspace.