15#include "MantidHistogramData/Points.h"
38 descriptor.
pathExists(
"/entry0/instrument/Tx") && descriptor.
pathExists(
"/entry0/instrument/Ty") &&
39 descriptor.
pathExists(
"/entry0/instrument/Tz"))
50 "File path of the Data file to load");
52 "The name to use for the output workspace");
53 auto mustBePositive = std::make_shared<Kernel::BoundedValidator<double>>();
54 mustBePositive->setLower(0.0);
55 declareProperty(
"DetectorDistance", 1.0, mustBePositive,
"Distance between the sample and the detector (meters)");
56 declareProperty(
"ThetaOffset", 0.0,
"Offset for the 2theta value (degrees)");
64 H5::H5File h5file(filename, H5F_ACC_RDONLY);
71 H5::Group detectorDataset = h5file.openGroup(
"entry0/data");
72 detectorDataset.close();
74 }
catch (H5::Exception &) {
77 if (fileType == NONE) {
79 H5::Group detectorDataset = h5file.openGroup(
"entry0/data_scan");
80 detectorDataset.close();
82 }
catch (H5::Exception &) {
89 throw std::runtime_error(
"The Nexus file your are trying to open is not supported by the SALSA loader.");
101 double sampleToDetectorDistance =
getProperty(
"DetectorDistance");
102 H5::DataSet thetaDataset = h5file.openDataSet(
"entry0/instrument/2theta/value");
104 thetaDataset.read(&theta, thetaDataset.getDataType());
105 double twoThetaAngle = theta +
static_cast<double>(
getProperty(
"ThetaOffset"));
107 thetaDataset.close();
122 loadInst->setPropertyValue(
"InstrumentName",
"SALSA");
128 double angleRad = angle * M_PI / 180.0;
129 double dx = -distance * sin(angleRad);
130 double dz = distance * cos(angleRad);
133 moveInst->setPropertyValue(
"ComponentName",
"detector");
134 moveInst->setProperty<
double>(
"X", dx);
135 moveInst->setProperty<
double>(
"Y", 0.);
136 moveInst->setProperty<
double>(
"Z", dz);
137 moveInst->setProperty<
bool>(
"RelativePosition",
false);
143 rotateInst->setPropertyValue(
"ComponentName",
"detector");
144 rotateInst->setPropertyValue(
"Y",
"1");
145 rotateInst->setProperty<
double>(
"Angle", -angle);
146 rotateInst->execute();
154 H5::DataSet detectorDataset = h5file.openDataSet(
"entry0/data/Multi_data");
155 H5::DataSet monitorDataset = h5file.openDataSet(
"entry0/monitor/data");
162 detectorDataset.read(dataInt.data(), detectorDataset.getDataType());
165 for (
size_t i = 0; i < dataInt.size(); i++) {
166 double count = dataInt[i];
172 detectorDataset.close();
173 monitorDataset.close();
182 H5::DataSet detectorDataset = h5file.openDataSet(
"entry0/data_scan/detector_data/data");
183 H5::DataSpace detectorDataspace = detectorDataset.getSpace();
185 int nDims = detectorDataspace.getSimpleExtentNdims();
186 std::vector<hsize_t> dimsSize(nDims);
187 detectorDataspace.getSimpleExtentDims(dimsSize.data(), NULL);
189 size_t numberOfScans = dimsSize[0];
192 std::ostringstream oss;
193 oss <<
"Unexpected data shape, got " << dimsSize[1] <<
"x" << dimsSize[2] <<
"pixels ";
195 throw std::runtime_error(oss.str());
203 detectorDataset.read(dataInt.data(), detectorDataset.getDataType());
205 detectorDataset.close();
208 H5::DataSet scanVarNames = h5file.openDataSet(
"entry0/data_scan/scanned_variables/variables_names/name");
209 H5::DataSpace scanVarNamesSpace = scanVarNames.getSpace();
211 nDims = scanVarNamesSpace.getSimpleExtentNdims();
212 dimsSize = std::vector<hsize_t>(nDims);
213 scanVarNamesSpace.getSimpleExtentDims(dimsSize.data(),
nullptr);
215 std::vector<char *> rdata(dimsSize[0]);
216 scanVarNames.read(rdata.data(), scanVarNames.getDataType());
217 size_t monitorIndex = 0;
218 while (monitorIndex < rdata.size()) {
219 if (std::string(rdata[monitorIndex]) ==
"Monitor1")
223 if (monitorIndex == rdata.size())
224 throw std::runtime_error(
"Monitor count not found. Please check your nexus file.");
225 scanVarNames.vlenReclaim(rdata.data(), scanVarNames.getDataType(), scanVarNamesSpace);
227 scanVarNames.close();
230 H5::DataSet scanVar = h5file.openDataSet(
"entry0/data_scan/scanned_variables/data");
231 H5::DataSpace scanVarSpace = scanVar.getSpace();
233 nDims = scanVarSpace.getSimpleExtentNdims();
234 dimsSize = std::vector<hsize_t>(nDims);
235 scanVarSpace.getSimpleExtentDims(dimsSize.data(),
nullptr);
236 if ((nDims != 2) || (dimsSize[1] != numberOfScans))
237 throw std::runtime_error(
"Scanned variables are not formatted properly. Check you nexus file.");
239 std::vector<double> scanVarData(dimsSize[0] * dimsSize[1]);
240 scanVar.read(scanVarData.data(), scanVar.getDataType());
241 std::vector<double> monitorData(dimsSize[1]);
242 for (
size_t i = 0; i < monitorData.size(); i++)
243 monitorData[i] = scanVarData[monitorIndex * dimsSize[1] + i];
248 for (
size_t j = 0; j < numberOfScans; j++) {
262 NXopen(filename.c_str(), NXACC_READ, &nxHandle);
#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.
@ Load
allowed here which will be passed to the algorithm
This class stores information regarding an experimental run as a series of log entries.
A property class for workspaces.
void exec() override
Executes the algorithm.
void init() override
Initialises the algorithm.
void loadNexusV2(const H5::H5File &h5file)
Load V2 Nexus file.
void fillWorkspaceMetadata(const std::string &filename)
int confidence(Kernel::NexusDescriptor &descriptor) const override
Returns a confidence value that this algorithm can load a file.
std::shared_ptr< DataObjects::Workspace2D > m_outputWorkspace
static const size_t HORIZONTAL_NUMBER_PIXELS
void loadNexusV1(const H5::H5File &h5file)
Load V1 Nexus file.
void setInstrument(double distance, double angle)
Load the instrument and set its position.
static const size_t VERTICAL_NUMBER_PIXELS
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
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.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
void addNexusFieldsToWsRun(NXhandle nxfileID, API::Run &runDetails, const std::string &entryName="", bool useFullPath=false)
Add properties from a nexus file to the workspace run.
FileType
Allowed file types.
@ Output
An output workspace.