IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11867


Ignore:
Timestamp:
Feb 16, 2007, 4:42:59 PM (19 years ago)
Author:
jhoblitt
Message:

VERSION 1.1.8

Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/dbconfig/p6.md

    r11815 r11867  
    1 # $Id: p6.md,v 1.2 2007-02-15 02:46:29 jhoblitt Exp $
     1# $Id: p6.md,v 1.3 2007-02-17 02:42:39 jhoblitt Exp $
    22
    33p6Run METADATA
     
    88END
    99
     10p6InputScfile METADATA
     11    p6_id       S32         0       # Primary Key
     12    p4_id       S32         0       # Primary Key
     13    skycell_id  STR         64      # Primary Key
     14    tess_id     STR         64      # Primary Key
     15END
     16
     17p6SumScfile METADATA
     18    p6_id       S32         0       # Primary Key
     19    skycell_id  STR         64      # Primary Key
     20    tess_id     STR         64      # Primary Key
     21    uri         STR         255
     22    bg          F64         0.0
     23    bg_mean_stdev   F64     0.0
     24END
  • trunk/ippTools/configure.ac

    r11821 r11867  
    11AC_PREREQ(2.59)
    22
    3 AC_INIT([ipptools], [1.1.7], [ipp-support@ifa.hawaii.edu])
     3AC_INIT([ipptools], [1.1.8], [ipp-support@ifa.hawaii.edu])
    44AC_CONFIG_SRCDIR([autogen.sh])
    55
     
    1818PKG_CHECK_MODULES([PSLIB], [pslib >= 1.1.0])
    1919PKG_CHECK_MODULES([PSMODULES], [psmodules >= 1.1.0])
    20 PKG_CHECK_MODULES([IPPDB], [ippdb >= 1.1.7])
     20PKG_CHECK_MODULES([IPPDB], [ippdb >= 1.1.8])
    2121
    2222PXTOOLS_CFLAGS="${PSLIB_CFLAGS=} ${PSMODULES_CFLAGS=} ${IPPDB_CFLAGS=}"
  • trunk/ippdb/Makefile.am

    r11820 r11867  
    4848    $(top_builddir)/docs/man/man3/p5InputScfileRow.3 \
    4949    $(top_builddir)/docs/man/man3/p5DiffScfileRow.3 \
    50     $(top_builddir)/docs/man/man3/p6RunRow.3
     50    $(top_builddir)/docs/man/man3/p6RunRow.3 \
     51    $(top_builddir)/docs/man/man3/p6InputScfileRow.3 \
     52    $(top_builddir)/docs/man/man3/p6SumScfileRow.3
    5153
    5254
    53 docs/man/man3/ippdb.3 docs/man/man3/expTagCounterRow.3 docs/man/man3/summitExpRow.3 docs/man/man3/summitImfileRow.3 docs/man/man3/pzPendingExpRow.3 docs/man/man3/pzPendingImfileRow.3 docs/man/man3/pzDoneExpRow.3 docs/man/man3/pzDoneImfileRow.3 docs/man/man3/newExpRow.3 docs/man/man3/newImfileRow.3 docs/man/man3/rawExpRow.3 docs/man/man3/rawImfileRow.3 docs/man/man3/p1PendingExpRow.3 docs/man/man3/p2PendingExpRow.3 docs/man/man3/p2PendingImfileRow.3 docs/man/man3/p2ProcessedExpRow.3 docs/man/man3/p2MaskRow.3 docs/man/man3/p2ProcessedImfileRow.3 docs/man/man3/p3PendingExpRow.3 docs/man/man3/p3ProcessedExpRow.3 docs/man/man3/p3MaskRow.3 docs/man/man3/detRunRow.3 docs/man/man3/detInputExpRow.3 docs/man/man3/detProcessedImfileRow.3 docs/man/man3/detProcessedExpRow.3 docs/man/man3/detStackedImfileRow.3 docs/man/man3/detNormalizedStatImfileRow.3 docs/man/man3/detNormalizedImfileRow.3 docs/man/man3/detNormalizedExpRow.3 docs/man/man3/detResidImfileRow.3 docs/man/man3/detResidExpRow.3 docs/man/man3/detRunSummaryRow.3 docs/man/man3/p4RunRow.3 docs/man/man3/p4InputExpRow.3 docs/man/man3/p4SkyCellMapRow.3 docs/man/man3/p4ScfileRow.3 docs/man/man3/p5RunRow.3 docs/man/man3/p5InputScfileRow.3 docs/man/man3/p5DiffScfileRow.3 docs/man/man3/p6RunRow.3:
     55docs/man/man3/ippdb.3 docs/man/man3/expTagCounterRow.3 docs/man/man3/summitExpRow.3 docs/man/man3/summitImfileRow.3 docs/man/man3/pzPendingExpRow.3 docs/man/man3/pzPendingImfileRow.3 docs/man/man3/pzDoneExpRow.3 docs/man/man3/pzDoneImfileRow.3 docs/man/man3/newExpRow.3 docs/man/man3/newImfileRow.3 docs/man/man3/rawExpRow.3 docs/man/man3/rawImfileRow.3 docs/man/man3/p1PendingExpRow.3 docs/man/man3/p2PendingExpRow.3 docs/man/man3/p2PendingImfileRow.3 docs/man/man3/p2ProcessedExpRow.3 docs/man/man3/p2MaskRow.3 docs/man/man3/p2ProcessedImfileRow.3 docs/man/man3/p3PendingExpRow.3 docs/man/man3/p3ProcessedExpRow.3 docs/man/man3/p3MaskRow.3 docs/man/man3/detRunRow.3 docs/man/man3/detInputExpRow.3 docs/man/man3/detProcessedImfileRow.3 docs/man/man3/detProcessedExpRow.3 docs/man/man3/detStackedImfileRow.3 docs/man/man3/detNormalizedStatImfileRow.3 docs/man/man3/detNormalizedImfileRow.3 docs/man/man3/detNormalizedExpRow.3 docs/man/man3/detResidImfileRow.3 docs/man/man3/detResidExpRow.3 docs/man/man3/detRunSummaryRow.3 docs/man/man3/p4RunRow.3 docs/man/man3/p4InputExpRow.3 docs/man/man3/p4SkyCellMapRow.3 docs/man/man3/p4ScfileRow.3 docs/man/man3/p5RunRow.3 docs/man/man3/p5InputScfileRow.3 docs/man/man3/p5DiffScfileRow.3 docs/man/man3/p6RunRow.3 docs/man/man3/p6InputScfileRow.3 docs/man/man3/p6SumScfileRow.3:
    5456        $(DOXYGEN)
    5557
  • trunk/ippdb/src/ippdb.c

    r11820 r11867  
    7070#define P5DIFFSCFILE_TABLE_NAME "p5DiffScfile"
    7171#define P6RUN_TABLE_NAME "p6Run"
     72#define P6INPUTSCFILE_TABLE_NAME "p6InputScfile"
     73#define P6SUMSCFILE_TABLE_NAME "p6SumScfile"
    7274#define MAX_STRING_LENGTH 1024
    7375
     
    1651016512    return true;
    1651116513}
     16514static void p6InputScfileRowFree(p6InputScfileRow *object);
     16515
     16516p6InputScfileRow *p6InputScfileRowAlloc(psS32 p6_id, psS32 p4_id, const char *skycell_id, const char *tess_id)
     16517{
     16518    p6InputScfileRow *_object;
     16519
     16520    _object = psAlloc(sizeof(p6InputScfileRow));
     16521    psMemSetDeallocator(_object, (psFreeFunc)p6InputScfileRowFree);
     16522
     16523    _object->p6_id = p6_id;
     16524    _object->p4_id = p4_id;
     16525    _object->skycell_id = psStringCopy(skycell_id);
     16526    _object->tess_id = psStringCopy(tess_id);
     16527
     16528    return _object;
     16529}
     16530
     16531static void p6InputScfileRowFree(p6InputScfileRow *object)
     16532{
     16533    psFree(object->skycell_id);
     16534    psFree(object->tess_id);
     16535}
     16536
     16537bool p6InputScfileCreateTable(psDB *dbh)
     16538{
     16539    psMetadata *md = psMetadataAlloc();
     16540    if (!psMetadataAdd(md, PS_LIST_TAIL, "p6_id", PS_DATA_S32, "Primary Key", 0)) {
     16541        psError(PS_ERR_UNKNOWN, false, "failed to add item p6_id");
     16542        psFree(md);
     16543        return false;
     16544    }
     16545    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, "Primary Key", 0)) {
     16546        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
     16547        psFree(md);
     16548        return false;
     16549    }
     16550    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {
     16551        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
     16552        psFree(md);
     16553        return false;
     16554    }
     16555    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {
     16556        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
     16557        psFree(md);
     16558        return false;
     16559    }
     16560
     16561    bool status = psDBCreateTable(dbh, P6INPUTSCFILE_TABLE_NAME, md);
     16562
     16563    psFree(md);
     16564
     16565    return status;
     16566}
     16567
     16568bool p6InputScfileDropTable(psDB *dbh)
     16569{
     16570    return psDBDropTable(dbh, P6INPUTSCFILE_TABLE_NAME);
     16571}
     16572
     16573bool p6InputScfileInsert(psDB * dbh, psS32 p6_id, psS32 p4_id, const char *skycell_id, const char *tess_id)
     16574{
     16575    psMetadata *md = psMetadataAlloc();
     16576    if (!psMetadataAdd(md, PS_LIST_TAIL, "p6_id", PS_DATA_S32, NULL, p6_id)) {
     16577        psError(PS_ERR_UNKNOWN, false, "failed to add item p6_id");
     16578        psFree(md);
     16579        return false;
     16580    }
     16581    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, p4_id)) {
     16582        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
     16583        psFree(md);
     16584        return false;
     16585    }
     16586    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {
     16587        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
     16588        psFree(md);
     16589        return false;
     16590    }
     16591    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {
     16592        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
     16593        psFree(md);
     16594        return false;
     16595    }
     16596
     16597    bool status = psDBInsertOneRow(dbh, P6INPUTSCFILE_TABLE_NAME, md);
     16598    psFree(md);
     16599
     16600    return status;
     16601}
     16602
     16603long long p6InputScfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
     16604{
     16605    long long       deleted = 0;
     16606
     16607    long long count = psDBDeleteRows(dbh, P6INPUTSCFILE_TABLE_NAME, where, limit);
     16608    if (count < 0) {
     16609        psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6InputScfile");
     16610        return count;
     16611
     16612        deleted += count;
     16613    }
     16614
     16615    return deleted;
     16616}
     16617bool p6InputScfileInsertObject(psDB *dbh, p6InputScfileRow *object)
     16618{
     16619    return p6InputScfileInsert(dbh, object->p6_id, object->p4_id, object->skycell_id, object->tess_id);
     16620}
     16621
     16622bool p6InputScfileInsertObjects(psDB *dbh, psArray *objects)
     16623{
     16624    for (long i = 0; i < psArrayLength(objects); i++) {
     16625        if (!p6InputScfileInsertObject(dbh, objects->data[i])) {
     16626            return false;
     16627        }
     16628    }
     16629
     16630    return true;
     16631}
     16632
     16633bool p6InputScfileInsertFits(psDB *dbh, const psFits *fits)
     16634{
     16635    psArray         *rowSet;
     16636
     16637    // move to (the first?) extension named  P6INPUTSCFILE_TABLE_NAME
     16638    if (!psFitsMoveExtName(fits, P6INPUTSCFILE_TABLE_NAME)) {
     16639        psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P6INPUTSCFILE_TABLE_NAME);
     16640        return false;
     16641    }
     16642
     16643    // check HDU type
     16644    if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
     16645        psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
     16646        return false;
     16647    }
     16648
     16649    // read fits table
     16650    rowSet = psFitsReadTable(fits);
     16651    if (!rowSet) {
     16652        psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
     16653        psFree(rowSet);
     16654        return false;
     16655    }
     16656
     16657    if (!psDBInsertRows(dbh, P6INPUTSCFILE_TABLE_NAME, rowSet)) {
     16658        psError(PS_ERR_UNKNOWN, false, "databse insert failed");
     16659        psFree(rowSet);
     16660        return false;
     16661    }
     16662
     16663    psFree(rowSet);
     16664
     16665    return true;
     16666}
     16667
     16668bool p6InputScfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
     16669{
     16670    psArray         *rowSet;
     16671
     16672    rowSet = psDBSelectRows(dbh, P6INPUTSCFILE_TABLE_NAME, where, limit);
     16673    if (!rowSet) {
     16674        return false;
     16675    }
     16676
     16677    // output to fits
     16678    if (!psFitsWriteTable(fits, NULL, rowSet, P6INPUTSCFILE_TABLE_NAME)) {
     16679        psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
     16680        psFree(rowSet);
     16681        return false;
     16682    }
     16683
     16684    psFree(rowSet);
     16685
     16686    return true;
     16687}
     16688
     16689psMetadata *p6InputScfileMetadataFromObject(const p6InputScfileRow *object)
     16690{
     16691    psMetadata *md = psMetadataAlloc();
     16692    if (!psMetadataAdd(md, PS_LIST_TAIL, "p6_id", PS_DATA_S32, NULL, object->p6_id)) {
     16693        psError(PS_ERR_UNKNOWN, false, "failed to add item p6_id");
     16694        psFree(md);
     16695        return false;
     16696    }
     16697    if (!psMetadataAdd(md, PS_LIST_TAIL, "p4_id", PS_DATA_S32, NULL, object->p4_id)) {
     16698        psError(PS_ERR_UNKNOWN, false, "failed to add item p4_id");
     16699        psFree(md);
     16700        return false;
     16701    }
     16702    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {
     16703        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
     16704        psFree(md);
     16705        return false;
     16706    }
     16707    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {
     16708        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
     16709        psFree(md);
     16710        return false;
     16711    }
     16712
     16713
     16714    return md;
     16715}
     16716
     16717p6InputScfileRow *p6InputScfileObjectFromMetadata(psMetadata *md)
     16718{
     16719
     16720bool status = false;
     16721    psS32 p6_id = psMetadataLookupS32(&status, md, "p6_id");
     16722    if (!status) {
     16723        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p6_id");
     16724        return false;
     16725    }
     16726    psS32 p4_id = psMetadataLookupS32(&status, md, "p4_id");
     16727    if (!status) {
     16728        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4_id");
     16729        return false;
     16730    }
     16731    char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");
     16732    if (!status) {
     16733        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");
     16734        return false;
     16735    }
     16736    char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");
     16737    if (!status) {
     16738        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");
     16739        return false;
     16740    }
     16741
     16742    return p6InputScfileRowAlloc(p6_id, p4_id, skycell_id, tess_id);
     16743}
     16744psArray *p6InputScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
     16745{
     16746    psArray         *rowSet;
     16747    psArray         *returnSet;
     16748    psU64           i;
     16749
     16750    rowSet = psDBSelectRows(dbh, P6INPUTSCFILE_TABLE_NAME, where, limit);
     16751    if (!rowSet) {
     16752        return NULL;
     16753    }
     16754
     16755    // convert psMetadata rows to row objects
     16756
     16757    returnSet = psArrayAllocEmpty(rowSet->n);
     16758
     16759    for (i = 0; i < rowSet->n; i++) {
     16760        p6InputScfileRow *object = p6InputScfileObjectFromMetadata(rowSet->data[i]);
     16761        psArrayAdd(returnSet, 0, object);
     16762        psFree(object);
     16763    }
     16764
     16765    psFree(rowSet);
     16766
     16767    return returnSet;
     16768}
     16769bool p6InputScfileDeleteObject(psDB *dbh, const p6InputScfileRow *object)
     16770{
     16771    psMetadata *where = p6InputScfileMetadataFromObject(object);
     16772    long long count = psDBDeleteRows(dbh, P6INPUTSCFILE_TABLE_NAME, where, 0);
     16773    psFree(where);
     16774    if (count < 0) {
     16775        psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6InputScfile");
     16776        return false;
     16777    }
     16778    if (count > 1) {
     16779        // XXX should this be a psAbort() instead?  It is possible that
     16780        // having an object match multiple rows was by design.
     16781        psError(PS_ERR_UNKNOWN, true, "p6InputScfileRow object matched more then one row.  Check your database schema");
     16782        return false;
     16783    }
     16784
     16785    return true;
     16786}
     16787long long p6InputScfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
     16788{
     16789    long long       deleted = 0;
     16790
     16791    for (long long i = 0; i < objects->n; i++) {
     16792        p6InputScfileRow *object = objects->data[i];
     16793        psMetadata *where = p6InputScfileMetadataFromObject(object);
     16794        long long count = psDBDeleteRows(dbh, P6INPUTSCFILE_TABLE_NAME, where, limit);
     16795        psFree(where);
     16796        if (count < 0) {
     16797            psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6InputScfile");
     16798            return count;
     16799        }
     16800
     16801        deleted += count;
     16802    }
     16803
     16804    return deleted;
     16805}
     16806bool p6InputScfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)
     16807{
     16808    PS_ASSERT_PTR_NON_NULL(objects, false);
     16809
     16810    psMetadata *output = psMetadataAlloc();
     16811    for (long i = 0; i < psArrayLength(objects); i++) {
     16812        psMetadata *md = p6InputScfileMetadataFromObject(objects->data[i]);
     16813        if (!psMetadataAddMetadata(
     16814            output,
     16815            PS_LIST_TAIL,
     16816            P6INPUTSCFILE_TABLE_NAME,
     16817            PS_META_DUPLICATE_OK,
     16818            NULL,
     16819            md
     16820        )) {
     16821            psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
     16822            psFree(md);
     16823            psFree(output);
     16824            return false;
     16825        }
     16826        psFree(md);
     16827    }
     16828
     16829    if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
     16830        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
     16831        psFree(output);
     16832    }
     16833    psFree(output);
     16834
     16835    return true;
     16836}
     16837bool p6InputScfilePrintObject(FILE *stream, p6InputScfileRow *object, bool mdcf)
     16838{
     16839    PS_ASSERT_PTR_NON_NULL(object, false);
     16840
     16841    psMetadata *md = p6InputScfileMetadataFromObject(object);
     16842
     16843    if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
     16844        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
     16845        psFree(md);
     16846    }
     16847
     16848    psFree(md);
     16849
     16850    return true;
     16851}
     16852static void p6SumScfileRowFree(p6SumScfileRow *object);
     16853
     16854p6SumScfileRow *p6SumScfileRowAlloc(psS32 p6_id, const char *skycell_id, const char *tess_id, const char *uri, psF64 bg, psF64 bg_mean_stdev)
     16855{
     16856    p6SumScfileRow  *_object;
     16857
     16858    _object = psAlloc(sizeof(p6SumScfileRow));
     16859    psMemSetDeallocator(_object, (psFreeFunc)p6SumScfileRowFree);
     16860
     16861    _object->p6_id = p6_id;
     16862    _object->skycell_id = psStringCopy(skycell_id);
     16863    _object->tess_id = psStringCopy(tess_id);
     16864    _object->uri = psStringCopy(uri);
     16865    _object->bg = bg;
     16866    _object->bg_mean_stdev = bg_mean_stdev;
     16867
     16868    return _object;
     16869}
     16870
     16871static void p6SumScfileRowFree(p6SumScfileRow *object)
     16872{
     16873    psFree(object->skycell_id);
     16874    psFree(object->tess_id);
     16875    psFree(object->uri);
     16876}
     16877
     16878bool p6SumScfileCreateTable(psDB *dbh)
     16879{
     16880    psMetadata *md = psMetadataAlloc();
     16881    if (!psMetadataAdd(md, PS_LIST_TAIL, "p6_id", PS_DATA_S32, "Primary Key", 0)) {
     16882        psError(PS_ERR_UNKNOWN, false, "failed to add item p6_id");
     16883        psFree(md);
     16884        return false;
     16885    }
     16886    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {
     16887        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
     16888        psFree(md);
     16889        return false;
     16890    }
     16891    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {
     16892        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
     16893        psFree(md);
     16894        return false;
     16895    }
     16896    if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) {
     16897        psError(PS_ERR_UNKNOWN, false, "failed to add item uri");
     16898        psFree(md);
     16899        return false;
     16900    }
     16901    if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, 0.0)) {
     16902        psError(PS_ERR_UNKNOWN, false, "failed to add item bg");
     16903        psFree(md);
     16904        return false;
     16905    }
     16906    if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, 0.0)) {
     16907        psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev");
     16908        psFree(md);
     16909        return false;
     16910    }
     16911
     16912    bool status = psDBCreateTable(dbh, P6SUMSCFILE_TABLE_NAME, md);
     16913
     16914    psFree(md);
     16915
     16916    return status;
     16917}
     16918
     16919bool p6SumScfileDropTable(psDB *dbh)
     16920{
     16921    return psDBDropTable(dbh, P6SUMSCFILE_TABLE_NAME);
     16922}
     16923
     16924bool p6SumScfileInsert(psDB * dbh, psS32 p6_id, const char *skycell_id, const char *tess_id, const char *uri, psF64 bg, psF64 bg_mean_stdev)
     16925{
     16926    psMetadata *md = psMetadataAlloc();
     16927    if (!psMetadataAdd(md, PS_LIST_TAIL, "p6_id", PS_DATA_S32, NULL, p6_id)) {
     16928        psError(PS_ERR_UNKNOWN, false, "failed to add item p6_id");
     16929        psFree(md);
     16930        return false;
     16931    }
     16932    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {
     16933        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
     16934        psFree(md);
     16935        return false;
     16936    }
     16937    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {
     16938        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
     16939        psFree(md);
     16940        return false;
     16941    }
     16942    if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) {
     16943        psError(PS_ERR_UNKNOWN, false, "failed to add item uri");
     16944        psFree(md);
     16945        return false;
     16946    }
     16947    if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, bg)) {
     16948        psError(PS_ERR_UNKNOWN, false, "failed to add item bg");
     16949        psFree(md);
     16950        return false;
     16951    }
     16952    if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, bg_mean_stdev)) {
     16953        psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev");
     16954        psFree(md);
     16955        return false;
     16956    }
     16957
     16958    bool status = psDBInsertOneRow(dbh, P6SUMSCFILE_TABLE_NAME, md);
     16959    psFree(md);
     16960
     16961    return status;
     16962}
     16963
     16964long long p6SumScfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)
     16965{
     16966    long long       deleted = 0;
     16967
     16968    long long count = psDBDeleteRows(dbh, P6SUMSCFILE_TABLE_NAME, where, limit);
     16969    if (count < 0) {
     16970        psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6SumScfile");
     16971        return count;
     16972
     16973        deleted += count;
     16974    }
     16975
     16976    return deleted;
     16977}
     16978bool p6SumScfileInsertObject(psDB *dbh, p6SumScfileRow *object)
     16979{
     16980    return p6SumScfileInsert(dbh, object->p6_id, object->skycell_id, object->tess_id, object->uri, object->bg, object->bg_mean_stdev);
     16981}
     16982
     16983bool p6SumScfileInsertObjects(psDB *dbh, psArray *objects)
     16984{
     16985    for (long i = 0; i < psArrayLength(objects); i++) {
     16986        if (!p6SumScfileInsertObject(dbh, objects->data[i])) {
     16987            return false;
     16988        }
     16989    }
     16990
     16991    return true;
     16992}
     16993
     16994bool p6SumScfileInsertFits(psDB *dbh, const psFits *fits)
     16995{
     16996    psArray         *rowSet;
     16997
     16998    // move to (the first?) extension named  P6SUMSCFILE_TABLE_NAME
     16999    if (!psFitsMoveExtName(fits, P6SUMSCFILE_TABLE_NAME)) {
     17000        psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P6SUMSCFILE_TABLE_NAME);
     17001        return false;
     17002    }
     17003
     17004    // check HDU type
     17005    if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE)  {
     17006        psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE");
     17007        return false;
     17008    }
     17009
     17010    // read fits table
     17011    rowSet = psFitsReadTable(fits);
     17012    if (!rowSet) {
     17013        psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty");
     17014        psFree(rowSet);
     17015        return false;
     17016    }
     17017
     17018    if (!psDBInsertRows(dbh, P6SUMSCFILE_TABLE_NAME, rowSet)) {
     17019        psError(PS_ERR_UNKNOWN, false, "databse insert failed");
     17020        psFree(rowSet);
     17021        return false;
     17022    }
     17023
     17024    psFree(rowSet);
     17025
     17026    return true;
     17027}
     17028
     17029bool p6SumScfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)
     17030{
     17031    psArray         *rowSet;
     17032
     17033    rowSet = psDBSelectRows(dbh, P6SUMSCFILE_TABLE_NAME, where, limit);
     17034    if (!rowSet) {
     17035        return false;
     17036    }
     17037
     17038    // output to fits
     17039    if (!psFitsWriteTable(fits, NULL, rowSet, P6SUMSCFILE_TABLE_NAME)) {
     17040        psError(PS_ERR_UNKNOWN, false, "FITS table write failed");
     17041        psFree(rowSet);
     17042        return false;
     17043    }
     17044
     17045    psFree(rowSet);
     17046
     17047    return true;
     17048}
     17049
     17050psMetadata *p6SumScfileMetadataFromObject(const p6SumScfileRow *object)
     17051{
     17052    psMetadata *md = psMetadataAlloc();
     17053    if (!psMetadataAdd(md, PS_LIST_TAIL, "p6_id", PS_DATA_S32, NULL, object->p6_id)) {
     17054        psError(PS_ERR_UNKNOWN, false, "failed to add item p6_id");
     17055        psFree(md);
     17056        return false;
     17057    }
     17058    if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {
     17059        psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");
     17060        psFree(md);
     17061        return false;
     17062    }
     17063    if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {
     17064        psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");
     17065        psFree(md);
     17066        return false;
     17067    }
     17068    if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) {
     17069        psError(PS_ERR_UNKNOWN, false, "failed to add item uri");
     17070        psFree(md);
     17071        return false;
     17072    }
     17073    if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, object->bg)) {
     17074        psError(PS_ERR_UNKNOWN, false, "failed to add item bg");
     17075        psFree(md);
     17076        return false;
     17077    }
     17078    if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, object->bg_mean_stdev)) {
     17079        psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev");
     17080        psFree(md);
     17081        return false;
     17082    }
     17083
     17084
     17085    return md;
     17086}
     17087
     17088p6SumScfileRow *p6SumScfileObjectFromMetadata(psMetadata *md)
     17089{
     17090
     17091bool status = false;
     17092    psS32 p6_id = psMetadataLookupS32(&status, md, "p6_id");
     17093    if (!status) {
     17094        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p6_id");
     17095        return false;
     17096    }
     17097    char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");
     17098    if (!status) {
     17099        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");
     17100        return false;
     17101    }
     17102    char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");
     17103    if (!status) {
     17104        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");
     17105        return false;
     17106    }
     17107    char* uri = psMetadataLookupPtr(&status, md, "uri");
     17108    if (!status) {
     17109        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri");
     17110        return false;
     17111    }
     17112    psF64 bg = psMetadataLookupF64(&status, md, "bg");
     17113    if (!status) {
     17114        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg");
     17115        return false;
     17116    }
     17117    psF64 bg_mean_stdev = psMetadataLookupF64(&status, md, "bg_mean_stdev");
     17118    if (!status) {
     17119        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_mean_stdev");
     17120        return false;
     17121    }
     17122
     17123    return p6SumScfileRowAlloc(p6_id, skycell_id, tess_id, uri, bg, bg_mean_stdev);
     17124}
     17125psArray *p6SumScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
     17126{
     17127    psArray         *rowSet;
     17128    psArray         *returnSet;
     17129    psU64           i;
     17130
     17131    rowSet = psDBSelectRows(dbh, P6SUMSCFILE_TABLE_NAME, where, limit);
     17132    if (!rowSet) {
     17133        return NULL;
     17134    }
     17135
     17136    // convert psMetadata rows to row objects
     17137
     17138    returnSet = psArrayAllocEmpty(rowSet->n);
     17139
     17140    for (i = 0; i < rowSet->n; i++) {
     17141        p6SumScfileRow *object = p6SumScfileObjectFromMetadata(rowSet->data[i]);
     17142        psArrayAdd(returnSet, 0, object);
     17143        psFree(object);
     17144    }
     17145
     17146    psFree(rowSet);
     17147
     17148    return returnSet;
     17149}
     17150bool p6SumScfileDeleteObject(psDB *dbh, const p6SumScfileRow *object)
     17151{
     17152    psMetadata *where = p6SumScfileMetadataFromObject(object);
     17153    long long count = psDBDeleteRows(dbh, P6SUMSCFILE_TABLE_NAME, where, 0);
     17154    psFree(where);
     17155    if (count < 0) {
     17156        psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6SumScfile");
     17157        return false;
     17158    }
     17159    if (count > 1) {
     17160        // XXX should this be a psAbort() instead?  It is possible that
     17161        // having an object match multiple rows was by design.
     17162        psError(PS_ERR_UNKNOWN, true, "p6SumScfileRow object matched more then one row.  Check your database schema");
     17163        return false;
     17164    }
     17165
     17166    return true;
     17167}
     17168long long p6SumScfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)
     17169{
     17170    long long       deleted = 0;
     17171
     17172    for (long long i = 0; i < objects->n; i++) {
     17173        p6SumScfileRow *object = objects->data[i];
     17174        psMetadata *where = p6SumScfileMetadataFromObject(object);
     17175        long long count = psDBDeleteRows(dbh, P6SUMSCFILE_TABLE_NAME, where, limit);
     17176        psFree(where);
     17177        if (count < 0) {
     17178            psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6SumScfile");
     17179            return count;
     17180        }
     17181
     17182        deleted += count;
     17183    }
     17184
     17185    return deleted;
     17186}
     17187bool p6SumScfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)
     17188{
     17189    PS_ASSERT_PTR_NON_NULL(objects, false);
     17190
     17191    psMetadata *output = psMetadataAlloc();
     17192    for (long i = 0; i < psArrayLength(objects); i++) {
     17193        psMetadata *md = p6SumScfileMetadataFromObject(objects->data[i]);
     17194        if (!psMetadataAddMetadata(
     17195            output,
     17196            PS_LIST_TAIL,
     17197            P6SUMSCFILE_TABLE_NAME,
     17198            PS_META_DUPLICATE_OK,
     17199            NULL,
     17200            md
     17201        )) {
     17202            psError(PS_ERR_UNKNOWN, false, "failed to add metadata");
     17203            psFree(md);
     17204            psFree(output);
     17205            return false;
     17206        }
     17207        psFree(md);
     17208    }
     17209
     17210    if (!ippdbPrintMetadataRaw(stream, output, mdcf)) {
     17211        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
     17212        psFree(output);
     17213    }
     17214    psFree(output);
     17215
     17216    return true;
     17217}
     17218bool p6SumScfilePrintObject(FILE *stream, p6SumScfileRow *object, bool mdcf)
     17219{
     17220    PS_ASSERT_PTR_NON_NULL(object, false);
     17221
     17222    psMetadata *md = p6SumScfileMetadataFromObject(object);
     17223
     17224    if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
     17225        psError(PS_ERR_UNKNOWN, false, "failed to print metadata");
     17226        psFree(md);
     17227    }
     17228
     17229    psFree(md);
     17230
     17231    return true;
     17232}
  • trunk/ippdb/src/ippdb.h

    r11820 r11867  
    85108510    bool            mdcf                ///< format as mdconfig or simple
    85118511);
     8512/** p6InputScfileRow data structure
     8513 *
     8514 * Structure for representing a single row of p6InputScfile table data.
     8515 */
     8516
     8517typedef struct {
     8518    psS32           p6_id;
     8519    psS32           p4_id;
     8520    char            *skycell_id;
     8521    char            *tess_id;
     8522} p6InputScfileRow;
     8523
     8524/** Creates a new p6InputScfileRow object
     8525 *
     8526 *  @return A new p6InputScfileRow object or NULL on failure.
     8527 */
     8528
     8529p6InputScfileRow *p6InputScfileRowAlloc(
     8530    psS32           p6_id,
     8531    psS32           p4_id,
     8532    const char      *skycell_id,
     8533    const char      *tess_id
     8534);
     8535
     8536/** Creates a new p6InputScfile table
     8537 *
     8538 * @return true on success
     8539 */
     8540
     8541bool p6InputScfileCreateTable(
     8542    psDB            *dbh                ///< Database handle
     8543);
     8544
     8545/** Deletes a p6InputScfile table
     8546 *
     8547 * @return true on success
     8548 */
     8549
     8550bool p6InputScfileDropTable(
     8551    psDB            *dbh                ///< Database handle
     8552);
     8553
     8554/** Insert a single row into a table
     8555 *
     8556 * This function constructs and inserts a single row based on it's parameters.
     8557 *
     8558 * @return true on success
     8559 */
     8560
     8561bool p6InputScfileInsert(
     8562    psDB            *dbh,               ///< Database handle
     8563    psS32           p6_id,
     8564    psS32           p4_id,
     8565    const char      *skycell_id,
     8566    const char      *tess_id
     8567);
     8568
     8569/** Deletes up to limit rows from the database and returns the number of rows actually deleted.
     8570 *
     8571 * @return A The number of rows removed or a negative value on error
     8572 */
     8573
     8574long long p6InputScfileDelete(
     8575    psDB            *dbh,               ///< Database handle
     8576    const psMetadata *where,            ///< Row match criteria
     8577    unsigned long long limit            ///< Maximum number of elements to delete
     8578);
     8579
     8580/** Insert a single p6InputScfileRow object into a table
     8581 *
     8582 * This function constructs and inserts a single row based on it's parameters.
     8583 *
     8584 * @return true on success
     8585 */
     8586
     8587bool p6InputScfileInsertObject(
     8588    psDB            *dbh,               ///< Database handle
     8589    p6InputScfileRow *object             ///< p6InputScfileRow object
     8590);
     8591
     8592/** Insert an array of p6InputScfileRow object into a table
     8593 *
     8594 * This function constructs and inserts multiple rows based on it's parameters.
     8595 *
     8596 * @return true on success
     8597 */
     8598
     8599bool p6InputScfileInsertObjects(
     8600    psDB            *dbh,               ///< Database handle
     8601    psArray         *objects            ///< array of p6InputScfileRow objects
     8602);
     8603
     8604/** Insert data from a binary FITS table p6InputScfileRow into the database
     8605 *
     8606 * This function expects a psFits object with a FITS table as the first
     8607 * extension.  The table must have at least one row of data in it, that is of
     8608 * the appropriate format (number of columns and their type).  All other
     8609 * extensions are ignored.
     8610 *
     8611 * @return true on success
     8612 */
     8613
     8614bool p6InputScfileInsertFits(
     8615    psDB            *dbh,               ///< Database handle
     8616    const psFits    *fits               ///< psFits object
     8617);
     8618
     8619/** Selects up to limit from the database and returns them in a binary FITS table
     8620 *
     8621 * This function assumes an empty psFits object and will create a FITS table
     8622 * as the first extension.
     8623 *
     8624 *  See psDBSelectRows() for documentation on the format of where.
     8625 *
     8626 * @return true on success
     8627 */
     8628
     8629bool p6InputScfileSelectRowsFits(
     8630    psDB            *dbh,               ///< Database handle
     8631    psFits          *fits,              ///< psFits object
     8632    const psMetadata *where,            ///< Row match criteria
     8633    unsigned long long limit            ///< Maximum number of elements to return
     8634);
     8635
     8636/** Convert a p6InputScfileRow into an equivalent psMetadata
     8637 *
     8638 * @return A psMetadata pointer or NULL on error
     8639 */
     8640
     8641psMetadata *p6InputScfileMetadataFromObject(
     8642    const p6InputScfileRow *object             ///< fooRow to convert into a psMetadata
     8643);
     8644
     8645/** Convert a psMetadata into an equivalent fooRow
     8646 *
     8647 * @return A p6InputScfileRow pointer or NULL on error
     8648 */
     8649
     8650p6InputScfileRow *p6InputScfileObjectFromMetadata(
     8651    psMetadata      *md                 ///< psMetadata to convert into a fooRow
     8652);
     8653/** Selects up to limit rows from the database and returns as p6InputScfileRow objects in a psArray
     8654 *
     8655 *  See psDBSelectRows() for documentation on the format of where.
     8656 *
     8657 * @return A psArray pointer or NULL on error
     8658 */
     8659
     8660psArray *p6InputScfileSelectRowObjects(
     8661    psDB            *dbh,               ///< Database handle
     8662    const psMetadata *where,            ///< Row match criteria
     8663    unsigned long long limit            ///< Maximum number of elements to return
     8664);
     8665/** Deletes a row from the database coresponding to an p6InputScfile
     8666 *
     8667 *  Note that a 'where' search psMetadata is constructed from each object and
     8668 *  used to find rows to delete.
     8669 *
     8670 * @return A The number of rows removed or a negative value on error
     8671 */
     8672
     8673bool p6InputScfileDeleteObject(
     8674    psDB            *dbh,               ///< Database handle
     8675    const p6InputScfileRow *object    ///< Object to delete
     8676);
     8677/** Deletes up to limit rows from the database and returns the number of rows actually deleted.
     8678 *
     8679 *  Note that a 'where' search psMetadata is constructed from each object and
     8680 *  used to find rows to delete.
     8681 *
     8682 * @return A The number of rows removed or a negative value on error
     8683 */
     8684
     8685long long p6InputScfileDeleteRowObjects(
     8686    psDB            *dbh,               ///< Database handle
     8687    const psArray   *objects,           ///< Array of objects to delete
     8688    unsigned long long limit            ///< Maximum number of elements to delete
     8689);
     8690/** Formats and prints an array of p6InputScfileRow objects
     8691 *
     8692 * When mdcf is set the formated output is in psMetadataConfig
     8693 * format, otherwise it is in a simple tabular format.
     8694 *
     8695 * @return true on success
     8696 */
     8697
     8698bool p6InputScfilePrintObjects(
     8699    FILE            *stream,            ///< a stream
     8700    psArray         *objects,           ///< An array of p6InputScfileRow objects
     8701    bool            mdcf                ///< format as mdconfig or simple
     8702);
     8703/** Formats and prints an p6InputScfileRow object
     8704 *
     8705 * When mdcf is set the formated output is in psMetadataConfig
     8706 * format, otherwise it is in a simple tabular format.
     8707 *
     8708 * @return true on success
     8709 */
     8710
     8711bool p6InputScfilePrintObject(
     8712    FILE            *stream,            ///< a stream
     8713    p6InputScfileRow *object,    ///< an p6InputScfileRow object
     8714    bool            mdcf                ///< format as mdconfig or simple
     8715);
     8716/** p6SumScfileRow data structure
     8717 *
     8718 * Structure for representing a single row of p6SumScfile table data.
     8719 */
     8720
     8721typedef struct {
     8722    psS32           p6_id;
     8723    char            *skycell_id;
     8724    char            *tess_id;
     8725    char            *uri;
     8726    psF64           bg;
     8727    psF64           bg_mean_stdev;
     8728} p6SumScfileRow;
     8729
     8730/** Creates a new p6SumScfileRow object
     8731 *
     8732 *  @return A new p6SumScfileRow object or NULL on failure.
     8733 */
     8734
     8735p6SumScfileRow *p6SumScfileRowAlloc(
     8736    psS32           p6_id,
     8737    const char      *skycell_id,
     8738    const char      *tess_id,
     8739    const char      *uri,
     8740    psF64           bg,
     8741    psF64           bg_mean_stdev
     8742);
     8743
     8744/** Creates a new p6SumScfile table
     8745 *
     8746 * @return true on success
     8747 */
     8748
     8749bool p6SumScfileCreateTable(
     8750    psDB            *dbh                ///< Database handle
     8751);
     8752
     8753/** Deletes a p6SumScfile table
     8754 *
     8755 * @return true on success
     8756 */
     8757
     8758bool p6SumScfileDropTable(
     8759    psDB            *dbh                ///< Database handle
     8760);
     8761
     8762/** Insert a single row into a table
     8763 *
     8764 * This function constructs and inserts a single row based on it's parameters.
     8765 *
     8766 * @return true on success
     8767 */
     8768
     8769bool p6SumScfileInsert(
     8770    psDB            *dbh,               ///< Database handle
     8771    psS32           p6_id,
     8772    const char      *skycell_id,
     8773    const char      *tess_id,
     8774    const char      *uri,
     8775    psF64           bg,
     8776    psF64           bg_mean_stdev
     8777);
     8778
     8779/** Deletes up to limit rows from the database and returns the number of rows actually deleted.
     8780 *
     8781 * @return A The number of rows removed or a negative value on error
     8782 */
     8783
     8784long long p6SumScfileDelete(
     8785    psDB            *dbh,               ///< Database handle
     8786    const psMetadata *where,            ///< Row match criteria
     8787    unsigned long long limit            ///< Maximum number of elements to delete
     8788);
     8789
     8790/** Insert a single p6SumScfileRow object into a table
     8791 *
     8792 * This function constructs and inserts a single row based on it's parameters.
     8793 *
     8794 * @return true on success
     8795 */
     8796
     8797bool p6SumScfileInsertObject(
     8798    psDB            *dbh,               ///< Database handle
     8799    p6SumScfileRow  *object             ///< p6SumScfileRow object
     8800);
     8801
     8802/** Insert an array of p6SumScfileRow object into a table
     8803 *
     8804 * This function constructs and inserts multiple rows based on it's parameters.
     8805 *
     8806 * @return true on success
     8807 */
     8808
     8809bool p6SumScfileInsertObjects(
     8810    psDB            *dbh,               ///< Database handle
     8811    psArray         *objects            ///< array of p6SumScfileRow objects
     8812);
     8813
     8814/** Insert data from a binary FITS table p6SumScfileRow into the database
     8815 *
     8816 * This function expects a psFits object with a FITS table as the first
     8817 * extension.  The table must have at least one row of data in it, that is of
     8818 * the appropriate format (number of columns and their type).  All other
     8819 * extensions are ignored.
     8820 *
     8821 * @return true on success
     8822 */
     8823
     8824bool p6SumScfileInsertFits(
     8825    psDB            *dbh,               ///< Database handle
     8826    const psFits    *fits               ///< psFits object
     8827);
     8828
     8829/** Selects up to limit from the database and returns them in a binary FITS table
     8830 *
     8831 * This function assumes an empty psFits object and will create a FITS table
     8832 * as the first extension.
     8833 *
     8834 *  See psDBSelectRows() for documentation on the format of where.
     8835 *
     8836 * @return true on success
     8837 */
     8838
     8839bool p6SumScfileSelectRowsFits(
     8840    psDB            *dbh,               ///< Database handle
     8841    psFits          *fits,              ///< psFits object
     8842    const psMetadata *where,            ///< Row match criteria
     8843    unsigned long long limit            ///< Maximum number of elements to return
     8844);
     8845
     8846/** Convert a p6SumScfileRow into an equivalent psMetadata
     8847 *
     8848 * @return A psMetadata pointer or NULL on error
     8849 */
     8850
     8851psMetadata *p6SumScfileMetadataFromObject(
     8852    const p6SumScfileRow *object             ///< fooRow to convert into a psMetadata
     8853);
     8854
     8855/** Convert a psMetadata into an equivalent fooRow
     8856 *
     8857 * @return A p6SumScfileRow pointer or NULL on error
     8858 */
     8859
     8860p6SumScfileRow *p6SumScfileObjectFromMetadata(
     8861    psMetadata      *md                 ///< psMetadata to convert into a fooRow
     8862);
     8863/** Selects up to limit rows from the database and returns as p6SumScfileRow objects in a psArray
     8864 *
     8865 *  See psDBSelectRows() for documentation on the format of where.
     8866 *
     8867 * @return A psArray pointer or NULL on error
     8868 */
     8869
     8870psArray *p6SumScfileSelectRowObjects(
     8871    psDB            *dbh,               ///< Database handle
     8872    const psMetadata *where,            ///< Row match criteria
     8873    unsigned long long limit            ///< Maximum number of elements to return
     8874);
     8875/** Deletes a row from the database coresponding to an p6SumScfile
     8876 *
     8877 *  Note that a 'where' search psMetadata is constructed from each object and
     8878 *  used to find rows to delete.
     8879 *
     8880 * @return A The number of rows removed or a negative value on error
     8881 */
     8882
     8883bool p6SumScfileDeleteObject(
     8884    psDB            *dbh,               ///< Database handle
     8885    const p6SumScfileRow *object    ///< Object to delete
     8886);
     8887/** Deletes up to limit rows from the database and returns the number of rows actually deleted.
     8888 *
     8889 *  Note that a 'where' search psMetadata is constructed from each object and
     8890 *  used to find rows to delete.
     8891 *
     8892 * @return A The number of rows removed or a negative value on error
     8893 */
     8894
     8895long long p6SumScfileDeleteRowObjects(
     8896    psDB            *dbh,               ///< Database handle
     8897    const psArray   *objects,           ///< Array of objects to delete
     8898    unsigned long long limit            ///< Maximum number of elements to delete
     8899);
     8900/** Formats and prints an array of p6SumScfileRow objects
     8901 *
     8902 * When mdcf is set the formated output is in psMetadataConfig
     8903 * format, otherwise it is in a simple tabular format.
     8904 *
     8905 * @return true on success
     8906 */
     8907
     8908bool p6SumScfilePrintObjects(
     8909    FILE            *stream,            ///< a stream
     8910    psArray         *objects,           ///< An array of p6SumScfileRow objects
     8911    bool            mdcf                ///< format as mdconfig or simple
     8912);
     8913/** Formats and prints an p6SumScfileRow object
     8914 *
     8915 * When mdcf is set the formated output is in psMetadataConfig
     8916 * format, otherwise it is in a simple tabular format.
     8917 *
     8918 * @return true on success
     8919 */
     8920
     8921bool p6SumScfilePrintObject(
     8922    FILE            *stream,            ///< a stream
     8923    p6SumScfileRow *object,    ///< an p6SumScfileRow object
     8924    bool            mdcf                ///< format as mdconfig or simple
     8925);
    85128926
    85138927/// @}
     
    85178931#endif
    85188932
    8519 #endif // P6RUN_DB_H
     8933#endif // P6SUMSCFILE_DB_H
  • trunk/ippdb/tests/alloc.c

    r11820 r11867  
    17001700    }
    17011701
     1702    {
     1703        p6InputScfileRow *object;
     1704
     1705        object = p6InputScfileRowAlloc(-32, -32, "a string", "a string"    );
     1706
     1707        if (!object) {
     1708            exit(EXIT_FAILURE);
     1709        }
     1710
     1711        if (!object->p6_id == -32) {
     1712            psFree(object);
     1713            exit(EXIT_FAILURE);
     1714        }
     1715        if (!object->p4_id == -32) {
     1716            psFree(object);
     1717            exit(EXIT_FAILURE);
     1718        }
     1719        if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
     1720            psFree(object);
     1721            exit(EXIT_FAILURE);
     1722        }
     1723        if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
     1724            psFree(object);
     1725            exit(EXIT_FAILURE);
     1726        }
     1727
     1728        psFree(object);
     1729    }
     1730
     1731    {
     1732        p6SumScfileRow  *object;
     1733
     1734        object = p6SumScfileRowAlloc(-32, "a string", "a string", "a string", 64.64, 64.64    );
     1735
     1736        if (!object) {
     1737            exit(EXIT_FAILURE);
     1738        }
     1739
     1740        if (!object->p6_id == -32) {
     1741            psFree(object);
     1742            exit(EXIT_FAILURE);
     1743        }
     1744        if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
     1745            psFree(object);
     1746            exit(EXIT_FAILURE);
     1747        }
     1748        if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
     1749            psFree(object);
     1750            exit(EXIT_FAILURE);
     1751        }
     1752        if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) {
     1753            psFree(object);
     1754            exit(EXIT_FAILURE);
     1755        }
     1756        if (!object->bg == 64.64) {
     1757            psFree(object);
     1758            exit(EXIT_FAILURE);
     1759        }
     1760        if (!object->bg_mean_stdev == 64.64) {
     1761            psFree(object);
     1762            exit(EXIT_FAILURE);
     1763        }
     1764
     1765        psFree(object);
     1766    }
     1767
    17021768    exit(EXIT_SUCCESS);
    17031769}
  • trunk/ippdb/tests/createtable.c

    r11820 r11867  
    590590    }
    591591
     592    {
     593        psDB            *dbh;
     594
     595        dbh = psDBInit("localhost", "test", NULL, "test");
     596        if (!dbh) {
     597            exit(EXIT_FAILURE);
     598        }
     599
     600        if(!p6InputScfileCreateTable(dbh)) {
     601            exit(EXIT_FAILURE);
     602        }
     603
     604        psDBCleanup(dbh);
     605    }
     606
     607    {
     608        psDB            *dbh;
     609
     610        dbh = psDBInit("localhost", "test", NULL, "test");
     611        if (!dbh) {
     612            exit(EXIT_FAILURE);
     613        }
     614
     615        if(!p6SumScfileCreateTable(dbh)) {
     616            exit(EXIT_FAILURE);
     617        }
     618
     619        psDBCleanup(dbh);
     620    }
     621
    592622    exit(EXIT_SUCCESS);
    593623}
  • trunk/ippdb/tests/dbcleanup.c

    r11820 r11867  
    5050    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p5DiffScfile");
    5151    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p6Run");
     52    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p6InputScfile");
     53    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p6SumScfile");
    5254
    5355    psDBCleanup(dbh);
  • trunk/ippdb/tests/dbsetup.c

    r11820 r11867  
    130130    p6RunCreateTable(dbh);
    131131
     132    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p6InputScfile");
     133    p6InputScfileCreateTable(dbh);
     134
     135    p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p6SumScfile");
     136    p6SumScfileCreateTable(dbh);
     137
    132138    psDBCleanup(dbh);
    133139
  • trunk/ippdb/tests/droptable.c

    r11820 r11867  
    590590    }
    591591
     592    {
     593        psDB            *dbh;
     594
     595        dbh = psDBInit("localhost", "test", NULL, "test");
     596        if (!dbh) {
     597            exit(EXIT_FAILURE);
     598        }
     599
     600        if (!p6InputScfileDropTable(dbh)) {
     601            exit(EXIT_FAILURE);
     602        }
     603
     604        psDBCleanup(dbh);
     605    }
     606
     607    {
     608        psDB            *dbh;
     609
     610        dbh = psDBInit("localhost", "test", NULL, "test");
     611        if (!dbh) {
     612            exit(EXIT_FAILURE);
     613        }
     614
     615        if (!p6SumScfileDropTable(dbh)) {
     616            exit(EXIT_FAILURE);
     617        }
     618
     619        psDBCleanup(dbh);
     620    }
     621
    592622    exit(EXIT_SUCCESS);
    593623}
  • trunk/ippdb/tests/insert.c

    r11820 r11867  
    590590    }
    591591
     592    {
     593        psDB            *dbh;
     594
     595        dbh = psDBInit("localhost", "test", NULL, "test");
     596        if (!dbh) {
     597            exit(EXIT_FAILURE);
     598        }
     599
     600        if (!p6InputScfileInsert(dbh, -32, -32, "a string", "a string")) {
     601            exit(EXIT_FAILURE);
     602        }
     603
     604        psDBCleanup(dbh);
     605    }
     606
     607    {
     608        psDB            *dbh;
     609
     610        dbh = psDBInit("localhost", "test", NULL, "test");
     611        if (!dbh) {
     612            exit(EXIT_FAILURE);
     613        }
     614
     615        if (!p6SumScfileInsert(dbh, -32, "a string", "a string", "a string", 64.64, 64.64)) {
     616            exit(EXIT_FAILURE);
     617        }
     618
     619        psDBCleanup(dbh);
     620    }
     621
    592622    exit(EXIT_SUCCESS);
    593623}
  • trunk/ippdb/tests/insertfits.c

    r11820 r11867  
    10231023    }
    10241024
     1025    {
     1026        psDB            *dbh;
     1027        psFits          *fits;
     1028
     1029        dbh = psDBInit("localhost", "test", NULL, "test");
     1030        if (!dbh) {
     1031            exit(EXIT_FAILURE);
     1032        }
     1033
     1034        // open a temp
     1035        fits = psFitsOpen(TMP_FILENAME, "r");
     1036        if (!fits) {
     1037            exit(EXIT_FAILURE);
     1038        }
     1039
     1040        if (!p6InputScfileInsertFits(dbh, fits)) {
     1041            exit(EXIT_FAILURE);
     1042        }
     1043
     1044        if (!psFitsClose(fits)) {
     1045            exit(EXIT_FAILURE);
     1046        }
     1047
     1048        psDBCleanup(dbh);
     1049    }
     1050
     1051    {
     1052        psDB            *dbh;
     1053        psFits          *fits;
     1054
     1055        dbh = psDBInit("localhost", "test", NULL, "test");
     1056        if (!dbh) {
     1057            exit(EXIT_FAILURE);
     1058        }
     1059
     1060        // open a temp
     1061        fits = psFitsOpen(TMP_FILENAME, "r");
     1062        if (!fits) {
     1063            exit(EXIT_FAILURE);
     1064        }
     1065
     1066        if (!p6SumScfileInsertFits(dbh, fits)) {
     1067            exit(EXIT_FAILURE);
     1068        }
     1069
     1070        if (!psFitsClose(fits)) {
     1071            exit(EXIT_FAILURE);
     1072        }
     1073
     1074        psDBCleanup(dbh);
     1075    }
     1076
    10251077    exit(EXIT_SUCCESS);
    10261078}
  • trunk/ippdb/tests/insertobject.c

    r11820 r11867  
    863863    }
    864864
     865    {
     866        psDB            *dbh;
     867        p6InputScfileRow *object;
     868
     869        dbh = psDBInit("localhost", "test", NULL, "test");
     870        if (!dbh) {
     871            exit(EXIT_FAILURE);
     872        }
     873
     874        object = p6InputScfileRowAlloc(-32, -32, "a string", "a string");
     875        if (!object) {
     876            exit(EXIT_FAILURE);
     877        }
     878
     879        if (!p6InputScfileInsertObject(dbh, object)) {
     880            exit(EXIT_FAILURE);
     881        }
     882
     883        psFree(object);
     884        psDBCleanup(dbh);
     885    }
     886
     887    {
     888        psDB            *dbh;
     889        p6SumScfileRow  *object;
     890
     891        dbh = psDBInit("localhost", "test", NULL, "test");
     892        if (!dbh) {
     893            exit(EXIT_FAILURE);
     894        }
     895
     896        object = p6SumScfileRowAlloc(-32, "a string", "a string", "a string", 64.64, 64.64);
     897        if (!object) {
     898            exit(EXIT_FAILURE);
     899        }
     900
     901        if (!p6SumScfileInsertObject(dbh, object)) {
     902            exit(EXIT_FAILURE);
     903        }
     904
     905        psFree(object);
     906        psDBCleanup(dbh);
     907    }
     908
    865909    exit(EXIT_SUCCESS);
    866910}
  • trunk/ippdb/tests/metadatafromobject.c

    r11820 r11867  
    19981998    }
    19991999
     2000    {
     2001        psMetadata      *md;
     2002        p6InputScfileRow *object;
     2003        bool            status;
     2004
     2005        object = p6InputScfileRowAlloc(-32, -32, "a string", "a string");
     2006        if (!object) {
     2007            exit(EXIT_FAILURE);
     2008        }
     2009
     2010        md = p6InputScfileMetadataFromObject(object);
     2011        if (!md) {
     2012            exit(EXIT_FAILURE);
     2013        }
     2014
     2015        psFree(object);
     2016
     2017        if (!psMetadataLookupS32(&status, md, "p6_id") == -32) {
     2018            psFree(md);
     2019            exit(EXIT_FAILURE);
     2020        }
     2021        if (!psMetadataLookupS32(&status, md, "p4_id") == -32) {
     2022            psFree(md);
     2023            exit(EXIT_FAILURE);
     2024        }
     2025        if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {
     2026            psFree(md);
     2027            exit(EXIT_FAILURE);
     2028        }
     2029        if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {
     2030            psFree(md);
     2031            exit(EXIT_FAILURE);
     2032        }
     2033
     2034        psFree(md);
     2035    }
     2036
     2037    {
     2038        psMetadata      *md;
     2039        p6SumScfileRow  *object;
     2040        bool            status;
     2041
     2042        object = p6SumScfileRowAlloc(-32, "a string", "a string", "a string", 64.64, 64.64);
     2043        if (!object) {
     2044            exit(EXIT_FAILURE);
     2045        }
     2046
     2047        md = p6SumScfileMetadataFromObject(object);
     2048        if (!md) {
     2049            exit(EXIT_FAILURE);
     2050        }
     2051
     2052        psFree(object);
     2053
     2054        if (!psMetadataLookupS32(&status, md, "p6_id") == -32) {
     2055            psFree(md);
     2056            exit(EXIT_FAILURE);
     2057        }
     2058        if (strncmp(psMetadataLookupPtr(&status, md, "skycell_id"), "a string", MAX_STRING_LENGTH)) {
     2059            psFree(md);
     2060            exit(EXIT_FAILURE);
     2061        }
     2062        if (strncmp(psMetadataLookupPtr(&status, md, "tess_id"), "a string", MAX_STRING_LENGTH)) {
     2063            psFree(md);
     2064            exit(EXIT_FAILURE);
     2065        }
     2066        if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) {
     2067            psFree(md);
     2068            exit(EXIT_FAILURE);
     2069        }
     2070        if (!psMetadataLookupF64(&status, md, "bg") == 64.64) {
     2071            psFree(md);
     2072            exit(EXIT_FAILURE);
     2073        }
     2074        if (!psMetadataLookupF64(&status, md, "bg_mean_stdev") == 64.64) {
     2075            psFree(md);
     2076            exit(EXIT_FAILURE);
     2077        }
     2078
     2079        psFree(md);
     2080    }
     2081
    20002082    exit(EXIT_SUCCESS);
    20012083}
  • trunk/ippdb/tests/objectfrommetadata.c

    r11820 r11867  
    30523052    }
    30533053
     3054    {
     3055        psMetadata      *md;
     3056        p6InputScfileRow *object;
     3057
     3058        md = psMetadataAlloc();
     3059        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p6_id", 0, NULL, -32)) {
     3060            psFree(md);
     3061            exit(EXIT_FAILURE);
     3062        }
     3063        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p4_id", 0, NULL, -32)) {
     3064            psFree(md);
     3065            exit(EXIT_FAILURE);
     3066        }
     3067        if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {
     3068            psFree(md);
     3069            exit(EXIT_FAILURE);
     3070        }
     3071        if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {
     3072            psFree(md);
     3073            exit(EXIT_FAILURE);
     3074        }
     3075
     3076        object = p6InputScfileObjectFromMetadata(md);
     3077        if (!object) {
     3078            psFree(md);
     3079            exit(EXIT_FAILURE);
     3080        }
     3081
     3082        psFree(md);
     3083
     3084        if (!object->p6_id == -32) {
     3085            psFree(object);
     3086            exit(EXIT_FAILURE);
     3087        }
     3088        if (!object->p4_id == -32) {
     3089            psFree(object);
     3090            exit(EXIT_FAILURE);
     3091        }
     3092        if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
     3093            psFree(object);
     3094            exit(EXIT_FAILURE);
     3095        }
     3096        if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
     3097            psFree(object);
     3098            exit(EXIT_FAILURE);
     3099        }
     3100
     3101        psFree(object);
     3102    }
     3103
     3104    {
     3105        psMetadata      *md;
     3106        p6SumScfileRow  *object;
     3107
     3108        md = psMetadataAlloc();
     3109        if (!psMetadataAddS32(md, PS_LIST_TAIL, "p6_id", 0, NULL, -32)) {
     3110            psFree(md);
     3111            exit(EXIT_FAILURE);
     3112        }
     3113        if (!psMetadataAddStr(md, PS_LIST_TAIL, "skycell_id", 0, NULL, "a string")) {
     3114            psFree(md);
     3115            exit(EXIT_FAILURE);
     3116        }
     3117        if (!psMetadataAddStr(md, PS_LIST_TAIL, "tess_id", 0, NULL, "a string")) {
     3118            psFree(md);
     3119            exit(EXIT_FAILURE);
     3120        }
     3121        if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) {
     3122            psFree(md);
     3123            exit(EXIT_FAILURE);
     3124        }
     3125        if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, 64.64)) {
     3126            psFree(md);
     3127            exit(EXIT_FAILURE);
     3128        }
     3129        if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_mean_stdev", 0, NULL, 64.64)) {
     3130            psFree(md);
     3131            exit(EXIT_FAILURE);
     3132        }
     3133
     3134        object = p6SumScfileObjectFromMetadata(md);
     3135        if (!object) {
     3136            psFree(md);
     3137            exit(EXIT_FAILURE);
     3138        }
     3139
     3140        psFree(md);
     3141
     3142        if (!object->p6_id == -32) {
     3143            psFree(object);
     3144            exit(EXIT_FAILURE);
     3145        }
     3146        if (strncmp(object->skycell_id, "a string", MAX_STRING_LENGTH)) {
     3147            psFree(object);
     3148            exit(EXIT_FAILURE);
     3149        }
     3150        if (strncmp(object->tess_id, "a string", MAX_STRING_LENGTH)) {
     3151            psFree(object);
     3152            exit(EXIT_FAILURE);
     3153        }
     3154        if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) {
     3155            psFree(object);
     3156            exit(EXIT_FAILURE);
     3157        }
     3158        if (!object->bg == 64.64) {
     3159            psFree(object);
     3160            exit(EXIT_FAILURE);
     3161        }
     3162        if (!object->bg_mean_stdev == 64.64) {
     3163            psFree(object);
     3164            exit(EXIT_FAILURE);
     3165        }
     3166
     3167        psFree(object);
     3168    }
     3169
    30543170    exit(EXIT_SUCCESS);
    30553171}
  • trunk/ippdb/tests/selectrowsfits.c

    r11820 r11867  
    865865    }
    866866
     867    {
     868        psDB            *dbh;
     869        psFits          *fits;
     870
     871        dbh = psDBInit("localhost", "test", NULL, "test");
     872        if (!dbh) {
     873            exit(EXIT_FAILURE);
     874        }
     875
     876        fits = psFitsOpen(TMP_FILENAME, "w");
     877        if (!fits) {
     878            exit(EXIT_FAILURE);
     879        }
     880
     881        if (!p6InputScfileSelectRowsFits(dbh, fits, NULL, 1)) {
     882            exit(EXIT_FAILURE);
     883        }
     884
     885        psFree(fits);
     886        psDBCleanup(dbh);
     887    }
     888
     889    {
     890        psDB            *dbh;
     891        psFits          *fits;
     892
     893        dbh = psDBInit("localhost", "test", NULL, "test");
     894        if (!dbh) {
     895            exit(EXIT_FAILURE);
     896        }
     897
     898        fits = psFitsOpen(TMP_FILENAME, "w");
     899        if (!fits) {
     900            exit(EXIT_FAILURE);
     901        }
     902
     903        if (!p6SumScfileSelectRowsFits(dbh, fits, NULL, 1)) {
     904            exit(EXIT_FAILURE);
     905        }
     906
     907        psFree(fits);
     908        psDBCleanup(dbh);
     909    }
     910
    867911    exit(EXIT_SUCCESS);
    868912}
Note: See TracChangeset for help on using the changeset viewer.