From 6d6cf54f7eb8597d64aa8f36d57ffd8b0103f644 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 10 Jun 2020 16:38:51 +0200 Subject: Tidy up Regarding check_path_existence: This was a very complicated procedure, for not very much gain. The attempt to open a dataset for real, which invariably follows, can still fail after this check. --- libcrystfel/src/datatemplate.c | 26 +++++++----- libcrystfel/src/datatemplate.h | 2 +- libcrystfel/src/detgeom.c | 1 + libcrystfel/src/image-hdf5.c | 93 ++++++++++++++---------------------------- libcrystfel/src/stream.c | 4 +- 5 files changed, 49 insertions(+), 77 deletions(-) diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c index 7117a62e..3e7c4c80 100644 --- a/libcrystfel/src/datatemplate.c +++ b/libcrystfel/src/datatemplate.c @@ -1296,7 +1296,8 @@ int data_template_panel_to_file_coords(const DataTemplate *dt, } -const char *data_template_panel_name(const DataTemplate *dt, int pn) +const char *data_template_panel_number_to_name(const DataTemplate *dt, + int pn) { if ( pn >= dt->n_panels ) return NULL; return dt->panels[pn].name; @@ -1307,6 +1308,8 @@ int data_template_panel_name_to_number(const DataTemplate *dt, const char *panel_name, int *pn) { + int i; + if ( panel_name == NULL ) return 1; for ( i=0; in_panels; i++ ) { @@ -1344,10 +1347,10 @@ struct detgeom *data_template_to_detgeom(const DataTemplate *dt) if ( dt == NULL ) return NULL; detgeom = malloc(sizeof(struct detgeom)); - if ( detgeom == NULL ) return; + if ( detgeom == NULL ) return NULL; detgeom->panels = malloc(dt->n_panels*sizeof(struct detgeom_panel)); - if ( detgeom->panels == NULL ) return; + if ( detgeom->panels == NULL ) return NULL; detgeom->n_panels = dt->n_panels; @@ -1393,6 +1396,7 @@ int data_template_get_slab_extents(const DataTemplate *dt, { int w, h; char *data_from; + int i; data_from = dt->panels[0].data; @@ -1408,7 +1412,7 @@ int data_template_get_slab_extents(const DataTemplate *dt, if ( p->dim_structure != NULL ) { int j; - for ( j=0; jdim_structure->ndims; j++ ) { + for ( j=0; jdim_structure->num_dims; j++ ) { if ( p->dim_structure->dims[j] == HYSL_PLACEHOLDER ) { /* Not slabby */ return 1; @@ -1416,11 +1420,11 @@ int data_template_get_slab_extents(const DataTemplate *dt, } } - if ( p->file_max_fs > w ) { - w = p->file_max_fs; + if ( p->orig_max_fs > w ) { + w = p->orig_max_fs; } - if ( p->file_max_ss > h ) { - h = p->file_max_ss; + if ( p->orig_max_ss > h ) { + h = p->orig_max_ss; } } @@ -1434,7 +1438,7 @@ int data_template_get_slab_extents(const DataTemplate *dt, /* Return non-zero if pixel fs,ss on panel p is in a bad region * as specified in the geometry file (regions only, not including * masks, NaN/inf, no_index etc */ -int data_template_in_bad_region(DataTemplate *dtempl, +int data_template_in_bad_region(const DataTemplate *dtempl, int pn, double fs, double ss) { double rx, ry; @@ -1442,11 +1446,11 @@ int data_template_in_bad_region(DataTemplate *dtempl, int i; struct panel_template *p; - if ( p >= dtempl->n_panels ) { + if ( pn >= dtempl->n_panels ) { ERROR("Panel index out of range\n"); return 0; } - p = dtempl->panels[pn]; + p = &dtempl->panels[pn]; /* Convert xs and ys, which are in fast scan/slow scan coordinates, * to x and y */ diff --git a/libcrystfel/src/datatemplate.h b/libcrystfel/src/datatemplate.h index a4520ba2..b1771d4f 100644 --- a/libcrystfel/src/datatemplate.h +++ b/libcrystfel/src/datatemplate.h @@ -76,7 +76,7 @@ extern struct detgeom *data_template_to_detgeom(const DataTemplate *dt); extern int data_template_get_slab_extents(const DataTemplate *dt, int *pw, int *ph); -extern int data_template_in_bad_region(DataTemplate *dtempl, +extern int data_template_in_bad_region(const DataTemplate *dtempl, int pn, double fs, double ss); #ifdef __cplusplus diff --git a/libcrystfel/src/detgeom.c b/libcrystfel/src/detgeom.c index 772a620c..392b9b69 100644 --- a/libcrystfel/src/detgeom.c +++ b/libcrystfel/src/detgeom.c @@ -34,6 +34,7 @@ #include #include "detgeom.h" +#include "utils.h" /** diff --git a/libcrystfel/src/image-hdf5.c b/libcrystfel/src/image-hdf5.c index 02b83068..58541574 100644 --- a/libcrystfel/src/image-hdf5.c +++ b/libcrystfel/src/image-hdf5.c @@ -87,14 +87,6 @@ static int load_hdf5_hyperslab(struct panel_template *p, panel_full_path = retrieve_full_path(ev, path_spec); - if ( !check_path_existence(fh, panel_full_path) ) { - ERROR("Cannot find data for panel %s (%s)\n", - p->name, panel_full_path); - free_event(ev); - H5Fclose(fh); - return 1; - } - dh = H5Dopen2(fh, panel_full_path, H5P_DEFAULT); if ( dh < 0 ) { ERROR("Cannot open data for panel %s (%s)\n", @@ -324,7 +316,6 @@ double image_hdf5_get_value(const char *name, const char *filename, hsize_t size[64]; herr_t r; herr_t check; - int check_pe; int dim_flag; int ndims; int i; @@ -352,13 +343,13 @@ double image_hdf5_get_value(const char *name, const char *filename, subst_name = retrieve_full_path(ev, name); - check_pe = check_path_existence(fh, subst_name); - if ( check_pe == 0 ) { - ERROR("No such event-based numeric field '%s'\n", subst_name); + dh = H5Dopen2(fh, subst_name, H5P_DEFAULT); + if ( dh < 0 ) { + ERROR("No such numeric field '%s'\n", subst_name); + H5Fclose(fh); return NAN; } - dh = H5Dopen2(fh, subst_name, H5P_DEFAULT); type = H5Dget_type(dh); class = H5Tget_class(type); @@ -710,14 +701,6 @@ ImageFeatureList *image_hdf5_read_peaks_cxi(const DataTemplate *dtempl, return NULL; } - if ( check_path_existence(fh, subst_name) == 0 ) { - ERROR("Peak path not found: %s:%s", - filename, subst_name); - free(subst_name); - H5Fclose(fh); - return NULL; - } - snprintf(path_n, 1024, "%s/nPeaks", subst_name); snprintf(path_x, 1024, "%s/peakXPosRaw", subst_name); snprintf(path_y, 1024, "%s/peakYPosRaw", subst_name); @@ -808,14 +791,6 @@ ImageFeatureList *image_hdf5_read_peaks_hdf5(const DataTemplate *dtempl, return NULL; } - if ( check_path_existence(fh, subst_name) == 0 ) { - ERROR("Peak path not found: %s:%s", - filename, subst_name); - free(subst_name); - H5Fclose(fh); - return NULL; - } - dh = H5Dopen2(fh, subst_name, H5P_DEFAULT); free(subst_name); if ( dh < 0 ) { @@ -924,7 +899,6 @@ static herr_t parse_file_event_structure(hid_t loc_id, char *name, char *substituted_path; char *ph_loc; char *truncated_path; - htri_t check; herr_t herrt_iterate, herrt_info; struct H5O_info_t object_info; @@ -956,49 +930,42 @@ static herr_t parse_file_event_structure(hid_t loc_id, char *name, herrt_iterate = 0; herrt_info = 0; - check = check_path_existence(pp->fh, truncated_path); - if ( check == 0 ) { - pop_path_entry_from_event(pp->curr_event); - return 0; - } else { + herrt_info = H5Oget_info_by_name(pp->fh, truncated_path, + &object_info, H5P_DEFAULT); + if ( herrt_info < 0 ) { + free(truncated_path); + free(substituted_path); + return -1; + } - herrt_info = H5Oget_info_by_name(pp->fh, truncated_path, - &object_info, H5P_DEFAULT); - if ( herrt_info < 0 ) { + if ( pp->curr_event->path_length == pp->path_dim + && object_info.type == H5O_TYPE_DATASET ) + { + + int fail_append; + + fail_append = append_event_to_event_list(pp->ev_list, + pp->curr_event); + if ( fail_append ) { free(truncated_path); free(substituted_path); return -1; } - if ( pp->curr_event->path_length == pp->path_dim - && object_info.type == H5O_TYPE_DATASET ) - { + pop_path_entry_from_event(pp->curr_event); + return 0; - int fail_append; - - fail_append = append_event_to_event_list(pp->ev_list, - pp->curr_event); - if ( fail_append ) { - free(truncated_path); - free(substituted_path); - return -1; - } - - pop_path_entry_from_event(pp->curr_event); - return 0; - - } else { + } else { - pp->path = substituted_path; + pp->path = substituted_path; - if ( object_info.type == H5O_TYPE_GROUP ) { + if ( object_info.type == H5O_TYPE_GROUP ) { - herrt_iterate = H5Literate_by_name(pp->fh, - truncated_path, H5_INDEX_NAME, - H5_ITER_NATIVE, NULL, - (H5L_iterate_t)parse_file_event_structure, - (void *)pp, H5P_DEFAULT); - } + herrt_iterate = H5Literate_by_name(pp->fh, + truncated_path, H5_INDEX_NAME, + H5_ITER_NATIVE, NULL, + (H5L_iterate_t)parse_file_event_structure, + (void *)pp, H5P_DEFAULT); } } diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c index b8433f31..7ddb6474 100644 --- a/libcrystfel/src/stream.c +++ b/libcrystfel/src/stream.c @@ -905,8 +905,8 @@ static void read_crystal(Stream *st, struct image *image, /** * Read the next chunk from a stream and fill in 'image' */ -int read_chunk(Stream *st, struct image *image, - const DataTemplate *dtempl, StreamFlags srf) +struct image *stream_read_chunk(Stream *st, const DataTemplate *dtempl, + StreamFlags srf) { char line[1024]; char *rval = NULL; -- cgit v1.2.3