Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALMetaIO 4.0.6.1-ea7c608
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sngl_ringdown.c
Go to the documentation of this file.
1/*
2 * sngl_ringdown.c
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with with program; see the file COPYING. If not, write to the Free
16 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA
18 */
19
20#include <stdlib.h>
21#include <stdio.h>
22#include <string.h>
23
24
25#include <metaio.h>
26
27
28#include <lal/Date.h>
29#include <lal/LALMalloc.h>
30#include <lal/LIGOLwXML.h>
31#include <lal/LIGOLwXMLRead.h>
32#include <lal/LIGOMetadataTables.h>
33#include <lal/LIGOMetadataUtils.h>
34#include <lal/XLALError.h>
35
36
37/**
38 * Create a SnglRingdownTable structure.
39 */
41 const ProcessTable *process
42)
43{
44 SnglRingdownTable *new = XLALMalloc(sizeof(*new));
45
46 if(!new)
48
49 new->next = NULL;
50 memset(new->ifo, 0, sizeof(new->ifo));
51 memset(new->channel, 0, sizeof(new->channel));
52 if(process) {
53 /*new->process_id = process->process_id;*/
54 } else {
55 /*new->process_id = -1; */
56 }
57
58 return new;
59}
60
61
62/**
63 * Destroy a SnglRingdownTable structure.
64 */
67)
68{
69 SnglRingdownTable *next = row ? row->next : NULL;
70 XLALFree(row);
71 return next;
72}
73
74
75/**
76 * Destroy a SnglRingdownTable linked list.
77 */
80)
81{
82 while(head)
84}
85
86
87/**
88 * Read the sngl_ringdown table from a LIGO Light Weight XML file into a
89 * linked list of SnglRingdownTable structures.
90 */
92 const char *filename
93)
94{
95 static const char table_name[] = "sngl_ringdown";
96 int miostatus;
97 SnglRingdownTable *head = NULL;
98 SnglRingdownTable **next = &head;
99 struct MetaioParseEnvironment env;
100 struct {
101 int process_id;
102 int ifo;
103 int channel;
104 int start_time;
105 int start_time_ns;
106 int start_time_gmst;
107 int frequency;
108 int quality;
109 int phase;
110 int mass;
111 int spin;
112 int epsilon;
113 int num_clust_trigs;
114 int ds2_H1H2;
115 int ds2_H1L1;
116 int ds2_H1V1;
117 int ds2_H2L1;
118 int ds2_H2V1;
119 int ds2_L1V1;
120 int amplitude;
121 int snr;
122 int eff_dist;
123 int sigma_sq;
124 int event_id;
125 } column_pos;
126
127 /* open the file and find table */
128
129 if(MetaioOpenFile(&env, filename)) {
130 XLALPrintError("%s(): error opening \"%s\": %s\n", __func__, filename, env.mierrmsg.data ? env.mierrmsg.data : "unknown reason");
132 }
133 if(MetaioOpenTableOnly(&env, table_name)) {
134 MetaioAbort(&env);
135 XLALPrintError("%s(): cannot find %s table: %s\n", __func__, table_name, env.mierrmsg.data ? env.mierrmsg.data : "unknown reason");
137 }
138
139 /* find columns */
140
142 column_pos.process_id = XLALLIGOLwFindColumn(&env, "process_id", METAIO_TYPE_INT_8S, 1);
143 column_pos.ifo = XLALLIGOLwFindColumn(&env, "ifo", METAIO_TYPE_LSTRING, 1);
144 column_pos.channel = XLALLIGOLwFindColumn(&env, "channel", METAIO_TYPE_LSTRING, 1);
145 column_pos.start_time = XLALLIGOLwFindColumn(&env, "start_time", METAIO_TYPE_INT_4S, 1);
146 column_pos.start_time_ns = XLALLIGOLwFindColumn(&env, "start_time_ns", METAIO_TYPE_INT_4S, 1);
147 column_pos.start_time_gmst = XLALLIGOLwFindColumn(&env, "start_time_gmst", METAIO_TYPE_REAL_8, 1);
148 column_pos.frequency = XLALLIGOLwFindColumn(&env, "frequency", METAIO_TYPE_REAL_4, 1);
149 column_pos.quality = XLALLIGOLwFindColumn(&env, "quality", METAIO_TYPE_REAL_4, 1);
150 column_pos.phase = XLALLIGOLwFindColumn(&env, "phase", METAIO_TYPE_REAL_4, 1);
151 column_pos.mass = XLALLIGOLwFindColumn(&env, "mass", METAIO_TYPE_REAL_4, 1);
152 column_pos.spin = XLALLIGOLwFindColumn(&env, "spin", METAIO_TYPE_REAL_4, 1);
153 column_pos.epsilon = XLALLIGOLwFindColumn(&env, "epsilon", METAIO_TYPE_REAL_4, 1);
154 column_pos.num_clust_trigs = XLALLIGOLwFindColumn(&env, "num_clust_trigs", METAIO_TYPE_INT_4S, 1);
155 column_pos.ds2_H1H2 = XLALLIGOLwFindColumn(&env, "ds2_H1H2", METAIO_TYPE_REAL_4, 1);
156 column_pos.ds2_H1L1 = XLALLIGOLwFindColumn(&env, "ds2_H1L1", METAIO_TYPE_REAL_4, 1);
157 column_pos.ds2_H1V1 = XLALLIGOLwFindColumn(&env, "ds2_H1V1", METAIO_TYPE_REAL_4, 1);
158 column_pos.ds2_H2L1 = XLALLIGOLwFindColumn(&env, "ds2_H2L1", METAIO_TYPE_REAL_4, 1);
159 column_pos.ds2_H2V1 = XLALLIGOLwFindColumn(&env, "ds2_H2V1", METAIO_TYPE_REAL_4, 1);
160 column_pos.ds2_L1V1 = XLALLIGOLwFindColumn(&env, "ds2_L1V1", METAIO_TYPE_REAL_4, 1);
161 column_pos.amplitude = XLALLIGOLwFindColumn(&env, "amplitude", METAIO_TYPE_REAL_4, 1);
162 column_pos.snr = XLALLIGOLwFindColumn(&env, "snr", METAIO_TYPE_REAL_4, 1);
163 column_pos.eff_dist = XLALLIGOLwFindColumn(&env, "eff_dist", METAIO_TYPE_REAL_4, 1);
164 column_pos.sigma_sq = XLALLIGOLwFindColumn(&env, "sigma_sq", METAIO_TYPE_REAL_4, 1);
165 column_pos.event_id = XLALLIGOLwFindColumn(&env, "event_id", METAIO_TYPE_INT_8S, 1);
166
167 /* check for failure (== a required column is missing) */
168
169 if(XLALGetBaseErrno()) {
170 MetaioAbort(&env);
171 XLALPrintError("%s(): failure reading %s table\n", __func__, table_name);
173 }
174
175 /* loop over the rows in the file */
176
177 while((miostatus = MetaioGetRow(&env)) > 0) {
178 /* create a new row */
179
181
182 if(!row) {
184 MetaioAbort(&env);
186 }
187
188 /* append to linked list */
189
190 *next = row;
191 next = &(*next)->next;
192
193 /* populate the columns */
194
195 /*row->process_id = env.ligo_lw.table.elt[column_pos.process_id].data.int_8s;*/
196 strncpy(row->ifo, env.ligo_lw.table.elt[column_pos.ifo].data.lstring.data, sizeof(row->ifo) - 1);
197 strncpy(row->channel, env.ligo_lw.table.elt[column_pos.channel].data.lstring.data, sizeof(row->channel) - 1);
198 XLALGPSSet(&row->start_time, env.ligo_lw.table.elt[column_pos.start_time].data.int_4s, env.ligo_lw.table.elt[column_pos.start_time_ns].data.int_4s);
199 row->start_time_gmst = env.ligo_lw.table.elt[column_pos.start_time_gmst].data.real_8;
200 row->frequency = env.ligo_lw.table.elt[column_pos.frequency].data.real_4;
201 row->quality = env.ligo_lw.table.elt[column_pos.quality].data.real_4;
202 row->phase = env.ligo_lw.table.elt[column_pos.phase].data.real_4;
203 row->mass = env.ligo_lw.table.elt[column_pos.mass].data.real_4;
204 row->spin = env.ligo_lw.table.elt[column_pos.spin].data.real_4;
205 row->epsilon = env.ligo_lw.table.elt[column_pos.epsilon].data.real_4;
206 row->num_clust_trigs = env.ligo_lw.table.elt[column_pos.num_clust_trigs].data.int_4s;
207 row->ds2_H1H2 = env.ligo_lw.table.elt[column_pos.ds2_H1H2].data.real_4;
208 row->ds2_H1L1 = env.ligo_lw.table.elt[column_pos.ds2_H1L1].data.real_4;
209 row->ds2_H1V1 = env.ligo_lw.table.elt[column_pos.ds2_H1V1].data.real_4;
210 row->ds2_H2L1 = env.ligo_lw.table.elt[column_pos.ds2_H2L1].data.real_4;
211 row->ds2_H2V1 = env.ligo_lw.table.elt[column_pos.ds2_H2V1].data.real_4;
212 row->ds2_L1V1 = env.ligo_lw.table.elt[column_pos.ds2_L1V1].data.real_4;
213 row->amplitude = env.ligo_lw.table.elt[column_pos.amplitude].data.real_4;
214 row->snr = env.ligo_lw.table.elt[column_pos.snr].data.real_4;
215 row->eff_dist = env.ligo_lw.table.elt[column_pos.eff_dist].data.real_4;
216 row->sigma_sq = env.ligo_lw.table.elt[column_pos.sigma_sq].data.real_4;
217 row->event_id = env.ligo_lw.table.elt[column_pos.event_id].data.int_8s;
218 }
219 if(miostatus < 0) {
221 MetaioAbort(&env);
222 XLALPrintError("%s(): I/O error parsing %s table: %s\n", __func__, table_name, env.mierrmsg.data ? env.mierrmsg.data : "unknown reason");
224 }
225
226 /* close file */
227
228 if(MetaioClose(&env)) {
230 XLALPrintError("%s(): error parsing document after %s table: %s\n", __func__, table_name, env.mierrmsg.data ? env.mierrmsg.data : "unknown reason");
232 }
233
234 /* done */
235
236 return head;
237}
int XLALLIGOLwFindColumn(struct MetaioParseEnvironment *env, const char *name, unsigned int type, int required)
Convenience wrapper for MetaioFindColumn(), translating to XLAL-style error reporting and printing us...
void * XLALMalloc(size_t n)
void XLALFree(void *p)
#define XLAL_ERROR_NULL(...)
int XLALGetBaseErrno(void)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
int XLALClearErrno(void)
XLAL_EFUNC
XLAL_EIO
LIGOTimeGPS * XLALGPSSet(LIGOTimeGPS *epoch, INT4 gpssec, INT8 gpsnan)
filename
SnglRingdownTable * XLALDestroySnglRingdownTableRow(SnglRingdownTable *row)
Destroy a SnglRingdownTable structure.
Definition: sngl_ringdown.c:65
SnglRingdownTable * XLALCreateSnglRingdownTableRow(const ProcessTable *process)
Create a SnglRingdownTable structure.
Definition: sngl_ringdown.c:40
SnglRingdownTable * XLALSnglRingdownTableFromLIGOLw(const char *filename)
Read the sngl_ringdown table from a LIGO Light Weight XML file into a linked list of SnglRingdownTabl...
Definition: sngl_ringdown.c:91
void XLALDestroySnglRingdownTable(SnglRingdownTable *head)
Destroy a SnglRingdownTable linked list.
Definition: sngl_ringdown.c:78
This structure contains the required information for generating a ringdown template and storing ringd...
CHAR ifo[LIGOMETA_IFO_MAX]
CHAR channel[LIGOMETA_CHANNEL_MAX]
struct tagSnglRingdownTable * next