# $Id: tasks.md,v 1.115 2007-01-29 17:42:51 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
    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
    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 
    object      STR         64
    fault       S16         0       # NOT NULL
END

rawImfile METADATA
    exp_tag     STR         64      # Primary Key
    class       STR         64
    class_id    STR         64      # Primary Key
    uri         STR         255
    exp_type    STR         64
    filter      STR         64
    airmass     F32         0.0
    ra          F64         0.0
    decl        F64         0.0
    exp_time    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 
    object      STR         64
    dateobs     UTC         0001-01-01T00:00:00Z
    fault       S16         0       # NOT NULL
END

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

p1PendingExp METADATA
    exp_tag     STR         64     # Primary Key
    recipe      STR         64
    p1_version  S32         0
END

# do we need nclass?
# class is missing

p2PendingExp METADATA
    exp_tag     STR         64      # Primary Key
    recipe      STR         64
    p1_version  S32         0
    p2_version  S32         0
    label       STR         64      # key
END

# uris in & out ?

p2PendingImfile METADATA
    exp_tag     STR         64      # Primary Key
    class_id    STR         64      # Primary Key
    uri         STR         255
    recipe      STR         64
    p1_version  S32         0
    p2_version  S32         0
END

# nclass & ndone?
# and/or logging imfile done better?

p2ProcessedExp METADATA
    exp_tag     STR         64      # Primary Key
    p1_version  S32         0
    p2_version  S32         0
    label       STR         64      # key
END

p2Mask METADATA
    label       STR         64      # Primary Key
END

# uris in & out ?
# state?

p2ProcessedImfile METADATA
    exp_tag     STR         64      # Primary Key
    class_id    STR         64      # Primary Key
    uri         STR         255
    recipe      STR         64
    bg          F64         0.0
    bg_stdev    F64         0.0
    bg_mean_stdev   F64         0.0
    b1_uri      STR         255
    b2_uri      STR         255
    p1_version  S32         0
    p2_version  S32         0
    fault       S16         0       # NOT NULL
END

# imfiles is not here... is it needed?

p3PendingExp METADATA
    exp_tag     STR         64      # Primary Key
    p2_version  S32         0
    p3_version  S32         0
    label       STR         64      # key
END

p3ProcessedExp METADATA
    exp_tag     STR         64      # Primary Key
    uri         STR         255
    recipe      STR         64
    bg          F64         0.0
    bg_stdev    F64         0.0
    bg_mean_stdev   F64         0.0
    sigma_ra    F32         0.0
    sigma_dec   F32         0.0
    nastro      S32         0
    b1_uri      STR         255
    b2_uri      STR         255
    zp_mean     F32         0.0
    zp_stdev    F32         0.0
    p2_version  S32         0
    p3_version  S32         0
    label       STR         64      # key
    fault       S16         0       # NOT NULL
END

p3Mask METADATA
    label       STR         64      # Primary Key
END

detRun METADATA
    det_id      S32         0      # Primary Key AUTO_INCREMENT
    iteration   S32         0      # Key
    det_type    STR         64     # Key
    mode        STR         64     # Key
    state       STR         64     # Key
    workdir     STR         255     # destination for output files
    camera      STR         64
    telescope   STR         64
    exp_type    STR         64     # XXX this should be dropped
    filter      STR         64
    airmass_min F32         0.0
    airmass_max F32         0.0
    exp_time_min F32        0.0
    exp_time_max F32        0.0
    ccd_temp_min F32        0.0
    ccd_temp_max F32        0.0
    posang_min  F64         0.0 
    posang_max  F64         0.0 
    registered  TAI         0001-01-01T00:00:00Z
    time_begin  TAI         0001-01-01T00:00:00Z
    time_end    TAI         0001-01-01T00:00:00Z
    use_begin   TAI         0001-01-01T00:00:00Z
    use_end     TAI         0001-01-01T00:00:00Z
END

