Package pylal :: Module SearchSummaryUtils
[hide private]
[frames] | no frames]

Source Code for Module pylal.SearchSummaryUtils

 1  # Copyright (C) 2006  Craig Robinson and Anand Sengupta 
 2  # 
 3  # This program is free software; you can redistribute it and/or modify it 
 4  # under the terms of the GNU General Public License as published by the 
 5  # Free Software Foundation; either version 2 of the License, or (at your 
 6  # option) any later version. 
 7  # 
 8  # This program is distributed in the hope that it will be useful, but 
 9  # WITHOUT ANY WARRANTY; without even the implied warranty of 
10  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General 
11  # Public License for more details. 
12  # 
13  # You should have received a copy of the GNU General Public License along 
14  # with this program; if not, write to the Free Software Foundation, Inc., 
15  # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. 
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    # old glue did not allow .use_in(). 
30    # FIXME:  remove when we can require the latest version of glue 
31    pass 
32   
33 -def _table_filter_generator(tables):
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
45 -def ReadTablesFromFiles(fileList, table_list, verbose=False):
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
62 -def GetSegListFromSearchSummaries(fileList, verbose=False):
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 #Now add these segments to the existing list 78 segList.extend(segs) 79 80 for value in segList.values(): 81 value.sort() 82 83 return segList
84