LALPulsar 7.1.1.1-eeff03c
FstatToplist.h
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Bernd Machenschalk, Reinhard Prix
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 FSTATTOPLIST_H
21#define FSTATTOPLIST_H
22
23#include <stdio.h>
24#include <math.h>
25
26#include <lal/LALDatatypes.h>
27#include <lal/LALConstants.h>
28#include <lal/HeapToplist.h>
29
30#define MAXFILENAMELENGTH 256 /* Maximum # of characters of a filename */
31/** Type to hold the fields that will be output in unclustered output file */
32typedef struct {
33 REAL8 Freq; /**< Frequency at maximum (?) of the cluster */
34 REAL8 f1dot; /**< spindown value f1dot = df/dt */
35 REAL8 Alpha; /**< Skyposition: longitude in equatorial coords, radians */
36 REAL8 Delta; /**< skyposition: latitude */
37 REAL8 Fstat; /**< value of 2F */
39
40
41/* This has by now been reduced to an interface to the HeapToplist functions */
42
43/**
44 * creates a toplist with length elements,
45 * returns -1 on error (usually out of memory), else 0
46 */
47extern int create_fstat_toplist( toplist_t **list, UINT8 length );
48
49/** frees the space occupied by the toplist */
50extern void free_fstat_toplist( toplist_t **list );
51
52/**
53 * Inserts an element in to the toplist either if there is space left
54 * or the element is larger than the smallest element in the toplist.
55 * In the latter case, remove the smallest element from the toplist
56 * Returns 1 if the element was actually inserted, 0 if not.
57 */
59
60/**
61 * Writes the toplist to an (already open) filepointer
62 * Returns the number of written charactes
63 * sets the checksum if non-NULL
64 * Returns something <0 on error
65 */
66extern int write_fstat_toplist_to_fp( toplist_t *list, FILE *fp, UINT4 *checksum );
67
68/**
69 * reads a (created!) toplist from an open filepointer
70 * sets the checksum if non-NULL
71 * reads maximum maxbytes, all that is there if maxbytes is 0
72 * returns the number of bytes read,
73 * 0 if we found a %DONE marker at the end,
74 * -1 if the file contained a syntax error,
75 * -2 if given an improper toplist
76 */
77extern int read_fstat_toplist_from_fp( toplist_t *list, FILE *fp, UINT4 *checksum, UINT4 maxbytes );
78
79/**
80 * sorts the toplist with an internal sorting function,
81 * used before finally writing it
82 */
83extern void sort_fstat_toplist( toplist_t *list );
84
85
86
87
88/** File IO */
89
90/**
91 * writes an FstatOutputEntry line to an open filepointer.
92 * Returns the number of chars written, -1 if in error
93 * Updates checksum if given (i.e. not NULL)
94 */
95extern int write_fstat_toplist_item_to_fp( FstatOutputEntry line, FILE *fp, UINT4 *checksum );
96
97/**
98 * writes the given toplitst to a temporary file, then renames the
99 * temporary file to filename. The name of the temporary file is
100 * derived from the filename by appending ".tmp". Returns the number
101 * of chars written or -1 if the temp file could not be opened.
102 */
103extern int atomic_write_fstat_toplist_to_file( toplist_t *list, const char *filename, UINT4 *checksum );
104
105/**
106 * meant for the final writing of the toplist
107 * - reduces toplist precision
108 * - sorts the toplist
109 * - finally calls atomic_write_fstat_toplist_to_file()
110 */
111extern int final_write_fstat_toplist_to_file( toplist_t *list, const char *filename, UINT4 *checksum );
112
113
114
115
116/** a toplist as a checkpointed file */
117
118typedef struct {
119 CHAR *filename; /**< name of the toplist file */
120 CHAR *buffer; /**< write buffer if needed */
121 UINT4 bufsize; /**< buffer size if needed */
122 UINT4 bytes; /**< counts the bytes in the file */
123 UINT4 maxsize; /**< the file must not grow larger than that */
124 UINT4 checksum; /**< keeps the checksum */
125 FILE *fp; /**< FILE* currently associated */
126 toplist_t *list; /**< toplist this file reflects */
128
129/** creates a FstatCheckpointFile */
131 CHAR *filename,
132 UINT4 bufsize,
133 UINT4 maxsize,
134 toplist_t *tl );
135
136/** destroys a FstatCheckpointFile */
138
139/** opens a file for checkpointing the desired toplist */
140extern int fstat_cpt_file_open( FstatCheckpointFile *cptf );
141
142/** flushes the checkpoint file (only useful if buffered) */
143extern int fstat_cpt_file_flush( FstatCheckpointFile *cptf );
144
145/** returns information for checkpointing */
146extern int fstat_cpt_file_info( FstatCheckpointFile *cptf, CHAR **filename, UINT4 *bytes, UINT4 *checksum );
147
148/**
149 * adds an item to the toplist and keeps the file consistent, i.e.
150 * adds the entry to the file if it was really inserted
151 * and compacts the file if necessary
152 */
154
155/**
156 * closes the file, reduces the precision, sorts the toplist,
157 * finally rewrites the file (sorted and compact) with end marker
158 */
159extern int fstat_cpt_file_close( FstatCheckpointFile *cptf );
160
161/** reads a written checkpointed toplist back into memory */
162extern int fstat_cpt_file_read( FstatCheckpointFile *cptf, UINT4 checksum, UINT4 maxbytes );
163
164/** compact a toplist file if the length has reached maxbytes */
166
167/** new, simpler checkpointing for HierarchicalSearch */
168
169
170/**
171 * writes a checkpoint:
172 * - constructs temporary filename (by appending .TMP)
173 * - writes number of elements ("elems") in toplist to tempfile
174 * - dumps data to tempfile
175 * - appends counter
176 * - appends checksum (of elems, data and counter)
177 * - renames tempfile to final name
178 * returns
179 * -1 in case of an I/O error,
180 * -2 if out of memory,
181 * 0 otherwise (successful)
182 */
183extern int write_hs_checkpoint( const char *filename, toplist_t *tl, UINT4 counter, BOOLEAN do_sync );
184
185/**
186 * tries to read a checkpoint
187 * - tries to open the file, returns 1 if no file found
188 * - reads elems, data, counter and checksum
189 * - verifies checksum
190 * - restores the heap by sorting
191 * returns
192 * 0 if successfully read a checkpoint
193 * 1 if no checkpoint was found
194 * -1 in case of an I/O error
195 * -2 if the checksum was wrong or elems was unreasonable
196 */
197extern int read_hs_checkpoint( const char *filename, toplist_t *tl, UINT4 *counter );
198
199/**
200 * write the final output file:
201 * - re-sort the toplist into freq/alpha/delta/fdot order
202 * - write out the toplist in ASCII format with end marker to a temporary file
203 * - rename the file to the final name
204 */
205extern int write_hs_oputput( const char *filename, toplist_t *tl );
206
207#endif /* FSTATTOPLIST_H - double inclusion protection */
int create_fstat_toplist(toplist_t **list, UINT8 length)
creates a toplist with length elements, returns -1 on error (usually out of memory),...
Definition: FstatToplist.c:111
int fstat_cpt_file_destroy(FstatCheckpointFile **cptf)
destroys a FstatCheckpointFile
Definition: FstatToplist.c:525
int fstat_cpt_file_create(FstatCheckpointFile **cptf, CHAR *filename, UINT4 bufsize, UINT4 maxsize, toplist_t *tl)
creates a FstatCheckpointFile
Definition: FstatToplist.c:467
int fstat_cpt_file_flush(FstatCheckpointFile *cptf)
flushes the checkpoint file (only useful if buffered)
Definition: FstatToplist.c:574
int fstat_cpt_file_compact(FstatCheckpointFile *cptf)
compact a toplist file if the length has reached maxbytes
Definition: FstatToplist.c:721
int fstat_cpt_file_open(FstatCheckpointFile *cptf)
opens a file for checkpointing the desired toplist
Definition: FstatToplist.c:545
int fstat_cpt_file_close(FstatCheckpointFile *cptf)
closes the file, reduces the precision, sorts the toplist, finally rewrites the file (sorted and comp...
Definition: FstatToplist.c:611
int write_hs_oputput(const char *filename, toplist_t *tl)
write the final output file:
Definition: FstatToplist.c:988
int fstat_cpt_file_info(FstatCheckpointFile *cptf, CHAR **filename, UINT4 *bytes, UINT4 *checksum)
returns information for checkpointing
Definition: FstatToplist.c:590
void free_fstat_toplist(toplist_t **list)
frees the space occupied by the toplist
Definition: FstatToplist.c:118
int write_fstat_toplist_item_to_fp(FstatOutputEntry line, FILE *fp, UINT4 *checksum)
File IO.
Definition: FstatToplist.c:303
int write_fstat_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 ...
Definition: FstatToplist.c:352
int read_hs_checkpoint(const char *filename, toplist_t *tl, UINT4 *counter)
tries to read a checkpoint
Definition: FstatToplist.c:878
int fstat_cpt_file_read(FstatCheckpointFile *cptf, UINT4 checksum, UINT4 maxbytes)
reads a written checkpointed toplist back into memory
Definition: FstatToplist.c:668
int insert_into_fstat_toplist(toplist_t *list, FstatOutputEntry line)
Inserts an element in to the toplist either if there is space left or the element is larger than the ...
Definition: FstatToplist.c:129
int final_write_fstat_toplist_to_file(toplist_t *list, const char *filename, UINT4 *checksum)
meant for the final writing of the toplist
Definition: FstatToplist.c:456
int read_fstat_toplist_from_fp(toplist_t *list, FILE *fp, UINT4 *checksum, UINT4 maxbytes)
reads a (created!) toplist from an open filepointer sets the checksum if non-NULL reads maximum maxby...
Definition: FstatToplist.c:151
void sort_fstat_toplist(toplist_t *list)
sorts the toplist with an internal sorting function, used before finally writing it
Definition: FstatToplist.c:140
int atomic_write_fstat_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.
Definition: FstatToplist.c:378
int write_hs_checkpoint(const char *filename, toplist_t *tl, UINT4 counter, BOOLEAN do_sync)
new, simpler checkpointing for HierarchicalSearch
Definition: FstatToplist.c:766
int fstat_cpt_file_add(FstatCheckpointFile *cptf, FstatOutputEntry line)
adds an item to the toplist and keeps the file consistent, i.e.
Definition: FstatToplist.c:637
unsigned char BOOLEAN
uint64_t UINT8
double REAL8
char CHAR
uint32_t UINT4
a toplist as a checkpointed file
Definition: FstatToplist.h:118
CHAR * buffer
write buffer if needed
Definition: FstatToplist.h:120
FILE * fp
FILE* currently associated.
Definition: FstatToplist.h:125
UINT4 maxsize
the file must not grow larger than that
Definition: FstatToplist.h:123
CHAR * filename
name of the toplist file
Definition: FstatToplist.h:119
UINT4 bytes
counts the bytes in the file
Definition: FstatToplist.h:122
toplist_t * list
toplist this file reflects
Definition: FstatToplist.h:126
UINT4 bufsize
buffer size if needed
Definition: FstatToplist.h:121
UINT4 checksum
keeps the checksum
Definition: FstatToplist.h:124
Type to hold the fields that will be output in unclustered output file
Definition: FstatToplist.h:32
REAL8 Alpha
Skyposition: longitude in equatorial coords, radians.
Definition: FstatToplist.h:35
REAL8 Fstat
value of 2F
Definition: FstatToplist.h:37
REAL8 Delta
skyposition: latitude
Definition: FstatToplist.h:36
REAL8 Freq
Frequency at maximum (?) of the cluster.
Definition: FstatToplist.h:33
REAL8 f1dot
spindown value f1dot = df/dt
Definition: FstatToplist.h:34