From cf4edf303603635833e7fe8d9efa216b35733c3f Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 22 Mar 2021 14:20:38 +0100 Subject: Allow HDF5 path substitution when there are too many placeholder values This allows, for example, masks which have fewer % signs in their HDF5 locations than the main data. --- libcrystfel/src/image-hdf5.c | 32 +++++++++++++++++++++----------- tests/evparse7.c | 10 +++++----- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/libcrystfel/src/image-hdf5.c b/libcrystfel/src/image-hdf5.c index ac987970..16f20e8a 100644 --- a/libcrystfel/src/image-hdf5.c +++ b/libcrystfel/src/image-hdf5.c @@ -7,7 +7,7 @@ * a research centre of the Helmholtz Association. * * Authors: - * 2020 Thomas White + * 2020-2021 Thomas White * 2014-2018 Valerio Mariani * * This file is part of CrystFEL. @@ -227,7 +227,7 @@ static int imh_num_path_placeholders(const char *pattern) * * Not part of public API. Not "static" for testing. */ -char *substitute_path(const char *ev, const char *pattern) +char *substitute_path(const char *ev, const char *pattern, int skip_ok) { char **plvals; int n_plvals; @@ -243,14 +243,23 @@ char *substitute_path(const char *ev, const char *pattern) return NULL; } + /* tag_1334/wibble1//3/6 */ plvals = read_path_parts(ev, &n_plvals); if ( plvals == NULL ) return NULL; + /* /data/%/image_data/%/rawpixels */ n_pl_exp = imh_num_path_placeholders(pattern); - if ( n_plvals != n_pl_exp ) { - ERROR("Wrong number of path placeholders: " - "'%s' (%i) into '%s' (%i)\n", + if ( n_plvals < n_pl_exp ) { + ERROR("Event ID does not have enough path placeholder values: " + "event ID '%s' (%i) into pattern '%s' (%i)\n", + ev, n_plvals, pattern, n_pl_exp); + return NULL; + } + + if ( (n_plvals > n_pl_exp) && !skip_ok ) { + ERROR("Event ID has too many path placeholder values: " + "event ID '%s' (%i) into pattern '%s' (%i)\n", ev, n_plvals, pattern, n_pl_exp); return NULL; } @@ -284,7 +293,7 @@ char *substitute_path(const char *ev, const char *pattern) subs[pl_pos-pattern] = '\0'; start = pl_pos+1; - for ( i=0; ipeak_list); + subst_name = substitute_path(event, dtempl->peak_list, 0); if ( subst_name == NULL ) { ERROR("Invalid peak path %s\n", subst_name); return NULL; @@ -1107,7 +1117,7 @@ ImageFeatureList *image_hdf5_read_peaks_hdf5(const DataTemplate *dtempl, return NULL; } - subst_name = substitute_path(event, dtempl->peak_list); + subst_name = substitute_path(event, dtempl->peak_list, 0); if ( subst_name == NULL ) { ERROR("Invalid peak path: '%s' '%s'\n", event, dtempl->peak_list); @@ -1571,7 +1581,7 @@ char **image_hdf5_expand_frames(const DataTemplate *dtempl, int j; struct panel_template *p = &dtempl->panels[0]; - path = substitute_path(path_evs[i], p->data); + path = substitute_path(path_evs[i], p->data, 0); if ( path == NULL ) { ERROR("Path substitution failed during " "expansion of '%s' with partial event " diff --git a/tests/evparse7.c b/tests/evparse7.c index 26f2dc41..5817ce8e 100644 --- a/tests/evparse7.c +++ b/tests/evparse7.c @@ -3,11 +3,11 @@ * * Check that event string parsing works * - * Copyright © 2020 Deutsches Elektronen-Synchrotron DESY, - * a research centre of the Helmholtz Association. + * Copyright © 2020-2021 Deutsches Elektronen-Synchrotron DESY, + * a research centre of the Helmholtz Association. * * Authors: - * 2020 Thomas White + * 2020-2021 Thomas White * * This file is part of CrystFEL. * @@ -30,14 +30,14 @@ #include #include -extern char *substitute_path(const char *ev, const char *pattern); +extern char *substitute_path(const char *ev, const char *pattern, int skip_ok); int main(int argc, char *argv[]) { char *subs; subs = substitute_path("cc/data123/bb//234/59", - "/data/%/test/%/%"); + "/data/%/test/%/%", 0); if ( subs == NULL ) { printf("substitute_path() failed\n"); -- cgit v1.2.3