Changeset 18044 for trunk/ippdb/src
- Timestamp:
- Jun 9, 2008, 5:11:49 PM (18 years ago)
- Location:
- trunk/ippdb/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippdb/src/ippdb.c
r17872 r18044 47 47 #define CAMPROCESSEDEXP_TABLE_NAME "camProcessedExp" 48 48 #define CAMMASK_TABLE_NAME "camMask" 49 #define FAKERUN_TABLE_NAME "fakeRun" 50 #define FAKEPROCESSEDIMFILE_TABLE_NAME "fakeProcessedImfile" 51 #define FAKEMASK_TABLE_NAME "fakeMask" 49 52 #define WARPRUN_TABLE_NAME "warpRun" 50 53 #define WARPSKYCELLMAP_TABLE_NAME "warpSkyCellMap" … … 8617 8620 static void camProcessedExpRowFree(camProcessedExpRow *object); 8618 8621 8619 camProcessedExpRow *camProcessedExpRowAlloc(psS64 cam_id, psS64 chip_id,const char *uri, psF32 bg, psF32 bg_stdev, psF32 bg_mean_stdev, psF32 bias, psF32 bias_stdev, psF32 fringe_0, psF32 fringe_1, psF32 fringe_2, psF32 sigma_ra, psF32 sigma_dec, psF32 ap_resid, psF32 ap_resid_stdev, psF32 zp_mean, psF32 zp_stdev, psF32 fwhm_major, psF32 fwhm_minor, psF32 dtime_detrend, psF32 dtime_photom, psF32 dtime_astrom, const char *hostname, psS32 n_stars, psS32 n_extended, psS32 n_cr, psS32 n_astrom, const char *path_base, psS16 fault)8622 camProcessedExpRow *camProcessedExpRowAlloc(psS64 cam_id, const char *uri, psF32 bg, psF32 bg_stdev, psF32 bg_mean_stdev, psF32 bias, psF32 bias_stdev, psF32 fringe_0, psF32 fringe_1, psF32 fringe_2, psF32 sigma_ra, psF32 sigma_dec, psF32 ap_resid, psF32 ap_resid_stdev, psF32 zp_mean, psF32 zp_stdev, psF32 fwhm_major, psF32 fwhm_minor, psF32 dtime_detrend, psF32 dtime_photom, psF32 dtime_astrom, const char *hostname, psS32 n_stars, psS32 n_extended, psS32 n_cr, psS32 n_astrom, const char *path_base, psS16 fault) 8620 8623 { 8621 8624 camProcessedExpRow *_object; … … 8625 8628 8626 8629 _object->cam_id = cam_id; 8627 _object->chip_id = chip_id;8628 8630 _object->uri = psStringCopy(uri); 8629 8631 _object->bg = bg; … … 8672 8674 return false; 8673 8675 } 8674 if (!psMetadataAdd(md, PS_LIST_TAIL, "chip_id", PS_DATA_S64, "Primary Key fkey(cam_id, chip_id) ref camRun(cam_id, chip_id)", 0)) { 8675 psError(PS_ERR_UNKNOWN, false, "failed to add item chip_id"); 8676 psFree(md); 8677 return false; 8678 } 8679 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) { 8676 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, "fkey(cam_id) ref camRun(cam_id)", "255")) { 8680 8677 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 8681 8678 psFree(md); … … 8825 8822 } 8826 8823 8827 bool camProcessedExpInsert(psDB * dbh, psS64 cam_id, psS64 chip_id,const char *uri, psF32 bg, psF32 bg_stdev, psF32 bg_mean_stdev, psF32 bias, psF32 bias_stdev, psF32 fringe_0, psF32 fringe_1, psF32 fringe_2, psF32 sigma_ra, psF32 sigma_dec, psF32 ap_resid, psF32 ap_resid_stdev, psF32 zp_mean, psF32 zp_stdev, psF32 fwhm_major, psF32 fwhm_minor, psF32 dtime_detrend, psF32 dtime_photom, psF32 dtime_astrom, const char *hostname, psS32 n_stars, psS32 n_extended, psS32 n_cr, psS32 n_astrom, const char *path_base, psS16 fault)8824 bool camProcessedExpInsert(psDB * dbh, psS64 cam_id, const char *uri, psF32 bg, psF32 bg_stdev, psF32 bg_mean_stdev, psF32 bias, psF32 bias_stdev, psF32 fringe_0, psF32 fringe_1, psF32 fringe_2, psF32 sigma_ra, psF32 sigma_dec, psF32 ap_resid, psF32 ap_resid_stdev, psF32 zp_mean, psF32 zp_stdev, psF32 fwhm_major, psF32 fwhm_minor, psF32 dtime_detrend, psF32 dtime_photom, psF32 dtime_astrom, const char *hostname, psS32 n_stars, psS32 n_extended, psS32 n_cr, psS32 n_astrom, const char *path_base, psS16 fault) 8828 8825 { 8829 8826 psMetadata *md = psMetadataAlloc(); 8830 8827 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, NULL, cam_id)) { 8831 8828 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id"); 8832 psFree(md);8833 return false;8834 }8835 if (!psMetadataAdd(md, PS_LIST_TAIL, "chip_id", PS_DATA_S64, NULL, chip_id)) {8836 psError(PS_ERR_UNKNOWN, false, "failed to add item chip_id");8837 8829 psFree(md); 8838 8830 return false; … … 8996 8988 bool camProcessedExpInsertObject(psDB *dbh, camProcessedExpRow *object) 8997 8989 { 8998 return camProcessedExpInsert(dbh, object->cam_id, object-> chip_id, object->uri, object->bg, object->bg_stdev, object->bg_mean_stdev, object->bias, object->bias_stdev, object->fringe_0, object->fringe_1, object->fringe_2, object->sigma_ra, object->sigma_dec, object->ap_resid, object->ap_resid_stdev, object->zp_mean, object->zp_stdev, object->fwhm_major, object->fwhm_minor, object->dtime_detrend, object->dtime_photom, object->dtime_astrom, object->hostname, object->n_stars, object->n_extended, object->n_cr, object->n_astrom, object->path_base, object->fault);8990 return camProcessedExpInsert(dbh, object->cam_id, object->uri, object->bg, object->bg_stdev, object->bg_mean_stdev, object->bias, object->bias_stdev, object->fringe_0, object->fringe_1, object->fringe_2, object->sigma_ra, object->sigma_dec, object->ap_resid, object->ap_resid_stdev, object->zp_mean, object->zp_stdev, object->fwhm_major, object->fwhm_minor, object->dtime_detrend, object->dtime_photom, object->dtime_astrom, object->hostname, object->n_stars, object->n_extended, object->n_cr, object->n_astrom, object->path_base, object->fault); 8999 8991 } 9000 8992 … … 9074 9066 return false; 9075 9067 } 9076 if (!psMetadataAdd(md, PS_LIST_TAIL, "chip_id", PS_DATA_S64, NULL, object->chip_id)) {9077 psError(PS_ERR_UNKNOWN, false, "failed to add item chip_id");9078 psFree(md);9079 return false;9080 }9081 9068 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) { 9082 9069 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); … … 9228 9215 return false; 9229 9216 } 9230 psS64 chip_id = psMetadataLookupS64(&status, md, "chip_id");9231 if (!status) {9232 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item chip_id");9233 return false;9234 }9235 9217 char* uri = psMetadataLookupPtr(&status, md, "uri"); 9236 9218 if (!status) { … … 9369 9351 } 9370 9352 9371 return camProcessedExpRowAlloc(cam_id, chip_id,uri, bg, bg_stdev, bg_mean_stdev, bias, bias_stdev, fringe_0, fringe_1, fringe_2, sigma_ra, sigma_dec, ap_resid, ap_resid_stdev, zp_mean, zp_stdev, fwhm_major, fwhm_minor, dtime_detrend, dtime_photom, dtime_astrom, hostname, n_stars, n_extended, n_cr, n_astrom, path_base, fault);9353 return camProcessedExpRowAlloc(cam_id, uri, bg, bg_stdev, bg_mean_stdev, bias, bias_stdev, fringe_0, fringe_1, fringe_2, sigma_ra, sigma_dec, ap_resid, ap_resid_stdev, zp_mean, zp_stdev, fwhm_major, fwhm_minor, dtime_detrend, dtime_photom, dtime_astrom, hostname, n_stars, n_extended, n_cr, n_astrom, path_base, fault); 9372 9354 } 9373 9355 psArray *camProcessedExpSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) … … 9765 9747 return true; 9766 9748 } 9749 static void fakeRunRowFree(fakeRunRow *object); 9750 9751 fakeRunRow *fakeRunRowAlloc(psS64 fake_id, psS64 cam_id, const char *state, const char *workdir, const char *label, const char *reduction, const char *expgroup, const char *dvodb, const char *tess_id, const char *end_stage, psTime* epoch) 9752 { 9753 fakeRunRow *_object; 9754 9755 _object = psAlloc(sizeof(fakeRunRow)); 9756 psMemSetDeallocator(_object, (psFreeFunc)fakeRunRowFree); 9757 9758 _object->fake_id = fake_id; 9759 _object->cam_id = cam_id; 9760 _object->state = psStringCopy(state); 9761 _object->workdir = psStringCopy(workdir); 9762 _object->label = psStringCopy(label); 9763 _object->reduction = psStringCopy(reduction); 9764 _object->expgroup = psStringCopy(expgroup); 9765 _object->dvodb = psStringCopy(dvodb); 9766 _object->tess_id = psStringCopy(tess_id); 9767 _object->end_stage = psStringCopy(end_stage); 9768 _object->epoch = psTimeCopy(epoch); 9769 9770 return _object; 9771 } 9772 9773 static void fakeRunRowFree(fakeRunRow *object) 9774 { 9775 psFree(object->state); 9776 psFree(object->workdir); 9777 psFree(object->label); 9778 psFree(object->reduction); 9779 psFree(object->expgroup); 9780 psFree(object->dvodb); 9781 psFree(object->tess_id); 9782 psFree(object->end_stage); 9783 psFree(object->epoch); 9784 } 9785 9786 bool fakeRunCreateTable(psDB *dbh) 9787 { 9788 psMetadata *md = psMetadataAlloc(); 9789 if (!psMetadataAdd(md, PS_LIST_TAIL, "fake_id", PS_DATA_S64, "Primary Key AUTO_INCREMENT", 0)) { 9790 psError(PS_ERR_UNKNOWN, false, "failed to add item fake_id"); 9791 psFree(md); 9792 return false; 9793 } 9794 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, "Key INDEX(fake_id, cam_id) fkey (cam_id) ref camRun(cam_id)", 0)) { 9795 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id"); 9796 psFree(md); 9797 return false; 9798 } 9799 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, "Key", "64")) { 9800 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 9801 psFree(md); 9802 return false; 9803 } 9804 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, "255")) { 9805 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 9806 psFree(md); 9807 return false; 9808 } 9809 if (!psMetadataAdd(md, PS_LIST_TAIL, "label", PS_DATA_STRING, "Key", "64")) { 9810 psError(PS_ERR_UNKNOWN, false, "failed to add item label"); 9811 psFree(md); 9812 return false; 9813 } 9814 if (!psMetadataAdd(md, PS_LIST_TAIL, "reduction", PS_DATA_STRING, "Reduction class", "64")) { 9815 psError(PS_ERR_UNKNOWN, false, "failed to add item reduction"); 9816 psFree(md); 9817 return false; 9818 } 9819 if (!psMetadataAdd(md, PS_LIST_TAIL, "expgroup", PS_DATA_STRING, "Key", "64")) { 9820 psError(PS_ERR_UNKNOWN, false, "failed to add item expgroup"); 9821 psFree(md); 9822 return false; 9823 } 9824 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, "255")) { 9825 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb"); 9826 psFree(md); 9827 return false; 9828 } 9829 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, "64")) { 9830 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 9831 psFree(md); 9832 return false; 9833 } 9834 if (!psMetadataAdd(md, PS_LIST_TAIL, "end_stage", PS_DATA_STRING, "Key", "64")) { 9835 psError(PS_ERR_UNKNOWN, false, "failed to add item end_stage"); 9836 psFree(md); 9837 return false; 9838 } 9839 if (!psMetadataAdd(md, PS_LIST_TAIL, "epoch", PS_DATA_TIME, NULL, NULL)) { 9840 psError(PS_ERR_UNKNOWN, false, "failed to add item epoch"); 9841 psFree(md); 9842 return false; 9843 } 9844 9845 bool status = psDBCreateTable(dbh, FAKERUN_TABLE_NAME, md); 9846 9847 psFree(md); 9848 9849 return status; 9850 } 9851 9852 bool fakeRunDropTable(psDB *dbh) 9853 { 9854 return psDBDropTable(dbh, FAKERUN_TABLE_NAME); 9855 } 9856 9857 bool fakeRunInsert(psDB * dbh, psS64 fake_id, psS64 cam_id, const char *state, const char *workdir, const char *label, const char *reduction, const char *expgroup, const char *dvodb, const char *tess_id, const char *end_stage, psTime* epoch) 9858 { 9859 psMetadata *md = psMetadataAlloc(); 9860 if (!psMetadataAdd(md, PS_LIST_TAIL, "fake_id", PS_DATA_S64, NULL, fake_id)) { 9861 psError(PS_ERR_UNKNOWN, false, "failed to add item fake_id"); 9862 psFree(md); 9863 return false; 9864 } 9865 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, NULL, cam_id)) { 9866 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id"); 9867 psFree(md); 9868 return false; 9869 } 9870 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, state)) { 9871 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 9872 psFree(md); 9873 return false; 9874 } 9875 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, workdir)) { 9876 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 9877 psFree(md); 9878 return false; 9879 } 9880 if (!psMetadataAdd(md, PS_LIST_TAIL, "label", PS_DATA_STRING, NULL, label)) { 9881 psError(PS_ERR_UNKNOWN, false, "failed to add item label"); 9882 psFree(md); 9883 return false; 9884 } 9885 if (!psMetadataAdd(md, PS_LIST_TAIL, "reduction", PS_DATA_STRING, NULL, reduction)) { 9886 psError(PS_ERR_UNKNOWN, false, "failed to add item reduction"); 9887 psFree(md); 9888 return false; 9889 } 9890 if (!psMetadataAdd(md, PS_LIST_TAIL, "expgroup", PS_DATA_STRING, NULL, expgroup)) { 9891 psError(PS_ERR_UNKNOWN, false, "failed to add item expgroup"); 9892 psFree(md); 9893 return false; 9894 } 9895 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, dvodb)) { 9896 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb"); 9897 psFree(md); 9898 return false; 9899 } 9900 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) { 9901 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 9902 psFree(md); 9903 return false; 9904 } 9905 if (!psMetadataAdd(md, PS_LIST_TAIL, "end_stage", PS_DATA_STRING, NULL, end_stage)) { 9906 psError(PS_ERR_UNKNOWN, false, "failed to add item end_stage"); 9907 psFree(md); 9908 return false; 9909 } 9910 if (!psMetadataAdd(md, PS_LIST_TAIL, "epoch", PS_DATA_TIME, NULL, epoch)) { 9911 psError(PS_ERR_UNKNOWN, false, "failed to add item epoch"); 9912 psFree(md); 9913 return false; 9914 } 9915 9916 bool status = psDBInsertOneRow(dbh, FAKERUN_TABLE_NAME, md); 9917 psFree(md); 9918 9919 return status; 9920 } 9921 9922 long long fakeRunDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 9923 { 9924 long long deleted = 0; 9925 9926 long long count = psDBDeleteRows(dbh, FAKERUN_TABLE_NAME, where, limit); 9927 if (count < 0) { 9928 psError(PS_ERR_UNKNOWN, true, "failed to delete row from fakeRun"); 9929 return count; 9930 9931 deleted += count; 9932 } 9933 9934 return deleted; 9935 } 9936 bool fakeRunInsertObject(psDB *dbh, fakeRunRow *object) 9937 { 9938 return fakeRunInsert(dbh, object->fake_id, object->cam_id, object->state, object->workdir, object->label, object->reduction, object->expgroup, object->dvodb, object->tess_id, object->end_stage, object->epoch); 9939 } 9940 9941 bool fakeRunInsertObjects(psDB *dbh, psArray *objects) 9942 { 9943 for (long i = 0; i < psArrayLength(objects); i++) { 9944 if (!fakeRunInsertObject(dbh, objects->data[i])) { 9945 return false; 9946 } 9947 } 9948 9949 return true; 9950 } 9951 9952 bool fakeRunInsertFits(psDB *dbh, const psFits *fits) 9953 { 9954 psArray *rowSet; 9955 9956 // move to (the first?) extension named FAKERUN_TABLE_NAME 9957 if (!psFitsMoveExtName(fits, FAKERUN_TABLE_NAME)) { 9958 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", FAKERUN_TABLE_NAME); 9959 return false; 9960 } 9961 9962 // check HDU type 9963 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 9964 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 9965 return false; 9966 } 9967 9968 // read fits table 9969 rowSet = psFitsReadTable(fits); 9970 if (!rowSet) { 9971 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 9972 psFree(rowSet); 9973 return false; 9974 } 9975 9976 if (!psDBInsertRows(dbh, FAKERUN_TABLE_NAME, rowSet)) { 9977 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 9978 psFree(rowSet); 9979 return false; 9980 } 9981 9982 psFree(rowSet); 9983 9984 return true; 9985 } 9986 9987 bool fakeRunSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 9988 { 9989 psArray *rowSet; 9990 9991 rowSet = psDBSelectRows(dbh, FAKERUN_TABLE_NAME, where, limit); 9992 if (!rowSet) { 9993 return false; 9994 } 9995 9996 // output to fits 9997 if (!psFitsWriteTable(fits, NULL, rowSet, FAKERUN_TABLE_NAME)) { 9998 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 9999 psFree(rowSet); 10000 return false; 10001 } 10002 10003 psFree(rowSet); 10004 10005 return true; 10006 } 10007 10008 psMetadata *fakeRunMetadataFromObject(const fakeRunRow *object) 10009 { 10010 psMetadata *md = psMetadataAlloc(); 10011 if (!psMetadataAdd(md, PS_LIST_TAIL, "fake_id", PS_DATA_S64, NULL, object->fake_id)) { 10012 psError(PS_ERR_UNKNOWN, false, "failed to add item fake_id"); 10013 psFree(md); 10014 return false; 10015 } 10016 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, NULL, object->cam_id)) { 10017 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id"); 10018 psFree(md); 10019 return false; 10020 } 10021 if (!psMetadataAdd(md, PS_LIST_TAIL, "state", PS_DATA_STRING, NULL, object->state)) { 10022 psError(PS_ERR_UNKNOWN, false, "failed to add item state"); 10023 psFree(md); 10024 return false; 10025 } 10026 if (!psMetadataAdd(md, PS_LIST_TAIL, "workdir", PS_DATA_STRING, NULL, object->workdir)) { 10027 psError(PS_ERR_UNKNOWN, false, "failed to add item workdir"); 10028 psFree(md); 10029 return false; 10030 } 10031 if (!psMetadataAdd(md, PS_LIST_TAIL, "label", PS_DATA_STRING, NULL, object->label)) { 10032 psError(PS_ERR_UNKNOWN, false, "failed to add item label"); 10033 psFree(md); 10034 return false; 10035 } 10036 if (!psMetadataAdd(md, PS_LIST_TAIL, "reduction", PS_DATA_STRING, NULL, object->reduction)) { 10037 psError(PS_ERR_UNKNOWN, false, "failed to add item reduction"); 10038 psFree(md); 10039 return false; 10040 } 10041 if (!psMetadataAdd(md, PS_LIST_TAIL, "expgroup", PS_DATA_STRING, NULL, object->expgroup)) { 10042 psError(PS_ERR_UNKNOWN, false, "failed to add item expgroup"); 10043 psFree(md); 10044 return false; 10045 } 10046 if (!psMetadataAdd(md, PS_LIST_TAIL, "dvodb", PS_DATA_STRING, NULL, object->dvodb)) { 10047 psError(PS_ERR_UNKNOWN, false, "failed to add item dvodb"); 10048 psFree(md); 10049 return false; 10050 } 10051 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) { 10052 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 10053 psFree(md); 10054 return false; 10055 } 10056 if (!psMetadataAdd(md, PS_LIST_TAIL, "end_stage", PS_DATA_STRING, NULL, object->end_stage)) { 10057 psError(PS_ERR_UNKNOWN, false, "failed to add item end_stage"); 10058 psFree(md); 10059 return false; 10060 } 10061 if (!psMetadataAdd(md, PS_LIST_TAIL, "epoch", PS_DATA_TIME, NULL, object->epoch)) { 10062 psError(PS_ERR_UNKNOWN, false, "failed to add item epoch"); 10063 psFree(md); 10064 return false; 10065 } 10066 10067 10068 return md; 10069 } 10070 10071 fakeRunRow *fakeRunObjectFromMetadata(psMetadata *md) 10072 { 10073 10074 bool status = false; 10075 psS64 fake_id = psMetadataLookupS64(&status, md, "fake_id"); 10076 if (!status) { 10077 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item fake_id"); 10078 return false; 10079 } 10080 psS64 cam_id = psMetadataLookupS64(&status, md, "cam_id"); 10081 if (!status) { 10082 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item cam_id"); 10083 return false; 10084 } 10085 char* state = psMetadataLookupPtr(&status, md, "state"); 10086 if (!status) { 10087 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item state"); 10088 return false; 10089 } 10090 char* workdir = psMetadataLookupPtr(&status, md, "workdir"); 10091 if (!status) { 10092 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item workdir"); 10093 return false; 10094 } 10095 char* label = psMetadataLookupPtr(&status, md, "label"); 10096 if (!status) { 10097 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item label"); 10098 return false; 10099 } 10100 char* reduction = psMetadataLookupPtr(&status, md, "reduction"); 10101 if (!status) { 10102 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item reduction"); 10103 return false; 10104 } 10105 char* expgroup = psMetadataLookupPtr(&status, md, "expgroup"); 10106 if (!status) { 10107 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item expgroup"); 10108 return false; 10109 } 10110 char* dvodb = psMetadataLookupPtr(&status, md, "dvodb"); 10111 if (!status) { 10112 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item dvodb"); 10113 return false; 10114 } 10115 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id"); 10116 if (!status) { 10117 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id"); 10118 return false; 10119 } 10120 char* end_stage = psMetadataLookupPtr(&status, md, "end_stage"); 10121 if (!status) { 10122 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item end_stage"); 10123 return false; 10124 } 10125 psTime* epoch = psMetadataLookupPtr(&status, md, "epoch"); 10126 if (!status) { 10127 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item epoch"); 10128 return false; 10129 } 10130 10131 return fakeRunRowAlloc(fake_id, cam_id, state, workdir, label, reduction, expgroup, dvodb, tess_id, end_stage, epoch); 10132 } 10133 psArray *fakeRunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 10134 { 10135 psArray *rowSet; 10136 psArray *returnSet; 10137 psU64 i; 10138 10139 rowSet = psDBSelectRows(dbh, FAKERUN_TABLE_NAME, where, limit); 10140 if (!rowSet) { 10141 return NULL; 10142 } 10143 10144 // convert psMetadata rows to row objects 10145 10146 returnSet = psArrayAllocEmpty(rowSet->n); 10147 10148 for (i = 0; i < rowSet->n; i++) { 10149 fakeRunRow *object = fakeRunObjectFromMetadata(rowSet->data[i]); 10150 if (!object) { 10151 psFree(object); 10152 psFree(returnSet); 10153 psError(PS_ERR_UNKNOWN, false, "database error"); 10154 return NULL; 10155 } 10156 psArrayAdd(returnSet, 0, object); 10157 psFree(object); 10158 } 10159 10160 psFree(rowSet); 10161 10162 return returnSet; 10163 } 10164 bool fakeRunDeleteObject(psDB *dbh, const fakeRunRow *object) 10165 { 10166 psMetadata *where = fakeRunMetadataFromObject(object); 10167 long long count = psDBDeleteRows(dbh, FAKERUN_TABLE_NAME, where, 0); 10168 psFree(where); 10169 if (count < 0) { 10170 psError(PS_ERR_UNKNOWN, true, "failed to delete row from fakeRun"); 10171 return false; 10172 } 10173 if (count > 1) { 10174 // XXX should this be a psAbort() instead? It is possible that 10175 // having an object match multiple rows was by design. 10176 psError(PS_ERR_UNKNOWN, true, "fakeRunRow object matched more then one row. Check your database schema"); 10177 return false; 10178 } 10179 10180 return true; 10181 } 10182 long long fakeRunDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 10183 { 10184 long long deleted = 0; 10185 10186 for (long long i = 0; i < objects->n; i++) { 10187 fakeRunRow *object = objects->data[i]; 10188 psMetadata *where = fakeRunMetadataFromObject(object); 10189 long long count = psDBDeleteRows(dbh, FAKERUN_TABLE_NAME, where, limit); 10190 psFree(where); 10191 if (count < 0) { 10192 psError(PS_ERR_UNKNOWN, true, "failed to delete row from fakeRun"); 10193 return count; 10194 } 10195 10196 deleted += count; 10197 } 10198 10199 return deleted; 10200 } 10201 bool fakeRunPrintObjects(FILE *stream, psArray *objects, bool mdcf) 10202 { 10203 PS_ASSERT_PTR_NON_NULL(objects, false); 10204 10205 psMetadata *output = psMetadataAlloc(); 10206 for (long i = 0; i < psArrayLength(objects); i++) { 10207 psMetadata *md = fakeRunMetadataFromObject(objects->data[i]); 10208 if (!psMetadataAddMetadata( 10209 output, 10210 PS_LIST_TAIL, 10211 FAKERUN_TABLE_NAME, 10212 PS_META_DUPLICATE_OK, 10213 NULL, 10214 md 10215 )) { 10216 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 10217 psFree(md); 10218 psFree(output); 10219 return false; 10220 } 10221 psFree(md); 10222 } 10223 10224 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 10225 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 10226 psFree(output); 10227 } 10228 psFree(output); 10229 10230 return true; 10231 } 10232 bool fakeRunPrintObject(FILE *stream, fakeRunRow *object, bool mdcf) 10233 { 10234 PS_ASSERT_PTR_NON_NULL(object, false); 10235 10236 psMetadata *md = fakeRunMetadataFromObject(object); 10237 10238 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 10239 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 10240 psFree(md); 10241 } 10242 10243 psFree(md); 10244 10245 return true; 10246 } 10247 static void fakeProcessedImfileRowFree(fakeProcessedImfileRow *object); 10248 10249 fakeProcessedImfileRow *fakeProcessedImfileRowAlloc(psS64 fake_id, psS64 exp_id, const char *class_id, const char *uri, psF32 dtime_fake, const char *hostname, const char *path_base, psS16 fault, psTime* epoch) 10250 { 10251 fakeProcessedImfileRow *_object; 10252 10253 _object = psAlloc(sizeof(fakeProcessedImfileRow)); 10254 psMemSetDeallocator(_object, (psFreeFunc)fakeProcessedImfileRowFree); 10255 10256 _object->fake_id = fake_id; 10257 _object->exp_id = exp_id; 10258 _object->class_id = psStringCopy(class_id); 10259 _object->uri = psStringCopy(uri); 10260 _object->dtime_fake = dtime_fake; 10261 _object->hostname = psStringCopy(hostname); 10262 _object->path_base = psStringCopy(path_base); 10263 _object->fault = fault; 10264 _object->epoch = psTimeCopy(epoch); 10265 10266 return _object; 10267 } 10268 10269 static void fakeProcessedImfileRowFree(fakeProcessedImfileRow *object) 10270 { 10271 psFree(object->class_id); 10272 psFree(object->uri); 10273 psFree(object->hostname); 10274 psFree(object->path_base); 10275 psFree(object->epoch); 10276 } 10277 10278 bool fakeProcessedImfileCreateTable(psDB *dbh) 10279 { 10280 psMetadata *md = psMetadataAlloc(); 10281 if (!psMetadataAdd(md, PS_LIST_TAIL, "fake_id", PS_DATA_S64, "Primary Key fkey (fake_id) ref fakeRun(fake_id)", 0)) { 10282 psError(PS_ERR_UNKNOWN, false, "failed to add item fake_id"); 10283 psFree(md); 10284 return false; 10285 } 10286 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_id", PS_DATA_S64, "Primary Key fkey (exp_id, class_id) ref rawImfile(exp_id, class_id)", 64)) { 10287 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id"); 10288 psFree(md); 10289 return false; 10290 } 10291 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, "Primary Key", "64")) { 10292 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 10293 psFree(md); 10294 return false; 10295 } 10296 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) { 10297 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 10298 psFree(md); 10299 return false; 10300 } 10301 if (!psMetadataAdd(md, PS_LIST_TAIL, "dtime_fake", PS_DATA_F32, NULL, 0.0)) { 10302 psError(PS_ERR_UNKNOWN, false, "failed to add item dtime_fake"); 10303 psFree(md); 10304 return false; 10305 } 10306 if (!psMetadataAdd(md, PS_LIST_TAIL, "hostname", PS_DATA_STRING, NULL, "64")) { 10307 psError(PS_ERR_UNKNOWN, false, "failed to add item hostname"); 10308 psFree(md); 10309 return false; 10310 } 10311 if (!psMetadataAdd(md, PS_LIST_TAIL, "path_base", PS_DATA_STRING, NULL, "255")) { 10312 psError(PS_ERR_UNKNOWN, false, "failed to add item path_base"); 10313 psFree(md); 10314 return false; 10315 } 10316 if (!psMetadataAdd(md, PS_LIST_TAIL, "fault", PS_DATA_S16, "Key NOT NULL", 0)) { 10317 psError(PS_ERR_UNKNOWN, false, "failed to add item fault"); 10318 psFree(md); 10319 return false; 10320 } 10321 if (!psMetadataAdd(md, PS_LIST_TAIL, "epoch", PS_DATA_TIME, NULL, NULL)) { 10322 psError(PS_ERR_UNKNOWN, false, "failed to add item epoch"); 10323 psFree(md); 10324 return false; 10325 } 10326 10327 bool status = psDBCreateTable(dbh, FAKEPROCESSEDIMFILE_TABLE_NAME, md); 10328 10329 psFree(md); 10330 10331 return status; 10332 } 10333 10334 bool fakeProcessedImfileDropTable(psDB *dbh) 10335 { 10336 return psDBDropTable(dbh, FAKEPROCESSEDIMFILE_TABLE_NAME); 10337 } 10338 10339 bool fakeProcessedImfileInsert(psDB * dbh, psS64 fake_id, psS64 exp_id, const char *class_id, const char *uri, psF32 dtime_fake, const char *hostname, const char *path_base, psS16 fault, psTime* epoch) 10340 { 10341 psMetadata *md = psMetadataAlloc(); 10342 if (!psMetadataAdd(md, PS_LIST_TAIL, "fake_id", PS_DATA_S64, NULL, fake_id)) { 10343 psError(PS_ERR_UNKNOWN, false, "failed to add item fake_id"); 10344 psFree(md); 10345 return false; 10346 } 10347 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_id", PS_DATA_S64, NULL, exp_id)) { 10348 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id"); 10349 psFree(md); 10350 return false; 10351 } 10352 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, class_id)) { 10353 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 10354 psFree(md); 10355 return false; 10356 } 10357 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) { 10358 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 10359 psFree(md); 10360 return false; 10361 } 10362 if (!psMetadataAdd(md, PS_LIST_TAIL, "dtime_fake", PS_DATA_F32, NULL, dtime_fake)) { 10363 psError(PS_ERR_UNKNOWN, false, "failed to add item dtime_fake"); 10364 psFree(md); 10365 return false; 10366 } 10367 if (!psMetadataAdd(md, PS_LIST_TAIL, "hostname", PS_DATA_STRING, NULL, hostname)) { 10368 psError(PS_ERR_UNKNOWN, false, "failed to add item hostname"); 10369 psFree(md); 10370 return false; 10371 } 10372 if (!psMetadataAdd(md, PS_LIST_TAIL, "path_base", PS_DATA_STRING, NULL, path_base)) { 10373 psError(PS_ERR_UNKNOWN, false, "failed to add item path_base"); 10374 psFree(md); 10375 return false; 10376 } 10377 if (!psMetadataAdd(md, PS_LIST_TAIL, "fault", PS_DATA_S16, NULL, fault)) { 10378 psError(PS_ERR_UNKNOWN, false, "failed to add item fault"); 10379 psFree(md); 10380 return false; 10381 } 10382 if (!psMetadataAdd(md, PS_LIST_TAIL, "epoch", PS_DATA_TIME, NULL, epoch)) { 10383 psError(PS_ERR_UNKNOWN, false, "failed to add item epoch"); 10384 psFree(md); 10385 return false; 10386 } 10387 10388 bool status = psDBInsertOneRow(dbh, FAKEPROCESSEDIMFILE_TABLE_NAME, md); 10389 psFree(md); 10390 10391 return status; 10392 } 10393 10394 long long fakeProcessedImfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 10395 { 10396 long long deleted = 0; 10397 10398 long long count = psDBDeleteRows(dbh, FAKEPROCESSEDIMFILE_TABLE_NAME, where, limit); 10399 if (count < 0) { 10400 psError(PS_ERR_UNKNOWN, true, "failed to delete row from fakeProcessedImfile"); 10401 return count; 10402 10403 deleted += count; 10404 } 10405 10406 return deleted; 10407 } 10408 bool fakeProcessedImfileInsertObject(psDB *dbh, fakeProcessedImfileRow *object) 10409 { 10410 return fakeProcessedImfileInsert(dbh, object->fake_id, object->exp_id, object->class_id, object->uri, object->dtime_fake, object->hostname, object->path_base, object->fault, object->epoch); 10411 } 10412 10413 bool fakeProcessedImfileInsertObjects(psDB *dbh, psArray *objects) 10414 { 10415 for (long i = 0; i < psArrayLength(objects); i++) { 10416 if (!fakeProcessedImfileInsertObject(dbh, objects->data[i])) { 10417 return false; 10418 } 10419 } 10420 10421 return true; 10422 } 10423 10424 bool fakeProcessedImfileInsertFits(psDB *dbh, const psFits *fits) 10425 { 10426 psArray *rowSet; 10427 10428 // move to (the first?) extension named FAKEPROCESSEDIMFILE_TABLE_NAME 10429 if (!psFitsMoveExtName(fits, FAKEPROCESSEDIMFILE_TABLE_NAME)) { 10430 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", FAKEPROCESSEDIMFILE_TABLE_NAME); 10431 return false; 10432 } 10433 10434 // check HDU type 10435 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 10436 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 10437 return false; 10438 } 10439 10440 // read fits table 10441 rowSet = psFitsReadTable(fits); 10442 if (!rowSet) { 10443 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 10444 psFree(rowSet); 10445 return false; 10446 } 10447 10448 if (!psDBInsertRows(dbh, FAKEPROCESSEDIMFILE_TABLE_NAME, rowSet)) { 10449 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 10450 psFree(rowSet); 10451 return false; 10452 } 10453 10454 psFree(rowSet); 10455 10456 return true; 10457 } 10458 10459 bool fakeProcessedImfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 10460 { 10461 psArray *rowSet; 10462 10463 rowSet = psDBSelectRows(dbh, FAKEPROCESSEDIMFILE_TABLE_NAME, where, limit); 10464 if (!rowSet) { 10465 return false; 10466 } 10467 10468 // output to fits 10469 if (!psFitsWriteTable(fits, NULL, rowSet, FAKEPROCESSEDIMFILE_TABLE_NAME)) { 10470 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 10471 psFree(rowSet); 10472 return false; 10473 } 10474 10475 psFree(rowSet); 10476 10477 return true; 10478 } 10479 10480 psMetadata *fakeProcessedImfileMetadataFromObject(const fakeProcessedImfileRow *object) 10481 { 10482 psMetadata *md = psMetadataAlloc(); 10483 if (!psMetadataAdd(md, PS_LIST_TAIL, "fake_id", PS_DATA_S64, NULL, object->fake_id)) { 10484 psError(PS_ERR_UNKNOWN, false, "failed to add item fake_id"); 10485 psFree(md); 10486 return false; 10487 } 10488 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_id", PS_DATA_S64, NULL, object->exp_id)) { 10489 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id"); 10490 psFree(md); 10491 return false; 10492 } 10493 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, object->class_id)) { 10494 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 10495 psFree(md); 10496 return false; 10497 } 10498 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) { 10499 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 10500 psFree(md); 10501 return false; 10502 } 10503 if (!psMetadataAdd(md, PS_LIST_TAIL, "dtime_fake", PS_DATA_F32, NULL, object->dtime_fake)) { 10504 psError(PS_ERR_UNKNOWN, false, "failed to add item dtime_fake"); 10505 psFree(md); 10506 return false; 10507 } 10508 if (!psMetadataAdd(md, PS_LIST_TAIL, "hostname", PS_DATA_STRING, NULL, object->hostname)) { 10509 psError(PS_ERR_UNKNOWN, false, "failed to add item hostname"); 10510 psFree(md); 10511 return false; 10512 } 10513 if (!psMetadataAdd(md, PS_LIST_TAIL, "path_base", PS_DATA_STRING, NULL, object->path_base)) { 10514 psError(PS_ERR_UNKNOWN, false, "failed to add item path_base"); 10515 psFree(md); 10516 return false; 10517 } 10518 if (!psMetadataAdd(md, PS_LIST_TAIL, "fault", PS_DATA_S16, NULL, object->fault)) { 10519 psError(PS_ERR_UNKNOWN, false, "failed to add item fault"); 10520 psFree(md); 10521 return false; 10522 } 10523 if (!psMetadataAdd(md, PS_LIST_TAIL, "epoch", PS_DATA_TIME, NULL, object->epoch)) { 10524 psError(PS_ERR_UNKNOWN, false, "failed to add item epoch"); 10525 psFree(md); 10526 return false; 10527 } 10528 10529 10530 return md; 10531 } 10532 10533 fakeProcessedImfileRow *fakeProcessedImfileObjectFromMetadata(psMetadata *md) 10534 { 10535 10536 bool status = false; 10537 psS64 fake_id = psMetadataLookupS64(&status, md, "fake_id"); 10538 if (!status) { 10539 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item fake_id"); 10540 return false; 10541 } 10542 psS64 exp_id = psMetadataLookupS64(&status, md, "exp_id"); 10543 if (!status) { 10544 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_id"); 10545 return false; 10546 } 10547 char* class_id = psMetadataLookupPtr(&status, md, "class_id"); 10548 if (!status) { 10549 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item class_id"); 10550 return false; 10551 } 10552 char* uri = psMetadataLookupPtr(&status, md, "uri"); 10553 if (!status) { 10554 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri"); 10555 return false; 10556 } 10557 psF32 dtime_fake = psMetadataLookupF32(&status, md, "dtime_fake"); 10558 if (!status) { 10559 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item dtime_fake"); 10560 return false; 10561 } 10562 char* hostname = psMetadataLookupPtr(&status, md, "hostname"); 10563 if (!status) { 10564 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item hostname"); 10565 return false; 10566 } 10567 char* path_base = psMetadataLookupPtr(&status, md, "path_base"); 10568 if (!status) { 10569 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item path_base"); 10570 return false; 10571 } 10572 psS16 fault = psMetadataLookupS16(&status, md, "fault"); 10573 if (!status) { 10574 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item fault"); 10575 return false; 10576 } 10577 psTime* epoch = psMetadataLookupPtr(&status, md, "epoch"); 10578 if (!status) { 10579 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item epoch"); 10580 return false; 10581 } 10582 10583 return fakeProcessedImfileRowAlloc(fake_id, exp_id, class_id, uri, dtime_fake, hostname, path_base, fault, epoch); 10584 } 10585 psArray *fakeProcessedImfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 10586 { 10587 psArray *rowSet; 10588 psArray *returnSet; 10589 psU64 i; 10590 10591 rowSet = psDBSelectRows(dbh, FAKEPROCESSEDIMFILE_TABLE_NAME, where, limit); 10592 if (!rowSet) { 10593 return NULL; 10594 } 10595 10596 // convert psMetadata rows to row objects 10597 10598 returnSet = psArrayAllocEmpty(rowSet->n); 10599 10600 for (i = 0; i < rowSet->n; i++) { 10601 fakeProcessedImfileRow *object = fakeProcessedImfileObjectFromMetadata(rowSet->data[i]); 10602 if (!object) { 10603 psFree(object); 10604 psFree(returnSet); 10605 psError(PS_ERR_UNKNOWN, false, "database error"); 10606 return NULL; 10607 } 10608 psArrayAdd(returnSet, 0, object); 10609 psFree(object); 10610 } 10611 10612 psFree(rowSet); 10613 10614 return returnSet; 10615 } 10616 bool fakeProcessedImfileDeleteObject(psDB *dbh, const fakeProcessedImfileRow *object) 10617 { 10618 psMetadata *where = fakeProcessedImfileMetadataFromObject(object); 10619 long long count = psDBDeleteRows(dbh, FAKEPROCESSEDIMFILE_TABLE_NAME, where, 0); 10620 psFree(where); 10621 if (count < 0) { 10622 psError(PS_ERR_UNKNOWN, true, "failed to delete row from fakeProcessedImfile"); 10623 return false; 10624 } 10625 if (count > 1) { 10626 // XXX should this be a psAbort() instead? It is possible that 10627 // having an object match multiple rows was by design. 10628 psError(PS_ERR_UNKNOWN, true, "fakeProcessedImfileRow object matched more then one row. Check your database schema"); 10629 return false; 10630 } 10631 10632 return true; 10633 } 10634 long long fakeProcessedImfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 10635 { 10636 long long deleted = 0; 10637 10638 for (long long i = 0; i < objects->n; i++) { 10639 fakeProcessedImfileRow *object = objects->data[i]; 10640 psMetadata *where = fakeProcessedImfileMetadataFromObject(object); 10641 long long count = psDBDeleteRows(dbh, FAKEPROCESSEDIMFILE_TABLE_NAME, where, limit); 10642 psFree(where); 10643 if (count < 0) { 10644 psError(PS_ERR_UNKNOWN, true, "failed to delete row from fakeProcessedImfile"); 10645 return count; 10646 } 10647 10648 deleted += count; 10649 } 10650 10651 return deleted; 10652 } 10653 bool fakeProcessedImfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 10654 { 10655 PS_ASSERT_PTR_NON_NULL(objects, false); 10656 10657 psMetadata *output = psMetadataAlloc(); 10658 for (long i = 0; i < psArrayLength(objects); i++) { 10659 psMetadata *md = fakeProcessedImfileMetadataFromObject(objects->data[i]); 10660 if (!psMetadataAddMetadata( 10661 output, 10662 PS_LIST_TAIL, 10663 FAKEPROCESSEDIMFILE_TABLE_NAME, 10664 PS_META_DUPLICATE_OK, 10665 NULL, 10666 md 10667 )) { 10668 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 10669 psFree(md); 10670 psFree(output); 10671 return false; 10672 } 10673 psFree(md); 10674 } 10675 10676 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 10677 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 10678 psFree(output); 10679 } 10680 psFree(output); 10681 10682 return true; 10683 } 10684 bool fakeProcessedImfilePrintObject(FILE *stream, fakeProcessedImfileRow *object, bool mdcf) 10685 { 10686 PS_ASSERT_PTR_NON_NULL(object, false); 10687 10688 psMetadata *md = fakeProcessedImfileMetadataFromObject(object); 10689 10690 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 10691 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 10692 psFree(md); 10693 } 10694 10695 psFree(md); 10696 10697 return true; 10698 } 10699 static void fakeMaskRowFree(fakeMaskRow *object); 10700 10701 fakeMaskRow *fakeMaskRowAlloc(const char *label) 10702 { 10703 fakeMaskRow *_object; 10704 10705 _object = psAlloc(sizeof(fakeMaskRow)); 10706 psMemSetDeallocator(_object, (psFreeFunc)fakeMaskRowFree); 10707 10708 _object->label = psStringCopy(label); 10709 10710 return _object; 10711 } 10712 10713 static void fakeMaskRowFree(fakeMaskRow *object) 10714 { 10715 psFree(object->label); 10716 } 10717 10718 bool fakeMaskCreateTable(psDB *dbh) 10719 { 10720 psMetadata *md = psMetadataAlloc(); 10721 if (!psMetadataAdd(md, PS_LIST_TAIL, "label", PS_DATA_STRING, "Primary Key", "64")) { 10722 psError(PS_ERR_UNKNOWN, false, "failed to add item label"); 10723 psFree(md); 10724 return false; 10725 } 10726 10727 bool status = psDBCreateTable(dbh, FAKEMASK_TABLE_NAME, md); 10728 10729 psFree(md); 10730 10731 return status; 10732 } 10733 10734 bool fakeMaskDropTable(psDB *dbh) 10735 { 10736 return psDBDropTable(dbh, FAKEMASK_TABLE_NAME); 10737 } 10738 10739 bool fakeMaskInsert(psDB * dbh, const char *label) 10740 { 10741 psMetadata *md = psMetadataAlloc(); 10742 if (!psMetadataAdd(md, PS_LIST_TAIL, "label", PS_DATA_STRING, NULL, label)) { 10743 psError(PS_ERR_UNKNOWN, false, "failed to add item label"); 10744 psFree(md); 10745 return false; 10746 } 10747 10748 bool status = psDBInsertOneRow(dbh, FAKEMASK_TABLE_NAME, md); 10749 psFree(md); 10750 10751 return status; 10752 } 10753 10754 long long fakeMaskDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 10755 { 10756 long long deleted = 0; 10757 10758 long long count = psDBDeleteRows(dbh, FAKEMASK_TABLE_NAME, where, limit); 10759 if (count < 0) { 10760 psError(PS_ERR_UNKNOWN, true, "failed to delete row from fakeMask"); 10761 return count; 10762 10763 deleted += count; 10764 } 10765 10766 return deleted; 10767 } 10768 bool fakeMaskInsertObject(psDB *dbh, fakeMaskRow *object) 10769 { 10770 return fakeMaskInsert(dbh, object->label); 10771 } 10772 10773 bool fakeMaskInsertObjects(psDB *dbh, psArray *objects) 10774 { 10775 for (long i = 0; i < psArrayLength(objects); i++) { 10776 if (!fakeMaskInsertObject(dbh, objects->data[i])) { 10777 return false; 10778 } 10779 } 10780 10781 return true; 10782 } 10783 10784 bool fakeMaskInsertFits(psDB *dbh, const psFits *fits) 10785 { 10786 psArray *rowSet; 10787 10788 // move to (the first?) extension named FAKEMASK_TABLE_NAME 10789 if (!psFitsMoveExtName(fits, FAKEMASK_TABLE_NAME)) { 10790 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", FAKEMASK_TABLE_NAME); 10791 return false; 10792 } 10793 10794 // check HDU type 10795 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 10796 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 10797 return false; 10798 } 10799 10800 // read fits table 10801 rowSet = psFitsReadTable(fits); 10802 if (!rowSet) { 10803 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 10804 psFree(rowSet); 10805 return false; 10806 } 10807 10808 if (!psDBInsertRows(dbh, FAKEMASK_TABLE_NAME, rowSet)) { 10809 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 10810 psFree(rowSet); 10811 return false; 10812 } 10813 10814 psFree(rowSet); 10815 10816 return true; 10817 } 10818 10819 bool fakeMaskSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 10820 { 10821 psArray *rowSet; 10822 10823 rowSet = psDBSelectRows(dbh, FAKEMASK_TABLE_NAME, where, limit); 10824 if (!rowSet) { 10825 return false; 10826 } 10827 10828 // output to fits 10829 if (!psFitsWriteTable(fits, NULL, rowSet, FAKEMASK_TABLE_NAME)) { 10830 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 10831 psFree(rowSet); 10832 return false; 10833 } 10834 10835 psFree(rowSet); 10836 10837 return true; 10838 } 10839 10840 psMetadata *fakeMaskMetadataFromObject(const fakeMaskRow *object) 10841 { 10842 psMetadata *md = psMetadataAlloc(); 10843 if (!psMetadataAdd(md, PS_LIST_TAIL, "label", PS_DATA_STRING, NULL, object->label)) { 10844 psError(PS_ERR_UNKNOWN, false, "failed to add item label"); 10845 psFree(md); 10846 return false; 10847 } 10848 10849 10850 return md; 10851 } 10852 10853 fakeMaskRow *fakeMaskObjectFromMetadata(psMetadata *md) 10854 { 10855 10856 bool status = false; 10857 char* label = psMetadataLookupPtr(&status, md, "label"); 10858 if (!status) { 10859 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item label"); 10860 return false; 10861 } 10862 10863 return fakeMaskRowAlloc(label); 10864 } 10865 psArray *fakeMaskSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 10866 { 10867 psArray *rowSet; 10868 psArray *returnSet; 10869 psU64 i; 10870 10871 rowSet = psDBSelectRows(dbh, FAKEMASK_TABLE_NAME, where, limit); 10872 if (!rowSet) { 10873 return NULL; 10874 } 10875 10876 // convert psMetadata rows to row objects 10877 10878 returnSet = psArrayAllocEmpty(rowSet->n); 10879 10880 for (i = 0; i < rowSet->n; i++) { 10881 fakeMaskRow *object = fakeMaskObjectFromMetadata(rowSet->data[i]); 10882 if (!object) { 10883 psFree(object); 10884 psFree(returnSet); 10885 psError(PS_ERR_UNKNOWN, false, "database error"); 10886 return NULL; 10887 } 10888 psArrayAdd(returnSet, 0, object); 10889 psFree(object); 10890 } 10891 10892 psFree(rowSet); 10893 10894 return returnSet; 10895 } 10896 bool fakeMaskDeleteObject(psDB *dbh, const fakeMaskRow *object) 10897 { 10898 psMetadata *where = fakeMaskMetadataFromObject(object); 10899 long long count = psDBDeleteRows(dbh, FAKEMASK_TABLE_NAME, where, 0); 10900 psFree(where); 10901 if (count < 0) { 10902 psError(PS_ERR_UNKNOWN, true, "failed to delete row from fakeMask"); 10903 return false; 10904 } 10905 if (count > 1) { 10906 // XXX should this be a psAbort() instead? It is possible that 10907 // having an object match multiple rows was by design. 10908 psError(PS_ERR_UNKNOWN, true, "fakeMaskRow object matched more then one row. Check your database schema"); 10909 return false; 10910 } 10911 10912 return true; 10913 } 10914 long long fakeMaskDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 10915 { 10916 long long deleted = 0; 10917 10918 for (long long i = 0; i < objects->n; i++) { 10919 fakeMaskRow *object = objects->data[i]; 10920 psMetadata *where = fakeMaskMetadataFromObject(object); 10921 long long count = psDBDeleteRows(dbh, FAKEMASK_TABLE_NAME, where, limit); 10922 psFree(where); 10923 if (count < 0) { 10924 psError(PS_ERR_UNKNOWN, true, "failed to delete row from fakeMask"); 10925 return count; 10926 } 10927 10928 deleted += count; 10929 } 10930 10931 return deleted; 10932 } 10933 bool fakeMaskPrintObjects(FILE *stream, psArray *objects, bool mdcf) 10934 { 10935 PS_ASSERT_PTR_NON_NULL(objects, false); 10936 10937 psMetadata *output = psMetadataAlloc(); 10938 for (long i = 0; i < psArrayLength(objects); i++) { 10939 psMetadata *md = fakeMaskMetadataFromObject(objects->data[i]); 10940 if (!psMetadataAddMetadata( 10941 output, 10942 PS_LIST_TAIL, 10943 FAKEMASK_TABLE_NAME, 10944 PS_META_DUPLICATE_OK, 10945 NULL, 10946 md 10947 )) { 10948 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 10949 psFree(md); 10950 psFree(output); 10951 return false; 10952 } 10953 psFree(md); 10954 } 10955 10956 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 10957 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 10958 psFree(output); 10959 } 10960 psFree(output); 10961 10962 return true; 10963 } 10964 bool fakeMaskPrintObject(FILE *stream, fakeMaskRow *object, bool mdcf) 10965 { 10966 PS_ASSERT_PTR_NON_NULL(object, false); 10967 10968 psMetadata *md = fakeMaskMetadataFromObject(object); 10969 10970 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { 10971 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 10972 psFree(md); 10973 } 10974 10975 psFree(md); 10976 10977 return true; 10978 } 9767 10979 static void warpRunRowFree(warpRunRow *object); 9768 10980 9769 warpRunRow *warpRunRowAlloc(psS64 warp_id, psS64 cam_id, const char *mode, const char *state, const char *workdir, const char *workdir_state, const char *label, const char *dvodb, const char *tess_id, const char *end_stage, psTime* registered, bool magiced)10981 warpRunRow *warpRunRowAlloc(psS64 warp_id, psS64 fake_id, const char *mode, const char *state, const char *workdir, const char *workdir_state, const char *label, const char *dvodb, const char *tess_id, const char *end_stage, psTime* registered, bool magiced) 9770 10982 { 9771 10983 warpRunRow *_object; … … 9775 10987 9776 10988 _object->warp_id = warp_id; 9777 _object-> cam_id = cam_id;10989 _object->fake_id = fake_id; 9778 10990 _object->mode = psStringCopy(mode); 9779 10991 _object->state = psStringCopy(state); … … 9811 11023 return false; 9812 11024 } 9813 if (!psMetadataAdd(md, PS_LIST_TAIL, " cam_id", PS_DATA_S64, "Key INDEX(warp_id, cam_id) fkey(cam_id) ref camProcessedExp(cam_id)", 0)) {9814 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");11025 if (!psMetadataAdd(md, PS_LIST_TAIL, "fake_id", PS_DATA_S64, "Key INDEX(warp_id, fake_id) fkey(fake_id) ref camProcessedExp(fake_id)", 0)) { 11026 psError(PS_ERR_UNKNOWN, false, "failed to add item fake_id"); 9815 11027 psFree(md); 9816 11028 return false; … … 9879 11091 } 9880 11092 9881 bool warpRunInsert(psDB * dbh, psS64 warp_id, psS64 cam_id, const char *mode, const char *state, const char *workdir, const char *workdir_state, const char *label, const char *dvodb, const char *tess_id, const char *end_stage, psTime* registered, bool magiced)11093 bool warpRunInsert(psDB * dbh, psS64 warp_id, psS64 fake_id, const char *mode, const char *state, const char *workdir, const char *workdir_state, const char *label, const char *dvodb, const char *tess_id, const char *end_stage, psTime* registered, bool magiced) 9882 11094 { 9883 11095 psMetadata *md = psMetadataAlloc(); … … 9887 11099 return false; 9888 11100 } 9889 if (!psMetadataAdd(md, PS_LIST_TAIL, " cam_id", PS_DATA_S64, NULL, cam_id)) {9890 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");11101 if (!psMetadataAdd(md, PS_LIST_TAIL, "fake_id", PS_DATA_S64, NULL, fake_id)) { 11102 psError(PS_ERR_UNKNOWN, false, "failed to add item fake_id"); 9891 11103 psFree(md); 9892 11104 return false; … … 9965 11177 bool warpRunInsertObject(psDB *dbh, warpRunRow *object) 9966 11178 { 9967 return warpRunInsert(dbh, object->warp_id, object-> cam_id, object->mode, object->state, object->workdir, object->workdir_state, object->label, object->dvodb, object->tess_id, object->end_stage, object->registered, object->magiced);11179 return warpRunInsert(dbh, object->warp_id, object->fake_id, object->mode, object->state, object->workdir, object->workdir_state, object->label, object->dvodb, object->tess_id, object->end_stage, object->registered, object->magiced); 9968 11180 } 9969 11181 … … 10043 11255 return false; 10044 11256 } 10045 if (!psMetadataAdd(md, PS_LIST_TAIL, " cam_id", PS_DATA_S64, NULL, object->cam_id)) {10046 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");11257 if (!psMetadataAdd(md, PS_LIST_TAIL, "fake_id", PS_DATA_S64, NULL, object->fake_id)) { 11258 psError(PS_ERR_UNKNOWN, false, "failed to add item fake_id"); 10047 11259 psFree(md); 10048 11260 return false; … … 10112 11324 return false; 10113 11325 } 10114 psS64 cam_id = psMetadataLookupS64(&status, md, "cam_id");10115 if (!status) { 10116 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item cam_id");11326 psS64 fake_id = psMetadataLookupS64(&status, md, "fake_id"); 11327 if (!status) { 11328 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item fake_id"); 10117 11329 return false; 10118 11330 } … … 10168 11380 } 10169 11381 10170 return warpRunRowAlloc(warp_id, cam_id, mode, state, workdir, workdir_state, label, dvodb, tess_id, end_stage, registered, magiced);11382 return warpRunRowAlloc(warp_id, fake_id, mode, state, workdir, workdir_state, label, dvodb, tess_id, end_stage, registered, magiced); 10171 11383 } 10172 11384 psArray *warpRunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) … … 10286 11498 static void warpSkyCellMapRowFree(warpSkyCellMapRow *object); 10287 11499 10288 warpSkyCellMapRow *warpSkyCellMapRowAlloc(psS64 warp_id, const char *skycell_id, const char *tess_id, psS64 cam_id,const char *class_id, psS16 fault)11500 warpSkyCellMapRow *warpSkyCellMapRowAlloc(psS64 warp_id, const char *skycell_id, const char *tess_id, const char *class_id, psS16 fault) 10289 11501 { 10290 11502 warpSkyCellMapRow *_object; … … 10296 11508 _object->skycell_id = psStringCopy(skycell_id); 10297 11509 _object->tess_id = psStringCopy(tess_id); 10298 _object->cam_id = cam_id;10299 11510 _object->class_id = psStringCopy(class_id); 10300 11511 _object->fault = fault; … … 10313 11524 { 10314 11525 psMetadata *md = psMetadataAlloc(); 10315 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, "Primary Key fkey(warp_id , cam_id) ref warpRun(warp_id, cam_id)", 0)) {11526 if (!psMetadataAdd(md, PS_LIST_TAIL, "warp_id", PS_DATA_S64, "Primary Key fkey(warp_id) ref warpRun(warp_id)", 0)) { 10316 11527 psError(PS_ERR_UNKNOWN, false, "failed to add item warp_id"); 10317 11528 psFree(md); … … 10328 11539 return false; 10329 11540 } 10330 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, "Primary Key", 0)) {10331 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");10332 psFree(md);10333 return false;10334 }10335 11541 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, "Primary Key", "64")) { 10336 11542 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); … … 10356 11562 } 10357 11563 10358 bool warpSkyCellMapInsert(psDB * dbh, psS64 warp_id, const char *skycell_id, const char *tess_id, psS64 cam_id,const char *class_id, psS16 fault)11564 bool warpSkyCellMapInsert(psDB * dbh, psS64 warp_id, const char *skycell_id, const char *tess_id, const char *class_id, psS16 fault) 10359 11565 { 10360 11566 psMetadata *md = psMetadataAlloc(); … … 10371 11577 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) { 10372 11578 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 10373 psFree(md);10374 return false;10375 }10376 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, NULL, cam_id)) {10377 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");10378 11579 psFree(md); 10379 11580 return false; … … 10412 11613 bool warpSkyCellMapInsertObject(psDB *dbh, warpSkyCellMapRow *object) 10413 11614 { 10414 return warpSkyCellMapInsert(dbh, object->warp_id, object->skycell_id, object->tess_id, object->c am_id, object->class_id, object->fault);11615 return warpSkyCellMapInsert(dbh, object->warp_id, object->skycell_id, object->tess_id, object->class_id, object->fault); 10415 11616 } 10416 11617 … … 10500 11701 return false; 10501 11702 } 10502 if (!psMetadataAdd(md, PS_LIST_TAIL, "cam_id", PS_DATA_S64, NULL, object->cam_id)) {10503 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");10504 psFree(md);10505 return false;10506 }10507 11703 if (!psMetadataAdd(md, PS_LIST_TAIL, "class_id", PS_DATA_STRING, NULL, object->class_id)) { 10508 11704 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); … … 10539 11735 return false; 10540 11736 } 10541 psS64 cam_id = psMetadataLookupS64(&status, md, "cam_id");10542 if (!status) {10543 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item cam_id");10544 return false;10545 }10546 11737 char* class_id = psMetadataLookupPtr(&status, md, "class_id"); 10547 11738 if (!status) { … … 10555 11746 } 10556 11747 10557 return warpSkyCellMapRowAlloc(warp_id, skycell_id, tess_id, c am_id, class_id, fault);11748 return warpSkyCellMapRowAlloc(warp_id, skycell_id, tess_id, class_id, fault); 10558 11749 } 10559 11750 psArray *warpSkyCellMapSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) -
trunk/ippdb/src/ippdb.h
r17872 r18044 3483 3483 typedef struct { 3484 3484 psS64 cam_id; 3485 psS64 chip_id;3486 3485 char *uri; 3487 3486 psF32 bg; … … 3520 3519 camProcessedExpRow *camProcessedExpRowAlloc( 3521 3520 psS64 cam_id, 3522 psS64 chip_id,3523 3521 const char *uri, 3524 3522 psF32 bg, … … 3578 3576 psDB *dbh, ///< Database handle 3579 3577 psS64 cam_id, 3580 psS64 chip_id,3581 3578 const char *uri, 3582 3579 psF32 bg, … … 3950 3947 bool mdcf ///< format as mdconfig or simple 3951 3948 ); 3949 /** fakeRunRow data structure 3950 * 3951 * Structure for representing a single row of fakeRun table data. 3952 */ 3953 3954 typedef struct { 3955 psS64 fake_id; 3956 psS64 cam_id; 3957 char *state; 3958 char *workdir; 3959 char *label; 3960 char *reduction; 3961 char *expgroup; 3962 char *dvodb; 3963 char *tess_id; 3964 char *end_stage; 3965 psTime* epoch; 3966 } fakeRunRow; 3967 3968 /** Creates a new fakeRunRow object 3969 * 3970 * @return A new fakeRunRow object or NULL on failure. 3971 */ 3972 3973 fakeRunRow *fakeRunRowAlloc( 3974 psS64 fake_id, 3975 psS64 cam_id, 3976 const char *state, 3977 const char *workdir, 3978 const char *label, 3979 const char *reduction, 3980 const char *expgroup, 3981 const char *dvodb, 3982 const char *tess_id, 3983 const char *end_stage, 3984 psTime* epoch 3985 ); 3986 3987 /** Creates a new fakeRun table 3988 * 3989 * @return true on success 3990 */ 3991 3992 bool fakeRunCreateTable( 3993 psDB *dbh ///< Database handle 3994 ); 3995 3996 /** Deletes a fakeRun table 3997 * 3998 * @return true on success 3999 */ 4000 4001 bool fakeRunDropTable( 4002 psDB *dbh ///< Database handle 4003 ); 4004 4005 /** Insert a single row into a table 4006 * 4007 * This function constructs and inserts a single row based on it's parameters. 4008 * 4009 * @return true on success 4010 */ 4011 4012 bool fakeRunInsert( 4013 psDB *dbh, ///< Database handle 4014 psS64 fake_id, 4015 psS64 cam_id, 4016 const char *state, 4017 const char *workdir, 4018 const char *label, 4019 const char *reduction, 4020 const char *expgroup, 4021 const char *dvodb, 4022 const char *tess_id, 4023 const char *end_stage, 4024 psTime* epoch 4025 ); 4026 4027 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 4028 * 4029 * @return A The number of rows removed or a negative value on error 4030 */ 4031 4032 long long fakeRunDelete( 4033 psDB *dbh, ///< Database handle 4034 const psMetadata *where, ///< Row match criteria 4035 unsigned long long limit ///< Maximum number of elements to delete 4036 ); 4037 4038 /** Insert a single fakeRunRow object into a table 4039 * 4040 * This function constructs and inserts a single row based on it's parameters. 4041 * 4042 * @return true on success 4043 */ 4044 4045 bool fakeRunInsertObject( 4046 psDB *dbh, ///< Database handle 4047 fakeRunRow *object ///< fakeRunRow object 4048 ); 4049 4050 /** Insert an array of fakeRunRow object into a table 4051 * 4052 * This function constructs and inserts multiple rows based on it's parameters. 4053 * 4054 * @return true on success 4055 */ 4056 4057 bool fakeRunInsertObjects( 4058 psDB *dbh, ///< Database handle 4059 psArray *objects ///< array of fakeRunRow objects 4060 ); 4061 4062 /** Insert data from a binary FITS table fakeRunRow into the database 4063 * 4064 * This function expects a psFits object with a FITS table as the first 4065 * extension. The table must have at least one row of data in it, that is of 4066 * the appropriate format (number of columns and their type). All other 4067 * extensions are ignored. 4068 * 4069 * @return true on success 4070 */ 4071 4072 bool fakeRunInsertFits( 4073 psDB *dbh, ///< Database handle 4074 const psFits *fits ///< psFits object 4075 ); 4076 4077 /** Selects up to limit from the database and returns them in a binary FITS table 4078 * 4079 * This function assumes an empty psFits object and will create a FITS table 4080 * as the first extension. 4081 * 4082 * See psDBSelectRows() for documentation on the format of where. 4083 * 4084 * @return true on success 4085 */ 4086 4087 bool fakeRunSelectRowsFits( 4088 psDB *dbh, ///< Database handle 4089 psFits *fits, ///< psFits object 4090 const psMetadata *where, ///< Row match criteria 4091 unsigned long long limit ///< Maximum number of elements to return 4092 ); 4093 4094 /** Convert a fakeRunRow into an equivalent psMetadata 4095 * 4096 * @return A psMetadata pointer or NULL on error 4097 */ 4098 4099 psMetadata *fakeRunMetadataFromObject( 4100 const fakeRunRow *object ///< fooRow to convert into a psMetadata 4101 ); 4102 4103 /** Convert a psMetadata into an equivalent fooRow 4104 * 4105 * @return A fakeRunRow pointer or NULL on error 4106 */ 4107 4108 fakeRunRow *fakeRunObjectFromMetadata( 4109 psMetadata *md ///< psMetadata to convert into a fooRow 4110 ); 4111 /** Selects up to limit rows from the database and returns as fakeRunRow objects in a psArray 4112 * 4113 * See psDBSelectRows() for documentation on the format of where. 4114 * 4115 * @return A psArray pointer or NULL on error 4116 */ 4117 4118 psArray *fakeRunSelectRowObjects( 4119 psDB *dbh, ///< Database handle 4120 const psMetadata *where, ///< Row match criteria 4121 unsigned long long limit ///< Maximum number of elements to return 4122 ); 4123 /** Deletes a row from the database coresponding to an fakeRun 4124 * 4125 * Note that a 'where' search psMetadata is constructed from each object and 4126 * used to find rows to delete. 4127 * 4128 * @return A The number of rows removed or a negative value on error 4129 */ 4130 4131 bool fakeRunDeleteObject( 4132 psDB *dbh, ///< Database handle 4133 const fakeRunRow *object ///< Object to delete 4134 ); 4135 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 4136 * 4137 * Note that a 'where' search psMetadata is constructed from each object and 4138 * used to find rows to delete. 4139 * 4140 * @return A The number of rows removed or a negative value on error 4141 */ 4142 4143 long long fakeRunDeleteRowObjects( 4144 psDB *dbh, ///< Database handle 4145 const psArray *objects, ///< Array of objects to delete 4146 unsigned long long limit ///< Maximum number of elements to delete 4147 ); 4148 /** Formats and prints an array of fakeRunRow objects 4149 * 4150 * When mdcf is set the formated output is in psMetadataConfig 4151 * format, otherwise it is in a simple tabular format. 4152 * 4153 * @return true on success 4154 */ 4155 4156 bool fakeRunPrintObjects( 4157 FILE *stream, ///< a stream 4158 psArray *objects, ///< An array of fakeRunRow objects 4159 bool mdcf ///< format as mdconfig or simple 4160 ); 4161 /** Formats and prints an fakeRunRow object 4162 * 4163 * When mdcf is set the formated output is in psMetadataConfig 4164 * format, otherwise it is in a simple tabular format. 4165 * 4166 * @return true on success 4167 */ 4168 4169 bool fakeRunPrintObject( 4170 FILE *stream, ///< a stream 4171 fakeRunRow *object, ///< an fakeRunRow object 4172 bool mdcf ///< format as mdconfig or simple 4173 ); 4174 /** fakeProcessedImfileRow data structure 4175 * 4176 * Structure for representing a single row of fakeProcessedImfile table data. 4177 */ 4178 4179 typedef struct { 4180 psS64 fake_id; 4181 psS64 exp_id; 4182 char *class_id; 4183 char *uri; 4184 psF32 dtime_fake; 4185 char *hostname; 4186 char *path_base; 4187 psS16 fault; 4188 psTime* epoch; 4189 } fakeProcessedImfileRow; 4190 4191 /** Creates a new fakeProcessedImfileRow object 4192 * 4193 * @return A new fakeProcessedImfileRow object or NULL on failure. 4194 */ 4195 4196 fakeProcessedImfileRow *fakeProcessedImfileRowAlloc( 4197 psS64 fake_id, 4198 psS64 exp_id, 4199 const char *class_id, 4200 const char *uri, 4201 psF32 dtime_fake, 4202 const char *hostname, 4203 const char *path_base, 4204 psS16 fault, 4205 psTime* epoch 4206 ); 4207 4208 /** Creates a new fakeProcessedImfile table 4209 * 4210 * @return true on success 4211 */ 4212 4213 bool fakeProcessedImfileCreateTable( 4214 psDB *dbh ///< Database handle 4215 ); 4216 4217 /** Deletes a fakeProcessedImfile table 4218 * 4219 * @return true on success 4220 */ 4221 4222 bool fakeProcessedImfileDropTable( 4223 psDB *dbh ///< Database handle 4224 ); 4225 4226 /** Insert a single row into a table 4227 * 4228 * This function constructs and inserts a single row based on it's parameters. 4229 * 4230 * @return true on success 4231 */ 4232 4233 bool fakeProcessedImfileInsert( 4234 psDB *dbh, ///< Database handle 4235 psS64 fake_id, 4236 psS64 exp_id, 4237 const char *class_id, 4238 const char *uri, 4239 psF32 dtime_fake, 4240 const char *hostname, 4241 const char *path_base, 4242 psS16 fault, 4243 psTime* epoch 4244 ); 4245 4246 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 4247 * 4248 * @return A The number of rows removed or a negative value on error 4249 */ 4250 4251 long long fakeProcessedImfileDelete( 4252 psDB *dbh, ///< Database handle 4253 const psMetadata *where, ///< Row match criteria 4254 unsigned long long limit ///< Maximum number of elements to delete 4255 ); 4256 4257 /** Insert a single fakeProcessedImfileRow object into a table 4258 * 4259 * This function constructs and inserts a single row based on it's parameters. 4260 * 4261 * @return true on success 4262 */ 4263 4264 bool fakeProcessedImfileInsertObject( 4265 psDB *dbh, ///< Database handle 4266 fakeProcessedImfileRow *object ///< fakeProcessedImfileRow object 4267 ); 4268 4269 /** Insert an array of fakeProcessedImfileRow object into a table 4270 * 4271 * This function constructs and inserts multiple rows based on it's parameters. 4272 * 4273 * @return true on success 4274 */ 4275 4276 bool fakeProcessedImfileInsertObjects( 4277 psDB *dbh, ///< Database handle 4278 psArray *objects ///< array of fakeProcessedImfileRow objects 4279 ); 4280 4281 /** Insert data from a binary FITS table fakeProcessedImfileRow into the database 4282 * 4283 * This function expects a psFits object with a FITS table as the first 4284 * extension. The table must have at least one row of data in it, that is of 4285 * the appropriate format (number of columns and their type). All other 4286 * extensions are ignored. 4287 * 4288 * @return true on success 4289 */ 4290 4291 bool fakeProcessedImfileInsertFits( 4292 psDB *dbh, ///< Database handle 4293 const psFits *fits ///< psFits object 4294 ); 4295 4296 /** Selects up to limit from the database and returns them in a binary FITS table 4297 * 4298 * This function assumes an empty psFits object and will create a FITS table 4299 * as the first extension. 4300 * 4301 * See psDBSelectRows() for documentation on the format of where. 4302 * 4303 * @return true on success 4304 */ 4305 4306 bool fakeProcessedImfileSelectRowsFits( 4307 psDB *dbh, ///< Database handle 4308 psFits *fits, ///< psFits object 4309 const psMetadata *where, ///< Row match criteria 4310 unsigned long long limit ///< Maximum number of elements to return 4311 ); 4312 4313 /** Convert a fakeProcessedImfileRow into an equivalent psMetadata 4314 * 4315 * @return A psMetadata pointer or NULL on error 4316 */ 4317 4318 psMetadata *fakeProcessedImfileMetadataFromObject( 4319 const fakeProcessedImfileRow *object ///< fooRow to convert into a psMetadata 4320 ); 4321 4322 /** Convert a psMetadata into an equivalent fooRow 4323 * 4324 * @return A fakeProcessedImfileRow pointer or NULL on error 4325 */ 4326 4327 fakeProcessedImfileRow *fakeProcessedImfileObjectFromMetadata( 4328 psMetadata *md ///< psMetadata to convert into a fooRow 4329 ); 4330 /** Selects up to limit rows from the database and returns as fakeProcessedImfileRow objects in a psArray 4331 * 4332 * See psDBSelectRows() for documentation on the format of where. 4333 * 4334 * @return A psArray pointer or NULL on error 4335 */ 4336 4337 psArray *fakeProcessedImfileSelectRowObjects( 4338 psDB *dbh, ///< Database handle 4339 const psMetadata *where, ///< Row match criteria 4340 unsigned long long limit ///< Maximum number of elements to return 4341 ); 4342 /** Deletes a row from the database coresponding to an fakeProcessedImfile 4343 * 4344 * Note that a 'where' search psMetadata is constructed from each object and 4345 * used to find rows to delete. 4346 * 4347 * @return A The number of rows removed or a negative value on error 4348 */ 4349 4350 bool fakeProcessedImfileDeleteObject( 4351 psDB *dbh, ///< Database handle 4352 const fakeProcessedImfileRow *object ///< Object to delete 4353 ); 4354 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 4355 * 4356 * Note that a 'where' search psMetadata is constructed from each object and 4357 * used to find rows to delete. 4358 * 4359 * @return A The number of rows removed or a negative value on error 4360 */ 4361 4362 long long fakeProcessedImfileDeleteRowObjects( 4363 psDB *dbh, ///< Database handle 4364 const psArray *objects, ///< Array of objects to delete 4365 unsigned long long limit ///< Maximum number of elements to delete 4366 ); 4367 /** Formats and prints an array of fakeProcessedImfileRow objects 4368 * 4369 * When mdcf is set the formated output is in psMetadataConfig 4370 * format, otherwise it is in a simple tabular format. 4371 * 4372 * @return true on success 4373 */ 4374 4375 bool fakeProcessedImfilePrintObjects( 4376 FILE *stream, ///< a stream 4377 psArray *objects, ///< An array of fakeProcessedImfileRow objects 4378 bool mdcf ///< format as mdconfig or simple 4379 ); 4380 /** Formats and prints an fakeProcessedImfileRow object 4381 * 4382 * When mdcf is set the formated output is in psMetadataConfig 4383 * format, otherwise it is in a simple tabular format. 4384 * 4385 * @return true on success 4386 */ 4387 4388 bool fakeProcessedImfilePrintObject( 4389 FILE *stream, ///< a stream 4390 fakeProcessedImfileRow *object, ///< an fakeProcessedImfileRow object 4391 bool mdcf ///< format as mdconfig or simple 4392 ); 4393 /** fakeMaskRow data structure 4394 * 4395 * Structure for representing a single row of fakeMask table data. 4396 */ 4397 4398 typedef struct { 4399 char *label; 4400 } fakeMaskRow; 4401 4402 /** Creates a new fakeMaskRow object 4403 * 4404 * @return A new fakeMaskRow object or NULL on failure. 4405 */ 4406 4407 fakeMaskRow *fakeMaskRowAlloc( 4408 const char *label 4409 ); 4410 4411 /** Creates a new fakeMask table 4412 * 4413 * @return true on success 4414 */ 4415 4416 bool fakeMaskCreateTable( 4417 psDB *dbh ///< Database handle 4418 ); 4419 4420 /** Deletes a fakeMask table 4421 * 4422 * @return true on success 4423 */ 4424 4425 bool fakeMaskDropTable( 4426 psDB *dbh ///< Database handle 4427 ); 4428 4429 /** Insert a single row into a table 4430 * 4431 * This function constructs and inserts a single row based on it's parameters. 4432 * 4433 * @return true on success 4434 */ 4435 4436 bool fakeMaskInsert( 4437 psDB *dbh, ///< Database handle 4438 const char *label 4439 ); 4440 4441 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 4442 * 4443 * @return A The number of rows removed or a negative value on error 4444 */ 4445 4446 long long fakeMaskDelete( 4447 psDB *dbh, ///< Database handle 4448 const psMetadata *where, ///< Row match criteria 4449 unsigned long long limit ///< Maximum number of elements to delete 4450 ); 4451 4452 /** Insert a single fakeMaskRow object into a table 4453 * 4454 * This function constructs and inserts a single row based on it's parameters. 4455 * 4456 * @return true on success 4457 */ 4458 4459 bool fakeMaskInsertObject( 4460 psDB *dbh, ///< Database handle 4461 fakeMaskRow *object ///< fakeMaskRow object 4462 ); 4463 4464 /** Insert an array of fakeMaskRow object into a table 4465 * 4466 * This function constructs and inserts multiple rows based on it's parameters. 4467 * 4468 * @return true on success 4469 */ 4470 4471 bool fakeMaskInsertObjects( 4472 psDB *dbh, ///< Database handle 4473 psArray *objects ///< array of fakeMaskRow objects 4474 ); 4475 4476 /** Insert data from a binary FITS table fakeMaskRow into the database 4477 * 4478 * This function expects a psFits object with a FITS table as the first 4479 * extension. The table must have at least one row of data in it, that is of 4480 * the appropriate format (number of columns and their type). All other 4481 * extensions are ignored. 4482 * 4483 * @return true on success 4484 */ 4485 4486 bool fakeMaskInsertFits( 4487 psDB *dbh, ///< Database handle 4488 const psFits *fits ///< psFits object 4489 ); 4490 4491 /** Selects up to limit from the database and returns them in a binary FITS table 4492 * 4493 * This function assumes an empty psFits object and will create a FITS table 4494 * as the first extension. 4495 * 4496 * See psDBSelectRows() for documentation on the format of where. 4497 * 4498 * @return true on success 4499 */ 4500 4501 bool fakeMaskSelectRowsFits( 4502 psDB *dbh, ///< Database handle 4503 psFits *fits, ///< psFits object 4504 const psMetadata *where, ///< Row match criteria 4505 unsigned long long limit ///< Maximum number of elements to return 4506 ); 4507 4508 /** Convert a fakeMaskRow into an equivalent psMetadata 4509 * 4510 * @return A psMetadata pointer or NULL on error 4511 */ 4512 4513 psMetadata *fakeMaskMetadataFromObject( 4514 const fakeMaskRow *object ///< fooRow to convert into a psMetadata 4515 ); 4516 4517 /** Convert a psMetadata into an equivalent fooRow 4518 * 4519 * @return A fakeMaskRow pointer or NULL on error 4520 */ 4521 4522 fakeMaskRow *fakeMaskObjectFromMetadata( 4523 psMetadata *md ///< psMetadata to convert into a fooRow 4524 ); 4525 /** Selects up to limit rows from the database and returns as fakeMaskRow objects in a psArray 4526 * 4527 * See psDBSelectRows() for documentation on the format of where. 4528 * 4529 * @return A psArray pointer or NULL on error 4530 */ 4531 4532 psArray *fakeMaskSelectRowObjects( 4533 psDB *dbh, ///< Database handle 4534 const psMetadata *where, ///< Row match criteria 4535 unsigned long long limit ///< Maximum number of elements to return 4536 ); 4537 /** Deletes a row from the database coresponding to an fakeMask 4538 * 4539 * Note that a 'where' search psMetadata is constructed from each object and 4540 * used to find rows to delete. 4541 * 4542 * @return A The number of rows removed or a negative value on error 4543 */ 4544 4545 bool fakeMaskDeleteObject( 4546 psDB *dbh, ///< Database handle 4547 const fakeMaskRow *object ///< Object to delete 4548 ); 4549 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 4550 * 4551 * Note that a 'where' search psMetadata is constructed from each object and 4552 * used to find rows to delete. 4553 * 4554 * @return A The number of rows removed or a negative value on error 4555 */ 4556 4557 long long fakeMaskDeleteRowObjects( 4558 psDB *dbh, ///< Database handle 4559 const psArray *objects, ///< Array of objects to delete 4560 unsigned long long limit ///< Maximum number of elements to delete 4561 ); 4562 /** Formats and prints an array of fakeMaskRow objects 4563 * 4564 * When mdcf is set the formated output is in psMetadataConfig 4565 * format, otherwise it is in a simple tabular format. 4566 * 4567 * @return true on success 4568 */ 4569 4570 bool fakeMaskPrintObjects( 4571 FILE *stream, ///< a stream 4572 psArray *objects, ///< An array of fakeMaskRow objects 4573 bool mdcf ///< format as mdconfig or simple 4574 ); 4575 /** Formats and prints an fakeMaskRow object 4576 * 4577 * When mdcf is set the formated output is in psMetadataConfig 4578 * format, otherwise it is in a simple tabular format. 4579 * 4580 * @return true on success 4581 */ 4582 4583 bool fakeMaskPrintObject( 4584 FILE *stream, ///< a stream 4585 fakeMaskRow *object, ///< an fakeMaskRow object 4586 bool mdcf ///< format as mdconfig or simple 4587 ); 3952 4588 /** warpRunRow data structure 3953 4589 * … … 3957 4593 typedef struct { 3958 4594 psS64 warp_id; 3959 psS64 cam_id;4595 psS64 fake_id; 3960 4596 char *mode; 3961 4597 char *state; … … 3977 4613 warpRunRow *warpRunRowAlloc( 3978 4614 psS64 warp_id, 3979 psS64 cam_id,4615 psS64 fake_id, 3980 4616 const char *mode, 3981 4617 const char *state, … … 4018 4654 psDB *dbh, ///< Database handle 4019 4655 psS64 warp_id, 4020 psS64 cam_id,4656 psS64 fake_id, 4021 4657 const char *mode, 4022 4658 const char *state, … … 4187 4823 char *skycell_id; 4188 4824 char *tess_id; 4189 psS64 cam_id;4190 4825 char *class_id; 4191 4826 psS16 fault; … … 4201 4836 const char *skycell_id, 4202 4837 const char *tess_id, 4203 psS64 cam_id,4204 4838 const char *class_id, 4205 4839 psS16 fault … … 4236 4870 const char *skycell_id, 4237 4871 const char *tess_id, 4238 psS64 cam_id,4239 4872 const char *class_id, 4240 4873 psS16 fault
Note:
See TracChangeset
for help on using the changeset viewer.
