Skip to content

Commit a8c3cfd

Browse files
author
Arthur Glowacki
committed
Changed return type of mda lodaing to help fix issue introduced for loading newer xspress3 datasets
1 parent 01f9e72 commit a8c3cfd

3 files changed

Lines changed: 18 additions & 15 deletions

File tree

src/io/file/hl_file_io.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,13 +1234,14 @@ DLL_EXPORT bool load_spectra_volume(std::string dataset_directory,
12341234
}
12351235

12361236
// try to load spectra from mda file
1237-
if (false == mda_io.load_spectra_volume(dataset_directory + "mda" + DIR_END_CHAR + dataset_file, detector_num, spectra_volume, (hasNetcdf || hasBnpNetcdf || hasHdf || hasXspress), hasNetcdf))
1237+
auto mda_ret_val = mda_io.load_spectra_volume(dataset_directory + "mda" + DIR_END_CHAR + dataset_file, detector_num, spectra_volume, (hasNetcdf || hasBnpNetcdf || hasHdf || hasXspress), hasNetcdf);
1238+
if (Load_Status::Failed == mda_ret_val)
12381239
{
12391240
scan_type = STR_SCAN_TYPE_2D_MAP;
12401241
logE << "Load spectra " << dataset_directory + "mda" + DIR_END_CHAR + dataset_file << "\n";
12411242
return false;
12421243
}
1243-
else
1244+
else if (Load_Status::Half_need_spectra == mda_ret_val)
12441245
{
12451246
// tetramm is scalers only
12461247
if(hasTetraMM)

src/io/file/mda_io.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ bool MDA_IO<T_real>::load_quantification_scalers(std::string path, data_struct::
233233
//-----------------------------------------------------------------------------
234234

235235
template<typename T_real>
236-
bool MDA_IO<T_real>::load_spectra_volume(std::string path,
236+
Load_Status MDA_IO<T_real>::load_spectra_volume(std::string path,
237237
size_t detector_num,
238238
data_struct::Spectra_Volume<T_real>* vol,
239239
bool hasNetCDF,
@@ -252,22 +252,22 @@ bool MDA_IO<T_real>::load_spectra_volume(std::string path,
252252

253253
if (fptr == nullptr)
254254
{
255-
return false;
255+
return Load_Status::Failed;
256256
}
257257

258258

259259
_mda_file = mda_load(fptr);
260260
std::fclose(fptr);
261261
if (_mda_file == nullptr || vol == nullptr)
262262
{
263-
return false;
263+
return Load_Status::Failed;
264264
}
265265
logI<<"mda info ver:"<<_mda_file->header->version<<" data rank:"<<_mda_file->header->data_rank<<"\n";
266266

267267
if (_mda_file->header->data_rank == 1)
268268
{
269269
logE << "Cannot load mda file data rank == 1" << "\n";
270-
return false;
270+
return Load_Status::Failed;
271271
}
272272

273273
_load_scalers(false,hasNetCDF, subtract_two_cols);
@@ -311,7 +311,7 @@ bool MDA_IO<T_real>::load_spectra_volume(std::string path,
311311
}
312312

313313
vol->resize_and_zero(rows, cols, 2048);
314-
return true;
314+
return Load_Status::Half_need_spectra;
315315
}
316316
else
317317
{
@@ -322,7 +322,7 @@ bool MDA_IO<T_real>::load_spectra_volume(std::string path,
322322
{
323323
logE<<"Max detectors saved = "<<_mda_file->scan->sub_scans[0]->number_detectors<< "\n";
324324
unload();
325-
return false;
325+
return Load_Status::Failed;
326326
}
327327

328328
rows = 1;
@@ -347,7 +347,7 @@ bool MDA_IO<T_real>::load_spectra_volume(std::string path,
347347
//if not then we don't know what is dataset is.
348348
logE << "Don't understand this dataset layout. Can not load it.\n";
349349
unload();
350-
return false;
350+
return Load_Status::Failed;
351351
}
352352
}
353353
}
@@ -392,15 +392,15 @@ bool MDA_IO<T_real>::load_spectra_volume(std::string path,
392392
cols = 1;
393393
}
394394
vol->resize_and_zero(rows, cols, 2048);
395-
return true;
395+
return Load_Status::Half_need_spectra;
396396
}
397397
// TODO: might need to check if is XANES like above
398398
}
399399
if(_mda_file->scan->sub_scans[0]->sub_scans[0]->number_detectors-1 < (int)detector_num)
400400
{
401401
logE<<"Max detectors saved = "<<_mda_file->scan->sub_scans[0]->sub_scans[0]->number_detectors<< "\n";
402402
unload();
403-
return false;
403+
return Load_Status::Failed;
404404
}
405405

406406
if(_mda_file->scan->requested_points == 0 || _mda_file->scan->last_point == 0)
@@ -442,7 +442,7 @@ bool MDA_IO<T_real>::load_spectra_volume(std::string path,
442442
{
443443
logE<<" No support for data rank "<< _mda_file->header->data_rank <<"\n";
444444
unload();
445-
return false;
445+
return Load_Status::Failed;
446446
}
447447

448448
elt_arr = _scan_info.scaler_values(STR_ELT + std::to_string(detector_num + 1));
@@ -524,10 +524,10 @@ bool MDA_IO<T_real>::load_spectra_volume(std::string path,
524524
{
525525
logE<<"Caught exception loading mda file."<<"\n";
526526
std::cerr << "Exception catched : " << e.what() << "\n";
527-
return false;
527+
return Load_Status::Failed;
528528
}
529529

530-
return true;
530+
return Load_Status::Loaded;
531531
}
532532

533533

src/io/file/mda_io.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ namespace io
8181
namespace file
8282
{
8383

84+
enum class Load_Status{ Failed, Half_need_spectra, Loaded };
85+
8486
template<typename T_real>
8587
class DLL_EXPORT MDA_IO
8688
{
@@ -101,7 +103,7 @@ class DLL_EXPORT MDA_IO
101103

102104
bool load_scalers(std::string path);
103105

104-
bool load_spectra_volume(std::string path,
106+
Load_Status load_spectra_volume(std::string path,
105107
size_t detector_num,
106108
data_struct::Spectra_Volume<T_real>* vol,
107109
bool hasNetCDF,

0 commit comments

Comments
 (0)