Skip to content

Commit ca2f580

Browse files
authored
Merge pull request #213 from aglowacki/master
Update to translating tetramm scalers to proper names
2 parents 6808fa2 + b8b819f commit ca2f580

6 files changed

Lines changed: 113 additions & 21 deletions

File tree

reference/Scaler_to_PV_map.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ BeamLines:
3030
OCR3: 2iddXMAP:dxp3:OutputCountRate
3131
OCR4: 2iddXMAP:dxp4:OutputCountRate
3232
XBIC: 2idd:scaler1_cts1.D
33-
US_FM: 2iddtmm1:Current3:MeanValue_RBV
33+
US_FM:
34+
- 2iddtmm1:Current3:MeanValue_RBV
35+
- 2iddtmm1:Current3
3436
TimeNormalizedScalers:
3537
Timing: [2idd:3820:mca1.VAL, 50000000.0]
3638
Scalers:

src/data_struct/detector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void Detector<T_real>::append_element(Fitting_Routines routine, std::string quan
112112
if (element != nullptr)
113113
{
114114
Electron_Shell shell = get_shell_by_name(name);
115-
fitting_quant_map.at(routine).update_weight(shell, element->number, weight);
115+
fitting_quant_map.at(routine).update_weight_if_greater(shell, element->number, weight);
116116

117117
if (fitting_quant_map.at(routine).quant_scaler_map.count(quant_scaler) > 0)
118118
{
@@ -274,7 +274,7 @@ void Detector<T_real>::generage_avg_quantification_scalers()
274274
if (itr.second.US_FM > 0.0)
275275
{
276276
avg_US_FM += itr.second.US_FM;
277-
us_cnt += 1.0;
277+
us_fm_cnt += 1.0;
278278
}
279279
if (itr.second.DS_IC > 0.0)
280280
{

src/data_struct/quantification_standard.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ struct DLL_EXPORT Fitting_Quantification_Struct
124124
}
125125
}
126126

127+
void update_weight_if_greater(Electron_Shell shell, unsigned int Z, T_real weight)
128+
{
129+
for (auto& itr : quant_scaler_map)
130+
{
131+
if(weight > itr.second.curve_quant_map.at(shell).at(Z - 1).weight)
132+
{
133+
itr.second.curve_quant_map.at(shell).at(Z - 1).weight = weight;
134+
}
135+
}
136+
}
137+
127138
// Quantifier {SR_Current, US_IC, DS_IC}
128139
std::unordered_map<std::string, Quantification_Scaler_Struct<T_real>> quant_scaler_map;
129140
// saved value from optimizer, {SR_Current, US_IC, DS_IC}

src/io/file/hdf5_io.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,5 +2926,31 @@ void HDF5_IO::add_exchange_layout(std::string dataset_file)
29262926
//-----------------------------------------------------------------------------
29272927
//-----------------------------------------------------------------------------
29282928

2929+
herr_t h5_ext_file_info(hid_t loc_id, const char *name, const H5L_info2_t *linfo, void *opdata)
2930+
{
2931+
hid_t group;
2932+
2933+
2934+
logI<< "external link to "<< name << "\n";
2935+
/*
2936+
* Open the group using its name.
2937+
*/
2938+
//hdf5_io_det_spec_line<T_real>* det_spec = (hdf5_io_det_spec_line<T_real>*)opdata;
2939+
std::map<std::string, hid_t>* ext_links = (std::map<std::string, hid_t>*)opdata;
2940+
2941+
if(ext_links != nullptr)
2942+
{
2943+
group = H5Gopen2(loc_id, name, H5P_DEFAULT);
2944+
if(group >= 0)
2945+
{
2946+
std::string str_name = std::string(name);
2947+
ext_links->insert({str_name, group});
2948+
}
2949+
}
2950+
return 0;
2951+
}
2952+
2953+
//-----------------------------------------------------------------------------
2954+
29292955
} //end namespace file
29302956
}// end namespace io

src/io/file/hdf5_io.h

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ enum GSE_CARS_SAVE_VER {UNKNOWN, XRFMAP, XRMMAP};
9090

