1 -- Copyright (C) 2011--2012,2014,2015 Kipp Cannon, Chad Hanna
3 -- This program is free software; you can redistribute it and/or modify it
4 -- under the terms of the GNU General Public License as published by the
5 -- Free Software Foundation; either version 2 of the License, or (at your
6 -- option) any later version.
8 -- This program is distributed in the hope that it will be useful, but
9 -- WITHOUT ANY WARRANTY; without even the implied warranty of
10 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 -- Public License for more details.
13 -- You should have received a copy of the GNU General Public License along
14 -- with this program; if not, write to the Free Software Foundation, Inc.,
15 -- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 -- process clean up. same computer, unix process ID, and start time =
22 CREATE INDEX tmpindex ON process (node, unix_procid, start_time);
23 CREATE TEMPORARY TABLE __idmap__ AS
25 old.process_id AS old,
26 MIN(new.process_id) AS new
29 JOIN process AS new ON (
31 AND new.unix_procid == old.unix_procid
32 AND new.start_time == old.start_time
37 CREATE INDEX tmpindex ON __idmap__ (old);
39 UPDATE coinc_event SET process_id = (SELECT new FROM __idmap__ WHERE old == process_id);
40 UPDATE segment SET process_id = (SELECT new FROM __idmap__ WHERE old == process_id);
41 UPDATE segment_definer SET process_id = (SELECT new FROM __idmap__ WHERE old == process_id);
42 UPDATE segment_summary SET process_id = (SELECT new FROM __idmap__ WHERE old == process_id);
43 UPDATE sngl_inspiral SET process_id = (SELECT new FROM __idmap__ WHERE old == process_id);
44 UPDATE time_slide SET process_id = (SELECT new FROM __idmap__ WHERE old == process_id);
46 DELETE FROM process WHERE process_id IN (SELECT old FROM __idmap__ WHERE old != new);
47 DELETE FROM process_params WHERE process_id NOT IN (SELECT process_id FROM process);
53 -- coinc_definer clean up
56 CREATE TEMPORARY TABLE __idmap__ AS
58 old.coinc_def_id AS old,
59 MIN(new.coinc_def_id) AS new
62 JOIN coinc_definer AS new ON (
63 new.search == old.search
64 AND new.search_coinc_type == old.search_coinc_type
68 CREATE INDEX tmpindex ON __idmap__ (old);
70 UPDATE coinc_event SET coinc_def_id = (SELECT new FROM __idmap__ WHERE old == coinc_def_id);
71 DELETE FROM coinc_definer WHERE coinc_def_id IN (SELECT old FROM __idmap__ WHERE old != new);
77 -- segment_definer clean up. NOTE: this assumes no meaningful information
78 -- is stored in the version and comment columns, and will scramble it if
79 -- there is. that is, two segment_definer rows are considered to be
80 -- equivalent even if their version and comment values differ, and the one
81 -- with the higher ID will be discarded.
84 CREATE TEMPORARY TABLE __idmap__ AS
86 old.segment_def_id AS old,
87 MIN(new.segment_def_id) AS new
89 segment_definer AS old
90 JOIN segment_definer AS new ON (
92 AND new.name == old.name
96 CREATE INDEX tmpindex ON __idmap__ (old);
98 UPDATE segment_summary SET segment_def_id = (SELECT new FROM __idmap__ WHERE old == segment_def_id);
99 UPDATE segment SET segment_def_id = (SELECT new FROM __idmap__ WHERE old == segment_def_id);
100 DELETE FROM segment_definer WHERE segment_def_id IN (SELECT old FROM __idmap__ WHERE old != new);
103 DROP TABLE __idmap__;
106 -- segment clean up. NOTE: this assumes that nothing references segment
107 -- rows by ID, so that redundant rows can be deleted without correcting
108 -- references to their IDs in other tables
120 other.segment_def_id == segment.segment_def_id
121 AND other.start_time == segment.start_time
122 AND other.start_time_ns == segment.start_time_ns
123 AND other.end_time == segment.end_time
124 AND other.end_time_ns == segment.end_time_ns
125 AND other.segment_id < segment.segment_id
129 -- time_slide clean up
132 CREATE TEMPORARY TABLE __idmap__ AS
134 time_slide_id AS old,
135 (SELECT group_concat(instrument || "=" || offset) FROM time_slide AS time_slide_a WHERE time_slide_a.time_slide_id == time_slide.time_slide_id ORDER BY instrument) AS repr,
141 CREATE INDEX tmpindex ON __idmap__ (repr, old);
143 UPDATE __idmap__ SET new = (SELECT MIN(old) FROM __idmap__ AS a WHERE a.repr == __idmap__.repr);
145 CREATE INDEX tmpindex ON __idmap__ (old);
147 UPDATE coinc_event SET time_slide_id = (SELECT __idmap__.new FROM __idmap__ WHERE __idmap__.old == time_slide_id);
148 DELETE FROM time_slide WHERE time_slide_id IN (SELECT old FROM __idmap__ WHERE old != new);
151 DROP TABLE __idmap__;
160 "Number of coincs before clustering: " || count(*)
165 -- create a look-up table of info required for clustering
168 CREATE TEMPORARY TABLE _cluster_info_ AS
170 coinc_event.coinc_event_id AS coinc_event_id,
171 coinc_event.time_slide_id AS category,
172 coinc_inspiral.end_time AS end_time, --- only keep the integer part
173 coinc_event.likelihood AS ranking_stat,
174 coinc_inspiral.combined_far as far,
175 coinc_inspiral.snr AS snr
178 JOIN coinc_inspiral ON (
179 coinc_inspiral.coinc_event_id == coinc_event.coinc_event_id
181 CREATE INDEX tmpindex1 ON _cluster_info_ (coinc_event_id);
182 CREATE INDEX tmpindex2 ON _cluster_info_ (category, end_time, ranking_stat);
185 -- delete all but the highest-ranked coinc in each integer second to match
186 -- the 1 second thinca interval used internally in online running
196 _cluster_info_ AS _cluster_info_a_
197 JOIN _cluster_info_ AS _cluster_info_b_ ON (
198 _cluster_info_b_.category == _cluster_info_a_.category
199 AND _cluster_info_b_.end_time == _cluster_info_a_.end_time
200 AND (_cluster_info_b_.ranking_stat > _cluster_info_a_.ranking_stat OR
201 _cluster_info_b_.ranking_stat == _cluster_info_a_.ranking_stat AND (_cluster_info_b_.snr > _cluster_info_a_.snr OR _cluster_info_b_.snr == _cluster_info_a_.snr AND (_cluster_info_b_.coinc_event_id > _cluster_info_a_.coinc_event_id))
205 _cluster_info_a_.coinc_event_id == coinc_event.coinc_event_id
208 -- delete all events with combined far < 1e-4 or NULL
217 _cluster_info_ AS _cluster_info_a_
219 _cluster_info_a_.coinc_event_id == coinc_event.coinc_event_id AND (_cluster_info_a_.far > 1e-4 OR _cluster_info_a_.far IS NULL)
221 DROP INDEX tmpindex1;
222 DROP INDEX tmpindex2;
223 DROP TABLE _cluster_info_;
226 "Number of coincs after clustering: " || count(*)
231 -- delete unused coinc_inspiral rows
237 coinc_event_id NOT IN (
245 -- delete unused coinc_event_map rows
251 coinc_event_id NOT IN (
259 -- delete unused sngl_inspiral rows
271 table_name == 'sngl_inspiral'