71 if (!h5file.nameExists(
"entry0"))
72 throw std::runtime_error(
73 "The Nexus file your are trying to open is incorrectly formatted, 'entry0' group does not exist");
74 H5::Group entryGroup = h5file.openGroup(
"entry0");
75 if (entryGroup.nameExists(
"data"))
77 else if (entryGroup.nameExists(
"data_scan"))
83 throw std::runtime_error(
"The Nexus file your are trying to open is not supported by the SALSA loader.");
95 double sampleToDetectorDistance =
getProperty(
"DetectorDistance");
96 H5::DataSet thetaDataset = h5file.openDataSet(
"entry0/instrument/2theta/value");
98 thetaDataset.read(&theta, thetaDataset.getDataType());
99 double twoThetaAngle = theta +
static_cast<double>(
getProperty(
"ThetaOffset"));
101 thetaDataset.close();
120 rotateInst->setPropertyValue(
"ComponentName",
"detector");
121 rotateInst->setPropertyValue(
"Z",
"1");
122 rotateInst->setProperty<
double>(
"Angle", 90);
123 rotateInst->execute();
126 double angleRad = angle * M_PI / 180.0;
127 double dx = -distance * sin(angleRad);
128 double dz = distance * cos(angleRad);
131 moveInst->setPropertyValue(
"ComponentName",
"detector");
132 moveInst->setProperty<
double>(
"X", dx);
133 moveInst->setProperty<
double>(
"Y", 0.);
134 moveInst->setProperty<
double>(
"Z", dz);
135 moveInst->setProperty<
bool>(
"RelativePosition",
false);
141 rotateInst->setPropertyValue(
"ComponentName",
"detector");
142 rotateInst->setPropertyValue(
"X",
"1");
143 rotateInst->setProperty<
double>(
"Angle", -angle);
144 rotateInst->execute();
152 H5::DataSet detectorDataset = h5file.openDataSet(
"entry0/data/Multi_data");
153 H5::DataSet monitorDataset = h5file.openDataSet(
"entry0/monitor/data");
160 detectorDataset.read(dataInt.data(), detectorDataset.getDataType());
163 for (
size_t i = 0; i < dataInt.size(); i++) {
164 double count = dataInt[i];
170 detectorDataset.close();
171 monitorDataset.close();
180 H5::DataSet detectorDataset = h5file.openDataSet(
"entry0/data_scan/detector_data/data");
181 H5::DataSpace detectorDataspace = detectorDataset.getSpace();
183 int nDims = detectorDataspace.getSimpleExtentNdims();
184 std::vector<hsize_t> dimsSize(nDims);
185 detectorDataspace.getSimpleExtentDims(dimsSize.data(), NULL);
187 size_t numberOfScans = dimsSize[0];
190 std::ostringstream oss;
191 oss <<
"Unexpected data shape, got " << dimsSize[1] <<
"x" << dimsSize[2] <<
"pixels ";
193 throw std::runtime_error(oss.str());
201 detectorDataset.read(dataInt.data(), detectorDataset.getDataType());
203 detectorDataset.close();
206 H5::DataSet scanVarNames = h5file.openDataSet(
"entry0/data_scan/scanned_variables/variables_names/name");
207 H5::DataSpace scanVarNamesSpace = scanVarNames.getSpace();
209 nDims = scanVarNamesSpace.getSimpleExtentNdims();
210 dimsSize.resize(nDims);
211 scanVarNamesSpace.getSimpleExtentDims(dimsSize.data(),
nullptr);
213 std::vector<char *> rdata(dimsSize[0]);
214 scanVarNames.read(rdata.data(), scanVarNames.getDataType());
215 size_t monitorIndex = 0;
216 while (monitorIndex < rdata.size()) {
217 if (std::string(rdata[monitorIndex]) ==
"Monitor1")
221 if (monitorIndex == rdata.size())
222 throw std::runtime_error(
"Monitor count not found. Please check your nexus file.");
223 scanVarNames.vlenReclaim(rdata.data(), scanVarNames.getDataType(), scanVarNamesSpace);
225 scanVarNames.close();
228 H5::DataSet scanVar = h5file.openDataSet(
"entry0/data_scan/scanned_variables/data");
229 H5::DataSpace scanVarSpace = scanVar.getSpace();
231 nDims = scanVarSpace.getSimpleExtentNdims();
232 std::vector<double> monitorData;
233 dimsSize.resize(nDims);
234 if (dimsSize.size() < 2) {
235 throw std::runtime_error(
"Scanned variables are not formatted properly. Check you nexus file.");
237 scanVarSpace.getSimpleExtentDims(dimsSize.data(),
nullptr);
239 if (dimsSize[1] != numberOfScans)
240 throw std::runtime_error(
"Scanned variables are not formatted properly. Check you nexus file.");
242 std::vector<double> scanVarData(dimsSize[0] * dimsSize[1]);
243 scanVar.read(scanVarData.data(), scanVar.getDataType());
244 monitorData.resize(dimsSize[1]);
245 for (
size_t i = 0; i < monitorData.size(); i++)
246 monitorData[i] = scanVarData[monitorIndex * dimsSize[1] + i];
251 for (
size_t j = 0; j < numberOfScans; j++) {
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 addNexusFieldsToWsRun(Nexus::File &filehandle, API::Run &runDetails, const std::string &entryName="", bool useFullAddress=false)
Add properties from a nexus file to the workspace run.