9191
using ROI_Vec = std::vector<std::pair<int, int>>;
9292

93+
extern "C" herr_t h5_ext_file_info(hid_t loc_id, const char *name, const H5L_info2_t *linfo, void *opdata);
94+
9395
//-----------------------------------------------------------------------------
9496

9597
template<typename T_real>
@@ -925,14 +927,42 @@ class DLL_EXPORT HDF5_IO
925927
{
926928
return false;
927929
}
930+
/*
928931
if (false == _open_h5_object(pos_grp_id, H5O_GROUP, close_map, "/positions", file_id))
929932
{
930933
return false;
931934
}
932935
if (false == _open_h5_object(xspres_grp_id, H5O_GROUP, close_map, "/flyXRF", file_id))
936+
*/
937+
if (false == _open_h5_object(xspres_grp_id, H5O_GROUP, close_map, "/detectors/XRF_ME7", file_id, false, false))
933938
{
939+
if (false == _open_h5_object(xspres_grp_id, H5O_GROUP, close_map, "/detectors/XRF_RS", file_id))
940+
{
941+
return false;
942+
}
934943
return false;
935944
}
945+
946+
int idx = filename.find_last_of("_master.h5") - 9;
947+
if(idx > 0)
948+
{
949+
std::string base_name = filename.substr(0, idx);
950+
std::map<std::string, hid_t> ext_links;
951+
herr_t idx = H5Literate2(xspres_grp_id, H5_INDEX_NAME, H5_ITER_INC, NULL, h5_ext_file_info, &ext_links);
952+
spec_vol->resize_and_zero(ext_links.size(),1,4096);
953+
for(unsigned long i = 0; i<ext_links.size(); i++)
954+
{
955+
std::string search_name = base_name + "_" + std::to_string(i) + ".hdf5";
956+
logI<< "searching "<< search_name << "\n";
957+
if(ext_links.count(search_name) > 0)
958+
{
959+
logI<< "loading "<< search_name << "\n";
960+
_load_spectra_line_xspress3(ext_links.at(search_name), detector_num, &(*spec_vol)[i]);
961+
H5Gclose(ext_links.at(search_name));
962+
}
963+
}
964+
}
965+
/*
936966
// load spectra link
937967
err = H5Lget_name_by_idx(xspres_grp_id, ".", H5_INDEX_NAME, H5_ITER_NATIVE, 0, &xspress3_link[0], 2048, H5P_DEFAULT);
938968
if (err < 0)
@@ -941,7 +971,6 @@ class DLL_EXPORT HDF5_IO
941971
_close_h5_objects(close_map);
942972
return false;
943973
}
944-
945974
err = H5Lget_name_by_idx(pos_grp_id, ".", H5_INDEX_NAME, H5_ITER_NATIVE, 0, &positions_link[0], 2048, H5P_DEFAULT);
946975
if (err < 0)
947976
{
@@ -993,15 +1022,18 @@ class DLL_EXPORT HDF5_IO
9931022
9941023
// read in scalers from TertraMM
9951024
996-
1025+
*/
1026+
9971027
_close_h5_objects(close_map);
9981028
}
1029+
/*
9991030
spec_vol->resize_and_zero(1,1,1);
10001031
if(false == load_spectra_line_xspress3(path + "flyXRF/" + xspress3_link, detector_num, &(*spec_vol)[0]) )
1032+
if(false == load_spectra_line_xspress3(path + "XRF_ME7/" + xspress3_link, detector_num, &(*spec_vol)[0]) )
10011033
{
10021034
return false;
10031035
}
1004-
1036+
*/
10051037
return true;
10061038
}
10071039

@@ -1506,9 +1538,30 @@ class DLL_EXPORT HDF5_IO
15061538
start = std::chrono::system_clock::now();
15071539

15081540
logI << path << " detector : " << detector_num << "\n";
1541+
std::stack<std::pair<hid_t, H5_OBJECTS> > close_map;
1542+
hid_t file_id;
15091543

