diff options
Diffstat (limited to 'src/merge.c')
-rw-r--r-- | src/merge.c | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/src/merge.c b/src/merge.c index da333f6a..1dec13fd 100644 --- a/src/merge.c +++ b/src/merge.c @@ -3,11 +3,11 @@ * * Parallel weighted merging of intensities * - * Copyright © 2012-2015 Deutsches Elektronen-Synchrotron DESY, + * Copyright © 2012-2018 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: - * 2010-2015 Thomas White <taw@physics.org> + * 2010-2018 Thomas White <taw@physics.org> * * This file is part of CrystFEL. * @@ -46,6 +46,7 @@ #include "cell.h" #include "utils.h" #include "reflist.h" +#include "reflist-utils.h" #include "cell-utils.h" @@ -89,6 +90,17 @@ static void *create_merge_job(void *vqargs) } +static int alloc_contribs(struct reflection_contributions *c) +{ + c->contribs = realloc(c->contribs, c->max_contrib*sizeof(Reflection *)); + c->contrib_crystals = realloc(c->contrib_crystals, + c->max_contrib*sizeof(Crystal *)); + if ( c->contribs == NULL ) return 1; + if ( c->contrib_crystals == NULL ) return 1; + return 0; +} + + /* Find reflection hkl in 'list', creating it if it's not there, under * protection of 'lock' and returning a locked reflection */ static Reflection *get_locked_reflection(RefList *list, pthread_rwlock_t *lock, @@ -109,12 +121,31 @@ static Reflection *get_locked_reflection(RefList *list, pthread_rwlock_t *lock, * So, we must check again */ f = find_refl(list, h, k, l); if ( f == NULL ) { + + struct reflection_contributions *c; + f = add_refl(list, h, k, l); lock_reflection(f); pthread_rwlock_unlock(lock); set_intensity(f, 0.0); set_temp1(f, 0.0); set_temp2(f, 0.0); + + c = malloc(sizeof(struct reflection_contributions)); + if ( c != NULL ) { + c->n_contrib = 0; + c->max_contrib = 32; + c->contribs = NULL; + c->contrib_crystals = NULL; + if ( alloc_contribs(c) ) { + set_contributions(f, NULL); + } else { + set_contributions(f, c); + } + } else { + set_contributions(f, NULL); + } + } else { /* Someone else created it */ lock_reflection(f); @@ -160,6 +191,7 @@ static void run_merge_job(void *vwargs, int cookie) signed int h, k, l; double mean, sumweight, M2, temp, delta, R; double corr, res, w; + struct reflection_contributions *c; if ( get_partiality(refl) < MIN_PART_MERGE ) continue; @@ -212,6 +244,18 @@ static void run_merge_job(void *vwargs, int cookie) set_temp2(f, M2 + sumweight * delta * R); set_temp1(f, temp); set_redundancy(f, get_redundancy(f)+1); + + /* Record this contribution */ + c = get_contributions(f); + if ( c != NULL ) { + c->contribs[c->n_contrib] = refl; + c->contrib_crystals[c->n_contrib++] = cr; + if ( c->n_contrib == c->max_contrib ) { + c->max_contrib += 64; + alloc_contribs(c); + } + } /* else, too bad! */ + unlock_reflection(f); wargs->n_reflections++; @@ -291,9 +335,18 @@ RefList *merge_intensities(Crystal **crystals, int n, int n_threads, Reflection *r2; get_indices(refl, &h, &k, &l); - r2 = add_refl(full2, h, k, l); + r2 = add_refl(full2, h, k, l); copy_data(r2, refl); + } else { + + /* We do not need the contribution list any more */ + struct reflection_contributions *c; + c = get_contributions(refl); + free(c->contribs); + free(c->contrib_crystals); + free(c); + } } |