lxt2_read.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2003-2004 Tony Bybell.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00017  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00019  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00020  * DEALINGS IN THE SOFTWARE.
00021  */
00022 
00023 #ifndef DEFS_LXTR_H
00024 #define DEFS_LXTR_H
00025 
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 #include <ctype.h>
00030 #include <errno.h>
00031 
00032 #ifndef _MSC_VER
00033 #include <unistd.h>
00034 #include <inttypes.h>
00035 #else
00036 typedef long off_t;
00037 #include <windows.h>
00038 #include <io.h>
00039 #endif
00040 
00041 #if defined _MSC_VER || defined __MINGW32__
00042 #define fseeko fseek
00043 #define ftello ftell
00044 #endif
00045 
00046 #ifdef HAVE_LIBZ
00047 #include <zlib.h>
00048 #endif
00049 
00050 #ifdef __GNUC__
00051 #define _LXT2_RD_INLINE inline
00052 #else
00053 #define _LXT2_RD_INLINE
00054 #endif
00055 
00056 #define LXT2_RDLOAD "LXTLOAD | "
00057 
00058 #define LXT2_RD_HDRID (0x1380)
00059 #define LXT2_RD_VERSION (0x0001)
00060 
00061 #define LXT2_RD_GRANULE_SIZE (64)
00062 #define LXT2_RD_PARTIAL_SIZE (2048)
00063 
00064 #define LXT2_RD_GRAN_SECT_TIME 0
00065 #define LXT2_RD_GRAN_SECT_DICT 1
00066 #define LXT2_RD_GRAN_SECT_TIME_PARTIAL 2
00067 
00068 #define LXT2_RD_MAX_BLOCK_MEM_USAGE (64*1024*1024)      /* 64MB */
00069 
00070 #ifndef _MSC_VER
00071 typedef uint8_t                 lxtint8_t;
00072 typedef uint16_t                lxtint16_t;
00073 typedef uint32_t                lxtint32_t;
00074 typedef uint64_t                lxtint64_t;
00075 #ifndef __MINGW32__
00076 #define LXT2_RD_LLD "%lld"
00077 #else
00078 #define LXT2_RD_LLD "%I64d"
00079 #endif
00080 #define LXT2_RD_LLDESC(x) x##LL
00081 #define LXT2_RD_ULLDESC(x) x##ULL
00082 #else
00083 typedef unsigned __int8         lxtint8_t;
00084 typedef unsigned __int16        lxtint16_t;
00085 typedef unsigned __int32        lxtint32_t;
00086 typedef unsigned __int64        lxtint64_t;
00087 #define LXT2_RD_LLD "%I64d"
00088 #define LXT2_RD_LLDESC(x) x##i64
00089 #define LXT2_RD_ULLDESC(x) x##i64
00090 #endif
00091 
00092 #if LXT2_RD_GRANULE_SIZE > 32
00093 typedef lxtint64_t              granmsk_t;
00094 typedef lxtint32_t              granmsk_smaller_t;
00095 #define LXT2_RD_GRAN_0VAL       (LXT2_RD_ULLDESC(0))
00096 #define LXT2_RD_GRAN_1VAL       (LXT2_RD_ULLDESC(1))
00097 #define get_fac_msk             lxt2_rd_get_64
00098 #define get_fac_msk_smaller     lxt2_rd_get_32
00099 #else
00100 typedef lxtint32_t              granmsk_t;
00101 #define LXT2_RD_GRAN_0VAL       (0)
00102 #define LXT2_RD_GRAN_1VAL       (1)
00103 #define get_fac_msk             lxt2_rd_get_32
00104 #endif
00105 
00106 
00107 #define LXT2_RD_SYM_F_BITS      (0)
00108 #define LXT2_RD_SYM_F_INTEGER   (1<<0)
00109 #define LXT2_RD_SYM_F_DOUBLE    (1<<1)
00110 #define LXT2_RD_SYM_F_STRING    (1<<2)
00111 #define LXT2_RD_SYM_F_TIME      (LXT2_RD_SYM_F_STRING)  /* user must correctly format this as a string */
00112 #define LXT2_RD_SYM_F_ALIAS     (1<<3)
00113 
00114 #define LXT2_RD_SYM_F_SIGNED    (1<<4)
00115 #define LXT2_RD_SYM_F_BOOLEAN   (1<<5)
00116 #define LXT2_RD_SYM_F_NATURAL   ((1<<6)|(LXT2_RD_SYM_F_INTEGER))
00117 #define LXT2_RD_SYM_F_POSITIVE  ((1<<7)|(LXT2_RD_SYM_F_INTEGER))
00118 #define LXT2_RD_SYM_F_CHARACTER (1<<8)
00119 #define LXT2_RD_SYM_F_CONSTANT  (1<<9)
00120 #define LXT2_RD_SYM_F_VARIABLE  (1<<10)
00121 #define LXT2_RD_SYM_F_SIGNAL    (1<<11)
00122 
00123 #define LXT2_RD_SYM_F_IN        (1<<12)
00124 #define LXT2_RD_SYM_F_OUT       (1<<13)
00125 #define LXT2_RD_SYM_F_INOUT     (1<<14)
00126 
00127 #define LXT2_RD_SYM_F_WIRE      (1<<15)
00128 #define LXT2_RD_SYM_F_REG       (1<<16)
00129 
00130 
00131 enum LXT2_RD_Encodings {
00132         LXT2_RD_ENC_0,
00133         LXT2_RD_ENC_1,
00134         LXT2_RD_ENC_INV,
00135         LXT2_RD_ENC_LSH0,
00136         LXT2_RD_ENC_LSH1,
00137         LXT2_RD_ENC_RSH0,
00138         LXT2_RD_ENC_RSH1,
00139 
00140         LXT2_RD_ENC_ADD1,
00141         LXT2_RD_ENC_ADD2,
00142         LXT2_RD_ENC_ADD3,
00143         LXT2_RD_ENC_ADD4,
00144 
00145         LXT2_RD_ENC_SUB1,
00146         LXT2_RD_ENC_SUB2,
00147         LXT2_RD_ENC_SUB3,
00148         LXT2_RD_ENC_SUB4,
00149 
00150         LXT2_RD_ENC_X,
00151         LXT2_RD_ENC_Z, 
00152 
00153         LXT2_RD_ENC_BLACKOUT,
00154 
00155         LXT2_RD_DICT_START
00156         };
00157 
00158 
00159 struct lxt2_rd_block
00160 {
00161 unsigned char *mem;
00162 struct lxt2_rd_block *next;
00163 
00164 lxtint32_t uncompressed_siz, compressed_siz;
00165 lxtint64_t start, end;
00166 
00167 lxtint32_t num_map_entries, num_dict_entries;
00168 unsigned char *map_start;
00169 unsigned char *dict_start;
00170 
00171 unsigned char **string_pointers; /* based inside dict_start */
00172 unsigned int *string_lens;
00173 
00174 off_t filepos; /* where block starts in file if we have to reload */
00175 
00176 unsigned short_read_ignore : 1;  /* tried to read once and it was corrupt so ignore next time */
00177 unsigned exclude_block : 1;      /* user marked this block off to be ignored */
00178 };
00179 
00180 
00181 struct lxt2_rd_geometry
00182 {
00183 lxtint32_t rows, msb, lsb, flags, len;
00184 };
00185 
00186 
00187 struct lxt2_rd_facname_cache 
00188 {
00189 char *n;
00190 char *bufprev, *bufcurr;
00191 
00192 lxtint32_t old_facidx;
00193 };
00194 
00195 
00196 struct lxt2_rd_trace
00197 {
00198 lxtint32_t *rows, *msb, *lsb, *flags, *len;
00199 char **value;
00200 
00201 granmsk_t *fac_map;
00202 unsigned char **fac_curpos;
00203 char *process_mask;
00204 char *process_mask_compressed;
00205 
00206 void **radix_sort[LXT2_RD_GRANULE_SIZE+1];
00207 void **next_radix;
00208 
00209 void (*value_change_callback)(struct lxt2_rd_trace **lt, lxtint64_t *time, lxtint32_t *facidx, char **value);
00210 void *user_callback_data_pointer;
00211 
00212 unsigned char fac_map_index_width;
00213 unsigned char fac_curpos_width;
00214 lxtint8_t granule_size;
00215 
00216 lxtint32_t numfacs, numrealfacs, numfacbytes, longestname, zfacnamesize, zfacname_predec_size, zfacgeometrysize;
00217 lxtint8_t timescale;
00218 
00219 lxtint64_t prev_time;
00220 unsigned char num_time_table_entries;
00221 lxtint64_t time_table[LXT2_RD_GRANULE_SIZE];
00222 
00223 char *zfacnames;
00224 
00225 unsigned int numblocks;
00226 struct lxt2_rd_block *block_head, *block_curr;
00227 
00228 lxtint64_t start, end;
00229 struct lxt2_rd_geometry geometry;
00230 
00231 struct lxt2_rd_facname_cache *faccache;
00232 
00233 FILE *handle;
00234 #ifdef HAVE_LIBZ
00235 gzFile zhandle;
00236 #endif
00237 
00238 lxtint64_t block_mem_consumed, block_mem_max;
00239 
00240 unsigned process_mask_dirty : 1; /* only used on partial block reads */
00241 };
00242 
00243 
00244 /*
00245  * LXT2 Reader API functions...
00246  */
00247 struct lxt2_rd_trace *          lxt2_rd_init(const char *name);
00248 void                            lxt2_rd_close(struct lxt2_rd_trace *lt);
00249 
00250 _LXT2_RD_INLINE lxtint64_t      lxt2_rd_set_max_block_mem_usage(struct lxt2_rd_trace *lt, lxtint64_t block_mem_max);
00251 _LXT2_RD_INLINE lxtint64_t      lxt2_rd_get_block_mem_usage(struct lxt2_rd_trace *lt);
00252 _LXT2_RD_INLINE unsigned int    lxt2_rd_get_num_blocks(struct lxt2_rd_trace *lt);
00253 unsigned int                    lxt2_rd_get_num_active_blocks(struct lxt2_rd_trace *lt);
00254 
00255 _LXT2_RD_INLINE lxtint32_t      lxt2_rd_get_num_facs(struct lxt2_rd_trace *lt);
00256 char *                          lxt2_rd_get_facname(struct lxt2_rd_trace *lt, lxtint32_t facidx);
00257 struct lxt2_rd_geometry *       lxt2_rd_get_fac_geometry(struct lxt2_rd_trace *lt, lxtint32_t facidx);
00258 _LXT2_RD_INLINE lxtint32_t      lxt2_rd_get_fac_rows(struct lxt2_rd_trace *lt, lxtint32_t facidx);
00259 _LXT2_RD_INLINE lxtint32_t      lxt2_rd_get_fac_msb(struct lxt2_rd_trace *lt, lxtint32_t facidx);
00260 _LXT2_RD_INLINE lxtint32_t      lxt2_rd_get_fac_lsb(struct lxt2_rd_trace *lt, lxtint32_t facidx);
00261 _LXT2_RD_INLINE lxtint32_t      lxt2_rd_get_fac_flags(struct lxt2_rd_trace *lt, lxtint32_t facidx);
00262 _LXT2_RD_INLINE lxtint32_t      lxt2_rd_get_fac_len(struct lxt2_rd_trace *lt, lxtint32_t facidx);
00263 _LXT2_RD_INLINE lxtint32_t      lxt2_rd_get_alias_root(struct lxt2_rd_trace *lt, lxtint32_t facidx);
00264 
00265 _LXT2_RD_INLINE char            lxt2_rd_get_timescale(struct lxt2_rd_trace *lt);
00266 _LXT2_RD_INLINE lxtint64_t      lxt2_rd_get_start_time(struct lxt2_rd_trace *lt);
00267 _LXT2_RD_INLINE lxtint64_t      lxt2_rd_get_end_time(struct lxt2_rd_trace *lt);
00268 
00269 _LXT2_RD_INLINE int             lxt2_rd_get_fac_process_mask(struct lxt2_rd_trace *lt, lxtint32_t facidx);
00270 _LXT2_RD_INLINE int             lxt2_rd_set_fac_process_mask(struct lxt2_rd_trace *lt, lxtint32_t facidx);
00271 _LXT2_RD_INLINE int             lxt2_rd_clr_fac_process_mask(struct lxt2_rd_trace *lt, lxtint32_t facidx);
00272 _LXT2_RD_INLINE int             lxt2_rd_set_fac_process_mask_all(struct lxt2_rd_trace *lt);
00273 _LXT2_RD_INLINE int             lxt2_rd_clr_fac_process_mask_all(struct lxt2_rd_trace *lt);
00274 
00275                                 /* null value_change_callback calls an empty dummy function */
00276 int                             lxt2_rd_iter_blocks(struct lxt2_rd_trace *lt, 
00277                                 void (*value_change_callback)(struct lxt2_rd_trace **lt, lxtint64_t *time, lxtint32_t *facidx, char **value),
00278                                 void *user_callback_data_pointer);
00279 _LXT2_RD_INLINE void *          lxt2_rd_get_user_callback_data_pointer(struct lxt2_rd_trace *lt);
00280 
00281                                 /* time (un)/restricted read ops */
00282 unsigned int                    lxt2_rd_limit_time_range(struct lxt2_rd_trace *lt, lxtint64_t strt_time, lxtint64_t end_time);
00283 unsigned int                    lxt2_rd_unlimit_time_range(struct lxt2_rd_trace *lt);
00284 
00285 #endif
Generated on Sun Nov 21 00:55:35 2010 for Covered by  doxygen 1.6.3