Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
CrossCorrToplist.h
Go to the documentation of this file.
1/*
2* Copyright (C) 2010 Christine Chung (based on HoughFstatToplist.h)
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#ifndef CROSSCORRTOPLIST_H
21#define CROSSCORRTOPLIST_H
22
23#include <lal/HeapToplist.h>
24#include <lal/LALDatatypes.h>
25
26
27/** Type to hold the fields that will be kept in a "toplist" */
28typedef struct {
29 REAL8 Freq; /**< Frequency */
30 REAL8 Alpha; /**< Skyposition: longitude in equatorial coords, radians */
31 REAL8 Delta; /**< skyposition: latitude */
32 REAL8 Q1; /**< Q1 */
33 REAL8 Q2; /**< Q2 */
34 REAL8 BrakingIndex; /**< braking index */
35 REAL8 Rho; /**< Crosscorr statistic */
37
38/** Type to hold the fields that will be kept in a "toplist" -- for a directed binary search */
39/* add field for sensitivity estimate */
40typedef struct {
41 REAL8 freq; /**< Frequency */
42 REAL8 tp; /**< time of periapse passage */
43 REAL8 argp; /**< argument of periapse */
44 REAL8 asini; /**< projected semi-major axis */
45 REAL8 ecc; /**< eccentricity */
46 REAL8 period; /**< bperiod */
47 REAL8 rho; /**< Crosscorr statistic */
48 REAL8 evSquared; /**< E[rho]/h0^2)^2 */
49 REAL8 estSens; /**< average template E[rho]/h0^2)^2*/
51
52
53
54
55
56
57/**
58 * creates a toplist with length elements,
59 * returns -1 on error (usually out of memory), else 0
60 */
61extern int create_crossCorr_toplist( toplist_t **list, UINT8 length );
62extern int create_crossCorrBinary_toplist( toplist_t **list, UINT8 length );
63
64/** frees the space occupied by the toplist */
65extern void free_crossCorr_toplist( toplist_t **list );
66
67/**
68 * Inserts an element in to the toplist either if there is space left
69 * or the element is larger than the smallest element in the toplist.
70 * In the latter case, remove the smallest element from the toplist
71 * Returns 1 if the element was actually inserted, 0 if not.
72 */
74
76
77/**
78 * Writes the toplist to an (already open) filepointer
79 * Returns the number of written charactes
80 * sets the checksum if non-NULL
81 * Returns something <0 on error
82 */
83extern int write_crossCorr_toplist_to_fp( toplist_t *list, FILE *fp, UINT4 *checksum );
84
85extern int write_crossCorrBinary_toplist_to_fp( toplist_t *list, FILE *fp, UINT4 *checksum );
86
87/**
88 * reads a (created!) toplist from an open filepointer
89 * sets the checksum if non-NULL
90 * reads maximum maxbytes, all that is there if maxbytes is 0
91 * returns the number of bytes read,
92 * 0 if we found a %DONE marker at the end,
93 * -1 if the file contained a syntax error,
94 * -2 if given an improper toplist
95 */
96/* extern int read_crossCorr_toplist_from_fp(toplist_t*list, FILE*fp, UINT4*checksum, UINT4 maxbytes); */
97
98/* extern int read_crossCorrBinary_toplist_from_fp(toplist_t*list, FILE*fp, UINT4*checksum, UINT4 maxbytes); */
99
100/**
101 * sorts the toplist with an internal sorting function,
102 * used before finally writing it
103 */
104extern void sort_crossCorr_toplist( toplist_t *list );
105
106extern void sort_crossCorrBinary_toplist( toplist_t *list );
107
108
109/** File IO */
110
111/**
112 * writes a CrossCorrOutputEntry line to an open filepointer.
113 * Returns the number of chars written, -1 if in error
114 * Updates checksum if given (i.e. not NULL)
115 */
117
119
120/**
121 * writes the given toplitst to a temporary file, then renames the
122 * temporary file to filename. The name of the temporary file is
123 * derived from the filename by appending ".tmp". Returns the number
124 * of chars written or -1 if the temp file could not be opened.
125 */
126extern int atomic_write_crossCorr_toplist_to_file( toplist_t *list, const char *filename, UINT4 *checksum );
127
128extern int atomic_write_crossCorrBinary_toplist_to_file( toplist_t *list, const char *filename, UINT4 *checksum );
129
130/**
131 * meant for the final writing of the toplist
132 * - reduces toplist precision
133 * - sorts the toplist
134 * - finally calls atomic_write_crossCorr_toplist_to_file()
135 */
136extern int final_write_crossCorr_toplist_to_file( toplist_t *list, const char *filename, UINT4 *checksum );
137
138extern int final_write_crossCorrBinary_toplist_to_file( toplist_t *list, const char *filename, UINT4 *checksum );
139
140
141/**
142 * writes a checkpoint:
143 * - constructs temporary filename (by appending .TMP)
144 * - writes number of elements ("elems") in toplist to tempfile
145 * - dumps data to tempfile
146 * - appends counter
147 * - appends checksum (of elems, data and counter)
148 * - renames tempfile to final name
149 * returns
150 * -1 in case of an I/O error,
151 * -2 if out of memory,
152 * 0 otherwise (successful)
153 */
154extern int write_cc_checkpoint( const char *filename, toplist_t *tl, UINT4 counter, BOOLEAN do_sync );
155
156/**
157 * tries to read a checkpoint
158 * - tries to open the file, returns 1 if no file found
159 * - reads elems, data, counter and checksum
160 * - verifies checksum
161 * - restores the heap by sorting
162 * returns
163 * 0 if successfully read a checkpoint
164 * 1 if no checkpoint was found
165 * -1 in case of an I/O error
166 * -2 if the checksum was wrong or elems was unreasonable
167 */
168extern int read_cc_checkpoint( const char *filename, toplist_t *tl, UINT4 *counter );
169
170/**
171 * write the final output file:
172 * - re-sort the toplist into freq/alpha/delta/fdot order
173 * - write out the toplist in ASCII format with end marker to a temporary file
174 * - rename the file to the final name
175 */
176extern int write_cc_output( const char *filename, toplist_t *tl );
177
178#endif /* CROSSCORRTOPLIST_H - double inclusion protection */
int create_crossCorr_toplist(toplist_t **list, UINT8 length)
creates a toplist with length elements, returns -1 on error (usually out of memory),...
void sort_crossCorrBinary_toplist(toplist_t *list)
int write_cc_checkpoint(const char *filename, toplist_t *tl, UINT4 counter, BOOLEAN do_sync)
writes a checkpoint:
int final_write_crossCorr_toplist_to_file(toplist_t *list, const char *filename, UINT4 *checksum)
meant for the final writing of the toplist
void free_crossCorr_toplist(toplist_t **list)
frees the space occupied by the toplist
int atomic_write_crossCorr_toplist_to_file(toplist_t *list, const char *filename, UINT4 *checksum)
writes the given toplitst to a temporary file, then renames the temporary file to filename.
int insert_into_crossCorrBinary_toplist(toplist_t *list, CrossCorrBinaryOutputEntry line)
int final_write_crossCorrBinary_toplist_to_file(toplist_t *list, const char *filename, UINT4 *checksum)
int write_crossCorrBinary_toplist_item_to_fp(CrossCorrBinaryOutputEntry line, FILE *fp, UINT4 *checksum)
int create_crossCorrBinary_toplist(toplist_t **list, UINT8 length)
int write_crossCorr_toplist_to_fp(toplist_t *list, FILE *fp, UINT4 *checksum)
Writes the toplist to an (already open) filepointer Returns the number of written charactes sets the ...
int atomic_write_crossCorrBinary_toplist_to_file(toplist_t *list, const char *filename, UINT4 *checksum)
int write_crossCorr_toplist_item_to_fp(CrossCorrOutputEntry line, FILE *fp, UINT4 *checksum)
File IO.
int write_cc_output(const char *filename, toplist_t *tl)
write the final output file:
int write_crossCorrBinary_toplist_to_fp(toplist_t *list, FILE *fp, UINT4 *checksum)
int read_cc_checkpoint(const char *filename, toplist_t *tl, UINT4 *counter)
tries to read a checkpoint
void sort_crossCorr_toplist(toplist_t *list)
reads a (created!) toplist from an open filepointer sets the checksum if non-NULL reads maximum maxby...
int insert_into_crossCorr_toplist(toplist_t *list, CrossCorrOutputEntry line)
Inserts an element in to the toplist either if there is space left or the element is larger than the ...
unsigned char BOOLEAN
uint64_t UINT8
double REAL8
uint32_t UINT4
Type to hold the fields that will be kept in a "toplist" – for a directed binary search.
REAL8 ecc
eccentricity
REAL8 argp
argument of periapse
REAL8 estSens
average template E[rho]/h0^2)^2
REAL8 period
bperiod
REAL8 evSquared
E[rho]/h0^2)^2.
REAL8 tp
time of periapse passage
REAL8 rho
Crosscorr statistic.
REAL8 freq
Frequency.
REAL8 asini
projected semi-major axis
Type to hold the fields that will be kept in a "toplist"
REAL8 Q1
Q1.
REAL8 BrakingIndex
braking index
REAL8 Freq
Frequency.
REAL8 Rho
Crosscorr statistic.
REAL8 Q2
Q2.
REAL8 Delta
skyposition: latitude
REAL8 Alpha
Skyposition: longitude in equatorial coords, radians.