detInputExp METADATA
    det_id      S32         0       # Primary Key
    iteration   S32         0       # Primary Key
    exp_tag     STR         64      # Primary Key
    include     BOOL        f
END

detProcessedImfile METADATA
    det_id      S32         0      # Primary Key
    exp_tag     STR         64     # Primary Key
    class_id    STR         64     # Primary Key
    uri         STR         255
    recipe      STR         64
    bg          F64         0.0
    bg_stdev    F64         0.0
    bg_mean_stdev   F64         0.0
    b1_uri      STR         255
    b2_uri      STR         255
    fault       S16         0       # NOT NULL
END

detProcessedExp METADATA
    det_id      S32         0      # Primary Key
    exp_tag     STR         64     # Primary Key
    recipe      STR         64
    bg          F64         0.0
    bg_stdev    F64         0.0
    bg_mean_stdev   F64         0.0
    b1_uri      STR         255
    b2_uri      STR         255
    fault       S16         0       # NOT NULL
END

detStackedImfile METADATA
    det_id      S32         0       # Primary Key
    iteration   S32         0       # Primary Key
    class_id    STR         64      # Primary Key
    uri         STR         255
    recipe      STR         64
    bg          F64         0.0
    bg_stdev    F64         0.0
    bg_mean_stdev   F64         0.0
    fault       S16         0       # NOT NULL
END

detNormalizedStatImfile METADATA
    det_id      S32         0       # Primary Key
    iteration   S32         0       # Primary Key
    class_id    STR         64      # Primary Key
    norm        F32         0.0
    fault       S16         0       # NOT NULL
END

detNormalizedImfile METADATA
    det_id      S32         0       # Primary Key
    iteration   S32         0       # Primary Key
    class_id    STR         64      # Primary Key
    uri         STR         255
    bg          F64         0.0
    bg_stdev    F64         0.0
    bg_mean_stdev   F64         0.0
    b1_uri      STR         255
    b2_uri      STR         255
    fault       S16         0       # NOT NULL
END

detNormalizedExp METADATA
    det_id      S32         0       # Primary Key
    iteration   S32         0       # Primary Key
    recipe      STR         64
    bg          F64         0.0
    bg_stdev    F64         0.0
    bg_mean_stdev   F64         0.0
    b1_uri      STR         255
    b2_uri      STR         255
    fault       S16         0       # NOT NULL
END

#detMasterFrame METADATA
#    det_id      S32         0       # Primary Key
#    iteration   S32         0       # Primary Key
#    comment     STR         255
#END
#
## drop?
#detMasterImfile METADATA
#    det_id      S32         0       # Primary Key
#    class_id    STR         64      # Primary Key
#    uri         STR         255
#    recipe      STR         64
#END

detResidImfile METADATA
    det_id      S32         0       # Primary Key
    iteration   S32         0       # Primary Key
    exp_tag     STR         64      # Primary Key
    class_id    STR         64      # Primary Key
    uri         STR         255
    recipe      STR         64
    bg          F64         0.0
    bg_stdev    F64         0.0
    bg_mean_stdev   F64         0.0
    b1_uri      STR         255
    b2_uri      STR         255
    fault       S16         0       # NOT NULL
END

detResidExp METADATA
    det_id      S32         0       # Primary Key
    iteration   S32         0       # Primary Key
    exp_tag     STR         64      # Primary Key
    recipe      STR         64
    bg          F64         0.0
    bg_stdev    F64         0.0
    bg_mean_stdev   F64         0.0
    b1_uri      STR         255
    b2_uri      STR         255
    accept      BOOL        f
    fault       S16         0       # NOT NULL
END

detRunSummary METADATA
    det_id      S32         0       # Primary Key
    iteration   S32         0       # Primary Key
    bg          F64         0.0
    bg_stdev    F64         0.0
    bg_mean_stdev   F64         0.0
    accept      BOOL        f
    fault       S16         0       # NOT NULL
END
