next up previous contents
Next: JSOC environment functions Up: JSOC Internal functions Previous: JSOC Internal functions   Contents

JSOC API types

Below is the contents of the header file jsoc_types.h, which defines the data structures for series, record, keywords, links, and data segments.

#ifndef _JSOC_TYPES_H
#define _JSOC_TYPES_H

#include "db.h"
#include "hash_table.h"

/* Constants */
#define JSOC_MAXNAMELEN        (255)
#define JSOC_MAXHASHKEYLEN     (JSOC_MAXNAMELEN+20)
#define JSOC_MAXUNITLEN        (20)
#define JSOC_MAXCLASSES        (8192)
#define JSOC_MAXQUERYLEN       (8192)
#define JSOC_MAXPATHLEN        (8192)
#define JSOC_MAXFORMATLEN      (20)
#define JSOC_MAXRANK           (255)
#define JSOC_MAXDATASEGMENTS    (255)
#define JSOC_LAZY_INIT         (1L)
#define JSOC_MAXCOMMENTLEN     (2048)

/*************************** JSOC related types ************************/

/* ("Keyword") values of keywords belong to one of the following
   simple classes. */
typedef enum {JSOC_TYPE_CHAR, JSOC_TYPE_SHORT, JSOC_TYPE_LONG, 
              JSOC_TYPE_LONGLONG, JSOC_TYPE_FLOAT, JSOC_TYPE_DOUBLE, 
              JSOC_TYPE_DATETIME, JSOC_TYPE_TIMESTAMP, 
              JSOC_TYPE_STRING} JSOC_Simple_t;

#ifndef JSOC_TYPES_C
extern char *mdc_type_names[];
#endif

#define JSOC_MAXTYPENAMELEN  (9)
#define JSOC_DATETIMELEN  (32)
#define JSOC_TIMESTAMPLEN (32)

typedef union JSOC_Simple_Value
{
  char char_val;
  short short_val;
  long   long_val;
  long long longlong_val;
  float float_val;
  double double_val;
  char datetime_val[JSOC_DATETIMELEN];
  char timestamp_val[JSOC_TIMESTAMPLEN];
  char *string_val;
} JSOC_Simple_Value_t;


typedef struct  JSOC_Keyword_struct
{
  char name[JSOC_MAXNAMELEN];     /* Keyword name. */

  /* If this is an inherited keyword, islink is non-zero,
     and linkname holds the name of the link which points
     to the dataset holding the actual keyword value. */

  int islink;
  char linkname[JSOC_MAXNAMELEN]; /* Link name. */

  int column;                    /* Which column in the dataset table
                                    holds this keyword? */ 
  JSOC_Simple_t type;             /* Keyword type. */
  char format[JSOC_MAXFORMATLEN]; /* Format string for formatted input 
                                    and output. */
  char unit[JSOC_MAXUNITLEN];     /* Physical unit. */
  int  size;                     /* Size of keyword data in bytes.*/
  JSOC_Simple_Value_t value;      /* Keyword data. If the Keyword is used as part
                                    of a series template then value contains the
                                    default value. */
  char comment[JSOC_MAXCOMMENTLEN];


} JSOC_Keyword_t;


/* Links to other objects from which keyword values can be inherited. 
   A link often indicates that the present object was computed using the
   data in the object pointed to.
*/

typedef enum { SIMPLE_LINK, QUERY_LINK } JSOC_Link_type_t;
typedef struct JSOC_Link_struct
{
  char name[JSOC_MAXNAMELEN];           /* Link name. */
  char target_series[JSOC_MAXNAMELEN];   /* Series pointed to. */  
  int id, version;
  int column;                          /* Column in main series table where the
                                          target id is found; version is found
                                          in (column+1). */
  JSOC_Link_type_t type;
  char where_clause[JSOC_MAXQUERYLEN];
  char comment[JSOC_MAXCOMMENTLEN];
} JSOC_Link_t;


/* 
   The data descriptors hold basic information about the in-memory
   representation of the data. 
*/
typedef enum  {JSOC_BINARY, JSOC_FITZ, JSOC_FITS} JSOC_Storage_Protocol_t;
typedef struct JSOC_Data_Locator_struct
{
  long long dsindex;   /* Index to the storage management table in
                          the database. */
  char *path;          /* If non-null points to the resolved path. */
  JSOC_Storage_Protocol_t storage_protocol;
} JSOC_Data_Locator_t;
      

typedef struct JSOC_Data_struct
{
  JSOC_Simple_t type;      /* Type of the observable. */
  char unit[JSOC_MAXUNITLEN];             /* Physical unit. */
  int size;               /* Size in bytes of the elements. */
  int naxis;               /* Number of dimensions. */
  int axis[JSOC_MAXRANK];   /* Size of each dimension. */
} JSOC_Data_t;

