Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALInference 4.1.9.1-00ddc7f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
lalinference_multi_pipe.py
Go to the documentation of this file.
1##python
2# DAG generation code for running LALInference pipeline
3# (C) 2012 John Veitch
4# 2013 Salvatore Vitale: extended to work with several ini files
5
6from lalinference import lalinference_pipe_utils as pipe_utils
7import configparser
8from optparse import OptionParser
9import sys
10
11usage=""" %prog [options] config1.ini config2.ini ... configN.ini
12Setup a Condor DAG file to run the LALInference pipeline based on
13N config.ini files.
14
15The user must specify either an injection file to analyse, with the --inj option,
16a list of SnglInspiralTable or CoincInspiralTable triggers with the --<x>-triggers options,
17or an ASCII list of GPS times with the --gps-time-file option.
18
19The user must also specify and ini file which will contain the main analysis config.
20
21"""
22
23import os
24def vararg_callback(option, opt_str, value, parser):
25 assert value is None
26 value = []
27 def floatable(str):
28 try:
29 float(str)
30 return True
31 except ValueError:
32 return False
33 for arg in parser.rargs:
34 # stop on --foo like options
35 if arg[:2] == "--" and len(arg) > 2:
36 break
37 # stop on -a, but not on -3 or -3.0
38 if arg[:1] == "-" and len(arg) > 1 and not floatable(arg):
39 break
40 value.append(arg)
41 del parser.rargs[:len(value)]
42 setattr(parser.values, option.dest, value)
43
44parser=OptionParser(usage)
45parser.add_option("-r","--run-path",default=None,action="store",type="string",help="Directory to run pipeline in (default: $PWD)",metavar="RUNDIR")
46parser.add_option("-p","--daglog-path",default=None,action="store",type="string",help="Path to directory to contain DAG log file. SHOULD BE LOCAL TO SUBMIT NODE",metavar="LOGDIR")
47parser.add_option("-g","--gps-time-file",action="store",type="string",default=None,help="Text file containing list of GPS times to analyse",metavar="TIMES.txt")
48parser.add_option("-t","--single-triggers",action="store",type="string",default=None,help="SnglInspiralTable trigger list",metavar="SNGL_FILE.xml")
49parser.add_option("-C","--coinc-triggers",action="store",type="string",default=None,help="CoinInspiralTable trigger list",metavar="COINC_FILE.xml")
50parser.add_option("-L","--lvalert",action="store",type="string",default=None,help="LVAlert coinc file",metavar="coinc_G0000.xml")
51parser.add_option("--gid",action="store",type="string",default=None,help="Optional GraceDB ID for submitting results")
52parser.add_option("-I","--injections",action="store",type="string",default=None,help="List of injections to perform and analyse",metavar="INJFILE.xml")
53parser.add_option("-P","--pipedown-db",action="store",type="string",default=None,help="Pipedown database to read and analyse",metavar="pipedown.sqlite")
54parser.add_option("-F","--folder-names",dest="fnames",action="callback", callback=vararg_callback,help="Space separated list of folders that will be created, corresponding to the TIGER parameters that are being tested or GR. The order has to be the same used with the ini files!",default=None,metavar="GR phi1")
55parser.add_option("--condor-submit",action="store_true",default=False,help="Automatically submit the condor dag")
56
57(opts,args)=parser.parse_args()
58
59if len(args)>1:
60 print('Using %s ini files\n'%len(args))
61elif len(args)==1:
62 inifile=args[0]
63
64inits=args
65ninits=len(inits)
66fnames=opts.fnames
67nfnames=len(fnames)
68
69if not ninits==nfnames:
70 print("You seem to be using %d parser files and %d foldernames. These two numbers must be the same. Exiting...\n"%(ninits,nfnames))
71 sys.exit(1)
72
73fnames_dic={}
74for fname in fnames:
75 fnames_dic[fnames.index(fname)]=str(fname)
76
77glob_hyp=fnames
78hyp_str=" "
79
80for hy in glob_hyp:
81 hyp_str+=hy+" "
82
83cp=configparser.ConfigParser()
84cp.optionxform = str
85
86first_dag=True
87common_path=opts.run_path
88
89for inifile in inits:
90 try:
91 cp.read_file(open(inifile))
92 except AttributeError:
93 cp.readfp(open(inifile))
94 if opts.run_path is not None:
95 cp.set('paths','basedir',opts.run_path)
96 if opts.daglog_path is not None:
97 cp.set('paths','daglogdir',opts.daglog_path)
98 else:
99 cp.set('paths','daglogdir',opts.run_path)
100 if opts.gps_time_file is not None:
101 cp.set('input','gps-time-file',opts.gps_time_file)
102 if opts.single_triggers is not None:
103 cp.set('input','sngl-inspiral-file',opts.single_triggers)
104 if opts.injections is not None:
105 cp.set('input','injection-file',opts.injections)
106 if opts.coinc_triggers is not None:
107 cp.set('input','coinc-inspiral-file',opts.coinc_triggers)
108 if opts.lvalert is not None:
109 cp.set('input','lvalert-file',opts.lvalert)
110 if opts.gid is not None:
111 cp.set('input','gid',opts.gid)
112 if opts.pipedown_db is not None:
113 cp.set('input','pipedown-db',opts.pipedown_db)
114
115 if opts.run_path is not None:
116 cp.set('paths','basedir',os.path.join(str(common_path),str(fnames_dic[inits.index(inifile)])))
117 # Create the DAG from the configparser object
118 if first_dag:
119 dag=pipe_utils.LALInferencePipelineDAG(cp)
120 first_dag=False
121 dag.write_sub_files()
122 dag2=dag
123 else:
124 dag2=pipe_utils.LALInferencePipelineDAG(cp,first_dag=False,previous_dag=dag)
125 dag2.write_sub_files()
126 dag=dag2
127
128# Create the DAG from the configparser object
129dag2.set_dag_file(os.path.join(common_path,'common_dag'))
130dag2.write_dag()
131dag2.write_script()
132# End of program
133print('Successfully created DAG file.')
134print('Now run condor_submit_dag %s\n'%(dag2.get_dag_file()))
135
136if opts.condor_submit:
137 import subprocess
138
139 x = subprocess.Popen(['condor_submit_dag',dag.get_dag_file()])
140 x.wait()
141 if x.returncode==0:
142 print('Submitted DAG file')
143 else:
144 print('Unable to submit DAG file')