41#include <boost/algorithm/string/trim.hpp>
42#include <boost/regex.hpp>
56using namespace DataObjects;
57using namespace Kernel;
60using Mantid::Types::Event::TofEvent;
61using Types::Core::DateAndTime;
85using SpectraInfo_optional = std::optional<SpectraInfo>;
94SpectraInfo extractMappingInfo(
const NXEntry &mtd_entry,
Logger &logger) {
95 SpectraInfo spectraInfo;
99 logger.
information() <<
"No NXinstrument group called `instrument` under "
100 "NXEntry. The workspace will not "
101 "contain any detector information.\n";
106 logger.
information() <<
"Detector block not found. The workspace will not "
107 "contain any detector information.\n";
119 spectra_block.
load();
120 spectraInfo.spectraNumbers = spectra_block.
vecBuffer();
121 spectraInfo.nSpectra =
static_cast<int>(spectra_block.
dim0());
122 spectraInfo.hasSpectra =
true;
123 }
catch (std::runtime_error &) {
124 spectraInfo.hasSpectra =
false;
133 detlist_group.
load();
134 spectraInfo.detectorList = detlist_group.
vecBuffer();
135 }
catch (std::runtime_error &) {
136 logger.
information() <<
"detector_list block not found. The workspace will "
137 "not contain any detector information.\n";
145 spectraInfo.detectorCount = det_count.
vecBuffer();
149 spectraInfo.nSpectra =
static_cast<int>(det_index.
dim0());
150 spectraInfo.detectorIndex = det_index.
vecBuffer();
163 bool isMultiPeriod =
false;
165 const std::string nPeriodsLogEntryName =
"nperiods";
166 const Run &run = expInfo->run();
169 if (nPeriods == nWorkspaceEntries) {
170 isMultiPeriod =
true;
171 log.
information(
"Loading as MultiPeriod group workspace.");
175 return isMultiPeriod;
182 : m_shared_bins(false), m_xbins(0), m_axis1vals(), m_list(false), m_interval(false), m_spec_min(0),
183 m_spec_max(
Mantid::
EMPTY_INT()), m_spec_list(), m_filtered_spec_idxs(), m_nexusFile() {}
196 if (descriptor.
isEntry(
"/mantid_workspace_1"))
211 const std::vector<std::string> exts{
".nxs",
".nx5",
".xml"};
213 "The name of the Nexus file to read, as a full or relative path.");
215 "The name of the workspace to be created as the output of "
216 "the algorithm. A workspace of this name will be created "
217 "and stored in the Analysis Data Service. For multiperiod "
218 "files, one workspace may be generated for each period. "
219 "Currently only one workspace can be saved at a time so "
220 "multiperiod Mantid files are not generated.");
223 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
224 mustBePositive->setLower(0);
227 declareProperty(
"SpectrumMin",
static_cast<int>(1), mustBePositive,
"Number of first spectrum to read.");
229 "Number of last spectrum to read.");
232 "0 indicates that every entry is loaded, into a separate "
233 "workspace within a group. "
234 "A positive number identifies one entry to be loaded, into "
236 declareProperty(
"LoadHistory",
true,
"If true, the workspace history will be loaded");
238 "For multiperiod workspaces. Copy instrument, parameter and x-data "
239 "rather than loading it directly for each workspace. Y, E and log "
240 "information is always loaded.");
255 const size_t nWorkspaceEntries,
const size_t p) {
259 const size_t nHistograms = periodWorkspace->getNumberHistograms();
260 for (
size_t i = 0; i < nHistograms; ++i) {
261 periodWorkspace->setSharedX(i, tempMatrixWorkspace->sharedX(i));
273 NXEntry mtdEntry(root, entryName);
276 NXData wsEntry(mtdEntry,
"workspace");
278 std::stringstream buffer;
279 buffer <<
"Group entry " << p - 1
280 <<
" is not a workspace 2D. Retry with "
281 "FastMultiPeriod option set off.\n";
282 throw std::runtime_error(buffer.str());
285 if (wsEntry.
isValid(
"frac_area")) {
286 std::stringstream buffer;
287 buffer <<
"Group entry " << p - 1
288 <<
" has fractional area present. Try "
289 "reloading with FastMultiPeriod set "
291 throw std::runtime_error(buffer.str());
299 const int64_t nChannels = data.
dim1();
304 static_cast<int>(nHistograms) / blockSize;
305 const int readOptimumStop = (nFullBlocks * blockSize);
307 const int finalBlockSize = readStop - readOptimumStop;
312 for (; histIndex < readStop;) {
313 if (histIndex >= readOptimumStop) {
314 blockSize = finalBlockSize;
317 data.
load(blockSize, histIndex);
318 errors.
load(blockSize, histIndex);
320 double *dataStart = data();
321 double *dataEnd = dataStart + nChannels;
323 double *errorStart = errors();
324 double *errorEnd = errorStart + nChannels;
326 int64_t
final(histIndex + blockSize);
327 while (histIndex <
final) {
328 auto &
Y = periodWorkspace->mutableY(wsIndex);
329 Y.assign(dataStart, dataEnd);
330 dataStart += nChannels;
331 dataEnd += nChannels;
332 auto &E = periodWorkspace->mutableE(wsIndex);
333 E.assign(errorStart, errorEnd);
334 errorStart += nChannels;
335 errorEnd += nChannels;
353 periodWorkspace->loadSampleAndLogInfoNexus(
m_nexusFile.get());
354 }
catch (std::exception &e) {
364 const double fractionComplete = double(p - 1) / double(nWorkspaceEntries);
365 progress(fractionComplete,
"Loading multiperiod entry");
366 return periodWorkspace;
378 size_t nWorkspaceEntries = 0;
383 bool bDefaultEntryNumber = entryNumberProperty->
isDefault();
397 nWorkspaceEntries = std::count_if(root.
groups().cbegin(), root.
groups().cend(),
398 [](
const auto &g) { return g.nxclass ==
"NXentry"; });
400 if (!bDefaultEntryNumber &&
static_cast<size_t>(entryNumber) > nWorkspaceEntries) {
401 g_log.
error() <<
"Invalid entry number: " << entryNumber
402 <<
" specified. File only contains: " << nWorkspaceEntries <<
" entries.\n";
403 throw std::invalid_argument(
"Invalid entry number specified.");
406 const std::string basename =
"mantid_workspace_";
408 std::ostringstream os;
409 if (bDefaultEntryNumber) {
413 os << basename << entryNumber;
414 const std::string targetEntryName = os.str();
418 tempWS =
loadEntry(root, targetEntryName, 0, 1);
420 if (nWorkspaceEntries == 1 || !bDefaultEntryNumber) {
427 const bool bFastMultiPeriod = this->
getProperty(
"FastMultiPeriod");
428 const bool bIsMultiPeriod = isMultiPeriodFile(
static_cast<int>(nWorkspaceEntries), tempWS,
g_log);
433 auto wksp_group = std::make_shared<WorkspaceGroup>();
443 bool wsExists = AnalysisDataService::Instance().doesExist(base_name);
445 Algorithm_sptr alg = AlgorithmManager::Instance().createUnmanaged(
"DeleteWorkspace");
448 alg->setProperty(
"Workspace", base_name);
453 const std::string prop_name =
"OutputWorkspace_";
456 bool bAccelleratedMultiPeriodLoading =
false;
457 if (tempMatrixWorkspace) {
460 bAccelleratedMultiPeriodLoading = bIsMultiPeriod && bFastMultiPeriod && !
m_list;
463 tempMatrixWorkspace->mutableRun().clearLogs();
466 if (bAccelleratedMultiPeriodLoading) {
472 for (
size_t p = 1; p <= nWorkspaceEntries; ++p) {
486 if (bAccelleratedMultiPeriodLoading) {
491 const auto nWorkspaceEntries_d =
static_cast<double>(nWorkspaceEntries);
492 local_workspace =
loadEntry(root, basename + indexStr,
static_cast<double>(p - 1) / nWorkspaceEntries_d,
493 1. / nWorkspaceEntries_d);
499 wksp_group->addWorkspace(local_workspace);
500 setProperty(prop_name + indexStr, local_workspace);
504 setProperty(
"OutputWorkspace", std::static_pointer_cast<Workspace>(wksp_group));
517 if (nWorkspaceEntries == 1 || !bDefaultEntryNumber)
518 loadNexusGeometry(*getValue<API::Workspace_sptr>(
"OutputWorkspace"),
static_cast<size_t>(entryNumber),
g_log,
521 for (
size_t nEntry = 1; nEntry <= static_cast<size_t>(nWorkspaceEntries); ++nEntry) {
522 std::ostringstream wsPropertyName;
523 wsPropertyName <<
"OutputWorkspace_" << nEntry;
554 boost::smatch results;
555 const boost::regex exp(
".*_(\\d+$)");
557 if (boost::regex_search(
name, results, exp)) {
558 wsName = baseName + std::string(results[1].first, results[1].second);
561 wsName = baseName +
index;
578 for (
int i = 0; !noClash; ++i) {
585 bool wsExists = AnalysisDataService::Instance().doesExist(wsName + wsIndex);
600 std::vector<std::string> names(nWorkspaceEntries + 1);
601 for (
size_t p = 1; p <= nWorkspaceEntries; ++p) {
608 auto it = std::unique(names.begin(), names.end());
609 if (it != names.end()) {
610 auto size = names.size();
626 std::string workspaceName = std::string();
628 workspaceName = mtd_entry.
getString(
"workspace_name");
629 }
catch (std::runtime_error &) {
632 return workspaceName;
647 const double &progressStart,
const double &progressRange) {
650 size_t numspec = indices_data.dim0() - 1;
658 auto num_xbins = xbins.
dim0();
659 if (xbins.
rank() == 2) {
660 num_xbins = xbins.
dim1();
668 ws->setYUnit(indices_data.attributes(
"units"));
669 std::string unitLabel = indices_data.attributes(
"unit_label");
670 if (unitLabel.empty())
671 unitLabel = indices_data.attributes(
"units");
672 ws->setYUnitLabel(unitLabel);
676 std::vector<int64_t> pulsetimes;
677 if (wksp_cls.
isValid(
"pulsetime")) {
680 pulsetimes = pulsetime.vecBuffer();
683 std::vector<double> tofs;
690 std::vector<float> error_squareds;
691 if (wksp_cls.
isValid(
"error_squared")) {
693 error_squared.
load();
694 error_squareds = error_squared.
vecBuffer();
697 std::vector<float> weights;
698 if (wksp_cls.
isValid(
"weight")) {
706 if (!tofs.empty() && !pulsetimes.empty() && !weights.empty() && !error_squareds.empty())
708 else if ((!tofs.empty() && !weights.empty() && !error_squareds.empty()))
710 else if (!pulsetimes.empty() && !tofs.empty())
713 throw std::runtime_error(
"Could not figure out the type of event list!");
716 std::vector<int64_t> indices = indices_data.vecBuffer();
721 for (int64_t j = 0; j < max; ++j) {
724 int64_t index_start = indices[wi];
725 int64_t index_end = indices[wi + 1];
726 if (index_end >= index_start) {
731 el.
reserve(index_end - index_start);
734 for (int64_t i = index_start; i < index_end; i++)
753 for (std::size_t i = 0; i < xbins.
dim1(); i++)
758 std::distance(
x.rbegin(), std::find_if_not(
x.rbegin(),
x.rend(), [](
auto val) { return std::isnan(val); }));
760 x.resize(
x.size() - idx);
782template <
typename ColumnType,
typename NexusType>
786 std::string columnTitle = data.
attributes(
"name");
787 if (!columnTitle.empty()) {
789 auto length =
static_cast<size_t>(data.
dim0());
790 auto rowCount = tableWs->rowCount();
793 tableWs->setRowCount(length);
794 }
else if (rowCount != length) {
795 throw std::runtime_error(
"Columns have different sizes.");
798 auto column = tableWs->addColumn(columnType, columnTitle);
799 for (
size_t i = 0; i < length; i++) {
800 column->cell<ColumnType>(i) =
static_cast<ColumnType
>(*(data() + i));
815 int columnNumber = 1;
817 std::string dataSetName =
"column_" +
std::to_string(columnNumber);
825 if (info.
rank == 1) {
827 loadNumericColumn<double, double>(nx_tw, dataSetName,
workspace,
"double");
829 loadNumericColumn<int, int32_t>(nx_tw, dataSetName,
workspace,
"int");
831 loadNumericColumn<uint32_t, uint32_t>(nx_tw, dataSetName,
workspace,
"uint");
833 loadNumericColumn<int64_t, int64_t>(nx_tw, dataSetName,
workspace,
"long64");
835 loadNumericColumn<size_t, uint64_t>(nx_tw, dataSetName,
workspace,
"size_t");
837 loadNumericColumn<float, float>(nx_tw, dataSetName,
workspace,
"float");
839 loadNumericColumn<bool, bool>(nx_tw, dataSetName,
workspace,
"bool");
841 throw std::logic_error(
"Column with Nexus data type " +
std::to_string(
static_cast<int>(info.
type)) +
842 " cannot be loaded.");
844 }
else if (info.
rank == 2) {
847 std::string columnTitle = data.attributes(
"name");
848 if (!columnTitle.empty()) {
849 workspace->addColumn(
"str", columnTitle);
855 for (
dimsize_t iR = 0; iR < nRows; ++iR) {
856 auto &cellContents =
workspace->cell<std::string>(iR, columnNumber - 1);
857 auto startPoint = data() + maxStr * iR;
858 cellContents.assign(startPoint, startPoint + maxStr);
859 boost::trim_right(cellContents);
863 loadVectorColumn<int32_t>(nx_tw, dataSetName,
workspace,
"vector_int");
866 if (data.attributes(
"interpret_as") ==
"V3D") {
869 loadVectorColumn<double>(nx_tw, dataSetName,
workspace,
"vector_double");
878 return std::static_pointer_cast<API::Workspace>(
workspace);
888template <
typename Type>
892 std::string columnTitle = data.
attributes(
"name");
893 if (!columnTitle.empty()) {
894 tableWs->addColumn(columnType, columnTitle);
897 const size_t rowCount = info.
dims[0];
898 const size_t blockSize = info.
dims[1];
901 tableWs->setRowCount(rowCount);
905 for (
size_t i = 0; i < rowCount; ++i) {
906 auto &cell = tableWs->cell<std::vector<Type>>(i, tableWs->columnCount() - 1);
908 Type *from = data() + blockSize * i;
910 cell.assign(from, from + blockSize);
912 std::ostringstream rowSizeAttrName;
913 rowSizeAttrName <<
"row_size_" << i;
916 std::istringstream rowSizeStr(data.
attributes(rowSizeAttrName.str()));
919 rowSizeStr >> rowSize;
921 cell.resize(rowSize);
932 std::string columnTitle = data.
attributes(
"name");
933 if (!columnTitle.empty()) {
936 const int64_t rowCount = data.
dim0();
939 tableWs->setRowCount(rowCount);
943 for (int64_t i = 0; i < rowCount; ++i) {
945 cell(data(i, 0), data(i, 1), data(i, 2));
968 size_t columnNumber = 1;
969 size_t numberPeaks = 0;
970 std::vector<std::string> columnNames;
981 columnNames.emplace_back(str);
988 std::string columnTitle = nxDouble.
attributes(
"name");
989 if (!columnTitle.empty() && numberPeaks == 0) {
990 numberPeaks = nxDouble.
dim0();
1001 }
catch (std::runtime_error &re) {
1002 throw std::runtime_error(
1003 "Error while opening a address in a Peaks entry in a Nexus processed file. This address is wrong: " +
1004 std::string(entry.
address()) +
". Lower level error description: " + re.what());
1008 std::string parameterStr;
1012 peakWS->readParameterMap(parameterStr);
1013 }
catch (std::exception &e) {
1020 const std::string peaksWSName =
"peaks_workspace";
1023 }
catch (std::runtime_error &re) {
1024 throw std::runtime_error(
"Error while opening a peaks workspace in a Nexus processed file. Cannot open group " +
1025 peaksWSName +
". Lower level error description: " + re.what());
1028 uint32_t loadCoord(0);
1029 m_nexusFile->readData(
"coordinate_system", loadCoord);
1033 auto logs = peakWS->logs();
1034 if (logs->hasProperty(
"CoordinateSystem")) {
1037 int value((*prop)());
1043 std::string m_QConvention =
"Inelastic";
1045 m_nexusFile->getAttr(
"QConvention", m_QConvention);
1046 }
catch (std::exception &) {
1054 std::string convention = ConfigService::Instance().getString(
"Q.convention");
1055 if (convention != m_QConvention)
1058 for (
size_t r = 0; r < numberPeaks; r++) {
1060 const auto &goniometer = peakWS->run().getGoniometer();
1064 peakWS->addPeak(peak);
1067 for (
const auto &str : columnNames) {
1068 if (str ==
"column_1") {
1072 for (
size_t r = 0; r < numberPeaks; r++) {
1073 double val = qSign * nxDouble[r];
1074 peakWS->getPeak(r).setH(val);
1076 }
else if (str ==
"column_2") {
1080 for (
size_t r = 0; r < numberPeaks; r++) {
1081 double val = qSign * nxDouble[r];
1082 peakWS->getPeak(r).setK(val);
1084 }
else if (str ==
"column_3") {
1088 for (
size_t r = 0; r < numberPeaks; r++) {
1089 double val = qSign * nxDouble[r];
1090 peakWS->getPeak(r).setL(val);
1092 }
else if (str ==
"column_4") {
1096 for (
size_t r = 0; r < numberPeaks; r++) {
1097 double val = nxDouble[r];
1098 peakWS->getPeak(r).setIntensity(val);
1100 }
else if (str ==
"column_5") {
1104 for (
size_t r = 0; r < numberPeaks; r++) {
1105 double val = nxDouble[r];
1106 peakWS->getPeak(r).setSigmaIntensity(val);
1108 }
else if (str ==
"column_6") {
1112 for (
size_t r = 0; r < numberPeaks; r++) {
1113 double val = nxDouble[r];
1114 peakWS->getPeak(r).setBinCount(val);
1116 }
else if (str ==
"column_7") {
1120 for (
size_t r = 0; r < numberPeaks; r++) {
1121 double val = nxDouble[r];
1122 peakWS->getPeak(r).setWavelength(val);
1124 }
else if (str ==
"column_10") {
1128 for (
size_t r = 0; r < numberPeaks; r++) {
1129 int ival = nxInt[r];
1131 peakWS->getPeak(r).setRunNumber(ival);
1133 }
else if (str ==
"column_11") {
1137 for (
size_t r = 0; r < numberPeaks; r++) {
1138 int ival = nxInt[r];
1139 peakWS->getPeak(r).setPeakNumber(ival);
1141 }
else if (str ==
"column_12") {
1145 for (
size_t r = 0; r < numberPeaks; r++) {
1146 double val = nxDouble[r];
1147 peakWS->getPeak(r).setAbsorptionWeightedPathLength(val);
1149 }
else if (str ==
"column_13") {
1154 for (
size_t r = 0; r < numberPeaks; r++) {
1155 for (
int j = 0; j < 9; j++) {
1156 double val = nxDouble[k];
1158 gm[j % 3][j / 3] = val;
1160 peakWS->getPeak(r).setGoniometerMatrix(gm);
1162 }
else if (str ==
"column_14") {
1171 peakFactoryEllipsoid->setSuccessor(peakFactorySphere);
1172 peakFactorySphere->setSuccessor(peakFactoryDetectorBin);
1173 peakFactoryDetectorBin->setSuccessor(peakFactoryNone);
1180 for (
size_t i = 0; i < numberPeaks; ++i) {
1183 auto startPoint = data() + (maxShapeJSONLength * i);
1184 std::string shapeJSON(startPoint, startPoint + maxShapeJSONLength);
1185 boost::trim_right(shapeJSON);
1191 peakWS->getPeak(i).setPeakShape(peakShape);
1193 }
else if (str ==
"column_15") {
1197 for (
size_t r = 0; r < numberPeaks; ++r) {
1198 qlab =
V3D(nxDouble[r * 3], nxDouble[r * 3 + 1], nxDouble[r * 3 + 2]);
1199 peakWS->getPeak(r).setQLabFrame(qlab, 0.0);
1201 }
else if (str ==
"column_16") {
1205 for (
size_t r = 0; r < numberPeaks; ++r) {
1206 hkl =
V3D(nxDouble[r * 3], nxDouble[r * 3 + 1], nxDouble[r * 3 + 2]);
1207 peakWS->getPeak(r).setIntHKL(hkl);
1209 }
else if (str ==
"column_17") {
1213 for (
size_t r = 0; r < numberPeaks; ++r) {
1214 mnp =
V3D(nxDouble[r * 3], nxDouble[r * 3 + 1], nxDouble[r * 3 + 2]);
1215 peakWS->getPeak(r).setIntMNP(mnp);
1220 for (
size_t r = 0; r < numberPeaks; r++) {
1221 V3D intHKL = peakWS->getPeak(r).getIntHKL();
1222 if (intHKL.
norm2() == 0) {
1223 intHKL =
V3D(peakWS->getPeak(r).getH(), peakWS->getPeak(r).getK(), peakWS->getPeak(r).getL());
1224 peakWS->getPeak(r).setIntHKL(intHKL);
1229 return std::static_pointer_cast<API::Workspace>(peakWS);
1246 size_t columnNumber = 1;
1247 size_t numberPeaks = 0;
1248 std::vector<std::string> columnNames;
1259 columnNames.emplace_back(str);
1266 std::string columnTitle = nxDouble.
attributes(
"name");
1267 if (!columnTitle.empty() && numberPeaks == 0) {
1268 numberPeaks = nxDouble.
dim0();
1279 }
catch (std::runtime_error &re) {
1280 throw std::runtime_error(
1281 "Error while opening a address in a Peaks entry in a Nexus processed file. This address is wrong: " +
1282 std::string(entry.
address()) +
". Lower level error description: " + re.what());
1286 std::string parameterStr;
1290 peakWS->readParameterMap(parameterStr);
1291 }
catch (std::exception &e) {
1298 const std::string peaksWSName =
"peaks_workspace";
1301 }
catch (std::runtime_error &re) {
1302 throw std::runtime_error(
"Error while opening a peaks workspace in a Nexus processed file. Cannot open group " +
1303 peaksWSName +
". Lower level error description: " + re.what());
1306 uint32_t loadCoord(0);
1307 m_nexusFile->readData(
"coordinate_system", loadCoord);
1311 auto logs = peakWS->logs();
1312 if (logs->hasProperty(
"CoordinateSystem")) {
1315 int value((*prop)());
1321 std::string m_QConvention =
"Inelastic";
1323 m_nexusFile->getAttr(
"QConvention", m_QConvention);
1324 }
catch (std::exception &) {
1332 std::string convention = ConfigService::Instance().getString(
"Q.convention");
1333 if (convention != m_QConvention)
1336 for (
size_t r = 0; r < numberPeaks; r++) {
1342 const auto &goniometer = peakWS->run().getGoniometer();
1347 peakWS->addPeak(std::move(peak));
1350 for (
const auto &str : columnNames) {
1351 if (str ==
"column_1") {
1355 for (
size_t r = 0; r < numberPeaks; r++) {
1356 int ival = nxInt[r];
1358 peakWS->getPeak(r).setDetectorID(ival);
1360 }
else if (str ==
"column_2") {
1364 for (
size_t r = 0; r < numberPeaks; r++) {
1365 double val = qSign * nxDouble[r];
1366 peakWS->getPeak(r).setH(val);
1368 }
else if (str ==
"column_3") {
1372 for (
size_t r = 0; r < numberPeaks; r++) {
1373 double val = qSign * nxDouble[r];
1374 peakWS->getPeak(r).setK(val);
1376 }
else if (str ==
"column_4") {
1380 for (
size_t r = 0; r < numberPeaks; r++) {
1381 double val = qSign * nxDouble[r];
1382 peakWS->getPeak(r).setL(val);
1384 }
else if (str ==
"column_5") {
1388 for (
size_t r = 0; r < numberPeaks; r++) {
1389 double val = nxDouble[r];
1390 peakWS->getPeak(r).setIntensity(val);
1392 }
else if (str ==
"column_6") {
1396 for (
size_t r = 0; r < numberPeaks; r++) {
1397 double val = nxDouble[r];
1398 peakWS->getPeak(r).setSigmaIntensity(val);
1400 }
else if (str ==
"column_7") {
1404 for (
size_t r = 0; r < numberPeaks; r++) {
1405 double val = nxDouble[r];
1406 peakWS->getPeak(r).setBinCount(val);
1408 }
else if (str ==
"column_10") {
1412 for (
size_t r = 0; r < numberPeaks; r++) {
1413 double val = nxDouble[r];
1414 peakWS->getPeak(r).setWavelength(val);
1416 }
else if (str ==
"column_14") {
1420 for (
size_t r = 0; r < numberPeaks; r++) {
1421 int ival = nxInt[r];
1423 peakWS->getPeak(r).setRunNumber(ival);
1425 }
else if (str ==
"column_17") {
1429 for (
size_t r = 0; r < numberPeaks; r++) {
1430 int ival = nxInt[r];
1431 peakWS->getPeak(r).setPeakNumber(ival);
1433 }
else if (str ==
"column_18") {
1437 for (
size_t r = 0; r < numberPeaks; r++) {
1438 double val = nxDouble[r];
1439 peakWS->getPeak(r).setAbsorptionWeightedPathLength(val);
1441 }
else if (str ==
"column_15") {
1446 for (
size_t r = 0; r < numberPeaks; r++) {
1447 for (
size_t j = 0; j < 9; j++) {
1448 double val = nxDouble[k];
1450 gm[j % 3][j / 3] = val;
1452 peakWS->getPeak(r).setGoniometerMatrix(gm);
1454 }
else if (str ==
"column_16") {
1463 peakFactoryEllipsoid->setSuccessor(peakFactorySphere);
1464 peakFactorySphere->setSuccessor(peakFactoryDetectorBin);
1465 peakFactoryDetectorBin->setSuccessor(peakFactoryNone);
1472 for (
size_t i = 0; i < numberPeaks; ++i) {
1475 auto startPoint = data() + (maxShapeJSONLength * i);
1476 std::string shapeJSON(startPoint, startPoint + maxShapeJSONLength);
1477 boost::trim_right(shapeJSON);
1483 peakWS->getPeak(i).setPeakShape(peakShape);
1485 }
else if (str ==
"column_19") {
1489 for (
size_t r = 0; r < numberPeaks; ++r) {
1490 hkl =
V3D(nxDouble[r * 3], nxDouble[r * 3 + 1], nxDouble[r * 3 + 2]);
1491 peakWS->getPeak(r).setIntHKL(hkl);
1493 }
else if (str ==
"column_20") {
1497 for (
size_t r = 0; r < numberPeaks; ++r) {
1498 mnp =
V3D(nxDouble[r * 3], nxDouble[r * 3 + 1], nxDouble[r * 3 + 2]);
1499 peakWS->getPeak(r).setIntMNP(mnp);
1504 for (
size_t r = 0; r < numberPeaks; r++) {
1505 V3D intHKL = peakWS->getPeak(r).getIntHKL();
1506 if (intHKL.
norm2() == 0) {
1507 intHKL =
V3D(peakWS->getPeak(r).getH(), peakWS->getPeak(r).getK(), peakWS->getPeak(r).getL());
1508 peakWS->getPeak(r).setIntHKL(intHKL);
1512 return std::static_pointer_cast<API::Workspace>(peakWS);
1531 const double &progressStart,
1532 const double &progressRange,
const NXEntry &mtd_entry,
1533 const int64_t xlength, std::string &workspaceType) {
1537 size_t nspectra = data.
dim0();
1543 if (nchannels == 1 && nspectra == 1) {
1547 if (hasInstrument) {
1548 std::string inst_name = mtd_entry.
getString(
"instrument/name");
1549 boost::algorithm::trim(inst_name);
1550 if (inst_name ==
"")
1551 hasInstrument =
false;
1556 hasInstrument =
true;
1559 for (
auto facility : ConfigService::Instance().getFacilities()) {
1560 for (
auto instrumentName : facility->instruments()) {
1561 if (instrumentName.name() !=
"" && mtd_entry.
containsGroup(instrumentName.name())) {
1562 hasInstrument =
true;
1575 hasMetadata =
false;
1579 if (!hasInstrument && !hasMetadata)
1580 workspaceType =
"WorkspaceSingleValue";
1582 bool hasFracArea =
false;
1583 if (wksp_cls.
isValid(
"frac_area")) {
1586 workspaceType =
"RebinnedOutput";
1592 local_workspace->setTitle(mtd_entry.
getString(
"title"));
1593 }
catch (std::runtime_error &) {
1598 local_workspace->setYUnit(data.
attributes(
"units"));
1599 std::string unitLabel = data.
attributes(
"unit_label");
1600 if (unitLabel.empty())
1602 local_workspace->setYUnitLabel(unitLabel);
1612 auto rbWS = std::dynamic_pointer_cast<RebinnedOutput>(local_workspace);
1613 auto finalizedValue = fracarea.
attributes(
"finalized");
1614 auto finalized = (finalizedValue.empty() ? true : finalizedValue ==
"1");
1615 rbWS->setFinalized(finalized);
1616 auto sqrdErrsValue = fracarea.
attributes(
"sqrd_errors");
1617 auto sqrdErrs = (sqrdErrsValue.empty() ? false : sqrdErrsValue ==
"1");
1618 rbWS->setSqrdErrors(sqrdErrs);
1623 auto hasXErrors = wksp_cls.
isValid(
"xerrors");
1624 auto xErrors = hasXErrors ? wksp_cls.
openNXDouble(
"xerrors") : errors;
1626 if (xErrors.dim1() == nchannels + 1)
1627 g_log.
warning() <<
"Legacy X uncertainty found in input file, i.e., "
1628 "delta-Q for each BIN EDGE. Uncertainties will be "
1629 "re-interpreted as delta-Q of the BIN CENTRE and the "
1630 "last value will be dropped.\n";
1637 int fullblocks =
static_cast<int>(total_specs) / blocksize;
1638 int read_stop = (fullblocks * blocksize);
1639 const double progressBegin = progressStart + 0.25 * progressRange;
1640 const double progressScaler = 0.75 * progressRange;
1641 int64_t hist_index = 0;
1642 int64_t wsIndex = 0;
1652 fullblocks = (interval_specs) / blocksize;
1653 read_stop = (fullblocks * blocksize) +
m_spec_min - 1;
1655 if (interval_specs < blocksize) {
1656 blocksize =
static_cast<int>(total_specs);
1661 for (; hist_index < read_stop;) {
1662 progress(progressBegin + progressScaler *
static_cast<double>(hist_index) /
static_cast<double>(read_stop),
1663 "Reading workspace data...");
1664 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, blocksize, nchannels, hist_index, wsIndex,
1667 size_t finalblock =
m_spec_max - 1 - read_stop;
1668 if (finalblock > 0) {
1669 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, finalblock, nchannels, hist_index,
1670 wsIndex, local_workspace);
1677 int64_t specIndex = itr - 1;
1679 progressScaler *
static_cast<double>(specIndex) /
static_cast<double>(
m_spec_list.size()),
1680 "Reading workspace data...");
1681 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, 1, nchannels, specIndex, wsIndex,
1686 for (; hist_index < read_stop;) {
1687 progress(progressBegin + progressScaler *
static_cast<double>(hist_index) /
static_cast<double>(read_stop),
1688 "Reading workspace data...");
1689 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, blocksize, nchannels, hist_index, wsIndex,
1692 size_t finalblock = total_specs - read_stop;
1693 if (finalblock > 0) {
1694 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, finalblock, nchannels, hist_index, wsIndex,
1703 fullblocks = (interval_specs) / blocksize;
1704 read_stop = (fullblocks * blocksize) +
m_spec_min - 1;
1706 if (interval_specs < blocksize) {
1707 blocksize = interval_specs;
1712 for (; hist_index < read_stop;) {
1713 progress(progressBegin + progressScaler *
static_cast<double>(hist_index) /
static_cast<double>(read_stop),
1714 "Reading workspace data...");
1715 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, xbins, blocksize, nchannels, hist_index,
1716 wsIndex, local_workspace);
1718 size_t finalblock =
m_spec_max - 1 - read_stop;
1719 if (finalblock > 0) {
1720 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, xbins, finalblock, nchannels, hist_index,
1721 wsIndex, local_workspace);
1727 int64_t specIndex = itr - 1;
1728 progress(progressBegin + progressScaler *
static_cast<double>(specIndex) /
static_cast<double>(read_stop),
1729 "Reading workspace data...");
1730 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, xbins, 1, nchannels, specIndex, wsIndex,
1735 for (; hist_index < read_stop;) {
1736 progress(progressBegin + progressScaler *
static_cast<double>(hist_index) /
static_cast<double>(read_stop),
1737 "Reading workspace data...");
1738 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, xbins, blocksize, nchannels, hist_index,
1739 wsIndex, local_workspace);
1741 size_t finalblock = total_specs - read_stop;
1742 if (finalblock > 0) {
1743 loadBlock(data, errors, fracarea, hasFracArea, xErrors, hasXErrors, xbins, finalblock, nchannels, hist_index,
1744 wsIndex, local_workspace);
1749 for (
size_t i = 0; i < local_workspace->getNumberHistograms(); i++) {
1750 const auto &
x = local_workspace->readX(i);
1752 std::distance(
x.rbegin(), std::find_if_not(
x.rbegin(),
x.rend(), [](
auto val) { return std::isnan(val); }));
1754 local_workspace->resizeHistogram(i, local_workspace->histogramSize(i) - idx);
1757 return local_workspace;
1774 const double &progressStart,
const double &progressRange) {
1775 progress(progressStart,
"Opening entry " + entry_name +
"...");
1787 }
catch (std::exception &) {
1794 bool isEvent =
false;
1795 std::string workspaceType =
"Workspace2D";
1796 std::string group_name =
"workspace";
1799 group_name =
"event_workspace";
1801 workspaceType =
"OffsetsWorkspace";
1802 group_name =
"offsets_workspace";
1804 workspaceType =
"MaskWorkspace";
1805 group_name =
"mask_workspace";
1807 workspaceType =
"GroupingWorkspace";
1808 group_name =
"grouping_workspace";
1819 std::string unit1 = xbins.
attributes(
"units");
1821 int64_t xlength(-1);
1822 if (xbins.
rank() == 2) {
1823 xlength = xbins.
dim1();
1825 }
else if (xbins.
rank() == 1) {
1826 xlength = xbins.
dim0();
1829 m_xbins = HistogramData::HistogramX(xbins(), xbins() + xlength);
1831 throw std::runtime_error(
"Unknown axis1 dimension encountered.");
1836 std::string unit2 = axis2.
attributes(
"units");
1841 local_workspace =
loadEventEntry(wksp_cls, xbins, progressStart, progressRange);
1844 loadNonEventEntry(wksp_cls, xbins, progressStart, progressRange, mtd_entry, xlength, workspaceType);
1846 size_t nspectra = local_workspace->getNumberHistograms();
1849 bool verticalHistogram(
false);
1851 local_workspace->getAxis(0)->unit() = UnitFactory::Instance().create(unit1);
1852 if (unit1 ==
"Label") {
1853 auto label = std::dynamic_pointer_cast<Mantid::Kernel::Units::Label>(local_workspace->getAxis(0)->unit());
1855 label->setLabel(ax.attributes(
"caption"), ax.attributes(
"label"));
1862 if (
static_cast<size_t>(axis2.
size()) == nspectra + 1)
1863 verticalHistogram =
true;
1865 }
catch (std::runtime_error &) {
1866 g_log.
information() <<
"Axis 0 set to unitless quantity \"" << unit1 <<
"\"\n";
1870 if (unit2 ==
"TextAxis") {
1871 auto newAxis = std::make_unique<Mantid::API::TextAxis>(nspectra);
1872 local_workspace->replaceAxis(1, std::move(newAxis));
1873 }
else if (unit2 !=
"spectraNumber") {
1875 auto newAxis = (verticalHistogram) ? std::make_unique<API::BinEdgeAxis>(nspectra + 1)
1876 : std::make_unique<API::NumericAxis>(nspectra);
1877 auto newAxisRaw = newAxis.get();
1878 local_workspace->replaceAxis(1, std::move(newAxis));
1879 newAxisRaw->unit() = UnitFactory::Instance().create(unit2);
1880 if (unit2 ==
"Label") {
1881 auto label = std::dynamic_pointer_cast<Mantid::Kernel::Units::Label>(newAxisRaw->unit());
1883 label->setLabel(ax.attributes(
"caption"), ax.attributes(
"label"));
1885 }
catch (std::runtime_error &) {
1886 g_log.
information() <<
"Axis 1 set to unitless quantity \"" << unit2 <<
"\"\n";
1891 std::string dist = xbins.
attributes(
"distribution");
1893 local_workspace->setDistribution(
true);
1895 local_workspace->setDistribution(
false);
1898 progress(progressStart + 0.05 * progressRange,
"Reading the sample details...");
1904 std::string parameterStr;
1911 progress(progressStart + 0.11 * progressRange,
"Reading the parameter maps...");
1912 local_workspace->readParameterMap(parameterStr);
1913 }
catch (std::exception &e) {
1917 const auto &entries =
getFileInfo()->getAllEntries();
1918 if (
version() < 2 || entries.find(
"NXinstrument") == entries.end()) {
1919 g_log.
warning(
"Error loading Instrument section of nxs file");
1921 g_log.
warning(
"Try running LoadInstrument Algorithm on the Workspace to "
1922 "update the geometry");
1928 if (!local_workspace->getAxis(1)->isSpectra()) {
1933 progress(progressStart + 0.15 * progressRange,
"Reading the workspace history...");
1938 local_workspace->history().loadNexus(
m_nexusFile.get());
1939 }
catch (std::out_of_range &) {
1940 g_log.
warning() <<
"Error in the workspaces algorithm list, its processing "
1941 "history is incomplete\n";
1944 progress(progressStart + 0.2 * progressRange,
"Reading the workspace history...");
1947 if (local_workspace->getTitle().empty())
1948 local_workspace->setTitle(mtd_entry.
getString(
"title"));
1949 }
catch (std::runtime_error &) {
1953 return std::static_pointer_cast<API::Workspace>(local_workspace);
1965 SpectraInfo spectraInfo = extractMappingInfo(mtd_entry, this->
g_log);
1971 for (
int i = 1; i <= spectraInfo.nSpectra; ++i) {
1979 if (spectraInfo.hasSpectra) {
1980 spectrum = spectraInfo.spectraNumbers[i - 1];
1981 }
else if (haveSpectraAxis && !
m_axis1vals.empty()) {
1993 if (!spectraInfo.detectorIndex.empty()) {
1994 const int start = spectraInfo.detectorIndex[i - 1];
1995 const int end = start + spectraInfo.detectorCount[i - 1];
1996 spec.setDetectorIDs(
1997 std::set<detid_t>(spectraInfo.detectorList.data() + start, spectraInfo.detectorList.data() + end));
2008 using namespace std;
2009 map<string, string> errorList;
2015 if (specMax < specMin) {
2016 errorList[
"SpectrumMin"] =
"SpectrumMin must be smaller than SpectrumMax";
2017 errorList[
"SpectrumMax"] =
"SpectrumMax must be larger than SpectrumMin";
2034 Axis *axis = local_workspace->getAxis(1);
2039 for (
int i = 0; i < static_cast<int>(axis->
length()); i++) {
2042 }
else if (axis->
isText()) {
2044 std::string axisLabels;
2047 axisLabels = std::string(axisData(), axisData.dim0());
2048 }
catch (std::runtime_error &) {
2054 auto *textAxis =
static_cast<TextAxis *
>(axis);
2070 std::string::size_type index1, index2;
2071 std::string num1, num2;
2073 index1 = elem1.
nxname.find(
'_');
2074 if (index1 != std::string::npos) {
2075 num1 = elem1.
nxname.substr(index1 + 1, elem1.
nxname.length() - index1);
2077 index2 = elem2.
nxname.find(
'_');
2078 if (index2 != std::string::npos) {
2079 num2 = elem2.
nxname.substr(index2 + 1, elem2.
nxname.length() - index2);
2081 std::stringstream is1, is2;
2090 return execNum1 < execNum2;
2106 if (data.
count() != 3) {
2107 g_log.
warning() <<
"Algorithm list line " + words3 +
" is not of the correct format\n";
2108 throw std::out_of_range(words3);
2130 if (data.
count() != 4) {
2131 g_log.
warning() <<
"Algorithm list line " + words4 +
" is not of the correct format\n";
2132 throw std::out_of_range(words4);
2158 const int64_t
n = spec.
dim0();
2159 const int64_t n1 =
n - 1;
2160 for (
int i = 0; i <
n; ++i) {
2161 int64_t si = spec(i, 0);
2162 int64_t j0 = spec(i, 1);
2163 int64_t j1 = i < n1 ? spec(i + 1, 1) : bins.dim0();
2164 for (int64_t j = j0; j < j1; ++j) {
2165 local_workspace->flagMasked(si, bins[j], weights[j]);
2187 bool hasXErrors, int64_t blocksize, int64_t nchannels, int64_t &hist,
2189 data.
load(blocksize, hist);
2190 errors.
load(blocksize, hist);
2191 double *data_start = data();
2192 double *data_end = data_start + nchannels;
2193 double *err_start = errors();
2194 double *err_end = err_start + nchannels;
2195 double *farea_start =
nullptr;
2196 double *farea_end =
nullptr;
2197 double *xErrors_start =
nullptr;
2198 double *xErrors_end =
nullptr;
2199 size_t dx_increment = nchannels;
2204 size_t dx_input_increment = xErrors.
dim1();
2207 farea.
load(blocksize, hist);
2208 farea_start = farea();
2209 farea_end = farea_start + nchannels;
2210 rb_workspace = std::dynamic_pointer_cast<RebinnedOutput>(local_workspace);
2213 xErrors.
load(blocksize, hist);
2214 xErrors_start = xErrors();
2215 xErrors_end = xErrors_start + dx_increment;
2218 int64_t
final(hist + blocksize);
2219 while (hist <
final) {
2220 auto &
Y = local_workspace->mutableY(hist);
2221 Y.assign(data_start, data_end);
2222 data_start += nchannels;
2223 data_end += nchannels;
2224 auto &E = local_workspace->mutableE(hist);
2225 E.assign(err_start, err_end);
2226 err_start += nchannels;
2227 err_end += nchannels;
2229 MantidVec &F = rb_workspace->dataF(hist);
2230 F.assign(farea_start, farea_end);
2231 farea_start += nchannels;
2232 farea_end += nchannels;
2235 local_workspace->setSharedDx(hist, Kernel::make_cow<HistogramData::HistogramDx>(xErrors_start, xErrors_end));
2236 xErrors_start += dx_input_increment;
2237 xErrors_end += dx_input_increment;
2240 local_workspace->setSharedX(hist,
m_xbins.cowData());
2264 bool hasXErrors, int64_t blocksize, int64_t nchannels, int64_t &hist,
2266 data.
load(blocksize, hist);
2267 errors.
load(blocksize, hist);
2268 double *data_start = data();
2269 double *data_end = data_start + nchannels;
2270 double *err_start = errors();
2271 double *err_end = err_start + nchannels;
2272 double *farea_start =
nullptr;
2273 double *farea_end =
nullptr;
2274 double *xErrors_start =
nullptr;
2275 double *xErrors_end =
nullptr;
2276 size_t dx_increment = nchannels;
2281 size_t dx_input_increment = xErrors.
dim1();
2284 farea.
load(blocksize, hist);
2285 farea_start = farea();
2286 farea_end = farea_start + nchannels;
2287 rb_workspace = std::dynamic_pointer_cast<RebinnedOutput>(local_workspace);
2290 xErrors.
load(blocksize, hist);
2291 xErrors_start = xErrors();
2292 xErrors_end = xErrors_start + dx_increment;
2295 int64_t
final(hist + blocksize);
2296 while (hist <
final) {
2297 auto &
Y = local_workspace->mutableY(wsIndex);
2298 Y.assign(data_start, data_end);
2299 data_start += nchannels;
2300 data_end += nchannels;
2301 auto &E = local_workspace->mutableE(wsIndex);
2302 E.assign(err_start, err_end);
2303 err_start += nchannels;
2304 err_end += nchannels;
2306 MantidVec &F = rb_workspace->dataF(wsIndex);
2307 F.assign(farea_start, farea_end);
2308 farea_start += nchannels;
2309 farea_end += nchannels;
2312 local_workspace->setSharedDx(wsIndex, Kernel::make_cow<HistogramData::HistogramDx>(xErrors_start, xErrors_end));
2313 xErrors_start += dx_input_increment;
2314 xErrors_end += dx_input_increment;
2316 local_workspace->setSharedX(wsIndex,
m_xbins.cowData());
2341 bool hasXErrors,
NXDouble &xbins, int64_t blocksize, int64_t nchannels,
2343 data.
load(blocksize, hist);
2344 double *data_start = data();
2345 double *data_end = data_start + nchannels;
2346 errors.
load(blocksize, hist);
2347 double *err_start = errors();
2348 double *err_end = err_start + nchannels;
2349 double *farea_start =
nullptr;
2350 double *farea_end =
nullptr;
2351 double *xErrors_start =
nullptr;
2352 double *xErrors_end =
nullptr;
2353 size_t dx_increment = nchannels;
2358 size_t dx_input_increment = xErrors.
dim1();
2361 farea.
load(blocksize, hist);
2362 farea_start = farea();
2363 farea_end = farea_start + nchannels;
2364 rb_workspace = std::dynamic_pointer_cast<RebinnedOutput>(local_workspace);
2366 xbins.
load(blocksize, hist);
2367 const int64_t nxbins(xbins.
dim1());
2368 double *xbin_start = xbins();
2369 double *xbin_end = xbin_start + nxbins;
2370 int64_t
final(hist + blocksize);
2373 xErrors.
load(blocksize, hist);
2374 xErrors_start = xErrors();
2375 xErrors_end = xErrors_start + dx_increment;
2378 while (hist <
final) {
2379 auto &
Y = local_workspace->mutableY(wsIndex);
2380 Y.assign(data_start, data_end);
2381 data_start += nchannels;
2382 data_end += nchannels;
2383 auto &E = local_workspace->mutableE(wsIndex);
2384 E.assign(err_start, err_end);
2385 err_start += nchannels;
2386 err_end += nchannels;
2388 MantidVec &F = rb_workspace->dataF(wsIndex);
2389 F.assign(farea_start, farea_end);
2390 farea_start += nchannels;
2391 farea_end += nchannels;
2394 local_workspace->setSharedDx(wsIndex, Kernel::make_cow<HistogramData::HistogramDx>(xErrors_start, xErrors_end));
2395 xErrors_start += dx_input_increment;
2396 xErrors_end += dx_input_increment;
2398 auto &
X = local_workspace->mutableX(wsIndex);
2399 X.assign(xbin_start, xbin_end);
2400 xbin_start += nxbins;
2429 throw std::invalid_argument(
"Spectra max is less than 0");
2432 if (maxlist >
static_cast<int>(numberofspectra) || minlist == 0) {
2434 throw std::invalid_argument(
"Inconsistent properties defined");
2443 m_spec_max =
static_cast<int>(numberofspectra);
2445 if (m_spec_max < m_spec_min || m_spec_max >
static_cast<int>(numberofspectra)) {
2446 g_log.
error(
"Invalid Spectrum min/max properties");
2447 throw std::invalid_argument(
"Inconsistent properties defined");
2471 m_spec_max =
static_cast<int>(numberofspectra);
2476 if (gen_filtered_list) {
2498 if (gen_filtered_list) {
2506 total_specs = numberofspectra;
2508 m_spec_max =
static_cast<int>(numberofspectra) + 1;
2510 if (gen_filtered_list) {
2512 for (
int j = 0; j < static_cast<int>(total_specs); j++)
2525 auto mWorkspace = std::dynamic_pointer_cast<MatrixWorkspace>(local_workspace);
2527 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.
virtual const std::shared_ptr< Mantid::Nexus::NexusDescriptor > getFileInfo() const noexcept
Required to pass m_fileInfo to static functions Keeping it shared_ptr to match setFileInfo signature ...
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.
~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.
API::Workspace_sptr loadLeanElasticPeaksEntry(const Mantid::Nexus::NXEntry &entry)
Load LeanElasticPeakWorkspace.
int m_spec_max
The value of the spectrum_max property.
int confidence(Nexus::NexusDescriptor &descriptor) const override
Returns a confidence value that this algorithm can load a file.
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
void execLoader() override
Overwrites Algorithm method.
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(const std::string &entryName, const std::string &groupClass) const noexcept
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
Kernel::Logger g_log("ExperimentInfo")
static logger object
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