18#include "MantidHistogramData/LinearGenerator.h"
24#include "MantidNexus/NexusFile.h"
27#include <boost/algorithm/string.hpp>
28#include <boost/format.hpp>
33using namespace Kernel;
44 : m_numberOfTubes{16}, m_numberOfChannels{1024}, m_numberOfSimpleDetectors{8}, m_numberOfMonitors{1}, m_bats{
false},
45 m_firstTubeAngleRounded{251}, m_supportedInstruments{
"IN16B"} {}
65 if (descriptor.
isEntry(
"/entry0/wavelength")
66 && descriptor.
isEntry(
"/entry0/experiment_identifier")
67 && descriptor.
isEntry(
"/entry0/mode")
68 && ((descriptor.
isEntry(
"/entry0/instrument/Doppler/mirror_sense") &&
69 descriptor.
isEntry(
"/entry0/dataSD/SingleD_data"))
70 || (descriptor.
isEntry(
"/entry0/instrument/Doppler/doppler_frequency") &&
71 descriptor.
isEntry(
"/entry0/dataSD/dataSD"))
84 "File path of the Data file to load");
87 "The name to use for the output workspace");
89 std::vector<std::string> loadingOptions{
"Spectrometer",
"Diffractometer"};
90 declareProperty(
"LoadDetectors",
"Spectrometer", std::make_shared<StringListValidator>(loadingOptions),
91 "Select the type of data to load from IN16B.");
104 size_t progressSteps =
m_loadOption ==
"Diffractometer" ? 5 : 7;
119 progress.report(
"Initialised the workspace");
122 progress.report(
"Loaded data details");
132 progress.report(
"Loaded the instrument");
136 progress.report(
"Loaded the single detectors");
139 progress.report(
"Rotating tubes if necessary");
151 if (instrumentNameAddress.empty()) {
152 std::string message(
"Cannot set the instrument name from the Nexus file!");
154 throw std::runtime_error(message);
166 return "instrument/DiffDet/data";
168 return "dataDiffDet/DiffDet_data";
170 throw std::runtime_error(
"Cannot find diffraction detector data in the Nexus file. Make sure "
171 "they exist or load the spectrometer data instead.");
205 std::string entryNameFlagSD = boost::str(boost::format(
"instrument/SingleD/tubes%i_function") % (i + 1));
209 if (flagSD[0] == 1.0)
223 firstTubeAngle.
load();
242 const auto timeChannels =
243 make_cow<HistogramData::HistogramX>(
m_numberOfChannels + 1, HistogramData::LinearGenerator(0.0, 1.0));
244 for (
size_t i = 0; i < nHistograms; ++i) {
247 m_localWorkspace->getAxis(0)->unit() = UnitFactory::Instance().create(
"Empty");
259 std::iota(xAxis.begin(), xAxis.end(), 0.0);
277 std::set<detid_t> sdIndices;
279 [offset](
const auto &
index) { return index + offset; });
302 int *monitor_p = &dataMon(0, 0);
306 std::transform(monitor_p, monitor_p +
m_numberOfChannels, dataE.begin(), [](
const double v) { return std::sqrt(v); });
314 if (i == 2 || i == 3) {
324 int *data_p = &data(
static_cast<int>(i),
static_cast<int>(j), 0);
328 std::transform(data_p, data_p +
m_numberOfChannels, E.begin(), [](
const double v) { return std::sqrt(v); });
344 g_log.
debug() <<
"convertNexusToProperties: Error loading \"" << nexusfilename <<
"\" in read mode: " << e.what()
348 runDetails.
addProperty(
"Facility", std::string(
"ILL"));
358 instrumentFileName +=
"D";
362 instrumentFileName +=
"F";
364 instrumentFileName +=
"_Definition.xml";
365 return instrumentFileName;
376 double r, theta, phi;
377 V3D oldPos = component->getPos();
381 g_log.
debug() << componentName <<
" : t = " << theta <<
" ==> t = " <<
twoTheta <<
"\n";
383 const auto componentIndex = compInfo.indexOf(component->getComponentID());
384 compInfo.setPosition(componentIndex, newPos);
393 std::string prefix(
"single_tube_");
396 std::string angleEntry = boost::str(boost::format(
"instrument/SingleD/SD%i angle") % (i + 1));
413 <<
" degrees. Check your instrument configuration. "
414 "Assuming 25.1 degrees instead.";
418 rotator->setProperty(
"RelativeRotation",
false);
419 rotator->setPropertyValue(
"ComponentName",
"psds");
420 rotator->setProperty(
"Y", 1.);
421 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 loadDataIntoWorkspace(const Nexus::NXEntry &entry)
Load data found in nexus file in general, indirect mode.
void setInstrumentName(const Nexus::NXEntry &firstEntry, const std::string &instrumentNameAddress)
Set member variable with the instrument name.
void moveComponent(const std::string &, double)
Moves the component to the given 2theta.
std::string m_instrumentName
Name of the instrument.
std::set< int32_t > m_activeSDIndices
std::string getDataAddress(const Nexus::NXEntry &entry)
void initWorkSpace()
Creates the workspace and initialises member variables with the corresponding values.
void loadDiffractionData(Nexus::NXEntry &entry)
LoadILLIndirect2::loadDiffractionData Load IN16B diffraction data from the Nexus file when requested.
const std::string name() const override
Algorithm's name for identification.
size_t m_numberOfPixelsPerTube
std::string getInstrumentFileName()
Attaches proper suffixes of the relevant IDF dependent on first tube angle and mode.
size_t m_numberOfSimpleDetectors
size_t m_numberOfChannels
void loadDataDetails(const Nexus::NXEntry &entry)
Load Data details (number of tubes, channels, etc)
API::MatrixWorkspace_sptr m_localWorkspace
void rotateTubes()
The detector has two positions.
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
int confidence(Nexus::NexusDescriptor &descriptor) const override
Returns a confidence value that this algorithm can load a file.
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.
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.
Class that provides for a standard Nexus exception.
The base class for a Nexus class (group).
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.
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.
Implements NXentry Nexus class.
Implements NXroot Nexus class.
NXEntry openFirstEntry()
Open the first NXentry in the file.
bool isEntry(const std::string &entryName, const std::string &groupClass) const noexcept
Checks if a full-address entry exists for a particular groupClass in a Nexus dataset.
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.
Nexus::NXInt getIntDataset(const Nexus::NXEntry &, const std::string &)
Fetches NXInt 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...
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.
int32_t detid_t
Typedef for a detector ID.
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.