Skip to content

Commit e44d8cc

Browse files
author
Arthur Glowacki
committed
Merge branch 'polar'
2 parents d38bf54 + ec8a659 commit e44d8cc

File tree

4 files changed

+68
-15
lines changed

4 files changed

+68
-15
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ cmake_minimum_required(VERSION 3.20)
4848

4949
project(XRF_Maps)
5050

51+
#include(CTest)
52+
#enable_testing()
53+
5154
set(VCPKG_TARGET_ARCHITECTURE x64)
5255
set(VCPKG_CRT_LINKAGE dynamic)
5356

src/io/file/hdf5_io.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,51 @@ bool HDF5_IO::end_save_seq(bool loginfo)
512512

513513
//-----------------------------------------------------------------------------
514514

515+
bool HDF5_IO::polar_copy_raw(const std::string filename)
516+
{
517+
hid_t src_file_id = -1;
518+
hid_t src_grp_id = -1;
519+
hid_t maps_grp_id = -1;
520+
std::stack<std::pair<hid_t, H5_OBJECTS> > close_map;
521+
522+
if (_cur_file_id < 1)
523+
{
524+
logE << "Destination file is not open. Can not copy over from "<<filename<<"\n";
525+
return false;
526+
}
527+
528+
if (false == _open_h5_object(src_file_id, H5O_FILE, close_map, filename, -1))
529+
{
530+
logE << "Could not open file: " << filename << " \n";
531+
return false;
532+
}
533+
534+
hid_t ocpypl_id = H5Pcreate(H5P_OBJECT_COPY);
535+
close_map.push({ ocpypl_id, H5O_PROPERTY });
536+
537+
if (false == _open_h5_object(src_grp_id, H5O_GROUP, close_map, "/", src_file_id, false))
538+
{
539+
logW << "Tried to open / but failed. "<<filename<<"\n";
540+
_close_h5_objects(close_map);
541+
return false;
542+
}
543+
if (false == _open_h5_object(maps_grp_id, H5O_GROUP, close_map, "/MAPS", _cur_file_id, false))
544+
{
545+
logW << "Tried to open /MAPS but failed. " << _cur_filename << "\n";
546+
_close_h5_objects(close_map);
547+
return false;
548+
}
549+
//copy /entry to /MAPS/raw
550+
herr_t status = H5Ocopy(src_grp_id, "entry", maps_grp_id, "Raw", ocpypl_id, H5P_DEFAULT);
551+
if (status > 0)
552+
{
553+
logW << "Failed to copy from /entry to /MAPS/Raw\n";
554+
}
555+
_close_h5_objects(close_map);
556+
}
557+
558+
//-----------------------------------------------------------------------------
559+
515560
bool HDF5_IO::_save_extras(hid_t scan_grp_id, std::vector<data_struct::Extra_PV>* extra_pvs)
516561
{
517562
hid_t memoryspace_id;

src/io/file/hdf5_io.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,7 @@ class DLL_EXPORT HDF5_IO
13861386

13871387
scan_info.scaler_maps.push_back(energy_map);
13881388
scan_info.scaler_maps.push_back(i0_map);
1389+
13891390
/*
13901391
// x, y, and z dataset are all rows x cols size
13911392
// read x motor scaler from /entry/measurement/pseudo/x
@@ -2972,8 +2973,8 @@ class DLL_EXPORT HDF5_IO
29722973
{
29732974
logI << path << " detector : " << detector_num << "\n";
29742975
}
2975-
hid_t file_id, dset_id, dataspace_id, maps_grp_id, memoryspace_id, memoryspace_meta_id;
2976-
herr_t error;
2976+
hid_t file_id = -1, dset_id = -1, dataspace_id = -1, maps_grp_id = -1, memoryspace_id = -1, memoryspace_meta_id = -1;
2977+
herr_t error = -1;
29772978
std::string detector_path;
29782979
T_real* buffer;
29792980
hsize_t offset_row[2] = { 0,0 };
@@ -3206,9 +3207,9 @@ class DLL_EXPORT HDF5_IO
32063207

32073208
logI << path << " detector : " << detector_num << "\n";
32083209

3209-
hid_t file_id, dset_id, dataspace_id, maps_grp_id, memoryspace_id, memoryspace_meta_id, dset_incnt_id, dset_outcnt_id, dset_rt_id, dset_lt_id;
3210-
hid_t dataspace_lt_id, dataspace_rt_id, dataspace_inct_id, dataspace_outct_id;
3211-
herr_t error;
3210+
hid_t file_id = -1, dset_id = -1, dataspace_id = -1, maps_grp_id = -1, memoryspace_id = -1, memoryspace_meta_id = -1, dset_incnt_id = -1, dset_outcnt_id = -1, dset_rt_id = -1, dset_lt_id = -1;
3211+
hid_t dataspace_lt_id = -1, dataspace_rt_id = -1, dataspace_inct_id = -1, dataspace_outct_id = -1;
3212+
herr_t error = -1;
32123213
std::string detector_path;
32133214
T_real* buffer;
32143215
hsize_t offset_row[2] = { 0,0 };
@@ -3408,9 +3409,9 @@ class DLL_EXPORT HDF5_IO
34083409

34093410
logI << path << "\n";
34103411

3411-
hid_t file_id, dset_id, dataspace_id, spec_grp_id, memoryspace_id, memoryspace_meta_id, dset_incnt_id, dset_outcnt_id, dset_rt_id, dset_lt_id;
3412-
hid_t dataspace_lt_id, dataspace_rt_id, dataspace_inct_id, dataspace_outct_id;
3413-
herr_t error;
3412+
hid_t file_id = -1, dset_id = -1, dataspace_id = -1, spec_grp_id = -1, memoryspace_id = -1, memoryspace_meta_id = -1, dset_incnt_id = -1, dset_outcnt_id = -1, dset_rt_id = -1, dset_lt_id = -1;
3413+
hid_t dataspace_lt_id = -1, dataspace_rt_id = -1, dataspace_inct_id = -1, dataspace_outct_id = -1;
3414+
herr_t error = -1;
34143415
hsize_t dims_in[3] = { 0,0,0 };
34153416
hsize_t offset[3] = { 0,0,0 };
34163417
hsize_t count[3] = { 1,1,1 };
@@ -3554,7 +3555,7 @@ class DLL_EXPORT HDF5_IO
35543555
bool load_integrated_spectra_analyzed_h5(std::string path, data_struct::Spectra<T_real>* spectra, [[maybe_unused]] ROI_Vec* roi = nullptr, bool log_error=true)
35553556
{
35563557
std::lock_guard<std::mutex> lock(_mutex);
3557-
hid_t file_id;
3558+
hid_t file_id = -1;
35583559

35593560
file_id = H5Fopen(path.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
35603561
if (file_id < 0)
@@ -3585,11 +3586,11 @@ class DLL_EXPORT HDF5_IO
35853586

35863587
logI << path << "\n";
35873588

3588-
hid_t file_id, dset_id, dataspace_id, spec_grp_id, memoryspace_id, memoryspace_meta_id, dset_incnt_id, dset_outcnt_id;
3589-
hid_t memoryspace_1;
3590-
hid_t dset_rt_id, dset_lt_id, dset_scalers, dset_scaler_names;
3591-
hid_t dataspace_lt_id, dataspace_rt_id, dataspace_inct_id, dataspace_outct_id, dataspace_scalers, dataspace_scaler_names;
3592-
herr_t error;
3589+
hid_t file_id = -1, dset_id = -1, dataspace_id = -1, spec_grp_id = -1, memoryspace_id = -1, memoryspace_meta_id = -1, dset_incnt_id = -1, dset_outcnt_id = -1;
3590+
hid_t memoryspace_1 = -1;
3591+
hid_t dset_rt_id = -1, dset_lt_id = -1, dset_scalers = -1, dset_scaler_names = -1;
3592+
hid_t dataspace_lt_id = -1, dataspace_rt_id = -1, dataspace_inct_id = -1, dataspace_outct_id = -1, dataspace_scalers = -1, dataspace_scaler_names = -1;
3593+
herr_t error = -1;
35933594
hsize_t dims_in[3] = { 0,0,0 };
35943595
hsize_t offset[3] = { 0,0,0 };
35953596
hsize_t count[3] = { 1,1,1 };
@@ -4851,7 +4852,6 @@ class DLL_EXPORT HDF5_IO
48514852
hsize_t nobj;
48524853
int otype;
48534854
hsize_t names_cnt[1] = { 1 };
4854-
char group_name[1024];
48554855
char memb_name[1024];
48564856

48574857
char acqui_data[10240];
@@ -5445,6 +5445,9 @@ class DLL_EXPORT HDF5_IO
54455445
void set_filename(std::string fname) {_cur_filename = fname;}
54465446

54475447
const std::string& get_filename() { return _cur_filename; }
5448+
5449+
bool polar_copy_raw(const std::string filename);
5450+
54485451
//-----------------------------------------------------------------------------
54495452

54505453
template<typename T_real>

src/io/file/hl_file_io.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,8 @@ DLL_EXPORT bool load_spectra_volume(std::string dataset_directory,
854854
{
855855
data_struct::Params_Override<double>* null_po = nullptr;
856856
io::file::HDF5_IO::inst()->save_scan_scalers(&scan_info, null_po);
857+
// copy /entry to /MAPS/raw
858+
io::file::HDF5_IO::inst()->polar_copy_raw(dataset_directory+dataset_file);
857859
return true;
858860
}
859861
else

0 commit comments

Comments
 (0)