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

Source Code for Module pylal.SimInspiralUtils

 1  # Copyright (C) 2006  Duncan A. Brown 
 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  # 
18  # ============================================================================= 
19  # 
20  #                                   Preamble 
21  # 
22  # ============================================================================= 
23  # 
24   
25  from glue.ligolw import table 
26  from glue.ligolw import lsctables 
27  from glue.ligolw import utils 
28  from glue.ligolw import ligolw 
29   
30  # 
31  # ============================================================================= 
32  # 
33  #                                   Input 
34  # 
35  # ============================================================================= 
36  # 
37   
38 -class ExtractSimInspiralTableLIGOLWContentHandler(ligolw.PartialLIGOLWContentHandler):
39 """ 40 LIGOLWContentHandler that will extract only the SimInspiralTable from a document. 41 See glue.ligolw.LIGOLWContentHandler help for more info. 42 """
43 - def __init__(self,document):
44 def filterfunc(name,attrs): 45 return name==ligolw.Table.tagName and attrs.has_key('Name') and table.Table.TableName(attrs.get('Name'))==lsctables.SimInspiralTable.tableName
46 ligolw.PartialLIGOLWContentHandler.__init__(self,document,filterfunc)
47 48
49 -def ReadSimInspiralFromFiles(fileList, verbose=False):
50 """ 51 Read the simInspiral tables from a list of files 52 53 @param fileList: list of input files 54 @param verbose: print ligolw_add progress 55 """ 56 simInspiralTriggers = None 57 58 lsctables.use_in(ExtractSimInspiralTableLIGOLWContentHandler) 59 for thisFile in fileList: 60 doc = utils.load_filename(thisFile, gz=(thisFile or "stdin").endswith(".gz"), verbose=verbose, contenthandler=ExtractSimInspiralTableLIGOLWContentHandler) 61 # extract the sim inspiral table 62 try: simInspiralTable = lsctables.SimInspiralTable.get_table(doc) 63 except: simInspiralTable = None 64 if simInspiralTriggers and simInspiralTable: 65 simInspiralTriggers.extend(simInspiralTable) 66 elif not simInspiralTriggers: 67 simInspiralTriggers = simInspiralTable 68 69 return simInspiralTriggers
70