From 808211a10a7e05f5cafa41d0dcf27adff5c92805 Mon Sep 17 00:00:00 2001
From: Kipp Cannon <kipp.cannon@ligo.org>
Date: Fri, 16 Mar 2018 18:28:46 -0400
Subject: [PATCH] inspiral.py:  improve scaling of trigger segmentlist
 extraction

- use stream_thinca's discard_boundary and a bisection search to clip the ratebinlist objects to the range of segments we actually care about
---
 gstlal-inspiral/python/inspiral.py | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/gstlal-inspiral/python/inspiral.py b/gstlal-inspiral/python/inspiral.py
index bf04081c89..3ad99691c3 100644
--- a/gstlal-inspiral/python/inspiral.py
+++ b/gstlal-inspiral/python/inspiral.py
@@ -778,13 +778,20 @@ class Data(object):
 			if not buf_is_gap:
 				self.rankingstat.denominator.triggerrates[instrument].add_ratebin(map(float, buf_seg), len(events))
 
+			# extract times when instruments were producing
+			# SNR.  used to define "on instruments" for coinc
+			# tables among other things.  will only need
+			# segment information for the times for which we
+			# have triggers, so use stream_thinca's discard
+			# boundary and a bisection search to clip the lists
+			# to reduce subsequent operation count.
+			discard_boundary = float(self.stream_thinca.discard_boundary)
+			snr_segments = segments.segmentlistdict((instrument, ratebinlist[bisect.bisect_left(ratebinlist, (discard_boundary,)):].segmentlist()) for instrument, ratebinlist in self.rankingstat.denominator.triggerrates.items())
+
 			# times when at least 2 instruments were generating
 			# SNR.  used to sieve triggers for inclusion in the
-			# denominator.  fast path:  because all end times
-			# have been confirmed to be later than the start of
-			# the buffer we just collected, that can be used to
-			# clip the trigger rate history for speed
-			two_or_more_instruments = segmentsUtils.vote((ratebinlist[bisect.bisect_left(ratebinlist, (float(buf_timestamp),)):] for ratebinlist in self.rankingstat.denominator.triggerrates.values() if ratebinlist), 2)
+			# denominator.
+			two_or_more_instruments = segmentsUtils.vote(snr_segments.values(), 2)
 
 			# run stream thinca.  update the parameter
 			# distribution data from sngls that weren't used in
@@ -802,7 +809,7 @@ class Data(object):
 			# contaminating our noise model, so it's not
 			# necessary for this test to be super precisely
 			# defined.
-			for event in itertools.chain(self.stream_thinca.add_events(self.coincs_document.xmldoc, self.coincs_document.process_id, events, buf_timestamp, self.rankingstat.segmentlists, fapfar = self.fapfar), self.stream_thinca.last_coincs.single_sngl_inspirals() if self.stream_thinca.last_coincs else ()):
+			for event in itertools.chain(self.stream_thinca.add_events(self.coincs_document.xmldoc, self.coincs_document.process_id, events, buf_timestamp, snr_segments, fapfar = self.fapfar), self.stream_thinca.last_coincs.single_sngl_inspirals() if self.stream_thinca.last_coincs else ()):
 				if event.end in two_or_more_instruments:
 					self.rankingstat.denominator.increment(event)
 			self.coincs_document.commit()
-- 
GitLab