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);
52 DROP TABLE ___idmap___;
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);
78 DROP TABLE ___idmap___;
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);
107 DROP TABLE ___idmap___;
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);
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);
158 DROP TABLE ___idmap___;
167 "Number of coincs before clustering: " || count(*)
172 -- create a look-up table of info required for clustering
175 CREATE INDEX tmpindex1 ON coinc_event_map (coinc_event_id);
176 CREATE INDEX tmpindex2 ON coinc_event (coinc_event_id);
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_inspiral.snr AS snr,
184 -- NOTE FIXME we are using bank_chisq to hold a chisq weighted snr value
185 (SELECT SUM(sngl.bank_chisq * sngl.bank_chisq) FROM sngl_inspiral as sngl WHERE sngl.event_id IN (SELECT event_id FROM coinc_event_map WHERE coinc_event_map.coinc_event_id == coinc_event.coinc_event_id)) AS ranking_stat
188 JOIN coinc_inspiral ON (
189 coinc_inspiral.coinc_event_id == coinc_event.coinc_event_id
191 DROP INDEX tmpindex1;
192 DROP INDEX tmpindex2;
194 CREATE INDEX tmpindex1 ON _cluster_info_ (coinc_event_id);
195 CREATE INDEX tmpindex2 ON _cluster_info_ (category, end_time, ranking_stat);
198 -- delete coincs that are within 1 s of coincs with higher ranking
199 -- statistic in the same category. break ties by root-sum-square of SNRs,
200 -- break ties by coinc_event_id
210 _cluster_info_ AS _cluster_info_a_
211 JOIN _cluster_info_ AS _cluster_info_b_ ON (
212 _cluster_info_b_.category == _cluster_info_a_.category
213 AND (_cluster_info_b_.end_time BETWEEN _cluster_info_a_.end_time - 0.1 AND _cluster_info_a_.end_time + 0.1)
214 AND (_cluster_info_b_.ranking_stat > _cluster_info_a_.ranking_stat OR
215 _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))
219 _cluster_info_a_.coinc_event_id == coinc_event.coinc_event_id
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
265 sngl_inspiral.snr < (
267 -- if they aren't all the same err on the size of
273 program == "gstlal_inspiral"
274 AND param == "--singles-threshold"
276 AND event_id NOT IN (
282 table_name == 'sngl_inspiral'