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.");
94 double sampleToDetectorDistance =
getProperty(
"DetectorDistance");
95 H5::DataSet thetaDataset = h5file.openDataSet(
"entry0/instrument/2theta/value");
97 thetaDataset.read(&theta, thetaDataset.getDataType());
98 double twoThetaAngle = theta +
static_cast<double>(
getProperty(
"ThetaOffset"));
100 thetaDataset.close();
119 rotateInst->setPropertyValue(
"ComponentName",
"detector");
120 rotateInst->setPropertyValue(
"Z",
"1");
121 rotateInst->setProperty<
double>(
"Angle", 90);
122 rotateInst->execute();
125 double angleRad = angle * M_PI / 180.0;
126 double dx = -distance * sin(angleRad);
127 double dz = distance * cos(angleRad);
130 moveInst->setPropertyValue(
"ComponentName",
"detector");
131 moveInst->setProperty<
double>(
"X", dx);
132 moveInst->setProperty<
double>(
"Y", 0.);
133 moveInst->setProperty<
double>(
"Z", dz);
134 moveInst->setProperty<
bool>(
"RelativePosition",
false);
140 rotateInst->setPropertyValue(
"ComponentName",
"detector");
141 rotateInst->setPropertyValue(
"X",
"1");
142 rotateInst->setProperty<
double>(
"Angle", -angle);
143 rotateInst->execute();
151 H5::DataSet detectorDataset = h5file.openDataSet(
"entry0/data/Multi_data");
152 H5::DataSet monitorDataset = h5file.openDataSet(
"entry0/monitor/data");
159 detectorDataset.read(dataInt.data(), detectorDataset.getDataType());
162 for (
size_t i = 0; i < dataInt.size(); i++) {
163 double count = dataInt[i];
169 detectorDataset.close();
170 monitorDataset.close();
179 H5::DataSet detectorDataset = h5file.openDataSet(
"entry0/data_scan/detector_data/data");
180 H5::DataSpace detectorDataspace = detectorDataset.getSpace();
182 int nDims = detectorDataspace.getSimpleExtentNdims();
183 std::vector<hsize_t> dimsSize(nDims);
184 detectorDataspace.getSimpleExtentDims(dimsSize.data(), NULL);
186 size_t numberOfScans = dimsSize[0];
189 std::ostringstream oss;
190 oss <<
"Unexpected data shape, got " << dimsSize[1] <<
"x" << dimsSize[2] <<
"pixels ";
192 throw std::runtime_error(oss.str());
200 detectorDataset.read(dataInt.data(), detectorDataset.getDataType());
202 detectorDataset.close();
205 H5::DataSet scanVarNames = h5file.openDataSet(
"entry0/data_scan/scanned_variables/variables_names/name");
206 H5::DataSpace scanVarNamesSpace = scanVarNames.getSpace();
208 nDims = scanVarNamesSpace.getSimpleExtentNdims();
209 dimsSize.resize(nDims);
210 scanVarNamesSpace.getSimpleExtentDims(dimsSize.data(),
nullptr);
212 std::vector<char *> rdata(dimsSize[0]);
213 scanVarNames.read(rdata.data(), scanVarNames.getDataType());
214 size_t monitorIndex = 0;
215 while (monitorIndex < rdata.size()) {
216 if (std::string(rdata[monitorIndex]) ==
"Monitor1")
220 if (monitorIndex == rdata.size())
221 throw std::runtime_error(
"Monitor count not found. Please check your nexus file.");
222 scanVarNames.vlenReclaim(rdata.data(), scanVarNames.getDataType(), scanVarNamesSpace);
224 scanVarNames.close();
227 H5::DataSet scanVar = h5file.openDataSet(
"entry0/data_scan/scanned_variables/data");
228 H5::DataSpace scanVarSpace = scanVar.getSpace();
230 nDims = scanVarSpace.getSimpleExtentNdims();
231 std::vector<double> monitorData;
232 dimsSize.resize(nDims);
233 if (dimsSize.size() < 2) {
234 throw std::runtime_error(
"Scanned variables are not formatted properly. Check you nexus file.");
236 scanVarSpace.getSimpleExtentDims(dimsSize.data(),
nullptr);
238 if (dimsSize[1] != numberOfScans)
239 throw std::runtime_error(
"Scanned variables are not formatted properly. Check you nexus file.");
241 std::vector<double> scanVarData(dimsSize[0] * dimsSize[1]);
242 scanVar.read(scanVarData.data(), scanVar.getDataType());
243 monitorData.resize(dimsSize[1]);
244 for (
size_t i = 0; i < monitorData.size(); i++)
245 monitorData[i] = scanVarData[monitorIndex * dimsSize[1] + i];
250 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.