Skip to content

Commit

Permalink
Merge pull request #560 from mantidproject/11505_improve_loadnexuspro…
Browse files Browse the repository at this point in the history
…c_performance

Optimise LoadNexusProcessed for multiperiod data
  • Loading branch information
OwenArnold committed Apr 10, 2015
2 parents 4162fe5 + bddad68 commit 21854ca
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions Code/Mantid/Framework/DataHandling/src/LoadNexusProcessed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,16 @@ Workspace_sptr LoadNexusProcessed::doAccelleratedMultiPeriodLoading(
periodWorkspace->setX(i, tempMatrixWorkspace->refX(i));
}

NXEntry mtdEntry = root.openEntry(entryName);
const std::string groupName = "workspace";
if (!mtdEntry.containsGroup(groupName)) {
// We avoid using `openEntry` or similar here because they're just wrappers
// around `open`. `open` is slow for large multiperiod datasets, because it
// does a search upon the entire HDF5 tree. `openLocal` is *much* quicker, as
// it only searches the current group. It does, however, require that the parent
// group is currently open.
NXEntry mtdEntry(root, entryName);
mtdEntry.openLocal();

NXData wsEntry(mtdEntry, "workspace");
if (!wsEntry.openLocal()) {
std::stringstream buffer;
buffer
<< "Group entry " << p - 1
Expand All @@ -295,7 +302,6 @@ Workspace_sptr LoadNexusProcessed::doAccelleratedMultiPeriodLoading(
throw std::runtime_error(buffer.str());
}

NXData wsEntry = mtdEntry.openNXData(groupName);
if (wsEntry.isValid("frac_area")) {
std::stringstream buffer;
buffer << "Group entry " << p - 1 << " has fractional area present. Try "
Expand All @@ -304,8 +310,10 @@ Workspace_sptr LoadNexusProcessed::doAccelleratedMultiPeriodLoading(
throw std::runtime_error(buffer.str());
}

NXDataSetTyped<double> data = wsEntry.openDoubleData();
NXDataSetTyped<double> errors = wsEntry.openNXDouble("errors");
NXDataSetTyped<double> data(wsEntry, "values");
data.openLocal();
NXDataSetTyped<double> errors(wsEntry, "errors");
errors.openLocal();

const int nChannels = data.dim1();

Expand Down Expand Up @@ -360,6 +368,11 @@ Workspace_sptr LoadNexusProcessed::doAccelleratedMultiPeriodLoading(
g_log.information(e.what());
}

// We make sure to close the current entries. Failing to do this can cause
// strange off-by-one errors when loading the spectra.
wsEntry.close();
mtdEntry.close();

const double fractionComplete = double(p - 1) / double(nWorkspaceEntries);
progress(fractionComplete, "Loading multiperiod entry");
return periodWorkspace;
Expand Down

0 comments on commit 21854ca

Please sign in to comment.