LALApps 10.1.0.1-eeff03c
coh_PTF_output.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Duncan Brown, Jolien Creighton, Lisa M. Goggin
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20#include "config.h"
21#include "coh_PTF.h"
22#include <lal/LIGOLwXML.h>
23#include "LIGOLwXMLlegacy.h"
24
25/*
26 *
27 * Routines to output event triggers.
28 * Note that a lot of functions should be merged with ring_output
29 *
30 */
31
32
33/* creates a process params table from command line arguments */
35 const char *program )
36{
37 ProcessParamsTable *processParamsTable = NULL;
38 int c;
39 for ( c = 1; c < argc; ++c )
40 {
41 char *arg = argv[c];
42 char *opt = NULL;
43 char *val = NULL;
44
45 /* duplicate arg in opt */
46 opt = LALMalloc( strlen( arg ) + 1 );
47 strcpy( opt, arg );
48
49 if ( ! is_option( opt ) )
50 error( "%s is not an option\n", opt );
51
52 /* search for equals-sign to identify val */
53 if ( ( val = strchr( opt, '=' ) ) )
54 *val++ = 0; /* nul terminate opt and set val to value */
55 else if ( c < argc - 1 && ! is_option( argv[c+1] ) ) /* next arg is value */
56 val = argv[++c]; /* set value and increment counter */
57 else /* no value for this option */
58 val = NULL;
59
60 /* now write the option and value */
61 if ( opt )
62 {
63 ProcessParamsTable *thisParam;
64 thisParam = LALCalloc( 1, sizeof( *thisParam ) );
65 thisParam->next = processParamsTable;
66 processParamsTable = thisParam;
67
68 strncpy( thisParam->program, program, LIGOMETA_PROGRAM_MAX - 1 );
69 strncpy( thisParam->param, opt, LIGOMETA_PARAM_MAX - 1 );
70 strncpy( thisParam->type, "string", LIGOMETA_TYPE_MAX - 1 );
71 if ( val )
72 strncpy( thisParam->value, val, LIGOMETA_VALUE_MAX - 1 );
73 }
74
75 LALFree( opt );
76 }
77
78 return processParamsTable;
79}
80
82 LIGOLwXMLStream *xml,
83 const TimeSlideSegmentMapTable *time_slide_seg_map
84)
85{
86 const char *row_head = "\n\t\t\t";
87
88 /* table header */
89
91 XLALFilePuts("\t<Table Name=\"time_slide_segment_map:table\">\n", xml->fp);
92 XLALFilePuts("\t\t<Column Name=\"time_slide_segment_map:segment_def_id\" Type=\"ilwd:char\"/>\n", xml->fp);
93 XLALFilePuts("\t\t<Column Name=\"time_slide_segment_map:time_slide_id\" Type=\"ilwd:char\"/>\n", xml->fp);
94 XLALFilePuts("\t\t<Stream Name=\"time_slide_segment_map:table\" Type=\"Local\" Delimiter=\",\">", xml->fp);
97
98 /* rows */
99
100 for(; time_slide_seg_map; time_slide_seg_map = time_slide_seg_map->next) {
101 if(XLALFilePrintf(xml->fp, "%s\"segment_def:segment_def_id:%ld\",\"time_slide:time_slide_id:%ld\"",
102 row_head,
103 time_slide_seg_map->segment_def_id,
104 time_slide_seg_map->time_slide_id
105 ) < 0)
107 row_head = ",\n\t\t\t";
108 }
109
110 /* table footer */
111
112 if(XLALFilePuts("\n\t\t</Stream>\n\t</Table>\n", xml->fp) < 0)
114
115 /* done */
116
117 return 0;
118}
119
120
121/* routine to output events as LIGOLw XML file */
123 char *outputFile,
124 MultiInspiralTable *events,
125 SnglInspiralTable *snglEvents,
127 ProcessParamsTable *processParamsTable,
128 TimeSlide *time_slide_head,
129 TimeSlideSegmentMapTable *time_slide_map_head,
130 SegmentTable *segment_table_head,
131 struct coh_PTF_params *params
132 )
133{
135 LIGOLwXMLStream *results;
136
137 verbose( "output events to LIGOLw XML file %s\n", outputFile );
138
139 /* open results xml file */
140 results = XLALOpenLIGOLwXMLFile(outputFile);
141
142 /* output the process table */
144 XLALWriteLIGOLwXMLProcessTable(results,processTable);
145 LALFree(processTable);
146
147 /* output process params table */
148 XLALWriteLIGOLwXMLProcessParamsTable(results, processParamsTable);
149
150 /* output search summary table */
152 XLALWriteLIGOLwXMLSearchSummaryTable(results,searchSummTable);
153 LALFree(searchSummTable);
154
155 /* write the signals injected in a template bank simulation */
156 if ( injections )
158
159 /* output time slide table */
160 XLALWriteLIGOLwXMLTimeSlideTable( results, time_slide_head);
161
162 /* output time slide map table */
163 XLALWriteLIGOLwXMLTimeSlideSegmentMapTable( results, time_slide_map_head);
164
165 /* output segment list */
166 XLALWriteLIGOLwXMLSegmentTable( results, segment_table_head);
167
168 /* output the events */
169 if (! params->writeSnglInspiralTable)
170 {
171 MetadataTable ringEvents;
172 memset( &ringEvents, 0, sizeof( ringEvents ) );
173 ringEvents.multiInspiralTable = events;
176 LAL_CALL( LALEndLIGOLwXMLTable( &status, results ), &status );
177 }
178 else
179 {
180 (void) events; /* silence unused variable warning */
181 XLALWriteLIGOLwXMLSnglInspiralTable( results, snglEvents );
182 }
183
184 /* close the xml file */
185 XLALCloseLIGOLwXMLFile(results);
186
187 return 0;
188}
189
190/* routine to output template bank as LIGOLw XML file */
192 char *outputFile,
193 SnglInspiralTable *tmplts,
194 ProcessParamsTable *processParamsTable,
195 struct coh_PTF_params *params
196 )
197{
199 ProcessParamsTable *processParams;
200 SearchSummaryTable *searchSummary;
201 LIGOLwXMLStream *results;
202
203 verbose( "output template bank to LIGOLw XML file %s\n", outputFile );
204
205 /* create process table and search summary tables */
207 processParams = processParamsTable;
208 searchSummary = coh_PTF_create_search_summary( params );
209
210 /* open results xml file */
211 results = XLALOpenLIGOLwXMLFile( outputFile );
212
213 /* output the process table */
215
216 /* output process params table */
217 XLALWriteLIGOLwXMLProcessParamsTable( results, processParams );
218
219 /* output search summary table */
220 XLALWriteLIGOLwXMLSearchSummaryTable( results, searchSummary );
221
222 /* output the events */
223 if ( tmplts )
224 XLALWriteLIGOLwXMLSnglInspiralTable( results, tmplts );
225
226 /* close the xml file */
227 XLALCloseLIGOLwXMLFile( results );
228
230 XLALDestroyProcessParamsTable( processParams );
231 XLALDestroySearchSummaryTable( searchSummary );
232
233 return 0;
234}
235
236
237
238/* routine to create process table */
240{
241 ProcessTable *processTable = NULL;
242
243 processTable = LALCalloc( 1, sizeof( *processTable ) );
244
245 /* call lalapps routine to populate the process table */
246
247 XLALPopulateProcessTable(processTable, params->programName,
249
250 strncpy( processTable->comment, " ", LIGOMETA_COMMENT_MAX );
251
252 /* store ifos */
253 if ( params->numIFO == 1 )
254 {
255 snprintf( processTable->ifos, LIGOMETA_IFOS_MAX,\
256 "%s", params->ifoName[0] );
257 }
258 else if( params->numIFO == 2 )
259 {
260 XLALStringPrint( processTable->ifos, LIGOMETA_IFOS_MAX,\
261 "%s%s", params->ifoName[0], params->ifoName[1] );
262 }
263 else if ( params->numIFO == 3 )
264 {
265 XLALStringPrint( processTable->ifos, LIGOMETA_IFOS_MAX,\
266 "%s%s%s", params->ifoName[0], params->ifoName[1],
267 params->ifoName[2] );
268 }
269 else if ( params->numIFO == 4 )
270 {
271 XLALStringPrint( processTable->ifos, LIGOMETA_IFOS_MAX,\
272 "%s%s%s%s", params->ifoName[0], params->ifoName[1],
273 params->ifoName[2], params->ifoName[3]);
274 }
275
276 processTable->start_time = params->jobStartTime;
277 XLALGPSTimeNow(&processTable->end_time);
278
279 return processTable;
280}
281
282
283/* routine to create search summary table */
285{
286 SearchSummaryTable *searchSummary = NULL;
287 LIGOTimeGPS outStartTime;
288 LIGOTimeGPS outEndTime;
289 INT8 outStartTimeNS;
290 INT8 outEndTimeNS;
291
292 /* setup search summary table */
293 searchSummary = LALCalloc( 1, sizeof( *searchSummary ) );
294 strncpy( searchSummary->comment, params->programName, LIGOMETA_COMMENT_MAX-1 );
295 searchSummary->nnodes = 1;
296
297 /* compute the start and end times of data analyzed */
298 outStartTimeNS = epoch_to_ns( &params->startTime )
299 + sec_to_ns( params->analStartPoint / (REAL4)params->sampleRate );
300 outEndTimeNS = epoch_to_ns( &params->endTime )
301 - sec_to_ns( (params->numTimePoints - params->analEndPoint)
302 / (REAL4)params->sampleRate );
303 if( params->trigStartTimeNS && (params->trigStartTimeNS > outStartTimeNS))
304 outStartTimeNS = (outEndTimeNS < params->trigStartTimeNS) ?
305 outEndTimeNS : params->trigStartTimeNS;
306 if( params->trigEndTimeNS && (params->trigEndTimeNS < outEndTimeNS))
307 outEndTimeNS = (outStartTimeNS > params->trigEndTimeNS) ?
308 outStartTimeNS : params->trigEndTimeNS;
309 ns_to_epoch( &outStartTime, outStartTimeNS );
310 ns_to_epoch( &outEndTime, outEndTimeNS );
311
312 /* store input start time and end time of raw data in search summary */
313 searchSummary->in_start_time = params->startTime;
314 searchSummary->in_end_time = params->endTime;
315 searchSummary->out_start_time = outStartTime;
316 /*XLALGPSAdd( &searchSummary->out_start_time, -1.0 * params->padData ); */
317 searchSummary->out_end_time = outEndTime;
318 /*XLALGPSAdd( &searchSummary->out_end_time, 1.0 * params->padData); */
319 searchSummary->nevents = params->numEvents;
320
321 /* store ifos */
322 if ( params->numIFO == 1 )
323 {
324 snprintf( searchSummary->ifos, LIGOMETA_IFOS_MAX,\
325 "%s", params->ifoName[0] );
326 }
327 else if( params->numIFO == 2 )
328 {
329 XLALStringPrint( searchSummary->ifos, LIGOMETA_IFOS_MAX,\
330 "%s%s", params->ifoName[0], params->ifoName[1] );
331 }
332 else if ( params->numIFO == 3 )
333 {
334 XLALStringPrint( searchSummary->ifos, LIGOMETA_IFOS_MAX,\
335 "%s%s%s", params->ifoName[0], params->ifoName[1],
336 params->ifoName[2] );
337 }
338 else if ( params->numIFO == 4 )
339 {
340 XLALStringPrint( searchSummary->ifos, LIGOMETA_IFOS_MAX,\
341 "%s%s%s%s", params->ifoName[0], params->ifoName[1],
342 params->ifoName[2], params->ifoName[3]);
343 }
344
345 return searchSummary;
346}
347
348
349/*
350 *
351 * Routines to write intermediate results (time/frequency series and bank).
352 *
353 */
354
355/* routine to write a time series */
357{
358 char fname[FILENAME_SIZE];
359 int t, dt;
360 t = series->epoch.gpsSeconds;
361 dt = ceil(1e-9*series->epoch.gpsNanoSeconds + series->data->length*series->deltaT);
362 generate_file_name( fname, sizeof( fname ), series->name, t, dt );
363 verbose( "writing series %s to file %s\n", series->name, fname );
365 return 0;
366}
367
368
369/* routine to write a real frequency series */
371{
372 char fname[FILENAME_SIZE];
373 int t, dt;
374 t = series->epoch.gpsSeconds;
375 dt = ceil(1e-9*series->epoch.gpsNanoSeconds + 1.0/series->deltaF);
376 generate_file_name( fname, sizeof( fname ), series->name, t, dt );
377 verbose( "writing series %s to file %s\n", series->name, fname );
379 return 0;
380}
381
382
383/* routine to write a complex frequency series */
385{
386 char fname[FILENAME_SIZE];
387 int t, dt;
388 t = series->epoch.gpsSeconds;
389 dt = ceil(1e-9*series->epoch.gpsNanoSeconds + 1.0/series->deltaF);
390 generate_file_name( fname, sizeof( fname ), series->name, t, dt );
391 verbose( "writing series %s to file %s\n", series->name, fname );
393 return 0;
394}
395
396/* routine to construct an appropriately-formatted filename from series name */
397int generate_file_name( char *fname, size_t size,
398 const char *sname, int t, int dt )
399{
400 char *c;
401 char *tmp_name;
402
403 tmp_name = (char *) LALCalloc( size, sizeof(char) );
404
405 strncpy( tmp_name, sname, size - 1 );
406 tmp_name[size-1] = 0;
407
408 /* slashes are not allowed */
409 if ( strchr( tmp_name, '/' ) )
410 error( "slashes are not allowed in output file name %s\n", tmp_name );
411
412 /* convert hyphens to underscores */
413 while ( ( c = strchr( tmp_name, '-' ) ) )
414 *c = '_';
415
416 /* convert colons to hypens */
417 while ( ( c = strchr( tmp_name, ':' ) ) )
418 *c = '-';
419
420 /* convert spaces to underscores */
421 while ( ( c = strchr( tmp_name, ' ' ) ) )
422 *c = '_';
423
424 snprintf( fname, size, "%s-%d-%d.dat", tmp_name, t, dt );
425
426 LALFree( tmp_name );
427
428 return 0;
429}
const char * program
const LALVCSInfo lalAppsVCSIdentInfo
Identable VCS and build information for LALApps.
#define LAL_CALL(function, statusptr)
#define LALCalloc(m, n)
#define LALMalloc(n)
#define LALFree(p)
int XLALCloseLIGOLwXMLFile(LIGOLwXMLStream *xml)
LIGOLwXMLStream * XLALOpenLIGOLwXMLFile(const char *path)
int XLALWriteLIGOLwXMLProcessTable(LIGOLwXMLStream *, const ProcessTable *)
int XLALWriteLIGOLwXMLProcessParamsTable(LIGOLwXMLStream *, const ProcessParamsTable *)
int XLALWriteLIGOLwXMLSegmentTable(LIGOLwXMLStream *xml, const SegmentTable *segment_table)
int XLALWriteLIGOLwXMLSimInspiralTable(LIGOLwXMLStream *, const SimInspiralTable *)
int XLALWriteLIGOLwXMLSnglInspiralTable(LIGOLwXMLStream *xml, const SnglInspiralTable *sngl_inspiral)
int XLALWriteLIGOLwXMLSearchSummaryTable(LIGOLwXMLStream *, const SearchSummaryTable *)
int XLALWriteLIGOLwXMLTimeSlideTable(LIGOLwXMLStream *, const TimeSlide *)
void LALWriteLIGOLwXMLTable(LALStatus *status, LIGOLwXMLStream *xml, MetadataTable tablePtr, MetadataTableType table)
void LALBeginLIGOLwXMLTable(LALStatus *status, LIGOLwXMLStream *xml, MetadataTableType table)
void LALEndLIGOLwXMLTable(LALStatus *status, LIGOLwXMLStream *xml)
Provides prototypes for obsolete code.
@ multi_inspiral_table
#define LIGOMETA_IFOS_MAX
#define LIGOMETA_COMMENT_MAX
#define LIGOMETA_TYPE_MAX
#define LIGOMETA_PROGRAM_MAX
#define LIGOMETA_VALUE_MAX
#define LIGOMETA_PARAM_MAX
void XLALDestroyProcessParamsTable(ProcessParamsTable *)
void XLALDestroyProcessTable(ProcessTable *)
int XLALPopulateProcessTable(ProcessTable *ptable, const char *program_name, const char *cvs_revision, const char *cvs_source, const char *cvs_date, long process_id)
void XLALDestroySearchSummaryTable(SearchSummaryTable *)
double e
int verbose
Definition: chirplen.c:77
#define FILENAME_SIZE
Definition: coh_PTF.h:81
#define is_option(s)
Definition: coh_PTF.h:94
int coh_PTF_output_events_xml(char *outputFile, MultiInspiralTable *events, SnglInspiralTable *snglEvents, SimInspiralTable *injections, ProcessParamsTable *processParamsTable, TimeSlide *time_slide_head, TimeSlideSegmentMapTable *time_slide_map_head, SegmentTable *segment_table_head, struct coh_PTF_params *params)
static int XLALWriteLIGOLwXMLTimeSlideSegmentMapTable(LIGOLwXMLStream *xml, const TimeSlideSegmentMapTable *time_slide_seg_map)
int write_COMPLEX8FrequencySeries(COMPLEX8FrequencySeries *series)
ProcessTable * coh_PTF_create_process_table(struct coh_PTF_params *params)
int write_REAL4FrequencySeries(REAL4FrequencySeries *series)
ProcessParamsTable * create_process_params(int argc, char **argv, const char *program)
int generate_file_name(char *fname, size_t size, const char *sname, int t, int dt)
int coh_PTF_output_tmpltbank(char *outputFile, SnglInspiralTable *tmplts, ProcessParamsTable *processParamsTable, struct coh_PTF_params *params)
SearchSummaryTable * coh_PTF_create_search_summary(struct coh_PTF_params *params)
int write_REAL4TimeSeries(REAL4TimeSeries *series)
int error(const char *fmt,...)
Definition: errutil.c:37
INT8 sec_to_ns(REAL8 sec)
Definition: gpstime.c:57
LIGOTimeGPS * ns_to_epoch(LIGOTimeGPS *epoch, INT8 ns)
Definition: gpstime.c:48
INT8 epoch_to_ns(LIGOTimeGPS *epoch)
Definition: gpstime.c:38
LIGOTimeGPS * XLALGPSTimeNow(LIGOTimeGPS *gpstime)
int XLALFilePuts(const char *s, LALFILE *file)
int XLALFilePrintf(LALFILE *file, const char *fmt,...)
#define XLAL_INIT_DECL(var,...)
int64_t INT8
float REAL4
int XLALStringPrint(char *s, size_t n, const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(3
void LALCPrintFrequencySeries(COMPLEX8FrequencySeries *series, const CHAR *filename)
void LALSPrintFrequencySeries(REAL4FrequencySeries *series, const CHAR *filename)
void LALSPrintTimeSeries(REAL4TimeSeries *series, const CHAR *filename)
int XLALGetBaseErrno(void)
#define XLAL_ERROR(...)
int XLALClearErrno(void)
XLAL_EFUNC
SimInspiralTable * injections
Definition: inspfrinj.c:339
static LALStatus status
Definition: inspinj.c:552
size
c
int t
CHAR fname[256]
Definition: spininj.c:211
const char *const vcsDate
const char *const vcsStatus
const char *const vcsId
CHAR type[LIGOMETA_TYPE_MAX]
CHAR param[LIGOMETA_PARAM_MAX]
CHAR value[LIGOMETA_VALUE_MAX]
struct tagProcessParamsTable * next
CHAR program[LIGOMETA_PROGRAM_MAX]
LIGOTimeGPS start_time
CHAR ifos[LIGOMETA_IFOS_MAX]
LIGOTimeGPS end_time
CHAR comment[LIGOMETA_COMMENT_MAX]
CHAR comment[LIGOMETA_COMMENT_MAX]
LIGOTimeGPS out_start_time
LIGOTimeGPS in_end_time
CHAR ifos[LIGOMETA_IFOS_MAX]
LIGOTimeGPS in_start_time
LIGOTimeGPS out_end_time
struct tagTimeSlideSegmentMapTable * next
Definition: series.h:36
char * name
Definition: series.h:37
float * data
Definition: series.h:46
MultiInspiralTable * multiInspiralTable