Skip to content

Commit e442df5

Browse files
Get rid of void pointers for data in NexusFile - ornl-next (#39138)
* Get rid of unnecessary method * Template code to help nexus reading * Switch from void * to templates for data functions * Edit files until all of the magic works * Allocate memory in load() * Use sized integer types that match what is told to nexus * Fix typo in type name * Move from NXSize to NXUInt64 to make things more obvious * Small changes for reviewer comments and reformating docstrings
1 parent a487fbd commit e442df5

21 files changed

+412
-303
lines changed

Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ class MANTID_DATAHANDLING_DLL LoadISISNexus2 : public API::IFileLoader<Kernel::N
107107
void loadPeriodData(int64_t period, Mantid::NeXus::NXEntry &entry, DataObjects::Workspace2D_sptr &local_workspace,
108108
bool update_spectra2det_mapping = false);
109109
// Load a data block
110-
void loadBlock(Mantid::NeXus::NXDataSetTyped<int> &data, int64_t blocksize, int64_t period, int64_t start,
111-
int64_t &hist, int64_t &spec_num, DataObjects::Workspace2D_sptr &local_workspace);
110+
void loadBlock(NeXus::NXInt &data, int64_t blocksize, int64_t period, int64_t start, int64_t &hist, int64_t &spec_num,
111+
DataObjects::Workspace2D_sptr &local_workspace);
112112

113113
// Create period logs
114114
void createPeriodLogs(int64_t period, DataObjects::Workspace2D_sptr &local_workspace);

Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,20 @@ class MANTID_DATAHANDLING_DLL LoadNexusProcessed : public API::NexusFileLoader {
145145

146146
/// Load a block of data into the workspace where it is assumed that the x
147147
/// bins have already been cached
148-
void loadBlock(Mantid::NeXus::NXDataSetTyped<double> &data, Mantid::NeXus::NXDataSetTyped<double> &errors,
149-
Mantid::NeXus::NXDataSetTyped<double> &farea, bool hasFArea, Mantid::NeXus::NXDouble &xErrors,
150-
bool hasXErrors, int64_t blocksize, int64_t nchannels, int64_t &hist,
151-
const API::MatrixWorkspace_sptr &local_workspace);
148+
void loadBlock(Mantid::NeXus::NXDouble &data, Mantid::NeXus::NXDouble &errors, Mantid::NeXus::NXDouble &farea,
149+
bool hasFArea, Mantid::NeXus::NXDouble &xErrors, bool hasXErrors, int64_t blocksize, int64_t nchannels,
150+
int64_t &hist, const API::MatrixWorkspace_sptr &local_workspace);
152151

153152
/// Load a block of data into the workspace where it is assumed that the x
154153
/// bins have already been cached
155-
void loadBlock(Mantid::NeXus::NXDataSetTyped<double> &data, Mantid::NeXus::NXDataSetTyped<double> &errors,
156-
Mantid::NeXus::NXDataSetTyped<double> &farea, bool hasFArea, Mantid::NeXus::NXDouble &xErrors,
157-
bool hasXErrors, int64_t blocksize, int64_t nchannels, int64_t &hist, int64_t &wsIndex,
158-
const API::MatrixWorkspace_sptr &local_workspace);
154+
void loadBlock(Mantid::NeXus::NXDouble &data, Mantid::NeXus::NXDouble &errors, Mantid::NeXus::NXDouble &farea,
155+
bool hasFArea, Mantid::NeXus::NXDouble &xErrors, bool hasXErrors, int64_t blocksize, int64_t nchannels,
156+
int64_t &hist, int64_t &wsIndex, const API::MatrixWorkspace_sptr &local_workspace);
159157
/// Load a block of data into the workspace
160-
void loadBlock(Mantid::NeXus::NXDataSetTyped<double> &data, Mantid::NeXus::NXDataSetTyped<double> &errors,
161-
Mantid::NeXus::NXDataSetTyped<double> &farea, bool hasFArea, Mantid::NeXus::NXDouble &xErrors,
162-
bool hasXErrors, Mantid::NeXus::NXDouble &xbins, int64_t blocksize, int64_t nchannels, int64_t &hist,
163-
int64_t &wsIndex, const API::MatrixWorkspace_sptr &local_workspace);
158+
void loadBlock(Mantid::NeXus::NXDouble &data, Mantid::NeXus::NXDouble &errors, Mantid::NeXus::NXDouble &farea,
159+
bool hasFArea, Mantid::NeXus::NXDouble &xErrors, bool hasXErrors, Mantid::NeXus::NXDouble &xbins,
160+
int64_t blocksize, int64_t nchannels, int64_t &hist, int64_t &wsIndex,
161+
const API::MatrixWorkspace_sptr &local_workspace);
164162

165163
/// Load the data from a non-spectra axis (Numeric/Text) into the workspace
166164
void loadNonSpectraAxis(const API::MatrixWorkspace_sptr &local_workspace, const Mantid::NeXus::NXData &data);

Framework/DataHandling/inc/MantidDataHandling/SaveNexusProcessedHelper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class MANTID_DATAHANDLING_DLL NexusFileIO {
7373
float const *weights, float const *errorSquareds, int64_t const *pulsetimes,
7474
bool compress) const;
7575

76-
void writeData(const char *name, NXnumtype datatype, std::vector<int> dims_array, void const *data,
76+
template <typename NumT>
77+
void writeData(const char *name, NXnumtype datatype, std::vector<int> dims_array, NumT const *data,
7778
bool compress = false) const;
7879

7980
/// write bin masking information

Framework/DataHandling/src/LoadEMU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ template <>
109109
double GetNeXusValue<double>(const NeXus::NXEntry &entry, const std::string &path, const double &defval,
110110
int32_t index) {
111111
try {
112-
NeXus::NXDataSetTyped<float> dataSet = entry.openNXDataSet<float>(path);
112+
NeXus::NXFloat dataSet = entry.openNXFloat(path);
113113
dataSet.load();
114114

115115
return dataSet()[index];

Framework/DataHandling/src/LoadISISNexus2.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ void LoadISISNexus2::loadPeriodData(int64_t period, NXEntry &entry, DataObjects:
718718
hist_index++;
719719
} else if (m_have_detector) {
720720
NXData nxdata = entry.openNXData("detector_1");
721-
NXDataSetTyped<int> data = nxdata.openIntData();
721+
NXInt data = nxdata.openIntData();
722722
data.open();
723723
// Start with the list members that are lower than the required spectrum
724724
const int *const spec_begin = m_spec.data();
@@ -784,10 +784,9 @@ void LoadISISNexus2::createPeriodLogs(int64_t period, DataObjects::Workspace2D_s
784784
* @param spec_num :: The spectrum number that matches the hist variable
785785
* @param local_workspace :: The workspace to fill the data with
786786
*/
787-
void LoadISISNexus2::loadBlock(NXDataSetTyped<int> &data, int64_t blocksize, int64_t period, int64_t start,
788-
int64_t &hist, int64_t &spec_num, DataObjects::Workspace2D_sptr &local_workspace) {
789-
data.load(static_cast<int>(blocksize), static_cast<int>(period),
790-
static_cast<int>(start)); // TODO this is just wrong
787+
void LoadISISNexus2::loadBlock(NXInt &data, int64_t blocksize, int64_t period, int64_t start, int64_t &hist,
788+
int64_t &spec_num, DataObjects::Workspace2D_sptr &local_workspace) {
789+
data.load(blocksize, period, start); // TODO this is just wrong
791790
int *data_start = data();
792791
int *data_end = data_start + m_loadBlockInfo.getNumberOfChannels();
793792
int64_t final(hist + blocksize);

Framework/DataHandling/src/LoadNexusProcessed.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ Workspace_sptr LoadNexusProcessed::doAccelleratedMultiPeriodLoading(NXRoot &root
291291
throw std::runtime_error(buffer.str());
292292
}
293293

294-
NXDataSetTyped<double> data(wsEntry, "values");
294+
NXDouble data(wsEntry, "values");
295295
data.openLocal();
296-
NXDataSetTyped<double> errors(wsEntry, "errors");
296+
NXDouble errors(wsEntry, "errors");
297297
errors.openLocal();
298298

299299
const int64_t nChannels = data.dim1();
@@ -644,7 +644,7 @@ std::string LoadNexusProcessed::loadWorkspaceName(NXRoot &root, const std::strin
644644
*/
645645
API::MatrixWorkspace_sptr LoadNexusProcessed::loadEventEntry(NXData &wksp_cls, NXDouble &xbins,
646646
const double &progressStart, const double &progressRange) {
647-
NXDataSetTyped<int64_t> indices_data = wksp_cls.openNXDataSet<int64_t>("indices");
647+
NXInt64 indices_data = wksp_cls.openNXDataSet<int64_t>("indices");
648648
indices_data.load();
649649
size_t numspec = indices_data.dim0() - 1;
650650

@@ -674,7 +674,7 @@ API::MatrixWorkspace_sptr LoadNexusProcessed::loadEventEntry(NXData &wksp_cls, N
674674
// TODO: Handle inconsistent sizes
675675
std::vector<int64_t> pulsetimes;
676676
if (wksp_cls.isValid("pulsetime")) {
677-
NXDataSetTyped<int64_t> pulsetime = wksp_cls.openNXDataSet<int64_t>("pulsetime");
677+
NXInt64 pulsetime = wksp_cls.openNXDataSet<int64_t>("pulsetime");
678678
pulsetime.load();
679679
pulsetimes = pulsetime.vecBuffer();
680680
}
@@ -859,7 +859,7 @@ API::Workspace_sptr LoadNexusProcessed::loadTableEntry(const NXEntry &entry) {
859859
}
860860
}
861861
} else if (info.type == NXnumtype::INT32) {
862-
loadVectorColumn<int>(nx_tw, dataSetName, workspace, "vector_int");
862+
loadVectorColumn<int32_t>(nx_tw, dataSetName, workspace, "vector_int");
863863
} else if (info.type == NXnumtype::FLOAT64) {
864864
auto data = nx_tw.openNXDouble(dataSetName);
865865
if (data.attributes("interpret_as") == "V3D") {
@@ -1535,7 +1535,7 @@ API::MatrixWorkspace_sptr LoadNexusProcessed::loadNonEventEntry(NXData &wksp_cls
15351535
const double &progressRange, const NXEntry &mtd_entry,
15361536
const int64_t xlength, std::string &workspaceType) {
15371537
// Filter the list of spectra to process, applying min/max/list options
1538-
NXDataSetTyped<double> data = wksp_cls.openDoubleData();
1538+
NXDouble data = wksp_cls.openDoubleData();
15391539
int64_t nchannels = data.dim1();
15401540
size_t nspectra = data.dim0();
15411541
// process optional spectrum parameters, if set
@@ -1605,8 +1605,8 @@ API::MatrixWorkspace_sptr LoadNexusProcessed::loadNonEventEntry(NXData &wksp_cls
16051605
local_workspace->setYUnitLabel(unitLabel);
16061606

16071607
readBinMasking(wksp_cls, local_workspace);
1608-
NXDataSetTyped<double> errors = wksp_cls.openNXDouble("errors");
1609-
NXDataSetTyped<double> fracarea = errors;
1608+
NXDouble errors = wksp_cls.openNXDouble("errors");
1609+
NXDouble fracarea = errors;
16101610
if (hasFracArea) {
16111611
fracarea = wksp_cls.openNXDouble("frac_area");
16121612

@@ -2154,7 +2154,7 @@ void LoadNexusProcessed::readBinMasking(const NXData &wksp_cls, const API::Matri
21542154
}
21552155
NXInt spec = wksp_cls.openNXInt("masked_spectra");
21562156
spec.load();
2157-
NXSize bins = wksp_cls.openNXSize("masked_bins");
2157+
NXUInt64 bins = wksp_cls.openNXSize("masked_bins");
21582158
bins.load();
21592159
NXDouble weights = wksp_cls.openNXDouble("mask_weights");
21602160
weights.load();
@@ -2186,9 +2186,8 @@ void LoadNexusProcessed::readBinMasking(const NXData &wksp_cls, const API::Matri
21862186
* @param hist :: The workspace index to start reading into
21872187
* @param local_workspace :: A pointer to the workspace
21882188
*/
2189-
void LoadNexusProcessed::loadBlock(NXDataSetTyped<double> &data, NXDataSetTyped<double> &errors,
2190-
NXDataSetTyped<double> &farea, bool hasFArea, NXDouble &xErrors, bool hasXErrors,
2191-
int64_t blocksize, int64_t nchannels, int64_t &hist,
2189+
void LoadNexusProcessed::loadBlock(NXDouble &data, NXDouble &errors, NXDouble &farea, bool hasFArea, NXDouble &xErrors,
2190+
bool hasXErrors, int64_t blocksize, int64_t nchannels, int64_t &hist,
21922191
const API::MatrixWorkspace_sptr &local_workspace) {
21932192
data.load(blocksize, hist);
21942193
errors.load(blocksize, hist);
@@ -2264,10 +2263,9 @@ void LoadNexusProcessed::loadBlock(NXDataSetTyped<double> &data, NXDataSetTyped<
22642263
* @param local_workspace :: A pointer to the workspace
22652264
*/
22662265

2267-
void LoadNexusProcessed::loadBlock(NXDataSetTyped<double> &data, NXDataSetTyped<double> &errors,
2268-
NXDataSetTyped<double> &farea, bool hasFArea, NXDouble &xErrors, bool hasXErrors,
2269-
int64_t blocksize, int64_t nchannels, int64_t &hist, int64_t &wsIndex,
2270-
const API::MatrixWorkspace_sptr &local_workspace) {
2266+
void LoadNexusProcessed::loadBlock(NXDouble &data, NXDouble &errors, NXDouble &farea, bool hasFArea, NXDouble &xErrors,
2267+
bool hasXErrors, int64_t blocksize, int64_t nchannels, int64_t &hist,
2268+
int64_t &wsIndex, const API::MatrixWorkspace_sptr &local_workspace) {
22712269
data.load(blocksize, hist);
22722270
errors.load(blocksize, hist);
22732271
double *data_start = data();
@@ -2342,10 +2340,9 @@ void LoadNexusProcessed::loadBlock(NXDataSetTyped<double> &data, NXDataSetTyped<
23422340
* @param wsIndex :: The workspace index to save data into
23432341
* @param local_workspace :: A pointer to the workspace
23442342
*/
2345-
void LoadNexusProcessed::loadBlock(NXDataSetTyped<double> &data, NXDataSetTyped<double> &errors,
2346-
NXDataSetTyped<double> &farea, bool hasFArea, NXDouble &xErrors, bool hasXErrors,
2347-
NXDouble &xbins, int64_t blocksize, int64_t nchannels, int64_t &hist,
2348-
int64_t &wsIndex, const API::MatrixWorkspace_sptr &local_workspace) {
2343+
void LoadNexusProcessed::loadBlock(NXDouble &data, NXDouble &errors, NXDouble &farea, bool hasFArea, NXDouble &xErrors,
2344+
bool hasXErrors, NXDouble &xbins, int64_t blocksize, int64_t nchannels,
2345+
int64_t &hist, int64_t &wsIndex, const API::MatrixWorkspace_sptr &local_workspace) {
23492346
data.load(blocksize, hist);
23502347
double *data_start = data();
23512348
double *data_end = data_start + nchannels;

Framework/DataHandling/src/LoadPLN.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ template <>
9292
double GetNeXusValue<double>(const NeXus::NXEntry &entry, const std::string &path, const double &defval,
9393
int32_t index) {
9494
try {
95-
NeXus::NXDataSetTyped<float> dataSet = entry.openNXDataSet<float>(path);
95+
NeXus::NXFloat dataSet = entry.openNXDataSet<float>(path);
9696
dataSet.load();
9797

9898
return dataSet()[index];

Framework/DataHandling/src/SaveNexusProcessedHelper.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@ int NexusFileIO::writeNexusProcessedDataEventCombined(const DataObjects::EventWo
662662

663663
//-------------------------------------------------------------------------------------
664664
/** Write out an array to the open file. */
665-
void NexusFileIO::writeData(const char *name, NXnumtype datatype, std::vector<int> dims_array, void const *data,
665+
template <typename NumT>
666+
void NexusFileIO::writeData(const char *name, NXnumtype datatype, std::vector<int> dims_array, NumT const *data,
666667
bool compress) const {
667668
if (compress) {
668669
// We'll use the same slab/buffer size as the size of the array
@@ -698,8 +699,8 @@ int NexusFileIO::findMantidWSEntries() const {
698699
* @return true for OK, false for error
699700
*/
700701
bool NexusFileIO::writeNexusBinMasking(const API::MatrixWorkspace_const_sptr &ws) const {
701-
std::vector<int> spectra;
702-
std::vector<std::size_t> bins;
702+
std::vector<int32_t> spectra;
703+
std::vector<int64_t> bins;
703704
std::vector<double> weights;
704705
int spectra_count = 0;
705706
int offset = 0;

Framework/DataObjects/src/LeanElasticPeaksWorkspace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ void LeanElasticPeaksWorkspace::saveNexus(::NeXus::File *file) const {
613613
toNexus[ii * maxShapeJSONLength + ic] = ' ';
614614
}
615615

616-
file->putData(static_cast<void *>(toNexus));
616+
file->putData(toNexus);
617617

618618
delete[] toNexus;
619619
file->putAttr("units", "Not known"); // Units may need changing when known

Framework/DataObjects/src/PeaksWorkspace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ void PeaksWorkspace::saveNexus(::NeXus::File *file) const {
910910
toNexus[ii * maxShapeJSONLength + ic] = ' ';
911911
}
912912

913-
file->putData(static_cast<void *>(toNexus));
913+
file->putData(toNexus);
914914

915915
delete[] toNexus;
916916
file->putAttr("units", "Not known"); // Units may need changing when known

0 commit comments

Comments
 (0)