#!/home/conda/feedstock_root/build_artifacts/bld/rattler-build_gstlal-ugly_1767612080/host_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pl/bin/python
import os
import argparse
from gstlal import dagparts
from lal.utils import CacheEntry

parser = argparse.ArgumentParser()
parser.add_argument("--output", help = "provide the output file")
parser.add_argument("--psd-xml-file", help = "provide a psd xml file")
parser.add_argument("--svd-cache", help = "provide the svd bank cache.")
parser.add_argument("--name", action = "append", help = "provide the name of the source category, e.g., NSBH")
parser.add_argument("--m1", action = "append", help = "provide the num:start:stop parameters for mass 1, e.g., 100:1:3")
parser.add_argument("--m2", action = "append", help = "provide the num:start:stop parameters for mass 2, e.g., 100:1:3")
parser.add_argument("--chi-eff", action = "append", help = "provide the num:start:stop parameters for chi effective, e.g., 11:-1:1")
parser.add_argument("--accounting-group", help = "set accounting group")
parser.add_argument("--accounting-group-user", help = "set accounting group user")
parser.add_argument("--condor-command", action = "append", help = "set condor commands of the form command=value, can be given multiple times")

args = parser.parse_args()

try:
	os.mkdir("logs")
except:
	pass

dag = dagparts.DAG("ac_counts")

condor_opts = {
	"accounting_group": args.accounting_group,
	"accounting_group_user": args.accounting_group_user,
	"want_graceful_removal": "True",
	"kill_sig": "15"
}
condor_commands = dagparts.condor_command_dict_from_opts(args.condor_command, condor_opts)
acJob = dagparts.DAGJob("gstlal_inspiral_activation_counts", condor_commands = condor_commands)

for bin_id, line in enumerate(open(args.svd_cache)):
	dagparts.DAGNode(acJob,
		dag,
		parent_nodes = [],
		opts = {"m1": args.m1, "m2": args.m2, "chi-eff":args.chi_eff, "name":args.name},
		input_files = {"psd-xml-file": args.psd_xml_file, "svd-file": CacheEntry(line).path},
		output_files = {"output": "%04d-COUNTS.txt" % bin_id}
		)

dag.write_sub_files()
dag.write_dag()
dag.write_script()
dag.write_cache()
