#!/usr/bin/env python3
#
# Copyright (C) 2020  Chad Hanna
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

import sys
from gstlal import far
from ligo import lw
from ligo.lw import utils as ligolw_utils
from ligo.lw.utils import process as ligolw_process

fname = sys.argv[1]

_, zlpdf = far.parse_likelihood_control_doc(ligolw_utils.load_url(fname, verbose = True, contenthandler = far.RankingStat.LIGOLWContentHandler))

# Zero it out
zlpdf.zero_lag_lr_lnpdf.count.array[:] = 0.

# write out the file to disk
xmldoc = lw.ligolw.Document()
xmldoc.appendChild(lw.ligolw.LIGO_LW())
process = ligolw_process.register_to_xmldoc(xmldoc, sys.argv[0], paramdict = {})
far.gen_likelihood_control_doc(xmldoc, None, zlpdf)
ligolw_process.set_process_end_time(process)
ligolw_utils.write_url(xmldoc, fname, verbose = True, trap_signals = None)