/* Data descriptor for a dataset. The data part of a dataset consists
   of a collection of observables. Each observable is an n-dimensional
   array of a simple type. */
typedef struct JSOC_Data_struct
{
  JSOC_Data_Locator_t location;   /* Data set location and storage protocol. */
  int num_obs;                   /* Number of observables. */
  JSOC_Data_t obs[JSOC_MAXDATASEGMENTS]; /* An array of descriptors. 
                                               Each layer represents an 
                                               n-dimensional array of a 
                                               single observable.*/
} JSOC_Data_t;


/* An in-memory slice of an observable. If the full observable is
   the n-dimensional array 
     A(0:(obs->axis[0]-1),0:(obs->axis[1]-1),...,0:(obs->axis[obs->naxis-1]-1)
   then the memory location pointed to by data holds the slice
     A(start[0]:end[0],start[1]:end[1],...,start[obs->naxis-1]:end[obs->naxis-1])
   stored in column major order.
*/
typedef struct JSOC_Data_Slice_struct
{
  JSOC_Data_t *obs;
  int start[JSOC_MAXRANK];
  int end[JSOC_MAXRANK];
  void *data;
} JSOC_Data_Slice_t;

/* Datastructure holding a single data record. */
typedef struct JSOC_DataRecord_struct
{
  struct JSOC_Env_struct *env;         /* Pointer to global JSOC environment. */

  /* The following three fields uniquely identify the object: */
  char seriesname[JSOC_MAXNAMELEN];  /* Name of series this dataset belongs to. */
  int id, version;                 /* (id, version) is a unique identifier 
                                      of this object within its series. */
  char hashkey[JSOC_MAXHASHKEYLEN]; /* Hash key is a string containing 
                                      "seriesname_<id>_<version>". */

  /* Dirty flags */
  int keyw_dirty;              /* Have the keywords been modified? */ 
  int link_dirty;              /* Have the links been modified? */
  int data_dirty;              /* Have the data arrays been modified? */ 

  /* Keywords. */
  int num_keyw, max_keyw;      /* Number of keywords. */
  JSOC_Keyword_t *keyw;            /* Array of keywords. */
  Hash_Table_t keyw_hash;      /* Hash table for fast lookup of keywords. */


  /* Links. */
  int num_link, max_link;      /* Number of links. */
  JSOC_Link_t *link;            /* Array of links. */
  Hash_Table_t link_hash;      /* Hash table for fast lookup of links. */

  /* "Image" data. */
  JSOC_Data_t *data;            /* Data descriptor. */
} JSOC_DataRecord_t;

typedef struct JSOC_Series_struct
{
  int tapegroup;
  int chunksize;
  int archive;
  char author[JSOC_MAXCOMMENTLEN];
  char owners[JSOC_MAXCOMMENTLEN];
  char description[JSOC_MAXCOMMENTLEN];
  JSOC_DataRecord_t template;
}  JSOC_Series_t;

typedef struct JSOC_Env_struct
{
  int errno;                         /* Error flag. */
  DB_Handle_t *db;                   /* Database connection handle. */

  /* Series cache data structures. */
  int num_series;                   /* Total number of series listed in the
                                        database. */
  char *init_tag;                     /* Array of tags indicating which
                                        series templates have been populated
                                        with data from the database. */
  JSOC_DataRecord_t *series_cache;       /* Cache array of series templates for 
                                       all series in the system. */
  Hash_Table_t series_hash;           /* Hash table for mapping series names
                                        to indices in the series_cache array. */
  DB_Text_Result_t *series_names;    /*  Table of all seriesnames returned from
                                        the database. These strings are used as
                                        keys in the hash table. */
  /* DataRecord cache data structures. */
  int num_ds;                        /* Number of datasets in memory. */
  int max_ds;                        /* Max number of datasets in cache 
                                        memory. */
  char *ds_freelist;                 /* List of free slots in the
                                           ds_cache. */
  int ds_firstfree;                  /* Index of first free slot in the 
                                        ds_cache */
  JSOC_DataRecord_t *ds_cache;          /* Array of all datasets currently
                                        in memory. */
  Hash_Table_t ds_hash;             /* Hash table for mapping dataset 
                                       identifer (seriesname, id, version) to
                                       indices in the ds_cache array. */
} JSOC_Env_t;

/* Return enum value for a simple type given its name. */
JSOC_Simple_t mdc_str2type(char *);
const char  *mdc_type2str(JSOC_Simple_t type);
int mdc_copy_db2mdc(JSOC_Simple_t mdc_type, JSOC_Simple_Value_t *mdc_dst, 
                    DB_Type_t db_type, char *db_src);
DB_Type_t mdc2dbtype(JSOC_Simple_t type);
int mdc_sizeof(JSOC_Simple_t type);



Philip Scherrer 2006-06-17