Changeset 11720 for trunk/ippdb/src
- Timestamp:
- Feb 8, 2007, 3:18:04 PM (20 years ago)
- Location:
- trunk/ippdb/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippdb/src/ippdb.c
r11679 r11720 20 20 /* 21 21 * 22 * This file was generated by glueforge 0.3622 * This file was generated by glueforge 1.00 23 23 * 24 24 * Do NOT directly edit this file. … … 62 62 #define DETRESIDEXP_TABLE_NAME "detResidExp" 63 63 #define DETRUNSUMMARY_TABLE_NAME "detRunSummary" 64 #define P4ARUN_TABLE_NAME "p4aRun" 65 #define P4AINPUTEXP_TABLE_NAME "p4aInputExp" 66 #define P4ASCFILE_TABLE_NAME "p4aScfile" 67 #define P4BRUN_TABLE_NAME "p4bRun" 68 #define P4BINPUTSCFILE_TABLE_NAME "p4bInputScfile" 69 #define P4BDIFFSCFILE_TABLE_NAME "p4bDiffScfile" 70 #define P4CRUN_TABLE_NAME "p4cRun" 71 #define P4CINPUTEXP_TABLE_NAME "p4cInputExp" 64 #define P4RUN_TABLE_NAME "p4Run" 65 #define P4INPUTEXP_TABLE_NAME "p4InputExp" 66 #define P4SCFILE_TABLE_NAME "p4Scfile" 67 #define P4INPUTSCFILE_TABLE_NAME "p4InputScfile" 68 #define P4DIFFSCFILE_TABLE_NAME "p4DiffScfile" 72 69 #define P4MAGICMASKIMFILE_TABLE_NAME "p4MagicMaskImfile" 73 70 #define SKYCELL_TABLE_NAME "skyCell" … … 13463 13460 return true; 13464 13461 } 13465 static void p4 aRunRowFree(p4aRunRow *object);13466 13467 p4 aRunRow *p4aRunRowAlloc(psS32 p4a_id, const char *state, const char *workdir, bool magic)13468 { 13469 p4 aRunRow*_object;13470 13471 _object = psAlloc(sizeof(p4 aRunRow));13472 psMemSetDeallocator(_object, (psFreeFunc)p4 aRunRowFree);13462 static void p4RunRowFree(p4RunRow *object); 13463 13464 p4RunRow *p4RunRowAlloc(psS32 p4a_id, const char *mode, const char *state, const char *workdir, psTime* registered) 13465 { 13466 p4RunRow *_object; 13467 13468 _object = psAlloc(sizeof(p4RunRow)); 13469 psMemSetDeallocator(_object, (psFreeFunc)p4RunRowFree); 13473 13470 13474 13471 _object->p4a_id = p4a_id; 13472 _object->mode = psStringCopy(mode); 13475 13473 _object->state = psStringCopy(state); 13476 13474 _object->workdir = psStringCopy(workdir); 13477 _object-> magic = magic;13475 _object->registered = psTimeCopy(registered); 13478 13476 13479 13477 return _object; 13480 13478 } 13481 13479 13482 static void p4aRunRowFree(p4aRunRow *object) 13483 { 13480 static void p4RunRowFree(p4RunRow *object) 13481 { 13482 psFree(object->mode); 13484 13483 psFree(object->state); 13485 13484 psFree(object->workdir); 13486 } 13487 13488 bool p4aRunCreateTable(psDB *dbh) 13485 psFree(object->registered); 13486 } 13487 13488 bool p4RunCreateTable(psDB *dbh) 13489 13489 { 13490 13490 psMetadata *md = psMetadataAlloc(); … … 13494 13494 return false; 13495 13495 } 13496 if (!psMetadataAdd(md, PS_LIST_TAIL, "mode", PS_DATA_STRING, "Key", "64")) { 13497 psError(PS_ERR_UNKNOWN, false, "failed to add item mode"); 13498 psFree(md); 13499 return false; 13500 } 13496 13501 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, "Key", "64")) { 13497 13502 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); … … 13504 13509 return false; 13505 13510 } 13506 if (!psMetadataAdd(md, PS_LIST_TAIL, " magic", PS_DATA_BOOL, "Primary Key", 0)) {13507 psError(PS_ERR_UNKNOWN, false, "failed to add item magic");13508 psFree(md); 13509 return false; 13510 } 13511 13512 bool status = psDBCreateTable(dbh, P4 ARUN_TABLE_NAME, md);13511 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, NULL)) { 13512 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 13513 psFree(md); 13514 return false; 13515 } 13516 13517 bool status = psDBCreateTable(dbh, P4RUN_TABLE_NAME, md); 13513 13518 13514 13519 psFree(md); … … 13517 13522 } 13518 13523 13519 bool p4 aRunDropTable(psDB *dbh)13520 { 13521 return psDBDropTable(dbh, P4 ARUN_TABLE_NAME);13522 } 13523 13524 bool p4 aRunInsert(psDB * dbh, psS32 p4a_id, const char *state, const char *workdir, bool magic)13524 bool p4RunDropTable(psDB *dbh) 13525 { 13526 return psDBDropTable(dbh, P4RUN_TABLE_NAME); 13527 } 13528 13529 bool p4RunInsert(psDB * dbh, psS32 p4a_id, const char *mode, const char *state, const char *workdir, psTime* registered) 13525 13530 { 13526 13531 psMetadata *md = psMetadataAlloc(); … … 13530 13535 return false; 13531 13536 } 13537 if (!psMetadataAdd(md, PS_LIST_TAIL, "mode", PS_DATA_STRING, NULL, mode)) { 13538 psError(PS_ERR_UNKNOWN, false, "failed to add item mode"); 13539 psFree(md); 13540 return false; 13541 } 13532 13542 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) { 13533 13543 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); … … 13540 13550 return false; 13541 13551 } 13542 if (!psMetadataAdd(md, PS_LIST_TAIL, " magic", PS_DATA_BOOL, NULL, magic)) {13543 psError(PS_ERR_UNKNOWN, false, "failed to add item magic");13544 psFree(md); 13545 return false; 13546 } 13547 13548 bool status = psDBInsertOneRow(dbh, P4 ARUN_TABLE_NAME, md);13552 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, registered)) { 13553 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 13554 psFree(md); 13555 return false; 13556 } 13557 13558 bool status = psDBInsertOneRow(dbh, P4RUN_TABLE_NAME, md); 13549 13559 psFree(md); 13550 13560 … … 13552 13562 } 13553 13563 13554 long long p4 aRunDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)13564 long long p4RunDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 13555 13565 { 13556 13566 long long deleted = 0; 13557 13567 13558 long long count = psDBDeleteRows(dbh, P4 ARUN_TABLE_NAME, where, limit);13568 long long count = psDBDeleteRows(dbh, P4RUN_TABLE_NAME, where, limit); 13559 13569 if (count < 0) { 13560 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4 aRun");13570 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4Run"); 13561 13571 return count; 13562 13572 … … 13566 13576 return deleted; 13567 13577 } 13568 bool p4 aRunInsertObject(psDB *dbh, p4aRunRow *object)13569 { 13570 return p4 aRunInsert(dbh, object->p4a_id, object->state, object->workdir, object->magic);13571 } 13572 13573 bool p4 aRunInsertObjects(psDB *dbh, psArray *objects)13578 bool p4RunInsertObject(psDB *dbh, p4RunRow *object) 13579 { 13580 return p4RunInsert(dbh, object->p4a_id, object->mode, object->state, object->workdir, object->registered); 13581 } 13582 13583 bool p4RunInsertObjects(psDB *dbh, psArray *objects) 13574 13584 { 13575 13585 for (long i = 0; i < psArrayLength(objects); i++) { 13576 if (!p4 aRunInsertObject(dbh, objects->data[i])) {13586 if (!p4RunInsertObject(dbh, objects->data[i])) { 13577 13587 return false; 13578 13588 } … … 13582 13592 } 13583 13593 13584 bool p4 aRunInsertFits(psDB *dbh, const psFits *fits)13594 bool p4RunInsertFits(psDB *dbh, const psFits *fits) 13585 13595 { 13586 13596 psArray *rowSet; 13587 13597 13588 // move to (the first?) extension named P4 ARUN_TABLE_NAME13589 if (!psFitsMoveExtName(fits, P4 ARUN_TABLE_NAME)) {13590 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4 ARUN_TABLE_NAME);13598 // move to (the first?) extension named P4RUN_TABLE_NAME 13599 if (!psFitsMoveExtName(fits, P4RUN_TABLE_NAME)) { 13600 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4RUN_TABLE_NAME); 13591 13601 return false; 13592 13602 } … … 13606 13616 } 13607 13617 13608 if (!psDBInsertRows(dbh, P4 ARUN_TABLE_NAME, rowSet)) {13618 if (!psDBInsertRows(dbh, P4RUN_TABLE_NAME, rowSet)) { 13609 13619 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 13610 13620 psFree(rowSet); … … 13617 13627 } 13618 13628 13619 bool p4 aRunSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)13629 bool p4RunSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 13620 13630 { 13621 13631 psArray *rowSet; 13622 13632 13623 rowSet = psDBSelectRows(dbh, P4 ARUN_TABLE_NAME, where, limit);13633 rowSet = psDBSelectRows(dbh, P4RUN_TABLE_NAME, where, limit); 13624 13634 if (!rowSet) { 13625 13635 return false; … … 13627 13637 13628 13638 // output to fits 13629 if (!psFitsWriteTable(fits, NULL, rowSet, P4 ARUN_TABLE_NAME)) {13639 if (!psFitsWriteTable(fits, NULL, rowSet, P4RUN_TABLE_NAME)) { 13630 13640 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 13631 13641 psFree(rowSet); … … 13638 13648 } 13639 13649 13640 psMetadata *p4 aRunMetadataFromObject(const p4aRunRow *object)13650 psMetadata *p4RunMetadataFromObject(const p4RunRow *object) 13641 13651 { 13642 13652 psMetadata *md = psMetadataAlloc(); … … 13646 13656 return false; 13647 13657 } 13658 if (!psMetadataAdd(md, PS_LIST_TAIL, "mode", PS_DATA_STRING, NULL, object->mode)) { 13659 psError(PS_ERR_UNKNOWN, false, "failed to add item mode"); 13660 psFree(md); 13661 return false; 13662 } 13648 13663 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) { 13649 13664 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); … … 13656 13671 return false; 13657 13672 } 13658 if (!psMetadataAdd(md, PS_LIST_TAIL, " magic", PS_DATA_BOOL, NULL, object->magic)) {13659 psError(PS_ERR_UNKNOWN, false, "failed to add item magic");13673 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, object->registered)) { 13674 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 13660 13675 psFree(md); 13661 13676 return false; … … 13666 13681 } 13667 13682 13668 p4 aRunRow *p4aRunObjectFromMetadata(psMetadata *md)13683 p4RunRow *p4RunObjectFromMetadata(psMetadata *md) 13669 13684 { 13670 13685 … … 13675 13690 return false; 13676 13691 } 13692 char* mode = psMetadataLookupPtr(&status, md, "mode"); 13693 if (!status) { 13694 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item mode"); 13695 return false; 13696 } 13677 13697 char* state = psMetadataLookupPtr(&status, md, "state"); 13678 13698 if (!status) { … … 13685 13705 return false; 13686 13706 } 13687 bool magic = psMetadataLookupBool(&status, md, "magic");13688 if (!status) { 13689 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item magic");13690 return false; 13691 } 13692 13693 return p4 aRunRowAlloc(p4a_id, state, workdir, magic);13694 } 13695 psArray *p4 aRunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)13707 psTime* registered = psMetadataLookupPtr(&status, md, "registered"); 13708 if (!status) { 13709 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item registered"); 13710 return false; 13711 } 13712 13713 return p4RunRowAlloc(p4a_id, mode, state, workdir, registered); 13714 } 13715 psArray *p4RunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 13696 13716 { 13697 13717 psArray *rowSet; … … 13699 13719 psU64 i; 13700 13720 13701 rowSet = psDBSelectRows(dbh, P4 ARUN_TABLE_NAME, where, limit);13721 rowSet = psDBSelectRows(dbh, P4RUN_TABLE_NAME, where, limit); 13702 13722 if (!rowSet) { 13703 13723 return NULL; … … 13709 13729 13710 13730 for (i = 0; i < rowSet->n; i++) { 13711 p4 aRunRow *object = p4aRunObjectFromMetadata(rowSet->data[i]);13731 p4RunRow *object = p4RunObjectFromMetadata(rowSet->data[i]); 13712 13732 psArrayAdd(returnSet, 0, object); 13713 13733 psFree(object); … … 13718 13738 return returnSet; 13719 13739 } 13720 bool p4 aRunDeleteObject(psDB *dbh, const p4aRunRow *object)13721 { 13722 psMetadata *where = p4 aRunMetadataFromObject(object);13723 long long count = psDBDeleteRows(dbh, P4 ARUN_TABLE_NAME, where, 0);13740 bool p4RunDeleteObject(psDB *dbh, const p4RunRow *object) 13741 { 13742 psMetadata *where = p4RunMetadataFromObject(object); 13743 long long count = psDBDeleteRows(dbh, P4RUN_TABLE_NAME, where, 0); 13724 13744 psFree(where); 13725 13745 if (count < 0) { 13726 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4 aRun");13746 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4Run"); 13727 13747 return false; 13728 13748 } … … 13730 13750 // XXX should this be a psAbort() instead? It is possible that 13731 13751 // having an object match multiple rows was by design. 13732 psError(PS_ERR_UNKNOWN, true, "p4 aRunRow object matched more then one row. Check your database schema");13733 return false; 13734 } 13735 13736 return true; 13737 } 13738 long long p4 aRunDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)13752 psError(PS_ERR_UNKNOWN, true, "p4RunRow object matched more then one row. Check your database schema"); 13753 return false; 13754 } 13755 13756 return true; 13757 } 13758 long long p4RunDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 13739 13759 { 13740 13760 long long deleted = 0; 13741 13761 13742 13762 for (long long i = 0; i < objects->n; i++) { 13743 p4 aRunRow *object = objects->data[i];13744 psMetadata *where = p4 aRunMetadataFromObject(object);13745 long long count = psDBDeleteRows(dbh, P4 ARUN_TABLE_NAME, where, limit);13763 p4RunRow *object = objects->data[i]; 13764 psMetadata *where = p4RunMetadataFromObject(object); 13765 long long count = psDBDeleteRows(dbh, P4RUN_TABLE_NAME, where, limit); 13746 13766 psFree(where); 13747 13767 if (count < 0) { 13748 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4 aRun");13768 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4Run"); 13749 13769 return count; 13750 13770 } … … 13755 13775 return deleted; 13756 13776 } 13757 bool p4 aRunPrintObjects(FILE *stream, psArray *objects, bool mdcf)13777 bool p4RunPrintObjects(FILE *stream, psArray *objects, bool mdcf) 13758 13778 { 13759 13779 PS_ASSERT_PTR_NON_NULL(objects, false); … … 13761 13781 psMetadata *output = psMetadataAlloc(); 13762 13782 for (long i = 0; i < psArrayLength(objects); i++) { 13763 psMetadata *md = p4 aRunMetadataFromObject(objects->data[i]);13783 psMetadata *md = p4RunMetadataFromObject(objects->data[i]); 13764 13784 if (!psMetadataAddMetadata( 13765 13785 output, 13766 13786 PS_LIST_TAIL, 13767 P4 ARUN_TABLE_NAME,13787 P4RUN_TABLE_NAME, 13768 13788 PS_META_DUPLICATE_OK, 13769 13789 NULL, … … 13786 13806 return true; 13787 13807 } 13788 bool p4 aRunPrintObject(FILE *stream, p4aRunRow *object, bool mdcf)13808 bool p4RunPrintObject(FILE *stream, p4RunRow *object, bool mdcf) 13789 13809 { 13790 13810 PS_ASSERT_PTR_NON_NULL(object, false); 13791 13811 13792 psMetadata *md = p4 aRunMetadataFromObject(object);13812 psMetadata *md = p4RunMetadataFromObject(object); 13793 13813 13794 13814 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { … … 13801 13821 return true; 13802 13822 } 13803 static void p4 aInputExpRowFree(p4aInputExpRow *object);13804 13805 p4 aInputExpRow *p4aInputExpRowAlloc(psS32 p4a_id, const char *exp_tag, psS32 p3_version)13806 { 13807 p4 aInputExpRow*_object;13808 13809 _object = psAlloc(sizeof(p4 aInputExpRow));13810 psMemSetDeallocator(_object, (psFreeFunc)p4 aInputExpRowFree);13823 static void p4InputExpRowFree(p4InputExpRow *object); 13824 13825 p4InputExpRow *p4InputExpRowAlloc(psS32 p4a_id, const char *exp_tag, psS32 p3_version, bool magiced) 13826 { 13827 p4InputExpRow *_object; 13828 13829 _object = psAlloc(sizeof(p4InputExpRow)); 13830 psMemSetDeallocator(_object, (psFreeFunc)p4InputExpRowFree); 13811 13831 13812 13832 _object->p4a_id = p4a_id; 13813 13833 _object->exp_tag = psStringCopy(exp_tag); 13814 13834 _object->p3_version = p3_version; 13835 _object->magiced = magiced; 13815 13836 13816 13837 return _object; 13817 13838 } 13818 13839 13819 static void p4 aInputExpRowFree(p4aInputExpRow *object)13840 static void p4InputExpRowFree(p4InputExpRow *object) 13820 13841 { 13821 13842 psFree(object->exp_tag); 13822 13843 } 13823 13844 13824 bool p4 aInputExpCreateTable(psDB *dbh)13845 bool p4InputExpCreateTable(psDB *dbh) 13825 13846 { 13826 13847 psMetadata *md = psMetadataAlloc(); … … 13840 13861 return false; 13841 13862 } 13842 13843 bool status = psDBCreateTable(dbh, P4AINPUTEXP_TABLE_NAME, md); 13863 if (!psMetadataAdd(md, PS_LIST_TAIL, "magiced", PS_DATA_BOOL, "Primary Key", 0)) { 13864 psError(PS_ERR_UNKNOWN, false, "failed to add item magiced"); 13865 psFree(md); 13866 return false; 13867 } 13868 13869 bool status = psDBCreateTable(dbh, P4INPUTEXP_TABLE_NAME, md); 13844 13870 13845 13871 psFree(md); … … 13848 13874 } 13849 13875 13850 bool p4 aInputExpDropTable(psDB *dbh)13851 { 13852 return psDBDropTable(dbh, P4 AINPUTEXP_TABLE_NAME);13853 } 13854 13855 bool p4 aInputExpInsert(psDB * dbh, psS32 p4a_id, const char *exp_tag, psS32 p3_version)13876 bool p4InputExpDropTable(psDB *dbh) 13877 { 13878 return psDBDropTable(dbh, P4INPUTEXP_TABLE_NAME); 13879 } 13880 13881 bool p4InputExpInsert(psDB * dbh, psS32 p4a_id, const char *exp_tag, psS32 p3_version, bool magiced) 13856 13882 { 13857 13883 psMetadata *md = psMetadataAlloc(); … … 13871 13897 return false; 13872 13898 } 13873 13874 bool status = psDBInsertOneRow(dbh, P4AINPUTEXP_TABLE_NAME, md); 13899 if (!psMetadataAdd(md, PS_LIST_TAIL, "magiced", PS_DATA_BOOL, NULL, magiced)) { 13900 psError(PS_ERR_UNKNOWN, false, "failed to add item magiced"); 13901 psFree(md); 13902 return false; 13903 } 13904 13905 bool status = psDBInsertOneRow(dbh, P4INPUTEXP_TABLE_NAME, md); 13875 13906 psFree(md); 13876 13907 … … 13878 13909 } 13879 13910 13880 long long p4 aInputExpDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)13911 long long p4InputExpDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 13881 13912 { 13882 13913 long long deleted = 0; 13883 13914 13884 long long count = psDBDeleteRows(dbh, P4 AINPUTEXP_TABLE_NAME, where, limit);13915 long long count = psDBDeleteRows(dbh, P4INPUTEXP_TABLE_NAME, where, limit); 13885 13916 if (count < 0) { 13886 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4 aInputExp");13917 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4InputExp"); 13887 13918 return count; 13888 13919 … … 13892 13923 return deleted; 13893 13924 } 13894 bool p4 aInputExpInsertObject(psDB *dbh, p4aInputExpRow *object)13895 { 13896 return p4 aInputExpInsert(dbh, object->p4a_id, object->exp_tag, object->p3_version);13897 } 13898 13899 bool p4 aInputExpInsertObjects(psDB *dbh, psArray *objects)13925 bool p4InputExpInsertObject(psDB *dbh, p4InputExpRow *object) 13926 { 13927 return p4InputExpInsert(dbh, object->p4a_id, object->exp_tag, object->p3_version, object->magiced); 13928 } 13929 13930 bool p4InputExpInsertObjects(psDB *dbh, psArray *objects) 13900 13931 { 13901 13932 for (long i = 0; i < psArrayLength(objects); i++) { 13902 if (!p4 aInputExpInsertObject(dbh, objects->data[i])) {13933 if (!p4InputExpInsertObject(dbh, objects->data[i])) { 13903 13934 return false; 13904 13935 } … … 13908 13939 } 13909 13940 13910 bool p4 aInputExpInsertFits(psDB *dbh, const psFits *fits)13941 bool p4InputExpInsertFits(psDB *dbh, const psFits *fits) 13911 13942 { 13912 13943 psArray *rowSet; 13913 13944 13914 // move to (the first?) extension named P4 AINPUTEXP_TABLE_NAME13915 if (!psFitsMoveExtName(fits, P4 AINPUTEXP_TABLE_NAME)) {13916 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4 AINPUTEXP_TABLE_NAME);13945 // move to (the first?) extension named P4INPUTEXP_TABLE_NAME 13946 if (!psFitsMoveExtName(fits, P4INPUTEXP_TABLE_NAME)) { 13947 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4INPUTEXP_TABLE_NAME); 13917 13948 return false; 13918 13949 } … … 13932 13963 } 13933 13964 13934 if (!psDBInsertRows(dbh, P4 AINPUTEXP_TABLE_NAME, rowSet)) {13965 if (!psDBInsertRows(dbh, P4INPUTEXP_TABLE_NAME, rowSet)) { 13935 13966 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 13936 13967 psFree(rowSet); … … 13943 13974 } 13944 13975 13945 bool p4 aInputExpSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)13976 bool p4InputExpSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 13946 13977 { 13947 13978 psArray *rowSet; 13948 13979 13949 rowSet = psDBSelectRows(dbh, P4 AINPUTEXP_TABLE_NAME, where, limit);13980 rowSet = psDBSelectRows(dbh, P4INPUTEXP_TABLE_NAME, where, limit); 13950 13981 if (!rowSet) { 13951 13982 return false; … … 13953 13984 13954 13985 // output to fits 13955 if (!psFitsWriteTable(fits, NULL, rowSet, P4 AINPUTEXP_TABLE_NAME)) {13986 if (!psFitsWriteTable(fits, NULL, rowSet, P4INPUTEXP_TABLE_NAME)) { 13956 13987 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 13957 13988 psFree(rowSet); … … 13964 13995 } 13965 13996 13966 psMetadata *p4 aInputExpMetadataFromObject(const p4aInputExpRow *object)13997 psMetadata *p4InputExpMetadataFromObject(const p4InputExpRow *object) 13967 13998 { 13968 13999 psMetadata *md = psMetadataAlloc(); … … 13982 14013 return false; 13983 14014 } 14015 if (!psMetadataAdd(md, PS_LIST_TAIL, "magiced", PS_DATA_BOOL, NULL, object->magiced)) { 14016 psError(PS_ERR_UNKNOWN, false, "failed to add item magiced"); 14017 psFree(md); 14018 return false; 14019 } 13984 14020 13985 14021 … … 13987 14023 } 13988 14024 13989 p4 aInputExpRow *p4aInputExpObjectFromMetadata(psMetadata *md)14025 p4InputExpRow *p4InputExpObjectFromMetadata(psMetadata *md) 13990 14026 { 13991 14027 … … 14006 14042 return false; 14007 14043 } 14008 14009 return p4aInputExpRowAlloc(p4a_id, exp_tag, p3_version); 14010 } 14011 psArray *p4aInputExpSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 14044 bool magiced = psMetadataLookupBool(&status, md, "magiced"); 14045 if (!status) { 14046 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item magiced"); 14047 return false; 14048 } 14049 14050 return p4InputExpRowAlloc(p4a_id, exp_tag, p3_version, magiced); 14051 } 14052 psArray *p4InputExpSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 14012 14053 { 14013 14054 psArray *rowSet; … … 14015 14056 psU64 i; 14016 14057 14017 rowSet = psDBSelectRows(dbh, P4 AINPUTEXP_TABLE_NAME, where, limit);14058 rowSet = psDBSelectRows(dbh, P4INPUTEXP_TABLE_NAME, where, limit); 14018 14059 if (!rowSet) { 14019 14060 return NULL; … … 14025 14066 14026 14067 for (i = 0; i < rowSet->n; i++) { 14027 p4 aInputExpRow *object = p4aInputExpObjectFromMetadata(rowSet->data[i]);14068 p4InputExpRow *object = p4InputExpObjectFromMetadata(rowSet->data[i]); 14028 14069 psArrayAdd(returnSet, 0, object); 14029 14070 psFree(object); … … 14034 14075 return returnSet; 14035 14076 } 14036 bool p4 aInputExpDeleteObject(psDB *dbh, const p4aInputExpRow *object)14037 { 14038 psMetadata *where = p4 aInputExpMetadataFromObject(object);14039 long long count = psDBDeleteRows(dbh, P4 AINPUTEXP_TABLE_NAME, where, 0);14077 bool p4InputExpDeleteObject(psDB *dbh, const p4InputExpRow *object) 14078 { 14079 psMetadata *where = p4InputExpMetadataFromObject(object); 14080 long long count = psDBDeleteRows(dbh, P4INPUTEXP_TABLE_NAME, where, 0); 14040 14081 psFree(where); 14041 14082 if (count < 0) { 14042 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4 aInputExp");14083 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4InputExp"); 14043 14084 return false; 14044 14085 } … … 14046 14087 // XXX should this be a psAbort() instead? It is possible that 14047 14088 // having an object match multiple rows was by design. 14048 psError(PS_ERR_UNKNOWN, true, "p4 aInputExpRow object matched more then one row. Check your database schema");14049 return false; 14050 } 14051 14052 return true; 14053 } 14054 long long p4 aInputExpDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)14089 psError(PS_ERR_UNKNOWN, true, "p4InputExpRow object matched more then one row. Check your database schema"); 14090 return false; 14091 } 14092 14093 return true; 14094 } 14095 long long p4InputExpDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 14055 14096 { 14056 14097 long long deleted = 0; 14057 14098 14058 14099 for (long long i = 0; i < objects->n; i++) { 14059 p4 aInputExpRow *object = objects->data[i];14060 psMetadata *where = p4 aInputExpMetadataFromObject(object);14061 long long count = psDBDeleteRows(dbh, P4 AINPUTEXP_TABLE_NAME, where, limit);14100 p4InputExpRow *object = objects->data[i]; 14101 psMetadata *where = p4InputExpMetadataFromObject(object); 14102 long long count = psDBDeleteRows(dbh, P4INPUTEXP_TABLE_NAME, where, limit); 14062 14103 psFree(where); 14063 14104 if (count < 0) { 14064 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4 aInputExp");14105 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4InputExp"); 14065 14106 return count; 14066 14107 } … … 14071 14112 return deleted; 14072 14113 } 14073 bool p4 aInputExpPrintObjects(FILE *stream, psArray *objects, bool mdcf)14114 bool p4InputExpPrintObjects(FILE *stream, psArray *objects, bool mdcf) 14074 14115 { 14075 14116 PS_ASSERT_PTR_NON_NULL(objects, false); … … 14077 14118 psMetadata *output = psMetadataAlloc(); 14078 14119 for (long i = 0; i < psArrayLength(objects); i++) { 14079 psMetadata *md = p4 aInputExpMetadataFromObject(objects->data[i]);14120 psMetadata *md = p4InputExpMetadataFromObject(objects->data[i]); 14080 14121 if (!psMetadataAddMetadata( 14081 14122 output, 14082 14123 PS_LIST_TAIL, 14083 P4 AINPUTEXP_TABLE_NAME,14124 P4INPUTEXP_TABLE_NAME, 14084 14125 PS_META_DUPLICATE_OK, 14085 14126 NULL, … … 14102 14143 return true; 14103 14144 } 14104 bool p4 aInputExpPrintObject(FILE *stream, p4aInputExpRow *object, bool mdcf)14145 bool p4InputExpPrintObject(FILE *stream, p4InputExpRow *object, bool mdcf) 14105 14146 { 14106 14147 PS_ASSERT_PTR_NON_NULL(object, false); 14107 14148 14108 psMetadata *md = p4 aInputExpMetadataFromObject(object);14149 psMetadata *md = p4InputExpMetadataFromObject(object); 14109 14150 14110 14151 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { … … 14117 14158 return true; 14118 14159 } 14119 static void p4 aScfileRowFree(p4aScfileRow *object);14120 14121 p4 aScfileRow *p4aScfileRowAlloc(psS32 p4a_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *uri, psF64 bg, psF64 bg_mean_stdev)14122 { 14123 p4 aScfileRow*_object;14124 14125 _object = psAlloc(sizeof(p4 aScfileRow));14126 psMemSetDeallocator(_object, (psFreeFunc)p4 aScfileRowFree);14160 static void p4ScfileRowFree(p4ScfileRow *object); 14161 14162 p4ScfileRow *p4ScfileRowAlloc(psS32 p4a_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *uri, psF64 bg, psF64 bg_mean_stdev) 14163 { 14164 p4ScfileRow *_object; 14165 14166 _object = psAlloc(sizeof(p4ScfileRow)); 14167 psMemSetDeallocator(_object, (psFreeFunc)p4ScfileRowFree); 14127 14168 14128 14169 _object->p4a_id = p4a_id; … … 14138 14179 } 14139 14180 14140 static void p4 aScfileRowFree(p4aScfileRow *object)14181 static void p4ScfileRowFree(p4ScfileRow *object) 14141 14182 { 14142 14183 psFree(object->skycell_id); … … 14146 14187 } 14147 14188 14148 bool p4 aScfileCreateTable(psDB *dbh)14189 bool p4ScfileCreateTable(psDB *dbh) 14149 14190 { 14150 14191 psMetadata *md = psMetadataAlloc(); … … 14190 14231 } 14191 14232 14192 bool status = psDBCreateTable(dbh, P4 ASCFILE_TABLE_NAME, md);14233 bool status = psDBCreateTable(dbh, P4SCFILE_TABLE_NAME, md); 14193 14234 14194 14235 psFree(md); … … 14197 14238 } 14198 14239 14199 bool p4 aScfileDropTable(psDB *dbh)14200 { 14201 return psDBDropTable(dbh, P4 ASCFILE_TABLE_NAME);14202 } 14203 14204 bool p4 aScfileInsert(psDB * dbh, psS32 p4a_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *uri, psF64 bg, psF64 bg_mean_stdev)14240 bool p4ScfileDropTable(psDB *dbh) 14241 { 14242 return psDBDropTable(dbh, P4SCFILE_TABLE_NAME); 14243 } 14244 14245 bool p4ScfileInsert(psDB * dbh, psS32 p4a_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *uri, psF64 bg, psF64 bg_mean_stdev) 14205 14246 { 14206 14247 psMetadata *md = psMetadataAlloc(); … … 14246 14287 } 14247 14288 14248 bool status = psDBInsertOneRow(dbh, P4 ASCFILE_TABLE_NAME, md);14289 bool status = psDBInsertOneRow(dbh, P4SCFILE_TABLE_NAME, md); 14249 14290 psFree(md); 14250 14291 … … 14252 14293 } 14253 14294 14254 long long p4 aScfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)14295 long long p4ScfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 14255 14296 { 14256 14297 long long deleted = 0; 14257 14298 14258 long long count = psDBDeleteRows(dbh, P4 ASCFILE_TABLE_NAME, where, limit);14299 long long count = psDBDeleteRows(dbh, P4SCFILE_TABLE_NAME, where, limit); 14259 14300 if (count < 0) { 14260 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4 aScfile");14301 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4Scfile"); 14261 14302 return count; 14262 14303 … … 14266 14307 return deleted; 14267 14308 } 14268 bool p4 aScfileInsertObject(psDB *dbh, p4aScfileRow *object)14269 { 14270 return p4 aScfileInsert(dbh, object->p4a_id, object->skycell_id, object->tess_id, object->exp_tag, object->p3_version, object->uri, object->bg, object->bg_mean_stdev);14271 } 14272 14273 bool p4 aScfileInsertObjects(psDB *dbh, psArray *objects)14309 bool p4ScfileInsertObject(psDB *dbh, p4ScfileRow *object) 14310 { 14311 return p4ScfileInsert(dbh, object->p4a_id, object->skycell_id, object->tess_id, object->exp_tag, object->p3_version, object->uri, object->bg, object->bg_mean_stdev); 14312 } 14313 14314 bool p4ScfileInsertObjects(psDB *dbh, psArray *objects) 14274 14315 { 14275 14316 for (long i = 0; i < psArrayLength(objects); i++) { 14276 if (!p4 aScfileInsertObject(dbh, objects->data[i])) {14317 if (!p4ScfileInsertObject(dbh, objects->data[i])) { 14277 14318 return false; 14278 14319 } … … 14282 14323 } 14283 14324 14284 bool p4 aScfileInsertFits(psDB *dbh, const psFits *fits)14325 bool p4ScfileInsertFits(psDB *dbh, const psFits *fits) 14285 14326 { 14286 14327 psArray *rowSet; 14287 14328 14288 // move to (the first?) extension named P4 ASCFILE_TABLE_NAME14289 if (!psFitsMoveExtName(fits, P4 ASCFILE_TABLE_NAME)) {14290 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4 ASCFILE_TABLE_NAME);14329 // move to (the first?) extension named P4SCFILE_TABLE_NAME 14330 if (!psFitsMoveExtName(fits, P4SCFILE_TABLE_NAME)) { 14331 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4SCFILE_TABLE_NAME); 14291 14332 return false; 14292 14333 } … … 14306 14347 } 14307 14348 14308 if (!psDBInsertRows(dbh, P4 ASCFILE_TABLE_NAME, rowSet)) {14349 if (!psDBInsertRows(dbh, P4SCFILE_TABLE_NAME, rowSet)) { 14309 14350 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 14310 14351 psFree(rowSet); … … 14317 14358 } 14318 14359 14319 bool p4 aScfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)14360 bool p4ScfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 14320 14361 { 14321 14362 psArray *rowSet; 14322 14363 14323 rowSet = psDBSelectRows(dbh, P4 ASCFILE_TABLE_NAME, where, limit);14364 rowSet = psDBSelectRows(dbh, P4SCFILE_TABLE_NAME, where, limit); 14324 14365 if (!rowSet) { 14325 14366 return false; … … 14327 14368 14328 14369 // output to fits 14329 if (!psFitsWriteTable(fits, NULL, rowSet, P4 ASCFILE_TABLE_NAME)) {14370 if (!psFitsWriteTable(fits, NULL, rowSet, P4SCFILE_TABLE_NAME)) { 14330 14371 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 14331 14372 psFree(rowSet); … … 14338 14379 } 14339 14380 14340 psMetadata *p4 aScfileMetadataFromObject(const p4aScfileRow *object)14381 psMetadata *p4ScfileMetadataFromObject(const p4ScfileRow *object) 14341 14382 { 14342 14383 psMetadata *md = psMetadataAlloc(); … … 14386 14427 } 14387 14428 14388 p4 aScfileRow *p4aScfileObjectFromMetadata(psMetadata *md)14429 p4ScfileRow *p4ScfileObjectFromMetadata(psMetadata *md) 14389 14430 { 14390 14431 … … 14431 14472 } 14432 14473 14433 return p4 aScfileRowAlloc(p4a_id, skycell_id, tess_id, exp_tag, p3_version, uri, bg, bg_mean_stdev);14434 } 14435 psArray *p4 aScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)14474 return p4ScfileRowAlloc(p4a_id, skycell_id, tess_id, exp_tag, p3_version, uri, bg, bg_mean_stdev); 14475 } 14476 psArray *p4ScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 14436 14477 { 14437 14478 psArray *rowSet; … … 14439 14480 psU64 i; 14440 14481 14441 rowSet = psDBSelectRows(dbh, P4 ASCFILE_TABLE_NAME, where, limit);14482 rowSet = psDBSelectRows(dbh, P4SCFILE_TABLE_NAME, where, limit); 14442 14483 if (!rowSet) { 14443 14484 return NULL; … … 14449 14490 14450 14491 for (i = 0; i < rowSet->n; i++) { 14451 p4 aScfileRow *object = p4aScfileObjectFromMetadata(rowSet->data[i]);14492 p4ScfileRow *object = p4ScfileObjectFromMetadata(rowSet->data[i]); 14452 14493 psArrayAdd(returnSet, 0, object); 14453 14494 psFree(object); … … 14458 14499 return returnSet; 14459 14500 } 14460 bool p4 aScfileDeleteObject(psDB *dbh, const p4aScfileRow *object)14461 { 14462 psMetadata *where = p4 aScfileMetadataFromObject(object);14463 long long count = psDBDeleteRows(dbh, P4 ASCFILE_TABLE_NAME, where, 0);14501 bool p4ScfileDeleteObject(psDB *dbh, const p4ScfileRow *object) 14502 { 14503 psMetadata *where = p4ScfileMetadataFromObject(object); 14504 long long count = psDBDeleteRows(dbh, P4SCFILE_TABLE_NAME, where, 0); 14464 14505 psFree(where); 14465 14506 if (count < 0) { 14466 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4 aScfile");14507 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4Scfile"); 14467 14508 return false; 14468 14509 } … … 14470 14511 // XXX should this be a psAbort() instead? It is possible that 14471 14512 // having an object match multiple rows was by design. 14472 psError(PS_ERR_UNKNOWN, true, "p4 aScfileRow object matched more then one row. Check your database schema");14473 return false; 14474 } 14475 14476 return true; 14477 } 14478 long long p4 aScfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)14513 psError(PS_ERR_UNKNOWN, true, "p4ScfileRow object matched more then one row. Check your database schema"); 14514 return false; 14515 } 14516 14517 return true; 14518 } 14519 long long p4ScfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 14479 14520 { 14480 14521 long long deleted = 0; 14481 14522 14482 14523 for (long long i = 0; i < objects->n; i++) { 14483 p4 aScfileRow *object = objects->data[i];14484 psMetadata *where = p4 aScfileMetadataFromObject(object);14485 long long count = psDBDeleteRows(dbh, P4 ASCFILE_TABLE_NAME, where, limit);14524 p4ScfileRow *object = objects->data[i]; 14525 psMetadata *where = p4ScfileMetadataFromObject(object); 14526 long long count = psDBDeleteRows(dbh, P4SCFILE_TABLE_NAME, where, limit); 14486 14527 psFree(where); 14487 14528 if (count < 0) { 14488 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4 aScfile");14529 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4Scfile"); 14489 14530 return count; 14490 14531 } … … 14495 14536 return deleted; 14496 14537 } 14497 bool p4 aScfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)14538 bool p4ScfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 14498 14539 { 14499 14540 PS_ASSERT_PTR_NON_NULL(objects, false); … … 14501 14542 psMetadata *output = psMetadataAlloc(); 14502 14543 for (long i = 0; i < psArrayLength(objects); i++) { 14503 psMetadata *md = p4 aScfileMetadataFromObject(objects->data[i]);14544 psMetadata *md = p4ScfileMetadataFromObject(objects->data[i]); 14504 14545 if (!psMetadataAddMetadata( 14505 14546 output, 14506 14547 PS_LIST_TAIL, 14507 P4 ASCFILE_TABLE_NAME,14548 P4SCFILE_TABLE_NAME, 14508 14549 PS_META_DUPLICATE_OK, 14509 14550 NULL, … … 14526 14567 return true; 14527 14568 } 14528 bool p4 aScfilePrintObject(FILE *stream, p4aScfileRow *object, bool mdcf)14569 bool p4ScfilePrintObject(FILE *stream, p4ScfileRow *object, bool mdcf) 14529 14570 { 14530 14571 PS_ASSERT_PTR_NON_NULL(object, false); 14531 14572 14532 psMetadata *md = p4 aScfileMetadataFromObject(object);14573 psMetadata *md = p4ScfileMetadataFromObject(object); 14533 14574 14534 14575 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { … … 14541 14582 return true; 14542 14583 } 14543 static void p4 bRunRowFree(p4bRunRow *object);14544 14545 p4 bRunRow *p4bRunRowAlloc(psS32 p4b_id, const char *state, const char *workdir, bool magic)14546 { 14547 p4 bRunRow*_object;14548 14549 _object = psAlloc(sizeof(p4 bRunRow));14550 psMemSetDeallocator(_object, (psFreeFunc)p4 bRunRowFree);14584 static void p4InputScfileRowFree(p4InputScfileRow *object); 14585 14586 p4InputScfileRow *p4InputScfileRowAlloc(psS32 p4b_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *kind) 14587 { 14588 p4InputScfileRow *_object; 14589 14590 _object = psAlloc(sizeof(p4InputScfileRow)); 14591 psMemSetDeallocator(_object, (psFreeFunc)p4InputScfileRowFree); 14551 14592 14552 14593 _object->p4b_id = p4b_id; 14553 _object->state = psStringCopy(state); 14554 _object->workdir = psStringCopy(workdir); 14555 _object->magic = magic; 14594 _object->skycell_id = psStringCopy(skycell_id); 14595 _object->tess_id = psStringCopy(tess_id); 14596 _object->exp_tag = psStringCopy(exp_tag); 14597 _object->p3_version = p3_version; 14598 _object->kind = psStringCopy(kind); 14556 14599 14557 14600 return _object; 14558 14601 } 14559 14602 14560 static void p4bRunRowFree(p4bRunRow *object) 14561 { 14562 psFree(object->state); 14563 psFree(object->workdir); 14564 } 14565 14566 bool p4bRunCreateTable(psDB *dbh) 14603 static void p4InputScfileRowFree(p4InputScfileRow *object) 14604 { 14605 psFree(object->skycell_id); 14606 psFree(object->tess_id); 14607 psFree(object->exp_tag); 14608 psFree(object->kind); 14609 } 14610 14611 bool p4InputScfileCreateTable(psDB *dbh) 14567 14612 { 14568 14613 psMetadata *md = psMetadataAlloc(); 14569 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, "Primary Key AUTO_INCREMENT", 0)) {14614 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, "Primary Key", 0)) { 14570 14615 psError(PS_ERR_UNKNOWN, false, "failed to add item p4b_id"); 14571 14616 psFree(md); 14572 14617 return false; 14573 14618 } 14574 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, "Key", "64")) { 14575 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 14576 psFree(md); 14577 return false; 14578 } 14579 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, "255")) { 14580 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 14581 psFree(md); 14582 return false; 14583 } 14584 if (!psMetadataAdd(md, PS_LIST_TAIL, "magic", PS_DATA_BOOL, "Primary Key", 0)) { 14585 psError(PS_ERR_UNKNOWN, false, "failed to add item magic"); 14586 psFree(md); 14587 return false; 14588 } 14589 14590 bool status = psDBCreateTable(dbh, P4BRUN_TABLE_NAME, md); 14619 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) { 14620 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 14621 psFree(md); 14622 return false; 14623 } 14624 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) { 14625 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 14626 psFree(md); 14627 return false; 14628 } 14629 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) { 14630 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 14631 psFree(md); 14632 return false; 14633 } 14634 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) { 14635 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 14636 psFree(md); 14637 return false; 14638 } 14639 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, "Key", "64")) { 14640 psError(PS_ERR_UNKNOWN, false, "failed to add item kind"); 14641 psFree(md); 14642 return false; 14643 } 14644 14645 bool status = psDBCreateTable(dbh, P4INPUTSCFILE_TABLE_NAME, md); 14591 14646 14592 14647 psFree(md); … … 14595 14650 } 14596 14651 14597 bool p4 bRunDropTable(psDB *dbh)14598 { 14599 return psDBDropTable(dbh, P4 BRUN_TABLE_NAME);14600 } 14601 14602 bool p4 bRunInsert(psDB * dbh, psS32 p4b_id, const char *state, const char *workdir, bool magic)14652 bool p4InputScfileDropTable(psDB *dbh) 14653 { 14654 return psDBDropTable(dbh, P4INPUTSCFILE_TABLE_NAME); 14655 } 14656 14657 bool p4InputScfileInsert(psDB * dbh, psS32 p4b_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *kind) 14603 14658 { 14604 14659 psMetadata *md = psMetadataAlloc(); … … 14608 14663 return false; 14609 14664 } 14610 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) { 14611 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 14612 psFree(md); 14613 return false; 14614 } 14615 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, workdir)) { 14616 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 14617 psFree(md); 14618 return false; 14619 } 14620 if (!psMetadataAdd(md, PS_LIST_TAIL, "magic", PS_DATA_BOOL, NULL, magic)) { 14621 psError(PS_ERR_UNKNOWN, false, "failed to add item magic"); 14622 psFree(md); 14623 return false; 14624 } 14625 14626 bool status = psDBInsertOneRow(dbh, P4BRUN_TABLE_NAME, md); 14665 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) { 14666 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 14667 psFree(md); 14668 return false; 14669 } 14670 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) { 14671 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 14672 psFree(md); 14673 return false; 14674 } 14675 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) { 14676 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 14677 psFree(md); 14678 return false; 14679 } 14680 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) { 14681 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 14682 psFree(md); 14683 return false; 14684 } 14685 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, NULL, kind)) { 14686 psError(PS_ERR_UNKNOWN, false, "failed to add item kind"); 14687 psFree(md); 14688 return false; 14689 } 14690 14691 bool status = psDBInsertOneRow(dbh, P4INPUTSCFILE_TABLE_NAME, md); 14627 14692 psFree(md); 14628 14693 … … 14630 14695 } 14631 14696 14632 long long p4 bRunDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)14697 long long p4InputScfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 14633 14698 { 14634 14699 long long deleted = 0; 14635 14700 14636 long long count = psDBDeleteRows(dbh, P4 BRUN_TABLE_NAME, where, limit);14701 long long count = psDBDeleteRows(dbh, P4INPUTSCFILE_TABLE_NAME, where, limit); 14637 14702 if (count < 0) { 14638 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4 bRun");14703 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4InputScfile"); 14639 14704 return count; 14640 14705 … … 14644 14709 return deleted; 14645 14710 } 14646 bool p4 bRunInsertObject(psDB *dbh, p4bRunRow *object)14647 { 14648 return p4 bRunInsert(dbh, object->p4b_id, object->state, object->workdir, object->magic);14649 } 14650 14651 bool p4 bRunInsertObjects(psDB *dbh, psArray *objects)14711 bool p4InputScfileInsertObject(psDB *dbh, p4InputScfileRow *object) 14712 { 14713 return p4InputScfileInsert(dbh, object->p4b_id, object->skycell_id, object->tess_id, object->exp_tag, object->p3_version, object->kind); 14714 } 14715 14716 bool p4InputScfileInsertObjects(psDB *dbh, psArray *objects) 14652 14717 { 14653 14718 for (long i = 0; i < psArrayLength(objects); i++) { 14654 if (!p4 bRunInsertObject(dbh, objects->data[i])) {14719 if (!p4InputScfileInsertObject(dbh, objects->data[i])) { 14655 14720 return false; 14656 14721 } … … 14660 14725 } 14661 14726 14662 bool p4 bRunInsertFits(psDB *dbh, const psFits *fits)14727 bool p4InputScfileInsertFits(psDB *dbh, const psFits *fits) 14663 14728 { 14664 14729 psArray *rowSet; 14665 14730 14666 // move to (the first?) extension named P4 BRUN_TABLE_NAME14667 if (!psFitsMoveExtName(fits, P4 BRUN_TABLE_NAME)) {14668 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4 BRUN_TABLE_NAME);14731 // move to (the first?) extension named P4INPUTSCFILE_TABLE_NAME 14732 if (!psFitsMoveExtName(fits, P4INPUTSCFILE_TABLE_NAME)) { 14733 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4INPUTSCFILE_TABLE_NAME); 14669 14734 return false; 14670 14735 } … … 14684 14749 } 14685 14750 14686 if (!psDBInsertRows(dbh, P4 BRUN_TABLE_NAME, rowSet)) {14751 if (!psDBInsertRows(dbh, P4INPUTSCFILE_TABLE_NAME, rowSet)) { 14687 14752 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 14688 14753 psFree(rowSet); … … 14695 14760 } 14696 14761 14697 bool p4 bRunSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)14762 bool p4InputScfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 14698 14763 { 14699 14764 psArray *rowSet; 14700 14765 14701 rowSet = psDBSelectRows(dbh, P4 BRUN_TABLE_NAME, where, limit);14766 rowSet = psDBSelectRows(dbh, P4INPUTSCFILE_TABLE_NAME, where, limit); 14702 14767 if (!rowSet) { 14703 14768 return false; … … 14705 14770 14706 14771 // output to fits 14707 if (!psFitsWriteTable(fits, NULL, rowSet, P4 BRUN_TABLE_NAME)) {14772 if (!psFitsWriteTable(fits, NULL, rowSet, P4INPUTSCFILE_TABLE_NAME)) { 14708 14773 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 14709 14774 psFree(rowSet); … … 14716 14781 } 14717 14782 14718 psMetadata *p4 bRunMetadataFromObject(const p4bRunRow *object)14783 psMetadata *p4InputScfileMetadataFromObject(const p4InputScfileRow *object) 14719 14784 { 14720 14785 psMetadata *md = psMetadataAlloc(); … … 14724 14789 return false; 14725 14790 } 14726 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) { 14727 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 14728 psFree(md); 14729 return false; 14730 } 14731 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, object->workdir)) { 14732 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 14733 psFree(md); 14734 return false; 14735 } 14736 if (!psMetadataAdd(md, PS_LIST_TAIL, "magic", PS_DATA_BOOL, NULL, object->magic)) { 14737 psError(PS_ERR_UNKNOWN, false, "failed to add item magic"); 14791 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) { 14792 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 14793 psFree(md); 14794 return false; 14795 } 14796 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) { 14797 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 14798 psFree(md); 14799 return false; 14800 } 14801 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) { 14802 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 14803 psFree(md); 14804 return false; 14805 } 14806 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) { 14807 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 14808 psFree(md); 14809 return false; 14810 } 14811 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, NULL, object->kind)) { 14812 psError(PS_ERR_UNKNOWN, false, "failed to add item kind"); 14738 14813 psFree(md); 14739 14814 return false; … … 14744 14819 } 14745 14820 14746 p4 bRunRow *p4bRunObjectFromMetadata(psMetadata *md)14821 p4InputScfileRow *p4InputScfileObjectFromMetadata(psMetadata *md) 14747 14822 { 14748 14823 … … 14753 14828 return false; 14754 14829 } 14755 char* state = psMetadataLookupPtr(&status, md, "state"); 14756 if (!status) { 14757 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item state"); 14758 return false; 14759 } 14760 char* workdir = psMetadataLookupPtr(&status, md, "workdir"); 14761 if (!status) { 14762 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item workdir"); 14763 return false; 14764 } 14765 bool magic = psMetadataLookupBool(&status, md, "magic"); 14766 if (!status) { 14767 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item magic"); 14768 return false; 14769 } 14770 14771 return p4bRunRowAlloc(p4b_id, state, workdir, magic); 14772 } 14773 psArray *p4bRunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 14830 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id"); 14831 if (!status) { 14832 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id"); 14833 return false; 14834 } 14835 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id"); 14836 if (!status) { 14837 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id"); 14838 return false; 14839 } 14840 char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag"); 14841 if (!status) { 14842 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag"); 14843 return false; 14844 } 14845 psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version"); 14846 if (!status) { 14847 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version"); 14848 return false; 14849 } 14850 char* kind = psMetadataLookupPtr(&status, md, "kind"); 14851 if (!status) { 14852 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item kind"); 14853 return false; 14854 } 14855 14856 return p4InputScfileRowAlloc(p4b_id, skycell_id, tess_id, exp_tag, p3_version, kind); 14857 } 14858 psArray *p4InputScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 14774 14859 { 14775 14860 psArray *rowSet; … … 14777 14862 psU64 i; 14778 14863 14779 rowSet = psDBSelectRows(dbh, P4 BRUN_TABLE_NAME, where, limit);14864 rowSet = psDBSelectRows(dbh, P4INPUTSCFILE_TABLE_NAME, where, limit); 14780 14865 if (!rowSet) { 14781 14866 return NULL; … … 14787 14872 14788 14873 for (i = 0; i < rowSet->n; i++) { 14789 p4 bRunRow *object = p4bRunObjectFromMetadata(rowSet->data[i]);14874 p4InputScfileRow *object = p4InputScfileObjectFromMetadata(rowSet->data[i]); 14790 14875 psArrayAdd(returnSet, 0, object); 14791 14876 psFree(object); … … 14796 14881 return returnSet; 14797 14882 } 14798 bool p4 bRunDeleteObject(psDB *dbh, const p4bRunRow *object)14799 { 14800 psMetadata *where = p4 bRunMetadataFromObject(object);14801 long long count = psDBDeleteRows(dbh, P4 BRUN_TABLE_NAME, where, 0);14883 bool p4InputScfileDeleteObject(psDB *dbh, const p4InputScfileRow *object) 14884 { 14885 psMetadata *where = p4InputScfileMetadataFromObject(object); 14886 long long count = psDBDeleteRows(dbh, P4INPUTSCFILE_TABLE_NAME, where, 0); 14802 14887 psFree(where); 14803 14888 if (count < 0) { 14804 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4 bRun");14889 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4InputScfile"); 14805 14890 return false; 14806 14891 } … … 14808 14893 // XXX should this be a psAbort() instead? It is possible that 14809 14894 // having an object match multiple rows was by design. 14810 psError(PS_ERR_UNKNOWN, true, "p4 bRunRow object matched more then one row. Check your database schema");14811 return false; 14812 } 14813 14814 return true; 14815 } 14816 long long p4 bRunDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)14895 psError(PS_ERR_UNKNOWN, true, "p4InputScfileRow object matched more then one row. Check your database schema"); 14896 return false; 14897 } 14898 14899 return true; 14900 } 14901 long long p4InputScfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 14817 14902 { 14818 14903 long long deleted = 0; 14819 14904 14820 14905 for (long long i = 0; i < objects->n; i++) { 14821 p4 bRunRow *object = objects->data[i];14822 psMetadata *where = p4 bRunMetadataFromObject(object);14823 long long count = psDBDeleteRows(dbh, P4 BRUN_TABLE_NAME, where, limit);14906 p4InputScfileRow *object = objects->data[i]; 14907 psMetadata *where = p4InputScfileMetadataFromObject(object); 14908 long long count = psDBDeleteRows(dbh, P4INPUTSCFILE_TABLE_NAME, where, limit); 14824 14909 psFree(where); 14825 14910 if (count < 0) { 14826 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4 bRun");14911 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4InputScfile"); 14827 14912 return count; 14828 14913 } … … 14833 14918 return deleted; 14834 14919 } 14835 bool p4 bRunPrintObjects(FILE *stream, psArray *objects, bool mdcf)14920 bool p4InputScfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 14836 14921 { 14837 14922 PS_ASSERT_PTR_NON_NULL(objects, false); … … 14839 14924 psMetadata *output = psMetadataAlloc(); 14840 14925 for (long i = 0; i < psArrayLength(objects); i++) { 14841 psMetadata *md = p4 bRunMetadataFromObject(objects->data[i]);14926 psMetadata *md = p4InputScfileMetadataFromObject(objects->data[i]); 14842 14927 if (!psMetadataAddMetadata( 14843 14928 output, 14844 14929 PS_LIST_TAIL, 14845 P4 BRUN_TABLE_NAME,14930 P4INPUTSCFILE_TABLE_NAME, 14846 14931 PS_META_DUPLICATE_OK, 14847 14932 NULL, … … 14864 14949 return true; 14865 14950 } 14866 bool p4 bRunPrintObject(FILE *stream, p4bRunRow *object, bool mdcf)14951 bool p4InputScfilePrintObject(FILE *stream, p4InputScfileRow *object, bool mdcf) 14867 14952 { 14868 14953 PS_ASSERT_PTR_NON_NULL(object, false); 14869 14954 14870 psMetadata *md = p4 bRunMetadataFromObject(object);14955 psMetadata *md = p4InputScfileMetadataFromObject(object); 14871 14956 14872 14957 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { … … 14879 14964 return true; 14880 14965 } 14881 static void p4 bInputScfileRowFree(p4bInputScfileRow *object);14882 14883 p4 bInputScfileRow *p4bInputScfileRowAlloc(psS32 p4b_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *kind)14884 { 14885 p4 bInputScfileRow *_object;14886 14887 _object = psAlloc(sizeof(p4 bInputScfileRow));14888 psMemSetDeallocator(_object, (psFreeFunc)p4 bInputScfileRowFree);14966 static void p4DiffScfileRowFree(p4DiffScfileRow *object); 14967 14968 p4DiffScfileRow *p4DiffScfileRowAlloc(psS32 p4b_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *uri, psF64 bg, psF64 bg_mean_stdev) 14969 { 14970 p4DiffScfileRow *_object; 14971 14972 _object = psAlloc(sizeof(p4DiffScfileRow)); 14973 psMemSetDeallocator(_object, (psFreeFunc)p4DiffScfileRowFree); 14889 14974 14890 14975 _object->p4b_id = p4b_id; … … 14893 14978 _object->exp_tag = psStringCopy(exp_tag); 14894 14979 _object->p3_version = p3_version; 14895 _object->kind = psStringCopy(kind); 14980 _object->uri = psStringCopy(uri); 14981 _object->bg = bg; 14982 _object->bg_mean_stdev = bg_mean_stdev; 14896 14983 14897 14984 return _object; 14898 14985 } 14899 14986 14900 static void p4 bInputScfileRowFree(p4bInputScfileRow *object)14987 static void p4DiffScfileRowFree(p4DiffScfileRow *object) 14901 14988 { 14902 14989 psFree(object->skycell_id); 14903 14990 psFree(object->tess_id); 14904 14991 psFree(object->exp_tag); 14905 psFree(object-> kind);14906 } 14907 14908 bool p4 bInputScfileCreateTable(psDB *dbh)14992 psFree(object->uri); 14993 } 14994 14995 bool p4DiffScfileCreateTable(psDB *dbh) 14909 14996 { 14910 14997 psMetadata *md = psMetadataAlloc(); … … 14934 15021 return false; 14935 15022 } 14936 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, "Key", "64")) { 14937 psError(PS_ERR_UNKNOWN, false, "failed to add item kind"); 14938 psFree(md); 14939 return false; 14940 } 14941 14942 bool status = psDBCreateTable(dbh, P4BINPUTSCFILE_TABLE_NAME, md); 15023 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) { 15024 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 15025 psFree(md); 15026 return false; 15027 } 15028 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, 0.0)) { 15029 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 15030 psFree(md); 15031 return false; 15032 } 15033 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, 0.0)) { 15034 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev"); 15035 psFree(md); 15036 return false; 15037 } 15038 15039 bool status = psDBCreateTable(dbh, P4DIFFSCFILE_TABLE_NAME, md); 14943 15040 14944 15041 psFree(md); … … 14947 15044 } 14948 15045 14949 bool p4 bInputScfileDropTable(psDB *dbh)14950 { 14951 return psDBDropTable(dbh, P4 BINPUTSCFILE_TABLE_NAME);14952 } 14953 14954 bool p4 bInputScfileInsert(psDB * dbh, psS32 p4b_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *kind)15046 bool p4DiffScfileDropTable(psDB *dbh) 15047 { 15048 return psDBDropTable(dbh, P4DIFFSCFILE_TABLE_NAME); 15049 } 15050 15051 bool p4DiffScfileInsert(psDB * dbh, psS32 p4b_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *uri, psF64 bg, psF64 bg_mean_stdev) 14955 15052 { 14956 15053 psMetadata *md = psMetadataAlloc(); … … 14980 15077 return false; 14981 15078 } 14982 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, NULL, kind)) { 14983 psError(PS_ERR_UNKNOWN, false, "failed to add item kind"); 14984 psFree(md); 14985 return false; 14986 } 14987 14988 bool status = psDBInsertOneRow(dbh, P4BINPUTSCFILE_TABLE_NAME, md); 15079 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) { 15080 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 15081 psFree(md); 15082 return false; 15083 } 15084 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, bg)) { 15085 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 15086 psFree(md); 15087 return false; 15088 } 15089 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, bg_mean_stdev)) { 15090 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev"); 15091 psFree(md); 15092 return false; 15093 } 15094 15095 bool status = psDBInsertOneRow(dbh, P4DIFFSCFILE_TABLE_NAME, md); 14989 15096 psFree(md); 14990 15097 … … 14992 15099 } 14993 15100 14994 long long p4 bInputScfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)15101 long long p4DiffScfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 14995 15102 { 14996 15103 long long deleted = 0; 14997 15104 14998 long long count = psDBDeleteRows(dbh, P4 BINPUTSCFILE_TABLE_NAME, where, limit);15105 long long count = psDBDeleteRows(dbh, P4DIFFSCFILE_TABLE_NAME, where, limit); 14999 15106 if (count < 0) { 15000 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4 bInputScfile");15107 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4DiffScfile"); 15001 15108 return count; 15002 15109 … … 15006 15113 return deleted; 15007 15114 } 15008 bool p4 bInputScfileInsertObject(psDB *dbh, p4bInputScfileRow *object)15009 { 15010 return p4 bInputScfileInsert(dbh, object->p4b_id, object->skycell_id, object->tess_id, object->exp_tag, object->p3_version, object->kind);15011 } 15012 15013 bool p4 bInputScfileInsertObjects(psDB *dbh, psArray *objects)15115 bool p4DiffScfileInsertObject(psDB *dbh, p4DiffScfileRow *object) 15116 { 15117 return p4DiffScfileInsert(dbh, object->p4b_id, object->skycell_id, object->tess_id, object->exp_tag, object->p3_version, object->uri, object->bg, object->bg_mean_stdev); 15118 } 15119 15120 bool p4DiffScfileInsertObjects(psDB *dbh, psArray *objects) 15014 15121 { 15015 15122 for (long i = 0; i < psArrayLength(objects); i++) { 15016 if (!p4 bInputScfileInsertObject(dbh, objects->data[i])) {15123 if (!p4DiffScfileInsertObject(dbh, objects->data[i])) { 15017 15124 return false; 15018 15125 } … … 15022 15129 } 15023 15130 15024 bool p4 bInputScfileInsertFits(psDB *dbh, const psFits *fits)15131 bool p4DiffScfileInsertFits(psDB *dbh, const psFits *fits) 15025 15132 { 15026 15133 psArray *rowSet; 15027 15134 15028 // move to (the first?) extension named P4 BINPUTSCFILE_TABLE_NAME15029 if (!psFitsMoveExtName(fits, P4 BINPUTSCFILE_TABLE_NAME)) {15030 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4 BINPUTSCFILE_TABLE_NAME);15135 // move to (the first?) extension named P4DIFFSCFILE_TABLE_NAME 15136 if (!psFitsMoveExtName(fits, P4DIFFSCFILE_TABLE_NAME)) { 15137 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4DIFFSCFILE_TABLE_NAME); 15031 15138 return false; 15032 15139 } … … 15046 15153 } 15047 15154 15048 if (!psDBInsertRows(dbh, P4 BINPUTSCFILE_TABLE_NAME, rowSet)) {15155 if (!psDBInsertRows(dbh, P4DIFFSCFILE_TABLE_NAME, rowSet)) { 15049 15156 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 15050 15157 psFree(rowSet); … … 15057 15164 } 15058 15165 15059 bool p4 bInputScfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)15166 bool p4DiffScfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 15060 15167 { 15061 15168 psArray *rowSet; 15062 15169 15063 rowSet = psDBSelectRows(dbh, P4 BINPUTSCFILE_TABLE_NAME, where, limit);15170 rowSet = psDBSelectRows(dbh, P4DIFFSCFILE_TABLE_NAME, where, limit); 15064 15171 if (!rowSet) { 15065 15172 return false; … … 15067 15174 15068 15175 // output to fits 15069 if (!psFitsWriteTable(fits, NULL, rowSet, P4 BINPUTSCFILE_TABLE_NAME)) {15176 if (!psFitsWriteTable(fits, NULL, rowSet, P4DIFFSCFILE_TABLE_NAME)) { 15070 15177 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 15071 15178 psFree(rowSet); … … 15078 15185 } 15079 15186 15080 psMetadata *p4 bInputScfileMetadataFromObject(const p4bInputScfileRow *object)15187 psMetadata *p4DiffScfileMetadataFromObject(const p4DiffScfileRow *object) 15081 15188 { 15082 15189 psMetadata *md = psMetadataAlloc(); … … 15106 15213 return false; 15107 15214 } 15108 if (!psMetadataAdd(md, PS_LIST_TAIL, "kind", PS_DATA_STRING, NULL, object->kind)) { 15109 psError(PS_ERR_UNKNOWN, false, "failed to add item kind"); 15215 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) { 15216 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 15217 psFree(md); 15218 return false; 15219 } 15220 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, object->bg)) { 15221 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 15222 psFree(md); 15223 return false; 15224 } 15225 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, object->bg_mean_stdev)) { 15226 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev"); 15110 15227 psFree(md); 15111 15228 return false; … … 15116 15233 } 15117 15234 15118 p4 bInputScfileRow *p4bInputScfileObjectFromMetadata(psMetadata *md)15235 p4DiffScfileRow *p4DiffScfileObjectFromMetadata(psMetadata *md) 15119 15236 { 15120 15237 … … 15145 15262 return false; 15146 15263 } 15147 char* kind = psMetadataLookupPtr(&status, md, "kind"); 15148 if (!status) { 15149 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item kind"); 15150 return false; 15151 } 15152 15153 return p4bInputScfileRowAlloc(p4b_id, skycell_id, tess_id, exp_tag, p3_version, kind); 15154 } 15155 psArray *p4bInputScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 15264 char* uri = psMetadataLookupPtr(&status, md, "uri"); 15265 if (!status) { 15266 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri"); 15267 return false; 15268 } 15269 psF64 bg = psMetadataLookupF64(&status, md, "bg"); 15270 if (!status) { 15271 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg"); 15272 return false; 15273 } 15274 psF64 bg_mean_stdev = psMetadataLookupF64(&status, md, "bg_mean_stdev"); 15275 if (!status) { 15276 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_mean_stdev"); 15277 return false; 15278 } 15279 15280 return p4DiffScfileRowAlloc(p4b_id, skycell_id, tess_id, exp_tag, p3_version, uri, bg, bg_mean_stdev); 15281 } 15282 psArray *p4DiffScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 15156 15283 { 15157 15284 psArray *rowSet; … … 15159 15286 psU64 i; 15160 15287 15161 rowSet = psDBSelectRows(dbh, P4 BINPUTSCFILE_TABLE_NAME, where, limit);15288 rowSet = psDBSelectRows(dbh, P4DIFFSCFILE_TABLE_NAME, where, limit); 15162 15289 if (!rowSet) { 15163 15290 return NULL; … … 15169 15296 15170 15297 for (i = 0; i < rowSet->n; i++) { 15171 p4 bInputScfileRow *object = p4bInputScfileObjectFromMetadata(rowSet->data[i]);15298 p4DiffScfileRow *object = p4DiffScfileObjectFromMetadata(rowSet->data[i]); 15172 15299 psArrayAdd(returnSet, 0, object); 15173 15300 psFree(object); … … 15178 15305 return returnSet; 15179 15306 } 15180 bool p4 bInputScfileDeleteObject(psDB *dbh, const p4bInputScfileRow *object)15181 { 15182 psMetadata *where = p4 bInputScfileMetadataFromObject(object);15183 long long count = psDBDeleteRows(dbh, P4 BINPUTSCFILE_TABLE_NAME, where, 0);15307 bool p4DiffScfileDeleteObject(psDB *dbh, const p4DiffScfileRow *object) 15308 { 15309 psMetadata *where = p4DiffScfileMetadataFromObject(object); 15310 long long count = psDBDeleteRows(dbh, P4DIFFSCFILE_TABLE_NAME, where, 0); 15184 15311 psFree(where); 15185 15312 if (count < 0) { 15186 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4 bInputScfile");15313 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4DiffScfile"); 15187 15314 return false; 15188 15315 } … … 15190 15317 // XXX should this be a psAbort() instead? It is possible that 15191 15318 // having an object match multiple rows was by design. 15192 psError(PS_ERR_UNKNOWN, true, "p4 bInputScfileRow object matched more then one row. Check your database schema");15193 return false; 15194 } 15195 15196 return true; 15197 } 15198 long long p4 bInputScfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)15319 psError(PS_ERR_UNKNOWN, true, "p4DiffScfileRow object matched more then one row. Check your database schema"); 15320 return false; 15321 } 15322 15323 return true; 15324 } 15325 long long p4DiffScfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 15199 15326 { 15200 15327 long long deleted = 0; 15201 15328 15202 15329 for (long long i = 0; i < objects->n; i++) { 15203 p4 bInputScfileRow *object = objects->data[i];15204 psMetadata *where = p4 bInputScfileMetadataFromObject(object);15205 long long count = psDBDeleteRows(dbh, P4 BINPUTSCFILE_TABLE_NAME, where, limit);15330 p4DiffScfileRow *object = objects->data[i]; 15331 psMetadata *where = p4DiffScfileMetadataFromObject(object); 15332 long long count = psDBDeleteRows(dbh, P4DIFFSCFILE_TABLE_NAME, where, limit); 15206 15333 psFree(where); 15207 15334 if (count < 0) { 15208 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4 bInputScfile");15335 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4DiffScfile"); 15209 15336 return count; 15210 15337 } … … 15215 15342 return deleted; 15216 15343 } 15217 bool p4 bInputScfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)15344 bool p4DiffScfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 15218 15345 { 15219 15346 PS_ASSERT_PTR_NON_NULL(objects, false); … … 15221 15348 psMetadata *output = psMetadataAlloc(); 15222 15349 for (long i = 0; i < psArrayLength(objects); i++) { 15223 psMetadata *md = p4 bInputScfileMetadataFromObject(objects->data[i]);15350 psMetadata *md = p4DiffScfileMetadataFromObject(objects->data[i]); 15224 15351 if (!psMetadataAddMetadata( 15225 15352 output, 15226 15353 PS_LIST_TAIL, 15227 P4 BINPUTSCFILE_TABLE_NAME,15354 P4DIFFSCFILE_TABLE_NAME, 15228 15355 PS_META_DUPLICATE_OK, 15229 15356 NULL, … … 15246 15373 return true; 15247 15374 } 15248 bool p4 bInputScfilePrintObject(FILE *stream, p4bInputScfileRow *object, bool mdcf)15375 bool p4DiffScfilePrintObject(FILE *stream, p4DiffScfileRow *object, bool mdcf) 15249 15376 { 15250 15377 PS_ASSERT_PTR_NON_NULL(object, false); 15251 15378 15252 psMetadata *md = p4bInputScfileMetadataFromObject(object); 15253 15254 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 15255 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 15256 psFree(md); 15257 } 15258 15259 psFree(md); 15260 15261 return true; 15262 } 15263 static void p4bDiffScfileRowFree(p4bDiffScfileRow *object); 15264 15265 p4bDiffScfileRow *p4bDiffScfileRowAlloc(psS32 p4b_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *uri, psF64 bg, psF64 bg_mean_stdev) 15266 { 15267 p4bDiffScfileRow *_object; 15268 15269 _object = psAlloc(sizeof(p4bDiffScfileRow)); 15270 psMemSetDeallocator(_object, (psFreeFunc)p4bDiffScfileRowFree); 15271 15272 _object->p4b_id = p4b_id; 15273 _object->skycell_id = psStringCopy(skycell_id); 15274 _object->tess_id = psStringCopy(tess_id); 15275 _object->exp_tag = psStringCopy(exp_tag); 15276 _object->p3_version = p3_version; 15277 _object->uri = psStringCopy(uri); 15278 _object->bg = bg; 15279 _object->bg_mean_stdev = bg_mean_stdev; 15280 15281 return _object; 15282 } 15283 15284 static void p4bDiffScfileRowFree(p4bDiffScfileRow *object) 15285 { 15286 psFree(object->skycell_id); 15287 psFree(object->tess_id); 15288 psFree(object->exp_tag); 15289 psFree(object->uri); 15290 } 15291 15292 bool p4bDiffScfileCreateTable(psDB *dbh) 15293 { 15294 psMetadata *md = psMetadataAlloc(); 15295 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, "Primary Key", 0)) { 15296 psError(PS_ERR_UNKNOWN, false, "failed to add item p4b_id"); 15297 psFree(md); 15298 return false; 15299 } 15300 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) { 15301 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 15302 psFree(md); 15303 return false; 15304 } 15305 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) { 15306 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 15307 psFree(md); 15308 return false; 15309 } 15310 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) { 15311 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 15312 psFree(md); 15313 return false; 15314 } 15315 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) { 15316 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 15317 psFree(md); 15318 return false; 15319 } 15320 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) { 15321 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 15322 psFree(md); 15323 return false; 15324 } 15325 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, 0.0)) { 15326 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 15327 psFree(md); 15328 return false; 15329 } 15330 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, 0.0)) { 15331 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev"); 15332 psFree(md); 15333 return false; 15334 } 15335 15336 bool status = psDBCreateTable(dbh, P4BDIFFSCFILE_TABLE_NAME, md); 15337 15338 psFree(md); 15339 15340 return status; 15341 } 15342 15343 bool p4bDiffScfileDropTable(psDB *dbh) 15344 { 15345 return psDBDropTable(dbh, P4BDIFFSCFILE_TABLE_NAME); 15346 } 15347 15348 bool p4bDiffScfileInsert(psDB * dbh, psS32 p4b_id, const char *skycell_id, const char *tess_id, const char *exp_tag, psS32 p3_version, const char *uri, psF64 bg, psF64 bg_mean_stdev) 15349 { 15350 psMetadata *md = psMetadataAlloc(); 15351 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, NULL, p4b_id)) { 15352 psError(PS_ERR_UNKNOWN, false, "failed to add item p4b_id"); 15353 psFree(md); 15354 return false; 15355 } 15356 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) { 15357 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 15358 psFree(md); 15359 return false; 15360 } 15361 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) { 15362 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 15363 psFree(md); 15364 return false; 15365 } 15366 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) { 15367 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 15368 psFree(md); 15369 return false; 15370 } 15371 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) { 15372 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 15373 psFree(md); 15374 return false; 15375 } 15376 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) { 15377 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 15378 psFree(md); 15379 return false; 15380 } 15381 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, bg)) { 15382 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 15383 psFree(md); 15384 return false; 15385 } 15386 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, bg_mean_stdev)) { 15387 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev"); 15388 psFree(md); 15389 return false; 15390 } 15391 15392 bool status = psDBInsertOneRow(dbh, P4BDIFFSCFILE_TABLE_NAME, md); 15393 psFree(md); 15394 15395 return status; 15396 } 15397 15398 long long p4bDiffScfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 15399 { 15400 long long deleted = 0; 15401 15402 long long count = psDBDeleteRows(dbh, P4BDIFFSCFILE_TABLE_NAME, where, limit); 15403 if (count < 0) { 15404 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4bDiffScfile"); 15405 return count; 15406 15407 deleted += count; 15408 } 15409 15410 return deleted; 15411 } 15412 bool p4bDiffScfileInsertObject(psDB *dbh, p4bDiffScfileRow *object) 15413 { 15414 return p4bDiffScfileInsert(dbh, object->p4b_id, object->skycell_id, object->tess_id, object->exp_tag, object->p3_version, object->uri, object->bg, object->bg_mean_stdev); 15415 } 15416 15417 bool p4bDiffScfileInsertObjects(psDB *dbh, psArray *objects) 15418 { 15419 for (long i = 0; i < psArrayLength(objects); i++) { 15420 if (!p4bDiffScfileInsertObject(dbh, objects->data[i])) { 15421 return false; 15422 } 15423 } 15424 15425 return true; 15426 } 15427 15428 bool p4bDiffScfileInsertFits(psDB *dbh, const psFits *fits) 15429 { 15430 psArray *rowSet; 15431 15432 // move to (the first?) extension named P4BDIFFSCFILE_TABLE_NAME 15433 if (!psFitsMoveExtName(fits, P4BDIFFSCFILE_TABLE_NAME)) { 15434 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4BDIFFSCFILE_TABLE_NAME); 15435 return false; 15436 } 15437 15438 // check HDU type 15439 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 15440 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 15441 return false; 15442 } 15443 15444 // read fits table 15445 rowSet = psFitsReadTable(fits); 15446 if (!rowSet) { 15447 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 15448 psFree(rowSet); 15449 return false; 15450 } 15451 15452 if (!psDBInsertRows(dbh, P4BDIFFSCFILE_TABLE_NAME, rowSet)) { 15453 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 15454 psFree(rowSet); 15455 return false; 15456 } 15457 15458 psFree(rowSet); 15459 15460 return true; 15461 } 15462 15463 bool p4bDiffScfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 15464 { 15465 psArray *rowSet; 15466 15467 rowSet = psDBSelectRows(dbh, P4BDIFFSCFILE_TABLE_NAME, where, limit); 15468 if (!rowSet) { 15469 return false; 15470 } 15471 15472 // output to fits 15473 if (!psFitsWriteTable(fits, NULL, rowSet, P4BDIFFSCFILE_TABLE_NAME)) { 15474 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 15475 psFree(rowSet); 15476 return false; 15477 } 15478 15479 psFree(rowSet); 15480 15481 return true; 15482 } 15483 15484 psMetadata *p4bDiffScfileMetadataFromObject(const p4bDiffScfileRow *object) 15485 { 15486 psMetadata *md = psMetadataAlloc(); 15487 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4b_id", PS_DATA_S32, NULL, object->p4b_id)) { 15488 psError(PS_ERR_UNKNOWN, false, "failed to add item p4b_id"); 15489 psFree(md); 15490 return false; 15491 } 15492 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) { 15493 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 15494 psFree(md); 15495 return false; 15496 } 15497 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) { 15498 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 15499 psFree(md); 15500 return false; 15501 } 15502 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) { 15503 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 15504 psFree(md); 15505 return false; 15506 } 15507 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) { 15508 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 15509 psFree(md); 15510 return false; 15511 } 15512 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) { 15513 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 15514 psFree(md); 15515 return false; 15516 } 15517 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg", PS_DATA_F64, NULL, object->bg)) { 15518 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 15519 psFree(md); 15520 return false; 15521 } 15522 if (!psMetadataAdd(md, PS_LIST_TAIL, "bg_mean_stdev", PS_DATA_F64, NULL, object->bg_mean_stdev)) { 15523 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev"); 15524 psFree(md); 15525 return false; 15526 } 15527 15528 15529 return md; 15530 } 15531 15532 p4bDiffScfileRow *p4bDiffScfileObjectFromMetadata(psMetadata *md) 15533 { 15534 15535 bool status = false; 15536 psS32 p4b_id = psMetadataLookupS32(&status, md, "p4b_id"); 15537 if (!status) { 15538 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4b_id"); 15539 return false; 15540 } 15541 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id"); 15542 if (!status) { 15543 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id"); 15544 return false; 15545 } 15546 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id"); 15547 if (!status) { 15548 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id"); 15549 return false; 15550 } 15551 char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag"); 15552 if (!status) { 15553 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag"); 15554 return false; 15555 } 15556 psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version"); 15557 if (!status) { 15558 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version"); 15559 return false; 15560 } 15561 char* uri = psMetadataLookupPtr(&status, md, "uri"); 15562 if (!status) { 15563 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri"); 15564 return false; 15565 } 15566 psF64 bg = psMetadataLookupF64(&status, md, "bg"); 15567 if (!status) { 15568 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg"); 15569 return false; 15570 } 15571 psF64 bg_mean_stdev = psMetadataLookupF64(&status, md, "bg_mean_stdev"); 15572 if (!status) { 15573 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_mean_stdev"); 15574 return false; 15575 } 15576 15577 return p4bDiffScfileRowAlloc(p4b_id, skycell_id, tess_id, exp_tag, p3_version, uri, bg, bg_mean_stdev); 15578 } 15579 psArray *p4bDiffScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 15580 { 15581 psArray *rowSet; 15582 psArray *returnSet; 15583 psU64 i; 15584 15585 rowSet = psDBSelectRows(dbh, P4BDIFFSCFILE_TABLE_NAME, where, limit); 15586 if (!rowSet) { 15587 return NULL; 15588 } 15589 15590 // convert psMetadata rows to row objects 15591 15592 returnSet = psArrayAllocEmpty(rowSet->n); 15593 15594 for (i = 0; i < rowSet->n; i++) { 15595 p4bDiffScfileRow *object = p4bDiffScfileObjectFromMetadata(rowSet->data[i]); 15596 psArrayAdd(returnSet, 0, object); 15597 psFree(object); 15598 } 15599 15600 psFree(rowSet); 15601 15602 return returnSet; 15603 } 15604 bool p4bDiffScfileDeleteObject(psDB *dbh, const p4bDiffScfileRow *object) 15605 { 15606 psMetadata *where = p4bDiffScfileMetadataFromObject(object); 15607 long long count = psDBDeleteRows(dbh, P4BDIFFSCFILE_TABLE_NAME, where, 0); 15608 psFree(where); 15609 if (count < 0) { 15610 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4bDiffScfile"); 15611 return false; 15612 } 15613 if (count > 1) { 15614 // XXX should this be a psAbort() instead? It is possible that 15615 // having an object match multiple rows was by design. 15616 psError(PS_ERR_UNKNOWN, true, "p4bDiffScfileRow object matched more then one row. Check your database schema"); 15617 return false; 15618 } 15619 15620 return true; 15621 } 15622 long long p4bDiffScfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 15623 { 15624 long long deleted = 0; 15625 15626 for (long long i = 0; i < objects->n; i++) { 15627 p4bDiffScfileRow *object = objects->data[i]; 15628 psMetadata *where = p4bDiffScfileMetadataFromObject(object); 15629 long long count = psDBDeleteRows(dbh, P4BDIFFSCFILE_TABLE_NAME, where, limit); 15630 psFree(where); 15631 if (count < 0) { 15632 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4bDiffScfile"); 15633 return count; 15634 } 15635 15636 deleted += count; 15637 } 15638 15639 return deleted; 15640 } 15641 bool p4bDiffScfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 15642 { 15643 PS_ASSERT_PTR_NON_NULL(objects, false); 15644 15645 psMetadata *output = psMetadataAlloc(); 15646 for (long i = 0; i < psArrayLength(objects); i++) { 15647 psMetadata *md = p4bDiffScfileMetadataFromObject(objects->data[i]); 15648 if (!psMetadataAddMetadata( 15649 output, 15650 PS_LIST_TAIL, 15651 P4BDIFFSCFILE_TABLE_NAME, 15652 PS_META_DUPLICATE_OK, 15653 NULL, 15654 md 15655 )) { 15656 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 15657 psFree(md); 15658 psFree(output); 15659 return false; 15660 } 15661 psFree(md); 15662 } 15663 15664 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 15665 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 15666 psFree(output); 15667 } 15668 psFree(output); 15669 15670 return true; 15671 } 15672 bool p4bDiffScfilePrintObject(FILE *stream, p4bDiffScfileRow *object, bool mdcf) 15673 { 15674 PS_ASSERT_PTR_NON_NULL(object, false); 15675 15676 psMetadata *md = p4bDiffScfileMetadataFromObject(object); 15677 15678 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 15679 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 15680 psFree(md); 15681 } 15682 15683 psFree(md); 15684 15685 return true; 15686 } 15687 static void p4cRunRowFree(p4cRunRow *object); 15688 15689 p4cRunRow *p4cRunRowAlloc(psS32 p4c_id, const char *state, const char *workdir, bool magic) 15690 { 15691 p4cRunRow *_object; 15692 15693 _object = psAlloc(sizeof(p4cRunRow)); 15694 psMemSetDeallocator(_object, (psFreeFunc)p4cRunRowFree); 15695 15696 _object->p4c_id = p4c_id; 15697 _object->state = psStringCopy(state); 15698 _object->workdir = psStringCopy(workdir); 15699 _object->magic = magic; 15700 15701 return _object; 15702 } 15703 15704 static void p4cRunRowFree(p4cRunRow *object) 15705 { 15706 psFree(object->state); 15707 psFree(object->workdir); 15708 } 15709 15710 bool p4cRunCreateTable(psDB *dbh) 15711 { 15712 psMetadata *md = psMetadataAlloc(); 15713 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4c_id", PS_DATA_S32, "Primary Key AUTO_INCREMENT", 0)) { 15714 psError(PS_ERR_UNKNOWN, false, "failed to add item p4c_id"); 15715 psFree(md); 15716 return false; 15717 } 15718 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, "Key", "64")) { 15719 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 15720 psFree(md); 15721 return false; 15722 } 15723 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, "255")) { 15724 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 15725 psFree(md); 15726 return false; 15727 } 15728 if (!psMetadataAdd(md, PS_LIST_TAIL, "magic", PS_DATA_BOOL, "Primary Key", 0)) { 15729 psError(PS_ERR_UNKNOWN, false, "failed to add item magic"); 15730 psFree(md); 15731 return false; 15732 } 15733 15734 bool status = psDBCreateTable(dbh, P4CRUN_TABLE_NAME, md); 15735 15736 psFree(md); 15737 15738 return status; 15739 } 15740 15741 bool p4cRunDropTable(psDB *dbh) 15742 { 15743 return psDBDropTable(dbh, P4CRUN_TABLE_NAME); 15744 } 15745 15746 bool p4cRunInsert(psDB * dbh, psS32 p4c_id, const char *state, const char *workdir, bool magic) 15747 { 15748 psMetadata *md = psMetadataAlloc(); 15749 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4c_id", PS_DATA_S32, NULL, p4c_id)) { 15750 psError(PS_ERR_UNKNOWN, false, "failed to add item p4c_id"); 15751 psFree(md); 15752 return false; 15753 } 15754 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) { 15755 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 15756 psFree(md); 15757 return false; 15758 } 15759 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, workdir)) { 15760 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 15761 psFree(md); 15762 return false; 15763 } 15764 if (!psMetadataAdd(md, PS_LIST_TAIL, "magic", PS_DATA_BOOL, NULL, magic)) { 15765 psError(PS_ERR_UNKNOWN, false, "failed to add item magic"); 15766 psFree(md); 15767 return false; 15768 } 15769 15770 bool status = psDBInsertOneRow(dbh, P4CRUN_TABLE_NAME, md); 15771 psFree(md); 15772 15773 return status; 15774 } 15775 15776 long long p4cRunDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 15777 { 15778 long long deleted = 0; 15779 15780 long long count = psDBDeleteRows(dbh, P4CRUN_TABLE_NAME, where, limit); 15781 if (count < 0) { 15782 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4cRun"); 15783 return count; 15784 15785 deleted += count; 15786 } 15787 15788 return deleted; 15789 } 15790 bool p4cRunInsertObject(psDB *dbh, p4cRunRow *object) 15791 { 15792 return p4cRunInsert(dbh, object->p4c_id, object->state, object->workdir, object->magic); 15793 } 15794 15795 bool p4cRunInsertObjects(psDB *dbh, psArray *objects) 15796 { 15797 for (long i = 0; i < psArrayLength(objects); i++) { 15798 if (!p4cRunInsertObject(dbh, objects->data[i])) { 15799 return false; 15800 } 15801 } 15802 15803 return true; 15804 } 15805 15806 bool p4cRunInsertFits(psDB *dbh, const psFits *fits) 15807 { 15808 psArray *rowSet; 15809 15810 // move to (the first?) extension named P4CRUN_TABLE_NAME 15811 if (!psFitsMoveExtName(fits, P4CRUN_TABLE_NAME)) { 15812 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4CRUN_TABLE_NAME); 15813 return false; 15814 } 15815 15816 // check HDU type 15817 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 15818 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 15819 return false; 15820 } 15821 15822 // read fits table 15823 rowSet = psFitsReadTable(fits); 15824 if (!rowSet) { 15825 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 15826 psFree(rowSet); 15827 return false; 15828 } 15829 15830 if (!psDBInsertRows(dbh, P4CRUN_TABLE_NAME, rowSet)) { 15831 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 15832 psFree(rowSet); 15833 return false; 15834 } 15835 15836 psFree(rowSet); 15837 15838 return true; 15839 } 15840 15841 bool p4cRunSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 15842 { 15843 psArray *rowSet; 15844 15845 rowSet = psDBSelectRows(dbh, P4CRUN_TABLE_NAME, where, limit); 15846 if (!rowSet) { 15847 return false; 15848 } 15849 15850 // output to fits 15851 if (!psFitsWriteTable(fits, NULL, rowSet, P4CRUN_TABLE_NAME)) { 15852 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 15853 psFree(rowSet); 15854 return false; 15855 } 15856 15857 psFree(rowSet); 15858 15859 return true; 15860 } 15861 15862 psMetadata *p4cRunMetadataFromObject(const p4cRunRow *object) 15863 { 15864 psMetadata *md = psMetadataAlloc(); 15865 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4c_id", PS_DATA_S32, NULL, object->p4c_id)) { 15866 psError(PS_ERR_UNKNOWN, false, "failed to add item p4c_id"); 15867 psFree(md); 15868 return false; 15869 } 15870 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) { 15871 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 15872 psFree(md); 15873 return false; 15874 } 15875 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, object->workdir)) { 15876 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 15877 psFree(md); 15878 return false; 15879 } 15880 if (!psMetadataAdd(md, PS_LIST_TAIL, "magic", PS_DATA_BOOL, NULL, object->magic)) { 15881 psError(PS_ERR_UNKNOWN, false, "failed to add item magic"); 15882 psFree(md); 15883 return false; 15884 } 15885 15886 15887 return md; 15888 } 15889 15890 p4cRunRow *p4cRunObjectFromMetadata(psMetadata *md) 15891 { 15892 15893 bool status = false; 15894 psS32 p4c_id = psMetadataLookupS32(&status, md, "p4c_id"); 15895 if (!status) { 15896 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4c_id"); 15897 return false; 15898 } 15899 char* state = psMetadataLookupPtr(&status, md, "state"); 15900 if (!status) { 15901 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item state"); 15902 return false; 15903 } 15904 char* workdir = psMetadataLookupPtr(&status, md, "workdir"); 15905 if (!status) { 15906 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item workdir"); 15907 return false; 15908 } 15909 bool magic = psMetadataLookupBool(&status, md, "magic"); 15910 if (!status) { 15911 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item magic"); 15912 return false; 15913 } 15914 15915 return p4cRunRowAlloc(p4c_id, state, workdir, magic); 15916 } 15917 psArray *p4cRunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 15918 { 15919 psArray *rowSet; 15920 psArray *returnSet; 15921 psU64 i; 15922 15923 rowSet = psDBSelectRows(dbh, P4CRUN_TABLE_NAME, where, limit); 15924 if (!rowSet) { 15925 return NULL; 15926 } 15927 15928 // convert psMetadata rows to row objects 15929 15930 returnSet = psArrayAllocEmpty(rowSet->n); 15931 15932 for (i = 0; i < rowSet->n; i++) { 15933 p4cRunRow *object = p4cRunObjectFromMetadata(rowSet->data[i]); 15934 psArrayAdd(returnSet, 0, object); 15935 psFree(object); 15936 } 15937 15938 psFree(rowSet); 15939 15940 return returnSet; 15941 } 15942 bool p4cRunDeleteObject(psDB *dbh, const p4cRunRow *object) 15943 { 15944 psMetadata *where = p4cRunMetadataFromObject(object); 15945 long long count = psDBDeleteRows(dbh, P4CRUN_TABLE_NAME, where, 0); 15946 psFree(where); 15947 if (count < 0) { 15948 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4cRun"); 15949 return false; 15950 } 15951 if (count > 1) { 15952 // XXX should this be a psAbort() instead? It is possible that 15953 // having an object match multiple rows was by design. 15954 psError(PS_ERR_UNKNOWN, true, "p4cRunRow object matched more then one row. Check your database schema"); 15955 return false; 15956 } 15957 15958 return true; 15959 } 15960 long long p4cRunDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 15961 { 15962 long long deleted = 0; 15963 15964 for (long long i = 0; i < objects->n; i++) { 15965 p4cRunRow *object = objects->data[i]; 15966 psMetadata *where = p4cRunMetadataFromObject(object); 15967 long long count = psDBDeleteRows(dbh, P4CRUN_TABLE_NAME, where, limit); 15968 psFree(where); 15969 if (count < 0) { 15970 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4cRun"); 15971 return count; 15972 } 15973 15974 deleted += count; 15975 } 15976 15977 return deleted; 15978 } 15979 bool p4cRunPrintObjects(FILE *stream, psArray *objects, bool mdcf) 15980 { 15981 PS_ASSERT_PTR_NON_NULL(objects, false); 15982 15983 psMetadata *output = psMetadataAlloc(); 15984 for (long i = 0; i < psArrayLength(objects); i++) { 15985 psMetadata *md = p4cRunMetadataFromObject(objects->data[i]); 15986 if (!psMetadataAddMetadata( 15987 output, 15988 PS_LIST_TAIL, 15989 P4CRUN_TABLE_NAME, 15990 PS_META_DUPLICATE_OK, 15991 NULL, 15992 md 15993 )) { 15994 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 15995 psFree(md); 15996 psFree(output); 15997 return false; 15998 } 15999 psFree(md); 16000 } 16001 16002 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 16003 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 16004 psFree(output); 16005 } 16006 psFree(output); 16007 16008 return true; 16009 } 16010 bool p4cRunPrintObject(FILE *stream, p4cRunRow *object, bool mdcf) 16011 { 16012 PS_ASSERT_PTR_NON_NULL(object, false); 16013 16014 psMetadata *md = p4cRunMetadataFromObject(object); 16015 16016 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 16017 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 16018 psFree(md); 16019 } 16020 16021 psFree(md); 16022 16023 return true; 16024 } 16025 static void p4cInputExpRowFree(p4cInputExpRow *object); 16026 16027 p4cInputExpRow *p4cInputExpRowAlloc(psS32 p4c_id, const char *exp_tag, psS32 p3_version) 16028 { 16029 p4cInputExpRow *_object; 16030 16031 _object = psAlloc(sizeof(p4cInputExpRow)); 16032 psMemSetDeallocator(_object, (psFreeFunc)p4cInputExpRowFree); 16033 16034 _object->p4c_id = p4c_id; 16035 _object->exp_tag = psStringCopy(exp_tag); 16036 _object->p3_version = p3_version; 16037 16038 return _object; 16039 } 16040 16041 static void p4cInputExpRowFree(p4cInputExpRow *object) 16042 { 16043 psFree(object->exp_tag); 16044 } 16045 16046 bool p4cInputExpCreateTable(psDB *dbh) 16047 { 16048 psMetadata *md = psMetadataAlloc(); 16049 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4c_id", PS_DATA_S32, "Primary Key", 0)) { 16050 psError(PS_ERR_UNKNOWN, false, "failed to add item p4c_id"); 16051 psFree(md); 16052 return false; 16053 } 16054 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Primary Key", "64")) { 16055 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 16056 psFree(md); 16057 return false; 16058 } 16059 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Primary Key", 0)) { 16060 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 16061 psFree(md); 16062 return false; 16063 } 16064 16065 bool status = psDBCreateTable(dbh, P4CINPUTEXP_TABLE_NAME, md); 16066 16067 psFree(md); 16068 16069 return status; 16070 } 16071 16072 bool p4cInputExpDropTable(psDB *dbh) 16073 { 16074 return psDBDropTable(dbh, P4CINPUTEXP_TABLE_NAME); 16075 } 16076 16077 bool p4cInputExpInsert(psDB * dbh, psS32 p4c_id, const char *exp_tag, psS32 p3_version) 16078 { 16079 psMetadata *md = psMetadataAlloc(); 16080 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4c_id", PS_DATA_S32, NULL, p4c_id)) { 16081 psError(PS_ERR_UNKNOWN, false, "failed to add item p4c_id"); 16082 psFree(md); 16083 return false; 16084 } 16085 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) { 16086 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 16087 psFree(md); 16088 return false; 16089 } 16090 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) { 16091 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 16092 psFree(md); 16093 return false; 16094 } 16095 16096 bool status = psDBInsertOneRow(dbh, P4CINPUTEXP_TABLE_NAME, md); 16097 psFree(md); 16098 16099 return status; 16100 } 16101 16102 long long p4cInputExpDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 16103 { 16104 long long deleted = 0; 16105 16106 long long count = psDBDeleteRows(dbh, P4CINPUTEXP_TABLE_NAME, where, limit); 16107 if (count < 0) { 16108 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4cInputExp"); 16109 return count; 16110 16111 deleted += count; 16112 } 16113 16114 return deleted; 16115 } 16116 bool p4cInputExpInsertObject(psDB *dbh, p4cInputExpRow *object) 16117 { 16118 return p4cInputExpInsert(dbh, object->p4c_id, object->exp_tag, object->p3_version); 16119 } 16120 16121 bool p4cInputExpInsertObjects(psDB *dbh, psArray *objects) 16122 { 16123 for (long i = 0; i < psArrayLength(objects); i++) { 16124 if (!p4cInputExpInsertObject(dbh, objects->data[i])) { 16125 return false; 16126 } 16127 } 16128 16129 return true; 16130 } 16131 16132 bool p4cInputExpInsertFits(psDB *dbh, const psFits *fits) 16133 { 16134 psArray *rowSet; 16135 16136 // move to (the first?) extension named P4CINPUTEXP_TABLE_NAME 16137 if (!psFitsMoveExtName(fits, P4CINPUTEXP_TABLE_NAME)) { 16138 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4CINPUTEXP_TABLE_NAME); 16139 return false; 16140 } 16141 16142 // check HDU type 16143 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 16144 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 16145 return false; 16146 } 16147 16148 // read fits table 16149 rowSet = psFitsReadTable(fits); 16150 if (!rowSet) { 16151 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 16152 psFree(rowSet); 16153 return false; 16154 } 16155 16156 if (!psDBInsertRows(dbh, P4CINPUTEXP_TABLE_NAME, rowSet)) { 16157 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 16158 psFree(rowSet); 16159 return false; 16160 } 16161 16162 psFree(rowSet); 16163 16164 return true; 16165 } 16166 16167 bool p4cInputExpSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 16168 { 16169 psArray *rowSet; 16170 16171 rowSet = psDBSelectRows(dbh, P4CINPUTEXP_TABLE_NAME, where, limit); 16172 if (!rowSet) { 16173 return false; 16174 } 16175 16176 // output to fits 16177 if (!psFitsWriteTable(fits, NULL, rowSet, P4CINPUTEXP_TABLE_NAME)) { 16178 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 16179 psFree(rowSet); 16180 return false; 16181 } 16182 16183 psFree(rowSet); 16184 16185 return true; 16186 } 16187 16188 psMetadata *p4cInputExpMetadataFromObject(const p4cInputExpRow *object) 16189 { 16190 psMetadata *md = psMetadataAlloc(); 16191 if (!psMetadataAdd(md, PS_LIST_TAIL, "p4c_id", PS_DATA_S32, NULL, object->p4c_id)) { 16192 psError(PS_ERR_UNKNOWN, false, "failed to add item p4c_id"); 16193 psFree(md); 16194 return false; 16195 } 16196 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) { 16197 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 16198 psFree(md); 16199 return false; 16200 } 16201 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) { 16202 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 16203 psFree(md); 16204 return false; 16205 } 16206 16207 16208 return md; 16209 } 16210 16211 p4cInputExpRow *p4cInputExpObjectFromMetadata(psMetadata *md) 16212 { 16213 16214 bool status = false; 16215 psS32 p4c_id = psMetadataLookupS32(&status, md, "p4c_id"); 16216 if (!status) { 16217 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p4c_id"); 16218 return false; 16219 } 16220 char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag"); 16221 if (!status) { 16222 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag"); 16223 return false; 16224 } 16225 psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version"); 16226 if (!status) { 16227 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version"); 16228 return false; 16229 } 16230 16231 return p4cInputExpRowAlloc(p4c_id, exp_tag, p3_version); 16232 } 16233 psArray *p4cInputExpSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 16234 { 16235 psArray *rowSet; 16236 psArray *returnSet; 16237 psU64 i; 16238 16239 rowSet = psDBSelectRows(dbh, P4CINPUTEXP_TABLE_NAME, where, limit); 16240 if (!rowSet) { 16241 return NULL; 16242 } 16243 16244 // convert psMetadata rows to row objects 16245 16246 returnSet = psArrayAllocEmpty(rowSet->n); 16247 16248 for (i = 0; i < rowSet->n; i++) { 16249 p4cInputExpRow *object = p4cInputExpObjectFromMetadata(rowSet->data[i]); 16250 psArrayAdd(returnSet, 0, object); 16251 psFree(object); 16252 } 16253 16254 psFree(rowSet); 16255 16256 return returnSet; 16257 } 16258 bool p4cInputExpDeleteObject(psDB *dbh, const p4cInputExpRow *object) 16259 { 16260 psMetadata *where = p4cInputExpMetadataFromObject(object); 16261 long long count = psDBDeleteRows(dbh, P4CINPUTEXP_TABLE_NAME, where, 0); 16262 psFree(where); 16263 if (count < 0) { 16264 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4cInputExp"); 16265 return false; 16266 } 16267 if (count > 1) { 16268 // XXX should this be a psAbort() instead? It is possible that 16269 // having an object match multiple rows was by design. 16270 psError(PS_ERR_UNKNOWN, true, "p4cInputExpRow object matched more then one row. Check your database schema"); 16271 return false; 16272 } 16273 16274 return true; 16275 } 16276 long long p4cInputExpDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 16277 { 16278 long long deleted = 0; 16279 16280 for (long long i = 0; i < objects->n; i++) { 16281 p4cInputExpRow *object = objects->data[i]; 16282 psMetadata *where = p4cInputExpMetadataFromObject(object); 16283 long long count = psDBDeleteRows(dbh, P4CINPUTEXP_TABLE_NAME, where, limit); 16284 psFree(where); 16285 if (count < 0) { 16286 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4cInputExp"); 16287 return count; 16288 } 16289 16290 deleted += count; 16291 } 16292 16293 return deleted; 16294 } 16295 bool p4cInputExpPrintObjects(FILE *stream, psArray *objects, bool mdcf) 16296 { 16297 PS_ASSERT_PTR_NON_NULL(objects, false); 16298 16299 psMetadata *output = psMetadataAlloc(); 16300 for (long i = 0; i < psArrayLength(objects); i++) { 16301 psMetadata *md = p4cInputExpMetadataFromObject(objects->data[i]); 16302 if (!psMetadataAddMetadata( 16303 output, 16304 PS_LIST_TAIL, 16305 P4CINPUTEXP_TABLE_NAME, 16306 PS_META_DUPLICATE_OK, 16307 NULL, 16308 md 16309 )) { 16310 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 16311 psFree(md); 16312 psFree(output); 16313 return false; 16314 } 16315 psFree(md); 16316 } 16317 16318 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 16319 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 16320 psFree(output); 16321 } 16322 psFree(output); 16323 16324 return true; 16325 } 16326 bool p4cInputExpPrintObject(FILE *stream, p4cInputExpRow *object, bool mdcf) 16327 { 16328 PS_ASSERT_PTR_NON_NULL(object, false); 16329 16330 psMetadata *md = p4cInputExpMetadataFromObject(object); 15379 psMetadata *md = p4DiffScfileMetadataFromObject(object); 16331 15380 16332 15381 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { -
trunk/ippdb/src/ippdb.h
r11679 r11720 20 20 /* 21 21 * 22 * This file was generated by glueforge 0.3622 * This file was generated by glueforge 1.00 23 23 * 24 24 * Do NOT directly edit this file. … … 6830 6830 bool mdcf ///< format as mdconfig or simple 6831 6831 ); 6832 /** p4 aRunRow data structure6833 * 6834 * Structure for representing a single row of p4 aRun table data.6832 /** p4RunRow data structure 6833 * 6834 * Structure for representing a single row of p4Run table data. 6835 6835 */ 6836 6836 6837 6837 typedef struct { 6838 6838 psS32 p4a_id; 6839 char *mode; 6839 6840 char *state; 6840 6841 char *workdir; 6841 bool magic;6842 } p4 aRunRow;6843 6844 /** Creates a new p4 aRunRow object6845 * 6846 * @return A new p4 aRunRow object or NULL on failure.6847 */ 6848 6849 p4 aRunRow *p4aRunRowAlloc(6842 psTime* registered; 6843 } p4RunRow; 6844 6845 /** Creates a new p4RunRow object 6846 * 6847 * @return A new p4RunRow object or NULL on failure. 6848 */ 6849 6850 p4RunRow *p4RunRowAlloc( 6850 6851 psS32 p4a_id, 6852 const char *mode, 6851 6853 const char *state, 6852 6854 const char *workdir, 6853 bool magic6854 ); 6855 6856 /** Creates a new p4 aRun table6857 * 6858 * @return true on success 6859 */ 6860 6861 bool p4 aRunCreateTable(6855 psTime* registered 6856 ); 6857 6858 /** Creates a new p4Run table 6859 * 6860 * @return true on success 6861 */ 6862 6863 bool p4RunCreateTable( 6862 6864 psDB *dbh ///< Database handle 6863 6865 ); 6864 6866 6865 /** Deletes a p4 aRun table6866 * 6867 * @return true on success 6868 */ 6869 6870 bool p4 aRunDropTable(6867 /** Deletes a p4Run table 6868 * 6869 * @return true on success 6870 */ 6871 6872 bool p4RunDropTable( 6871 6873 psDB *dbh ///< Database handle 6872 6874 ); … … 6879 6881 */ 6880 6882 6881 bool p4 aRunInsert(6883 bool p4RunInsert( 6882 6884 psDB *dbh, ///< Database handle 6883 6885 psS32 p4a_id, 6886 const char *mode, 6884 6887 const char *state, 6885 6888 const char *workdir, 6886 bool magic6889 psTime* registered 6887 6890 ); 6888 6891 … … 6892 6895 */ 6893 6896 6894 long long p4 aRunDelete(6897 long long p4RunDelete( 6895 6898 psDB *dbh, ///< Database handle 6896 6899 const psMetadata *where, ///< Row match criteria … … 6898 6901 ); 6899 6902 6900 /** Insert a single p4 aRunRow object into a table6903 /** Insert a single p4RunRow object into a table 6901 6904 * 6902 6905 * This function constructs and inserts a single row based on it's parameters. … … 6905 6908 */ 6906 6909 6907 bool p4 aRunInsertObject(6908 psDB *dbh, ///< Database handle 6909 p4 aRunRow *object ///< p4aRunRow object6910 ); 6911 6912 /** Insert an array of p4 aRunRow object into a table6910 bool p4RunInsertObject( 6911 psDB *dbh, ///< Database handle 6912 p4RunRow *object ///< p4RunRow object 6913 ); 6914 6915 /** Insert an array of p4RunRow object into a table 6913 6916 * 6914 6917 * This function constructs and inserts multiple rows based on it's parameters. … … 6917 6920 */ 6918 6921 6919 bool p4 aRunInsertObjects(6920 psDB *dbh, ///< Database handle 6921 psArray *objects ///< array of p4 aRunRow objects6922 ); 6923 6924 /** Insert data from a binary FITS table p4 aRunRow into the database6922 bool p4RunInsertObjects( 6923 psDB *dbh, ///< Database handle 6924 psArray *objects ///< array of p4RunRow objects 6925 ); 6926 6927 /** Insert data from a binary FITS table p4RunRow into the database 6925 6928 * 6926 6929 * This function expects a psFits object with a FITS table as the first … … 6932 6935 */ 6933 6936 6934 bool p4 aRunInsertFits(6937 bool p4RunInsertFits( 6935 6938 psDB *dbh, ///< Database handle 6936 6939 const psFits *fits ///< psFits object … … 6947 6950 */ 6948 6951 6949 bool p4 aRunSelectRowsFits(6952 bool p4RunSelectRowsFits( 6950 6953 psDB *dbh, ///< Database handle 6951 6954 psFits *fits, ///< psFits object … … 6954 6957 ); 6955 6958 6956 /** Convert a p4 aRunRow into an equivalent psMetadata6959 /** Convert a p4RunRow into an equivalent psMetadata 6957 6960 * 6958 6961 * @return A psMetadata pointer or NULL on error 6959 6962 */ 6960 6963 6961 psMetadata *p4 aRunMetadataFromObject(6962 const p4 aRunRow*object ///< fooRow to convert into a psMetadata6964 psMetadata *p4RunMetadataFromObject( 6965 const p4RunRow *object ///< fooRow to convert into a psMetadata 6963 6966 ); 6964 6967 6965 6968 /** Convert a psMetadata into an equivalent fooRow 6966 6969 * 6967 * @return A p4 aRunRow pointer or NULL on error6968 */ 6969 6970 p4 aRunRow *p4aRunObjectFromMetadata(6970 * @return A p4RunRow pointer or NULL on error 6971 */ 6972 6973 p4RunRow *p4RunObjectFromMetadata( 6971 6974 psMetadata *md ///< psMetadata to convert into a fooRow 6972 6975 ); 6973 /** Selects up to limit rows from the database and returns as p4 aRunRow objects in a psArray6976 /** Selects up to limit rows from the database and returns as p4RunRow objects in a psArray 6974 6977 * 6975 6978 * See psDBSelectRows() for documentation on the format of where. … … 6978 6981 */ 6979 6982 6980 psArray *p4 aRunSelectRowObjects(6983 psArray *p4RunSelectRowObjects( 6981 6984 psDB *dbh, ///< Database handle 6982 6985 const psMetadata *where, ///< Row match criteria 6983 6986 unsigned long long limit ///< Maximum number of elements to return 6984 6987 ); 6985 /** Deletes a row from the database coresponding to an p4 aRun6988 /** Deletes a row from the database coresponding to an p4Run 6986 6989 * 6987 6990 * Note that a 'where' search psMetadata is constructed from each object and … … 6991 6994 */ 6992 6995 6993 bool p4 aRunDeleteObject(6994 psDB *dbh, ///< Database handle 6995 const p4 aRunRow *object ///< Object to delete6996 bool p4RunDeleteObject( 6997 psDB *dbh, ///< Database handle 6998 const p4RunRow *object ///< Object to delete 6996 6999 ); 6997 7000 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. … … 7003 7006 */ 7004 7007 7005 long long p4 aRunDeleteRowObjects(7008 long long p4RunDeleteRowObjects( 7006 7009 psDB *dbh, ///< Database handle 7007 7010 const psArray *objects, ///< Array of objects to delete 7008 7011 unsigned long long limit ///< Maximum number of elements to delete 7009 7012 ); 7010 /** Formats and prints an array of p4 aRunRow objects7013 /** Formats and prints an array of p4RunRow objects 7011 7014 * 7012 7015 * When mdcf is set the formated output is in psMetadataConfig … … 7016 7019 */ 7017 7020 7018 bool p4 aRunPrintObjects(7021 bool p4RunPrintObjects( 7019 7022 FILE *stream, ///< a stream 7020 psArray *objects, ///< An array of p4 aRunRow objects7023 psArray *objects, ///< An array of p4RunRow objects 7021 7024 bool mdcf ///< format as mdconfig or simple 7022 7025 ); 7023 /** Formats and prints an p4 aRunRow object7026 /** Formats and prints an p4RunRow object 7024 7027 * 7025 7028 * When mdcf is set the formated output is in psMetadataConfig … … 7029 7032 */ 7030 7033 7031 bool p4 aRunPrintObject(7034 bool p4RunPrintObject( 7032 7035 FILE *stream, ///< a stream 7033 p4 aRunRow *object, ///< an p4aRunRow object7036 p4RunRow *object, ///< an p4RunRow object 7034 7037 bool mdcf ///< format as mdconfig or simple 7035 7038 ); 7036 /** p4 aInputExpRow data structure7037 * 7038 * Structure for representing a single row of p4 aInputExp table data.7039 /** p4InputExpRow data structure 7040 * 7041 * Structure for representing a single row of p4InputExp table data. 7039 7042 */ 7040 7043 … … 7043 7046 char *exp_tag; 7044 7047 psS32 p3_version; 7045 } p4aInputExpRow; 7046 7047 /** Creates a new p4aInputExpRow object 7048 * 7049 * @return A new p4aInputExpRow object or NULL on failure. 7050 */ 7051 7052 p4aInputExpRow *p4aInputExpRowAlloc( 7048 bool magiced; 7049 } p4InputExpRow; 7050 7051 /** Creates a new p4InputExpRow object 7052 * 7053 * @return A new p4InputExpRow object or NULL on failure. 7054 */ 7055 7056 p4InputExpRow *p4InputExpRowAlloc( 7053 7057 psS32 p4a_id, 7054 7058 const char *exp_tag, 7055 psS32 p3_version 7056 ); 7057 7058 /** Creates a new p4aInputExp table 7059 * 7060 * @return true on success 7061 */ 7062 7063 bool p4aInputExpCreateTable( 7059 psS32 p3_version, 7060 bool magiced 7061 ); 7062 7063 /** Creates a new p4InputExp table 7064 * 7065 * @return true on success 7066 */ 7067 7068 bool p4InputExpCreateTable( 7064 7069 psDB *dbh ///< Database handle 7065 7070 ); 7066 7071 7067 /** Deletes a p4 aInputExp table7068 * 7069 * @return true on success 7070 */ 7071 7072 bool p4 aInputExpDropTable(7072 /** Deletes a p4InputExp table 7073 * 7074 * @return true on success 7075 */ 7076 7077 bool p4InputExpDropTable( 7073 7078 psDB *dbh ///< Database handle 7074 7079 ); … … 7081 7086 */ 7082 7087 7083 bool p4 aInputExpInsert(7088 bool p4InputExpInsert( 7084 7089 psDB *dbh, ///< Database handle 7085 7090 psS32 p4a_id, 7086 7091 const char *exp_tag, 7087 psS32 p3_version 7092 psS32 p3_version, 7093 bool magiced 7088 7094 ); 7089 7095 … … 7093 7099 */ 7094 7100 7095 long long p4 aInputExpDelete(7101 long long p4InputExpDelete( 7096 7102 psDB *dbh, ///< Database handle 7097 7103 const psMetadata *where, ///< Row match criteria … … 7099 7105 ); 7100 7106 7101 /** Insert a single p4 aInputExpRow object into a table7107 /** Insert a single p4InputExpRow object into a table 7102 7108 * 7103 7109 * This function constructs and inserts a single row based on it's parameters. … … 7106 7112 */ 7107 7113 7108 bool p4 aInputExpInsertObject(7109 psDB *dbh, ///< Database handle 7110 p4 aInputExpRow *object ///< p4aInputExpRow object7111 ); 7112 7113 /** Insert an array of p4 aInputExpRow object into a table7114 bool p4InputExpInsertObject( 7115 psDB *dbh, ///< Database handle 7116 p4InputExpRow *object ///< p4InputExpRow object 7117 ); 7118 7119 /** Insert an array of p4InputExpRow object into a table 7114 7120 * 7115 7121 * This function constructs and inserts multiple rows based on it's parameters. … … 7118 7124 */ 7119 7125 7120 bool p4 aInputExpInsertObjects(7121 psDB *dbh, ///< Database handle 7122 psArray *objects ///< array of p4 aInputExpRow objects7123 ); 7124 7125 /** Insert data from a binary FITS table p4 aInputExpRow into the database7126 bool p4InputExpInsertObjects( 7127 psDB *dbh, ///< Database handle 7128 psArray *objects ///< array of p4InputExpRow objects 7129 ); 7130 7131 /** Insert data from a binary FITS table p4InputExpRow into the database 7126 7132 * 7127 7133 * This function expects a psFits object with a FITS table as the first … … 7133 7139 */ 7134 7140 7135 bool p4 aInputExpInsertFits(7141 bool p4InputExpInsertFits( 7136 7142 psDB *dbh, ///< Database handle 7137 7143 const psFits *fits ///< psFits object … … 7148 7154 */ 7149 7155 7150 bool p4 aInputExpSelectRowsFits(7156 bool p4InputExpSelectRowsFits( 7151 7157 psDB *dbh, ///< Database handle 7152 7158 psFits *fits, ///< psFits object … … 7155 7161 ); 7156 7162 7157 /** Convert a p4 aInputExpRow into an equivalent psMetadata7163 /** Convert a p4InputExpRow into an equivalent psMetadata 7158 7164 * 7159 7165 * @return A psMetadata pointer or NULL on error 7160 7166 */ 7161 7167 7162 psMetadata *p4 aInputExpMetadataFromObject(7163 const p4 aInputExpRow *object ///< fooRow to convert into a psMetadata7168 psMetadata *p4InputExpMetadataFromObject( 7169 const p4InputExpRow *object ///< fooRow to convert into a psMetadata 7164 7170 ); 7165 7171 7166 7172 /** Convert a psMetadata into an equivalent fooRow 7167 7173 * 7168 * @return A p4 aInputExpRow pointer or NULL on error7169 */ 7170 7171 p4 aInputExpRow *p4aInputExpObjectFromMetadata(7174 * @return A p4InputExpRow pointer or NULL on error 7175 */ 7176 7177 p4InputExpRow *p4InputExpObjectFromMetadata( 7172 7178 psMetadata *md ///< psMetadata to convert into a fooRow 7173 7179 ); 7174 /** Selects up to limit rows from the database and returns as p4 aInputExpRow objects in a psArray7180 /** Selects up to limit rows from the database and returns as p4InputExpRow objects in a psArray 7175 7181 * 7176 7182 * See psDBSelectRows() for documentation on the format of where. … … 7179 7185 */ 7180 7186 7181 psArray *p4 aInputExpSelectRowObjects(7187 psArray *p4InputExpSelectRowObjects( 7182 7188 psDB *dbh, ///< Database handle 7183 7189 const psMetadata *where, ///< Row match criteria 7184 7190 unsigned long long limit ///< Maximum number of elements to return 7185 7191 ); 7186 /** Deletes a row from the database coresponding to an p4 aInputExp7192 /** Deletes a row from the database coresponding to an p4InputExp 7187 7193 * 7188 7194 * Note that a 'where' search psMetadata is constructed from each object and … … 7192 7198 */ 7193 7199 7194 bool p4 aInputExpDeleteObject(7195 psDB *dbh, ///< Database handle 7196 const p4 aInputExpRow *object ///< Object to delete7200 bool p4InputExpDeleteObject( 7201 psDB *dbh, ///< Database handle 7202 const p4InputExpRow *object ///< Object to delete 7197 7203 ); 7198 7204 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. … … 7204 7210 */ 7205 7211 7206 long long p4 aInputExpDeleteRowObjects(7212 long long p4InputExpDeleteRowObjects( 7207 7213 psDB *dbh, ///< Database handle 7208 7214 const psArray *objects, ///< Array of objects to delete 7209 7215 unsigned long long limit ///< Maximum number of elements to delete 7210 7216 ); 7211 /** Formats and prints an array of p4 aInputExpRow objects7217 /** Formats and prints an array of p4InputExpRow objects 7212 7218 * 7213 7219 * When mdcf is set the formated output is in psMetadataConfig … … 7217 7223 */ 7218 7224 7219 bool p4 aInputExpPrintObjects(7225 bool p4InputExpPrintObjects( 7220 7226 FILE *stream, ///< a stream 7221 psArray *objects, ///< An array of p4 aInputExpRow objects7227 psArray *objects, ///< An array of p4InputExpRow objects 7222 7228 bool mdcf ///< format as mdconfig or simple 7223 7229 ); 7224 /** Formats and prints an p4 aInputExpRow object7230 /** Formats and prints an p4InputExpRow object 7225 7231 * 7226 7232 * When mdcf is set the formated output is in psMetadataConfig … … 7230 7236 */ 7231 7237 7232 bool p4 aInputExpPrintObject(7238 bool p4InputExpPrintObject( 7233 7239 FILE *stream, ///< a stream 7234 p4 aInputExpRow *object, ///< an p4aInputExpRow object7240 p4InputExpRow *object, ///< an p4InputExpRow object 7235 7241 bool mdcf ///< format as mdconfig or simple 7236 7242 ); 7237 /** p4 aScfileRow data structure7238 * 7239 * Structure for representing a single row of p4 aScfile table data.7243 /** p4ScfileRow data structure 7244 * 7245 * Structure for representing a single row of p4Scfile table data. 7240 7246 */ 7241 7247 … … 7249 7255 psF64 bg; 7250 7256 psF64 bg_mean_stdev; 7251 } p4 aScfileRow;7252 7253 /** Creates a new p4 aScfileRow object7254 * 7255 * @return A new p4 aScfileRow object or NULL on failure.7256 */ 7257 7258 p4 aScfileRow *p4aScfileRowAlloc(7257 } p4ScfileRow; 7258 7259 /** Creates a new p4ScfileRow object 7260 * 7261 * @return A new p4ScfileRow object or NULL on failure. 7262 */ 7263 7264 p4ScfileRow *p4ScfileRowAlloc( 7259 7265 psS32 p4a_id, 7260 7266 const char *skycell_id, … … 7267 7273 ); 7268 7274 7269 /** Creates a new p4 aScfile table7270 * 7271 * @return true on success 7272 */ 7273 7274 bool p4 aScfileCreateTable(7275 /** Creates a new p4Scfile table 7276 * 7277 * @return true on success 7278 */ 7279 7280 bool p4ScfileCreateTable( 7275 7281 psDB *dbh ///< Database handle 7276 7282 ); 7277 7283 7278 /** Deletes a p4 aScfile table7279 * 7280 * @return true on success 7281 */ 7282 7283 bool p4 aScfileDropTable(7284 /** Deletes a p4Scfile table 7285 * 7286 * @return true on success 7287 */ 7288 7289 bool p4ScfileDropTable( 7284 7290 psDB *dbh ///< Database handle 7285 7291 ); … … 7292 7298 */ 7293 7299 7294 bool p4 aScfileInsert(7300 bool p4ScfileInsert( 7295 7301 psDB *dbh, ///< Database handle 7296 7302 psS32 p4a_id, … … 7309 7315 */ 7310 7316 7311 long long p4 aScfileDelete(7317 long long p4ScfileDelete( 7312 7318 psDB *dbh, ///< Database handle 7313 7319 const psMetadata *where, ///< Row match criteria … … 7315 7321 ); 7316 7322 7317 /** Insert a single p4 aScfileRow object into a table7323 /** Insert a single p4ScfileRow object into a table 7318 7324 * 7319 7325 * This function constructs and inserts a single row based on it's parameters. … … 7322 7328 */ 7323 7329 7324 bool p4 aScfileInsertObject(7325 psDB *dbh, ///< Database handle 7326 p4 aScfileRow *object ///< p4aScfileRow object7327 ); 7328 7329 /** Insert an array of p4 aScfileRow object into a table7330 bool p4ScfileInsertObject( 7331 psDB *dbh, ///< Database handle 7332 p4ScfileRow *object ///< p4ScfileRow object 7333 ); 7334 7335 /** Insert an array of p4ScfileRow object into a table 7330 7336 * 7331 7337 * This function constructs and inserts multiple rows based on it's parameters. … … 7334 7340 */ 7335 7341 7336 bool p4 aScfileInsertObjects(7337 psDB *dbh, ///< Database handle 7338 psArray *objects ///< array of p4 aScfileRow objects7339 ); 7340 7341 /** Insert data from a binary FITS table p4 aScfileRow into the database7342 bool p4ScfileInsertObjects( 7343 psDB *dbh, ///< Database handle 7344 psArray *objects ///< array of p4ScfileRow objects 7345 ); 7346 7347 /** Insert data from a binary FITS table p4ScfileRow into the database 7342 7348 * 7343 7349 * This function expects a psFits object with a FITS table as the first … … 7349 7355 */ 7350 7356 7351 bool p4 aScfileInsertFits(7357 bool p4ScfileInsertFits( 7352 7358 psDB *dbh, ///< Database handle 7353 7359 const psFits *fits ///< psFits object … … 7364 7370 */ 7365 7371 7366 bool p4 aScfileSelectRowsFits(7372 bool p4ScfileSelectRowsFits( 7367 7373 psDB *dbh, ///< Database handle 7368 7374 psFits *fits, ///< psFits object … … 7371 7377 ); 7372 7378 7373 /** Convert a p4 aScfileRow into an equivalent psMetadata7379 /** Convert a p4ScfileRow into an equivalent psMetadata 7374 7380 * 7375 7381 * @return A psMetadata pointer or NULL on error 7376 7382 */ 7377 7383 7378 psMetadata *p4 aScfileMetadataFromObject(7379 const p4 aScfileRow *object ///< fooRow to convert into a psMetadata7384 psMetadata *p4ScfileMetadataFromObject( 7385 const p4ScfileRow *object ///< fooRow to convert into a psMetadata 7380 7386 ); 7381 7387 7382 7388 /** Convert a psMetadata into an equivalent fooRow 7383 7389 * 7384 * @return A p4 aScfileRow pointer or NULL on error7385 */ 7386 7387 p4 aScfileRow *p4aScfileObjectFromMetadata(7390 * @return A p4ScfileRow pointer or NULL on error 7391 */ 7392 7393 p4ScfileRow *p4ScfileObjectFromMetadata( 7388 7394 psMetadata *md ///< psMetadata to convert into a fooRow 7389 7395 ); 7390 /** Selects up to limit rows from the database and returns as p4 aScfileRow objects in a psArray7396 /** Selects up to limit rows from the database and returns as p4ScfileRow objects in a psArray 7391 7397 * 7392 7398 * See psDBSelectRows() for documentation on the format of where. … … 7395 7401 */ 7396 7402 7397 psArray *p4 aScfileSelectRowObjects(7403 psArray *p4ScfileSelectRowObjects( 7398 7404 psDB *dbh, ///< Database handle 7399 7405 const psMetadata *where, ///< Row match criteria 7400 7406 unsigned long long limit ///< Maximum number of elements to return 7401 7407 ); 7402 /** Deletes a row from the database coresponding to an p4 aScfile7408 /** Deletes a row from the database coresponding to an p4Scfile 7403 7409 * 7404 7410 * Note that a 'where' search psMetadata is constructed from each object and … … 7408 7414 */ 7409 7415 7410 bool p4 aScfileDeleteObject(7411 psDB *dbh, ///< Database handle 7412 const p4 aScfileRow *object ///< Object to delete7416 bool p4ScfileDeleteObject( 7417 psDB *dbh, ///< Database handle 7418 const p4ScfileRow *object ///< Object to delete 7413 7419 ); 7414 7420 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. … … 7420 7426 */ 7421 7427 7422 long long p4 aScfileDeleteRowObjects(7428 long long p4ScfileDeleteRowObjects( 7423 7429 psDB *dbh, ///< Database handle 7424 7430 const psArray *objects, ///< Array of objects to delete 7425 7431 unsigned long long limit ///< Maximum number of elements to delete 7426 7432 ); 7427 /** Formats and prints an array of p4 aScfileRow objects7433 /** Formats and prints an array of p4ScfileRow objects 7428 7434 * 7429 7435 * When mdcf is set the formated output is in psMetadataConfig … … 7433 7439 */ 7434 7440 7435 bool p4 aScfilePrintObjects(7441 bool p4ScfilePrintObjects( 7436 7442 FILE *stream, ///< a stream 7437 psArray *objects, ///< An array of p4 aScfileRow objects7443 psArray *objects, ///< An array of p4ScfileRow objects 7438 7444 bool mdcf ///< format as mdconfig or simple 7439 7445 ); 7440 /** Formats and prints an p4 aScfileRow object7446 /** Formats and prints an p4ScfileRow object 7441 7447 * 7442 7448 * When mdcf is set the formated output is in psMetadataConfig … … 7446 7452 */ 7447 7453 7448 bool p4 aScfilePrintObject(7454 bool p4ScfilePrintObject( 7449 7455 FILE *stream, ///< a stream 7450 p4 aScfileRow *object, ///< an p4aScfileRow object7456 p4ScfileRow *object, ///< an p4ScfileRow object 7451 7457 bool mdcf ///< format as mdconfig or simple 7452 7458 ); 7453 /** p4bRunRow data structure 7454 * 7455 * Structure for representing a single row of p4bRun table data. 7456 */ 7457 7458 typedef struct { 7459 psS32 p4b_id; 7460 char *state; 7461 char *workdir; 7462 bool magic; 7463 } p4bRunRow; 7464 7465 /** Creates a new p4bRunRow object 7466 * 7467 * @return A new p4bRunRow object or NULL on failure. 7468 */ 7469 7470 p4bRunRow *p4bRunRowAlloc( 7471 psS32 p4b_id, 7472 const char *state, 7473 const char *workdir, 7474 bool magic 7475 ); 7476 7477 /** Creates a new p4bRun table 7478 * 7479 * @return true on success 7480 */ 7481 7482 bool p4bRunCreateTable( 7483 psDB *dbh ///< Database handle 7484 ); 7485 7486 /** Deletes a p4bRun table 7487 * 7488 * @return true on success 7489 */ 7490 7491 bool p4bRunDropTable( 7492 psDB *dbh ///< Database handle 7493 ); 7494 7495 /** Insert a single row into a table 7496 * 7497 * This function constructs and inserts a single row based on it's parameters. 7498 * 7499 * @return true on success 7500 */ 7501 7502 bool p4bRunInsert( 7503 psDB *dbh, ///< Database handle 7504 psS32 p4b_id, 7505 const char *state, 7506 const char *workdir, 7507 bool magic 7508 ); 7509 7510 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 7511 * 7512 * @return A The number of rows removed or a negative value on error 7513 */ 7514 7515 long long p4bRunDelete( 7516 psDB *dbh, ///< Database handle 7517 const psMetadata *where, ///< Row match criteria 7518 unsigned long long limit ///< Maximum number of elements to delete 7519 ); 7520 7521 /** Insert a single p4bRunRow object into a table 7522 * 7523 * This function constructs and inserts a single row based on it's parameters. 7524 * 7525 * @return true on success 7526 */ 7527 7528 bool p4bRunInsertObject( 7529 psDB *dbh, ///< Database handle 7530 p4bRunRow *object ///< p4bRunRow object 7531 ); 7532 7533 /** Insert an array of p4bRunRow object into a table 7534 * 7535 * This function constructs and inserts multiple rows based on it's parameters. 7536 * 7537 * @return true on success 7538 */ 7539 7540 bool p4bRunInsertObjects( 7541 psDB *dbh, ///< Database handle 7542 psArray *objects ///< array of p4bRunRow objects 7543 ); 7544 7545 /** Insert data from a binary FITS table p4bRunRow into the database 7546 * 7547 * This function expects a psFits object with a FITS table as the first 7548 * extension. The table must have at least one row of data in it, that is of 7549 * the appropriate format (number of columns and their type). All other 7550 * extensions are ignored. 7551 * 7552 * @return true on success 7553 */ 7554 7555 bool p4bRunInsertFits( 7556 psDB *dbh, ///< Database handle 7557 const psFits *fits ///< psFits object 7558 ); 7559 7560 /** Selects up to limit from the database and returns them in a binary FITS table 7561 * 7562 * This function assumes an empty psFits object and will create a FITS table 7563 * as the first extension. 7564 * 7565 * See psDBSelectRows() for documentation on the format of where. 7566 * 7567 * @return true on success 7568 */ 7569 7570 bool p4bRunSelectRowsFits( 7571 psDB *dbh, ///< Database handle 7572 psFits *fits, ///< psFits object 7573 const psMetadata *where, ///< Row match criteria 7574 unsigned long long limit ///< Maximum number of elements to return 7575 ); 7576 7577 /** Convert a p4bRunRow into an equivalent psMetadata 7578 * 7579 * @return A psMetadata pointer or NULL on error 7580 */ 7581 7582 psMetadata *p4bRunMetadataFromObject( 7583 const p4bRunRow *object ///< fooRow to convert into a psMetadata 7584 ); 7585 7586 /** Convert a psMetadata into an equivalent fooRow 7587 * 7588 * @return A p4bRunRow pointer or NULL on error 7589 */ 7590 7591 p4bRunRow *p4bRunObjectFromMetadata( 7592 psMetadata *md ///< psMetadata to convert into a fooRow 7593 ); 7594 /** Selects up to limit rows from the database and returns as p4bRunRow objects in a psArray 7595 * 7596 * See psDBSelectRows() for documentation on the format of where. 7597 * 7598 * @return A psArray pointer or NULL on error 7599 */ 7600 7601 psArray *p4bRunSelectRowObjects( 7602 psDB *dbh, ///< Database handle 7603 const psMetadata *where, ///< Row match criteria 7604 unsigned long long limit ///< Maximum number of elements to return 7605 ); 7606 /** Deletes a row from the database coresponding to an p4bRun 7607 * 7608 * Note that a 'where' search psMetadata is constructed from each object and 7609 * used to find rows to delete. 7610 * 7611 * @return A The number of rows removed or a negative value on error 7612 */ 7613 7614 bool p4bRunDeleteObject( 7615 psDB *dbh, ///< Database handle 7616 const p4bRunRow *object ///< Object to delete 7617 ); 7618 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 7619 * 7620 * Note that a 'where' search psMetadata is constructed from each object and 7621 * used to find rows to delete. 7622 * 7623 * @return A The number of rows removed or a negative value on error 7624 */ 7625 7626 long long p4bRunDeleteRowObjects( 7627 psDB *dbh, ///< Database handle 7628 const psArray *objects, ///< Array of objects to delete 7629 unsigned long long limit ///< Maximum number of elements to delete 7630 ); 7631 /** Formats and prints an array of p4bRunRow objects 7632 * 7633 * When mdcf is set the formated output is in psMetadataConfig 7634 * format, otherwise it is in a simple tabular format. 7635 * 7636 * @return true on success 7637 */ 7638 7639 bool p4bRunPrintObjects( 7640 FILE *stream, ///< a stream 7641 psArray *objects, ///< An array of p4bRunRow objects 7642 bool mdcf ///< format as mdconfig or simple 7643 ); 7644 /** Formats and prints an p4bRunRow object 7645 * 7646 * When mdcf is set the formated output is in psMetadataConfig 7647 * format, otherwise it is in a simple tabular format. 7648 * 7649 * @return true on success 7650 */ 7651 7652 bool p4bRunPrintObject( 7653 FILE *stream, ///< a stream 7654 p4bRunRow *object, ///< an p4bRunRow object 7655 bool mdcf ///< format as mdconfig or simple 7656 ); 7657 /** p4bInputScfileRow data structure 7658 * 7659 * Structure for representing a single row of p4bInputScfile table data. 7459 /** p4InputScfileRow data structure 7460 * 7461 * Structure for representing a single row of p4InputScfile table data. 7660 7462 */ 7661 7463 … … 7667 7469 psS32 p3_version; 7668 7470 char *kind; 7669 } p4 bInputScfileRow;7670 7671 /** Creates a new p4 bInputScfileRow object7672 * 7673 * @return A new p4 bInputScfileRow object or NULL on failure.7674 */ 7675 7676 p4 bInputScfileRow *p4bInputScfileRowAlloc(7471 } p4InputScfileRow; 7472 7473 /** Creates a new p4InputScfileRow object 7474 * 7475 * @return A new p4InputScfileRow object or NULL on failure. 7476 */ 7477 7478 p4InputScfileRow *p4InputScfileRowAlloc( 7677 7479 psS32 p4b_id, 7678 7480 const char *skycell_id, … … 7683 7485 ); 7684 7486 7685 /** Creates a new p4 bInputScfile table7686 * 7687 * @return true on success 7688 */ 7689 7690 bool p4 bInputScfileCreateTable(7487 /** Creates a new p4InputScfile table 7488 * 7489 * @return true on success 7490 */ 7491 7492 bool p4InputScfileCreateTable( 7691 7493 psDB *dbh ///< Database handle 7692 7494 ); 7693 7495 7694 /** Deletes a p4 bInputScfile table7695 * 7696 * @return true on success 7697 */ 7698 7699 bool p4 bInputScfileDropTable(7496 /** Deletes a p4InputScfile table 7497 * 7498 * @return true on success 7499 */ 7500 7501 bool p4InputScfileDropTable( 7700 7502 psDB *dbh ///< Database handle 7701 7503 ); … … 7708 7510 */ 7709 7511 7710 bool p4 bInputScfileInsert(7512 bool p4InputScfileInsert( 7711 7513 psDB *dbh, ///< Database handle 7712 7514 psS32 p4b_id, … … 7723 7525 */ 7724 7526 7725 long long p4 bInputScfileDelete(7527 long long p4InputScfileDelete( 7726 7528 psDB *dbh, ///< Database handle 7727 7529 const psMetadata *where, ///< Row match criteria … … 7729 7531 ); 7730 7532 7731 /** Insert a single p4 bInputScfileRow object into a table7533 /** Insert a single p4InputScfileRow object into a table 7732 7534 * 7733 7535 * This function constructs and inserts a single row based on it's parameters. … … 7736 7538 */ 7737 7539 7738 bool p4 bInputScfileInsertObject(7739 psDB *dbh, ///< Database handle 7740 p4 bInputScfileRow *object ///< p4bInputScfileRow object7741 ); 7742 7743 /** Insert an array of p4 bInputScfileRow object into a table7540 bool p4InputScfileInsertObject( 7541 psDB *dbh, ///< Database handle 7542 p4InputScfileRow *object ///< p4InputScfileRow object 7543 ); 7544 7545 /** Insert an array of p4InputScfileRow object into a table 7744 7546 * 7745 7547 * This function constructs and inserts multiple rows based on it's parameters. … … 7748 7550 */ 7749 7551 7750 bool p4 bInputScfileInsertObjects(7751 psDB *dbh, ///< Database handle 7752 psArray *objects ///< array of p4 bInputScfileRow objects7753 ); 7754 7755 /** Insert data from a binary FITS table p4 bInputScfileRow into the database7552 bool p4InputScfileInsertObjects( 7553 psDB *dbh, ///< Database handle 7554 psArray *objects ///< array of p4InputScfileRow objects 7555 ); 7556 7557 /** Insert data from a binary FITS table p4InputScfileRow into the database 7756 7558 * 7757 7559 * This function expects a psFits object with a FITS table as the first … … 7763 7565 */ 7764 7566 7765 bool p4 bInputScfileInsertFits(7567 bool p4InputScfileInsertFits( 7766 7568 psDB *dbh, ///< Database handle 7767 7569 const psFits *fits ///< psFits object … … 7778 7580 */ 7779 7581 7780 bool p4 bInputScfileSelectRowsFits(7582 bool p4InputScfileSelectRowsFits( 7781 7583 psDB *dbh, ///< Database handle 7782 7584 psFits *fits, ///< psFits object … … 7785 7587 ); 7786 7588 7787 /** Convert a p4 bInputScfileRow into an equivalent psMetadata7589 /** Convert a p4InputScfileRow into an equivalent psMetadata 7788 7590 * 7789 7591 * @return A psMetadata pointer or NULL on error 7790 7592 */ 7791 7593 7792 psMetadata *p4 bInputScfileMetadataFromObject(7793 const p4 bInputScfileRow *object ///< fooRow to convert into a psMetadata7594 psMetadata *p4InputScfileMetadataFromObject( 7595 const p4InputScfileRow *object ///< fooRow to convert into a psMetadata 7794 7596 ); 7795 7597 7796 7598 /** Convert a psMetadata into an equivalent fooRow 7797 7599 * 7798 * @return A p4 bInputScfileRow pointer or NULL on error7799 */ 7800 7801 p4 bInputScfileRow *p4bInputScfileObjectFromMetadata(7600 * @return A p4InputScfileRow pointer or NULL on error 7601 */ 7602 7603 p4InputScfileRow *p4InputScfileObjectFromMetadata( 7802 7604 psMetadata *md ///< psMetadata to convert into a fooRow 7803 7605 ); 7804 /** Selects up to limit rows from the database and returns as p4 bInputScfileRow objects in a psArray7606 /** Selects up to limit rows from the database and returns as p4InputScfileRow objects in a psArray 7805 7607 * 7806 7608 * See psDBSelectRows() for documentation on the format of where. … … 7809 7611 */ 7810 7612 7811 psArray *p4 bInputScfileSelectRowObjects(7613 psArray *p4InputScfileSelectRowObjects( 7812 7614 psDB *dbh, ///< Database handle 7813 7615 const psMetadata *where, ///< Row match criteria 7814 7616 unsigned long long limit ///< Maximum number of elements to return 7815 7617 ); 7816 /** Deletes a row from the database coresponding to an p4 bInputScfile7618 /** Deletes a row from the database coresponding to an p4InputScfile 7817 7619 * 7818 7620 * Note that a 'where' search psMetadata is constructed from each object and … … 7822 7624 */ 7823 7625 7824 bool p4 bInputScfileDeleteObject(7825 psDB *dbh, ///< Database handle 7826 const p4 bInputScfileRow *object ///< Object to delete7626 bool p4InputScfileDeleteObject( 7627 psDB *dbh, ///< Database handle 7628 const p4InputScfileRow *object ///< Object to delete 7827 7629 ); 7828 7630 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. … … 7834 7636 */ 7835 7637 7836 long long p4 bInputScfileDeleteRowObjects(7638 long long p4InputScfileDeleteRowObjects( 7837 7639 psDB *dbh, ///< Database handle 7838 7640 const psArray *objects, ///< Array of objects to delete 7839 7641 unsigned long long limit ///< Maximum number of elements to delete 7840 7642 ); 7841 /** Formats and prints an array of p4 bInputScfileRow objects7643 /** Formats and prints an array of p4InputScfileRow objects 7842 7644 * 7843 7645 * When mdcf is set the formated output is in psMetadataConfig … … 7847 7649 */ 7848 7650 7849 bool p4 bInputScfilePrintObjects(7651 bool p4InputScfilePrintObjects( 7850 7652 FILE *stream, ///< a stream 7851 psArray *objects, ///< An array of p4 bInputScfileRow objects7653 psArray *objects, ///< An array of p4InputScfileRow objects 7852 7654 bool mdcf ///< format as mdconfig or simple 7853 7655 ); 7854 /** Formats and prints an p4 bInputScfileRow object7656 /** Formats and prints an p4InputScfileRow object 7855 7657 * 7856 7658 * When mdcf is set the formated output is in psMetadataConfig … … 7860 7662 */ 7861 7663 7862 bool p4 bInputScfilePrintObject(7664 bool p4InputScfilePrintObject( 7863 7665 FILE *stream, ///< a stream 7864 p4 bInputScfileRow *object, ///< an p4bInputScfileRow object7666 p4InputScfileRow *object, ///< an p4InputScfileRow object 7865 7667 bool mdcf ///< format as mdconfig or simple 7866 7668 ); 7867 /** p4 bDiffScfileRow data structure7868 * 7869 * Structure for representing a single row of p4 bDiffScfile table data.7669 /** p4DiffScfileRow data structure 7670 * 7671 * Structure for representing a single row of p4DiffScfile table data. 7870 7672 */ 7871 7673 … … 7879 7681 psF64 bg; 7880 7682 psF64 bg_mean_stdev; 7881 } p4 bDiffScfileRow;7882 7883 /** Creates a new p4 bDiffScfileRow object7884 * 7885 * @return A new p4 bDiffScfileRow object or NULL on failure.7886 */ 7887 7888 p4 bDiffScfileRow *p4bDiffScfileRowAlloc(7683 } p4DiffScfileRow; 7684 7685 /** Creates a new p4DiffScfileRow object 7686 * 7687 * @return A new p4DiffScfileRow object or NULL on failure. 7688 */ 7689 7690 p4DiffScfileRow *p4DiffScfileRowAlloc( 7889 7691 psS32 p4b_id, 7890 7692 const char *skycell_id, … … 7897 7699 ); 7898 7700 7899 /** Creates a new p4 bDiffScfile table7900 * 7901 * @return true on success 7902 */ 7903 7904 bool p4 bDiffScfileCreateTable(7701 /** Creates a new p4DiffScfile table 7702 * 7703 * @return true on success 7704 */ 7705 7706 bool p4DiffScfileCreateTable( 7905 7707 psDB *dbh ///< Database handle 7906 7708 ); 7907 7709 7908 /** Deletes a p4 bDiffScfile table7909 * 7910 * @return true on success 7911 */ 7912 7913 bool p4 bDiffScfileDropTable(7710 /** Deletes a p4DiffScfile table 7711 * 7712 * @return true on success 7713 */ 7714 7715 bool p4DiffScfileDropTable( 7914 7716 psDB *dbh ///< Database handle 7915 7717 ); … … 7922 7724 */ 7923 7725 7924 bool p4 bDiffScfileInsert(7726 bool p4DiffScfileInsert( 7925 7727 psDB *dbh, ///< Database handle 7926 7728 psS32 p4b_id, … … 7939 7741 */ 7940 7742 7941 long long p4 bDiffScfileDelete(7743 long long p4DiffScfileDelete( 7942 7744 psDB *dbh, ///< Database handle 7943 7745 const psMetadata *where, ///< Row match criteria … … 7945 7747 ); 7946 7748 7947 /** Insert a single p4 bDiffScfileRow object into a table7749 /** Insert a single p4DiffScfileRow object into a table 7948 7750 * 7949 7751 * This function constructs and inserts a single row based on it's parameters. … … 7952 7754 */ 7953 7755 7954 bool p4 bDiffScfileInsertObject(7955 psDB *dbh, ///< Database handle 7956 p4 bDiffScfileRow *object ///< p4bDiffScfileRow object7957 ); 7958 7959 /** Insert an array of p4 bDiffScfileRow object into a table7756 bool p4DiffScfileInsertObject( 7757 psDB *dbh, ///< Database handle 7758 p4DiffScfileRow *object ///< p4DiffScfileRow object 7759 ); 7760 7761 /** Insert an array of p4DiffScfileRow object into a table 7960 7762 * 7961 7763 * This function constructs and inserts multiple rows based on it's parameters. … … 7964 7766 */ 7965 7767 7966 bool p4 bDiffScfileInsertObjects(7967 psDB *dbh, ///< Database handle 7968 psArray *objects ///< array of p4 bDiffScfileRow objects7969 ); 7970 7971 /** Insert data from a binary FITS table p4 bDiffScfileRow into the database7768 bool p4DiffScfileInsertObjects( 7769 psDB *dbh, ///< Database handle 7770 psArray *objects ///< array of p4DiffScfileRow objects 7771 ); 7772 7773 /** Insert data from a binary FITS table p4DiffScfileRow into the database 7972 7774 * 7973 7775 * This function expects a psFits object with a FITS table as the first … … 7979 7781 */ 7980 7782 7981 bool p4 bDiffScfileInsertFits(7783 bool p4DiffScfileInsertFits( 7982 7784 psDB *dbh, ///< Database handle 7983 7785 const psFits *fits ///< psFits object … … 7994 7796 */ 7995 7797 7996 bool p4 bDiffScfileSelectRowsFits(7798 bool p4DiffScfileSelectRowsFits( 7997 7799 psDB *dbh, ///< Database handle 7998 7800 psFits *fits, ///< psFits object … … 8001 7803 ); 8002 7804 8003 /** Convert a p4 bDiffScfileRow into an equivalent psMetadata7805 /** Convert a p4DiffScfileRow into an equivalent psMetadata 8004 7806 * 8005 7807 * @return A psMetadata pointer or NULL on error 8006 7808 */ 8007 7809 8008 psMetadata *p4 bDiffScfileMetadataFromObject(8009 const p4 bDiffScfileRow *object ///< fooRow to convert into a psMetadata7810 psMetadata *p4DiffScfileMetadataFromObject( 7811 const p4DiffScfileRow *object ///< fooRow to convert into a psMetadata 8010 7812 ); 8011 7813 8012 7814 /** Convert a psMetadata into an equivalent fooRow 8013 7815 * 8014 * @return A p4 bDiffScfileRow pointer or NULL on error8015 */ 8016 8017 p4 bDiffScfileRow *p4bDiffScfileObjectFromMetadata(7816 * @return A p4DiffScfileRow pointer or NULL on error 7817 */ 7818 7819 p4DiffScfileRow *p4DiffScfileObjectFromMetadata( 8018 7820 psMetadata *md ///< psMetadata to convert into a fooRow 8019 7821 ); 8020 /** Selects up to limit rows from the database and returns as p4 bDiffScfileRow objects in a psArray7822 /** Selects up to limit rows from the database and returns as p4DiffScfileRow objects in a psArray 8021 7823 * 8022 7824 * See psDBSelectRows() for documentation on the format of where. … … 8025 7827 */ 8026 7828 8027 psArray *p4 bDiffScfileSelectRowObjects(7829 psArray *p4DiffScfileSelectRowObjects( 8028 7830 psDB *dbh, ///< Database handle 8029 7831 const psMetadata *where, ///< Row match criteria 8030 7832 unsigned long long limit ///< Maximum number of elements to return 8031 7833 ); 8032 /** Deletes a row from the database coresponding to an p4 bDiffScfile7834 /** Deletes a row from the database coresponding to an p4DiffScfile 8033 7835 * 8034 7836 * Note that a 'where' search psMetadata is constructed from each object and … … 8038 7840 */ 8039 7841 8040 bool p4 bDiffScfileDeleteObject(8041 psDB *dbh, ///< Database handle 8042 const p4 bDiffScfileRow *object ///< Object to delete7842 bool p4DiffScfileDeleteObject( 7843 psDB *dbh, ///< Database handle 7844 const p4DiffScfileRow *object ///< Object to delete 8043 7845 ); 8044 7846 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. … … 8050 7852 */ 8051 7853 8052 long long p4 bDiffScfileDeleteRowObjects(7854 long long p4DiffScfileDeleteRowObjects( 8053 7855 psDB *dbh, ///< Database handle 8054 7856 const psArray *objects, ///< Array of objects to delete 8055 7857 unsigned long long limit ///< Maximum number of elements to delete 8056 7858 ); 8057 /** Formats and prints an array of p4 bDiffScfileRow objects7859 /** Formats and prints an array of p4DiffScfileRow objects 8058 7860 * 8059 7861 * When mdcf is set the formated output is in psMetadataConfig … … 8063 7865 */ 8064 7866 8065 bool p4 bDiffScfilePrintObjects(7867 bool p4DiffScfilePrintObjects( 8066 7868 FILE *stream, ///< a stream 8067 psArray *objects, ///< An array of p4 bDiffScfileRow objects7869 psArray *objects, ///< An array of p4DiffScfileRow objects 8068 7870 bool mdcf ///< format as mdconfig or simple 8069 7871 ); 8070 /** Formats and prints an p4 bDiffScfileRow object7872 /** Formats and prints an p4DiffScfileRow object 8071 7873 * 8072 7874 * When mdcf is set the formated output is in psMetadataConfig … … 8076 7878 */ 8077 7879 8078 bool p4 bDiffScfilePrintObject(7880 bool p4DiffScfilePrintObject( 8079 7881 FILE *stream, ///< a stream 8080 p4bDiffScfileRow *object, ///< an p4bDiffScfileRow object 8081 bool mdcf ///< format as mdconfig or simple 8082 ); 8083 /** p4cRunRow data structure 8084 * 8085 * Structure for representing a single row of p4cRun table data. 8086 */ 8087 8088 typedef struct { 8089 psS32 p4c_id; 8090 char *state; 8091 char *workdir; 8092 bool magic; 8093 } p4cRunRow; 8094 8095 /** Creates a new p4cRunRow object 8096 * 8097 * @return A new p4cRunRow object or NULL on failure. 8098 */ 8099 8100 p4cRunRow *p4cRunRowAlloc( 8101 psS32 p4c_id, 8102 const char *state, 8103 const char *workdir, 8104 bool magic 8105 ); 8106 8107 /** Creates a new p4cRun table 8108 * 8109 * @return true on success 8110 */ 8111 8112 bool p4cRunCreateTable( 8113 psDB *dbh ///< Database handle 8114 ); 8115 8116 /** Deletes a p4cRun table 8117 * 8118 * @return true on success 8119 */ 8120 8121 bool p4cRunDropTable( 8122 psDB *dbh ///< Database handle 8123 ); 8124 8125 /** Insert a single row into a table 8126 * 8127 * This function constructs and inserts a single row based on it's parameters. 8128 * 8129 * @return true on success 8130 */ 8131 8132 bool p4cRunInsert( 8133 psDB *dbh, ///< Database handle 8134 psS32 p4c_id, 8135 const char *state, 8136 const char *workdir, 8137 bool magic 8138 ); 8139 8140 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 8141 * 8142 * @return A The number of rows removed or a negative value on error 8143 */ 8144 8145 long long p4cRunDelete( 8146 psDB *dbh, ///< Database handle 8147 const psMetadata *where, ///< Row match criteria 8148 unsigned long long limit ///< Maximum number of elements to delete 8149 ); 8150 8151 /** Insert a single p4cRunRow object into a table 8152 * 8153 * This function constructs and inserts a single row based on it's parameters. 8154 * 8155 * @return true on success 8156 */ 8157 8158 bool p4cRunInsertObject( 8159 psDB *dbh, ///< Database handle 8160 p4cRunRow *object ///< p4cRunRow object 8161 ); 8162 8163 /** Insert an array of p4cRunRow object into a table 8164 * 8165 * This function constructs and inserts multiple rows based on it's parameters. 8166 * 8167 * @return true on success 8168 */ 8169 8170 bool p4cRunInsertObjects( 8171 psDB *dbh, ///< Database handle 8172 psArray *objects ///< array of p4cRunRow objects 8173 ); 8174 8175 /** Insert data from a binary FITS table p4cRunRow into the database 8176 * 8177 * This function expects a psFits object with a FITS table as the first 8178 * extension. The table must have at least one row of data in it, that is of 8179 * the appropriate format (number of columns and their type). All other 8180 * extensions are ignored. 8181 * 8182 * @return true on success 8183 */ 8184 8185 bool p4cRunInsertFits( 8186 psDB *dbh, ///< Database handle 8187 const psFits *fits ///< psFits object 8188 ); 8189 8190 /** Selects up to limit from the database and returns them in a binary FITS table 8191 * 8192 * This function assumes an empty psFits object and will create a FITS table 8193 * as the first extension. 8194 * 8195 * See psDBSelectRows() for documentation on the format of where. 8196 * 8197 * @return true on success 8198 */ 8199 8200 bool p4cRunSelectRowsFits( 8201 psDB *dbh, ///< Database handle 8202 psFits *fits, ///< psFits object 8203 const psMetadata *where, ///< Row match criteria 8204 unsigned long long limit ///< Maximum number of elements to return 8205 ); 8206 8207 /** Convert a p4cRunRow into an equivalent psMetadata 8208 * 8209 * @return A psMetadata pointer or NULL on error 8210 */ 8211 8212 psMetadata *p4cRunMetadataFromObject( 8213 const p4cRunRow *object ///< fooRow to convert into a psMetadata 8214 ); 8215 8216 /** Convert a psMetadata into an equivalent fooRow 8217 * 8218 * @return A p4cRunRow pointer or NULL on error 8219 */ 8220 8221 p4cRunRow *p4cRunObjectFromMetadata( 8222 psMetadata *md ///< psMetadata to convert into a fooRow 8223 ); 8224 /** Selects up to limit rows from the database and returns as p4cRunRow objects in a psArray 8225 * 8226 * See psDBSelectRows() for documentation on the format of where. 8227 * 8228 * @return A psArray pointer or NULL on error 8229 */ 8230 8231 psArray *p4cRunSelectRowObjects( 8232 psDB *dbh, ///< Database handle 8233 const psMetadata *where, ///< Row match criteria 8234 unsigned long long limit ///< Maximum number of elements to return 8235 ); 8236 /** Deletes a row from the database coresponding to an p4cRun 8237 * 8238 * Note that a 'where' search psMetadata is constructed from each object and 8239 * used to find rows to delete. 8240 * 8241 * @return A The number of rows removed or a negative value on error 8242 */ 8243 8244 bool p4cRunDeleteObject( 8245 psDB *dbh, ///< Database handle 8246 const p4cRunRow *object ///< Object to delete 8247 ); 8248 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 8249 * 8250 * Note that a 'where' search psMetadata is constructed from each object and 8251 * used to find rows to delete. 8252 * 8253 * @return A The number of rows removed or a negative value on error 8254 */ 8255 8256 long long p4cRunDeleteRowObjects( 8257 psDB *dbh, ///< Database handle 8258 const psArray *objects, ///< Array of objects to delete 8259 unsigned long long limit ///< Maximum number of elements to delete 8260 ); 8261 /** Formats and prints an array of p4cRunRow objects 8262 * 8263 * When mdcf is set the formated output is in psMetadataConfig 8264 * format, otherwise it is in a simple tabular format. 8265 * 8266 * @return true on success 8267 */ 8268 8269 bool p4cRunPrintObjects( 8270 FILE *stream, ///< a stream 8271 psArray *objects, ///< An array of p4cRunRow objects 8272 bool mdcf ///< format as mdconfig or simple 8273 ); 8274 /** Formats and prints an p4cRunRow object 8275 * 8276 * When mdcf is set the formated output is in psMetadataConfig 8277 * format, otherwise it is in a simple tabular format. 8278 * 8279 * @return true on success 8280 */ 8281 8282 bool p4cRunPrintObject( 8283 FILE *stream, ///< a stream 8284 p4cRunRow *object, ///< an p4cRunRow object 8285 bool mdcf ///< format as mdconfig or simple 8286 ); 8287 /** p4cInputExpRow data structure 8288 * 8289 * Structure for representing a single row of p4cInputExp table data. 8290 */ 8291 8292 typedef struct { 8293 psS32 p4c_id; 8294 char *exp_tag; 8295 psS32 p3_version; 8296 } p4cInputExpRow; 8297 8298 /** Creates a new p4cInputExpRow object 8299 * 8300 * @return A new p4cInputExpRow object or NULL on failure. 8301 */ 8302 8303 p4cInputExpRow *p4cInputExpRowAlloc( 8304 psS32 p4c_id, 8305 const char *exp_tag, 8306 psS32 p3_version 8307 ); 8308 8309 /** Creates a new p4cInputExp table 8310 * 8311 * @return true on success 8312 */ 8313 8314 bool p4cInputExpCreateTable( 8315 psDB *dbh ///< Database handle 8316 ); 8317 8318 /** Deletes a p4cInputExp table 8319 * 8320 * @return true on success 8321 */ 8322 8323 bool p4cInputExpDropTable( 8324 psDB *dbh ///< Database handle 8325 ); 8326 8327 /** Insert a single row into a table 8328 * 8329 * This function constructs and inserts a single row based on it's parameters. 8330 * 8331 * @return true on success 8332 */ 8333 8334 bool p4cInputExpInsert( 8335 psDB *dbh, ///< Database handle 8336 psS32 p4c_id, 8337 const char *exp_tag, 8338 psS32 p3_version 8339 ); 8340 8341 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 8342 * 8343 * @return A The number of rows removed or a negative value on error 8344 */ 8345 8346 long long p4cInputExpDelete( 8347 psDB *dbh, ///< Database handle 8348 const psMetadata *where, ///< Row match criteria 8349 unsigned long long limit ///< Maximum number of elements to delete 8350 ); 8351 8352 /** Insert a single p4cInputExpRow object into a table 8353 * 8354 * This function constructs and inserts a single row based on it's parameters. 8355 * 8356 * @return true on success 8357 */ 8358 8359 bool p4cInputExpInsertObject( 8360 psDB *dbh, ///< Database handle 8361 p4cInputExpRow *object ///< p4cInputExpRow object 8362 ); 8363 8364 /** Insert an array of p4cInputExpRow object into a table 8365 * 8366 * This function constructs and inserts multiple rows based on it's parameters. 8367 * 8368 * @return true on success 8369 */ 8370 8371 bool p4cInputExpInsertObjects( 8372 psDB *dbh, ///< Database handle 8373 psArray *objects ///< array of p4cInputExpRow objects 8374 ); 8375 8376 /** Insert data from a binary FITS table p4cInputExpRow into the database 8377 * 8378 * This function expects a psFits object with a FITS table as the first 8379 * extension. The table must have at least one row of data in it, that is of 8380 * the appropriate format (number of columns and their type). All other 8381 * extensions are ignored. 8382 * 8383 * @return true on success 8384 */ 8385 8386 bool p4cInputExpInsertFits( 8387 psDB *dbh, ///< Database handle 8388 const psFits *fits ///< psFits object 8389 ); 8390 8391 /** Selects up to limit from the database and returns them in a binary FITS table 8392 * 8393 * This function assumes an empty psFits object and will create a FITS table 8394 * as the first extension. 8395 * 8396 * See psDBSelectRows() for documentation on the format of where. 8397 * 8398 * @return true on success 8399 */ 8400 8401 bool p4cInputExpSelectRowsFits( 8402 psDB *dbh, ///< Database handle 8403 psFits *fits, ///< psFits object 8404 const psMetadata *where, ///< Row match criteria 8405 unsigned long long limit ///< Maximum number of elements to return 8406 ); 8407 8408 /** Convert a p4cInputExpRow into an equivalent psMetadata 8409 * 8410 * @return A psMetadata pointer or NULL on error 8411 */ 8412 8413 psMetadata *p4cInputExpMetadataFromObject( 8414 const p4cInputExpRow *object ///< fooRow to convert into a psMetadata 8415 ); 8416 8417 /** Convert a psMetadata into an equivalent fooRow 8418 * 8419 * @return A p4cInputExpRow pointer or NULL on error 8420 */ 8421 8422 p4cInputExpRow *p4cInputExpObjectFromMetadata( 8423 psMetadata *md ///< psMetadata to convert into a fooRow 8424 ); 8425 /** Selects up to limit rows from the database and returns as p4cInputExpRow objects in a psArray 8426 * 8427 * See psDBSelectRows() for documentation on the format of where. 8428 * 8429 * @return A psArray pointer or NULL on error 8430 */ 8431 8432 psArray *p4cInputExpSelectRowObjects( 8433 psDB *dbh, ///< Database handle 8434 const psMetadata *where, ///< Row match criteria 8435 unsigned long long limit ///< Maximum number of elements to return 8436 ); 8437 /** Deletes a row from the database coresponding to an p4cInputExp 8438 * 8439 * Note that a 'where' search psMetadata is constructed from each object and 8440 * used to find rows to delete. 8441 * 8442 * @return A The number of rows removed or a negative value on error 8443 */ 8444 8445 bool p4cInputExpDeleteObject( 8446 psDB *dbh, ///< Database handle 8447 const p4cInputExpRow *object ///< Object to delete 8448 ); 8449 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 8450 * 8451 * Note that a 'where' search psMetadata is constructed from each object and 8452 * used to find rows to delete. 8453 * 8454 * @return A The number of rows removed or a negative value on error 8455 */ 8456 8457 long long p4cInputExpDeleteRowObjects( 8458 psDB *dbh, ///< Database handle 8459 const psArray *objects, ///< Array of objects to delete 8460 unsigned long long limit ///< Maximum number of elements to delete 8461 ); 8462 /** Formats and prints an array of p4cInputExpRow objects 8463 * 8464 * When mdcf is set the formated output is in psMetadataConfig 8465 * format, otherwise it is in a simple tabular format. 8466 * 8467 * @return true on success 8468 */ 8469 8470 bool p4cInputExpPrintObjects( 8471 FILE *stream, ///< a stream 8472 psArray *objects, ///< An array of p4cInputExpRow objects 8473 bool mdcf ///< format as mdconfig or simple 8474 ); 8475 /** Formats and prints an p4cInputExpRow object 8476 * 8477 * When mdcf is set the formated output is in psMetadataConfig 8478 * format, otherwise it is in a simple tabular format. 8479 * 8480 * @return true on success 8481 */ 8482 8483 bool p4cInputExpPrintObject( 8484 FILE *stream, ///< a stream 8485 p4cInputExpRow *object, ///< an p4cInputExpRow object 7882 p4DiffScfileRow *object, ///< an p4DiffScfileRow object 8486 7883 bool mdcf ///< format as mdconfig or simple 8487 7884 );
Note:
See TracChangeset
for help on using the changeset viewer.
