2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * Copyright (C) 2008 Liam Girdwood
24 #include <libastrodb/db.h>
26 #define TABLE_MAX_IDX 128 /* max number of indexes */
27 #define TABLE_MAX_AIDX 16 /* max number of alternate indexes */
28 #define HASH_MAPS 16 /* number of hash maps */
30 #define INSERT_POSN_MAG 1
31 #define INSERT_POSN_TYPE 2
32 #define INSERT_HASH_ID 3
33 #define INSERT_POSN_MAG_HASH 4
34 #define INSERT_POSN_TYPE_HASH 5
37 /*! \defgroup dataset Dataset
39 * A dataset is a container of astro objects organised in either a 3,2 or 1 dimensional
40 * tile array. Each tile in the array contains a singly linked list of objects and
41 * status information about the tile.
43 * The dataset tiles can be organised as follows:-
44 * - 3D as RA, DEC and Vmag
46 * - 1D as hashed object ID
47 * - 1D on object distance (for near object datasets)
49 * A dataset is generally equivalent to a table within a traditional database
50 * with additional data ordering.
52 * Datasets have a 1:1 mapping with with catalog data files and a catalog
53 * can have more than 1 dataset.
56 typedef int (*astrodb_alt_insert
)(void *dest
, void *src1
, void *src2
);
59 struct astrodb_schema_object pri
; /* primary field index */
60 struct astrodb_schema_object sec
; /* alternate field index */
61 astrodb_alt_insert insert
; /*!< alt field inserters */
65 struct astrodb_slist
**hobjects
; /*!< Hash table pointing to objects */
66 int offset
; /*!< offset in object for hashed ID */
70 /*! \typedef struct struct astrodb_table
71 * \brief Catalog Dataset.
74 * The dataset container holds the tile array and it's dimensions.
76 struct astrodb_table
{
77 char *name
; /*!< dataset name */
78 char *file
; /*!< dataset local filename */
79 struct astrodb_db
*db
; /*!< catalog we belong to */
80 int init_flags
; /*!< initialisation flags */
82 /* tile array dimensions */
83 int ra_stride
; /*!< number of ra strides, covers 360 deg*/
84 int dec_stride
; /*!< number of dec strides, covers 180 deg */
85 int mag_stride
; /*!< number of mag strides */
86 double ra_stride_size
; /*!< size of each ra stride in degrees */
87 double dec_stride_size
; /*!< size of each dec stride in degrees */
88 double mag_stride_size
; /*!< size of each mag stride */
91 int clip_min_ra
; /*!< Clipping Min RA stride */
92 int clip_min_dec
; /*!< Clipping Min DEC stride */
93 int clip_max_ra
; /*!< Clipping Max RA stride */
94 int clip_max_dec
; /*!< Clipping Max DEC stride */
95 int clip_faint_mag
; /*!< Clipping Max Mag stride */
96 int clip_bright_mag
; /*!< Clipping Min Mag stride */
97 double clip_radius
; /*!< Clipping radius in degrees */
98 double clip_centre_ra
; /*!< Clipping centre RA (circular) */
99 double clip_centre_dec
; /*!< Clipping centre DEC (circular) */
101 /* object data storage */
102 struct astrodb_slist
**objects
; /*!< ptr to object array */
103 struct astrodb_tile_status
*status
; /*!< ptr to status array */
104 int array_size
; /*!< cubic tile array size (in bytes)*/
105 int status_size
; /*!< cubic status size (in bytes) */
106 int no_tiles
; /*!< number of tiles in cubic array */
107 int object_size
; /*!< Object size (bytes) */
108 int table_size
; /*!< Number of objects in set */
109 int (*object_insert
)(void *table
, void* object
); /*!< Object insertion method */
110 int insert_id
; /*!< Object insertion method ID */
112 /* hashed object searching */
113 struct hash_map hmaps
[HASH_MAPS
];
116 /* object index description */
117 struct astrodb_dlist
*byte_description
;
118 int object_fields
; /*!< number of key and custom fields */
119 int alt_fields
; /*!< number of alt object fields */
120 struct astrodb_schema_object idx
[TABLE_MAX_IDX
]; /*!< key and custom field descriptors */
121 struct alt_idx_ alt_idx
[TABLE_MAX_AIDX
]; /*!< alt src data */
122 int record_size
; /*!< length in chars of each record */
125 /*! \typedef astrodb_table_info
126 * \brief Dataset binary db index.
129 * Index data for binary catalog datasets.
131 struct astrodb_table_index
{
132 int catalog_magic
; /*!< magic number */
133 int endian_magic
; /*!< magic number to determine endianess */
134 double ra_min
; /*!< Min catalog RA or AU */
135 double ra_max
; /*!< Max catalog RA or AU */
136 double dec_min
; /*!< Min catalog DEC */
137 double dec_max
; /*!< Max catalog DEC */
138 double mag_faint
; /*!< Min (faint) catalog mag */
139 double mag_bright
; /*!< Mag (bright) catalog mag */
140 int object_size
; /*!< Object size (bytes) */
141 int table_size
; /*!< Number of objects in catalog */
142 int object_fields
; /*!< number of custom fields */
143 int insert_id
; /*!< object importer func */
146 /*! \fn static inline int calc_deep_offset(struct astrodb_table* data, int ra, int dec, int mag)
147 * \brief Calculate offset into 3d tile array
149 static inline int table_calc_deep_offset(struct astrodb_table
*data
,
150 int ra
, int dec
, int mag
)
152 return ra
+ (dec
* data
->ra_stride
) +
153 (mag
* data
->ra_stride
* data
->dec_stride
);
156 /*! \fn static inline int calc_hash(char* data, int len, int mod)
157 * \brief Calculate hash based on string <data> and in range <mod>
159 * We dont hash ' ' or '-'.
161 static inline int table_calc_hash(char *data
, int len
, int mod
)
166 if (*data
>= '0' && *data
<= 'z')
167 val
= ((val
<< 5) ^ (val
>> 27)) ^ *data
;
171 val
= abs(val
% mod
);
175 int table_scan_afields(struct astrodb_table
*table
, struct astrodb_dlist
* desc
);
176 int table_is_field(struct astrodb_table
*table
, char *field
);
177 int table_find_field(struct astrodb_table
*table
, char *field
);
178 int table_add_alt_field(struct astrodb_table
*table
, char *field
, int pri_idx
);
179 int table_scan_dfields(struct astrodb_table
*table
, struct astrodb_dlist
* desc
);
180 int table_order_index(struct astrodb_table
*table
);
181 int table_add_custom_struct_field(struct astrodb_table
*table
, struct astrodb_schema_object
* idx
);
182 void table_set_insert(struct astrodb_table
*table
, int id
);
183 astrodb_ctype
table_get_ctype(char *type
);
184 int table_get_csize(char *type
);
185 void *table_get_custom_insert(char *type
);
186 void *table_get_key_insert(astrodb_ctype type
);
187 void *table_get_alt_key_insert(astrodb_ctype type
);
188 void table_get_object_insert(struct astrodb_table
*table
);
189 int table_import(struct astrodb_table
*table
, char *file
);
190 int table_cache_tiles(struct astrodb_table
*table
);
191 int table_uncache_tiles(struct astrodb_table
*table
);
192 int table_save_hdr(struct astrodb_table
*table
);
193 int table_load_hdr(struct astrodb_table
*table
);
194 int table_get_remote_dataset(struct astrodb_table
*table
);
195 int table_get_objects_mem(struct astrodb_table
*table
, struct astrodb_slist
** result
);
196 int table_get_objects_cache(struct astrodb_table
*table
, struct astrodb_slist
** result
);
197 int table_get_objects_raw(struct astrodb_table
*table
, struct astrodb_slist
** result
);
198 int table_get_objects_online(struct astrodb_table
*table
, struct astrodb_slist
** result
);
199 int table_get_objects_memc(struct astrodb_table
*table
, struct astrodb_slist
** result
);
200 int table_get_objects_cachec(struct astrodb_table
*table
, struct astrodb_slist
** result
);
201 int table_get_objects_rawc(struct astrodb_table
*table
, struct astrodb_slist
** result
);
202 int table_get_objects_onlinec(struct astrodb_table
*table
, struct astrodb_slist
** result
);
203 int table_get_objects_cache_near(struct astrodb_table
*table
, struct astrodb_slist
** result
);