Changeset 8368
- Timestamp:
- Aug 15, 2006, 4:31:35 PM (20 years ago)
- Location:
- trunk/ippdb
- Files:
-
- 18 edited
-
Makefile.am (modified) (2 diffs)
-
configure.ac (modified) (1 diff)
-
src/ippdb.c (modified) (2 diffs)
-
src/ippdb.h (modified) (1 diff)
-
tests/alloc.c (modified) (1 diff)
-
tests/createtable.c (modified) (1 diff)
-
tests/dbcleanup.c (modified) (1 diff)
-
tests/dbsetup.c (modified) (1 diff)
-
tests/droptable.c (modified) (1 diff)
-
tests/insert.c (modified) (1 diff)
-
tests/insertfits.c (modified) (1 diff)
-
tests/insertobject.c (modified) (1 diff)
-
tests/metadatafromobject.c (modified) (1 diff)
-
tests/objectfrommetadata.c (modified) (1 diff)
-
tests/pop.c (modified) (1 diff)
-
tests/popfits.c (modified) (1 diff)
-
tests/popobject.c (modified) (1 diff)
-
tests/selectrowsfits.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippdb/Makefile.am
r7461 r8368 36 36 $(top_builddir)/docs/man/man3/detProcessedImfileRow.3 \ 37 37 $(top_builddir)/docs/man/man3/detStackedImfileRow.3 \ 38 $(top_builddir)/docs/man/man3/detNormalizedStatImfileRow.3 \ 38 39 $(top_builddir)/docs/man/man3/detNormalizedImfileRow.3 \ 39 40 $(top_builddir)/docs/man/man3/detMasterFrameRow.3 \ … … 43 44 44 45 45 docs/man/man3/ippdb.3 docs/man/man3/weatherRow.3 docs/man/man3/skyp_transparencyRow.3 docs/man/man3/skyp_absorptionRow.3 docs/man/man3/skyp_emissionRow.3 docs/man/man3/dimmRow.3 docs/man/man3/skyp_irRow.3 docs/man/man3/domeRow.3 docs/man/man3/telescopeRow.3 docs/man/man3/summitExpRow.3 docs/man/man3/pzPendingExpRow.3 docs/man/man3/pzPendingImfileRow.3 docs/man/man3/newExpRow.3 docs/man/man3/newImfileRow.3 docs/man/man3/rawDetrendExpRow.3 docs/man/man3/rawScienceExpRow.3 docs/man/man3/rawImfileRow.3 docs/man/man3/p1PendingExpRow.3 docs/man/man3/p2PendingExpRow.3 docs/man/man3/p2PendingImfileRow.3 docs/man/man3/p2DoneExpRow.3 docs/man/man3/p2DoneImfileRow.3 docs/man/man3/p3PendingExpRow.3 docs/man/man3/detRunRow.3 docs/man/man3/detInputExpRow.3 docs/man/man3/detProcessedImfileRow.3 docs/man/man3/detStackedImfileRow.3 docs/man/man3/detNormalized ImfileRow.3 docs/man/man3/detMasterFrameRow.3 docs/man/man3/detMasterImfileRow.3 docs/man/man3/detResidImfileAnalysisRow.3 docs/man/man3/detResidExpAnalysisRow.3:46 docs/man/man3/ippdb.3 docs/man/man3/weatherRow.3 docs/man/man3/skyp_transparencyRow.3 docs/man/man3/skyp_absorptionRow.3 docs/man/man3/skyp_emissionRow.3 docs/man/man3/dimmRow.3 docs/man/man3/skyp_irRow.3 docs/man/man3/domeRow.3 docs/man/man3/telescopeRow.3 docs/man/man3/summitExpRow.3 docs/man/man3/pzPendingExpRow.3 docs/man/man3/pzPendingImfileRow.3 docs/man/man3/newExpRow.3 docs/man/man3/newImfileRow.3 docs/man/man3/rawDetrendExpRow.3 docs/man/man3/rawScienceExpRow.3 docs/man/man3/rawImfileRow.3 docs/man/man3/p1PendingExpRow.3 docs/man/man3/p2PendingExpRow.3 docs/man/man3/p2PendingImfileRow.3 docs/man/man3/p2DoneExpRow.3 docs/man/man3/p2DoneImfileRow.3 docs/man/man3/p3PendingExpRow.3 docs/man/man3/detRunRow.3 docs/man/man3/detInputExpRow.3 docs/man/man3/detProcessedImfileRow.3 docs/man/man3/detStackedImfileRow.3 docs/man/man3/detNormalizedStatImfileRow.3 docs/man/man3/detNormalizedImfileRow.3 docs/man/man3/detMasterFrameRow.3 docs/man/man3/detMasterImfileRow.3 docs/man/man3/detResidImfileAnalysisRow.3 docs/man/man3/detResidExpAnalysisRow.3: 46 47 $(DOXYGEN) 47 48 -
trunk/ippdb/configure.ac
r8325 r8368 1 1 AC_PREREQ(2.59) 2 2 3 AC_INIT([ippdb], [0.0.2 8], [pan-starrs.ifa.hawaii.edu])3 AC_INIT([ippdb], [0.0.29], [pan-starrs.ifa.hawaii.edu]) 4 4 AC_CONFIG_SRCDIR([ippdb.pc.in]) 5 5 -
trunk/ippdb/src/ippdb.c
r8325 r8368 56 56 #define DETSTACKEDIMFILE_TABLE_NAME "detStackedImfile" 57 57 #define DETSTACKEDIMFILE_INDEX_NAME IPPDB_DEFAULT_INDEX_NAME 58 #define DETNORMALIZEDSTATIMFILE_TABLE_NAME "detNormalizedStatImfile" 59 #define DETNORMALIZEDSTATIMFILE_INDEX_NAME IPPDB_DEFAULT_INDEX_NAME 58 60 #define DETNORMALIZEDIMFILE_TABLE_NAME "detNormalizedImfile" 59 61 #define DETNORMALIZEDIMFILE_INDEX_NAME IPPDB_DEFAULT_INDEX_NAME … … 14583 14585 return true; 14584 14586 } 14587 static void detNormalizedStatImfileRowFree(detNormalizedStatImfileRow *object); 14588 14589 detNormalizedStatImfileRow *detNormalizedStatImfileRowAlloc(psS32 det_id, psS32 iteration, const char *class_id, psF32 norm) 14590 { 14591 detNormalizedStatImfileRow *object; 14592 14593 object = psAlloc(sizeof(detNormalizedStatImfileRow)); 14594 psMemSetDeallocator(object, (psFreeFunc)detNormalizedStatImfileRowFree); 14595 14596 object->det_id = det_id; 14597 object->iteration = iteration; 14598 object->class_id = psStringCopy(class_id); 14599 object->norm = norm; 14600 14601 return object; 14602 } 14603 14604 static void detNormalizedStatImfileRowFree(detNormalizedStatImfileRow *object) 14605 { 14606 psFree(object->class_id); 14607 } 14608 14609 bool detNormalizedStatImfileCreateTable(psDB *dbh) 14610 { 14611 psMetadata *md; 14612 bool status; 14613 14614 md = psMetadataAlloc(); 14615 if (!psMetadataAdd(md, PS_LIST_TAIL, DETNORMALIZEDSTATIMFILE_INDEX_NAME, PS_DATA_S32, "AUTO_INCREMENT", 0.0)) { 14616 psError(PS_ERR_UNKNOWN, false, "failed to add item %s", DETNORMALIZEDSTATIMFILE_INDEX_NAME); 14617 psFree(md); 14618 return false; 14619 } 14620 if (!psMetadataAddS32(md, PS_LIST_TAIL, "det_id", 0, "Primary Key", 0)) { 14621 psError(PS_ERR_UNKNOWN, false, "failed to add item det_id"); 14622 psFree(md); 14623 return false; 14624 } 14625 if (!psMetadataAddS32(md, PS_LIST_TAIL, "iteration", 0, "Primary Key", 0)) { 14626 psError(PS_ERR_UNKNOWN, false, "failed to add item iteration"); 14627 psFree(md); 14628 return false; 14629 } 14630 if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, "Primary Key", "64")) { 14631 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 14632 psFree(md); 14633 return false; 14634 } 14635 if (!psMetadataAddF32(md, PS_LIST_TAIL, "norm", 0, NULL, 0.0)) { 14636 psError(PS_ERR_UNKNOWN, false, "failed to add item norm"); 14637 psFree(md); 14638 return false; 14639 } 14640 14641 status = psDBCreateTable(dbh, DETNORMALIZEDSTATIMFILE_TABLE_NAME, md); 14642 14643 psFree(md); 14644 14645 return status; 14646 } 14647 14648 bool detNormalizedStatImfileDropTable(psDB *dbh) 14649 { 14650 return psDBDropTable(dbh, DETNORMALIZEDSTATIMFILE_TABLE_NAME); 14651 } 14652 14653 bool detNormalizedStatImfileInsert(psDB * dbh, psS32 det_id, psS32 iteration, const char *class_id, psF32 norm) 14654 { 14655 psMetadata *md; 14656 bool status; 14657 14658 md = psMetadataAlloc(); 14659 if (!psMetadataAddS32(md, PS_LIST_TAIL, "det_id", 0, NULL, det_id)) { 14660 psError(PS_ERR_UNKNOWN, false, "failed to add item det_id"); 14661 psFree(md); 14662 return false; 14663 } 14664 if (!psMetadataAddS32(md, PS_LIST_TAIL, "iteration", 0, NULL, iteration)) { 14665 psError(PS_ERR_UNKNOWN, false, "failed to add item iteration"); 14666 psFree(md); 14667 return false; 14668 } 14669 if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, NULL, class_id)) { 14670 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 14671 psFree(md); 14672 return false; 14673 } 14674 if (!psMetadataAddF32(md, PS_LIST_TAIL, "norm", 0, NULL, norm)) { 14675 psError(PS_ERR_UNKNOWN, false, "failed to add item norm"); 14676 psFree(md); 14677 return false; 14678 } 14679 14680 status = psDBInsertOneRow(dbh, DETNORMALIZEDSTATIMFILE_TABLE_NAME, md); 14681 psFree(md); 14682 14683 return status; 14684 } 14685 14686 long long detNormalizedStatImfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 14687 { 14688 long long deleted = 0; 14689 14690 long long count = psDBDeleteRows(dbh, DETNORMALIZEDSTATIMFILE_TABLE_NAME, where, limit); 14691 if (count < 0) { 14692 psError(PS_ERR_UNKNOWN, true, "failed to delete row from detNormalizedStatImfile"); 14693 return count; 14694 14695 deleted += count; 14696 } 14697 14698 return deleted; 14699 } 14700 bool detNormalizedStatImfilePop(psDB *dbh, psS32 *det_id, psS32 *iteration, char **class_id, psF32 *norm) 14701 { 14702 psArray *rowSet; 14703 psMetadata *row; 14704 psMetadata *popped; 14705 long deleted; 14706 bool status; 14707 int rowID; 14708 14709 rowSet = psDBSelectRows(dbh, DETNORMALIZEDSTATIMFILE_TABLE_NAME, NULL, 1); 14710 if (!rowSet) { 14711 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item %s", DETNORMALIZEDSTATIMFILE_INDEX_NAME); 14712 psFree(rowSet); 14713 return NULL; 14714 } 14715 14716 row = psArrayGet(rowSet, 0); 14717 psMemIncrRefCounter(row); 14718 if (!row) { 14719 psError(PS_ERR_UNKNOWN, true, "database error or table is empty"); 14720 return NULL; 14721 } 14722 psFree(rowSet); 14723 14724 rowID = psMetadataLookupS32(&status, row, DETNORMALIZEDSTATIMFILE_INDEX_NAME); 14725 if (!status) { 14726 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item %s", DETNORMALIZEDSTATIMFILE_INDEX_NAME); 14727 psFree(row); 14728 return NULL; 14729 } 14730 14731 popped = psMetadataAlloc(); 14732 psMetadataAddS32(popped, PS_LIST_TAIL, DETNORMALIZEDSTATIMFILE_INDEX_NAME, 0, NULL, rowID); 14733 14734 deleted = psDBDeleteRows(dbh, DETNORMALIZEDSTATIMFILE_TABLE_NAME, popped, 0); 14735 if (deleted != 1) { 14736 psError(PS_ERR_UNKNOWN, false, "database failed to delete row"); 14737 psFree(popped); 14738 psFree(row); 14739 return NULL; 14740 } 14741 14742 psFree(popped); 14743 14744 *det_id = psMetadataLookupS32(&status, row, "det_id"); 14745 if (!status) { 14746 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item det_id"); 14747 psFree(row); 14748 return false; 14749 } 14750 *iteration = psMetadataLookupS32(&status, row, "iteration"); 14751 if (!status) { 14752 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item iteration"); 14753 psFree(row); 14754 return false; 14755 } 14756 *class_id = psMetadataLookupPtr(&status, row, "class_id"); 14757 if (!status) { 14758 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item class_id"); 14759 psFree(row); 14760 return false; 14761 } 14762 *norm = psMetadataLookupF32(&status, row, "norm"); 14763 if (!status) { 14764 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item norm"); 14765 psFree(row); 14766 return false; 14767 } 14768 14769 psFree(row); 14770 14771 return true; 14772 } 14773 14774 bool detNormalizedStatImfileInsertObject(psDB *dbh, detNormalizedStatImfileRow *object) 14775 { 14776 return detNormalizedStatImfileInsert(dbh, object->det_id, object->iteration, object->class_id, object->norm); 14777 } 14778 14779 bool detNormalizedStatImfileInsertObjects(psDB *dbh, psArray *objects) 14780 { 14781 for (long i = 0; i < psArrayLength(objects); i++) { 14782 if (!detNormalizedStatImfileInsertObject(dbh, objects->data[i])) { 14783 return false; 14784 } 14785 } 14786 14787 return true; 14788 } 14789 14790 detNormalizedStatImfileRow *detNormalizedStatImfilePopObject(psDB *dbh) 14791 { 14792 psS32 det_id; 14793 psS32 iteration; 14794 char class_id[256]; 14795 psF32 norm; 14796 14797 if (!detNormalizedStatImfilePop(dbh, &det_id, &iteration, (char **)&class_id, &norm)) { 14798 psError(PS_ERR_UNKNOWN, false, "failed to pop a database row"); 14799 return NULL; 14800 } 14801 14802 return detNormalizedStatImfileRowAlloc(det_id, iteration, class_id, norm); 14803 } 14804 14805 bool detNormalizedStatImfileInsertFits(psDB *dbh, const psFits *fits) 14806 { 14807 psArray *rowSet; 14808 14809 // move to (the first?) extension named DETNORMALIZEDSTATIMFILE_TABLE_NAME 14810 if (!psFitsMoveExtName(fits, DETNORMALIZEDSTATIMFILE_TABLE_NAME)) { 14811 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", DETNORMALIZEDSTATIMFILE_TABLE_NAME); 14812 return false; 14813 } 14814 14815 // check HDU type 14816 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 14817 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 14818 return false; 14819 } 14820 14821 // read fits table 14822 rowSet = psFitsReadTable(fits); 14823 if (!rowSet) { 14824 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 14825 psFree(rowSet); 14826 return false; 14827 } 14828 14829 if (!psDBInsertRows(dbh, DETNORMALIZEDSTATIMFILE_TABLE_NAME, rowSet)) { 14830 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 14831 psFree(rowSet); 14832 return false; 14833 } 14834 14835 psFree(rowSet); 14836 14837 return true; 14838 } 14839 14840 bool detNormalizedStatImfilePopFits(psDB *dbh, psFits *fits, unsigned long long limit) 14841 { 14842 char query[MAX_STRING_LENGTH]; 14843 14844 if (!detNormalizedStatImfileSelectRowsFits(dbh, fits, NULL, limit)) { 14845 psError(PS_ERR_UNKNOWN, true, "database error or table is empty"); 14846 return false; 14847 } 14848 14849 // remove limit rows from the end of the database 14850 if (snprintf(query, MAX_STRING_LENGTH, 14851 "DELETE FROM %s ORDER BY %s DESC LIMIT %lld", 14852 DETNORMALIZEDSTATIMFILE_TABLE_NAME, DETNORMALIZEDSTATIMFILE_INDEX_NAME, limit) < 0) { 14853 psError(PS_ERR_UNKNOWN, true, "query value attempted to exceed %s bytes", MAX_STRING_LENGTH); 14854 return false; 14855 } 14856 14857 if (!p_psDBRunQuery(dbh, query)) { 14858 psError(PS_ERR_UNKNOWN, false, "database query failed"); 14859 return false; 14860 } 14861 14862 return true; 14863 } 14864 14865 bool detNormalizedStatImfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 14866 { 14867 psArray *rowSet; 14868 psU64 i; 14869 14870 rowSet = psDBSelectRows(dbh, DETNORMALIZEDSTATIMFILE_TABLE_NAME, where, limit); 14871 if (!rowSet) { 14872 return false; 14873 } 14874 14875 // strip index column 14876 for (i = 0; i < rowSet->n; i++) { 14877 if (!psMetadataRemove((psMetadata *)rowSet->data[i], 0, DETNORMALIZEDSTATIMFILE_INDEX_NAME)) { 14878 psError(PS_ERR_UNKNOWN, true, "failed to remove item %s", DETNORMALIZEDSTATIMFILE_INDEX_NAME); 14879 psFree(rowSet); 14880 return false; 14881 } 14882 } 14883 14884 // output to fits 14885 if (!psFitsWriteTable(fits, NULL, rowSet, DETNORMALIZEDSTATIMFILE_TABLE_NAME)) { 14886 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 14887 psFree(rowSet); 14888 return false; 14889 } 14890 14891 psFree(rowSet); 14892 14893 return true; 14894 } 14895 14896 psMetadata *detNormalizedStatImfileMetadataFromObject(const detNormalizedStatImfileRow *object) 14897 { 14898 psMetadata *md; 14899 14900 md = psMetadataAlloc(); 14901 if (!psMetadataAddS32(md, PS_LIST_TAIL, "det_id", 0, NULL, object->det_id)) { 14902 psError(PS_ERR_UNKNOWN, false, "failed to add item det_id"); 14903 psFree(md); 14904 return NULL; 14905 } 14906 if (!psMetadataAddS32(md, PS_LIST_TAIL, "iteration", 0, NULL, object->iteration)) { 14907 psError(PS_ERR_UNKNOWN, false, "failed to add item iteration"); 14908 psFree(md); 14909 return NULL; 14910 } 14911 if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, NULL, object->class_id)) { 14912 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 14913 psFree(md); 14914 return NULL; 14915 } 14916 if (!psMetadataAddF32(md, PS_LIST_TAIL, "norm", 0, NULL, object->norm)) { 14917 psError(PS_ERR_UNKNOWN, false, "failed to add item norm"); 14918 psFree(md); 14919 return NULL; 14920 } 14921 14922 return md; 14923 } 14924 14925 detNormalizedStatImfileRow *detNormalizedStatImfileObjectFromMetadata(psMetadata *md) 14926 { 14927 bool status; 14928 psS32 det_id; 14929 psS32 iteration; 14930 char *class_id; 14931 psF32 norm; 14932 14933 det_id = psMetadataLookupS32(&status, md, "det_id"); 14934 if (!status) { 14935 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item det_id"); 14936 return false; 14937 } 14938 iteration = psMetadataLookupS32(&status, md, "iteration"); 14939 if (!status) { 14940 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item iteration"); 14941 return false; 14942 } 14943 class_id = psMetadataLookupPtr(&status, md, "class_id"); 14944 if (!status) { 14945 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item class_id"); 14946 return false; 14947 } 14948 norm = psMetadataLookupF32(&status, md, "norm"); 14949 if (!status) { 14950 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item norm"); 14951 return false; 14952 } 14953 14954 return detNormalizedStatImfileRowAlloc(det_id, iteration, class_id, norm); 14955 } 14956 psArray *detNormalizedStatImfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 14957 { 14958 psArray *rowSet; 14959 psArray *returnSet; 14960 psU64 i; 14961 14962 rowSet = psDBSelectRows(dbh, DETNORMALIZEDSTATIMFILE_TABLE_NAME, where, limit); 14963 if (!rowSet) { 14964 return NULL; 14965 } 14966 14967 // strip index column 14968 for (i = 0; i < rowSet->n; i++) { 14969 if (!psMetadataRemove((psMetadata *)(rowSet->data[i]), 0, DETNORMALIZEDSTATIMFILE_INDEX_NAME)) { 14970 psError(PS_ERR_UNKNOWN, true, "failed to remove item %s", DETNORMALIZEDSTATIMFILE_INDEX_NAME); 14971 psFree(rowSet); 14972 return false; 14973 } 14974 } 14975 14976 // convert psMetadata rows to row objects 14977 14978 returnSet = psArrayAlloc(rowSet->n); 14979 returnSet->n = 0; 14980 14981 for (i = 0; i < rowSet->n; i++) { 14982 detNormalizedStatImfileRow *object = detNormalizedStatImfileObjectFromMetadata(rowSet->data[i]); 14983 psArrayAdd(returnSet, 0, object); 14984 psFree(object); 14985 } 14986 14987 psFree(rowSet); 14988 14989 return returnSet; 14990 } 14991 bool detNormalizedStatImfileDeleteObject(psDB *dbh, const detNormalizedStatImfileRow *object) 14992 { 14993 psMetadata *where = detNormalizedStatImfileMetadataFromObject(object); 14994 long long count = psDBDeleteRows(dbh, DETNORMALIZEDSTATIMFILE_TABLE_NAME, where, 0); 14995 psFree(where) 14996 if (count < 0) { 14997 psError(PS_ERR_UNKNOWN, true, "failed to delete row from detNormalizedStatImfile"); 14998 return false; 14999 } 15000 if (count > 1) { 15001 // XXX should this be a psAbort() instead? It is possible that 15002 // having an object match multiple rows was by design. 15003 psError(PS_ERR_UNKNOWN, true, "detNormalizedStatImfileRow object matched more then one row. Check your database schema"); 15004 return false; 15005 } 15006 15007 return true; 15008 } 15009 long long detNormalizedStatImfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 15010 { 15011 long long deleted = 0; 15012 15013 for (long long i = 0; i < objects->n; i++) { 15014 detNormalizedStatImfileRow *object = objects->data[i]; 15015 psMetadata *where = detNormalizedStatImfileMetadataFromObject(object); 15016 long long count = psDBDeleteRows(dbh, DETNORMALIZEDSTATIMFILE_TABLE_NAME, where, limit); 15017 psFree(where) 15018 if (count < 0) { 15019 psError(PS_ERR_UNKNOWN, true, "failed to delete row from detNormalizedStatImfile"); 15020 return count; 15021 } 15022 15023 deleted += count; 15024 } 15025 15026 return deleted; 15027 } 15028 bool detNormalizedStatImfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 15029 { 15030 PS_ASSERT_PTR_NON_NULL(objects, false); 15031 15032 psMetadata *output = psMetadataAlloc(); 15033 for (long i = 0; i < psArrayLength(objects); i++) { 15034 psMetadata *md = detNormalizedStatImfileMetadataFromObject(objects->data[i]); 15035 if (!psMetadataAddMetadata( 15036 output, 15037 PS_LIST_TAIL, 15038 DETNORMALIZEDSTATIMFILE_TABLE_NAME, 15039 PS_META_DUPLICATE_OK, 15040 NULL, 15041 md 15042 )) { 15043 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 15044 psFree(md); 15045 psFree(output); 15046 return false; 15047 } 15048 psFree(md); 15049 } 15050 15051 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 15052 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 15053 psFree(output); 15054 } 15055 psFree(output); 15056 15057 return true; 15058 } 14585 15059 static void detNormalizedImfileRowFree(detNormalizedImfileRow *object); 14586 15060 -
trunk/ippdb/src/ippdb.h
r8325 r8368 6279 6279 bool mdcf ///< format as mdconfig or simple 6280 6280 ); 6281 /** detNormalizedStatImfileRow data structure 6282 * 6283 * Structure for representing a single row of detNormalizedStatImfile table data. 6284 */ 6285 6286 typedef struct { 6287 psS32 det_id; 6288 psS32 iteration; 6289 char *class_id; 6290 psF32 norm; 6291 } detNormalizedStatImfileRow; 6292 6293 /** Creates a new detNormalizedStatImfileRow object 6294 * 6295 * @return A new detNormalizedStatImfileRow object or NULL on failure. 6296 */ 6297 6298 detNormalizedStatImfileRow *detNormalizedStatImfileRowAlloc( 6299 psS32 det_id, 6300 psS32 iteration, 6301 const char *class_id, 6302 psF32 norm 6303 ); 6304 6305 /** Creates a new detNormalizedStatImfile table 6306 * 6307 * @return true on success 6308 */ 6309 6310 bool detNormalizedStatImfileCreateTable( 6311 psDB *dbh ///< Database handle 6312 ); 6313 6314 /** Deletes a detNormalizedStatImfile table 6315 * 6316 * @return true on success 6317 */ 6318 6319 bool detNormalizedStatImfileDropTable( 6320 psDB *dbh ///< Database handle 6321 ); 6322 6323 /** Insert a single row into a table 6324 * 6325 * This function constructs and inserts a single row based on it's parameters. 6326 * 6327 * @return true on success 6328 */ 6329 6330 bool detNormalizedStatImfileInsert( 6331 psDB *dbh, ///< Database handle 6332 psS32 det_id, 6333 psS32 iteration, 6334 const char *class_id, 6335 psF32 norm 6336 ); 6337 6338 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 6339 * 6340 * @return A The number of rows removed or a negative value on error 6341 */ 6342 6343 long long detNormalizedStatImfileDelete( 6344 psDB *dbh, ///< Database handle 6345 const psMetadata *where, ///< Row match criteria 6346 unsigned long long limit ///< Maximum number of elements to delete 6347 ); 6348 6349 /** Removes the last row from the database and returns it 6350 * 6351 * @return true on success 6352 */ 6353 6354 bool detNormalizedStatImfilePop( 6355 psDB *dbh, ///< Database handle 6356 psS32 *det_id, 6357 psS32 *iteration, 6358 char **class_id, 6359 psF32 *norm 6360 ); 6361 6362 /** Insert a single detNormalizedStatImfileRow object into a table 6363 * 6364 * This function constructs and inserts a single row based on it's parameters. 6365 * 6366 * @return true on success 6367 */ 6368 6369 bool detNormalizedStatImfileInsertObject( 6370 psDB *dbh, ///< Database handle 6371 detNormalizedStatImfileRow *object ///< detNormalizedStatImfileRow object 6372 ); 6373 6374 /** Insert an array of detNormalizedStatImfileRow object into a table 6375 * 6376 * This function constructs and inserts multiple rows based on it's parameters. 6377 * 6378 * @return true on success 6379 */ 6380 6381 bool detNormalizedStatImfileInsertObjects( 6382 psDB *dbh, ///< Database handle 6383 psArray *objects ///< array of detNormalizedStatImfileRow objects 6384 ); 6385 6386 /** Removes the last row from the database and returns it 6387 * 6388 * @return A new detNormalizedStatImfileRow on success or NULL on failure. 6389 */ 6390 6391 detNormalizedStatImfileRow *detNormalizedStatImfilePopObject( 6392 psDB *dbh ///< Database handle 6393 ); 6394 6395 /** Insert data from a binary FITS table detNormalizedStatImfileRow into the database 6396 * 6397 * This function expects a psFits object with a FITS table as the first 6398 * extension. The table must have at least one row of data in it, that is of 6399 * the appropriate format (number of columns and their type). All other 6400 * extensions are ignored. 6401 * 6402 * @return true on success 6403 */ 6404 6405 bool detNormalizedStatImfileInsertFits( 6406 psDB *dbh, ///< Database handle 6407 const psFits *fits ///< psFits object 6408 ); 6409 6410 /** Removes the last limit row from the database and returns them in a binary FITS table. 6411 * 6412 * This function assumes an empty psFits object and will create a FITS table as 6413 * the first extension. 6414 * 6415 * @return true on success 6416 */ 6417 6418 bool detNormalizedStatImfilePopFits( 6419 psDB *dbh, ///< Database handle 6420 psFits *fits, ///< psFits object 6421 unsigned long long limit ///< Maximum number of elements to return 6422 ); 6423 6424 /** Selects up to limit from the database and returns them in a binary FITS table 6425 * 6426 * This function assumes an empty psFits object and will create a FITS table 6427 * as the first extension. 6428 * 6429 * See psDBSelectRows() for documentation on the format of where. 6430 * 6431 * @return true on success 6432 */ 6433 6434 bool detNormalizedStatImfileSelectRowsFits( 6435 psDB *dbh, ///< Database handle 6436 psFits *fits, ///< psFits object 6437 const psMetadata *where, ///< Row match criteria 6438 unsigned long long limit ///< Maximum number of elements to return 6439 ); 6440 6441 /** Convert a detNormalizedStatImfileRow into an equivalent psMetadata 6442 * 6443 * @return A psMetadata pointer or NULL on error 6444 */ 6445 6446 psMetadata *detNormalizedStatImfileMetadataFromObject( 6447 const detNormalizedStatImfileRow *object ///< fooRow to convert into a psMetadata 6448 ); 6449 6450 /** Convert a psMetadata into an equivalent fooRow 6451 * 6452 * @return A detNormalizedStatImfileRow pointer or NULL on error 6453 */ 6454 6455 detNormalizedStatImfileRow *detNormalizedStatImfileObjectFromMetadata( 6456 psMetadata *md ///< psMetadata to convert into a fooRow 6457 ); 6458 /** Selects up to limit rows from the database and returns as detNormalizedStatImfileRow objects in a psArray 6459 * 6460 * See psDBSelectRows() for documentation on the format of where. 6461 * 6462 * @return A psArray pointer or NULL on error 6463 */ 6464 6465 psArray *detNormalizedStatImfileSelectRowObjects( 6466 psDB *dbh, ///< Database handle 6467 const psMetadata *where, ///< Row match criteria 6468 unsigned long long limit ///< Maximum number of elements to return 6469 ); 6470 /** Deletes a row from the database coresponding to an detNormalizedStatImfile 6471 * 6472 * Note that a 'where' search psMetadata is constructed from each object and 6473 * used to find rows to delete. 6474 * 6475 * @return A The number of rows removed or a negative value on error 6476 */ 6477 6478 bool detNormalizedStatImfileDeleteObject( 6479 psDB *dbh, ///< Database handle 6480 const detNormalizedStatImfileRow *object ///< Object to delete 6481 ); 6482 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 6483 * 6484 * Note that a 'where' search psMetadata is constructed from each object and 6485 * used to find rows to delete. 6486 * 6487 * @return A The number of rows removed or a negative value on error 6488 */ 6489 6490 long long detNormalizedStatImfileDeleteRowObjects( 6491 psDB *dbh, ///< Database handle 6492 const psArray *objects, ///< Array of objects to delete 6493 unsigned long long limit ///< Maximum number of elements to delete 6494 ); 6495 /** Formats and prints an array of detNormalizedStatImfileRow objects 6496 * 6497 * When mdcf is set the formated output is in psMetadataConfig 6498 * format, otherwise it is in a simple tabular format. 6499 * 6500 * @return true on success 6501 */ 6502 6503 bool detNormalizedStatImfilePrintObjects( 6504 FILE *stream, ///< a stream 6505 psArray *objects, ///< An array of detNormalizedStatImfileRow objects 6506 bool mdcf ///< format as mdconfig or simple 6507 ); 6281 6508 /** detNormalizedImfileRow data structure 6282 6509 * -
trunk/ippdb/tests/alloc.c
r8325 r8368 1042 1042 1043 1043 { 1044 detNormalizedStatImfileRow *object; 1045 1046 object = detNormalizedStatImfileRowAlloc(-32, -32, "a string", 32.32 ); 1047 1048 if (!object) { 1049 exit(EXIT_FAILURE); 1050 } 1051 1052 if (!object->det_id == -32) { 1053 psFree(object); 1054 exit(EXIT_FAILURE); 1055 } 1056 if (!object->iteration == -32) { 1057 psFree(object); 1058 exit(EXIT_FAILURE); 1059 } 1060 if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) { 1061 psFree(object); 1062 exit(EXIT_FAILURE); 1063 } 1064 if (!object->norm == 32.32) { 1065 psFree(object); 1066 exit(EXIT_FAILURE); 1067 } 1068 1069 psFree(object); 1070 } 1071 1072 { 1044 1073 detNormalizedImfileRow *object; 1045 1074 -
trunk/ippdb/tests/createtable.c
r7461 r8368 403 403 } 404 404 405 if(!detNormalizedStatImfileCreateTable(dbh)) { 406 exit(EXIT_FAILURE); 407 } 408 409 psDBCleanup(dbh); 410 } 411 412 { 413 psDB *dbh; 414 415 dbh = psDBInit("localhost", "test", NULL, "test"); 416 if (!dbh) { 417 exit(EXIT_FAILURE); 418 } 419 405 420 if(!detNormalizedImfileCreateTable(dbh)) { 406 421 exit(EXIT_FAILURE); -
trunk/ippdb/tests/dbcleanup.c
r7461 r8368 37 37 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detProcessedImfile"); 38 38 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detStackedImfile"); 39 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detNormalizedStatImfile"); 39 40 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detNormalizedImfile"); 40 41 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detMasterFrame"); -
trunk/ippdb/tests/dbsetup.c
r7461 r8368 91 91 detStackedImfileCreateTable(dbh); 92 92 93 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detNormalizedStatImfile"); 94 detNormalizedStatImfileCreateTable(dbh); 95 93 96 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detNormalizedImfile"); 94 97 detNormalizedImfileCreateTable(dbh); -
trunk/ippdb/tests/droptable.c
r7461 r8368 403 403 } 404 404 405 if (!detNormalizedStatImfileDropTable(dbh)) { 406 exit(EXIT_FAILURE); 407 } 408 409 psDBCleanup(dbh); 410 } 411 412 { 413 psDB *dbh; 414 415 dbh = psDBInit("localhost", "test", NULL, "test"); 416 if (!dbh) { 417 exit(EXIT_FAILURE); 418 } 419 405 420 if (!detNormalizedImfileDropTable(dbh)) { 406 421 exit(EXIT_FAILURE); -
trunk/ippdb/tests/insert.c
r8319 r8368 403 403 } 404 404 405 if (!detNormalizedStatImfileInsert(dbh, -32, -32, "a string", 32.32)) { 406 exit(EXIT_FAILURE); 407 } 408 409 psDBCleanup(dbh); 410 } 411 412 { 413 psDB *dbh; 414 415 dbh = psDBInit("localhost", "test", NULL, "test"); 416 if (!dbh) { 417 exit(EXIT_FAILURE); 418 } 419 405 420 if (!detNormalizedImfileInsert(dbh, -32, -32, "a string", "a string", "a string")) { 406 421 exit(EXIT_FAILURE); -
trunk/ippdb/tests/insertfits.c
r7461 r8368 700 700 } 701 701 702 if (!detNormalizedStatImfileInsertFits(dbh, fits)) { 703 exit(EXIT_FAILURE); 704 } 705 706 if (!psFitsClose(fits)) { 707 exit(EXIT_FAILURE); 708 } 709 710 psDBCleanup(dbh); 711 } 712 713 { 714 psDB *dbh; 715 psFits *fits; 716 717 dbh = psDBInit("localhost", "test", NULL, "test"); 718 if (!dbh) { 719 exit(EXIT_FAILURE); 720 } 721 722 // open a temp 723 fits = psFitsOpen(TMP_FILENAME, "r"); 724 if (!fits) { 725 exit(EXIT_FAILURE); 726 } 727 702 728 if (!detNormalizedImfileInsertFits(dbh, fits)) { 703 729 exit(EXIT_FAILURE); -
trunk/ippdb/tests/insertobject.c
r8319 r8368 579 579 { 580 580 psDB *dbh; 581 detNormalizedStatImfileRow *object; 582 583 dbh = psDBInit("localhost", "test", NULL, "test"); 584 if (!dbh) { 585 exit(EXIT_FAILURE); 586 } 587 588 object = detNormalizedStatImfileRowAlloc(-32, -32, "a string", 32.32); 589 if (!object) { 590 exit(EXIT_FAILURE); 591 } 592 593 if (!detNormalizedStatImfileInsertObject(dbh, object)) { 594 exit(EXIT_FAILURE); 595 } 596 597 psFree(object); 598 psDBCleanup(dbh); 599 } 600 601 { 602 psDB *dbh; 581 603 detNormalizedImfileRow *object; 582 604 -
trunk/ippdb/tests/metadatafromobject.c
r8325 r8368 1252 1252 { 1253 1253 psMetadata *md; 1254 detNormalizedStatImfileRow *object; 1255 bool status; 1256 1257 object = detNormalizedStatImfileRowAlloc(-32, -32, "a string", 32.32); 1258 if (!object) { 1259 exit(EXIT_FAILURE); 1260 } 1261 1262 md = detNormalizedStatImfileMetadataFromObject(object); 1263 if (!md) { 1264 exit(EXIT_FAILURE); 1265 } 1266 1267 psFree(object); 1268 1269 if (!psMetadataLookupS32(&status, md, "det_id") == -32) { 1270 psFree(md); 1271 exit(EXIT_FAILURE); 1272 } 1273 if (!psMetadataLookupS32(&status, md, "iteration") == -32) { 1274 psFree(md); 1275 exit(EXIT_FAILURE); 1276 } 1277 if (strncmp(psMetadataLookupPtr(&status, md, "class_id"), "a string", MAX_STRING_LENGTH)) { 1278 psFree(md); 1279 exit(EXIT_FAILURE); 1280 } 1281 if (!psMetadataLookupF32(&status, md, "norm") == 32.32) { 1282 psFree(md); 1283 exit(EXIT_FAILURE); 1284 } 1285 1286 psFree(md); 1287 } 1288 1289 { 1290 psMetadata *md; 1254 1291 detNormalizedImfileRow *object; 1255 1292 bool status; -
trunk/ippdb/tests/objectfrommetadata.c
r8325 r8368 1870 1870 { 1871 1871 psMetadata *md; 1872 detNormalizedStatImfileRow *object; 1873 1874 md = psMetadataAlloc(); 1875 if (!psMetadataAddS32(md, PS_LIST_TAIL, "det_id", 0, NULL, -32)) { 1876 psFree(md); 1877 exit(EXIT_FAILURE); 1878 } 1879 if (!psMetadataAddS32(md, PS_LIST_TAIL, "iteration", 0, NULL, -32)) { 1880 psFree(md); 1881 exit(EXIT_FAILURE); 1882 } 1883 if (!psMetadataAddStr(md, PS_LIST_TAIL, "class_id", 0, NULL, "a string")) { 1884 psFree(md); 1885 exit(EXIT_FAILURE); 1886 } 1887 if (!psMetadataAddF32(md, PS_LIST_TAIL, "norm", 0, NULL, 32.32)) { 1888 psFree(md); 1889 exit(EXIT_FAILURE); 1890 } 1891 1892 object = detNormalizedStatImfileObjectFromMetadata(md); 1893 if (!object) { 1894 psFree(md); 1895 exit(EXIT_FAILURE); 1896 } 1897 1898 psFree(md); 1899 1900 if (!object->det_id == -32) { 1901 psFree(object); 1902 exit(EXIT_FAILURE); 1903 } 1904 if (!object->iteration == -32) { 1905 psFree(object); 1906 exit(EXIT_FAILURE); 1907 } 1908 if (strncmp(object->class_id, "a string", MAX_STRING_LENGTH)) { 1909 psFree(object); 1910 exit(EXIT_FAILURE); 1911 } 1912 if (!object->norm == 32.32) { 1913 psFree(object); 1914 exit(EXIT_FAILURE); 1915 } 1916 1917 psFree(object); 1918 } 1919 1920 { 1921 psMetadata *md; 1872 1922 detNormalizedImfileRow *object; 1873 1923 -
trunk/ippdb/tests/pop.c
r8325 r8368 574 574 psS32 iteration; 575 575 char class_id[256]; 576 psF32 norm; 577 578 dbh = psDBInit("localhost", "test", NULL, "test"); 579 if (!dbh) { 580 exit(EXIT_FAILURE); 581 } 582 583 if (!detNormalizedStatImfilePop(dbh, &det_id, &iteration, (char **)&class_id, &norm)) { 584 exit(EXIT_FAILURE); 585 } 586 587 psDBCleanup(dbh); 588 } 589 590 { 591 psDB *dbh; 592 psS32 det_id; 593 psS32 iteration; 594 char class_id[256]; 576 595 char uri[256]; 577 596 char recipe[256]; -
trunk/ippdb/tests/popfits.c
r7461 r8368 700 700 } 701 701 702 if (!detNormalizedStatImfilePopFits(dbh, fits, 1)) { 703 exit(EXIT_FAILURE); 704 } 705 706 if (!psFitsClose(fits)) { 707 exit(EXIT_FAILURE); 708 } 709 710 psDBCleanup(dbh); 711 } 712 713 { 714 psDB *dbh; 715 psFits *fits; 716 717 dbh = psDBInit("localhost", "test", NULL, "test"); 718 if (!dbh) { 719 exit(EXIT_FAILURE); 720 } 721 722 // allocate a temp 723 fits = psFitsOpen(TMP_FILENAME, "w"); 724 if (!fits) { 725 exit(EXIT_FAILURE); 726 } 727 702 728 if (!detNormalizedImfilePopFits(dbh, fits, 1)) { 703 729 exit(EXIT_FAILURE); -
trunk/ippdb/tests/popobject.c
r7461 r8368 475 475 { 476 476 psDB *dbh; 477 detNormalizedStatImfileRow *object; 478 479 dbh = psDBInit("localhost", "test", NULL, "test"); 480 if (!dbh) { 481 exit(EXIT_FAILURE); 482 } 483 484 object = detNormalizedStatImfilePopObject(dbh); 485 if (!object) { 486 exit(EXIT_FAILURE); 487 } 488 489 psFree(object); 490 psDBCleanup(dbh); 491 } 492 493 { 494 psDB *dbh; 477 495 detNormalizedImfileRow *object; 478 496 -
trunk/ippdb/tests/selectrowsfits.c
r7461 r8368 593 593 } 594 594 595 if (!detNormalizedStatImfileSelectRowsFits(dbh, fits, NULL, 1)) { 596 exit(EXIT_FAILURE); 597 } 598 599 psFree(fits); 600 psDBCleanup(dbh); 601 } 602 603 { 604 psDB *dbh; 605 psFits *fits; 606 607 dbh = psDBInit("localhost", "test", NULL, "test"); 608 if (!dbh) { 609 exit(EXIT_FAILURE); 610 } 611 612 fits = psFitsOpen(TMP_FILENAME, "w"); 613 if (!fits) { 614 exit(EXIT_FAILURE); 615 } 616 595 617 if (!detNormalizedImfileSelectRowsFits(dbh, fits, NULL, 1)) { 596 618 exit(EXIT_FAILURE);
Note:
See TracChangeset
for help on using the changeset viewer.
