diff options
author | Thomas White <taw@physics.org> | 2020-05-25 15:01:58 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2020-07-29 18:42:57 +0200 |
commit | aab8403884c4731f7365796de8f53315f4a61616 (patch) | |
tree | 6a7bc45b52c7943220c71de07caba9c681b2567d | |
parent | 23ea67dc03ac19f7a1457ecfdc8d5ee9cac68632 (diff) |
Get rid of imagefile_field_list and stuff_from_stream
The only place this is used is in geoptimiser, to get the
average_camera_length, itself a very bad solution.
-rw-r--r-- | libcrystfel/src/datatemplate.c | 8 | ||||
-rw-r--r-- | libcrystfel/src/datatemplate.h | 3 | ||||
-rw-r--r-- | libcrystfel/src/image.c | 3 | ||||
-rw-r--r-- | libcrystfel/src/image.h | 17 | ||||
-rw-r--r-- | libcrystfel/src/stream.c | 62 | ||||
-rw-r--r-- | src/geoptimiser.c | 31 | ||||
-rw-r--r-- | src/im-sandbox.c | 1 | ||||
-rw-r--r-- | src/indexamajig.c | 39 | ||||
-rw-r--r-- | src/partial_sim.c | 2 | ||||
-rw-r--r-- | src/partialator.c | 3 | ||||
-rw-r--r-- | src/process_image.c | 4 | ||||
-rw-r--r-- | src/process_image.h | 1 |
12 files changed, 62 insertions, 112 deletions
diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c index f0e23ded..60c36358 100644 --- a/libcrystfel/src/datatemplate.c +++ b/libcrystfel/src/datatemplate.c @@ -1270,3 +1270,11 @@ void data_template_file_to_panel_coords(const DataTemplate *dt, *pfs = *pfs - dt->panels[pn].orig_min_fs; *pss = *pss - dt->panels[pn].orig_min_ss; } + + +void data_template_add_copy_header(DataTemplate *dt, + const char *header) +{ + /* FIXME: Add "header" to list of things to copy */ + STATUS("Adding %s\n", header); +} diff --git a/libcrystfel/src/datatemplate.h b/libcrystfel/src/datatemplate.h index 0adcdb0b..ac76c578 100644 --- a/libcrystfel/src/datatemplate.h +++ b/libcrystfel/src/datatemplate.h @@ -59,6 +59,9 @@ extern signed int data_template_find_panel(const DataTemplate *dt, extern void data_template_file_to_panel_coords(const DataTemplate *dt, float *pfs, float *pss); +extern void data_template_add_copy_header(DataTemplate *dt, + const char *header); + #ifdef __cplusplus } #endif diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c index c7d46978..8b73e414 100644 --- a/libcrystfel/src/image.c +++ b/libcrystfel/src/image.c @@ -838,8 +838,7 @@ struct image *image_new() image->detgeom = NULL; image->filename = NULL; image->ev = NULL; - image->copyme = NULL; - image->stuff_from_stream = NULL; + image->copied_headers = NULL; image->avg_clen = -1.0; image->id = 0; image->serial = 0; diff --git a/libcrystfel/src/image.h b/libcrystfel/src/image.h index 90cb823d..1ea0bc35 100644 --- a/libcrystfel/src/image.h +++ b/libcrystfel/src/image.h @@ -44,8 +44,6 @@ struct detector; struct imagefeature; struct sample; struct image; -struct imagefile; -struct imagefile_field_list; #include "utils.h" #include "cell.h" @@ -155,11 +153,8 @@ struct image char *ev; /** @} */ - /** A list of image file headers to copy to the stream */ - const struct imagefile_field_list *copyme; - /** A list of metadata read from the stream */ - struct stuff_from_stream *stuff_from_stream; + char *copied_headers; /** Mean of the camera length values for all panels */ double avg_clen; @@ -235,9 +230,6 @@ extern int imagefile_read(struct imagefile *f, struct image *image, extern int imagefile_read_simple(struct imagefile *f, struct image *image); extern struct hdfile *imagefile_get_hdfile(struct imagefile *f); extern enum imagefile_type imagefile_get_type(struct imagefile *f); -extern void imagefile_copy_fields(struct imagefile *f, - const struct imagefile_field_list *copyme, - FILE *fh, struct event *ev); extern void imagefile_close(struct imagefile *f); extern signed int is_cbf_file(const char *filename); @@ -256,13 +248,6 @@ extern ImageFeatureList *image_read_peaks(const DataTemplate *dtempl, extern struct event_list *image_expand_frames(const DataTemplate *dtempl, const char *filename); -/* Field lists */ -extern struct imagefile_field_list *new_imagefile_field_list(void); -extern void free_imagefile_field_list(struct imagefile_field_list *f); - -extern void add_imagefile_field(struct imagefile_field_list *copyme, - const char *name); - #ifdef __cplusplus } #endif diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c index 8255a711..419acd36 100644 --- a/libcrystfel/src/stream.c +++ b/libcrystfel/src/stream.c @@ -1144,55 +1144,6 @@ static void read_crystal(Stream *st, struct image *image, StreamReadFlags srf) } -void free_stuff_from_stream(struct stuff_from_stream *sfs) -{ - int i; - if ( sfs == NULL ) return; - for ( i=0; i<sfs->n_fields; i++ ) { - free(sfs->fields[i]); - } - free(sfs->fields); - free(sfs); -} - - -static int read_and_store_field(struct image *image, const char *line) -{ - char **new_fields; - char *nf; - - if ( image->stuff_from_stream == NULL ) { - image->stuff_from_stream = - malloc(sizeof(struct stuff_from_stream)); - if ( image->stuff_from_stream == NULL) { - ERROR("Failed reading entries from stream\n"); - return 1; - } - image->stuff_from_stream->fields = NULL; - image->stuff_from_stream->n_fields = 0; - } - - new_fields = realloc(image->stuff_from_stream->fields, - (1+image->stuff_from_stream->n_fields)* - sizeof(char *)); - if ( new_fields == NULL ) { - ERROR("Failed reading entries from stream\n"); - return 1; - } - image->stuff_from_stream->fields = new_fields; - - nf = strdup(line); - if ( nf == NULL ) { - ERROR("Failed to allocate field from stream\n"); - return 1; - } - image->stuff_from_stream->fields[image->stuff_from_stream->n_fields] = nf; - image->stuff_from_stream->n_fields++; - - return 0; -} - - /** * Read the next chunk from a stream and fill in 'image' */ @@ -1210,7 +1161,7 @@ int read_chunk_2(Stream *st, struct image *image, StreamReadFlags srf) image->crystals = NULL; image->n_crystals = 0; image->ev = NULL; - image->stuff_from_stream = NULL; + image->copied_headers = NULL; if ( (srf & STREAM_READ_REFLECTIONS) || (srf & STREAM_READ_UNITCELL) ) { srf |= STREAM_READ_CRYSTALS; @@ -1291,17 +1242,6 @@ int read_chunk_2(Stream *st, struct image *image, StreamReadFlags srf) } } - if ( strstr(line, " = ") != NULL ) { - - int fail; - - fail = read_and_store_field(image, line); - if ( fail ) { - ERROR("Failed to read fields from stream.\n"); - return 1; - } - } - if ( (srf & STREAM_READ_PEAKS) && strcmp(line, PEAK_LIST_START_MARKER) == 0 ) { diff --git a/src/geoptimiser.c b/src/geoptimiser.c index cae2ae4e..ec4fbcd4 100644 --- a/src/geoptimiser.c +++ b/src/geoptimiser.c @@ -219,21 +219,22 @@ static Reflection *find_closest_reflection(struct image *image, static double get_average_clen(struct image *image) { int i; - struct stuff_from_stream *stuff = image->stuff_from_stream; - - if ( stuff == NULL ) { - ERROR("No 'stuff' from stream!\n"); - return -1.0; - } - - for ( i=0; i<stuff->n_fields; i++ ) { - - if ( strncmp(stuff->fields[i], "average_camera_length = ", - 24) == 0 ) - { - return atof(stuff->fields[i]+24); - } - } + // FIXME! + // struct stuff_from_stream *stuff = image->stuff_from_stream; + // + // if ( stuff == NULL ) { + // ERROR("No 'stuff' from stream!\n"); + // return -1.0; + // } + // + // for ( i=0; i<stuff->n_fields; i++ ) { + // + // if ( strncmp(stuff->fields[i], "average_camera_length = ", + // 24) == 0 ) + // { + // return atof(stuff->fields[i]+24); + // } + // } ERROR("Failed to recover average camera length from stream file\n"); return -1.0; diff --git a/src/im-sandbox.c b/src/im-sandbox.c index c7840f94..660c2ae1 100644 --- a/src/im-sandbox.c +++ b/src/im-sandbox.c @@ -415,7 +415,6 @@ static int run_work(const struct index_args *iargs, Stream *st, time_accounts_set(taccs, TACC_FINALCLEANUP); cleanup_indexing(iargs->ipriv); - free_imagefile_field_list(iargs->copyme); cell_free(iargs->cell); if ( sb->profile ) time_accounts_print(taccs); time_accounts_free(taccs); diff --git a/src/indexamajig.c b/src/indexamajig.c index f4c3af50..bff9e90f 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -92,6 +92,8 @@ struct indexamajig_arguments int if_multi; int if_retry; int profile; /* Whether to do wall-clock time profiling */ + char **copy_headers; + int n_copy_headers; TakeTwoOptions **taketwo_opts_ptr; FelixOptions **felix_opts_ptr; @@ -107,6 +109,21 @@ static void show_version(FILE *fh, struct argp_state *state) } +static void add_copy_header(struct indexamajig_arguments *args, + const char *header) +{ + char **new_copy_headers = realloc(args->copy_headers, + (args->n_copy_headers+1)*sizeof(char *)); + if ( new_copy_headers == NULL ) { + ERROR("Failed to add copy header '%s'\n", header); + return; + } + + args->copy_headers = new_copy_headers; + args->copy_headers[args->n_copy_headers++] = strdup(header); +} + + static error_t parse_arg(int key, char *arg, struct argp_state *state) { float tmp; @@ -525,7 +542,7 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state) break; case 602 : - add_imagefile_field(args->iargs.copyme, arg); + add_copy_header(args, arg); break; case 603 : @@ -587,6 +604,8 @@ int main(int argc, char *argv[]) args.if_refine = 1; args.if_checkcell = 1; args.profile = 0; + args.copy_headers = NULL; + args.n_copy_headers = 0; args.taketwo_opts_ptr = &taketwo_opts; args.felix_opts_ptr = &felix_opts; args.xgandalf_opts_ptr = &xgandalf_opts; @@ -618,7 +637,6 @@ int main(int argc, char *argv[]) args.iargs.dtempl = NULL; args.iargs.peaks = PEAK_ZAEF; args.iargs.half_pixel_shift = 1; - args.iargs.copyme = NULL; args.iargs.pk_inn = -1.0; args.iargs.pk_mid = -1.0; args.iargs.pk_out = -1.0; @@ -634,11 +652,6 @@ int main(int argc, char *argv[]) args.iargs.min_peaks = 0; args.iargs.overpredict = 0; args.iargs.wait_for_file = 0; - args.iargs.copyme = new_imagefile_field_list(); - if ( args.iargs.copyme == NULL ) { - ERROR("Couldn't allocate HDF5 field list.\n"); - return 1; - } args.iargs.ipriv = NULL; /* No default */ args.iargs.int_meth = integration_method("rings-nocen-nosat-nograd", NULL); args.iargs.push_res = +INFINITY; @@ -759,8 +772,9 @@ int main(int argc, char *argv[]) {NULL, 0, 0, OPTION_DOC, "Output options:", 6}, {"no-non-hits-in-stream", 601, NULL, OPTION_NO_USAGE, "Don't include non-hits in " "stream (see --min-peaks)"}, - {"copy-hdf5-field", 602, "f", OPTION_NO_USAGE, "Put the value of this HDF5 field " - "into the stream"}, + {"copy-hdf5-field", 602, "f", OPTION_HIDDEN, NULL}, + {"copy-header", 602, "f", OPTION_NO_USAGE, "Put the value of this image header " + "field into the stream"}, {"no-peaks-in-stream", 603, NULL, OPTION_NO_USAGE, "Don't put peak search results " "in stream"}, {"no-refls-in-stream", 604, NULL, OPTION_NO_USAGE, "Don't put integration results " @@ -831,6 +845,12 @@ int main(int argc, char *argv[]) return 1; } + /* Add any headers we need to copy */ + for ( r=0; r<args.n_copy_headers; r++ ) { + data_template_add_copy_header(args.iargs.dtempl, + args.copy_headers[r]); + } + /* If no integration radii were given, apply the defaults */ if ( args.iargs.ir_inn < 0 ) { STATUS("WARNING: You did not specify --int-radius.\n"); @@ -1008,7 +1028,6 @@ int main(int argc, char *argv[]) fh, st, tmpdir, args.serial_start, zmq_address, timeout, args.profile); - free_imagefile_field_list(args.iargs.copyme); cell_free(args.iargs.cell); free(args.prefix); free(args.temp_location); diff --git a/src/partial_sim.c b/src/partial_sim.c index 32263cad..9e774431 100644 --- a/src/partial_sim.c +++ b/src/partial_sim.c @@ -899,7 +899,7 @@ int main(int argc, char *argv[]) image.spectrum = spectrum_generate_gaussian(image.lambda, image.bw); image.filename = "dummy.h5"; image.ev = "(none)"; - image.copyme = NULL; + image.copied_headers = NULL; image.crystals = NULL; image.n_crystals = 0; image.indexed_by = INDEXING_SIMULATION; diff --git a/src/partialator.c b/src/partialator.c index 47a752b0..032eb0d9 100644 --- a/src/partialator.c +++ b/src/partialator.c @@ -1389,9 +1389,6 @@ int main(int argc, char *argv[]) return 1; } - free_stuff_from_stream(cur.stuff_from_stream); - cur.stuff_from_stream = NULL; - for ( i=0; i<cur.n_crystals; i++ ) { Crystal *cr; diff --git a/src/process_image.c b/src/process_image.c index bca2a7f2..60e3edbc 100644 --- a/src/process_image.c +++ b/src/process_image.c @@ -201,7 +201,8 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, image = file_wait_open_read(pargs->filename, pargs->event, iargs->dtempl, sb_shared, taccs, last_task, - iargs->wait_for_file, cookie); + iargs->wait_for_file, + cookie); if ( image == NULL ) { if ( iargs->wait_for_file != 0 ) { pthread_mutex_lock(&sb_shared->totals_lock); @@ -213,7 +214,6 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs, } image->serial = serial; - image->copyme = iargs->copyme; /* Take snapshot of image before applying horrible noise filters */ time_accounts_set(taccs, TACC_FILTER); diff --git a/src/process_image.h b/src/process_image.h index 908a2e06..354641c3 100644 --- a/src/process_image.h +++ b/src/process_image.h @@ -80,7 +80,6 @@ struct index_args float min_snr_peak_pix; float min_sig; float min_peak_over_neighbour; - struct imagefile_field_list *copyme; int integrate_saturated; int use_saturated; int no_revalidate; |