Changeset 11988 for trunk/ippdb/src/ippdb.c
- Timestamp:
- Feb 21, 2007, 4:29:12 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippdb/src/ippdb.c (modified) (137 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippdb/src/ippdb.c
r11873 r11988 65 65 #define P4INPUTEXP_TABLE_NAME "p4InputExp" 66 66 #define P4SKYCELLMAP_TABLE_NAME "p4SkyCellMap" 67 #define P4S CFILE_TABLE_NAME "p4Scfile"67 #define P4SKYFILE_TABLE_NAME "p4Skyfile" 68 68 #define P5RUN_TABLE_NAME "p5Run" 69 #define P5INPUTS CFILE_TABLE_NAME "p5InputScfile"70 #define P5DIFFS CFILE_TABLE_NAME "p5DiffScfile"69 #define P5INPUTSKYFILE_TABLE_NAME "p5InputSkyfile" 70 #define P5DIFFSKYFILE_TABLE_NAME "p5DiffSkyfile" 71 71 #define P6RUN_TABLE_NAME "p6Run" 72 #define P6INPUTS CFILE_TABLE_NAME "p6InputScfile"73 #define P6SUMS CFILE_TABLE_NAME "p6SumScfile"72 #define P6INPUTSKYFILE_TABLE_NAME "p6InputSkyfile" 73 #define P6SUMSKYFILE_TABLE_NAME "p6SumSkyfile" 74 74 #define MAX_STRING_LENGTH 1024 75 75 … … 14846 14846 return true; 14847 14847 } 14848 static void p4S cfileRowFree(p4ScfileRow *object);14849 14850 p4S cfileRow *p4ScfileRowAlloc(psS32 p4_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)14851 { 14852 p4S cfileRow*_object;14853 14854 _object = psAlloc(sizeof(p4S cfileRow));14855 psMemSetDeallocator(_object, (psFreeFunc)p4S cfileRowFree);14848 static void p4SkyfileRowFree(p4SkyfileRow *object); 14849 14850 p4SkyfileRow *p4SkyfileRowAlloc(psS32 p4_id, const char *skycell_id, const char *tess_id, const char *uri, psF64 bg, psF64 bg_mean_stdev) 14851 { 14852 p4SkyfileRow *_object; 14853 14854 _object = psAlloc(sizeof(p4SkyfileRow)); 14855 psMemSetDeallocator(_object, (psFreeFunc)p4SkyfileRowFree); 14856 14856 14857 14857 _object->p4_id = p4_id; 14858 14858 _object->skycell_id = psStringCopy(skycell_id); 14859 14859 _object->tess_id = psStringCopy(tess_id); 14860 _object->exp_tag = psStringCopy(exp_tag);14861 _object->p3_version = p3_version;14862 14860 _object->uri = psStringCopy(uri); 14863 14861 _object->bg = bg; … … 14867 14865 } 14868 14866 14869 static void p4S cfileRowFree(p4ScfileRow *object)14867 static void p4SkyfileRowFree(p4SkyfileRow *object) 14870 14868 { 14871 14869 psFree(object->skycell_id); 14872 14870 psFree(object->tess_id); 14873 psFree(object->exp_tag);14874 14871 psFree(object->uri); 14875 14872 } 14876 14873 14877 bool p4S cfileCreateTable(psDB *dbh)14874 bool p4SkyfileCreateTable(psDB *dbh) 14878 14875 { 14879 14876 psMetadata *md = psMetadataAlloc(); … … 14893 14890 return false; 14894 14891 } 14895 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, "Key", "64")) {14896 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");14897 psFree(md);14898 return false;14899 }14900 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, "Key", 0)) {14901 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");14902 psFree(md);14903 return false;14904 }14905 14892 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) { 14906 14893 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); … … 14919 14906 } 14920 14907 14921 bool status = psDBCreateTable(dbh, P4S CFILE_TABLE_NAME, md);14908 bool status = psDBCreateTable(dbh, P4SKYFILE_TABLE_NAME, md); 14922 14909 14923 14910 psFree(md); … … 14926 14913 } 14927 14914 14928 bool p4S cfileDropTable(psDB *dbh)14929 { 14930 return psDBDropTable(dbh, P4S CFILE_TABLE_NAME);14931 } 14932 14933 bool p4S cfileInsert(psDB * dbh, psS32 p4_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)14915 bool p4SkyfileDropTable(psDB *dbh) 14916 { 14917 return psDBDropTable(dbh, P4SKYFILE_TABLE_NAME); 14918 } 14919 14920 bool p4SkyfileInsert(psDB * dbh, psS32 p4_id, const char *skycell_id, const char *tess_id, const char *uri, psF64 bg, psF64 bg_mean_stdev) 14934 14921 { 14935 14922 psMetadata *md = psMetadataAlloc(); … … 14949 14936 return false; 14950 14937 } 14951 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, exp_tag)) {14952 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");14953 psFree(md);14954 return false;14955 }14956 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, p3_version)) {14957 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");14958 psFree(md);14959 return false;14960 }14961 14938 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) { 14962 14939 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); … … 14975 14952 } 14976 14953 14977 bool status = psDBInsertOneRow(dbh, P4S CFILE_TABLE_NAME, md);14954 bool status = psDBInsertOneRow(dbh, P4SKYFILE_TABLE_NAME, md); 14978 14955 psFree(md); 14979 14956 … … 14981 14958 } 14982 14959 14983 long long p4S cfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)14960 long long p4SkyfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 14984 14961 { 14985 14962 long long deleted = 0; 14986 14963 14987 long long count = psDBDeleteRows(dbh, P4S CFILE_TABLE_NAME, where, limit);14964 long long count = psDBDeleteRows(dbh, P4SKYFILE_TABLE_NAME, where, limit); 14988 14965 if (count < 0) { 14989 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4S cfile");14966 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4Skyfile"); 14990 14967 return count; 14991 14968 … … 14995 14972 return deleted; 14996 14973 } 14997 bool p4S cfileInsertObject(psDB *dbh, p4ScfileRow *object)14998 { 14999 return p4S cfileInsert(dbh, object->p4_id, object->skycell_id, object->tess_id, object->exp_tag, object->p3_version, object->uri, object->bg, object->bg_mean_stdev);15000 } 15001 15002 bool p4S cfileInsertObjects(psDB *dbh, psArray *objects)14974 bool p4SkyfileInsertObject(psDB *dbh, p4SkyfileRow *object) 14975 { 14976 return p4SkyfileInsert(dbh, object->p4_id, object->skycell_id, object->tess_id, object->uri, object->bg, object->bg_mean_stdev); 14977 } 14978 14979 bool p4SkyfileInsertObjects(psDB *dbh, psArray *objects) 15003 14980 { 15004 14981 for (long i = 0; i < psArrayLength(objects); i++) { 15005 if (!p4S cfileInsertObject(dbh, objects->data[i])) {14982 if (!p4SkyfileInsertObject(dbh, objects->data[i])) { 15006 14983 return false; 15007 14984 } … … 15011 14988 } 15012 14989 15013 bool p4S cfileInsertFits(psDB *dbh, const psFits *fits)14990 bool p4SkyfileInsertFits(psDB *dbh, const psFits *fits) 15014 14991 { 15015 14992 psArray *rowSet; 15016 14993 15017 // move to (the first?) extension named P4S CFILE_TABLE_NAME15018 if (!psFitsMoveExtName(fits, P4S CFILE_TABLE_NAME)) {15019 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4S CFILE_TABLE_NAME);14994 // move to (the first?) extension named P4SKYFILE_TABLE_NAME 14995 if (!psFitsMoveExtName(fits, P4SKYFILE_TABLE_NAME)) { 14996 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P4SKYFILE_TABLE_NAME); 15020 14997 return false; 15021 14998 } … … 15035 15012 } 15036 15013 15037 if (!psDBInsertRows(dbh, P4S CFILE_TABLE_NAME, rowSet)) {15014 if (!psDBInsertRows(dbh, P4SKYFILE_TABLE_NAME, rowSet)) { 15038 15015 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 15039 15016 psFree(rowSet); … … 15046 15023 } 15047 15024 15048 bool p4S cfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)15025 bool p4SkyfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 15049 15026 { 15050 15027 psArray *rowSet; 15051 15028 15052 rowSet = psDBSelectRows(dbh, P4S CFILE_TABLE_NAME, where, limit);15029 rowSet = psDBSelectRows(dbh, P4SKYFILE_TABLE_NAME, where, limit); 15053 15030 if (!rowSet) { 15054 15031 return false; … … 15056 15033 15057 15034 // output to fits 15058 if (!psFitsWriteTable(fits, NULL, rowSet, P4S CFILE_TABLE_NAME)) {15035 if (!psFitsWriteTable(fits, NULL, rowSet, P4SKYFILE_TABLE_NAME)) { 15059 15036 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 15060 15037 psFree(rowSet); … … 15067 15044 } 15068 15045 15069 psMetadata *p4S cfileMetadataFromObject(const p4ScfileRow *object)15046 psMetadata *p4SkyfileMetadataFromObject(const p4SkyfileRow *object) 15070 15047 { 15071 15048 psMetadata *md = psMetadataAlloc(); … … 15085 15062 return false; 15086 15063 } 15087 if (!psMetadataAdd(md, PS_LIST_TAIL, "exp_tag", PS_DATA_STRING, NULL, object->exp_tag)) {15088 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");15089 psFree(md);15090 return false;15091 }15092 if (!psMetadataAdd(md, PS_LIST_TAIL, "p3_version", PS_DATA_S32, NULL, object->p3_version)) {15093 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version");15094 psFree(md);15095 return false;15096 }15097 15064 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) { 15098 15065 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); … … 15115 15082 } 15116 15083 15117 p4S cfileRow *p4ScfileObjectFromMetadata(psMetadata *md)15084 p4SkyfileRow *p4SkyfileObjectFromMetadata(psMetadata *md) 15118 15085 { 15119 15086 … … 15134 15101 return false; 15135 15102 } 15136 char* exp_tag = psMetadataLookupPtr(&status, md, "exp_tag");15137 if (!status) {15138 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag");15139 return false;15140 }15141 psS32 p3_version = psMetadataLookupS32(&status, md, "p3_version");15142 if (!status) {15143 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version");15144 return false;15145 }15146 15103 char* uri = psMetadataLookupPtr(&status, md, "uri"); 15147 15104 if (!status) { … … 15160 15117 } 15161 15118 15162 return p4S cfileRowAlloc(p4_id, skycell_id, tess_id, exp_tag, p3_version, uri, bg, bg_mean_stdev);15163 } 15164 psArray *p4S cfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)15119 return p4SkyfileRowAlloc(p4_id, skycell_id, tess_id, uri, bg, bg_mean_stdev); 15120 } 15121 psArray *p4SkyfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 15165 15122 { 15166 15123 psArray *rowSet; … … 15168 15125 psU64 i; 15169 15126 15170 rowSet = psDBSelectRows(dbh, P4S CFILE_TABLE_NAME, where, limit);15127 rowSet = psDBSelectRows(dbh, P4SKYFILE_TABLE_NAME, where, limit); 15171 15128 if (!rowSet) { 15172 15129 return NULL; … … 15178 15135 15179 15136 for (i = 0; i < rowSet->n; i++) { 15180 p4S cfileRow *object = p4ScfileObjectFromMetadata(rowSet->data[i]);15137 p4SkyfileRow *object = p4SkyfileObjectFromMetadata(rowSet->data[i]); 15181 15138 psArrayAdd(returnSet, 0, object); 15182 15139 psFree(object); … … 15187 15144 return returnSet; 15188 15145 } 15189 bool p4S cfileDeleteObject(psDB *dbh, const p4ScfileRow *object)15190 { 15191 psMetadata *where = p4S cfileMetadataFromObject(object);15192 long long count = psDBDeleteRows(dbh, P4S CFILE_TABLE_NAME, where, 0);15146 bool p4SkyfileDeleteObject(psDB *dbh, const p4SkyfileRow *object) 15147 { 15148 psMetadata *where = p4SkyfileMetadataFromObject(object); 15149 long long count = psDBDeleteRows(dbh, P4SKYFILE_TABLE_NAME, where, 0); 15193 15150 psFree(where); 15194 15151 if (count < 0) { 15195 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4S cfile");15152 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4Skyfile"); 15196 15153 return false; 15197 15154 } … … 15199 15156 // XXX should this be a psAbort() instead? It is possible that 15200 15157 // having an object match multiple rows was by design. 15201 psError(PS_ERR_UNKNOWN, true, "p4S cfileRow object matched more then one row. Check your database schema");15202 return false; 15203 } 15204 15205 return true; 15206 } 15207 long long p4S cfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)15158 psError(PS_ERR_UNKNOWN, true, "p4SkyfileRow object matched more then one row. Check your database schema"); 15159 return false; 15160 } 15161 15162 return true; 15163 } 15164 long long p4SkyfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 15208 15165 { 15209 15166 long long deleted = 0; 15210 15167 15211 15168 for (long long i = 0; i < objects->n; i++) { 15212 p4S cfileRow *object = objects->data[i];15213 psMetadata *where = p4S cfileMetadataFromObject(object);15214 long long count = psDBDeleteRows(dbh, P4S CFILE_TABLE_NAME, where, limit);15169 p4SkyfileRow *object = objects->data[i]; 15170 psMetadata *where = p4SkyfileMetadataFromObject(object); 15171 long long count = psDBDeleteRows(dbh, P4SKYFILE_TABLE_NAME, where, limit); 15215 15172 psFree(where); 15216 15173 if (count < 0) { 15217 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4S cfile");15174 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p4Skyfile"); 15218 15175 return count; 15219 15176 } … … 15224 15181 return deleted; 15225 15182 } 15226 bool p4S cfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)15183 bool p4SkyfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 15227 15184 { 15228 15185 PS_ASSERT_PTR_NON_NULL(objects, false); … … 15230 15187 psMetadata *output = psMetadataAlloc(); 15231 15188 for (long i = 0; i < psArrayLength(objects); i++) { 15232 psMetadata *md = p4S cfileMetadataFromObject(objects->data[i]);15189 psMetadata *md = p4SkyfileMetadataFromObject(objects->data[i]); 15233 15190 if (!psMetadataAddMetadata( 15234 15191 output, 15235 15192 PS_LIST_TAIL, 15236 P4S CFILE_TABLE_NAME,15193 P4SKYFILE_TABLE_NAME, 15237 15194 PS_META_DUPLICATE_OK, 15238 15195 NULL, … … 15255 15212 return true; 15256 15213 } 15257 bool p4S cfilePrintObject(FILE *stream, p4ScfileRow *object, bool mdcf)15214 bool p4SkyfilePrintObject(FILE *stream, p4SkyfileRow *object, bool mdcf) 15258 15215 { 15259 15216 PS_ASSERT_PTR_NON_NULL(object, false); 15260 15217 15261 psMetadata *md = p4S cfileMetadataFromObject(object);15218 psMetadata *md = p4SkyfileMetadataFromObject(object); 15262 15219 15263 15220 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { … … 15272 15229 static void p5RunRowFree(p5RunRow *object); 15273 15230 15274 p5RunRow *p5RunRowAlloc(psS32 p5_id, const char *state, const char *workdir, const char *dvodb, psTime* registered )15231 p5RunRow *p5RunRowAlloc(psS32 p5_id, const char *state, const char *workdir, const char *dvodb, psTime* registered, const char *skycell_id, const char *tess_id) 15275 15232 { 15276 15233 p5RunRow *_object; … … 15284 15241 _object->dvodb = psStringCopy(dvodb); 15285 15242 _object->registered = psTimeCopy(registered); 15243 _object->skycell_id = psStringCopy(skycell_id); 15244 _object->tess_id = psStringCopy(tess_id); 15286 15245 15287 15246 return _object; … … 15294 15253 psFree(object->dvodb); 15295 15254 psFree(object->registered); 15255 psFree(object->skycell_id); 15256 psFree(object->tess_id); 15296 15257 } 15297 15258 … … 15324 15285 return false; 15325 15286 } 15287 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Key", "64")) { 15288 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 15289 psFree(md); 15290 return false; 15291 } 15292 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Key", "64")) { 15293 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 15294 psFree(md); 15295 return false; 15296 } 15326 15297 15327 15298 bool status = psDBCreateTable(dbh, P5RUN_TABLE_NAME, md); … … 15337 15308 } 15338 15309 15339 bool p5RunInsert(psDB * dbh, psS32 p5_id, const char *state, const char *workdir, const char *dvodb, psTime* registered )15310 bool p5RunInsert(psDB * dbh, psS32 p5_id, const char *state, const char *workdir, const char *dvodb, psTime* registered, const char *skycell_id, const char *tess_id) 15340 15311 { 15341 15312 psMetadata *md = psMetadataAlloc(); … … 15362 15333 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, registered)) { 15363 15334 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 15335 psFree(md); 15336 return false; 15337 } 15338 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) { 15339 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 15340 psFree(md); 15341 return false; 15342 } 15343 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) { 15344 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 15364 15345 psFree(md); 15365 15346 return false; … … 15388 15369 bool p5RunInsertObject(psDB *dbh, p5RunRow *object) 15389 15370 { 15390 return p5RunInsert(dbh, object->p5_id, object->state, object->workdir, object->dvodb, object->registered );15371 return p5RunInsert(dbh, object->p5_id, object->state, object->workdir, object->dvodb, object->registered, object->skycell_id, object->tess_id); 15391 15372 } 15392 15373 … … 15486 15467 return false; 15487 15468 } 15469 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) { 15470 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 15471 psFree(md); 15472 return false; 15473 } 15474 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) { 15475 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 15476 psFree(md); 15477 return false; 15478 } 15488 15479 15489 15480 … … 15520 15511 return false; 15521 15512 } 15522 15523 return p5RunRowAlloc(p5_id, state, workdir, dvodb, registered); 15513 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id"); 15514 if (!status) { 15515 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id"); 15516 return false; 15517 } 15518 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id"); 15519 if (!status) { 15520 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id"); 15521 return false; 15522 } 15523 15524 return p5RunRowAlloc(p5_id, state, workdir, dvodb, registered, skycell_id, tess_id); 15524 15525 } 15525 15526 psArray *p5RunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) … … 15631 15632 return true; 15632 15633 } 15633 static void p5InputS cfileRowFree(p5InputScfileRow *object);15634 15635 p5InputS cfileRow *p5InputScfileRowAlloc(psS32 p5_id, psS32 p4_id, const char *skycell_id, const char *tess_id, const char *kind, bool template)15636 { 15637 p5InputS cfileRow *_object;15638 15639 _object = psAlloc(sizeof(p5InputS cfileRow));15640 psMemSetDeallocator(_object, (psFreeFunc)p5InputS cfileRowFree);15634 static void p5InputSkyfileRowFree(p5InputSkyfileRow *object); 15635 15636 p5InputSkyfileRow *p5InputSkyfileRowAlloc(psS32 p5_id, psS32 p4_id, const char *skycell_id, const char *tess_id, const char *kind, bool template) 15637 { 15638 p5InputSkyfileRow *_object; 15639 15640 _object = psAlloc(sizeof(p5InputSkyfileRow)); 15641 psMemSetDeallocator(_object, (psFreeFunc)p5InputSkyfileRowFree); 15641 15642 15642 15643 _object->p5_id = p5_id; … … 15650 15651 } 15651 15652 15652 static void p5InputS cfileRowFree(p5InputScfileRow *object)15653 static void p5InputSkyfileRowFree(p5InputSkyfileRow *object) 15653 15654 { 15654 15655 psFree(object->skycell_id); … … 15657 15658 } 15658 15659 15659 bool p5InputS cfileCreateTable(psDB *dbh)15660 bool p5InputSkyfileCreateTable(psDB *dbh) 15660 15661 { 15661 15662 psMetadata *md = psMetadataAlloc(); … … 15691 15692 } 15692 15693 15693 bool status = psDBCreateTable(dbh, P5INPUTS CFILE_TABLE_NAME, md);15694 bool status = psDBCreateTable(dbh, P5INPUTSKYFILE_TABLE_NAME, md); 15694 15695 15695 15696 psFree(md); … … 15698 15699 } 15699 15700 15700 bool p5InputS cfileDropTable(psDB *dbh)15701 { 15702 return psDBDropTable(dbh, P5INPUTS CFILE_TABLE_NAME);15703 } 15704 15705 bool p5InputS cfileInsert(psDB * dbh, psS32 p5_id, psS32 p4_id, const char *skycell_id, const char *tess_id, const char *kind, bool template)15701 bool p5InputSkyfileDropTable(psDB *dbh) 15702 { 15703 return psDBDropTable(dbh, P5INPUTSKYFILE_TABLE_NAME); 15704 } 15705 15706 bool p5InputSkyfileInsert(psDB * dbh, psS32 p5_id, psS32 p4_id, const char *skycell_id, const char *tess_id, const char *kind, bool template) 15706 15707 { 15707 15708 psMetadata *md = psMetadataAlloc(); … … 15737 15738 } 15738 15739 15739 bool status = psDBInsertOneRow(dbh, P5INPUTS CFILE_TABLE_NAME, md);15740 bool status = psDBInsertOneRow(dbh, P5INPUTSKYFILE_TABLE_NAME, md); 15740 15741 psFree(md); 15741 15742 … … 15743 15744 } 15744 15745 15745 long long p5InputS cfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)15746 long long p5InputSkyfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 15746 15747 { 15747 15748 long long deleted = 0; 15748 15749 15749 long long count = psDBDeleteRows(dbh, P5INPUTS CFILE_TABLE_NAME, where, limit);15750 long long count = psDBDeleteRows(dbh, P5INPUTSKYFILE_TABLE_NAME, where, limit); 15750 15751 if (count < 0) { 15751 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5InputS cfile");15752 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5InputSkyfile"); 15752 15753 return count; 15753 15754 … … 15757 15758 return deleted; 15758 15759 } 15759 bool p5InputS cfileInsertObject(psDB *dbh, p5InputScfileRow *object)15760 { 15761 return p5InputS cfileInsert(dbh, object->p5_id, object->p4_id, object->skycell_id, object->tess_id, object->kind, object->template);15762 } 15763 15764 bool p5InputS cfileInsertObjects(psDB *dbh, psArray *objects)15760 bool p5InputSkyfileInsertObject(psDB *dbh, p5InputSkyfileRow *object) 15761 { 15762 return p5InputSkyfileInsert(dbh, object->p5_id, object->p4_id, object->skycell_id, object->tess_id, object->kind, object->template); 15763 } 15764 15765 bool p5InputSkyfileInsertObjects(psDB *dbh, psArray *objects) 15765 15766 { 15766 15767 for (long i = 0; i < psArrayLength(objects); i++) { 15767 if (!p5InputS cfileInsertObject(dbh, objects->data[i])) {15768 if (!p5InputSkyfileInsertObject(dbh, objects->data[i])) { 15768 15769 return false; 15769 15770 } … … 15773 15774 } 15774 15775 15775 bool p5InputS cfileInsertFits(psDB *dbh, const psFits *fits)15776 bool p5InputSkyfileInsertFits(psDB *dbh, const psFits *fits) 15776 15777 { 15777 15778 psArray *rowSet; 15778 15779 15779 // move to (the first?) extension named P5INPUTS CFILE_TABLE_NAME15780 if (!psFitsMoveExtName(fits, P5INPUTS CFILE_TABLE_NAME)) {15781 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P5INPUTS CFILE_TABLE_NAME);15780 // move to (the first?) extension named P5INPUTSKYFILE_TABLE_NAME 15781 if (!psFitsMoveExtName(fits, P5INPUTSKYFILE_TABLE_NAME)) { 15782 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P5INPUTSKYFILE_TABLE_NAME); 15782 15783 return false; 15783 15784 } … … 15797 15798 } 15798 15799 15799 if (!psDBInsertRows(dbh, P5INPUTS CFILE_TABLE_NAME, rowSet)) {15800 if (!psDBInsertRows(dbh, P5INPUTSKYFILE_TABLE_NAME, rowSet)) { 15800 15801 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 15801 15802 psFree(rowSet); … … 15808 15809 } 15809 15810 15810 bool p5InputS cfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)15811 bool p5InputSkyfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 15811 15812 { 15812 15813 psArray *rowSet; 15813 15814 15814 rowSet = psDBSelectRows(dbh, P5INPUTS CFILE_TABLE_NAME, where, limit);15815 rowSet = psDBSelectRows(dbh, P5INPUTSKYFILE_TABLE_NAME, where, limit); 15815 15816 if (!rowSet) { 15816 15817 return false; … … 15818 15819 15819 15820 // output to fits 15820 if (!psFitsWriteTable(fits, NULL, rowSet, P5INPUTS CFILE_TABLE_NAME)) {15821 if (!psFitsWriteTable(fits, NULL, rowSet, P5INPUTSKYFILE_TABLE_NAME)) { 15821 15822 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 15822 15823 psFree(rowSet); … … 15829 15830 } 15830 15831 15831 psMetadata *p5InputS cfileMetadataFromObject(const p5InputScfileRow *object)15832 psMetadata *p5InputSkyfileMetadataFromObject(const p5InputSkyfileRow *object) 15832 15833 { 15833 15834 psMetadata *md = psMetadataAlloc(); … … 15867 15868 } 15868 15869 15869 p5InputS cfileRow *p5InputScfileObjectFromMetadata(psMetadata *md)15870 p5InputSkyfileRow *p5InputSkyfileObjectFromMetadata(psMetadata *md) 15870 15871 { 15871 15872 … … 15902 15903 } 15903 15904 15904 return p5InputS cfileRowAlloc(p5_id, p4_id, skycell_id, tess_id, kind, template);15905 } 15906 psArray *p5InputS cfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)15905 return p5InputSkyfileRowAlloc(p5_id, p4_id, skycell_id, tess_id, kind, template); 15906 } 15907 psArray *p5InputSkyfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 15907 15908 { 15908 15909 psArray *rowSet; … … 15910 15911 psU64 i; 15911 15912 15912 rowSet = psDBSelectRows(dbh, P5INPUTS CFILE_TABLE_NAME, where, limit);15913 rowSet = psDBSelectRows(dbh, P5INPUTSKYFILE_TABLE_NAME, where, limit); 15913 15914 if (!rowSet) { 15914 15915 return NULL; … … 15920 15921 15921 15922 for (i = 0; i < rowSet->n; i++) { 15922 p5InputS cfileRow *object = p5InputScfileObjectFromMetadata(rowSet->data[i]);15923 p5InputSkyfileRow *object = p5InputSkyfileObjectFromMetadata(rowSet->data[i]); 15923 15924 psArrayAdd(returnSet, 0, object); 15924 15925 psFree(object); … … 15929 15930 return returnSet; 15930 15931 } 15931 bool p5InputS cfileDeleteObject(psDB *dbh, const p5InputScfileRow *object)15932 { 15933 psMetadata *where = p5InputS cfileMetadataFromObject(object);15934 long long count = psDBDeleteRows(dbh, P5INPUTS CFILE_TABLE_NAME, where, 0);15932 bool p5InputSkyfileDeleteObject(psDB *dbh, const p5InputSkyfileRow *object) 15933 { 15934 psMetadata *where = p5InputSkyfileMetadataFromObject(object); 15935 long long count = psDBDeleteRows(dbh, P5INPUTSKYFILE_TABLE_NAME, where, 0); 15935 15936 psFree(where); 15936 15937 if (count < 0) { 15937 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5InputS cfile");15938 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5InputSkyfile"); 15938 15939 return false; 15939 15940 } … … 15941 15942 // XXX should this be a psAbort() instead? It is possible that 15942 15943 // having an object match multiple rows was by design. 15943 psError(PS_ERR_UNKNOWN, true, "p5InputS cfileRow object matched more then one row. Check your database schema");15944 return false; 15945 } 15946 15947 return true; 15948 } 15949 long long p5InputS cfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)15944 psError(PS_ERR_UNKNOWN, true, "p5InputSkyfileRow object matched more then one row. Check your database schema"); 15945 return false; 15946 } 15947 15948 return true; 15949 } 15950 long long p5InputSkyfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 15950 15951 { 15951 15952 long long deleted = 0; 15952 15953 15953 15954 for (long long i = 0; i < objects->n; i++) { 15954 p5InputS cfileRow *object = objects->data[i];15955 psMetadata *where = p5InputS cfileMetadataFromObject(object);15956 long long count = psDBDeleteRows(dbh, P5INPUTS CFILE_TABLE_NAME, where, limit);15955 p5InputSkyfileRow *object = objects->data[i]; 15956 psMetadata *where = p5InputSkyfileMetadataFromObject(object); 15957 long long count = psDBDeleteRows(dbh, P5INPUTSKYFILE_TABLE_NAME, where, limit); 15957 15958 psFree(where); 15958 15959 if (count < 0) { 15959 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5InputS cfile");15960 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5InputSkyfile"); 15960 15961 return count; 15961 15962 } … … 15966 15967 return deleted; 15967 15968 } 15968 bool p5InputS cfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)15969 bool p5InputSkyfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 15969 15970 { 15970 15971 PS_ASSERT_PTR_NON_NULL(objects, false); … … 15972 15973 psMetadata *output = psMetadataAlloc(); 15973 15974 for (long i = 0; i < psArrayLength(objects); i++) { 15974 psMetadata *md = p5InputS cfileMetadataFromObject(objects->data[i]);15975 psMetadata *md = p5InputSkyfileMetadataFromObject(objects->data[i]); 15975 15976 if (!psMetadataAddMetadata( 15976 15977 output, 15977 15978 PS_LIST_TAIL, 15978 P5INPUTS CFILE_TABLE_NAME,15979 P5INPUTSKYFILE_TABLE_NAME, 15979 15980 PS_META_DUPLICATE_OK, 15980 15981 NULL, … … 15997 15998 return true; 15998 15999 } 15999 bool p5InputS cfilePrintObject(FILE *stream, p5InputScfileRow *object, bool mdcf)16000 bool p5InputSkyfilePrintObject(FILE *stream, p5InputSkyfileRow *object, bool mdcf) 16000 16001 { 16001 16002 PS_ASSERT_PTR_NON_NULL(object, false); 16002 16003 16003 psMetadata *md = p5InputS cfileMetadataFromObject(object);16004 psMetadata *md = p5InputSkyfileMetadataFromObject(object); 16004 16005 16005 16006 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { … … 16012 16013 return true; 16013 16014 } 16014 static void p5DiffS cfileRowFree(p5DiffScfileRow *object);16015 16016 p5DiffS cfileRow *p5DiffScfileRowAlloc(psS32 p5_id, const char *skycell_id, const char *tess_id, const char *uri, psF64 bg, psF64 bg_mean_stdev)16017 { 16018 p5DiffS cfileRow *_object;16019 16020 _object = psAlloc(sizeof(p5DiffS cfileRow));16021 psMemSetDeallocator(_object, (psFreeFunc)p5DiffS cfileRowFree);16015 static void p5DiffSkyfileRowFree(p5DiffSkyfileRow *object); 16016 16017 p5DiffSkyfileRow *p5DiffSkyfileRowAlloc(psS32 p5_id, const char *uri, psF64 bg, psF64 bg_mean_stdev) 16018 { 16019 p5DiffSkyfileRow *_object; 16020 16021 _object = psAlloc(sizeof(p5DiffSkyfileRow)); 16022 psMemSetDeallocator(_object, (psFreeFunc)p5DiffSkyfileRowFree); 16022 16023 16023 16024 _object->p5_id = p5_id; 16024 _object->skycell_id = psStringCopy(skycell_id);16025 _object->tess_id = psStringCopy(tess_id);16026 16025 _object->uri = psStringCopy(uri); 16027 16026 _object->bg = bg; … … 16031 16030 } 16032 16031 16033 static void p5DiffScfileRowFree(p5DiffScfileRow *object) 16034 { 16035 psFree(object->skycell_id); 16036 psFree(object->tess_id); 16032 static void p5DiffSkyfileRowFree(p5DiffSkyfileRow *object) 16033 { 16037 16034 psFree(object->uri); 16038 16035 } 16039 16036 16040 bool p5DiffS cfileCreateTable(psDB *dbh)16037 bool p5DiffSkyfileCreateTable(psDB *dbh) 16041 16038 { 16042 16039 psMetadata *md = psMetadataAlloc(); … … 16046 16043 return false; 16047 16044 } 16048 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {16049 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");16050 psFree(md);16051 return false;16052 }16053 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {16054 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");16055 psFree(md);16056 return false;16057 }16058 16045 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) { 16059 16046 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); … … 16072 16059 } 16073 16060 16074 bool status = psDBCreateTable(dbh, P5DIFFS CFILE_TABLE_NAME, md);16061 bool status = psDBCreateTable(dbh, P5DIFFSKYFILE_TABLE_NAME, md); 16075 16062 16076 16063 psFree(md); … … 16079 16066 } 16080 16067 16081 bool p5DiffS cfileDropTable(psDB *dbh)16082 { 16083 return psDBDropTable(dbh, P5DIFFS CFILE_TABLE_NAME);16084 } 16085 16086 bool p5DiffS cfileInsert(psDB * dbh, psS32 p5_id, const char *skycell_id, const char *tess_id, const char *uri, psF64 bg, psF64 bg_mean_stdev)16068 bool p5DiffSkyfileDropTable(psDB *dbh) 16069 { 16070 return psDBDropTable(dbh, P5DIFFSKYFILE_TABLE_NAME); 16071 } 16072 16073 bool p5DiffSkyfileInsert(psDB * dbh, psS32 p5_id, const char *uri, psF64 bg, psF64 bg_mean_stdev) 16087 16074 { 16088 16075 psMetadata *md = psMetadataAlloc(); … … 16092 16079 return false; 16093 16080 } 16094 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {16095 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");16096 psFree(md);16097 return false;16098 }16099 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {16100 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");16101 psFree(md);16102 return false;16103 }16104 16081 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) { 16105 16082 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); … … 16118 16095 } 16119 16096 16120 bool status = psDBInsertOneRow(dbh, P5DIFFS CFILE_TABLE_NAME, md);16097 bool status = psDBInsertOneRow(dbh, P5DIFFSKYFILE_TABLE_NAME, md); 16121 16098 psFree(md); 16122 16099 … … 16124 16101 } 16125 16102 16126 long long p5DiffS cfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)16103 long long p5DiffSkyfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 16127 16104 { 16128 16105 long long deleted = 0; 16129 16106 16130 long long count = psDBDeleteRows(dbh, P5DIFFS CFILE_TABLE_NAME, where, limit);16107 long long count = psDBDeleteRows(dbh, P5DIFFSKYFILE_TABLE_NAME, where, limit); 16131 16108 if (count < 0) { 16132 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5DiffS cfile");16109 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5DiffSkyfile"); 16133 16110 return count; 16134 16111 … … 16138 16115 return deleted; 16139 16116 } 16140 bool p5DiffS cfileInsertObject(psDB *dbh, p5DiffScfileRow *object)16141 { 16142 return p5DiffS cfileInsert(dbh, object->p5_id, object->skycell_id, object->tess_id, object->uri, object->bg, object->bg_mean_stdev);16143 } 16144 16145 bool p5DiffS cfileInsertObjects(psDB *dbh, psArray *objects)16117 bool p5DiffSkyfileInsertObject(psDB *dbh, p5DiffSkyfileRow *object) 16118 { 16119 return p5DiffSkyfileInsert(dbh, object->p5_id, object->uri, object->bg, object->bg_mean_stdev); 16120 } 16121 16122 bool p5DiffSkyfileInsertObjects(psDB *dbh, psArray *objects) 16146 16123 { 16147 16124 for (long i = 0; i < psArrayLength(objects); i++) { 16148 if (!p5DiffS cfileInsertObject(dbh, objects->data[i])) {16125 if (!p5DiffSkyfileInsertObject(dbh, objects->data[i])) { 16149 16126 return false; 16150 16127 } … … 16154 16131 } 16155 16132 16156 bool p5DiffS cfileInsertFits(psDB *dbh, const psFits *fits)16133 bool p5DiffSkyfileInsertFits(psDB *dbh, const psFits *fits) 16157 16134 { 16158 16135 psArray *rowSet; 16159 16136 16160 // move to (the first?) extension named P5DIFFS CFILE_TABLE_NAME16161 if (!psFitsMoveExtName(fits, P5DIFFS CFILE_TABLE_NAME)) {16162 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P5DIFFS CFILE_TABLE_NAME);16137 // move to (the first?) extension named P5DIFFSKYFILE_TABLE_NAME 16138 if (!psFitsMoveExtName(fits, P5DIFFSKYFILE_TABLE_NAME)) { 16139 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P5DIFFSKYFILE_TABLE_NAME); 16163 16140 return false; 16164 16141 } … … 16178 16155 } 16179 16156 16180 if (!psDBInsertRows(dbh, P5DIFFS CFILE_TABLE_NAME, rowSet)) {16157 if (!psDBInsertRows(dbh, P5DIFFSKYFILE_TABLE_NAME, rowSet)) { 16181 16158 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 16182 16159 psFree(rowSet); … … 16189 16166 } 16190 16167 16191 bool p5DiffS cfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)16168 bool p5DiffSkyfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 16192 16169 { 16193 16170 psArray *rowSet; 16194 16171 16195 rowSet = psDBSelectRows(dbh, P5DIFFS CFILE_TABLE_NAME, where, limit);16172 rowSet = psDBSelectRows(dbh, P5DIFFSKYFILE_TABLE_NAME, where, limit); 16196 16173 if (!rowSet) { 16197 16174 return false; … … 16199 16176 16200 16177 // output to fits 16201 if (!psFitsWriteTable(fits, NULL, rowSet, P5DIFFS CFILE_TABLE_NAME)) {16178 if (!psFitsWriteTable(fits, NULL, rowSet, P5DIFFSKYFILE_TABLE_NAME)) { 16202 16179 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 16203 16180 psFree(rowSet); … … 16210 16187 } 16211 16188 16212 psMetadata *p5DiffS cfileMetadataFromObject(const p5DiffScfileRow *object)16189 psMetadata *p5DiffSkyfileMetadataFromObject(const p5DiffSkyfileRow *object) 16213 16190 { 16214 16191 psMetadata *md = psMetadataAlloc(); … … 16218 16195 return false; 16219 16196 } 16220 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {16221 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");16222 psFree(md);16223 return false;16224 }16225 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {16226 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");16227 psFree(md);16228 return false;16229 }16230 16197 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) { 16231 16198 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); … … 16248 16215 } 16249 16216 16250 p5DiffS cfileRow *p5DiffScfileObjectFromMetadata(psMetadata *md)16217 p5DiffSkyfileRow *p5DiffSkyfileObjectFromMetadata(psMetadata *md) 16251 16218 { 16252 16219 … … 16257 16224 return false; 16258 16225 } 16259 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");16260 if (!status) {16261 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");16262 return false;16263 }16264 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");16265 if (!status) {16266 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");16267 return false;16268 }16269 16226 char* uri = psMetadataLookupPtr(&status, md, "uri"); 16270 16227 if (!status) { … … 16283 16240 } 16284 16241 16285 return p5DiffS cfileRowAlloc(p5_id, skycell_id, tess_id, uri, bg, bg_mean_stdev);16286 } 16287 psArray *p5DiffS cfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)16242 return p5DiffSkyfileRowAlloc(p5_id, uri, bg, bg_mean_stdev); 16243 } 16244 psArray *p5DiffSkyfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 16288 16245 { 16289 16246 psArray *rowSet; … … 16291 16248 psU64 i; 16292 16249 16293 rowSet = psDBSelectRows(dbh, P5DIFFS CFILE_TABLE_NAME, where, limit);16250 rowSet = psDBSelectRows(dbh, P5DIFFSKYFILE_TABLE_NAME, where, limit); 16294 16251 if (!rowSet) { 16295 16252 return NULL; … … 16301 16258 16302 16259 for (i = 0; i < rowSet->n; i++) { 16303 p5DiffS cfileRow *object = p5DiffScfileObjectFromMetadata(rowSet->data[i]);16260 p5DiffSkyfileRow *object = p5DiffSkyfileObjectFromMetadata(rowSet->data[i]); 16304 16261 psArrayAdd(returnSet, 0, object); 16305 16262 psFree(object); … … 16310 16267 return returnSet; 16311 16268 } 16312 bool p5DiffS cfileDeleteObject(psDB *dbh, const p5DiffScfileRow *object)16313 { 16314 psMetadata *where = p5DiffS cfileMetadataFromObject(object);16315 long long count = psDBDeleteRows(dbh, P5DIFFS CFILE_TABLE_NAME, where, 0);16269 bool p5DiffSkyfileDeleteObject(psDB *dbh, const p5DiffSkyfileRow *object) 16270 { 16271 psMetadata *where = p5DiffSkyfileMetadataFromObject(object); 16272 long long count = psDBDeleteRows(dbh, P5DIFFSKYFILE_TABLE_NAME, where, 0); 16316 16273 psFree(where); 16317 16274 if (count < 0) { 16318 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5DiffS cfile");16275 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5DiffSkyfile"); 16319 16276 return false; 16320 16277 } … … 16322 16279 // XXX should this be a psAbort() instead? It is possible that 16323 16280 // having an object match multiple rows was by design. 16324 psError(PS_ERR_UNKNOWN, true, "p5DiffS cfileRow object matched more then one row. Check your database schema");16325 return false; 16326 } 16327 16328 return true; 16329 } 16330 long long p5DiffS cfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)16281 psError(PS_ERR_UNKNOWN, true, "p5DiffSkyfileRow object matched more then one row. Check your database schema"); 16282 return false; 16283 } 16284 16285 return true; 16286 } 16287 long long p5DiffSkyfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 16331 16288 { 16332 16289 long long deleted = 0; 16333 16290 16334 16291 for (long long i = 0; i < objects->n; i++) { 16335 p5DiffS cfileRow *object = objects->data[i];16336 psMetadata *where = p5DiffS cfileMetadataFromObject(object);16337 long long count = psDBDeleteRows(dbh, P5DIFFS CFILE_TABLE_NAME, where, limit);16292 p5DiffSkyfileRow *object = objects->data[i]; 16293 psMetadata *where = p5DiffSkyfileMetadataFromObject(object); 16294 long long count = psDBDeleteRows(dbh, P5DIFFSKYFILE_TABLE_NAME, where, limit); 16338 16295 psFree(where); 16339 16296 if (count < 0) { 16340 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5DiffS cfile");16297 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p5DiffSkyfile"); 16341 16298 return count; 16342 16299 } … … 16347 16304 return deleted; 16348 16305 } 16349 bool p5DiffS cfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)16306 bool p5DiffSkyfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 16350 16307 { 16351 16308 PS_ASSERT_PTR_NON_NULL(objects, false); … … 16353 16310 psMetadata *output = psMetadataAlloc(); 16354 16311 for (long i = 0; i < psArrayLength(objects); i++) { 16355 psMetadata *md = p5DiffS cfileMetadataFromObject(objects->data[i]);16312 psMetadata *md = p5DiffSkyfileMetadataFromObject(objects->data[i]); 16356 16313 if (!psMetadataAddMetadata( 16357 16314 output, 16358 16315 PS_LIST_TAIL, 16359 P5DIFFS CFILE_TABLE_NAME,16316 P5DIFFSKYFILE_TABLE_NAME, 16360 16317 PS_META_DUPLICATE_OK, 16361 16318 NULL, … … 16378 16335 return true; 16379 16336 } 16380 bool p5DiffS cfilePrintObject(FILE *stream, p5DiffScfileRow *object, bool mdcf)16337 bool p5DiffSkyfilePrintObject(FILE *stream, p5DiffSkyfileRow *object, bool mdcf) 16381 16338 { 16382 16339 PS_ASSERT_PTR_NON_NULL(object, false); 16383 16340 16384 psMetadata *md = p5DiffS cfileMetadataFromObject(object);16341 psMetadata *md = p5DiffSkyfileMetadataFromObject(object); 16385 16342 16386 16343 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { … … 16395 16352 static void p6RunRowFree(p6RunRow *object); 16396 16353 16397 p6RunRow *p6RunRowAlloc(psS32 p6_id, const char *state, const char *workdir, const char *dvodb, psTime* registered )16354 p6RunRow *p6RunRowAlloc(psS32 p6_id, const char *state, const char *workdir, const char *dvodb, psTime* registered, const char *skycell_id, const char *tess_id) 16398 16355 { 16399 16356 p6RunRow *_object; … … 16407 16364 _object->dvodb = psStringCopy(dvodb); 16408 16365 _object->registered = psTimeCopy(registered); 16366 _object->skycell_id = psStringCopy(skycell_id); 16367 _object->tess_id = psStringCopy(tess_id); 16409 16368 16410 16369 return _object; … … 16417 16376 psFree(object->dvodb); 16418 16377 psFree(object->registered); 16378 psFree(object->skycell_id); 16379 psFree(object->tess_id); 16419 16380 } 16420 16381 … … 16447 16408 return false; 16448 16409 } 16410 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Key", "64")) { 16411 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 16412 psFree(md); 16413 return false; 16414 } 16415 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Key", "64")) { 16416 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 16417 psFree(md); 16418 return false; 16419 } 16449 16420 16450 16421 bool status = psDBCreateTable(dbh, P6RUN_TABLE_NAME, md); … … 16460 16431 } 16461 16432 16462 bool p6RunInsert(psDB * dbh, psS32 p6_id, const char *state, const char *workdir, const char *dvodb, psTime* registered )16433 bool p6RunInsert(psDB * dbh, psS32 p6_id, const char *state, const char *workdir, const char *dvodb, psTime* registered, const char *skycell_id, const char *tess_id) 16463 16434 { 16464 16435 psMetadata *md = psMetadataAlloc(); … … 16485 16456 if (!psMetadataAdd(md, PS_LIST_TAIL, "registered", PS_DATA_TIME, NULL, registered)) { 16486 16457 psError(PS_ERR_UNKNOWN, false, "failed to add item registered"); 16458 psFree(md); 16459 return false; 16460 } 16461 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) { 16462 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 16463 psFree(md); 16464 return false; 16465 } 16466 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) { 16467 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 16487 16468 psFree(md); 16488 16469 return false; … … 16511 16492 bool p6RunInsertObject(psDB *dbh, p6RunRow *object) 16512 16493 { 16513 return p6RunInsert(dbh, object->p6_id, object->state, object->workdir, object->dvodb, object->registered );16494 return p6RunInsert(dbh, object->p6_id, object->state, object->workdir, object->dvodb, object->registered, object->skycell_id, object->tess_id); 16514 16495 } 16515 16496 … … 16609 16590 return false; 16610 16591 } 16592 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) { 16593 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 16594 psFree(md); 16595 return false; 16596 } 16597 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) { 16598 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 16599 psFree(md); 16600 return false; 16601 } 16611 16602 16612 16603 … … 16643 16634 return false; 16644 16635 } 16645 16646 return p6RunRowAlloc(p6_id, state, workdir, dvodb, registered); 16636 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id"); 16637 if (!status) { 16638 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id"); 16639 return false; 16640 } 16641 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id"); 16642 if (!status) { 16643 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id"); 16644 return false; 16645 } 16646 16647 return p6RunRowAlloc(p6_id, state, workdir, dvodb, registered, skycell_id, tess_id); 16647 16648 } 16648 16649 psArray *p6RunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) … … 16754 16755 return true; 16755 16756 } 16756 static void p6InputS cfileRowFree(p6InputScfileRow *object);16757 16758 p6InputS cfileRow *p6InputScfileRowAlloc(psS32 p6_id, psS32 p4_id, const char *skycell_id, const char *tess_id)16759 { 16760 p6InputS cfileRow *_object;16761 16762 _object = psAlloc(sizeof(p6InputS cfileRow));16763 psMemSetDeallocator(_object, (psFreeFunc)p6InputS cfileRowFree);16757 static void p6InputSkyfileRowFree(p6InputSkyfileRow *object); 16758 16759 p6InputSkyfileRow *p6InputSkyfileRowAlloc(psS32 p6_id, psS32 p4_id) 16760 { 16761 p6InputSkyfileRow *_object; 16762 16763 _object = psAlloc(sizeof(p6InputSkyfileRow)); 16764 psMemSetDeallocator(_object, (psFreeFunc)p6InputSkyfileRowFree); 16764 16765 16765 16766 _object->p6_id = p6_id; 16766 16767 _object->p4_id = p4_id; 16767 _object->skycell_id = psStringCopy(skycell_id);16768 _object->tess_id = psStringCopy(tess_id);16769 16768 16770 16769 return _object; 16771 16770 } 16772 16771 16773 static void p6InputScfileRowFree(p6InputScfileRow *object) 16774 { 16775 psFree(object->skycell_id); 16776 psFree(object->tess_id); 16777 } 16778 16779 bool p6InputScfileCreateTable(psDB *dbh) 16772 static void p6InputSkyfileRowFree(p6InputSkyfileRow *object) 16773 { 16774 } 16775 16776 bool p6InputSkyfileCreateTable(psDB *dbh) 16780 16777 { 16781 16778 psMetadata *md = psMetadataAlloc(); … … 16790 16787 return false; 16791 16788 } 16792 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) { 16793 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 16794 psFree(md); 16795 return false; 16796 } 16797 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) { 16798 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 16799 psFree(md); 16800 return false; 16801 } 16802 16803 bool status = psDBCreateTable(dbh, P6INPUTSCFILE_TABLE_NAME, md); 16789 16790 bool status = psDBCreateTable(dbh, P6INPUTSKYFILE_TABLE_NAME, md); 16804 16791 16805 16792 psFree(md); … … 16808 16795 } 16809 16796 16810 bool p6InputS cfileDropTable(psDB *dbh)16811 { 16812 return psDBDropTable(dbh, P6INPUTS CFILE_TABLE_NAME);16813 } 16814 16815 bool p6InputS cfileInsert(psDB * dbh, psS32 p6_id, psS32 p4_id, const char *skycell_id, const char *tess_id)16797 bool p6InputSkyfileDropTable(psDB *dbh) 16798 { 16799 return psDBDropTable(dbh, P6INPUTSKYFILE_TABLE_NAME); 16800 } 16801 16802 bool p6InputSkyfileInsert(psDB * dbh, psS32 p6_id, psS32 p4_id) 16816 16803 { 16817 16804 psMetadata *md = psMetadataAlloc(); … … 16826 16813 return false; 16827 16814 } 16828 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) { 16829 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id"); 16830 psFree(md); 16831 return false; 16832 } 16833 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) { 16834 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id"); 16835 psFree(md); 16836 return false; 16837 } 16838 16839 bool status = psDBInsertOneRow(dbh, P6INPUTSCFILE_TABLE_NAME, md); 16815 16816 bool status = psDBInsertOneRow(dbh, P6INPUTSKYFILE_TABLE_NAME, md); 16840 16817 psFree(md); 16841 16818 … … 16843 16820 } 16844 16821 16845 long long p6InputS cfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)16822 long long p6InputSkyfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 16846 16823 { 16847 16824 long long deleted = 0; 16848 16825 16849 long long count = psDBDeleteRows(dbh, P6INPUTS CFILE_TABLE_NAME, where, limit);16826 long long count = psDBDeleteRows(dbh, P6INPUTSKYFILE_TABLE_NAME, where, limit); 16850 16827 if (count < 0) { 16851 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6InputS cfile");16828 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6InputSkyfile"); 16852 16829 return count; 16853 16830 … … 16857 16834 return deleted; 16858 16835 } 16859 bool p6InputS cfileInsertObject(psDB *dbh, p6InputScfileRow *object)16860 { 16861 return p6InputS cfileInsert(dbh, object->p6_id, object->p4_id, object->skycell_id, object->tess_id);16862 } 16863 16864 bool p6InputS cfileInsertObjects(psDB *dbh, psArray *objects)16836 bool p6InputSkyfileInsertObject(psDB *dbh, p6InputSkyfileRow *object) 16837 { 16838 return p6InputSkyfileInsert(dbh, object->p6_id, object->p4_id); 16839 } 16840 16841 bool p6InputSkyfileInsertObjects(psDB *dbh, psArray *objects) 16865 16842 { 16866 16843 for (long i = 0; i < psArrayLength(objects); i++) { 16867 if (!p6InputS cfileInsertObject(dbh, objects->data[i])) {16844 if (!p6InputSkyfileInsertObject(dbh, objects->data[i])) { 16868 16845 return false; 16869 16846 } … … 16873 16850 } 16874 16851 16875 bool p6InputS cfileInsertFits(psDB *dbh, const psFits *fits)16852 bool p6InputSkyfileInsertFits(psDB *dbh, const psFits *fits) 16876 16853 { 16877 16854 psArray *rowSet; 16878 16855 16879 // move to (the first?) extension named P6INPUTS CFILE_TABLE_NAME16880 if (!psFitsMoveExtName(fits, P6INPUTS CFILE_TABLE_NAME)) {16881 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P6INPUTS CFILE_TABLE_NAME);16856 // move to (the first?) extension named P6INPUTSKYFILE_TABLE_NAME 16857 if (!psFitsMoveExtName(fits, P6INPUTSKYFILE_TABLE_NAME)) { 16858 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P6INPUTSKYFILE_TABLE_NAME); 16882 16859 return false; 16883 16860 } … … 16897 16874 } 16898 16875 16899 if (!psDBInsertRows(dbh, P6INPUTS CFILE_TABLE_NAME, rowSet)) {16876 if (!psDBInsertRows(dbh, P6INPUTSKYFILE_TABLE_NAME, rowSet)) { 16900 16877 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 16901 16878 psFree(rowSet); … … 16908 16885 } 16909 16886 16910 bool p6InputS cfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)16887 bool p6InputSkyfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 16911 16888 { 16912 16889 psArray *rowSet; 16913 16890 16914 rowSet = psDBSelectRows(dbh, P6INPUTS CFILE_TABLE_NAME, where, limit);16891 rowSet = psDBSelectRows(dbh, P6INPUTSKYFILE_TABLE_NAME, where, limit); 16915 16892 if (!rowSet) { 16916 16893 return false; … … 16918 16895 16919 16896 // output to fits 16920 if (!psFitsWriteTable(fits, NULL, rowSet, P6INPUTS CFILE_TABLE_NAME)) {16897 if (!psFitsWriteTable(fits, NULL, rowSet, P6INPUTSKYFILE_TABLE_NAME)) { 16921 16898 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 16922 16899 psFree(rowSet); … … 16929 16906 } 16930 16907 16931 psMetadata *p6InputS cfileMetadataFromObject(const p6InputScfileRow *object)16908 psMetadata *p6InputSkyfileMetadataFromObject(const p6InputSkyfileRow *object) 16932 16909 { 16933 16910 psMetadata *md = psMetadataAlloc(); … … 16942 16919 return false; 16943 16920 } 16944 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {16945 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");16946 psFree(md);16947 return false;16948 }16949 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {16950 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");16951 psFree(md);16952 return false;16953 }16954 16921 16955 16922 … … 16957 16924 } 16958 16925 16959 p6InputS cfileRow *p6InputScfileObjectFromMetadata(psMetadata *md)16926 p6InputSkyfileRow *p6InputSkyfileObjectFromMetadata(psMetadata *md) 16960 16927 { 16961 16928 … … 16971 16938 return false; 16972 16939 } 16973 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id"); 16974 if (!status) { 16975 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id"); 16976 return false; 16977 } 16978 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id"); 16979 if (!status) { 16980 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id"); 16981 return false; 16982 } 16983 16984 return p6InputScfileRowAlloc(p6_id, p4_id, skycell_id, tess_id); 16985 } 16986 psArray *p6InputScfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 16940 16941 return p6InputSkyfileRowAlloc(p6_id, p4_id); 16942 } 16943 psArray *p6InputSkyfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 16987 16944 { 16988 16945 psArray *rowSet; … … 16990 16947 psU64 i; 16991 16948 16992 rowSet = psDBSelectRows(dbh, P6INPUTS CFILE_TABLE_NAME, where, limit);16949 rowSet = psDBSelectRows(dbh, P6INPUTSKYFILE_TABLE_NAME, where, limit); 16993 16950 if (!rowSet) { 16994 16951 return NULL; … … 17000 16957 17001 16958 for (i = 0; i < rowSet->n; i++) { 17002 p6InputS cfileRow *object = p6InputScfileObjectFromMetadata(rowSet->data[i]);16959 p6InputSkyfileRow *object = p6InputSkyfileObjectFromMetadata(rowSet->data[i]); 17003 16960 psArrayAdd(returnSet, 0, object); 17004 16961 psFree(object); … … 17009 16966 return returnSet; 17010 16967 } 17011 bool p6InputS cfileDeleteObject(psDB *dbh, const p6InputScfileRow *object)17012 { 17013 psMetadata *where = p6InputS cfileMetadataFromObject(object);17014 long long count = psDBDeleteRows(dbh, P6INPUTS CFILE_TABLE_NAME, where, 0);16968 bool p6InputSkyfileDeleteObject(psDB *dbh, const p6InputSkyfileRow *object) 16969 { 16970 psMetadata *where = p6InputSkyfileMetadataFromObject(object); 16971 long long count = psDBDeleteRows(dbh, P6INPUTSKYFILE_TABLE_NAME, where, 0); 17015 16972 psFree(where); 17016 16973 if (count < 0) { 17017 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6InputS cfile");16974 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6InputSkyfile"); 17018 16975 return false; 17019 16976 } … … 17021 16978 // XXX should this be a psAbort() instead? It is possible that 17022 16979 // having an object match multiple rows was by design. 17023 psError(PS_ERR_UNKNOWN, true, "p6InputS cfileRow object matched more then one row. Check your database schema");17024 return false; 17025 } 17026 17027 return true; 17028 } 17029 long long p6InputS cfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)16980 psError(PS_ERR_UNKNOWN, true, "p6InputSkyfileRow object matched more then one row. Check your database schema"); 16981 return false; 16982 } 16983 16984 return true; 16985 } 16986 long long p6InputSkyfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 17030 16987 { 17031 16988 long long deleted = 0; 17032 16989 17033 16990 for (long long i = 0; i < objects->n; i++) { 17034 p6InputS cfileRow *object = objects->data[i];17035 psMetadata *where = p6InputS cfileMetadataFromObject(object);17036 long long count = psDBDeleteRows(dbh, P6INPUTS CFILE_TABLE_NAME, where, limit);16991 p6InputSkyfileRow *object = objects->data[i]; 16992 psMetadata *where = p6InputSkyfileMetadataFromObject(object); 16993 long long count = psDBDeleteRows(dbh, P6INPUTSKYFILE_TABLE_NAME, where, limit); 17037 16994 psFree(where); 17038 16995 if (count < 0) { 17039 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6InputS cfile");16996 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6InputSkyfile"); 17040 16997 return count; 17041 16998 } … … 17046 17003 return deleted; 17047 17004 } 17048 bool p6InputS cfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)17005 bool p6InputSkyfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 17049 17006 { 17050 17007 PS_ASSERT_PTR_NON_NULL(objects, false); … … 17052 17009 psMetadata *output = psMetadataAlloc(); 17053 17010 for (long i = 0; i < psArrayLength(objects); i++) { 17054 psMetadata *md = p6InputS cfileMetadataFromObject(objects->data[i]);17011 psMetadata *md = p6InputSkyfileMetadataFromObject(objects->data[i]); 17055 17012 if (!psMetadataAddMetadata( 17056 17013 output, 17057 17014 PS_LIST_TAIL, 17058 P6INPUTS CFILE_TABLE_NAME,17015 P6INPUTSKYFILE_TABLE_NAME, 17059 17016 PS_META_DUPLICATE_OK, 17060 17017 NULL, … … 17077 17034 return true; 17078 17035 } 17079 bool p6InputS cfilePrintObject(FILE *stream, p6InputScfileRow *object, bool mdcf)17036 bool p6InputSkyfilePrintObject(FILE *stream, p6InputSkyfileRow *object, bool mdcf) 17080 17037 { 17081 17038 PS_ASSERT_PTR_NON_NULL(object, false); 17082 17039 17083 psMetadata *md = p6InputS cfileMetadataFromObject(object);17040 psMetadata *md = p6InputSkyfileMetadataFromObject(object); 17084 17041 17085 17042 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) { … … 17092 17049 return true; 17093 17050 } 17094 static void p6SumS cfileRowFree(p6SumScfileRow *object);17095 17096 p6SumS cfileRow *p6SumScfileRowAlloc(psS32 p6_id, const char *skycell_id, const char *tess_id, const char *uri, psF64 bg, psF64 bg_mean_stdev)17097 { 17098 p6SumS cfileRow*_object;17099 17100 _object = psAlloc(sizeof(p6SumS cfileRow));17101 psMemSetDeallocator(_object, (psFreeFunc)p6SumS cfileRowFree);17051 static void p6SumSkyfileRowFree(p6SumSkyfileRow *object); 17052 17053 p6SumSkyfileRow *p6SumSkyfileRowAlloc(psS32 p6_id, const char *uri, psF64 bg, psF64 bg_mean_stdev) 17054 { 17055 p6SumSkyfileRow *_object; 17056 17057 _object = psAlloc(sizeof(p6SumSkyfileRow)); 17058 psMemSetDeallocator(_object, (psFreeFunc)p6SumSkyfileRowFree); 17102 17059 17103 17060 _object->p6_id = p6_id; 17104 _object->skycell_id = psStringCopy(skycell_id);17105 _object->tess_id = psStringCopy(tess_id);17106 17061 _object->uri = psStringCopy(uri); 17107 17062 _object->bg = bg; … … 17111 17066 } 17112 17067 17113 static void p6SumScfileRowFree(p6SumScfileRow *object) 17114 { 17115 psFree(object->skycell_id); 17116 psFree(object->tess_id); 17068 static void p6SumSkyfileRowFree(p6SumSkyfileRow *object) 17069 { 17117 17070 psFree(object->uri); 17118 17071 } 17119 17072 17120 bool p6SumS cfileCreateTable(psDB *dbh)17073 bool p6SumSkyfileCreateTable(psDB *dbh) 17121 17074 { 17122 17075 psMetadata *md = psMetadataAlloc(); … … 17126 17079 return false; 17127 17080 } 17128 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, "Primary Key", "64")) {17129 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");17130 psFree(md);17131 return false;17132 }17133 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, "Primary Key", "64")) {17134 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");17135 psFree(md);17136 return false;17137 }17138 17081 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, "255")) { 17139 17082 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); … … 17152 17095 } 17153 17096 17154 bool status = psDBCreateTable(dbh, P6SUMS CFILE_TABLE_NAME, md);17097 bool status = psDBCreateTable(dbh, P6SUMSKYFILE_TABLE_NAME, md); 17155 17098 17156 17099 psFree(md); … … 17159 17102 } 17160 17103 17161 bool p6SumS cfileDropTable(psDB *dbh)17162 { 17163 return psDBDropTable(dbh, P6SUMS CFILE_TABLE_NAME);17164 } 17165 17166 bool p6SumS cfileInsert(psDB * dbh, psS32 p6_id, const char *skycell_id, const char *tess_id, const char *uri, psF64 bg, psF64 bg_mean_stdev)17104 bool p6SumSkyfileDropTable(psDB *dbh) 17105 { 17106 return psDBDropTable(dbh, P6SUMSKYFILE_TABLE_NAME); 17107 } 17108 17109 bool p6SumSkyfileInsert(psDB * dbh, psS32 p6_id, const char *uri, psF64 bg, psF64 bg_mean_stdev) 17167 17110 { 17168 17111 psMetadata *md = psMetadataAlloc(); … … 17172 17115 return false; 17173 17116 } 17174 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, skycell_id)) {17175 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");17176 psFree(md);17177 return false;17178 }17179 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, tess_id)) {17180 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");17181 psFree(md);17182 return false;17183 }17184 17117 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, uri)) { 17185 17118 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); … … 17198 17131 } 17199 17132 17200 bool status = psDBInsertOneRow(dbh, P6SUMS CFILE_TABLE_NAME, md);17133 bool status = psDBInsertOneRow(dbh, P6SUMSKYFILE_TABLE_NAME, md); 17201 17134 psFree(md); 17202 17135 … … 17204 17137 } 17205 17138 17206 long long p6SumS cfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit)17139 long long p6SumSkyfileDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 17207 17140 { 17208 17141 long long deleted = 0; 17209 17142 17210 long long count = psDBDeleteRows(dbh, P6SUMS CFILE_TABLE_NAME, where, limit);17143 long long count = psDBDeleteRows(dbh, P6SUMSKYFILE_TABLE_NAME, where, limit); 17211 17144 if (count < 0) { 17212 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6SumS cfile");17145 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6SumSkyfile"); 17213 17146 return count; 17214 17147 … … 17218 17151 return deleted; 17219 17152 } 17220 bool p6SumS cfileInsertObject(psDB *dbh, p6SumScfileRow *object)17221 { 17222 return p6SumS cfileInsert(dbh, object->p6_id, object->skycell_id, object->tess_id, object->uri, object->bg, object->bg_mean_stdev);17223 } 17224 17225 bool p6SumS cfileInsertObjects(psDB *dbh, psArray *objects)17153 bool p6SumSkyfileInsertObject(psDB *dbh, p6SumSkyfileRow *object) 17154 { 17155 return p6SumSkyfileInsert(dbh, object->p6_id, object->uri, object->bg, object->bg_mean_stdev); 17156 } 17157 17158 bool p6SumSkyfileInsertObjects(psDB *dbh, psArray *objects) 17226 17159 { 17227 17160 for (long i = 0; i < psArrayLength(objects); i++) { 17228 if (!p6SumS cfileInsertObject(dbh, objects->data[i])) {17161 if (!p6SumSkyfileInsertObject(dbh, objects->data[i])) { 17229 17162 return false; 17230 17163 } … … 17234 17167 } 17235 17168 17236 bool p6SumS cfileInsertFits(psDB *dbh, const psFits *fits)17169 bool p6SumSkyfileInsertFits(psDB *dbh, const psFits *fits) 17237 17170 { 17238 17171 psArray *rowSet; 17239 17172 17240 // move to (the first?) extension named P6SUMS CFILE_TABLE_NAME17241 if (!psFitsMoveExtName(fits, P6SUMS CFILE_TABLE_NAME)) {17242 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P6SUMS CFILE_TABLE_NAME);17173 // move to (the first?) extension named P6SUMSKYFILE_TABLE_NAME 17174 if (!psFitsMoveExtName(fits, P6SUMSKYFILE_TABLE_NAME)) { 17175 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P6SUMSKYFILE_TABLE_NAME); 17243 17176 return false; 17244 17177 } … … 17258 17191 } 17259 17192 17260 if (!psDBInsertRows(dbh, P6SUMS CFILE_TABLE_NAME, rowSet)) {17193 if (!psDBInsertRows(dbh, P6SUMSKYFILE_TABLE_NAME, rowSet)) { 17261 17194 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 17262 17195 psFree(rowSet); … … 17269 17202 } 17270 17203 17271 bool p6SumS cfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit)17204 bool p6SumSkyfileSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 17272 17205 { 17273 17206 psArray *rowSet; 17274 17207 17275 rowSet = psDBSelectRows(dbh, P6SUMS CFILE_TABLE_NAME, where, limit);17208 rowSet = psDBSelectRows(dbh, P6SUMSKYFILE_TABLE_NAME, where, limit); 17276 17209 if (!rowSet) { 17277 17210 return false; … … 17279 17212 17280 17213 // output to fits 17281 if (!psFitsWriteTable(fits, NULL, rowSet, P6SUMS CFILE_TABLE_NAME)) {17214 if (!psFitsWriteTable(fits, NULL, rowSet, P6SUMSKYFILE_TABLE_NAME)) { 17282 17215 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 17283 17216 psFree(rowSet); … … 17290 17223 } 17291 17224 17292 psMetadata *p6SumS cfileMetadataFromObject(const p6SumScfileRow *object)17225 psMetadata *p6SumSkyfileMetadataFromObject(const p6SumSkyfileRow *object) 17293 17226 { 17294 17227 psMetadata *md = psMetadataAlloc(); … … 17298 17231 return false; 17299 17232 } 17300 if (!psMetadataAdd(md, PS_LIST_TAIL, "skycell_id", PS_DATA_STRING, NULL, object->skycell_id)) {17301 psError(PS_ERR_UNKNOWN, false, "failed to add item skycell_id");17302 psFree(md);17303 return false;17304 }17305 if (!psMetadataAdd(md, PS_LIST_TAIL, "tess_id", PS_DATA_STRING, NULL, object->tess_id)) {17306 psError(PS_ERR_UNKNOWN, false, "failed to add item tess_id");17307 psFree(md);17308 return false;17309 }17310 17233 if (!psMetadataAdd(md, PS_LIST_TAIL, "uri", PS_DATA_STRING, NULL, object->uri)) { 17311 17234 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); … … 17328 17251 } 17329 17252 17330 p6SumS cfileRow *p6SumScfileObjectFromMetadata(psMetadata *md)17253 p6SumSkyfileRow *p6SumSkyfileObjectFromMetadata(psMetadata *md) 17331 17254 { 17332 17255 … … 17337 17260 return false; 17338 17261 } 17339 char* skycell_id = psMetadataLookupPtr(&status, md, "skycell_id");17340 if (!status) {17341 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item skycell_id");17342 return false;17343 }17344 char* tess_id = psMetadataLookupPtr(&status, md, "tess_id");17345 if (!status) {17346 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item tess_id");17347 return false;17348 }17349 17262 char* uri = psMetadataLookupPtr(&status, md, "uri"); 17350 17263 if (!status) { … … 17363 17276 } 17364 17277 17365 return p6SumS cfileRowAlloc(p6_id, skycell_id, tess_id, uri, bg, bg_mean_stdev);17366 } 17367 psArray *p6SumS cfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)17278 return p6SumSkyfileRowAlloc(p6_id, uri, bg, bg_mean_stdev); 17279 } 17280 psArray *p6SumSkyfileSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 17368 17281 { 17369 17282 psArray *rowSet; … … 17371 17284 psU64 i; 17372 17285 17373 rowSet = psDBSelectRows(dbh, P6SUMS CFILE_TABLE_NAME, where, limit);17286 rowSet = psDBSelectRows(dbh, P6SUMSKYFILE_TABLE_NAME, where, limit); 17374 17287 if (!rowSet) { 17375 17288 return NULL; … … 17381 17294 17382 17295 for (i = 0; i < rowSet->n; i++) { 17383 p6SumS cfileRow *object = p6SumScfileObjectFromMetadata(rowSet->data[i]);17296 p6SumSkyfileRow *object = p6SumSkyfileObjectFromMetadata(rowSet->data[i]); 17384 17297 psArrayAdd(returnSet, 0, object); 17385 17298 psFree(object); … … 17390 17303 return returnSet; 17391 17304 } 17392 bool p6SumS cfileDeleteObject(psDB *dbh, const p6SumScfileRow *object)17393 { 17394 psMetadata *where = p6SumS cfileMetadataFromObject(object);17395 long long count = psDBDeleteRows(dbh, P6SUMS CFILE_TABLE_NAME, where, 0);17305 bool p6SumSkyfileDeleteObject(psDB *dbh, const p6SumSkyfileRow *object) 17306 { 17307 psMetadata *where = p6SumSkyfileMetadataFromObject(object); 17308 long long count = psDBDeleteRows(dbh, P6SUMSKYFILE_TABLE_NAME, where, 0); 17396 17309 psFree(where); 17397 17310 if (count < 0) { 17398 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6SumS cfile");17311 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6SumSkyfile"); 17399 17312 return false; 17400 17313 } … … 17402 17315 // XXX should this be a psAbort() instead? It is possible that 17403 17316 // having an object match multiple rows was by design. 17404 psError(PS_ERR_UNKNOWN, true, "p6SumS cfileRow object matched more then one row. Check your database schema");17405 return false; 17406 } 17407 17408 return true; 17409 } 17410 long long p6SumS cfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit)17317 psError(PS_ERR_UNKNOWN, true, "p6SumSkyfileRow object matched more then one row. Check your database schema"); 17318 return false; 17319 } 17320 17321 return true; 17322 } 17323 long long p6SumSkyfileDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 17411 17324 { 17412 17325 long long deleted = 0; 17413 17326 17414 17327 for (long long i = 0; i < objects->n; i++) { 17415 p6SumS cfileRow *object = objects->data[i];17416 psMetadata *where = p6SumS cfileMetadataFromObject(object);17417 long long count = psDBDeleteRows(dbh, P6SUMS CFILE_TABLE_NAME, where, limit);17328 p6SumSkyfileRow *object = objects->data[i]; 17329 psMetadata *where = p6SumSkyfileMetadataFromObject(object); 17330 long long count = psDBDeleteRows(dbh, P6SUMSKYFILE_TABLE_NAME, where, limit); 17418 17331 psFree(where); 17419 17332 if (count < 0) { 17420 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6SumS cfile");17333 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p6SumSkyfile"); 17421 17334 return count; 17422 17335 } … … 17427 17340 return deleted; 17428 17341 } 17429 bool p6SumS cfilePrintObjects(FILE *stream, psArray *objects, bool mdcf)17342 bool p6SumSkyfilePrintObjects(FILE *stream, psArray *objects, bool mdcf) 17430 17343 { 17431 17344 PS_ASSERT_PTR_NON_NULL(objects, false); … … 17433 17346 psMetadata *output = psMetadataAlloc(); 17434 17347 for (long i = 0; i < psArrayLength(objects); i++) { 17435 psMetadata *md = p6SumS cfileMetadataFromObject(objects->data[i]);17348 psMetadata *md = p6SumSkyfileMetadataFromObject(objects->data[i]); 17436 17349 if (!psMetadataAddMetadata( 17437 17350 output, 17438 17351 PS_LIST_TAIL, 17439 P6SUMS CFILE_TABLE_NAME,17352 P6SUMSKYFILE_TABLE_NAME, 17440 17353 PS_META_DUPLICATE_OK, 17441 17354 NULL, … … 17458 17371 return true; 17459 17372 } 17460 bool p6SumS cfilePrintObject(FILE *stream, p6SumScfileRow *object, bool mdcf)17373 bool p6SumSkyfilePrintObject(FILE *stream, p6SumSkyfileRow *object, bool mdcf) 17461 17374 { 17462 17375 PS_ASSERT_PTR_NON_NULL(object, false); 17463 17376 17464 psMetadata *md = p6SumS cfileMetadataFromObject(object);17377 psMetadata *md = p6SumSkyfileMetadataFromObject(object); 17465 17378 17466 17379 if (!ippdbPrintMetadataRaw(stream, md, mdcf)) {
Note:
See TracChangeset
for help on using the changeset viewer.
