gstlal-inspiral  0.4.2
 All Classes Namespaces Files Functions Variables Pages
gstlal_ll_inspiral_gracedb_threshold
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2012 Kipp Cannon
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2 of the License, or (at your
8 # option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19 """Manipulate the GraceDB false-alarm rate upload threshold of running
20 gstlal_ll_inspiral processes via their web interfaces."""
21 
22 
23 #
24 # =============================================================================
25 #
26 # Preamble
27 #
28 # =============================================================================
29 #
30 
31 
32 from optparse import OptionParser
33 import os
34 import sys
35 import urllib
36 
37 ## @file
38 # This program queries running gstlal_inspiral jobs and displays or updates the gracedb FAR threshold; See gstlal_ll_inspiral_gracedb_threshold for more details
39 
40 #
41 # =============================================================================
42 #
43 # Command Line
44 #
45 # =============================================================================
46 #
47 
48 
49 def parse_command_line():
50  parser = OptionParser(
51  usage = "%prog [options] registry1.txt ...",
52  description = __doc__
53  )
54  parser.add_option("--gracedb-far-threshold", metavar = "Hertz", type = "float", help = "Set the GraceDB false-alarm rate upload threshold to Hertz (default = retrieve and print the false-alarm rate threshold).")
55  parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose (optional).")
56 
57  options, filenames = parser.parse_args()
58 
59  if len(filenames) < 1:
60  raise ValueError("must provide the name of at least one registry file")
61 
62  return options, filenames
63 
64 
65 #
66 # =============================================================================
67 #
68 # Main
69 #
70 # =============================================================================
71 #
72 
73 
74 #
75 # parse command line
76 #
77 
78 
79 options, filenames = parse_command_line()
80 
81 
82 if options.gracedb_far_threshold is not None:
83  post_data = urllib.urlencode({"rate": options.gracedb_far_threshold})
84 else:
85  post_data = None
86 
87 
88 #
89 # Iterate over servers
90 #
91 
92 
93 OK = True
94 
95 urls = set("%sgracedb_far_threshold.txt" % url.strip() for filename in filenames for url in open(filename))
96 
97 for url in sorted(urls):
98  print "%s:" % url
99  for line in urllib.urlopen(url, data = post_data):
100  OK &= "error" not in line
101  print "\t%s" % line.strip()
102 
103 if not OK:
104  sys.exit(1)