1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import gzip
18
19 from glue import segments
20
21 from glue.ligolw import ligolw
22 from glue.ligolw import lsctables
23 from glue.ligolw import utils
24 from glue.ligolw.utils import search_summary as ligolw_search_summary
25
26 try:
27 lsctables.use_in(ligolw.PartialLIGOLWContentHandler)
28 except AttributeError:
29
30
31 pass
32
34 """
35 Return a function suitable for a PartialLIGOLWContentHandler that filters
36 for any table in the given list of tables.
37 """
38 def filter_func(name, attrs):
39 for table in tables:
40 if lsctables.IsTableProperties(table, name, attrs):
41 return True
42 return False
43 return filter_func
44
46 """
47 Return a parsed document containing only the tables enumerated in
48 table_list that appear in the files in fileList.
49 """
50 _is_table = _table_filter_generator(table_list)
51 doc = ligolw.Document()
52 searchsummary_handler = ligolw.PartialLIGOLWContentHandler(doc, _is_table)
53
54 for thisFile in fileList:
55 if thisFile.endswith(".gz"):
56 fileobj = gzip.open(thisFile)
57 else:
58 fileobj = open(thisFile)
59 ligolw.make_parser(searchsummary_handler).parse(fileobj)
60 return doc
61
63 """
64 Read segment lists from search summary tables
65 @param fileList: list of input files.
66 """
67 required_tables = [lsctables.SearchSummaryTable, lsctables.ProcessTable]
68
69 segList = segments.segmentlistdict()
70 for thisFile in fileList:
71 doc = ReadTablesFromFiles([thisFile], required_tables, verbose)
72 try:
73 segs = ligolw_search_summary.segmentlistdict_fromsearchsummary(doc)
74 except:
75 raise ValueError, "Cannot extract segments from the SearchSummaryTable of %s" % thisFile
76
77
78 segList.extend(segs)
79
80 for value in segList.values():
81 value.sort()
82
83 return segList
84