diff options
author | Thomas White <taw@physics.org> | 2022-03-08 15:18:27 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2022-03-08 17:41:52 +0100 |
commit | dad7c029fdfc1d0a475a86a01ecb02d2adc16dc2 (patch) | |
tree | 2e79bb418309fd9c6cd75484678fa01b374f1658 /libcrystfel/src/datatemplate.c | |
parent | 0b758e3ae3c3fd66c75a42740a80afbabba5c82f (diff) |
Fix slabbiness assumptions
This adds a new routine, data_template_slabby_file_to_panel_coords, to
be used (only!) in places where external forces require assumptions of
slabbiness: pixel maps and MsgPack/HDF5 peak lists (including
CXI-style).
This also fixes the prototype of data_template_file_to_panel_coords to
make the panel number strictly an input parameter. This was an
oversight in the implementation of DataTemplate, and caused problems
when reading non-slabby streams.
Fixes: https://gitlab.desy.de/thomas.white/crystfel/-/issues/66
Diffstat (limited to 'libcrystfel/src/datatemplate.c')
-rw-r--r-- | libcrystfel/src/datatemplate.c | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c index 26ff77c1..1ffa2777 100644 --- a/libcrystfel/src/datatemplate.c +++ b/libcrystfel/src/datatemplate.c @@ -1531,39 +1531,55 @@ void data_template_free(DataTemplate *dt) } -static int data_template_find_panel(const DataTemplate *dt, - int fs, int ss, int *ppn) +int data_template_file_to_panel_coords(const DataTemplate *dt, + float *pfs, float *pss, + int pn) +{ + *pfs = *pfs - dt->panels[pn].orig_min_fs; + *pss = *pss - dt->panels[pn].orig_min_ss; + return 0; +} + + +/** + * Convert image-data-space fs/ss coordinates to panel-relative fs/ss + * coordinates and panel number, assuming that the data is all in one slab. + * + * WARNING: This is probably not the routine you are looking for! + * If you use this routine, your code will only work with 'slabby' data, and + * will break for (amongst others) EuXFEL data. Use + * data_template_file_to_panel_coords instead, and provide the panel number. + * + * \returns 0 on success, 1 on failure + * + */ +int data_template_slabby_file_to_panel_coords(const DataTemplate *dt, + float *pfs, float *pss, int *ppn) { int p; + int found = 0; for ( p=0; p<dt->n_panels; p++ ) { - if ( (fs >= dt->panels[p].orig_min_fs) - && (fs < dt->panels[p].orig_max_fs+1) - && (ss >= dt->panels[p].orig_min_ss) - && (ss < dt->panels[p].orig_max_ss+1) ) { + if ( (*pfs >= dt->panels[p].orig_min_fs) + && (*pfs < dt->panels[p].orig_max_fs+1) + && (*pss >= dt->panels[p].orig_min_ss) + && (*pss < dt->panels[p].orig_max_ss+1) ) + { + if ( found ) { + ERROR("Panel is ambiguous for fs,ss %f,%f\n"); + return 1; + } *ppn = p; - return 0; + found = 1; } } - return 1; -} - - -int data_template_file_to_panel_coords(const DataTemplate *dt, - float *pfs, float *pss, - int *ppn) -{ - int pn; - - if ( data_template_find_panel(dt, *pfs, *pss, &pn) ) { + if ( !found ) { + ERROR("Couldn't find panel for fs,ss %f,%f\n", *pfs, *pss); return 1; } - *ppn = pn; - *pfs = *pfs - dt->panels[pn].orig_min_fs; - *pss = *pss - dt->panels[pn].orig_min_ss; - return 0; + return data_template_file_to_panel_coords(dt, pfs, pss, *ppn); } |