aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-09-04 12:16:57 +0200
committerThomas White <taw@physics.org>2020-09-04 12:16:57 +0200
commit4751409e51151ef0987720a321b0ca4a88a534a5 (patch)
treef9f42cade8d8737afa38ab954003dfaab81d5d0e
parentcf295e657e59acb6bf0a2e226572b35927daa258 (diff)
API for looking up results via gui_result
-rw-r--r--src/gui_project.c93
-rw-r--r--src/gui_project.h9
2 files changed, 101 insertions, 1 deletions
diff --git a/src/gui_project.c b/src/gui_project.c
index ca9249d9..63df4536 100644
--- a/src/gui_project.c
+++ b/src/gui_project.c
@@ -730,6 +730,7 @@ int add_result(struct crystfelproject *proj,
char **streams,
int n_streams)
{
+ int i;
struct gui_result *new_results;
new_results = realloc(proj->results,
@@ -739,6 +740,12 @@ int add_result(struct crystfelproject *proj,
new_results[proj->n_results].name = name;
new_results[proj->n_results].streams = streams;
new_results[proj->n_results].n_streams = n_streams;
+ new_results[proj->n_results].indices = malloc(n_streams*sizeof(StreamIndex *));
+
+ for ( i=0; i<n_streams; i++ ) {
+ new_results[proj->n_results].indices[i] = NULL;
+ }
+
proj->results = new_results;
proj->n_results++;
@@ -747,3 +754,89 @@ int add_result(struct crystfelproject *proj,
return 0;
}
+
+
+static void update_result_index(struct gui_result *result)
+{
+ int i;
+
+ for ( i=0; i<result->n_streams; i++ ) {
+
+ /* FIXME: Skip if already up to date */
+
+ stream_index_free(result->indices[i]);
+ result->indices[i] = stream_make_index(result->streams[i]);
+
+ }
+}
+
+
+static struct gui_result *find_result_by_name(struct crystfelproject *proj,
+ const char *name)
+{
+ int i;
+
+ for ( i=0; i<proj->n_results; i++ ) {
+ if ( strcmp(proj->results[i].name, name) == 0 ) {
+ return &proj->results[i];
+ }
+ }
+ return NULL;
+}
+
+
+struct image *find_result(struct crystfelproject *proj,
+ const char *results_name,
+ const char *filename,
+ const char *event)
+{
+ Stream *st;
+ int i;
+ int found = 0;
+ struct image *image;
+ struct gui_result *result;
+
+ result = find_result_by_name(proj, results_name);
+ if ( result == NULL ) return NULL;
+
+ for ( i=0; i<result->n_streams; i++ ) {
+ if ( stream_select_chunk(NULL,
+ result->indices[i],
+ filename,
+ event) == 0 )
+ {
+ found = 1;
+ break;
+ }
+ }
+
+ if ( !found ) {
+ update_result_index(result);
+ for ( i=0; i<result->n_streams; i++ ) {
+ if ( stream_select_chunk(NULL,
+ result->indices[i],
+ filename,
+ event) == 0 )
+ {
+ found = 1;
+ break;
+ }
+ }
+ }
+
+ if ( !found ) return NULL;
+
+ st = stream_open_for_read(result->streams[i]);
+ if ( stream_select_chunk(st, result->indices[i],
+ filename, event) )
+ {
+ ERROR("Error selecting chunk.\n");
+ return NULL;
+ }
+
+ image = stream_read_chunk(st, STREAM_REFLECTIONS
+ | STREAM_PEAKS);
+
+ stream_close(st);
+ return image;
+}
diff --git a/src/gui_project.h b/src/gui_project.h
index 36438517..c241b6f8 100644
--- a/src/gui_project.h
+++ b/src/gui_project.h
@@ -139,8 +139,10 @@ struct gui_task
struct gui_result
{
char *name;
- char **streams;
+
int n_streams;
+ char **streams;
+ StreamIndex **indices;
};
struct crystfelproject {
@@ -219,4 +221,9 @@ extern int add_result(struct crystfelproject *proj,
char **streams,
int n_streams);
+extern struct image *find_result(struct crystfelproject *proj,
+ const char *result_name,
+ const char *filename,
+ const char *event);
+
#endif