1 -- Copyright (C) 2011--2012,2014,2015 Kipp Cannon, Chad Hanna, Melissa Frei
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 DROP table if EXISTS sim_inspiral;
21 -- process clean up. same computer, unix process ID, and start time =
25 CREATE INDEX tmpindex ON process (node, unix_procid, start_time);
26 CREATE TEMPORARY TABLE _idmap_ AS
28 old.process_id AS old,
29 MIN(new.process_id) AS new
32 JOIN process AS new ON (
34 AND new.unix_procid == old.unix_procid
35 AND new.start_time == old.start_time
40 CREATE INDEX tmpindex ON _idmap_ (old);
41 CREATE INDEX tmpindex2 ON _idmap_ (new, old);
43 UPDATE coinc_event SET process_id = (SELECT new FROM _idmap_ WHERE old == process_id);
44 UPDATE segment SET process_id = (SELECT new FROM _idmap_ WHERE old == process_id);
45 UPDATE segment_definer SET process_id = (SELECT new FROM _idmap_ WHERE old == process_id);
46 UPDATE segment_summary SET process_id = (SELECT new FROM _idmap_ WHERE old == process_id);
47 UPDATE sngl_inspiral SET process_id = (SELECT new FROM _idmap_ WHERE old == process_id);
48 UPDATE time_slide SET process_id = (SELECT new FROM _idmap_ WHERE old == process_id);
50 DELETE FROM process WHERE process_id IN (SELECT old FROM _idmap_ WHERE old != new);
51 DELETE FROM process_params WHERE process_id NOT IN (SELECT process_id FROM process);
58 -- coinc_definer clean up
61 CREATE TEMPORARY TABLE _idmap_ AS
63 old.coinc_def_id AS old,
64 MIN(new.coinc_def_id) AS new
67 JOIN coinc_definer AS new ON (
68 new.search == old.search
69 AND new.search_coinc_type == old.search_coinc_type
73 CREATE INDEX tmpindex ON _idmap_ (old);
74 CREATE INDEX tmpindex2 ON _idmap_ (new, old);
76 UPDATE coinc_event SET coinc_def_id = (SELECT new FROM _idmap_ WHERE old == coinc_def_id);
77 DELETE FROM coinc_definer WHERE coinc_def_id IN (SELECT old FROM _idmap_ WHERE old != new);
84 -- segment_definer clean up. NOTE: this assumes no meaningful information
85 -- is stored in the version and comment columns, and will scramble it if
86 -- there is. that is, two segment_definer rows are considered to be
87 -- equivalent even if their version and comment values differ, and the one
88 -- with the higher ID will be discarded.
91 CREATE TEMPORARY TABLE _idmap_ AS
93 old.segment_def_id AS old,
94 MIN(new.segment_def_id) AS new
96 segment_definer AS old
97 JOIN segment_definer AS new ON (
99 AND new.name == old.name
103 CREATE INDEX tmpindex ON _idmap_ (old);
105 UPDATE segment_summary SET segment_def_id = (SELECT new FROM _idmap_ WHERE old == segment_def_id);
106 UPDATE segment SET segment_def_id = (SELECT new FROM _idmap_ WHERE old == segment_def_id);
107 DELETE FROM segment_definer WHERE segment_def_id IN (SELECT old FROM _idmap_ WHERE old != new);
113 -- segment clean up. NOTE: this assumes that nothing references segment
114 -- rows by ID, so that redundant rows can be deleted without correcting
115 -- references to their IDs in other tables
118 CREATE INDEX tmpindex ON segment(segment_def_id, start_time, start_time_ns, end_time, end_time_ns, segment_id);
129 other.segment_def_id == segment.segment_def_id
130 AND other.start_time == segment.start_time
131 AND other.start_time_ns == segment.start_time_ns
132 AND other.end_time == segment.end_time
133 AND other.end_time_ns == segment.end_time_ns
134 AND other.segment_id < segment.segment_id
139 -- time_slide clean up
142 CREATE TEMPORARY TABLE _idmap_ AS
144 time_slide_id AS old,
145 (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,
151 CREATE INDEX tmpindex ON _idmap_ (repr, old);
153 UPDATE _idmap_ SET new = (SELECT MIN(old) FROM _idmap_ AS a WHERE a.repr == _idmap_.repr);
155 CREATE INDEX tmpindex ON _idmap_ (old);
157 UPDATE coinc_event SET time_slide_id = (SELECT _idmap_.new FROM _idmap_ WHERE _idmap_.old == time_slide_id);
158 DELETE FROM time_slide WHERE time_slide_id IN (SELECT old FROM _idmap_ WHERE old != new);
170 "Number of coincs before clustering: " || count(*)
175 -- create a look-up table of info required for clustering
178 CREATE TEMPORARY TABLE _cluster_info_ AS
180 coinc_event.coinc_event_id AS coinc_event_id,
181 coinc_event.time_slide_id AS category,
182 (coinc_inspiral.end_time - (SELECT MIN(end_time) FROM coinc_inspiral)) + 1e-9 * coinc_inspiral.end_time_ns AS end_time,
183 coinc_event.likelihood AS ranking_stat,
184 coinc_inspiral.snr AS snr
187 JOIN coinc_inspiral ON (
188 coinc_inspiral.coinc_event_id == coinc_event.coinc_event_id
190 CREATE INDEX tmpindex1 ON _cluster_info_ (coinc_event_id);
191 CREATE INDEX tmpindex2 ON _cluster_info_ (category, end_time, ranking_stat);
194 -- delete coincs that are within 1 s of coincs with higher ranking
195 -- statistic in the same category. break ties by root-sum-square of SNRs,
196 -- break ties by coinc_event_id
206 _cluster_info_ AS _cluster_info_a_
207 JOIN _cluster_info_ AS _cluster_info_b_ ON (
208 _cluster_info_b_.category == _cluster_info_a_.category
209 AND (_cluster_info_b_.end_time BETWEEN _cluster_info_a_.end_time - 4.0 AND _cluster_info_a_.end_time + 4.0)
210 AND (_cluster_info_b_.ranking_stat > _cluster_info_a_.ranking_stat OR
211 _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))
215 _cluster_info_a_.coinc_event_id == coinc_event.coinc_event_id
217 DROP INDEX tmpindex1;
218 DROP INDEX tmpindex2;
219 DROP TABLE _cluster_info_;
222 "Number of coincs after clustering: " || count(*)
227 -- delete unused coinc_inspiral rows
233 coinc_event_id NOT IN (
241 -- delete unused coinc_event_map rows
247 coinc_event_id NOT IN (
255 -- delete unused sngl_inspiral rows
261 sngl_inspiral.snr < (
263 -- if they aren't all the same err on the size of
269 program == "gstlal_inspiral"
270 AND param == "--singles-threshold"
272 AND event_id NOT IN (
278 table_name == 'sngl_inspiral'