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>
48 new->process_id =
new->time_slide_id =
new->simulation_id = -1;
49 memset(new->waveform, 0,
sizeof(new->waveform));
64 new->waveform_number = 0;
99 static const char table_name[] =
"sim_burst";
103 struct MetaioParseEnvironment env;
110 int time_geocent_gps;
111 int time_geocent_gps_ns;
112 int time_geocent_gmst;
117 int pol_ellipse_angle;
121 int egw_over_rsquared;
129 if(MetaioOpenFile(&env,
filename)) {
130 XLALPrintError(
"%s(): error opening \"%s\": %s\n", __func__,
filename, env.mierrmsg.data ? env.mierrmsg.data :
"unknown reason");
133 if(MetaioOpenTableOnly(&env, table_name)) {
135 XLALPrintError(
"%s(): cannot find %s table: %s\n", __func__, table_name, env.mierrmsg.data ? env.mierrmsg.data :
"unknown reason");
147 column_pos.time_geocent_gps =
XLALLIGOLwFindColumn(&env,
"time_geocent_gps", METAIO_TYPE_INT_4S, 1);
148 column_pos.time_geocent_gps_ns =
XLALLIGOLwFindColumn(&env,
"time_geocent_gps_ns", METAIO_TYPE_INT_4S, 1);
149 column_pos.time_geocent_gmst =
XLALLIGOLwFindColumn(&env,
"time_geocent_gmst", METAIO_TYPE_REAL_8, 0);
154 column_pos.pol_ellipse_angle =
XLALLIGOLwFindColumn(&env,
"pol_ellipse_angle", METAIO_TYPE_REAL_8, 0);
158 column_pos.egw_over_rsquared =
XLALLIGOLwFindColumn(&env,
"egw_over_rsquared", METAIO_TYPE_REAL_8, 0);
159 column_pos.waveform_number =
XLALLIGOLwFindColumn(&env,
"waveform_number", METAIO_TYPE_INT_8U, 0);
167 XLALPrintError(
"%s(): failure reading %s table: missing required column\n", __func__, table_name);
173 while((miostatus = MetaioGetRow(&env)) > 0) {
186 row->
process_id = env.ligo_lw.table.elt[column_pos.process_id].data.int_8s;
187 if(strlen(env.ligo_lw.table.elt[column_pos.waveform].data.lstring.data) >=
sizeof(row->
waveform)) {
191 XLALPrintError(
"%s(): failure reading %s table: string too long\n", __func__, table_name);
194 strncpy(row->
waveform, env.ligo_lw.table.elt[column_pos.waveform].data.lstring.data,
sizeof(row->
waveform) - 1);
195 if(column_pos.ra >= 0)
196 row->
ra = env.ligo_lw.table.elt[column_pos.ra].data.real_8;
197 if(column_pos.dec >= 0)
198 row->
dec = env.ligo_lw.table.elt[column_pos.dec].data.real_8;
199 if(column_pos.psi >= 0)
200 row->
psi = env.ligo_lw.table.elt[column_pos.psi].data.real_8;
201 XLALGPSSet(&row->
time_geocent_gps, env.ligo_lw.table.elt[column_pos.time_geocent_gps].data.int_4s, env.ligo_lw.table.elt[column_pos.time_geocent_gps_ns].data.int_4s);
202 if(column_pos.time_geocent_gmst >= 0)
203 row->
time_geocent_gmst = env.ligo_lw.table.elt[column_pos.time_geocent_gmst].data.real_8;
204 row->
time_slide_id = env.ligo_lw.table.elt[column_pos.time_slide_id].data.int_8s;
205 row->
simulation_id = env.ligo_lw.table.elt[column_pos.simulation_id].data.int_8s;
207 if(!strcmp(row->
waveform,
"StringCusp")) {
208 if(column_pos.duration < 0 || column_pos.frequency < 0 || column_pos.amplitude < 0) {
212 XLALPrintError(
"%s(): failure reading %s table: missing required column\n", __func__, table_name);
215 row->
duration = env.ligo_lw.table.elt[column_pos.duration].data.real_8;
216 row->
frequency = env.ligo_lw.table.elt[column_pos.frequency].data.real_8;
217 row->
amplitude = env.ligo_lw.table.elt[column_pos.amplitude].data.real_8;
218 }
else if(!strcmp(row->
waveform,
"SineGaussian")||!strcmp(row->
waveform,
"SineGaussianF")) {
219 if(column_pos.duration < 0 || column_pos.frequency < 0 || column_pos.bandwidth < 0 || column_pos.q < 0 || column_pos.pol_ellipse_angle < 0 || column_pos.pol_ellipse_e < 0 || column_pos.hrss < 0) {
223 XLALPrintError(
"%s(): failure reading %s table: missing required column\n", __func__, table_name);
226 row->
duration = env.ligo_lw.table.elt[column_pos.duration].data.real_8;
227 row->
frequency = env.ligo_lw.table.elt[column_pos.frequency].data.real_8;
228 row->
bandwidth = env.ligo_lw.table.elt[column_pos.bandwidth].data.real_8;
229 row->
q = env.ligo_lw.table.elt[column_pos.q].data.real_8;
230 row->
pol_ellipse_angle = env.ligo_lw.table.elt[column_pos.pol_ellipse_angle].data.real_8;
231 row->
pol_ellipse_e = env.ligo_lw.table.elt[column_pos.pol_ellipse_e].data.real_8;
232 row->
hrss = env.ligo_lw.table.elt[column_pos.hrss].data.real_8;
233 }
else if(!strcmp(row->
waveform,
"Gaussian")) {
234 if(column_pos.duration < 0 || column_pos.hrss < 0) {
238 XLALPrintError(
"%s(): failure reading %s table: missing required column\n", __func__, table_name);
241 row->
duration = env.ligo_lw.table.elt[column_pos.duration].data.real_8;
242 row->
hrss = env.ligo_lw.table.elt[column_pos.hrss].data.real_8;
243 }
else if(!strcmp(row->
waveform,
"BTLWNB")) {
244 if(column_pos.duration < 0 || column_pos.frequency < 0 || column_pos.bandwidth < 0 || column_pos.pol_ellipse_angle < 0 || column_pos.pol_ellipse_e < 0 || column_pos.egw_over_rsquared < 0 || column_pos.waveform_number < 0) {
248 XLALPrintError(
"%s(): failure reading %s table: missing required column\n", __func__, table_name);
251 row->
duration = env.ligo_lw.table.elt[column_pos.duration].data.real_8;
252 row->
frequency = env.ligo_lw.table.elt[column_pos.frequency].data.real_8;
253 row->
bandwidth = env.ligo_lw.table.elt[column_pos.bandwidth].data.real_8;
254 row->
pol_ellipse_angle = env.ligo_lw.table.elt[column_pos.pol_ellipse_angle].data.real_8;
255 row->
pol_ellipse_e = env.ligo_lw.table.elt[column_pos.pol_ellipse_e].data.real_8;
256 row->
egw_over_rsquared = env.ligo_lw.table.elt[column_pos.egw_over_rsquared].data.real_8;
257 row->
waveform_number = env.ligo_lw.table.elt[column_pos.waveform_number].data.int_8u;
258 }
else if(!strcmp(row->
waveform,
"Impulse")) {
259 if(column_pos.amplitude < 0) {
263 XLALPrintError(
"%s(): failure reading %s table: missing required column\n", __func__, table_name);
266 row->
amplitude = env.ligo_lw.table.elt[column_pos.amplitude].data.real_8;
279 next = &(*next)->
next;
284 XLALPrintError(
"%s(): I/O error parsing %s table: %s\n", __func__, table_name, env.mierrmsg.data ? env.mierrmsg.data :
"unknown reason");
290 if(MetaioClose(&env)) {
292 XLALPrintError(
"%s(): error parsing document after %s table: %s\n", __func__, table_name, env.mierrmsg.data ? env.mierrmsg.data :
"unknown reason");
310 const char *row_head =
"\n\t\t\t";
316 XLALFilePuts(
"\t\t<Column Name=\"process:process_id\" Type=\"int_8s\"/>\n", xml->
fp);
317 XLALFilePuts(
"\t\t<Column Name=\"waveform\" Type=\"lstring\"/>\n", xml->
fp);
318 XLALFilePuts(
"\t\t<Column Name=\"ra\" Type=\"real_8\"/>\n", xml->
fp);
319 XLALFilePuts(
"\t\t<Column Name=\"dec\" Type=\"real_8\"/>\n", xml->
fp);
320 XLALFilePuts(
"\t\t<Column Name=\"psi\" Type=\"real_8\"/>\n", xml->
fp);
321 XLALFilePuts(
"\t\t<Column Name=\"time_geocent_gps\" Type=\"int_4s\"/>\n", xml->
fp);
322 XLALFilePuts(
"\t\t<Column Name=\"time_geocent_gps_ns\" Type=\"int_4s\"/>\n", xml->
fp);
323 XLALFilePuts(
"\t\t<Column Name=\"time_geocent_gmst\" Type=\"real_8\"/>\n", xml->
fp);
324 XLALFilePuts(
"\t\t<Column Name=\"duration\" Type=\"real_8\"/>\n", xml->
fp);
325 XLALFilePuts(
"\t\t<Column Name=\"frequency\" Type=\"real_8\"/>\n", xml->
fp);
326 XLALFilePuts(
"\t\t<Column Name=\"bandwidth\" Type=\"real_8\"/>\n", xml->
fp);
327 XLALFilePuts(
"\t\t<Column Name=\"q\" Type=\"real_8\"/>\n", xml->
fp);
328 XLALFilePuts(
"\t\t<Column Name=\"pol_ellipse_angle\" Type=\"real_8\"/>\n", xml->
fp);
329 XLALFilePuts(
"\t\t<Column Name=\"pol_ellipse_e\" Type=\"real_8\"/>\n", xml->
fp);
330 XLALFilePuts(
"\t\t<Column Name=\"amplitude\" Type=\"real_8\"/>\n", xml->
fp);
331 XLALFilePuts(
"\t\t<Column Name=\"hrss\" Type=\"real_8\"/>\n", xml->
fp);
332 XLALFilePuts(
"\t\t<Column Name=\"egw_over_rsquared\" Type=\"real_8\"/>\n", xml->
fp);
333 XLALFilePuts(
"\t\t<Column Name=\"waveform_number\" Type=\"int_8u\"/>\n", xml->
fp);
334 XLALFilePuts(
"\t\t<Column Name=\"time_slide:time_slide_id\" Type=\"int_8s\"/>\n", xml->
fp);
335 XLALFilePuts(
"\t\t<Column Name=\"simulation_id\" Type=\"int_8s\"/>\n", xml->
fp);
336 XLALFilePuts(
"\t\t<Stream Name=\"sim_burst:table\" Type=\"Local\" Delimiter=\",\">", xml->
fp);
342 for(; sim_burst; sim_burst = sim_burst->
next) {
343 if(
XLALFilePrintf(xml->
fp,
"%s%ld,\"%s\",%.16g,%.16g,%.16g,%d,%d,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%lu,%ld,%ld",
367 row_head =
",\n\t\t\t";
394 for(; sim_burst; sim_burst = sim_burst->
next) {
399 return simulation_id;
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...
int XLALFilePuts(const char *s, LALFILE *file)
int XLALFilePrintf(LALFILE *file, const char *fmt,...)
void * XLALMalloc(size_t n)
#define XLAL_ERROR_NULL(...)
int XLALGetBaseErrno(void)
#define XLAL_REAL8_FAIL_NAN
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
LIGOTimeGPS * XLALGPSSet(LIGOTimeGPS *epoch, INT4 gpssec, INT8 gpsnan)
int XLALWriteLIGOLwXMLSimBurstTable(LIGOLwXMLStream *xml, const SimBurst *sim_burst)
Write a sim_burst table to an XML file.
void XLALDestroySimBurstTable(SimBurst *head)
Destroy a SimBurst linked list.
long XLALSimBurstAssignIDs(SimBurst *sim_burst, long process_id, long time_slide_id, long simulation_id)
Assign simulation_id values to the entries in a sim_burst linked list.
SimBurst * XLALCreateSimBurst(void)
Create a SimBurst structure.
SimBurst * XLALSimBurstTableFromLIGOLw(const char *filename)
Read the sim_burst table from a LIGO Light Weight XML file into a linked list of SimBurst structures.
SimBurst * XLALDestroySimBurst(SimBurst *row)
Destroy a SimBurst structure.
This structure contains the file stream and current table type for writing to LIGO lightweight XML fi...
The SimBurst structure describes a burst injection.
char waveform[LIGOMETA_WAVEFORM_MAX]
struct tagSimBurst * next
LIGOTimeGPS time_geocent_gps
unsigned long waveform_number