1 -- Copyright (C) 2011--2012,2014 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 -- coinc_definer clean up
21 CREATE TEMPORARY TABLE _idmap_ AS
23 old.coinc_def_id AS old,
24 MIN(new.coinc_def_id) AS new
27 JOIN coinc_definer AS new ON (
28 new.search == old.search
29 AND new.search_coinc_type == old.search_coinc_type
33 CREATE INDEX tmpindex ON _idmap_ (old);
35 UPDATE coinc_event SET coinc_def_id = (SELECT new FROM _idmap_ WHERE old == coinc_def_id);
36 DELETE FROM coinc_definer WHERE coinc_def_id IN (SELECT old FROM _idmap_ WHERE old != new);
42 -- segment_definer clean up. NOTE; this assumes no meaningful information
43 -- is stored in the version and comment columns, and will scramble it if
44 -- there is. that is, two segment_definer rows are considered to be
45 -- equivalent even if their version and comment values differ, and the one
46 -- with the higher ID will be discarded.
49 CREATE TEMPORARY TABLE _idmap_ AS
51 old.segment_def_id AS old,
52 MIN(new.segment_def_id) AS new
54 segment_definer AS old
55 JOIN segment_definer AS new ON (
57 AND new.name == old.name
61 CREATE INDEX tmpindex ON _idmap_ (old);
63 UPDATE segment_summary SET segment_def_id = (SELECT new FROM _idmap_ WHERE old == segment_def_id);
64 UPDATE segment SET segment_def_id = (SELECT new FROM _idmap_ WHERE old == segment_def_id);
65 DELETE FROM segment_definer WHERE segment_def_id IN (SELECT old FROM _idmap_ WHERE old != new);
71 -- time_slide clean up
74 CREATE TEMPORARY TABLE _idmap_ AS
77 (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,
83 CREATE INDEX tmpindex ON _idmap_ (repr, old);
85 UPDATE _idmap_ SET new = (SELECT MIN(old) FROM _idmap_ AS a WHERE a.repr == _idmap_.repr);
87 CREATE INDEX tmpindex ON _idmap_ (old);
89 UPDATE coinc_event SET time_slide_id = (SELECT _idmap_.new FROM _idmap_ WHERE _idmap_.old == time_slide_id);
90 DELETE FROM time_slide WHERE time_slide_id IN (SELECT old FROM _idmap_ WHERE old != new);
102 "Number of coincs before clustering: " || count(*)
107 -- create a look-up table of info required for clustering
110 CREATE TEMPORARY TABLE _cluster_info_ AS
112 coinc_event.coinc_event_id AS coinc_event_id,
113 coinc_event.time_slide_id AS category,
114 (coinc_inspiral.end_time - (SELECT MIN(end_time) FROM coinc_inspiral)) + 1e-9 * coinc_inspiral.end_time_ns AS end_time,
115 coinc_event.likelihood AS ranking_stat
118 JOIN coinc_inspiral ON (
119 coinc_inspiral.coinc_event_id == coinc_event.coinc_event_id
121 CREATE INDEX tmpindex1 ON _cluster_info_ (coinc_event_id);
122 CREATE INDEX tmpindex2 ON _cluster_info_ (category, end_time, ranking_stat);
125 -- delete coincs that are within 4 s of coincs with higher SNR in the same
136 _cluster_info_ AS _cluster_info_a_
137 JOIN _cluster_info_ AS _cluster_info_b_ ON (
138 _cluster_info_b_.category == _cluster_info_a_.category
139 AND (_cluster_info_b_.end_time BETWEEN _cluster_info_a_.end_time - 4.0 AND _cluster_info_a_.end_time + 4.0)
140 AND _cluster_info_b_.ranking_stat > _cluster_info_a_.ranking_stat
143 _cluster_info_a_.coinc_event_id == coinc_event.coinc_event_id
145 DROP INDEX tmpindex1;
146 DROP INDEX tmpindex2;
147 DROP TABLE _cluster_info_;
150 "Number of coincs after clustering: " || count(*)
155 -- delete unused coinc_inspiral rows
161 coinc_event_id NOT IN (
169 -- delete unused coinc_event_map rows
175 coinc_event_id NOT IN (
183 -- delete unused sngl_inspiral rows
195 table_name == 'sngl_inspiral'