# $Id: tasks.md,v 1.134 2007-06-05 00:24:52 eugene Exp $

# this table records all exposure ID ever seen from the summit
# exp_id == fileset

# note that dec is a MySQL reserved word
# note that use is a MySQL reserved word
# note that exp is a MySQL reserved word

# for use with this stored procedure to generate exp_tags under Mysql 5+
#
#CREATE FUNCTION genTag (exp_id varchar(64)) RETURNS VARCHAR(64)
#BEGIN
#    UPDATE expTagCounter SET counter = LAST_INSERT_ID(counter + 1);
#    RETURN CONCAT(exp_id, '.', LAST_INSERT_ID());
#END
#
expTagCounter METADATA
   counter     U64         0 
END

# list of source exposures -- updated as exposures are seen
# summitExp.imfiles is updated as filesets are queried default value should be
# -1 as NULL or 0 might be a valid value (empty fileset)
summitExp METADATA
    exp_id      STR         64      # Primary Key
    camera      STR         64      # Primary Key
    telescope   STR         64      # Primary Key
    dateobs     UTC         NULL
    exp_type    STR         64
    uri         STR         255
    imfiles     S32         0
END

# class == type of file
# class_id == type set id
# list of source images -- updated as exposures/filesets are queried
summitImfile METADATA
    exp_id      STR         64      # Primary Key
    camera      STR         64      # Primary Key
    telescope   STR         64      # Primary Key
    file_id     STR         64      # Key
    bytes       S32         0
    md5sum      STR         32
    class       STR         64      # Primary Key
    class_id    STR         64      # Primary Key
    uri         STR         255
END

# list of exposures that have had their imfiles/files registered (but not
# downloaded) 
pzPendingExp METADATA
    exp_id      STR         64      # Primary Key
    camera      STR         64      # Primary Key
    telescope   STR         64      # Primary Key
END

pzPendingImfile METADATA
    exp_id      STR         64      # Primary Key
    camera      STR         64      # Primary Key
    telescope   STR         64      # Primary Key
    class       STR         64      # Primary Key
    class_id    STR         64      # Primary Key
    exp_tag     STR         64      # Unique Key
END

# list of exposures that have had all of their imfiles downloaded
pzDoneExp METADATA
    exp_id      STR         64      # Primary Key
    camera      STR         64      # Primary Key
    telescope   STR         64      # Primary Key
END

pzDoneImfile METADATA
    exp_id      STR         64      # Primary Key
    camera      STR         64      # Primary Key
    telescope   STR         64      # Primary Key
    class       STR         64      # Primary Key
    class_id    STR         64      # Primary Key
    exp_tag     STR         64      # Unique Key
    uri         STR         255
END

newExp METADATA
    exp_tag     STR         64      # Primary Key
    exp_id      STR         64      # Key
    camera      STR         64      # Key
    telescope   STR         64      # Key
    imfiles     S32         0
    workdir     STR         255     # destination for output files
END

# class needs to be carried here so it can go into rawImfile and be normalized
# from there
newImfile METADATA
    exp_tag     STR         64      # Primary Key
    class       STR         64      # Primary Key
    class_id    STR         64      # Primary Key
    uri         STR         255
END

# paired with rawImfile
rawExp METADATA
    exp_tag     STR         64      # Primary Key
    exp_id      STR         64      # Key
    camera      STR         64
    telescope   STR         64
    dateobs     UTC         0001-01-01T00:00:00Z
    exp_type    STR         64
    imfiles     S32         0
    filelevel   STR         64
    workdir     STR         255     # destination for output files
    filter      STR         64
    airmass     F32         0.0
    ra          F64         0.0
    decl        F64         0.0
    exp_time    F32         0.0
    sat_pixel_frac F32      0.0
    bg          F64         0.0
    bg_stdev    F64         0.0
    bg_mean_stdev   F64     0.0
    alt         F64         0.0
    az          F64         0.0
    ccd_temp    F32         0.0
    posang      F64         0.0 
    user_1      F64         0.0
    user_2      F64         0.0
    user_3      F64         0.0
    user_4      F64         0.0
    user_5      F64         0.0
    object      STR         64
    solang      F32         0.0
    fault       S16         0       # Key NOT NULL
END

rawImfile METADATA
    exp_tag     STR         64      # Primary Key
    class_id    STR         64      # Primary Key
    uri         STR         255
    exp_type    STR         64
# This field is used to set the per exp filelevel. Thus the values for all of
# the imfiles in an exposure need to be sanity checked to make sure that this
# value is in argeement.
    filelevel   STR         64 
    filter      STR         64
    airmass     F32         0.0
    ra          F64         0.0
    decl        F64         0.0
    exp_time    F32         0.0
    sat_pixel_frac F32      0.0
    bg          F64         0.0
    bg_stdev    F64         0.0
    bg_mean_stdev   F64     0.0
    alt         F64         0.0
    az          F64         0.0
    ccd_temp    F32         0.0
    posang      F64         0.0 
    user_1      F64         0.0
    user_2      F64         0.0
    user_3      F64         0.0
    user_4      F64         0.0
    user_5      F64         0.0
    object      STR         64
    dateobs     UTC         0001-01-01T00:00:00Z
    fault       S16         0       # Key NOT NULL
END

#
# XXX - temporarily (???) stop carrying around class in imfiles after rawImfile
#
