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);
1242 for (
size_t r = 0; r < numberPeaks; r++) {
1243 V3D intHKL = peakWS->getPeak(r).getIntHKL();
1244 if (intHKL.
norm2() == 0) {
1245 intHKL =
V3D(peakWS->getPeak(r).getH(), peakWS->getPeak(r).getK(), peakWS->getPeak(r).getL());
1246 peakWS->getPeak(r).setIntHKL(intHKL);
1251 return std::static_pointer_cast<API::Workspace>(peakWS);
1268 size_t columnNumber = 1;
1269 size_t numberPeaks = 0;
1270 std::vector<std::string> columnNames;
1281 columnNames.emplace_back(str);
1288 std::string columnTitle = nxDouble.
attributes(
"name");
1289 if (!columnTitle.empty() && numberPeaks == 0) {
1290 numberPeaks = nxDouble.
dim0();
1301 }
catch (std::runtime_error &re) {
1302 throw std::runtime_error(
1303 "Error while opening a address in a Peaks entry in a Nexus processed file. This address is wrong: " +
1304 std::string(entry.
address()) +
". Lower level error description: " + re.what());
1308 std::string parameterStr;
1312 peakWS->readParameterMap(parameterStr);
1313 }
catch (std::exception &e) {
1320 const std::string peaksWSName =
"peaks_workspace";
1323 }
catch (std::runtime_error &re) {
1324 throw std::runtime_error(
"Error while opening a peaks workspace in a Nexus processed file. Cannot open group " +
1325 peaksWSName +
". Lower level error description: " + re.what());
1328 uint32_t loadCoord(0);
1329 m_nexusFile->readData(
"coordinate_system", loadCoord);
1333 auto logs = peakWS->logs();
1334 if (logs->hasProperty(
"CoordinateSystem")) {
1337 int value((*prop)());
1343 std::string m_QConvention =
"Inelastic";
1345 m_nexusFile->getAttr(
"QConvention", m_QConvention);
1346 }
catch (std::exception &) {
1354 std::string convention = ConfigService::Instance().getString(
"Q.convention");
1355 if (convention != m_QConvention)
1358 for (
size_t r = 0; r < numberPeaks; r++) {
1364 const auto &goniometer = peakWS->run().getGoniometer();
1369 peakWS->addPeak(std::move(peak));
1372 for (
const auto &str : columnNames) {
1373 if (str ==
"column_1") {
1377 for (
size_t r = 0; r < numberPeaks; r++) {
1378 int ival = nxInt[r];
1380 peakWS->getPeak(r).setDetectorID(ival);
1382 }
else if (str ==
"column_2") {
1386 for (
size_t r = 0; r < numberPeaks; r++) {
1387 double val = qSign * nxDouble[r];
1388 peakWS->getPeak(r).setH(val);
1390 }
else if (str ==
"column_3") {
1394 for (
size_t r = 0; r < numberPeaks; r++) {
1395 double val = qSign * nxDouble[r];
1396 peakWS->getPeak(r).setK(val);
1398 }
else if (str ==
"column_4") {
1402 for (
size_t r = 0; r < numberPeaks; r++) {
1403 double val = qSign * nxDouble[r];
1404 peakWS->getPeak(r).setL(val);
1406 }
else if (str ==
"column_5") {
1410 for (
size_t r = 0; r < numberPeaks; r++) {
1411 double val = nxDouble[r];
1412 peakWS->getPeak(r).setIntensity(val);
1414 }
else if (str ==
"column_6") {
1418 for (
size_t r = 0; r < numberPeaks; r++) {
1419 double val = nxDouble[r];
1420 peakWS->getPeak(r).setSigmaIntensity(val);
1422 }
else if (str ==
"column_7") {
1426 for (
size_t r = 0; r < numberPeaks; r++) {
1427 double val = nxDouble[r];
1428 peakWS->getPeak(r).setBinCount(val);
1430 }
else if (str ==
"column_10") {
1434 for (
size_t r = 0; r < numberPeaks; r++) {
1435 double val = nxDouble[r];
1436 peakWS->getPeak(r).setWavelength(val);
1438 }
else if (str ==
"column_14") {
1442 for (
size_t r = 0; r < numberPeaks; r++) {
1443 int ival = nxInt[r];
1445 peakWS->getPeak(r).setRunNumber(ival);
1447 }
else if (str ==
"column_17") {
1451 for (
size_t r = 0; r < numberPeaks; r++) {
1452 int ival = nxInt[r];
1453 peakWS->getPeak(r).setPeakNumber(ival);
1455 }
else if (str ==
"column_18") {
1459 for (
size_t r = 0; r < numberPeaks; r++) {
1460 double val = nxDouble[r];
1461 peakWS->getPeak(r).setAbsorptionWeightedPathLength(val);
1463 }
else if (str ==
"column_15") {
1468 for (
size_t r = 0; r < numberPeaks; r++) {
1469 for (
size_t j = 0; j < 9; j++) {
1470 double val = nxDouble[k];
1472 gm[j % 3][j / 3] = val;
1474 peakWS->getPeak(r).setGoniometerMatrix(gm);
1476 }
else if (str ==
"column_16") {
1485 peakFactoryEllipsoid->setSuccessor(peakFactorySphere);
1486 peakFactorySphere->setSuccessor(peakFactoryDetectorBin);
1487 peakFactoryDetectorBin->setSuccessor(peakFactoryNone);
1494 for (
size_t i = 0; i < numberPeaks; ++i) {
1497 auto startPoint = data() + (maxShapeJSONLength * i);
1498 std::string shapeJSON(startPoint, startPoint + maxShapeJSONLength);
1499 boost::trim_right(shapeJSON);
1505 peakWS->getPeak(i).setPeakShape(peakShape);
1507 }
else if (str ==
"column_19") {
1511 for (
size_t r = 0; r < numberPeaks; ++r) {
1512 hkl =
V3D(nxDouble[r * 3], nxDouble[r * 3 + 1], nxDouble[r * 3 + 2]);
1513 peakWS->getPeak(r).setIntHKL(hkl);
1515 }
else if (str ==
"column_20") {
1519 for (
size_t r = 0; r < numberPeaks; ++r) {
1520 mnp =
V3D(nxDouble[r * 3], nxDouble[r * 3 + 1], nxDouble[r * 3 + 2]);
1521 peakWS->getPeak(r).setIntMNP(mnp);
1526 for (
size_t r = 0; r < numberPeaks; r++) {
1527 V3D intHKL = peakWS->getPeak(r).getIntHKL();
1528 if (intHKL.
norm2() == 0) {
1529 intHKL =
V3D(peakWS->getPeak(r).getH(), peakWS->getPeak(r).getK(), peakWS->getPeak(r).getL());
1530 peakWS->getPeak(r).setIntHKL(intHKL);
1534 return std::static_pointer_cast<API::Workspace>(peakWS);
1553 const double &progressStart,
1554 const double &progressRange,
const NXEntry &mtd_entry,
1555 const int64_t xlength, std::string &workspaceType) {
1559 size_t nspectra = data.
dim0();
1565 if (nchannels == 1 && nspectra == 1) {
1569 if (hasInstrument) {
1570 std::string inst_name = mtd_entry.
getString(
"instrument/name");
1571 boost::algorithm::trim(inst_name);
1572 if (inst_name ==
"")
1573 hasInstrument =
false;
1578 hasInstrument =
true;
1581 for (
auto facility : ConfigService::Instance().getFacilities()) {
1582 for (
auto instrumentName : facility->instruments()) {
1583 if (instrumentName.name() !=
"" && mtd_entry.
containsGroup(instrumentName.name())) {
1584 hasInstrument =
true;
1597 hasMetadata =
false;
1601 if (!hasInstrument && !hasMetadata)
1602 workspaceType =
"WorkspaceSingleValue";
1604 bool hasFracArea =
false;
1605 if (wksp_cls.
isValid(
"frac_area")) {
1608 workspaceType =
"RebinnedOutput";
1614 local_workspace->setTitle(mtd_entry.
getString(
"title"));
1615 }
catch (std::runtime_error &) {
1620 local_workspace->setYUnit(data.
attributes(
"units"));
1621 std::string unitLabel = data.
attributes(
"unit_label");
1622 if (unitLabel.empty())
1624 local_workspace->setYUnitLabel(unitLabel);
1634 auto rbWS = std::dynamic_pointer_cast<RebinnedOutput>(local_workspace);
1635 auto finalizedValue = fracarea.
attributes(
"finalized");
1636 auto finalized = (finalizedValue.empty() ? true : finalizedValue ==
"1");
1637 rbWS->setFinalized(finalized);
1638 auto sqrdErrsValue = fracarea.
attributes(
"sqrd_errors");
1639 auto sqrdErrs = (sqrdErrsValue.empty() ? false : sqrdErrsValue ==
"1");
1640 rbWS->setSqrdErrors(sqrdErrs);
1645 auto hasXErrors = wksp_cls.
isValid(
"xerrors");
1646 auto xErrors = hasXErrors ? wksp_cls.
openNXDouble(
"xerrors") : errors;
1648 if (xErrors.dim1() == nchannels + 1)
1649 g_log.
warning() <<
"Legacy X uncertainty found in input file, i.e., "
1650 "delta-Q for each BIN EDGE. Uncertainties will be "
1651 "re-interpreted as delta-Q of the BIN CENTRE and the "
1652 "last value will be dropped.\n";
1659 int fullblocks =
static_cast<int>(total_specs) / blocksize;
1660 int read_stop = (fullblocks * blocksize);
1661 const double progressBegin = progressStart + 0.25 * progressRange;
1662 const double progressScaler = 0.75 * progressRange;
1663 int64_t hist_index = 0;
1664 int64_t wsIndex = 0;
1674 fullblocks = (interval_specs) / blocksize;
1675 read_stop = (fullblocks * blocksize) +
m_spec_min - 1;
1677 if (interval_specs < blocksize) {
1678 blocksize =
static_cast<int>(total_specs);
1683 for (; hist_index < read_stop;) {
1684 progress(progressBegin + progressScaler *
static_cast<double>(hist_index) /
static_cast<double>(read_stop),
1685 "Reading workspace data...");
1686 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, blocksize, nchannels, hist_index, wsIndex,
1689 size_t finalblock =
m_spec_max - 1 - read_stop;
1690 if (finalblock > 0) {
1691 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, finalblock, nchannels, hist_index,
1692 wsIndex, local_workspace);
1699 int64_t specIndex = itr - 1;
1701 progressScaler *
static_cast<double>(specIndex) /
static_cast<double>(
m_spec_list.size()),
1702 "Reading workspace data...");
1703 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, 1, nchannels, specIndex, wsIndex,
1708 for (; hist_index < read_stop;) {
1709 progress(progressBegin + progressScaler *
static_cast<double>(hist_index) /
static_cast<double>(read_stop),
1710 "Reading workspace data...");
1711 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, blocksize, nchannels, hist_index, wsIndex,
1714 size_t finalblock = total_specs - read_stop;
1715 if (finalblock > 0) {
1716 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, finalblock, nchannels, hist_index, wsIndex,
1725 fullblocks = (interval_specs) / blocksize;
1726 read_stop = (fullblocks * blocksize) +
m_spec_min - 1;
1728 if (interval_specs < blocksize) {
1729 blocksize = interval_specs;
1734 for (; hist_index < read_stop;) {
1735 progress(progressBegin + progressScaler *
static_cast<double>(hist_index) /
static_cast<double>(read_stop),
1736 "Reading workspace data...");
1737 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, xbins, blocksize, nchannels, hist_index,
1738 wsIndex, local_workspace);
1740 size_t finalblock =
m_spec_max - 1 - read_stop;
1741 if (finalblock > 0) {
1742 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, xbins, finalblock, nchannels, hist_index,
1743 wsIndex, local_workspace);
1749 int64_t specIndex = itr - 1;
1750 progress(progressBegin + progressScaler *
static_cast<double>(specIndex) /
static_cast<double>(read_stop),
1751 "Reading workspace data...");
1752 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, xbins, 1, nchannels, specIndex, wsIndex,
1757 for (; hist_index < read_stop;) {
1758 progress(progressBegin + progressScaler *
static_cast<double>(hist_index) /
static_cast<double>(read_stop),
1759 "Reading workspace data...");
1760 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, xbins, blocksize, nchannels, hist_index,
1761 wsIndex, local_workspace);
1763 size_t finalblock = total_specs - read_stop;
1764 if (finalblock > 0) {
1765 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, xbins, finalblock, nchannels, hist_index,
1766 wsIndex, local_workspace);
1771 for (
size_t i = 0; i < local_workspace->getNumberHistograms(); i++) {
1772 const auto &
x = local_workspace->readX(i);
1774 std::distance(
x.rbegin(), std::find_if_not(
x.rbegin(),
x.rend(), [](
auto val) { return std::isnan(val); }));
1776 local_workspace->resizeHistogram(i, local_workspace->histogramSize(i) - idx);
1779 return local_workspace;
1796 const double &progressStart,
const double &progressRange) {
1797 progress(progressStart,
"Opening entry " + entry_name +
"...");
1809 }
catch (std::exception &) {
1816 bool isEvent =
false;
1817 std::string workspaceType =
"Workspace2D";
1818 std::string group_name =
"workspace";
1821 group_name =
"event_workspace";
1823 workspaceType =
"OffsetsWorkspace";
1824 group_name =
"offsets_workspace";
1826 workspaceType =
"MaskWorkspace";
1827 group_name =
"mask_workspace";
1829 workspaceType =
"GroupingWorkspace";
1830 group_name =
"grouping_workspace";
1841 std::string unit1 = xbins.
attributes(
"units");
1843 int64_t xlength(-1);
1844 if (xbins.
rank() == 2) {
1845 xlength = xbins.
dim1();
1847 }
else if (xbins.
rank() == 1) {
1848 xlength = xbins.
dim0();
1851 m_xbins = HistogramData::HistogramX(xbins(), xbins() + xlength);
1853 throw std::runtime_error(
"Unknown axis1 dimension encountered.");
1858 std::string unit2 = axis2.
attributes(
"units");
1863 local_workspace =
loadEventEntry(wksp_cls, xbins, progressStart, progressRange);
1866 loadNonEventEntry(wksp_cls, xbins, progressStart, progressRange, mtd_entry, xlength, workspaceType);
1868 size_t nspectra = local_workspace->getNumberHistograms();
1871 bool verticalHistogram(
false);
1873 local_workspace->getAxis(0)->unit() = UnitFactory::Instance().create(unit1);
1874 if (unit1 ==
"Label") {
1875 auto label = std::dynamic_pointer_cast<Mantid::Kernel::Units::Label>(local_workspace->getAxis(0)->unit());
1877 label->setLabel(ax.attributes(
"caption"), ax.attributes(
"label"));
1884 if (
static_cast<size_t>(axis2.
size()) == nspectra + 1)
1885 verticalHistogram =
true;
1887 }
catch (std::runtime_error &) {
1888 g_log.
information() <<
"Axis 0 set to unitless quantity \"" << unit1 <<
"\"\n";
1892 if (unit2 ==
"TextAxis") {
1893 auto newAxis = std::make_unique<Mantid::API::TextAxis>(nspectra);
1894 local_workspace->replaceAxis(1, std::move(newAxis));
1895 }
else if (unit2 !=
"spectraNumber") {
1897 auto newAxis = (verticalHistogram) ? std::make_unique<API::BinEdgeAxis>(nspectra + 1)
1898 : std::make_unique<API::NumericAxis>(nspectra);
1899 auto newAxisRaw = newAxis.get();
1900 local_workspace->replaceAxis(1, std::move(newAxis));
1901 newAxisRaw->unit() = UnitFactory::Instance().create(unit2);
1902 if (unit2 ==
"Label") {
1903 auto label = std::dynamic_pointer_cast<Mantid::Kernel::Units::Label>(newAxisRaw->unit());
1905 label->setLabel(ax.attributes(
"caption"), ax.attributes(
"label"));
1907 }
catch (std::runtime_error &) {
1908 g_log.
information() <<
"Axis 1 set to unitless quantity \"" << unit2 <<
"\"\n";
1913 std::string dist = xbins.
attributes(
"distribution");
1915 local_workspace->setDistribution(
true);
1917 local_workspace->setDistribution(
false);
1920 progress(progressStart + 0.05 * progressRange,
"Reading the sample details...");
1926 std::string parameterStr;
1933 progress(progressStart + 0.11 * progressRange,
"Reading the parameter maps...");
1934 local_workspace->readParameterMap(parameterStr);
1935 }
catch (std::exception &e) {
1940 g_log.
warning(
"Error loading Instrument section of nxs file");
1942 g_log.
warning(
"Try running LoadInstrument Algorithm on the Workspace to "
1943 "update the geometry");
1949 if (!local_workspace->getAxis(1)->isSpectra()) {
1954 progress(progressStart + 0.15 * progressRange,
"Reading the workspace history...");
1959 local_workspace->history().loadNexus(
m_nexusFile.get());
1960 }
catch (std::out_of_range &) {
1961 g_log.
warning() <<
"Error in the workspaces algorithm list, its processing "
1962 "history is incomplete\n";
1965 progress(progressStart + 0.2 * progressRange,
"Reading the workspace history...");
1968 if (local_workspace->getTitle().empty())
1969 local_workspace->setTitle(mtd_entry.
getString(
"title"));
1970 }
catch (std::runtime_error &) {
1974 return std::static_pointer_cast<API::Workspace>(local_workspace);
1986 SpectraInfo spectraInfo = extractMappingInfo(mtd_entry, this->
g_log);
1992 for (
int i = 1; i <= spectraInfo.nSpectra; ++i) {
2000 if (spectraInfo.hasSpectra) {
2001 spectrum = spectraInfo.spectraNumbers[i - 1];
2002 }
else if (haveSpectraAxis && !
m_axis1vals.empty()) {
2014 if (!spectraInfo.detectorIndex.empty()) {
2015 const int start = spectraInfo.detectorIndex[i - 1];
2016 const int end = start + spectraInfo.detectorCount[i - 1];
2017 spec.setDetectorIDs(
2018 std::set<detid_t>(spectraInfo.detectorList.data() + start, spectraInfo.detectorList.data() + end));
2029 using namespace std;
2030 map<string, string> errorList;
2036 if (specMax < specMin) {
2037 errorList[
"SpectrumMin"] =
"SpectrumMin must be smaller than SpectrumMax";
2038 errorList[
"SpectrumMax"] =
"SpectrumMax must be larger than SpectrumMin";
2055 Axis *axis = local_workspace->getAxis(1);
2060 for (
int i = 0; i < static_cast<int>(axis->
length()); i++) {
2063 }
else if (axis->
isText()) {
2065 std::string axisLabels;
2068 axisLabels = std::string(axisData(), axisData.dim0());
2069 }
catch (std::runtime_error &) {
2075 auto *textAxis =
static_cast<TextAxis *
>(axis);
2091 std::string::size_type index1, index2;
2092 std::string num1, num2;
2094 index1 = elem1.
nxname.find(
'_');
2095 if (index1 != std::string::npos) {
2096 num1 = elem1.
nxname.substr(index1 + 1, elem1.
nxname.length() - index1);
2098 index2 = elem2.
nxname.find(
'_');
2099 if (index2 != std::string::npos) {
2100 num2 = elem2.
nxname.substr(index2 + 1, elem2.
nxname.length() - index2);
2102 std::stringstream is1, is2;
2111 return execNum1 < execNum2;
2127 if (data.
count() != 3) {
2128 g_log.
warning() <<
"Algorithm list line " + words3 +
" is not of the correct format\n";
2129 throw std::out_of_range(words3);
2151 if (data.
count() != 4) {
2152 g_log.
warning() <<
"Algorithm list line " + words4 +
" is not of the correct format\n";
2153 throw std::out_of_range(words4);
2179 const int64_t
n = spec.
dim0();
2180 const int64_t n1 =
n - 1;
2181 for (
int i = 0; i <
n; ++i) {
2182 int64_t si = spec(i, 0);
2183 int64_t j0 = spec(i, 1);
2184 int64_t j1 = i < n1 ? spec(i + 1, 1) : bins.dim0();
2185 for (int64_t j = j0; j < j1; ++j) {
2186 local_workspace->flagMasked(si, bins[j], weights[j]);
2208 bool hasXErrors, int64_t blocksize, int64_t nchannels, int64_t &hist,
2210 data.
load(blocksize, hist);
2211 errors.
load(blocksize, hist);
2212 double *data_start = data();
2213 double *data_end = data_start + nchannels;
2214 double *err_start = errors();
2215 double *err_end = err_start + nchannels;
2216 double *farea_start =
nullptr;
2217 double *farea_end =
nullptr;
2218 double *xErrors_start =
nullptr;
2219 double *xErrors_end =
nullptr;
2220 size_t dx_increment = nchannels;
2225 size_t dx_input_increment = xErrors.
dim1();
2228 farea.
load(blocksize, hist);
2229 farea_start = farea();
2230 farea_end = farea_start + nchannels;
2231 rb_workspace = std::dynamic_pointer_cast<RebinnedOutput>(local_workspace);
2234 xErrors.
load(blocksize, hist);
2235 xErrors_start = xErrors();
2236 xErrors_end = xErrors_start + dx_increment;
2239 int64_t
final(hist + blocksize);
2240 while (hist <
final) {
2241 auto &
Y = local_workspace->mutableY(hist);
2242 Y.assign(data_start, data_end);
2243 data_start += nchannels;
2244 data_end += nchannels;
2245 auto &E = local_workspace->mutableE(hist);
2246 E.assign(err_start, err_end);
2247 err_start += nchannels;
2248 err_end += nchannels;
2250 MantidVec &F = rb_workspace->dataF(hist);
2251 F.assign(farea_start, farea_end);
2252 farea_start += nchannels;
2253 farea_end += nchannels;
2256 local_workspace->setSharedDx(hist, Kernel::make_cow<HistogramData::HistogramDx>(xErrors_start, xErrors_end));
2257 xErrors_start += dx_input_increment;
2258 xErrors_end += dx_input_increment;
2261 local_workspace->setSharedX(hist,
m_xbins.cowData());
2285 bool hasXErrors, int64_t blocksize, int64_t nchannels, int64_t &hist,
2287 data.
load(blocksize, hist);
2288 errors.
load(blocksize, hist);
2289 double *data_start = data();
2290 double *data_end = data_start + nchannels;
2291 double *err_start = errors();
2292 double *err_end = err_start + nchannels;
2293 double *farea_start =
nullptr;
2294 double *farea_end =
nullptr;
2295 double *xErrors_start =
nullptr;
2296 double *xErrors_end =
nullptr;
2297 size_t dx_increment = nchannels;
2302 size_t dx_input_increment = xErrors.
dim1();
2305 farea.
load(blocksize, hist);
2306 farea_start = farea();
2307 farea_end = farea_start + nchannels;
2308 rb_workspace = std::dynamic_pointer_cast<RebinnedOutput>(local_workspace);
2311 xErrors.
load(blocksize, hist);
2312 xErrors_start = xErrors();
2313 xErrors_end = xErrors_start + dx_increment;
2316 int64_t
final(hist + blocksize);
2317 while (hist <
final) {
2318 auto &
Y = local_workspace->mutableY(wsIndex);
2319 Y.assign(data_start, data_end);
2320 data_start += nchannels;
2321 data_end += nchannels;
2322 auto &E = local_workspace->mutableE(wsIndex);
2323 E.assign(err_start, err_end);
2324 err_start += nchannels;
2325 err_end += nchannels;
2327 MantidVec &F = rb_workspace->dataF(wsIndex);
2328 F.assign(farea_start, farea_end);
2329 farea_start += nchannels;
2330 farea_end += nchannels;
2333 local_workspace->setSharedDx(wsIndex, Kernel::make_cow<HistogramData::HistogramDx>(xErrors_start, xErrors_end));
2334 xErrors_start += dx_input_increment;
2335 xErrors_end += dx_input_increment;
2337 local_workspace->setSharedX(wsIndex,
m_xbins.cowData());
2362 bool hasXErrors,
NXDouble &xbins, int64_t blocksize, int64_t nchannels,
2364 data.
load(blocksize, hist);
2365 double *data_start = data();
2366 double *data_end = data_start + nchannels;
2367 errors.
load(blocksize, hist);
2368 double *err_start = errors();
2369 double *err_end = err_start + nchannels;
2370 double *farea_start =
nullptr;
2371 double *farea_end =
nullptr;
2372 double *xErrors_start =
nullptr;
2373 double *xErrors_end =
nullptr;
2374 size_t dx_increment = nchannels;
2379 size_t dx_input_increment = xErrors.
dim1();
2382 farea.
load(blocksize, hist);
2383 farea_start = farea();
2384 farea_end = farea_start + nchannels;
2385 rb_workspace = std::dynamic_pointer_cast<RebinnedOutput>(local_workspace);
2387 xbins.
load(blocksize, hist);
2388 const int64_t nxbins(xbins.
dim1());
2389 double *xbin_start = xbins();
2390 double *xbin_end = xbin_start + nxbins;
2391 int64_t
final(hist + blocksize);
2394 xErrors.
load(blocksize, hist);
2395 xErrors_start = xErrors();
2396 xErrors_end = xErrors_start + dx_increment;
2399 while (hist <
final) {
2400 auto &
Y = local_workspace->mutableY(wsIndex);
2401 Y.assign(data_start, data_end);
2402 data_start += nchannels;
2403 data_end += nchannels;
2404 auto &E = local_workspace->mutableE(wsIndex);
2405 E.assign(err_start, err_end);
2406 err_start += nchannels;
2407 err_end += nchannels;
2409 MantidVec &F = rb_workspace->dataF(wsIndex);
2410 F.assign(farea_start, farea_end);
2411 farea_start += nchannels;
2412 farea_end += nchannels;
2415 local_workspace->setSharedDx(wsIndex, Kernel::make_cow<HistogramData::HistogramDx>(xErrors_start, xErrors_end));
2416 xErrors_start += dx_input_increment;
2417 xErrors_end += dx_input_increment;
2419 auto &
X = local_workspace->mutableX(wsIndex);
2420 X.assign(xbin_start, xbin_end);
2421 xbin_start += nxbins;
2450 throw std::invalid_argument(
"Spectra max is less than 0");
2453 if (maxlist >
static_cast<int>(numberofspectra) || minlist == 0) {
2455 throw std::invalid_argument(
"Inconsistent properties defined");
2464 m_spec_max =
static_cast<int>(numberofspectra);
2466 if (m_spec_max < m_spec_min || m_spec_max >
static_cast<int>(numberofspectra)) {
2467 g_log.
error(
"Invalid Spectrum min/max properties");
2468 throw std::invalid_argument(
"Inconsistent properties defined");
2492 m_spec_max =
static_cast<int>(numberofspectra);
2497 if (gen_filtered_list) {
2519 if (gen_filtered_list) {
2527 total_specs = numberofspectra;
2529 m_spec_max =
static_cast<int>(numberofspectra) + 1;
2531 if (gen_filtered_list) {
2533 for (
int j = 0; j < static_cast<int>(total_specs); j++)
2546 auto mWorkspace = std::dynamic_pointer_cast<MatrixWorkspace>(local_workspace);
2548 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_LAZY_FILELOADER_ALGORITHM(classname)
DECLARE_NEXUS_LAZY_FILELOADER_ALGORITHM should be used in place of the standard DECLARE_ALGORITHM mac...
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< RebinnedOutput > RebinnedOutput_sptr
shared pointer to the RebinnedOutput class
std::shared_ptr< PeakShapeFactory > PeakShapeFactory_sptr
Helper typedef.
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
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