aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/geoptimiser.c2
-rw-r--r--src/im-sandbox.c153
-rw-r--r--src/im-zmq.c28
-rw-r--r--src/im-zmq.h17
-rw-r--r--src/indexamajig.c65
-rw-r--r--src/partial_sim.c5
-rw-r--r--src/partialator.c12
-rw-r--r--src/post-refinement.c8
-rw-r--r--src/process_hkl.c2
-rw-r--r--src/process_image.c314
-rw-r--r--src/process_image.h8
-rw-r--r--src/whirligig.c2
12 files changed, 186 insertions, 430 deletions
diff --git a/src/geoptimiser.c b/src/geoptimiser.c
index 73e37249..cae2ae4e 100644
--- a/src/geoptimiser.c
+++ b/src/geoptimiser.c
@@ -789,7 +789,7 @@ static int compute_pixel_displacements(struct image *images, int n_images,
"(panel %s), image %s %s\n",
imfe->fs, imfe->ss, gp->p->name,
images[cp].filename,
- get_event_string(images[cp].event));
+ images[cp].ev);
return r;
}
diff --git a/src/im-sandbox.c b/src/im-sandbox.c
index fb4a9674..c7840f94 100644
--- a/src/im-sandbox.c
+++ b/src/im-sandbox.c
@@ -113,7 +113,7 @@ struct get_pattern_ctx
{
FILE *fh;
int use_basename;
- struct detector *det;
+ const DataTemplate *dtempl;
const char *prefix;
char *filename;
struct event_list *events; /* FIXME: Deprecated */
@@ -251,107 +251,51 @@ static char *read_prefixed_filename(struct get_pattern_ctx *gpctx, char **event)
}
-static struct filename_plus_event *get_pattern(struct get_pattern_ctx *gpctx)
+/* Return 0 for "no more" */
+static int get_pattern(struct get_pattern_ctx *gpctx,
+ char **pfilename, char **pevent)
{
char *filename;
char *evstr;
- /* If single-event geometry, just return next filename */
- if ( !multi_event_geometry(gpctx->det) )
- {
- struct filename_plus_event *fne;
- fne = malloc(sizeof(struct filename_plus_event));
- if ( fne == NULL ) return NULL;
- fne->filename = read_prefixed_filename(gpctx, NULL);
- if ( fne->filename == NULL ) {
- free(fne);
- return NULL;
- }
- fne->ev = NULL;
- return fne;
- }
-
- /* Ok, multi-event geometry. Is an event available already? */
+ /* Is an event available already? */
if ( (gpctx->events != NULL)
&& (gpctx->event_index < gpctx->events->num_events) )
{
- struct filename_plus_event *fne;
- fne = malloc(sizeof(struct filename_plus_event));
- fne->filename = strdup(gpctx->filename);
- fne->ev = copy_event(gpctx->events->events[gpctx->event_index++]);
-
- return fne;
+ *pfilename = strdup(gpctx->filename);
+ *pevent = get_event_string(gpctx->events->events[gpctx->event_index++]);
+ return 1;
}
/* No events in list. Time to top it up */
filename = read_prefixed_filename(gpctx, &evstr);
/* Nothing left in file -> we're done */
- if ( filename == NULL ) return NULL;
-
- /* Muppet check */
- if ( is_cbf_file(filename) == 1 ) {
- ERROR("Your geometry file is for a multi-event format, but "
- "this file is in CBF format.\n");
- ERROR("Your geometry file probably needs to be changed.\n");
- return NULL;
- }
+ if ( filename == NULL ) return 0;
/* Does the line from the input file contain an event ID?
- * If so, just parse it and sent it straight back. */
+ * If so, just send it straight back. */
if ( evstr != NULL ) {
+ *pfilename = strdup(filename);
+ *pevent = strdup(evstr);
+ return 1;
+ }
- /* Make an event list with only one item */
- struct event *ev = get_event_from_event_string(evstr);
- if ( ev == NULL ) {
- ERROR("Bad event descriptor: '%s'\n", evstr);
- return NULL;
- } else {
- struct filename_plus_event *fne;
- fne = malloc(sizeof(struct filename_plus_event));
- fne->filename = filename;
- fne->ev = ev;
- return fne;
- }
-
- } else {
-
- /* Enumerate all the events in the file and then send the
- * first one back */
- struct hdfile *hdfile;
- struct filename_plus_event *fne;
-
- hdfile = hdfile_open(filename);
- if ( hdfile == NULL ) {
- ERROR("Failed to open %s\n", filename);
- return NULL;
- }
-
- if ( gpctx->events != NULL ) {
- free_event_list(gpctx->events);
- }
-
- gpctx->events = fill_event_list(hdfile, gpctx->det);
- if ( gpctx->events == NULL ) {
- ERROR("Failed to get event list.\n");
- return NULL;
- }
-
- hdfile_close(hdfile);
-
- /* Save filename for next time */
- if ( gpctx->filename != NULL ) {
- free(gpctx->filename);
- }
- gpctx->filename = filename;
+ free_event_list(gpctx->events);
+ gpctx->events = image_expand_frames(gpctx->dtempl, filename);
+ if ( gpctx->events == NULL ) {
+ ERROR("Failed to get event list.\n");
+ return 0;
+ }
- gpctx->event_index = 0;
- fne = malloc(sizeof(struct filename_plus_event));
- fne->filename = strdup(gpctx->filename);
- fne->ev = copy_event(gpctx->events->events[gpctx->event_index++]);
- return fne;
+ /* Save filename for next time */
+ free(gpctx->filename);
+ gpctx->filename = filename;
- }
+ gpctx->event_index = 0;
+ *pfilename = strdup(gpctx->filename);
+ *pevent = get_event_string(gpctx->events->events[gpctx->event_index++]);
+ return 1;
}
@@ -398,7 +342,6 @@ static int run_work(const struct index_args *iargs, Stream *st,
char filename[MAX_EV_LEN];
char event_str[MAX_EV_LEN];
int ser;
- struct event *ev;
int r;
if ( !sb->zmq ) {
@@ -444,31 +387,16 @@ static int run_work(const struct index_args *iargs, Stream *st,
if ( r != 3 ) continue;
- pargs.filename_p_e = initialize_filename_plus_event();
- pargs.filename_p_e->filename = strdup(filename);
-
- if ( strcmp(event_str, "(none)") != 0 ) {
-
- ev = get_event_from_event_string(event_str);
- if ( ev == NULL ) {
- ERROR("Bad event string '%s'\n", event_str);
- continue;
- }
- pargs.filename_p_e->ev = ev;
-
- } else {
+ pargs.filename = strdup(filename);
+ pargs.event = strdup(event_str);
- pargs.filename_p_e->ev = NULL;
-
- }
pargs.msgpack_obj = NULL;
} else {
pargs.msgpack_obj = im_zmq_fetch(zmqstuff);
- pargs.filename_p_e = initialize_filename_plus_event();
- pargs.filename_p_e->filename = strdup("(from ZMQ)");
- pargs.filename_p_e->ev = NULL;
+ pargs.filename = strdup("(from ZMQ)");
+ pargs.event = NULL;
ser = 0; /* FIXME */
}
@@ -477,9 +405,7 @@ static int run_work(const struct index_args *iargs, Stream *st,
process_image(iargs, &pargs, st, cookie, tmpdir, ser,
sb->shared, taccs, sb->shared->last_task[cookie]);
- if ( !sb->zmq ) {
- free_filename_plus_event(pargs.filename_p_e);
- } else {
+ if ( sb->zmq ) {
im_zmq_clean(zmqstuff);
}
@@ -489,8 +415,6 @@ static int run_work(const struct index_args *iargs, Stream *st,
time_accounts_set(taccs, TACC_FINALCLEANUP);
cleanup_indexing(iargs->ipriv);
- free_detector_geometry(iargs->det);
- free(iargs->hdf5_peak_path);
free_imagefile_field_list(iargs->copyme);
cell_free(iargs->cell);
if ( sb->profile ) time_accounts_print(taccs);
@@ -743,7 +667,6 @@ static void start_worker_process(struct sandbox *sb, int slot)
close_stream(st);
free(tmp);
- free(sb->iargs->beam->photon_energy_from);
munmap(sb->shared, sizeof(struct sb_shm));
@@ -861,19 +784,15 @@ static int fill_queue(struct get_pattern_ctx *gpctx, struct sandbox *sb)
while ( sb->shared->n_events < QUEUE_SIZE ) {
- struct filename_plus_event *ne;
+ char *filename;
char *evstr;
- ne = get_pattern(gpctx);
- if ( ne == NULL ) return 1; /* No more */
+ if ( !get_pattern(gpctx, &filename, &evstr) ) return 1;
memset(sb->shared->queue[sb->shared->n_events], 0, MAX_EV_LEN);
- evstr = get_event_string(ne->ev),
snprintf(sb->shared->queue[sb->shared->n_events++], MAX_EV_LEN,
- "%s %s %i", ne->filename, evstr, sb->serial++);
- free(evstr);
+ "%s %s %i", filename, evstr, sb->serial++);
sem_post(sb->queue_sem);
- free_filename_plus_event(ne);
}
return 0;
@@ -1103,7 +1022,7 @@ int create_sandbox(struct index_args *iargs, int n_proc, char *prefix,
gpctx.fh = fh;
gpctx.use_basename = config_basename;
- gpctx.det = iargs->det;
+ gpctx.dtempl = iargs->dtempl;
gpctx.prefix = prefix;
gpctx.filename = NULL;
gpctx.events = NULL;
diff --git a/src/im-zmq.c b/src/im-zmq.c
index da0a5fff..f8743dbb 100644
--- a/src/im-zmq.c
+++ b/src/im-zmq.c
@@ -408,7 +408,7 @@ static double *find_msgpack_data(msgpack_object *obj, int *width, int *height)
}
-static double *zero_array(struct detector *det, int *dw, int *dh)
+static double *zero_array(DataTemplate *dtempl, int *dw, int *dh)
{
int max_fs = 0;
int max_ss = 0;
@@ -446,17 +446,14 @@ static double *zero_array(struct detector *det, int *dw, int *dh)
* ...
* }
*/
-int unpack_msgpack_data(msgpack_object *obj, struct image *image,
- int no_image_data)
+struct image *unpack_msgpack_data(msgpack_object *obj,
+ const DataTemplate *dtempl,
+ int no_image_data)
{
+ struct image *image;
int data_width, data_height;
double *data;
- if ( image->det == NULL ) {
- ERROR("Geometry not available.\n");
- return 1;
- }
-
if ( obj == NULL ) {
ERROR("No MessagePack object!\n");
return 1;
@@ -469,20 +466,21 @@ int unpack_msgpack_data(msgpack_object *obj, struct image *image,
return 1;
}
} else {
- data = zero_array(image->det, &data_width, &data_height);
+ data = zero_array(dtempl, &data_width, &data_height);
}
+ image = image_new();
+ if ( image == NULL ) return 1;
+
if ( unpack_slab(image, data, data_width, data_height) ) {
ERROR("Failed to unpack data slab.\n");
return 1;
}
- if ( image->beam != NULL ) {
- im_zmq_fill_in_beam_parameters(image->beam, image);
- if ( image->lambda > 1000 ) {
- ERROR("Warning: Missing or nonsensical wavelength "
- "(%e m).\n", image->lambda);
- }
+ im_zmq_fill_in_beam_parameters(image->beam, image);
+ if ( image->lambda > 1000 ) {
+ ERROR("Warning: Missing or nonsensical wavelength "
+ "(%e m).\n", image->lambda);
}
im_zmq_fill_in_clen(image->det);
fill_in_adu(image);
diff --git a/src/im-zmq.h b/src/im-zmq.h
index bc6175af..270a7c3a 100644
--- a/src/im-zmq.h
+++ b/src/im-zmq.h
@@ -54,8 +54,9 @@ extern ImageFeatureList *get_peaks_msgpack(msgpack_object *obj,
const DataTemplate *dtempl,
int half_pixel_shift);
-extern int unpack_msgpack_data(msgpack_object *obj, struct image *image,
- int no_image_data);
+extern struct image *unpack_msgpack_data(msgpack_object *obj,
+ DataTemplate *dtempl,
+ int no_image_data);
#else /* defined(HAVE_MSGPACK) && defined(HAVE_ZMQ) */
@@ -67,11 +68,15 @@ static UNUSED void im_zmq_shutdown(struct im_zmq *z) { return; }
static UNUSED void *im_zmq_fetch(struct im_zmq *z) { return NULL; }
-static UNUSED int get_peaks_msgpack(void *obj, struct image *image,
- int half_pixel_shift) { return 0; }
+static UNUSED int get_peaks_msgpack(void *obj,
+ const DataTemplate *dtempl,
+ int half_pixel_shift)
+{ return 0; }
-static UNUSED int unpack_msgpack_data(void *obj, struct image *image,
- int no_image_data) { return 1; }
+static UNUSED struct image *unpack_msgpack_data(void *obj,
+ const DataTemplate *dtempl,
+ int no_image_data)
+{ return 1; }
#endif /* defined(HAVE_MSGPACK) && defined(HAVE_ZMQ) */
diff --git a/src/indexamajig.c b/src/indexamajig.c
index e44f9576..f4c3af50 100644
--- a/src/indexamajig.c
+++ b/src/indexamajig.c
@@ -68,27 +68,6 @@
#include "datatemplate.h"
-static void add_geom_beam_stuff_to_field_list(struct imagefile_field_list *copyme,
- struct detector *det,
- struct beam_params *beam)
-{
- int i;
-
- for ( i=0; i<det->n_panels; i++ ) {
-
- struct panel *p = &det->panels[i];
-
- if ( p->clen_from != NULL ) {
- add_imagefile_field(copyme, p->clen_from);
- }
- }
-
- if ( beam->photon_energy_from != NULL ) {
- add_imagefile_field(copyme, beam->photon_energy_from);
- }
-}
-
-
struct indexamajig_arguments
{
struct index_args iargs; /* These are the options that will be
@@ -107,7 +86,6 @@ struct indexamajig_arguments
int no_image_data;
int serial_start;
char *temp_location;
- char *command_line_peak_path;
int if_refine;
int if_checkcell;
int if_peaks;
@@ -251,8 +229,8 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
break;
case 304 :
- free(args->command_line_peak_path);
- args->command_line_peak_path = strdup(arg);
+ ERROR("The option --hdf5-peak-path is no longer used.\n");
+ ERROR("Set the peak path in the geometry file.\n");
break;
case 305 :
@@ -582,7 +560,6 @@ int main(int argc, char *argv[])
char *tmpdir; /* e.g. /tmp/indexamajig.12345 */
char *rn; /* e.g. /home/taw/indexing */
int r;
- struct beam_params beam;
char *zmq_address = NULL;
int timeout = 240;
TakeTwoOptions *taketwo_opts = NULL;
@@ -604,7 +581,6 @@ int main(int argc, char *argv[])
args.basename = 0;
args.zmq = 0;
args.serial_start = 1;
- args.command_line_peak_path = NULL;
args.if_peaks = 1;
args.if_multi = 0;
args.if_retry = 1;
@@ -639,10 +615,8 @@ int main(int argc, char *argv[])
args.iargs.min_sig = 11.0;
args.iargs.min_peak_over_neighbour = -INFINITY;
args.iargs.check_hdf5_snr = 0;
- args.iargs.det = NULL;
+ args.iargs.dtempl = NULL;
args.iargs.peaks = PEAK_ZAEF;
- args.iargs.beam = &beam;
- args.iargs.hdf5_peak_path = NULL;
args.iargs.half_pixel_shift = 1;
args.iargs.copyme = NULL;
args.iargs.pk_inn = -1.0;
@@ -849,18 +823,6 @@ int main(int argc, char *argv[])
return 1;
}
- /* Load detector geometry (old API) */
- args.iargs.det = get_detector_geometry_2(args.geom_filename,
- args.iargs.beam,
- &args.iargs.hdf5_peak_path);
- if ( args.iargs.det == NULL ) {
- ERROR("Failed to read detector geometry from '%s'\n",
- args.geom_filename);
- return 1;
- }
- add_geom_beam_stuff_to_field_list(args.iargs.copyme, args.iargs.det,
- args.iargs.beam);
-
/* Load data template (new API) */
args.iargs.dtempl = data_template_new_from_file(args.geom_filename);
if ( args.iargs.dtempl == NULL ) {
@@ -869,21 +831,6 @@ int main(int argc, char *argv[])
return 1;
}
- /* If no peak path from geometry file, use these (but see later) */
- if ( args.iargs.hdf5_peak_path == NULL ) {
- if ( args.iargs.peaks == PEAK_HDF5 ) {
- args.iargs.hdf5_peak_path = strdup("/processing/hitfinder/peakinfo");
- } else if ( args.iargs.peaks == PEAK_CXI ) {
- args.iargs.hdf5_peak_path = strdup("/entry_1/result_1");
- }
- }
-
- /* If an HDF5 peak path was given on the command line, use it */
- if ( args.command_line_peak_path != NULL ) {
- free(args.iargs.hdf5_peak_path);
- args.iargs.hdf5_peak_path = args.command_line_peak_path;
- }
-
/* If no integration radii were given, apply the defaults */
if ( args.iargs.ir_inn < 0 ) {
STATUS("WARNING: You did not specify --int-radius.\n");
@@ -998,7 +945,7 @@ int main(int argc, char *argv[])
}
args.iargs.ipriv = setup_indexing(args.indm_str, args.iargs.cell,
- args.iargs.det, args.iargs.beam,
+ args.iargs.dtempl,
args.iargs.tols, flags,
taketwo_opts,
xgandalf_opts,
@@ -1063,12 +1010,10 @@ int main(int argc, char *argv[])
free_imagefile_field_list(args.iargs.copyme);
cell_free(args.iargs.cell);
- free(args.iargs.beam->photon_energy_from);
free(args.prefix);
free(args.temp_location);
free(tmpdir);
- free_detector_geometry(args.iargs.det);
- free(args.iargs.hdf5_peak_path);
+ data_template_free(args.iargs.dtempl);
close_stream(st);
cleanup_indexing(args.iargs.ipriv);
diff --git a/src/partial_sim.c b/src/partial_sim.c
index 884032b5..32263cad 100644
--- a/src/partial_sim.c
+++ b/src/partial_sim.c
@@ -362,7 +362,6 @@ static void *create_job(void *vqargs)
crystal_free(im.crystals[0]);
free(im.filename);
- free_event(im.event);
} else {
wargs->template_cell = NULL;
@@ -465,7 +464,7 @@ static void finalise_job(void *vqargs, void *vwargs)
int i;
int ret;
- ret = write_chunk(qargs->stream, &wargs->image, NULL, 0, 1, NULL);
+ ret = write_chunk(qargs->stream, &wargs->image, 0, 1);
if ( ret != 0) {
ERROR("WARNING: error writing stream file.\n");
}
@@ -899,12 +898,12 @@ int main(int argc, char *argv[])
image.bw = bandwidth;
image.spectrum = spectrum_generate_gaussian(image.lambda, image.bw);
image.filename = "dummy.h5";
+ image.ev = "(none)";
image.copyme = NULL;
image.crystals = NULL;
image.n_crystals = 0;
image.indexed_by = INDEXING_SIMULATION;
image.serial = 0;
- image.event = NULL;
image.hit = 0;
image.n_indexing_tries = 1;
image.features = NULL;
diff --git a/src/partialator.c b/src/partialator.c
index 246880da..47a752b0 100644
--- a/src/partialator.c
+++ b/src/partialator.c
@@ -254,14 +254,12 @@ static void write_custom_split(struct custom_split *csplit, int dsn,
for ( i=0; i<n_crystals; i++ ) {
const char *fn;
- struct event *ev;
char *evs;
char *id;
int dsn_crystal;
fn = crystal_get_image(crystals[i])->filename;
- ev = crystal_get_image(crystals[i])->event;
- evs = get_event_string(ev);
+ evs = crystal_get_image(crystals[i])->ev;
id = malloc(strlen(evs)+strlen(fn)+2);
if ( id == NULL ) {
@@ -349,14 +347,12 @@ static signed int find_first_crystal(Crystal **crystals, int n_crystals,
for ( i=0; i<n_crystals; i++ ) {
const char *fn;
- struct event *ev;
char *evs;
char *id;
int dsn_crystal;
fn = crystal_get_image(crystals[i])->filename;
- ev = crystal_get_image(crystals[i])->event;
- evs = get_event_string(ev);
+ evs = crystal_get_image(crystals[i])->ev;
id = malloc(strlen(evs)+strlen(fn)+2);
if ( id == NULL ) {
@@ -389,14 +385,12 @@ static void check_csplit(Crystal **crystals, int n_crystals,
for ( i=0; i<n_crystals; i++ ) {
const char *fn;
- struct event *ev;
char *evs;
char *id;
int dsn_crystal;
fn = crystal_get_image(crystals[i])->filename;
- ev = crystal_get_image(crystals[i])->event;
- evs = get_event_string(ev);
+ evs = crystal_get_image(crystals[i])->ev;
id = malloc(strlen(evs)+strlen(fn)+2);
if ( id == NULL ) {
diff --git a/src/post-refinement.c b/src/post-refinement.c
index 16ab41ce..b3ce79c1 100644
--- a/src/post-refinement.c
+++ b/src/post-refinement.c
@@ -336,9 +336,7 @@ void write_test_logs(Crystal *crystal, const RefList *full,
}
if ( cycle == 0 ) {
- char *evstr = get_event_string(image->event);
- fprintf(fh, "Image: %s %s\n", image->filename, evstr);
- free(evstr);
+ fprintf(fh, "Image: %s %s\n", image->filename, image->ev);
}
if ( cycle >= 0 ) {
@@ -393,10 +391,8 @@ void write_specgraph(Crystal *crystal, const RefList *full,
}
if ( cycle == 0 ) {
- char *evstr = get_event_string(image->event);
- fprintf(fh, "Image: %s %s\n", image->filename, evstr);
+ fprintf(fh, "Image: %s %s\n", image->filename, image->ev);
fprintf(fh, "khalf/m 1/d(m) pcalc pobs iteration h k l\n");
- free(evstr);
}
cell = crystal_get_cell(crystal);
diff --git a/src/process_hkl.c b/src/process_hkl.c
index 63c24912..5aadda47 100644
--- a/src/process_hkl.c
+++ b/src/process_hkl.c
@@ -300,7 +300,7 @@ static int merge_crystal(RefList *model, struct image *image, Crystal *cr,
if ( scale <= 0.0 ) return 1;
if ( stat != NULL ) {
fprintf(stat, "%s %s %f %f\n", image->filename,
- get_event_string(image->event), scale, cc);
+ image->ev, scale, cc);
}
} else {
diff --git a/src/process_image.c b/src/process_image.c
index b71fbec3..d529a444 100644
--- a/src/process_image.c
+++ b/src/process_image.c
@@ -44,7 +44,6 @@
#include "hdf5-file.h"
#include "index.h"
#include "peaks.h"
-#include "detector.h"
#include "filters.h"
#include "thread-pool.h"
#include "geometry.h"
@@ -59,7 +58,7 @@
#include "detgeom.h"
-static float **backup_image_data(float **dp, struct detector *det)
+static float **backup_image_data(float **dp, struct detgeom *det)
{
float **bu;
int i;
@@ -87,7 +86,7 @@ static float **backup_image_data(float **dp, struct detector *det)
}
-static void restore_image_data(float **dp, struct detector *det, float **bu)
+static void restore_image_data(float **dp, struct detgeom *det, float **bu)
{
int i;
@@ -101,16 +100,20 @@ static void restore_image_data(float **dp, struct detector *det, float **bu)
}
-static int file_wait_open_read(struct sb_shm *sb_shared, struct image *image,
- TimeAccounts *taccs, char *last_task,
- signed int wait_for_file, int cookie,
- struct imagefile **pimfile)
+static struct image *file_wait_open_read(const char *filename,
+ const char *event,
+ DataTemplate *dtempl,
+ struct sb_shm *sb_shared,
+ TimeAccounts *taccs,
+ char *last_task,
+ signed int wait_for_file,
+ int cookie)
{
signed int file_wait_time = wait_for_file;
int wait_message_done = 0;
int read_retry_done = 0;
int r;
- struct imagefile *imfile;
+ struct image *image;
time_accounts_set(taccs, TACC_WAITFILE);
set_last_task(last_task, "wait for file");
@@ -120,7 +123,7 @@ static int file_wait_open_read(struct sb_shm *sb_shared, struct image *image,
struct stat statbuf;
sb_shared->pings[cookie]++;
- r = stat(image->filename, &statbuf);
+ r = stat(filename, &statbuf);
if ( r ) {
if ( (wait_for_file != 0) && (file_wait_time != 0) ) {
@@ -139,8 +142,8 @@ static int file_wait_open_read(struct sb_shm *sb_shared, struct image *image,
}
- ERROR("File %s not found\n", image->filename);
- return 1;
+ ERROR("File %s not found\n", filename);
+ return NULL;
}
} while ( r );
@@ -150,79 +153,28 @@ static int file_wait_open_read(struct sb_shm *sb_shared, struct image *image,
sb_shared->pings[cookie]++;
do {
- imfile = imagefile_open(image->filename);
- if ( imfile == NULL ) {
- if ( wait_for_file && !read_retry_done ) {
- read_retry_done = 1;
- r = 1;
- STATUS("File '%s' exists but could not be opened."
- " Trying again after 10 seconds.\n",
- image->filename);
- sleep(10);
- continue;
- }
- ERROR("Couldn't open file: %s\n", image->filename);
- return 1;
- }
time_accounts_set(taccs, TACC_HDF5READ);
set_last_task(last_task, "read file");
sb_shared->pings[cookie]++;
- r = imagefile_read(imfile, image, image->event);
- if ( r ) {
+ image = image_read(dtempl, filename, event);
+ if ( image == NULL ) {
if ( wait_for_file && !read_retry_done ) {
read_retry_done = 1;
- imagefile_close(imfile);
STATUS("File '%s' exists but could not be read."
" Trying again after 10 seconds.\n",
- image->filename);
+ filename);
sleep(10);
continue;
}
- ERROR("Couldn't open file: %s\n", image->filename);
- return 1;
+ ERROR("Couldn't open file: %s\n", filename);
+ return NULL;
}
} while ( r );
- *pimfile = imfile;
- return 0;
-}
-
-
-static struct detgeom *detgeom_from_olddet(struct detector *det)
-{
- struct detgeom *dg;
- int i;
-
- dg = malloc(sizeof(struct detgeom));
- if ( dg == NULL ) return NULL;
-
- dg->panels = malloc(det->n_panels*sizeof(struct detgeom_panel));
- if ( dg->panels == NULL ) return NULL;
-
- dg->n_panels = det->n_panels;
-
- for ( i=0; i<det->n_panels; i++ ) {
- dg->panels[i].name = strdup(det->panels[i].name);
- dg->panels[i].cnx = det->panels[i].cnx;
- dg->panels[i].cny = det->panels[i].cny;
- dg->panels[i].cnz = det->panels[i].clen;
- dg->panels[i].pixel_pitch = 1.0/det->panels[i].res;
- dg->panels[i].adu_per_photon = det->panels[i].adu_per_photon;
- dg->panels[i].max_adu = det->panels[i].max_adu;
- dg->panels[i].fsx = det->panels[i].fsx;
- dg->panels[i].fsy = det->panels[i].fsy;
- dg->panels[i].fsz = det->panels[i].fsz;
- dg->panels[i].ssx = det->panels[i].ssx;
- dg->panels[i].ssy = det->panels[i].ssy;
- dg->panels[i].ssz = det->panels[i].ssz;
- dg->panels[i].w = det->panels[i].w;
- dg->panels[i].h = det->panels[i].h;
- }
-
- return dg;
+ return image;
}
@@ -231,8 +183,7 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs,
int serial, struct sb_shm *sb_shared, TimeAccounts *taccs,
char *last_task)
{
- struct imagefile *imfile = NULL;
- struct image image;
+ struct image *image;
int i;
int r;
int ret;
@@ -240,27 +191,17 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs,
float **prefilter;
int any_crystals;
- image.features = NULL;
- image.copyme = iargs->copyme;
- image.id = cookie;
- image.beam = iargs->beam;
- image.det = copy_geom(iargs->det);
- image.crystals = NULL;
- image.n_crystals = 0;
- image.serial = serial;
- image.indexed_by = INDEXING_NONE;
-
- image.filename = pargs->filename_p_e->filename;
- image.event = pargs->filename_p_e->ev;
if ( pargs->msgpack_obj != NULL ) {
set_last_task(last_task, "unpacking messagepack object");
- if ( unpack_msgpack_data(pargs->msgpack_obj, &image,
- iargs->no_image_data) ) return;
+ image = unpack_msgpack_data(pargs->msgpack_obj,
+ iargs->no_image_data);
+ if ( image == NULL ) return;
} else {
- if ( file_wait_open_read(sb_shared, &image, taccs, last_task,
- iargs->wait_for_file, cookie,
- &imfile) )
- {
+ image = file_wait_open_read(pargs->filename, pargs->event,
+ iargs->dtempl,
+ sb_shared, taccs, last_task,
+ iargs->wait_for_file, cookie);
+ if ( image == NULL ) {
if ( iargs->wait_for_file != 0 ) {
pthread_mutex_lock(&sb_shared->totals_lock);
sb_shared->should_shutdown = 1;
@@ -270,66 +211,44 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs,
}
}
- /* Create detgeom structure after loading image,
- * so we get the "filled in" clen values, etc. */
- image.detgeom = detgeom_from_olddet(iargs->det);
-
- image.bw = iargs->beam->bandwidth;
+ image->serial = serial;
+ image->copyme = iargs->copyme;
/* Take snapshot of image before applying horrible noise filters */
time_accounts_set(taccs, TACC_FILTER);
set_last_task(last_task, "image filter");
sb_shared->pings[cookie]++;
- prefilter = backup_image_data(image.dp, image.det);
+ prefilter = backup_image_data(image->dp, image->detgeom);
if ( iargs->median_filter > 0 ) {
- filter_median(&image, iargs->median_filter);
+ filter_median(image, iargs->median_filter);
}
if ( iargs->noisefilter ) {
- filter_noise(&image);
+ filter_noise(image);
}
time_accounts_set(taccs, TACC_RESRANGE);
set_last_task(last_task, "resolution range");
sb_shared->pings[cookie]++;
- mark_resolution_range_as_bad(&image, iargs->highres, +INFINITY);
+ mark_resolution_range_as_bad(image, iargs->highres, +INFINITY);
time_accounts_set(taccs, TACC_PEAKSEARCH);
sb_shared->pings[cookie]++;
switch ( iargs->peaks ) {
- struct hdfile *hdfile;
-
case PEAK_HDF5:
- set_last_task(last_task, "peaksearch:hdf5");
- hdfile = imagefile_get_hdfile(imfile);
- if ( (hdfile == NULL)
- || (get_peaks_2(&image, hdfile, iargs->hdf5_peak_path,
- iargs->half_pixel_shift)) )
- {
- ERROR("Failed to get peaks from HDF5 file.\n");
- }
- if ( !iargs->no_revalidate ) {
- validate_peaks(&image, iargs->min_snr,
- iargs->pk_inn, iargs->pk_mid,
- iargs->pk_out, iargs->use_saturated,
- iargs->check_hdf5_snr);
- }
- break;
-
case PEAK_CXI:
- set_last_task(last_task, "peaksearch:cxi");
- hdfile = imagefile_get_hdfile(imfile);
- if ( (hdfile == NULL)
- || (get_peaks_cxi_2(&image, hdfile, iargs->hdf5_peak_path,
- pargs->filename_p_e,
- iargs->half_pixel_shift)) )
- {
- ERROR("Failed to get peaks from CXI file.\n");
+ set_last_task(last_task, "peaksearch:hdf5orcxi");
+ image->features = image_read_peaks(iargs->dtempl,
+ pargs->filename,
+ pargs->event,
+ iargs->half_pixel_shift);
+ if ( image->features == NULL ) {
+ ERROR("Failed to get peaks from HDF5 file.\n");
}
if ( !iargs->no_revalidate ) {
- validate_peaks(&image, iargs->min_snr,
+ validate_peaks(image, iargs->min_snr,
iargs->pk_inn, iargs->pk_mid,
iargs->pk_out, iargs->use_saturated,
iargs->check_hdf5_snr);
@@ -338,7 +257,7 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs,
case PEAK_ZAEF:
set_last_task(last_task, "peaksearch:zaef");
- search_peaks(&image, iargs->threshold,
+ search_peaks(image, iargs->threshold,
iargs->min_sq_gradient, iargs->min_snr,
iargs->pk_inn, iargs->pk_mid, iargs->pk_out,
iargs->use_saturated);
@@ -346,30 +265,24 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs,
case PEAK_PEAKFINDER8:
set_last_task(last_task, "peaksearch:pf8");
- if ( search_peaks_peakfinder8(&image, 2048,
- iargs->threshold,
- iargs->min_snr,
- iargs->min_pix_count,
- iargs->max_pix_count,
- iargs->local_bg_radius,
- iargs->min_res,
- iargs->max_res,
- iargs->use_saturated) ) {
- if ( image.event != NULL ) {
- ERROR("Failed to find peaks in image %s"
- "(event %s).\n", image.filename,
- get_event_string(image.event));
- } else {
- ERROR("Failed to find peaks in image %s.",
- image.filename);
- }
-
+ if ( search_peaks_peakfinder8(image, 2048,
+ iargs->threshold,
+ iargs->min_snr,
+ iargs->min_pix_count,
+ iargs->max_pix_count,
+ iargs->local_bg_radius,
+ iargs->min_res,
+ iargs->max_res,
+ iargs->use_saturated) ) {
+ ERROR("Failed to find peaks in image %s"
+ "(event %s).\n",
+ image->filename, image->ev);
}
break;
case PEAK_PEAKFINDER9:
set_last_task(last_task, "peaksearch:pf9");
- if ( search_peaks_peakfinder9(&image,
+ if ( search_peaks_peakfinder9(image,
iargs->min_snr_biggest_pix,
iargs->min_snr_peak_pix,
iargs->min_snr,
@@ -377,21 +290,16 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs,
iargs->min_peak_over_neighbour,
iargs->local_bg_radius) )
{
- if ( image.event != NULL ) {
- ERROR("Failed to find peaks in image %s"
- "(event %s).\n", image.filename,
- get_event_string(image.event));
- } else {
- ERROR("Failed to find peaks in image %s.",
- image.filename);
- }
+ ERROR("Failed to find peaks in image %s"
+ "(event %s).\n",
+ image->filename, image->ev);
}
break;
case PEAK_MSGPACK:
- image.features = get_peaks_msgpack(pargs->msgpack_obj,
- iargs->dtempl,
- iargs->half_pixel_shift);
+ image->features = get_peaks_msgpack(pargs->msgpack_obj,
+ iargs->dtempl,
+ iargs->half_pixel_shift);
break;
case PEAK_NONE:
@@ -400,11 +308,11 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs,
}
- image.peak_resolution = estimate_peak_resolution(image.features,
- image.lambda,
- image.det);
+ image->peak_resolution = estimate_peak_resolution(image->features,
+ image->lambda,
+ image->det);
- restore_image_data(image.dp, image.det, prefilter);
+ restore_image_data(image->dp, image->detgeom, prefilter);
rn = getcwd(NULL, 0);
@@ -412,33 +320,31 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs,
if ( r ) {
ERROR("Failed to chdir to temporary folder: %s\n",
strerror(errno));
- imagefile_close(imfile);
return;
}
/* Set beam parameters */
if ( iargs->fix_divergence >= 0.0 ) {
- image.div = iargs->fix_divergence;
+ image->div = iargs->fix_divergence;
} else {
- image.div = 0.0;
+ image->div = 0.0;
}
/* Set beam spectrum */
if ( iargs->spectrum != NULL ) {
- image.spectrum = iargs->spectrum;
+ image->spectrum = iargs->spectrum;
} else {
- image.spectrum = spectrum_generate_gaussian(image.lambda,
- image.bw);
+ image->spectrum = spectrum_generate_gaussian(image->lambda,
+ image->bw);
}
- if ( image_feature_count(image.features) < iargs->min_peaks ) {
+ if ( image_feature_count(image->features) < iargs->min_peaks ) {
r = chdir(rn);
if ( r ) {
ERROR("Failed to chdir: %s\n", strerror(errno));
- imagefile_close(imfile);
return;
}
free(rn);
- image.hit = 0;
+ image->hit = 0;
if ( iargs->stream_nonhits ) {
goto streamwrite;
@@ -446,18 +352,17 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs,
goto out;
}
}
- image.hit = 1;
+ image->hit = 1;
/* Index the pattern */
time_accounts_set(taccs, TACC_INDEXING);
set_last_task(last_task, "indexing");
- index_pattern_3(&image, iargs->ipriv, &sb_shared->pings[cookie],
+ index_pattern_3(image, iargs->ipriv, &sb_shared->pings[cookie],
last_task);
r = chdir(rn);
if ( r ) {
ERROR("Failed to chdir: %s\n", strerror(errno));
- imagefile_close(imfile);
return;
}
free(rn);
@@ -466,21 +371,21 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs,
time_accounts_set(taccs, TACC_PREDPARAMS);
set_last_task(last_task, "prediction params");
if ( iargs->fix_profile_r >= 0.0 ) {
- for ( i=0; i<image.n_crystals; i++ ) {
- crystal_set_profile_radius(image.crystals[i],
+ for ( i=0; i<image->n_crystals; i++ ) {
+ crystal_set_profile_radius(image->crystals[i],
iargs->fix_profile_r);
- crystal_set_mosaicity(image.crystals[i], 0.0);
+ crystal_set_mosaicity(image->crystals[i], 0.0);
}
} else {
- for ( i=0; i<image.n_crystals; i++ ) {
- crystal_set_profile_radius(image.crystals[i], 0.02e9);
- crystal_set_mosaicity(image.crystals[i], 0.0);
+ for ( i=0; i<image->n_crystals; i++ ) {
+ crystal_set_profile_radius(image->crystals[i], 0.02e9);
+ crystal_set_mosaicity(image->crystals[i], 0.0);
}
}
if ( iargs->fix_profile_r < 0.0 ) {
- for ( i=0; i<image.n_crystals; i++ ) {
- if ( refine_radius(image.crystals[i], &image) ) {
+ for ( i=0; i<image->n_crystals; i++ ) {
+ if ( refine_radius(image->crystals[i], image) ) {
ERROR("WARNING: Radius determination failed\n");
}
}
@@ -490,7 +395,7 @@ void process_image(const struct index_args *iargs, struct pattern_args *pargs,
time_accounts_set(taccs, TACC_INTEGRATION);
set_last_task(last_task, "integration");
sb_shared->pings[cookie]++;
- integrate_all_5(&image, iargs->int_meth, PMODEL_XSPHERE,
+ integrate_all_5(image, iargs->int_meth, PMODEL_XSPHERE,
iargs->push_res,
iargs->ir_inn, iargs->ir_mid, iargs->ir_out,
iargs->int_diag, iargs->int_diag_h,
@@ -501,21 +406,19 @@ streamwrite:
time_accounts_set(taccs, TACC_WRITESTREAM);
set_last_task(last_task, "stream write");
sb_shared->pings[cookie]++;
- ret = write_chunk(st, &image, imfile,
- iargs->stream_peaks, iargs->stream_refls,
- pargs->filename_p_e->ev);
+ ret = write_chunk(st, image, iargs->stream_peaks,
+ iargs->stream_refls);
if ( ret != 0 ) {
ERROR("Error writing stream file.\n");
}
int n = 0;
- for ( i=0; i<image.n_crystals; i++ ) {
- n += crystal_get_num_implausible_reflections(image.crystals[i]);
+ for ( i=0; i<image->n_crystals; i++ ) {
+ n += crystal_get_num_implausible_reflections(image->crystals[i]);
}
if ( n > 0 ) {
STATUS("WARNING: %i implausibly negative reflection%s in %s "
- "%s\n", n, n>1?"s":"", image.filename,
- get_event_string(image.event));
+ "%s\n", n, n>1?"s":"", image->filename, image->ev);
}
out:
@@ -525,40 +428,39 @@ out:
sb_shared->pings[cookie]++;
pthread_mutex_lock(&sb_shared->totals_lock);
any_crystals = 0;
- for ( i=0; i<image.n_crystals; i++ ) {
- if ( crystal_get_user_flag(image.crystals[i]) == 0 ) {
+ for ( i=0; i<image->n_crystals; i++ ) {
+ if ( crystal_get_user_flag(image->crystals[i]) == 0 ) {
sb_shared->n_crystals++;
any_crystals = 1;
}
}
sb_shared->n_processed++;
- sb_shared->n_hits += image.hit;
+ sb_shared->n_hits += image->hit;
sb_shared->n_hadcrystals += any_crystals;
pthread_mutex_unlock(&sb_shared->totals_lock);
- for ( i=0; i<image.n_crystals; i++ ) {
- cell_free(crystal_get_cell(image.crystals[i]));
- reflist_free(crystal_get_reflections(image.crystals[i]));
- crystal_free(image.crystals[i]);
+ for ( i=0; i<image->n_crystals; i++ ) {
+ cell_free(crystal_get_cell(image->crystals[i]));
+ reflist_free(crystal_get_reflections(image->crystals[i]));
+ crystal_free(image->crystals[i]);
}
- free(image.crystals);
+ free(image->crystals);
/* Free spectrum only if we generated it for this image */
if ( iargs->spectrum == NULL ) {
- spectrum_free(image.spectrum);
+ spectrum_free(image->spectrum);
}
- for ( i=0; i<image.det->n_panels; i++ ) {
- free(image.dp[i]);
- free(image.bad[i]);
- free(image.sat[i]);
+ for ( i=0; i<image->det->n_panels; i++ ) {
+ free(image->dp[i]);
+ free(image->bad[i]);
+ free(image->sat[i]);
}
- free(image.dp);
- free(image.bad);
- free(image.sat);
+ free(image->dp);
+ free(image->bad);
+ free(image->sat);
- image_feature_list_free(image.features);
- free_detector_geometry(image.det);
- if ( imfile != NULL ) imagefile_close(imfile);
+ image_feature_list_free(image->features);
+ free_detector_geometry(image->det);
set_last_task(last_task, "sandbox");
}
diff --git a/src/process_image.h b/src/process_image.h
index debae92e..908a2e06 100644
--- a/src/process_image.h
+++ b/src/process_image.h
@@ -58,13 +58,10 @@ struct index_args
float min_sq_gradient;
float min_snr;
int check_hdf5_snr;
- struct detector *det;
- const DataTemplate *dtempl;
+ DataTemplate *dtempl;
IndexingPrivate *ipriv;
enum peak_search_method peaks;
float tols[6];
- struct beam_params *beam;
- char *hdf5_peak_path;
int half_pixel_shift;
float pk_inn;
float pk_mid;
@@ -110,7 +107,8 @@ struct index_args
struct pattern_args
{
/* "Input" */
- struct filename_plus_event *filename_p_e;
+ char *filename;
+ char *event;
#ifdef HAVE_MSGPACK
msgpack_object *msgpack_obj;
#else
diff --git a/src/whirligig.c b/src/whirligig.c
index 199ad0f3..ee74a25e 100644
--- a/src/whirligig.c
+++ b/src/whirligig.c
@@ -173,7 +173,7 @@ static void process_series(struct image *images, signed int *ser,
Crystal *cr = images[i].crystals[ser[i]];
fprintf(fh, "%4i %5i %s %s %i\n", i, images[i].serial,
images[i].filename,
- get_event_string(images[i].event),
+ images[i].ev,
ser[i]);
p[i] = transform_reflections(crystal_get_reflections(cr),
mat[i]);