43#include <boost/algorithm/string/trim.hpp>
44#include <boost/regex.hpp>
58using namespace DataObjects;
59using namespace Kernel;
62using Mantid::Types::Event::TofEvent;
63using Types::Core::DateAndTime;
87using SpectraInfo_optional = std::optional<SpectraInfo>;
96SpectraInfo extractMappingInfo(
const NXEntry &mtd_entry,
Logger &logger) {
97 SpectraInfo spectraInfo;
101 logger.
information() <<
"No NXinstrument group called `instrument` under "
102 "NXEntry. The workspace will not "
103 "contain any detector information.\n";
108 logger.
information() <<
"Detector block not found. The workspace will not "
109 "contain any detector information.\n";
121 spectra_block.
load();
122 spectraInfo.spectraNumbers = spectra_block.
vecBuffer();
123 spectraInfo.nSpectra =
static_cast<int>(spectra_block.
dim0());
124 spectraInfo.hasSpectra =
true;
125 }
catch (std::runtime_error &) {
126 spectraInfo.hasSpectra =
false;
135 detlist_group.
load();
136 spectraInfo.detectorList = detlist_group.
vecBuffer();
137 }
catch (std::runtime_error &) {
138 logger.
information() <<
"detector_list block not found. The workspace will "
139 "not contain any detector information.\n";
147 spectraInfo.detectorCount = det_count.
vecBuffer();
151 spectraInfo.nSpectra =
static_cast<int>(det_index.
dim0());
152 spectraInfo.detectorIndex = det_index.
vecBuffer();
165 bool isMultiPeriod =
false;
167 const std::string nPeriodsLogEntryName =
"nperiods";
168 const Run &run = expInfo->run();
171 if (nPeriods == nWorkspaceEntries) {
172 isMultiPeriod =
true;
173 log.
information(
"Loading as MultiPeriod group workspace.");
177 return isMultiPeriod;
184 : m_shared_bins(false), m_xbins(0), m_axis1vals(), m_list(false), m_interval(false), m_spec_min(0),
185 m_spec_max(
Mantid::
EMPTY_INT()), m_spec_list(), m_filtered_spec_idxs(), m_nexusFile() {}
198 if (descriptor.
isEntry(
"/mantid_workspace_1"))
213 const std::vector<std::string> exts{
".nxs",
".nx5",
".xml"};
215 "The name of the Nexus file to read, as a full or relative path.");
217 "The name of the workspace to be created as the output of "
218 "the algorithm. A workspace of this name will be created "
219 "and stored in the Analysis Data Service. For multiperiod "
220 "files, one workspace may be generated for each period. "
221 "Currently only one workspace can be saved at a time so "
222 "multiperiod Mantid files are not generated.");
225 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
226 mustBePositive->setLower(0);
229 declareProperty(
"SpectrumMin",
static_cast<int>(1), mustBePositive,
"Number of first spectrum to read.");
231 "Number of last spectrum to read.");
234 "0 indicates that every entry is loaded, into a separate "
235 "workspace within a group. "
236 "A positive number identifies one entry to be loaded, into "
238 declareProperty(
"LoadHistory",
true,
"If true, the workspace history will be loaded");
240 "For multiperiod workspaces. Copy instrument, parameter and x-data "
241 "rather than loading it directly for each workspace. Y, E and log "
242 "information is always loaded.");
257 const size_t nWorkspaceEntries,
const size_t p) {
261 const size_t nHistograms = periodWorkspace->getNumberHistograms();
262 for (
size_t i = 0; i < nHistograms; ++i) {
263 periodWorkspace->setSharedX(i, tempMatrixWorkspace->sharedX(i));
275 NXEntry mtdEntry(root, entryName);
278 NXData wsEntry(mtdEntry,
"workspace");
280 std::stringstream buffer;
281 buffer <<
"Group entry " << p - 1
282 <<
" is not a workspace 2D. Retry with "
283 "FastMultiPeriod option set off.\n";
284 throw std::runtime_error(buffer.str());
287 if (wsEntry.
isValid(
"frac_area")) {
288 std::stringstream buffer;
289 buffer <<
"Group entry " << p - 1
290 <<
" has fractional area present. Try "
291 "reloading with FastMultiPeriod set "
293 throw std::runtime_error(buffer.str());
301 const int64_t nChannels = data.
dim1();
306 static_cast<int>(nHistograms) / blockSize;
307 const int readOptimumStop = (nFullBlocks * blockSize);
309 const int finalBlockSize = readStop - readOptimumStop;
314 for (; histIndex < readStop;) {
315 if (histIndex >= readOptimumStop) {
316 blockSize = finalBlockSize;
319 data.
load(blockSize, histIndex);
320 errors.
load(blockSize, histIndex);
322 double *dataStart = data();
323 double *dataEnd = dataStart + nChannels;
325 double *errorStart = errors();
326 double *errorEnd = errorStart + nChannels;
328 int64_t
final(histIndex + blockSize);
329 while (histIndex <
final) {
330 auto &
Y = periodWorkspace->mutableY(wsIndex);
331 Y.assign(dataStart, dataEnd);
332 dataStart += nChannels;
333 dataEnd += nChannels;
334 auto &E = periodWorkspace->mutableE(wsIndex);
335 E.assign(errorStart, errorEnd);
336 errorStart += nChannels;
337 errorEnd += nChannels;
355 periodWorkspace->loadSampleAndLogInfoNexus(
m_nexusFile.get());
356 }
catch (std::exception &e) {
366 const double fractionComplete = double(p - 1) / double(nWorkspaceEntries);
367 progress(fractionComplete,
"Loading multiperiod entry");
368 return periodWorkspace;
380 size_t nWorkspaceEntries = 0;
385 bool bDefaultEntryNumber = entryNumberProperty->
isDefault();
399 nWorkspaceEntries = std::count_if(root.
groups().cbegin(), root.
groups().cend(),
400 [](
const auto &g) { return g.nxclass ==
"NXentry"; });
402 if (!bDefaultEntryNumber &&
static_cast<size_t>(entryNumber) > nWorkspaceEntries) {
403 g_log.
error() <<
"Invalid entry number: " << entryNumber
404 <<
" specified. File only contains: " << nWorkspaceEntries <<
" entries.\n";
405 throw std::invalid_argument(
"Invalid entry number specified.");
408 const std::string basename =
"mantid_workspace_";
410 std::ostringstream os;
411 if (bDefaultEntryNumber) {
415 os << basename << entryNumber;
416 const std::string targetEntryName = os.str();
420 tempWS =
loadEntry(root, targetEntryName, 0, 1);
422 if (nWorkspaceEntries == 1 || !bDefaultEntryNumber) {
429 const bool bFastMultiPeriod = this->
getProperty(
"FastMultiPeriod");
430 const bool bIsMultiPeriod = isMultiPeriodFile(
static_cast<int>(nWorkspaceEntries), tempWS,
g_log);
435 auto wksp_group = std::make_shared<WorkspaceGroup>();
445 bool wsExists = AnalysisDataService::Instance().doesExist(base_name);
447 Algorithm_sptr alg = AlgorithmManager::Instance().createUnmanaged(
"DeleteWorkspace");
450 alg->setProperty(
"Workspace", base_name);
455 const std::string prop_name =
"OutputWorkspace_";
458 bool bAccelleratedMultiPeriodLoading =
false;
459 if (tempMatrixWorkspace) {
462 bAccelleratedMultiPeriodLoading = bIsMultiPeriod && bFastMultiPeriod && !
m_list;
465 tempMatrixWorkspace->mutableRun().clearLogs();
468 if (bAccelleratedMultiPeriodLoading) {
474 for (
size_t p = 1; p <= nWorkspaceEntries; ++p) {
488 if (bAccelleratedMultiPeriodLoading) {
493 const auto nWorkspaceEntries_d =
static_cast<double>(nWorkspaceEntries);
494 local_workspace =
loadEntry(root, basename + indexStr,
static_cast<double>(p - 1) / nWorkspaceEntries_d,
495 1. / nWorkspaceEntries_d);
501 wksp_group->addWorkspace(local_workspace);
502 setProperty(prop_name + indexStr, local_workspace);
506 setProperty(
"OutputWorkspace", std::static_pointer_cast<Workspace>(wksp_group));
519 if (nWorkspaceEntries == 1 || !bDefaultEntryNumber) {
520 loadNexusGeometry(*getValue<API::Workspace_sptr>(
"OutputWorkspace"),
static_cast<size_t>(entryNumber),
g_log,
525 std::shared_ptr<SpecialWorkspace2D> specialLocalWorkspace =
526 std::dynamic_pointer_cast<SpecialWorkspace2D>(getValue<API::Workspace_sptr>(
"OutputWorkspace"));
527 if (specialLocalWorkspace) {
531 for (
size_t nEntry = 1; nEntry <= static_cast<size_t>(nWorkspaceEntries); ++nEntry) {
532 std::ostringstream wsPropertyName;
533 wsPropertyName <<
"OutputWorkspace_" << nEntry;
536 std::shared_ptr<SpecialWorkspace2D> specialLocalWorkspace =
537 std::dynamic_pointer_cast<SpecialWorkspace2D>(getValue<API::Workspace_sptr>(wsPropertyName.str()));
538 if (specialLocalWorkspace) {
548 if (specialLocalWorkspace->isDetectorIDMappingEmpty()) {
549 g_log.
warning() <<
"SpecialWorkspace2D has an empty detector ID Mapping!";
551 specialLocalWorkspace->buildDetectorIDMapping();
576 boost::smatch results;
577 const boost::regex exp(
".*_(\\d+$)");
579 if (boost::regex_search(
name, results, exp)) {
580 wsName = baseName + std::string(results[1].first, results[1].second);
583 wsName = baseName +
index;
600 for (
int i = 0; !noClash; ++i) {
607 bool wsExists = AnalysisDataService::Instance().doesExist(wsName + wsIndex);
622 std::vector<std::string> names(nWorkspaceEntries + 1);
623 for (
size_t p = 1; p <= nWorkspaceEntries; ++p) {
630 auto it = std::unique(names.begin(), names.end());
631 if (it != names.end()) {
632 auto size = names.size();
648 std::string workspaceName = std::string();
650 workspaceName = mtd_entry.
getString(
"workspace_name");
651 }
catch (std::runtime_error &) {
654 return workspaceName;
669 const double &progressStart,
const double &progressRange) {
672 size_t numspec = indices_data.dim0() - 1;
680 auto num_xbins = xbins.
dim0();
681 if (xbins.
rank() == 2) {
682 num_xbins = xbins.
dim1();
690 ws->setYUnit(indices_data.attributes(
"units"));
691 std::string unitLabel = indices_data.attributes(
"unit_label");
692 if (unitLabel.empty())
693 unitLabel = indices_data.attributes(
"units");
694 ws->setYUnitLabel(unitLabel);
698 std::vector<int64_t> pulsetimes;
699 if (wksp_cls.
isValid(
"pulsetime")) {
702 pulsetimes = pulsetime.vecBuffer();
705 std::vector<double> tofs;
712 std::vector<float> error_squareds;
713 if (wksp_cls.
isValid(
"error_squared")) {
715 error_squared.
load();
716 error_squareds = error_squared.
vecBuffer();
719 std::vector<float> weights;
720 if (wksp_cls.
isValid(
"weight")) {
728 if (!tofs.empty() && !pulsetimes.empty() && !weights.empty() && !error_squareds.empty())
730 else if ((!tofs.empty() && !weights.empty() && !error_squareds.empty()))
732 else if (!pulsetimes.empty() && !tofs.empty())
735 throw std::runtime_error(
"Could not figure out the type of event list!");
738 std::vector<int64_t> indices = indices_data.vecBuffer();
743 for (int64_t j = 0; j < max; ++j) {
746 int64_t index_start = indices[wi];
747 int64_t index_end = indices[wi + 1];
748 if (index_end >= index_start) {
753 el.
reserve(index_end - index_start);
756 for (int64_t i = index_start; i < index_end; i++)
775 for (std::size_t i = 0; i < xbins.
dim1(); i++)
780 std::distance(
x.rbegin(), std::find_if_not(
x.rbegin(),
x.rend(), [](
auto val) { return std::isnan(val); }));
782 x.resize(
x.size() - idx);
804template <
typename ColumnType,
typename NexusType>
808 std::string columnTitle = data.
attributes(
"name");
809 if (!columnTitle.empty()) {
811 auto length =
static_cast<size_t>(data.
dim0());
812 auto rowCount = tableWs->rowCount();
815 tableWs->setRowCount(length);
816 }
else if (rowCount != length) {
817 throw std::runtime_error(
"Columns have different sizes.");
820 auto column = tableWs->addColumn(columnType, columnTitle);
821 for (
size_t i = 0; i < length; i++) {
822 column->cell<ColumnType>(i) =
static_cast<ColumnType
>(*(data() + i));
837 int columnNumber = 1;
839 std::string dataSetName =
"column_" +
std::to_string(columnNumber);
847 if (info.
rank == 1) {
849 loadNumericColumn<double, double>(nx_tw, dataSetName,
workspace,
"double");
851 loadNumericColumn<int, int32_t>(nx_tw, dataSetName,
workspace,
"int");
853 loadNumericColumn<uint32_t, uint32_t>(nx_tw, dataSetName,
workspace,
"uint");
855 loadNumericColumn<int64_t, int64_t>(nx_tw, dataSetName,
workspace,
"long64");
857 loadNumericColumn<size_t, uint64_t>(nx_tw, dataSetName,
workspace,
"size_t");
859 loadNumericColumn<float, float>(nx_tw, dataSetName,
workspace,
"float");
861 loadNumericColumn<bool, bool>(nx_tw, dataSetName,
workspace,
"bool");
863 throw std::logic_error(
"Column with Nexus data type " +
std::to_string(
static_cast<int>(info.
type)) +
864 " cannot be loaded.");
866 }
else if (info.
rank == 2) {
869 std::string columnTitle = data.attributes(
"name");
870 if (!columnTitle.empty()) {
871 workspace->addColumn(
"str", columnTitle);
877 for (
dimsize_t iR = 0; iR < nRows; ++iR) {
878 auto &cellContents =
workspace->cell<std::string>(iR, columnNumber - 1);
879 auto startPoint = data() + maxStr * iR;
880 cellContents.assign(startPoint, startPoint + maxStr);
881 boost::trim_right(cellContents);
885 loadVectorColumn<int32_t>(nx_tw, dataSetName,
workspace,
"vector_int");
888 if (data.attributes(
"interpret_as") ==
"V3D") {
891 loadVectorColumn<double>(nx_tw, dataSetName,
workspace,
"vector_double");
900 return std::static_pointer_cast<API::Workspace>(
workspace);
910template <
typename Type>
914 std::string columnTitle = data.
attributes(
"name");
915 if (!columnTitle.empty()) {
916 tableWs->addColumn(columnType, columnTitle);
919 const size_t rowCount = info.
dims[0];
920 const size_t blockSize = info.
dims[1];
923 tableWs->setRowCount(rowCount);
927 for (
size_t i = 0; i < rowCount; ++i) {
928 auto &cell = tableWs->cell<std::vector<Type>>(i, tableWs->columnCount() - 1);
930 Type *from = data() + blockSize * i;
932 cell.assign(from, from + blockSize);
934 std::ostringstream rowSizeAttrName;
935 rowSizeAttrName <<
"row_size_" << i;
938 std::istringstream rowSizeStr(data.
attributes(rowSizeAttrName.str()));
941 rowSizeStr >> rowSize;
943 cell.resize(rowSize);
954 std::string columnTitle = data.
attributes(
"name");
955 if (!columnTitle.empty()) {
958 const int64_t rowCount = data.
dim0();
961 tableWs->setRowCount(rowCount);
965 for (int64_t i = 0; i < rowCount; ++i) {
967 cell(data(i, 0), data(i, 1), data(i, 2));
990 size_t columnNumber = 1;
991 size_t numberPeaks = 0;
992 std::vector<std::string> columnNames;
1003 columnNames.emplace_back(str);
1010 std::string columnTitle = nxDouble.
attributes(
"name");
1011 if (!columnTitle.empty() && numberPeaks == 0) {
1012 numberPeaks = nxDouble.
dim0();
1023 }
catch (std::runtime_error &re) {
1024 throw std::runtime_error(
1025 "Error while opening a address in a Peaks entry in a Nexus processed file. This address is wrong: " +
1026 std::string(entry.
address()) +
". Lower level error description: " + re.what());
1030 std::string parameterStr;
1034 peakWS->readParameterMap(parameterStr);
1035 }
catch (std::exception &e) {
1042 const std::string peaksWSName =
"peaks_workspace";
1045 }
catch (std::runtime_error &re) {
1046 throw std::runtime_error(
"Error while opening a peaks workspace in a Nexus processed file. Cannot open group " +
1047 peaksWSName +
". Lower level error description: " + re.what());
1050 uint32_t loadCoord(0);
1051 m_nexusFile->readData(
"coordinate_system", loadCoord);
1055 auto logs = peakWS->logs();
1056 if (logs->hasProperty(
"CoordinateSystem")) {
1059 int value((*prop)());
1065 std::string m_QConvention =
"Inelastic";
1067 m_nexusFile->getAttr(
"QConvention", m_QConvention);
1068 }
catch (std::exception &) {
1076 std::string convention = ConfigService::Instance().getString(
"Q.convention");
1077 if (convention != m_QConvention)
1080 for (
size_t r = 0; r < numberPeaks; r++) {
1082 const auto &goniometer = peakWS->run().getGoniometer();
1086 peakWS->addPeak(peak);
1089 for (
const auto &str : columnNames) {
1090 if (str ==
"column_1") {
1094 for (
size_t r = 0; r < numberPeaks; r++) {
1095 double val = qSign * nxDouble[r];
1096 peakWS->getPeak(r).setH(val);
1098 }
else if (str ==
"column_2") {
1102 for (
size_t r = 0; r < numberPeaks; r++) {
1103 double val = qSign * nxDouble[r];
1104 peakWS->getPeak(r).setK(val);
1106 }
else if (str ==
"column_3") {
1110 for (
size_t r = 0; r < numberPeaks; r++) {
1111 double val = qSign * nxDouble[r];
1112 peakWS->getPeak(r).setL(val);
1114 }
else if (str ==
"column_4") {
1118 for (
size_t r = 0; r < numberPeaks; r++) {
1119 double val = nxDouble[r];
1120 peakWS->getPeak(r).setIntensity(val);
1122 }
else if (str ==
"column_5") {
1126 for (
size_t r = 0; r < numberPeaks; r++) {
1127 double val = nxDouble[r];
1128 peakWS->getPeak(r).setSigmaIntensity(val);
1130 }
else if (str ==
"column_6") {
1134 for (
size_t r = 0; r < numberPeaks; r++) {
1135 double val = nxDouble[r];
1136 peakWS->getPeak(r).setBinCount(val);
1138 }
else if (str ==
"column_7") {
1142 for (
size_t r = 0; r < numberPeaks; r++) {
1143 double val = nxDouble[r];
1144 peakWS->getPeak(r).setWavelength(val);
1146 }
else if (str ==
"column_10") {
1150 for (
size_t r = 0; r < numberPeaks; r++) {
1151 int ival = nxInt[r];
1153 peakWS->getPeak(r).setRunNumber(ival);
1155 }
else if (str ==
"column_11") {
1159 for (
size_t r = 0; r < numberPeaks; r++) {
1160 int ival = nxInt[r];
1161 peakWS->getPeak(r).setPeakNumber(ival);
1163 }
else if (str ==
"column_12") {
1167 for (
size_t r = 0; r < numberPeaks; r++) {
1168 double val = nxDouble[r];
1169 peakWS->getPeak(r).setAbsorptionWeightedPathLength(val);
1171 }
else if (str ==
"column_13") {
1176 for (
size_t r = 0; r < numberPeaks; r++) {
1177 for (
int j = 0; j < 9; j++) {
1178 double val = nxDouble[k];
1180 gm[j % 3][j / 3] = val;
1182 peakWS->getPeak(r).setGoniometerMatrix(gm);
1184 }
else if (str ==
"column_14") {
1193 peakFactoryEllipsoid->setSuccessor(peakFactorySphere);
1194 peakFactorySphere->setSuccessor(peakFactoryDetectorBin);
1195 peakFactoryDetectorBin->setSuccessor(peakFactoryNone);
1202 for (
size_t i = 0; i < numberPeaks; ++i) {
1205 auto startPoint = data() + (maxShapeJSONLength * i);
1206 std::string shapeJSON(startPoint, startPoint + maxShapeJSONLength);
1207 boost::trim_right(shapeJSON);
1213 peakWS->getPeak(i).setPeakShape(peakShape);
1215 }
else if (str ==
"column_15") {
1219 for (
size_t r = 0; r < numberPeaks; ++r) {
1220 qlab =
V3D(nxDouble[r * 3], nxDouble[r * 3 + 1], nxDouble[r * 3 + 2]);
1221 peakWS->getPeak(r).setQLabFrame(qlab, 0.0);
1223 }
else if (str ==
"column_16") {
1227 for (
size_t r = 0; r < numberPeaks; ++r) {
1228 hkl =
V3D(nxDouble[r * 3], nxDouble[r * 3 + 1], nxDouble[r * 3 + 2]);
1229 peakWS->getPeak(r).setIntHKL(hkl);
1231 }
else if (str ==
"column_17") {
1235 for (
size_t r = 0; r < numberPeaks; ++r) {
1236 mnp =
V3D(nxDouble[r * 3], nxDouble[r * 3 + 1], nxDouble[r * 3 + 2]);
1237 peakWS->getPeak(r).setIntMNP(mnp);
1239 }
else if (str ==
"column_18") {
1243 for (
size_t r = 0; r < numberPeaks; r++) {
1244 double val = nxDouble[r];
1245 peakWS->getPeak(r).setMonitorCount(val);
1250 for (
size_t r = 0; r < numberPeaks; r++) {
1251 V3D intHKL = peakWS->getPeak(r).getIntHKL();
1252 if (intHKL.
norm2() == 0) {
1253 intHKL =
V3D(peakWS->getPeak(r).getH(), peakWS->getPeak(r).getK(), peakWS->getPeak(r).getL());
1254 peakWS->getPeak(r).setIntHKL(intHKL);
1259 return std::static_pointer_cast<API::Workspace>(peakWS);
1276 size_t columnNumber = 1;
1277 size_t numberPeaks = 0;
1278 std::vector<std::string> columnNames;
1289 columnNames.emplace_back(str);
1296 std::string columnTitle = nxDouble.
attributes(
"name");
1297 if (!columnTitle.empty() && numberPeaks == 0) {
1298 numberPeaks = nxDouble.
dim0();
1309 }
catch (std::runtime_error &re) {
1310 throw std::runtime_error(
1311 "Error while opening a address in a Peaks entry in a Nexus processed file. This address is wrong: " +
1312 std::string(entry.
address()) +
". Lower level error description: " + re.what());
1316 std::string parameterStr;
1320 peakWS->readParameterMap(parameterStr);
1321 }
catch (std::exception &e) {
1328 const std::string peaksWSName =
"peaks_workspace";
1331 }
catch (std::runtime_error &re) {
1332 throw std::runtime_error(
"Error while opening a peaks workspace in a Nexus processed file. Cannot open group " +
1333 peaksWSName +
". Lower level error description: " + re.what());
1336 uint32_t loadCoord(0);
1337 m_nexusFile->readData(
"coordinate_system", loadCoord);
1341 auto logs = peakWS->logs();
1342 if (logs->hasProperty(
"CoordinateSystem")) {
1345 int value((*prop)());
1351 std::string m_QConvention =
"Inelastic";
1353 m_nexusFile->getAttr(
"QConvention", m_QConvention);
1354 }
catch (std::exception &) {
1362 std::string convention = ConfigService::Instance().getString(
"Q.convention");
1363 if (convention != m_QConvention)
1366 for (
size_t r = 0; r < numberPeaks; r++) {
1372 const auto &goniometer = peakWS->run().getGoniometer();
1377 peakWS->addPeak(std::move(peak));
1380 for (
const auto &str : columnNames) {
1381 if (str ==
"column_1") {
1385 for (
size_t r = 0; r < numberPeaks; r++) {
1386 int ival = nxInt[r];
1388 peakWS->getPeak(r).setDetectorID(ival);
1390 }
else if (str ==
"column_2") {
1394 for (
size_t r = 0; r < numberPeaks; r++) {
1395 double val = qSign * nxDouble[r];
1396 peakWS->getPeak(r).setH(val);
1398 }
else if (str ==
"column_3") {
1402 for (
size_t r = 0; r < numberPeaks; r++) {
1403 double val = qSign * nxDouble[r];
1404 peakWS->getPeak(r).setK(val);
1406 }
else if (str ==
"column_4") {
1410 for (
size_t r = 0; r < numberPeaks; r++) {
1411 double val = qSign * nxDouble[r];
1412 peakWS->getPeak(r).setL(val);
1414 }
else if (str ==
"column_5") {
1418 for (
size_t r = 0; r < numberPeaks; r++) {
1419 double val = nxDouble[r];
1420 peakWS->getPeak(r).setIntensity(val);
1422 }
else if (str ==
"column_6") {
1426 for (
size_t r = 0; r < numberPeaks; r++) {
1427 double val = nxDouble[r];
1428 peakWS->getPeak(r).setSigmaIntensity(val);
1430 }
else if (str ==
"column_7") {
1434 for (
size_t r = 0; r < numberPeaks; r++) {
1435 double val = nxDouble[r];
1436 peakWS->getPeak(r).setBinCount(val);
1438 }
else if (str ==
"column_10") {
1442 for (
size_t r = 0; r < numberPeaks; r++) {
1443 double val = nxDouble[r];
1444 peakWS->getPeak(r).setWavelength(val);
1446 }
else if (str ==
"column_14") {
1450 for (
size_t r = 0; r < numberPeaks; r++) {
1451 int ival = nxInt[r];
1453 peakWS->getPeak(r).setRunNumber(ival);
1455 }
else if (str ==
"column_17") {
1459 for (
size_t r = 0; r < numberPeaks; r++) {
1460 int ival = nxInt[r];
1461 peakWS->getPeak(r).setPeakNumber(ival);
1463 }
else if (str ==
"column_18") {
1467 for (
size_t r = 0; r < numberPeaks; r++) {
1468 double val = nxDouble[r];
1469 peakWS->getPeak(r).setAbsorptionWeightedPathLength(val);
1471 }
else if (str ==
"column_15") {
1476 for (
size_t r = 0; r < numberPeaks; r++) {
1477 for (
size_t j = 0; j < 9; j++) {
1478 double val = nxDouble[k];
1480 gm[j % 3][j / 3] = val;
1482 peakWS->getPeak(r).setGoniometerMatrix(gm);
1484 }
else if (str ==
"column_16") {
1493 peakFactoryEllipsoid->setSuccessor(peakFactorySphere);
1494 peakFactorySphere->setSuccessor(peakFactoryDetectorBin);
1495 peakFactoryDetectorBin->setSuccessor(peakFactoryNone);
1502 for (
size_t i = 0; i < numberPeaks; ++i) {
1505 auto startPoint = data() + (maxShapeJSONLength * i);
1506 std::string shapeJSON(startPoint, startPoint + maxShapeJSONLength);
1507 boost::trim_right(shapeJSON);
1513 peakWS->getPeak(i).setPeakShape(peakShape);
1515 }
else if (str ==
"column_19") {
1519 for (
size_t r = 0; r < numberPeaks; ++r) {
1520 hkl =
V3D(nxDouble[r * 3], nxDouble[r * 3 + 1], nxDouble[r * 3 + 2]);
1521 peakWS->getPeak(r).setIntHKL(hkl);
1523 }
else if (str ==
"column_20") {
1527 for (
size_t r = 0; r < numberPeaks; ++r) {
1528 mnp =
V3D(nxDouble[r * 3], nxDouble[r * 3 + 1], nxDouble[r * 3 + 2]);
1529 peakWS->getPeak(r).setIntMNP(mnp);
1531 }
else if (str ==
"column_21") {
1535 for (
size_t r = 0; r < numberPeaks; r++) {
1536 double val = nxDouble[r];
1537 peakWS->getPeak(r).setMonitorCount(val);
1542 for (
size_t r = 0; r < numberPeaks; r++) {
1543 V3D intHKL = peakWS->getPeak(r).getIntHKL();
1544 if (intHKL.
norm2() == 0) {
1545 intHKL =
V3D(peakWS->getPeak(r).getH(), peakWS->getPeak(r).getK(), peakWS->getPeak(r).getL());
1546 peakWS->getPeak(r).setIntHKL(intHKL);
1550 return std::static_pointer_cast<API::Workspace>(peakWS);
1569 const double &progressStart,
1570 const double &progressRange,
const NXEntry &mtd_entry,
1571 const int64_t xlength, std::string &workspaceType) {
1575 size_t nspectra = data.
dim0();
1581 if (nchannels == 1 && nspectra == 1) {
1585 if (hasInstrument) {
1586 std::string inst_name = mtd_entry.
getString(
"instrument/name");
1587 boost::algorithm::trim(inst_name);
1588 if (inst_name ==
"")
1589 hasInstrument =
false;
1594 hasInstrument =
true;
1597 for (
auto facility : ConfigService::Instance().getFacilities()) {
1598 for (
auto instrumentName : facility->instruments()) {
1599 if (instrumentName.name() !=
"" && mtd_entry.
containsGroup(instrumentName.name())) {
1600 hasInstrument =
true;
1613 hasMetadata =
false;
1617 if (!hasInstrument && !hasMetadata)
1618 workspaceType =
"WorkspaceSingleValue";
1620 bool hasFracArea =
false;
1621 if (wksp_cls.
isValid(
"frac_area")) {
1624 workspaceType =
"RebinnedOutput";
1630 local_workspace->setTitle(mtd_entry.
getString(
"title"));
1631 }
catch (std::runtime_error &) {
1636 local_workspace->setYUnit(data.
attributes(
"units"));
1637 std::string unitLabel = data.
attributes(
"unit_label");
1638 if (unitLabel.empty())
1640 local_workspace->setYUnitLabel(unitLabel);
1650 auto rbWS = std::dynamic_pointer_cast<RebinnedOutput>(local_workspace);
1651 auto finalizedValue = fracarea.
attributes(
"finalized");
1652 auto finalized = (finalizedValue.empty() ? true : finalizedValue ==
"1");
1653 rbWS->setFinalized(finalized);
1654 auto sqrdErrsValue = fracarea.
attributes(
"sqrd_errors");
1655 auto sqrdErrs = (sqrdErrsValue.empty() ? false : sqrdErrsValue ==
"1");
1656 rbWS->setSqrdErrors(sqrdErrs);
1661 auto hasXErrors = wksp_cls.
isValid(
"xerrors");
1662 auto xErrors = hasXErrors ? wksp_cls.
openNXDouble(
"xerrors") : errors;
1664 if (xErrors.dim1() == nchannels + 1)
1665 g_log.
warning() <<
"Legacy X uncertainty found in input file, i.e., "
1666 "delta-Q for each BIN EDGE. Uncertainties will be "
1667 "re-interpreted as delta-Q of the BIN CENTRE and the "
1668 "last value will be dropped.\n";
1675 int fullblocks =
static_cast<int>(total_specs) / blocksize;
1676 int read_stop = (fullblocks * blocksize);
1677 const double progressBegin = progressStart + 0.25 * progressRange;
1678 const double progressScaler = 0.75 * progressRange;
1679 int64_t hist_index = 0;
1680 int64_t wsIndex = 0;
1690 fullblocks = (interval_specs) / blocksize;
1691 read_stop = (fullblocks * blocksize) +
m_spec_min - 1;
1693 if (interval_specs < blocksize) {
1694 blocksize =
static_cast<int>(total_specs);
1699 for (; hist_index < read_stop;) {
1700 progress(progressBegin + progressScaler *
static_cast<double>(hist_index) /
static_cast<double>(read_stop),
1701 "Reading workspace data...");
1702 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, blocksize, nchannels, hist_index, wsIndex,
1705 size_t finalblock =
m_spec_max - 1 - read_stop;
1706 if (finalblock > 0) {
1707 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, finalblock, nchannels, hist_index,
1708 wsIndex, local_workspace);
1715 int64_t specIndex = itr - 1;
1717 progressScaler *
static_cast<double>(specIndex) /
static_cast<double>(
m_spec_list.size()),
1718 "Reading workspace data...");
1719 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, 1, nchannels, specIndex, wsIndex,
1724 for (; hist_index < read_stop;) {
1725 progress(progressBegin + progressScaler *
static_cast<double>(hist_index) /
static_cast<double>(read_stop),
1726 "Reading workspace data...");
1727 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, blocksize, nchannels, hist_index, wsIndex,
1730 size_t finalblock = total_specs - read_stop;
1731 if (finalblock > 0) {
1732 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, finalblock, nchannels, hist_index, wsIndex,
1741 fullblocks = (interval_specs) / blocksize;
1742 read_stop = (fullblocks * blocksize) +
m_spec_min - 1;
1744 if (interval_specs < blocksize) {
1745 blocksize = interval_specs;
1750 for (; hist_index < read_stop;) {
1751 progress(progressBegin + progressScaler *
static_cast<double>(hist_index) /
static_cast<double>(read_stop),
1752 "Reading workspace data...");
1753 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, xbins, blocksize, nchannels, hist_index,
1754 wsIndex, local_workspace);
1756 size_t finalblock =
m_spec_max - 1 - read_stop;
1757 if (finalblock > 0) {
1758 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, xbins, finalblock, nchannels, hist_index,
1759 wsIndex, local_workspace);
1765 int64_t specIndex = itr - 1;
1766 progress(progressBegin + progressScaler *
static_cast<double>(specIndex) /
static_cast<double>(read_stop),
1767 "Reading workspace data...");
1768 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, xbins, 1, nchannels, specIndex, wsIndex,
1773 for (; hist_index < read_stop;) {
1774 progress(progressBegin + progressScaler *
static_cast<double>(hist_index) /
static_cast<double>(read_stop),
1775 "Reading workspace data...");
1776 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, xbins, blocksize, nchannels, hist_index,
1777 wsIndex, local_workspace);
1779 size_t finalblock = total_specs - read_stop;
1780 if (finalblock > 0) {
1781 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, xbins, finalblock, nchannels, hist_index,
1782 wsIndex, local_workspace);
1787 for (
size_t i = 0; i < local_workspace->getNumberHistograms(); i++) {
1788 const auto &
x = local_workspace->readX(i);
1790 std::distance(
x.rbegin(), std::find_if_not(
x.rbegin(),
x.rend(), [](
auto val) { return std::isnan(val); }));
1792 local_workspace->resizeHistogram(i, local_workspace->histogramSize(i) - idx);
1795 return local_workspace;
1812 const double &progressStart,
const double &progressRange) {
1813 progress(progressStart,
"Opening entry " + entry_name +
"...");
1825 }
catch (std::exception &) {
1832 bool isEvent =
false;
1833 std::string workspaceType =
"Workspace2D";
1834 std::string group_name =
"workspace";
1837 group_name =
"event_workspace";
1839 workspaceType =
"OffsetsWorkspace";
1840 group_name =
"offsets_workspace";
1842 workspaceType =
"MaskWorkspace";
1843 group_name =
"mask_workspace";
1845 workspaceType =
"GroupingWorkspace";
1846 group_name =
"grouping_workspace";
1857 std::string unit1 = xbins.
attributes(
"units");
1859 int64_t xlength(-1);
1860 if (xbins.
rank() == 2) {
1861 xlength = xbins.
dim1();
1863 }
else if (xbins.
rank() == 1) {
1864 xlength = xbins.
dim0();
1867 m_xbins = HistogramData::HistogramX(xbins(), xbins() + xlength);
1869 throw std::runtime_error(
"Unknown axis1 dimension encountered.");
1874 std::string unit2 = axis2.
attributes(
"units");
1879 local_workspace =
loadEventEntry(wksp_cls, xbins, progressStart, progressRange);
1882 loadNonEventEntry(wksp_cls, xbins, progressStart, progressRange, mtd_entry, xlength, workspaceType);
1884 size_t nspectra = local_workspace->getNumberHistograms();
1887 bool verticalHistogram(
false);
1889 local_workspace->getAxis(0)->unit() = UnitFactory::Instance().create(unit1);
1890 if (unit1 ==
"Label") {
1891 auto label = std::dynamic_pointer_cast<Mantid::Kernel::Units::Label>(local_workspace->getAxis(0)->unit());
1893 label->setLabel(ax.attributes(
"caption"), ax.attributes(
"label"));
1900 if (
static_cast<size_t>(axis2.
size()) == nspectra + 1)
1901 verticalHistogram =
true;
1903 }
catch (std::runtime_error &) {
1904 g_log.
information() <<
"Axis 0 set to unitless quantity \"" << unit1 <<
"\"\n";
1908 if (unit2 ==
"TextAxis") {
1909 auto newAxis = std::make_unique<Mantid::API::TextAxis>(nspectra);
1910 local_workspace->replaceAxis(1, std::move(newAxis));
1911 }
else if (unit2 !=
"spectraNumber") {
1913 auto newAxis = (verticalHistogram) ? std::make_unique<API::BinEdgeAxis>(nspectra + 1)
1914 : std::make_unique<API::NumericAxis>(nspectra);
1915 auto newAxisRaw = newAxis.get();
1916 local_workspace->replaceAxis(1, std::move(newAxis));
1917 newAxisRaw->unit() = UnitFactory::Instance().create(unit2);
1918 if (unit2 ==
"Label") {
1919 auto label = std::dynamic_pointer_cast<Mantid::Kernel::Units::Label>(newAxisRaw->unit());
1921 label->setLabel(ax.attributes(
"caption"), ax.attributes(
"label"));
1923 }
catch (std::runtime_error &) {
1924 g_log.
information() <<
"Axis 1 set to unitless quantity \"" << unit2 <<
"\"\n";
1929 std::string dist = xbins.
attributes(
"distribution");
1931 local_workspace->setDistribution(
true);
1933 local_workspace->setDistribution(
false);
1936 progress(progressStart + 0.05 * progressRange,
"Reading the sample details...");
1942 std::string parameterStr;
1949 progress(progressStart + 0.11 * progressRange,
"Reading the parameter maps...");
1950 local_workspace->readParameterMap(parameterStr);
1951 }
catch (std::exception &e) {
1956 g_log.
warning(
"Error loading Instrument section of nxs file");
1958 g_log.
warning(
"Try running LoadInstrument Algorithm on the Workspace to "
1959 "update the geometry");
1965 if (!local_workspace->getAxis(1)->isSpectra()) {
1970 progress(progressStart + 0.15 * progressRange,
"Reading the workspace history...");
1975 local_workspace->history().loadNexus(
m_nexusFile.get());
1976 }
catch (std::out_of_range &) {
1977 g_log.
warning() <<
"Error in the workspaces algorithm list, its processing "
1978 "history is incomplete\n";
1981 progress(progressStart + 0.2 * progressRange,
"Reading the workspace history...");
1984 if (local_workspace->getTitle().empty())
1985 local_workspace->setTitle(mtd_entry.
getString(
"title"));
1986 }
catch (std::runtime_error &) {
1990 return std::static_pointer_cast<API::Workspace>(local_workspace);
2002 SpectraInfo spectraInfo = extractMappingInfo(mtd_entry, this->
g_log);
2008 for (
int i = 1; i <= spectraInfo.nSpectra; ++i) {
2016 if (spectraInfo.hasSpectra) {
2017 spectrum = spectraInfo.spectraNumbers[i - 1];
2018 }
else if (haveSpectraAxis && !
m_axis1vals.empty()) {
2030 if (!spectraInfo.detectorIndex.empty()) {
2031 const int start = spectraInfo.detectorIndex[i - 1];
2032 const int end = start + spectraInfo.detectorCount[i - 1];
2033 spec.setDetectorIDs(
2034 std::set<detid_t>(spectraInfo.detectorList.data() + start, spectraInfo.detectorList.data() + end));
2045 using namespace std;
2046 map<string, string> errorList;
2052 if (specMax < specMin) {
2053 errorList[
"SpectrumMin"] =
"SpectrumMin must be smaller than SpectrumMax";
2054 errorList[
"SpectrumMax"] =
"SpectrumMax must be larger than SpectrumMin";
2071 Axis *axis = local_workspace->getAxis(1);
2076 for (
int i = 0; i < static_cast<int>(axis->
length()); i++) {
2079 }
else if (axis->
isText()) {
2081 std::string axisLabels;
2084 axisLabels = std::string(axisData(), axisData.dim0());
2085 }
catch (std::runtime_error &) {
2091 auto *textAxis =
static_cast<TextAxis *
>(axis);
2107 std::string::size_type index1, index2;
2108 std::string num1, num2;
2110 index1 = elem1.
nxname.find(
'_');
2111 if (index1 != std::string::npos) {
2112 num1 = elem1.
nxname.substr(index1 + 1, elem1.
nxname.length() - index1);
2114 index2 = elem2.
nxname.find(
'_');
2115 if (index2 != std::string::npos) {
2116 num2 = elem2.
nxname.substr(index2 + 1, elem2.
nxname.length() - index2);
2118 std::stringstream is1, is2;
2127 return execNum1 < execNum2;
2143 if (data.
count() != 3) {
2144 g_log.
warning() <<
"Algorithm list line " + words3 +
" is not of the correct format\n";
2145 throw std::out_of_range(words3);
2167 if (data.
count() != 4) {
2168 g_log.
warning() <<
"Algorithm list line " + words4 +
" is not of the correct format\n";
2169 throw std::out_of_range(words4);
2195 const int64_t
n = spec.
dim0();
2196 const int64_t n1 =
n - 1;
2197 for (
int i = 0; i <
n; ++i) {
2198 int64_t si = spec(i, 0);
2199 int64_t j0 = spec(i, 1);
2200 int64_t j1 = i < n1 ? spec(i + 1, 1) : bins.dim0();
2201 for (int64_t j = j0; j < j1; ++j) {
2202 local_workspace->flagMasked(si, bins[j], weights[j]);
2224 bool hasXErrors, int64_t blocksize, int64_t nchannels, int64_t &hist,
2226 data.
load(blocksize, hist);
2227 errors.
load(blocksize, hist);
2228 double *data_start = data();
2229 double *data_end = data_start + nchannels;
2230 double *err_start = errors();
2231 double *err_end = err_start + nchannels;
2232 double *farea_start =
nullptr;
2233 double *farea_end =
nullptr;
2234 double *xErrors_start =
nullptr;
2235 double *xErrors_end =
nullptr;
2236 size_t dx_increment = nchannels;
2241 size_t dx_input_increment = xErrors.
dim1();
2244 farea.
load(blocksize, hist);
2245 farea_start = farea();
2246 farea_end = farea_start + nchannels;
2247 rb_workspace = std::dynamic_pointer_cast<RebinnedOutput>(local_workspace);
2250 xErrors.
load(blocksize, hist);
2251 xErrors_start = xErrors();
2252 xErrors_end = xErrors_start + dx_increment;
2255 int64_t
final(hist + blocksize);
2256 while (hist <
final) {
2257 auto &
Y = local_workspace->mutableY(hist);
2258 Y.assign(data_start, data_end);
2259 data_start += nchannels;
2260 data_end += nchannels;
2261 auto &E = local_workspace->mutableE(hist);
2262 E.assign(err_start, err_end);
2263 err_start += nchannels;
2264 err_end += nchannels;
2266 MantidVec &F = rb_workspace->dataF(hist);
2267 F.assign(farea_start, farea_end);
2268 farea_start += nchannels;
2269 farea_end += nchannels;
2272 local_workspace->setSharedDx(hist, Kernel::make_cow<HistogramData::HistogramDx>(xErrors_start, xErrors_end));
2273 xErrors_start += dx_input_increment;
2274 xErrors_end += dx_input_increment;
2277 local_workspace->setSharedX(hist,
m_xbins.cowData());
2301 bool hasXErrors, int64_t blocksize, int64_t nchannels, int64_t &hist,
2303 data.
load(blocksize, hist);
2304 errors.
load(blocksize, hist);
2305 double *data_start = data();
2306 double *data_end = data_start + nchannels;
2307 double *err_start = errors();
2308 double *err_end = err_start + nchannels;
2309 double *farea_start =
nullptr;
2310 double *farea_end =
nullptr;
2311 double *xErrors_start =
nullptr;
2312 double *xErrors_end =
nullptr;
2313 size_t dx_increment = nchannels;
2318 size_t dx_input_increment = xErrors.
dim1();
2321 farea.
load(blocksize, hist);
2322 farea_start = farea();
2323 farea_end = farea_start + nchannels;
2324 rb_workspace = std::dynamic_pointer_cast<RebinnedOutput>(local_workspace);
2327 xErrors.
load(blocksize, hist);
2328 xErrors_start = xErrors();
2329 xErrors_end = xErrors_start + dx_increment;
2332 int64_t
final(hist + blocksize);
2333 while (hist <
final) {
2334 auto &
Y = local_workspace->mutableY(wsIndex);
2335 Y.assign(data_start, data_end);
2336 data_start += nchannels;
2337 data_end += nchannels;
2338 auto &E = local_workspace->mutableE(wsIndex);
2339 E.assign(err_start, err_end);
2340 err_start += nchannels;
2341 err_end += nchannels;
2343 MantidVec &F = rb_workspace->dataF(wsIndex);
2344 F.assign(farea_start, farea_end);
2345 farea_start += nchannels;
2346 farea_end += nchannels;
2349 local_workspace->setSharedDx(wsIndex, Kernel::make_cow<HistogramData::HistogramDx>(xErrors_start, xErrors_end));
2350 xErrors_start += dx_input_increment;
2351 xErrors_end += dx_input_increment;
2353 local_workspace->setSharedX(wsIndex,
m_xbins.cowData());
2378 bool hasXErrors,
NXDouble &xbins, int64_t blocksize, int64_t nchannels,
2380 data.
load(blocksize, hist);
2381 double *data_start = data();
2382 double *data_end = data_start + nchannels;
2383 errors.
load(blocksize, hist);
2384 double *err_start = errors();
2385 double *err_end = err_start + nchannels;
2386 double *farea_start =
nullptr;
2387 double *farea_end =
nullptr;
2388 double *xErrors_start =
nullptr;
2389 double *xErrors_end =
nullptr;
2390 size_t dx_increment = nchannels;
2395 size_t dx_input_increment = xErrors.
dim1();
2398 farea.
load(blocksize, hist);
2399 farea_start = farea();
2400 farea_end = farea_start + nchannels;
2401 rb_workspace = std::dynamic_pointer_cast<RebinnedOutput>(local_workspace);
2403 xbins.
load(blocksize, hist);
2404 const int64_t nxbins(xbins.
dim1());
2405 double *xbin_start = xbins();
2406 double *xbin_end = xbin_start + nxbins;
2407 int64_t
final(hist + blocksize);
2410 xErrors.
load(blocksize, hist);
2411 xErrors_start = xErrors();
2412 xErrors_end = xErrors_start + dx_increment;
2415 while (hist <
final) {
2416 auto &
Y = local_workspace->mutableY(wsIndex);
2417 Y.assign(data_start, data_end);
2418 data_start += nchannels;
2419 data_end += nchannels;
2420 auto &E = local_workspace->mutableE(wsIndex);
2421 E.assign(err_start, err_end);
2422 err_start += nchannels;
2423 err_end += nchannels;
2425 MantidVec &F = rb_workspace->dataF(wsIndex);
2426 F.assign(farea_start, farea_end);
2427 farea_start += nchannels;
2428 farea_end += nchannels;
2431 local_workspace->setSharedDx(wsIndex, Kernel::make_cow<HistogramData::HistogramDx>(xErrors_start, xErrors_end));
2432 xErrors_start += dx_input_increment;
2433 xErrors_end += dx_input_increment;
2435 auto &
X = local_workspace->mutableX(wsIndex);
2436 X.assign(xbin_start, xbin_end);
2437 xbin_start += nxbins;
2466 throw std::invalid_argument(
"Spectra max is less than 0");
2469 if (maxlist >
static_cast<int>(numberofspectra) || minlist == 0) {
2471 throw std::invalid_argument(
"Inconsistent properties defined");
2480 m_spec_max =
static_cast<int>(numberofspectra);
2482 if (m_spec_max < m_spec_min || m_spec_max >
static_cast<int>(numberofspectra)) {
2483 g_log.
error(
"Invalid Spectrum min/max properties");
2484 throw std::invalid_argument(
"Inconsistent properties defined");
2508 m_spec_max =
static_cast<int>(numberofspectra);
2513 if (gen_filtered_list) {
2535 if (gen_filtered_list) {
2543 total_specs = numberofspectra;
2545 m_spec_max =
static_cast<int>(numberofspectra) + 1;
2547 if (gen_filtered_list) {
2549 for (
int j = 0; j < static_cast<int>(total_specs); j++)
2562 auto mWorkspace = std::dynamic_pointer_cast<MatrixWorkspace>(local_workspace);
2564 auto run = mWorkspace->run();
double value
The value of the point.
IPeaksWorkspace_sptr workspace
std::map< DeltaEMode::Type, std::string > index
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
#define PARALLEL_FOR_NO_WSP_CHECK()
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
#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.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Class to represent the axis of a workspace.
virtual bool isText() const
Returns true if the axis is Text.
virtual std::size_t length() const =0
Get the length of the axis.
virtual void setValue(const std::size_t &index, const double &value)=0
Sets the value at the specified index.
virtual bool isNumeric() const
Returns true if the axis is numeric.
virtual bool isSpectra() const
Returns true is the axis is a Spectra axis.
ColumnVector gives access to the column elements without alowing its resizing.
@ Load
allowed here which will be passed to the algorithm
static void applyLogFiltering(Mantid::API::Run &exptRun)
applies log filtering for a run
void setHistogram(T &&...data)
Sets the Histogram associated with this spectrum.
void clearDetectorIDs()
Clear the detector IDs set.
void setSpectrumNo(specnum_t num)
Sets the spectrum number of this spectrum.
bool hasProperty(const std::string &name) const
Does the property exist on the object.
HeldType getPropertyValueAsType(const std::string &name) const
Get the value of a property as the given TYPE.
Base MatrixWorkspace Abstract Class.
virtual ISpectrum & getSpectrum(const size_t index)=0
Return the underlying ISpectrum ptr at the given workspace index.
virtual Axis * getAxis(const std::size_t &axisIndex) const
Get a non owning pointer to a workspace axis.
Helper class for reporting progress from algorithms.
This class stores information regarding an experimental run as a series of log entries.
Class to represent a text axis of a workspace.
void setLabel(const std::size_t &index, const std::string &lbl)
Set the label at the given index.
A property class for workspaces.
API::Workspace_sptr loadTableEntry(const Mantid::Nexus::NXEntry &entry)
Load a table.
int m_spec_min
The value of the spectrum_min property.
Mantid::API::Workspace_sptr doAccelleratedMultiPeriodLoading(Mantid::Nexus::NXRoot &root, const std::string &entryName, Mantid::API::MatrixWorkspace_sptr &tempMatrixWorkspace, const size_t nWorkspaceEntries, const size_t p)
Accellerated multiperiod loading.
bool m_interval
Flag set if interval of spectra to write is set.
API::Workspace_sptr loadPeaksEntry(const Mantid::Nexus::NXEntry &entry)
Load peaks.
void exec() override
Overwrites Algorithm method.
~LoadNexusProcessed() override
Destructor.
HistogramData::BinEdges m_xbins
The cached x binning if we have bins.
API::Workspace_sptr loadEntry(Mantid::Nexus::NXRoot &root, const std::string &entry_name, const double &progressStart, const double &progressRange)
Load a single entry.
void checkOptionalProperties(const std::size_t numberofspectra)
Validates the optional 'spectra to read' properties, if they have been set.
void loadV3DColumn(Mantid::Nexus::NXDouble &data, const API::ITableWorkspace_sptr &tableWs)
Loads a V3D column to the TableWorkspace.
void correctForWorkspaceNameClash(std::string &wsName)
Add an index to the name if it already exists in the workspace.
virtual bool loadNexusGeometry(Mantid::API::Workspace &, size_t, Kernel::Logger &, const std::string &)
Load nexus geometry and apply to workspace.
void loadBlock(Mantid::Nexus::NXDouble &data, Mantid::Nexus::NXDouble &errors, Mantid::Nexus::NXDouble &farea, bool hasFArea, Mantid::Nexus::NXDouble &xErrors, bool hasXErrors, int64_t blocksize, int64_t nchannels, int64_t &hist, const API::MatrixWorkspace_sptr &local_workspace)
Load a block of data into the workspace where it is assumed that the x bins have already been cached.
void readInstrumentGroup(Mantid::Nexus::NXEntry &mtd_entry, API::MatrixWorkspace &local_workspace)
Read the spectra.
int confidence(Nexus::NexusDescriptorLazy &descriptor) const override
Returns a confidence value that this algorithm can load a file.
API::Workspace_sptr loadLeanElasticPeaksEntry(const Mantid::Nexus::NXEntry &entry)
Load LeanElasticPeakWorkspace.
void reinitSpecialWorkspace2D(std::shared_ptr< Mantid::DataObjects::SpecialWorkspace2D > specialLocalWorkspace)
int m_spec_max
The value of the spectrum_max property.
bool m_list
Flag set if list of spectra to save is specifed.
void getWordsInString(const std::string &words3, std::string &w1, std::string &w2, std::string &w3)
Splits a string of exactly three words into the separate words.
std::vector< int > m_filtered_spec_idxs
list of spectra filtered by min/max/list, currently used only when loading data into event_workspace
bool m_shared_bins
Does the current workspace have uniform binning.
std::string loadWorkspaceName(Mantid::Nexus::NXRoot &root, const std::string &entry_name)
Load the workspace name attribute if it exists.
std::vector< int > m_spec_list
The value of the spectrum_list property.
void loadNumericColumn(const Mantid::Nexus::NXData &tableData, const std::string &dataSetName, const API::ITableWorkspace_sptr &tableWs, const std::string &columnType)
Load a numeric column to the TableWorkspace.
API::MatrixWorkspace_sptr loadEventEntry(Mantid::Nexus::NXData &wksp_cls, Mantid::Nexus::NXDouble &xbins, const double &progressStart, const double &progressRange)
Load an event_workspace field.
std::map< std::string, std::string > validateInputs() override
Validates the input Min < Max and Max < Maximum_Int.
std::string buildWorkspaceName(const std::string &name, const std::string &baseName, size_t wsIndex)
Create the workspace name if it's part of a group workspace.
void loadVectorColumn(const Mantid::Nexus::NXData &tableData, const std::string &dataSetName, const API::ITableWorkspace_sptr &tableWs, const std::string &columnType)
Loads a vector column to the TableWorkspace.
void init() override
Overwrites Algorithm method.
MantidVec m_axis1vals
Numeric values for the second axis, if applicable.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
int version() const override
Algorithm's version for identification overriding a virtual method.
void loadNonSpectraAxis(const API::MatrixWorkspace_sptr &local_workspace, const Mantid::Nexus::NXData &data)
Load the data from a non-spectra axis (Numeric/Text) into the workspace.
std::size_t calculateWorkspaceSize(const std::size_t numberofspectra, bool gen_filtered_list=false)
calculates the workspace size
virtual void readSpectraToDetectorMapping(Mantid::Nexus::NXEntry &mtd_entry, Mantid::API::MatrixWorkspace &ws)
LoadNexusProcessed()
Default constructor.
std::unique_ptr< Nexus::File > m_nexusFile
API::MatrixWorkspace_sptr loadNonEventEntry(Mantid::Nexus::NXData &wksp_cls, Mantid::Nexus::NXDouble &xbins, const double &progressStart, const double &progressRange, const Mantid::Nexus::NXEntry &mtd_entry, const int64_t xlength, std::string &workspaceType)
Load a Workspace2D.
void readBinMasking(const Mantid::Nexus::NXData &wksp_cls, const API::MatrixWorkspace_sptr &local_workspace)
Read the bin masking information.
void applyLogFiltering(const Mantid::API::Workspace_sptr &local_workspace)
applies log filtering of the loaded logs if required
std::vector< std::string > extractWorkspaceNames(Mantid::Nexus::NXRoot &root, size_t nWorkspaceEntries)
Extract the workspace name.
void setRunNumber(int m_runNumber) override
Set the run number that measured this peak.
void setGoniometerMatrix(const Mantid::Kernel::Matrix< double > &goniometerMatrix) override
Set the goniometer rotation matrix at which this peak was measured.
void reserve(size_t num) override
Reserve a certain number of entries in event list of the specified eventType.
void switchTo(Mantid::API::EventType newType) override
Switch the EventList to use the given EventType (TOF, WEIGHTED, or WEIGHTED_NOTIME)
void addEventQuickly(const Types::Event::TofEvent &event)
Append an event to the histogram, without clearing the cache, to make it faster.
Structure describing a single-crystal peak.
Structure describing a single-crystal peak.
void setInstrument(const Geometry::Instrument_const_sptr &inst)
Set the instrument (and save the source/sample pos).
Info about a single neutron detection event, including a weight and error value, but excluding the pu...
Info about a single neutron detection event, including a weight and error value:
PeakShape : Abstract type to describes the shape of a peak.
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
static const std::string statusLogName()
Returns the name of the log created that defines the status during a run.
static const std::string periodsLogName()
Returns the name of the log that contains all of the periods.
The Logger class is in charge of the publishing messages from the framework through various channels.
void debug(const std::string &msg)
Logs at debug level.
void notice(const std::string &msg)
Logs at notice 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.
The concrete, templated class for properties.
Base class for properties.
virtual bool isDefault() const =0
Overriden function that returns if property has the same value that it was initialised with,...
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
@ TOK_IGNORE_EMPTY
ignore empty tokens
@ TOK_TRIM
remove leading and trailing whitespace from tokens
std::size_t count() const
Get the total number of tokens.
constexpr double norm2() const noexcept
Vector length squared.
Class that provides for a standard Nexus exception.
std::string getString(const std::string &name) const
Returns a string.
bool containsGroup(const std::string &query) const
Returns whether an individual group (or group) is present.
bool openLocal(const std::string &nxclass="")
Opens this NXClass using File::openGroup().
NXFloat openNXFloat(const std::string &name) const
Creates and opens a float dataset.
std::vector< NXClassInfo > & groups() const
Returns a list of all classes (or groups) in this NXClass.
NXClass openNXGroup(const std::string &name) const
Creates and opens an arbitrary (non-standard) class (group).
void close()
Close this class.
NXChar openNXChar(const std::string &name) const
Creates and opens a char dataset.
NXInt openNXInt(const std::string &name) const
Creates and opens an integer dataset.
NXUInt64 openNXSize(const std::string &name) const
Creates and opens a size_t dataset.
NXDouble openNXDouble(const std::string &name) const
Creates and opens a double dataset.
NXInfo getDataSetInfo(const std::string &name) const
Returns NXInfo for a dataset.
NXDataSetTyped< T > openNXDataSet(const std::string &name) const
Templated method for creating datasets.
bool isValid(const std::string &address) const
Check if a address exists relative to the current class address.
Templated class implementation of NXDataSet.
void load()
Read all of the datablock in.
container_T< T > & vecBuffer()
Returns a the internal buffer.
std::size_t size() const
Returns the size of the data buffer.
dimsize_t dim0() const
Returns the number of elements along the first dimension.
void openLocal()
Opens datasets faster but the parent group must be already open.
NXAttributes attributes
Attributes.
std::size_t rank() const
Returns the rank (number of dimensions) of the data. The maximum is 4.
dimsize_t dim1() const
Returns the number of elements along the second dimension.
Implements NXdata Nexus class.
NXDouble openDoubleData()
Opens data of double type.
Implements NXdetector Nexus class.
Implements NXentry Nexus class.
NXData openNXData(const std::string &name) const
Opens a NXData.
NXInstrument openNXInstrument(const std::string &name) const
Opens a NXInstrument.
Implements NXinstrument Nexus class.
NXDetector openNXDetector(const std::string &name)
Opens a NXDetector.
NexusAddress const & address() const
Returns the absolute address to the object.
std::shared_ptr< File > m_fileID
Nexus file id.
Implements NXroot Nexus class.
NXEntry openEntry(const std::string &name)
Opens an entry – a topmost Nexus class.
bool isEntry(std::string const &entryName, std::string const &groupClass) const
Checks if a full-address entry exists for a particular groupClass in a Nexus dataset.
static unsigned short constexpr UINT64
static unsigned short constexpr INT64
static unsigned short constexpr UINT32
static unsigned short constexpr CHAR
static unsigned short constexpr UINT8
static unsigned short constexpr INT32
static unsigned short constexpr FLOAT32
static unsigned short constexpr FLOAT64
std::shared_ptr< IPeaksWorkspace > IPeaksWorkspace_sptr
shared pointer to Mantid::API::IPeaksWorkspace
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< ExperimentInfo > ExperimentInfo_sptr
Shared pointer to ExperimentInfo.
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
Mantid::Kernel::StringTokenizer tokenizer
EventType
What kind of event list is being stored.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
bool UDlesserExecCount(const Mantid::Nexus::NXClassInfo &elem1, const Mantid::Nexus::NXClassInfo &elem2)
to sort the algorithmhistory vector
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
std::shared_ptr< RebinnedOutput > RebinnedOutput_sptr
shared pointer to the RebinnedOutput class
std::shared_ptr< PeakShapeFactory > PeakShapeFactory_sptr
Helper typedef.
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
SpecialCoordinateSystem
Special coordinate systems for Q3D.
Header for a base Nexus::Exception.
NXDataSetTyped< int64_t > NXInt64
The integer dataset type.
NXDataSetTyped< char > NXChar
The char dataset type.
NXDataSetTyped< uint64_t > NXUInt64
The integer dataset type.
Helper class which provides the Collimation Length for SANS instruments.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
int32_t specnum_t
Typedef for a spectrum Number.
Eigen::Array< IntT, static_cast< int >(ND), 1 > IntArray
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.
@ Output
An output workspace.
Information about a Nexus class.
std::string nxname
name of the object
Structure for keeping information about a Nexus data set, such as the dimensions and the type.
bool allGood
return status
std::size_t rank
number of dimensions of the data
NXDimArray dims
sizes along each dimension
NXnumtype type
type of the data, e.g. NX_CHAR, FLOAT32; see NexusFile_fwd.h