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);
38 CREATE INDEX tmpindex2 ON _idmap_ (new, old);
40 UPDATE coinc_event SET process_id = (SELECT new FROM _idmap_ WHERE old == process_id);
41 UPDATE segment SET process_id = (SELECT new FROM _idmap_ WHERE old == process_id);
42 UPDATE segment_definer SET process_id = (SELECT new FROM _idmap_ WHERE old == process_id);
43 UPDATE segment_summary SET process_id = (SELECT new FROM _idmap_ WHERE old == process_id);
44 UPDATE sngl_inspiral SET process_id = (SELECT new FROM _idmap_ WHERE old == process_id);
45 UPDATE time_slide SET process_id = (SELECT new FROM _idmap_ WHERE old == process_id);
47 DELETE FROM process WHERE process_id IN (SELECT old FROM _idmap_ WHERE old != new);
48 DELETE FROM process_params WHERE process_id NOT IN (SELECT process_id FROM process);
55 -- coinc_definer clean up
58 CREATE TEMPORARY TABLE _idmap_ AS
60 old.coinc_def_id AS old,
61 MIN(new.coinc_def_id) AS new
64 JOIN coinc_definer AS new ON (
65 new.search == old.search
66 AND new.search_coinc_type == old.search_coinc_type
70 CREATE INDEX tmpindex ON _idmap_ (old);
71 CREATE INDEX tmpindex2 ON _idmap_ (new, old);
73 UPDATE coinc_event SET coinc_def_id = (SELECT new FROM _idmap_ WHERE old == coinc_def_id);
74 DELETE FROM coinc_definer WHERE coinc_def_id IN (SELECT old FROM _idmap_ WHERE old != new);
81 -- segment_definer clean up. NOTE: this assumes no meaningful information
82 -- is stored in the version and comment columns, and will scramble it if
83 -- there is. that is, two segment_definer rows are considered to be
84 -- equivalent even if their version and comment values differ, and the one
85 -- with the higher ID will be discarded.
88 CREATE TEMPORARY TABLE _idmap_ AS
90 old.segment_def_id AS old,
91 MIN(new.segment_def_id) AS new
93 segment_definer AS old
94 JOIN segment_definer AS new ON (
96 AND new.name == old.name
100 CREATE INDEX tmpindex ON _idmap_ (old);
102 UPDATE segment_summary SET segment_def_id = (SELECT new FROM _idmap_ WHERE old == segment_def_id);
103 UPDATE segment SET segment_def_id = (SELECT new FROM _idmap_ WHERE old == segment_def_id);
104 DELETE FROM segment_definer WHERE segment_def_id IN (SELECT old FROM _idmap_ WHERE old != new);
110 -- segment clean up. NOTE: this assumes that nothing references segment
111 -- rows by ID, so that redundant rows can be deleted without correcting
112 -- references to their IDs in other tables
115 CREATE INDEX tmpindex ON segment(segment_def_id, start_time, start_time_ns, end_time, end_time_ns, segment_id);
126 other.segment_def_id == segment.segment_def_id
127 AND other.start_time == segment.start_time
128 AND other.start_time_ns == segment.start_time_ns
129 AND other.end_time == segment.end_time
130 AND other.end_time_ns == segment.end_time_ns
131 AND other.segment_id < segment.segment_id
136 -- time_slide clean up
139 CREATE TEMPORARY TABLE _idmap_ AS
141 time_slide_id AS old,
142 (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,
148 CREATE INDEX tmpindex ON _idmap_ (repr, old);
150 UPDATE _idmap_ SET new = (SELECT MIN(old) FROM _idmap_ AS a WHERE a.repr == _idmap_.repr);
152 CREATE INDEX tmpindex ON _idmap_ (old);
154 UPDATE coinc_event SET time_slide_id = (SELECT _idmap_.new FROM _idmap_ WHERE _idmap_.old == time_slide_id);
155 DELETE FROM time_slide WHERE time_slide_id IN (SELECT old FROM _idmap_ WHERE old != new);
167 "Number of coincs before clustering: " || count(*)
172 -- create a look-up table of info required for clustering
175 CREATE TEMPORARY TABLE _cluster_info_ AS
177 coinc_event.coinc_event_id AS coinc_event_id,
178 coinc_event.time_slide_id AS category,
179 (coinc_inspiral.end_time - (SELECT MIN(end_time) FROM coinc_inspiral)) + 1e-9 * coinc_inspiral.end_time_ns AS end_time,
180 coinc_event.likelihood AS ranking_stat,
181 coinc_inspiral.snr AS snr
184 JOIN coinc_inspiral ON (
185 coinc_inspiral.coinc_event_id == coinc_event.coinc_event_id
187 CREATE INDEX tmpindex1 ON _cluster_info_ (coinc_event_id);
188 CREATE INDEX tmpindex2 ON _cluster_info_ (category, end_time, ranking_stat);
191 -- delete coincs that are within 1 s of coincs with higher ranking
192 -- statistic in the same category. break ties by root-sum-square of SNRs,
193 -- break ties by coinc_event_id
203 _cluster_info_ AS _cluster_info_a_
204 JOIN _cluster_info_ AS _cluster_info_b_ ON (
205 _cluster_info_b_.category == _cluster_info_a_.category
206 AND (_cluster_info_b_.end_time BETWEEN _cluster_info_a_.end_time - 4.0 AND _cluster_info_a_.end_time + 4.0)
207 AND (_cluster_info_b_.ranking_stat > _cluster_info_a_.ranking_stat OR
208 _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))
212 _cluster_info_a_.coinc_event_id == coinc_event.coinc_event_id
214 DROP INDEX tmpindex1;
215 DROP INDEX tmpindex2;
216 DROP TABLE _cluster_info_;
219 "Number of coincs after clustering: " || count(*)
224 -- delete unused coinc_inspiral rows
230 coinc_event_id NOT IN (
238 -- delete unused coinc_event_map rows
244 coinc_event_id NOT IN (
252 -- delete unused sngl_inspiral rows
258 sngl_inspiral.snr < (
260 -- if they aren't all the same err on the size of
266 program == "gstlal_inspiral"
267 AND param == "--singles-threshold"
269 AND event_id NOT IN (
275 table_name == 'sngl_inspiral'