1544+
if (false == _open_h5_object(file_id, H5O_FILE, close_map, path, -1))
1545+
{
1546+
return false;
1547+
}
1548+
bool ret = _load_spectra_line_xspress3(file_id, detector_num, spec_row);
1549+
_close_h5_objects(close_map);
1550+
1551+
end = std::chrono::system_clock::now();
1552+
std::chrono::duration<double> elapsed_seconds = end - start;
1553+
1554+
logI << "elapsed time: " << elapsed_seconds.count() << "s" << "\n";
1555+
return ret;
1556+
}
1557+
1558+
//-----------------------------------------------------------------------------
1559+
1560+
template<typename T_real>
1561+
bool _load_spectra_line_xspress3(hid_t file_id, size_t detector_num, data_struct::Spectra_Line<T_real>* spec_row)
1562+
{
15101563
std::stack<std::pair<hid_t, H5_OBJECTS> > close_map;
1511-
hid_t file_id, dset_id, dataspace_id, maps_grp_id, scaler_grp_id, scaler2_grp_id, memoryspace_id, memoryspace_meta_id = -1;
1564+
hid_t dset_id, dataspace_id, maps_grp_id, scaler_grp_id, scaler2_grp_id, memoryspace_id, memoryspace_meta_id = -1;
15121565
hid_t dset_lt_id, dset_rt_id, dset_outcnt_id = -1;
15131566
hid_t dataspace_lt_id, dataspace_rt_id, dataspace_outcnt_id = -1;
15141567

@@ -1530,18 +1583,16 @@ class DLL_EXPORT HDF5_IO
15301583

15311584
std::string outcounts_dataset_name2 = "OutputCounts_" + std::to_string(detector_num);
15321585

1533-
1534-
if (false == _open_h5_object(file_id, H5O_FILE, close_map, path, -1))
1535-
{
1536-
return false;
1537-
}
15381586
if (false == _open_h5_object(maps_grp_id, H5O_GROUP, close_map, "/entry/data", file_id, false, false))
15391587
{
1540-
if (false == _open_h5_object(maps_grp_id, H5O_GROUP, close_map, "/entry/instrument/detector", file_id, false, false))
1588+
if (false == _open_h5_object(maps_grp_id, H5O_GROUP, close_map, "/data", file_id, false, false))
15411589
{
1542-
if (false == _open_h5_object(maps_grp_id, H5O_GROUP, close_map, "/entry/instrument/xspress3", file_id, false, true))
1590+
if (false == _open_h5_object(maps_grp_id, H5O_GROUP, close_map, "/entry/instrument/detector", file_id, false, false))
15431591
{
1544-
return false;
1592+
if (false == _open_h5_object(maps_grp_id, H5O_GROUP, close_map, "/entry/instrument/xspress3", file_id, false, true))
1593+
{
1594+
return false;
1595+
}
15451596
}
15461597
}
15471598
}
@@ -1723,11 +1774,6 @@ class DLL_EXPORT HDF5_IO
17231774

17241775
_close_h5_objects(close_map);
17251776

1726-
end = std::chrono::system_clock::now();
1727-
std::chrono::duration<double> elapsed_seconds = end - start;
1728-
//std::time_t end_time = std::chrono::system_clock::to_time_t(end);
1729-
1730-
logI << "elapsed time: " << elapsed_seconds.count() << "s" << "\n";
17311777
return true;
17321778
}
17331779

src/io/file/mda_io.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,14 @@ void MDA_IO<T_real>::_load_extra_pvs_vector()
12601260
data_struct::Scaler_Map<T_real> s_map;
12611261
s_map.values.resize(o_map.values.rows(), o_map.values.cols());
12621262
s_map.values.setZero(o_map.values.rows(), o_map.values.cols());
1263-
s_map.name = tokens[1];
1263+
if (data_struct::Scaler_Lookup::inst()->search_pv(tokens[0] + ":" + tokens[1], label, is_time_normalized, beamline))
1264+
{
1265+
s_map.name = label;
1266+
}
1267+
else
1268+
{
1269+
s_map.name = e_pv.name;
1270+
}
12641271

12651272
if(t1idx != std::string::npos)
12661273
{

0 commit comments

Comments
 (0)