- Timestamp:
- Jan 19, 2024, 8:12:15 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20230313/ippTools/src/xcfftool.c
r42594 r42596 33 33 34 34 static bool definebyqueryMode(pxConfig *config); 35 static bool defineforstacksMode(pxConfig *config);36 35 static bool updaterunMode(pxConfig *config); 37 36 static bool todoMode(pxConfig *config); … … 48 47 static bool importrunMode(pxConfig *config); 49 48 50 static bool setxcForceRunState(pxConfig *config, psS64 sky_id, const char *state);51 static psS64 getCameraIDfromName(pxConfig *config, const char * camera);49 static bool setxcForceRunState(pxConfig *config, psS64 xcff_id, const char *state); 50 static psS64 getCameraIDfromName(pxConfig *config, const char *dbname, const char *camera); 52 51 53 52 # define MODECASE(caseName, func) \ … … 70 69 switch (config->mode) { 71 70 MODECASE(XCFFTOOL_MODE_DEFINEBYQUERY, definebyqueryMode); 72 MODECASE(XCFFTOOL_MODE_DEFINEFORSTACKS, defineforstacksMode);73 71 MODECASE(XCFFTOOL_MODE_UPDATERUN, updaterunMode); 74 72 MODECASE(XCFFTOOL_MODE_TODO, todoMode); … … 110 108 { 111 109 PS_ASSERT_PTR_NON_NULL(config, false); 110 111 // I need the name of the current working database 112 psMetadataItem *dbnameMD = pmConfigUserSite(config->modules, "DBNAME", PS_DATA_STRING); 113 char *dbname = dbnameMD->data.str; 114 115 // required: 112 116 PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false); 113 117 PXOPT_LOOKUP_STR(label, config->args, "-set_label", true, false); 114 118 119 // we have two relevant databases: the current working database (e.g., gpc1) and the cross-camera 120 // database used to generate the cross-camera stacks (e.g., xcamera). the cross-camera database 121 // name is supplied with -xcamera as an argument. the current working database is part of the 122 // database config info 123 115 124 // The xcamera must be supplied as a string, then the camera_id is selected 116 // from the table xcstackCamera. 125 // from the table xcstackCamera. 117 126 PXOPT_LOOKUP_STR(xcamera, config->args, "-xcamera", true, false); 118 127 119 // get camera_id for the working database: 120 // XXX need to extract the camera name (-dbname) from the config 121 psS64 camera_id = getCameraIDfromName(config, config->dbh->camera); 128 // get camera_id for the working database from the xcamera database 129 psS64 camera_id = getCameraIDfromName(config, xcamera, dbname); 122 130 if (!camera_id) { 123 psError(PXTOOLS_ERR_SYS, false, "failed to find xcamera in database"); 124 return false; 131 psError(PXTOOLS_ERR_SYS, false, "failed to find camera %s in database", dbname); 132 return false; 133 } 134 // get xcamera_id for the cross-camera database from the working database 135 psS64 xcamera_id = getCameraIDfromName(config, dbname, xcamera); 136 if (!xcamera_id) { 137 psError(PXTOOLS_ERR_SYS, false, "failed to find camera %s in database", xcamera); 138 return false; 125 139 } 126 140 … … 131 145 PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false); 132 146 133 // XXX is needed or wanted?134 // PXOPT_LOOKUP_STR(sources_path_base, config->args, "-set_sources_path_base", false, false);135 136 147 // first, we need to select the xccalRun(s) which need to have xcForceRuns. we can limit the selection based on 137 148 // qualities of the xccalRun or the xcstackRun. There will be one xcForceRun for each 138 // identified xccalRun .149 // identified xccalRun (there may be multiple xcForceRuns with different labels) 139 150 140 151 psMetadata *xccalWhereMD = psMetadataAlloc(); … … 149 160 } 150 161 151 PXOPT_COPY_STR(config->args, xccalWhereMD, "-select_skycell_id", "xcstackRun.skycell_id", "LIKE"); 152 PXOPT_COPY_STR(config->args, xccalWhereMD, "-select_tess_id", "xcstackRun.tess_id", "=="); 153 pxAddLabelSearchArgs(config, xccalWhereMD, "-select_filter", "xcstackRun.filter", "LIKE"); 162 // the select query does not join to xcstackRun, but it does join to stackRun 163 PXOPT_COPY_STR(config->args, xccalWhereMD, "-select_skycell_id", "stackRun.skycell_id", "LIKE"); 164 PXOPT_COPY_STR(config->args, xccalWhereMD, "-select_tess_id", "stackRun.tess_id", "=="); 165 pxAddLabelSearchArgs(config, xccalWhereMD, "-select_filter", "stackRun.filter", "LIKE"); 154 166 if (!pxskycellAddWhere(config, xccalWhereMD)) { 155 167 psError(PXTOOLS_ERR_CONFIG, false, "failed to add skycell search arguments"); … … 167 179 pxAddLabelSearchArgs(config, warpWhereMD, "-select_warp_data_group", "warpRun.data_group", "LIKE"); 168 180 PXOPT_COPY_S64(config->args, warpWhereMD, "-select_warp_id", "warpRun.warp_id", "=="); 181 PXOPT_COPY_F32(config->args, warpWhereMD, "-select_good_frac_min", "warpSkyfile.good_frac", ">="); 169 182 // XXX is is really necessary to limit the warps? 170 183 if (!psListLength(warpWhereMD->list)) { … … 174 187 return false; 175 188 } 176 PXOPT_COPY_F32(config->args, warpWhereMD, "-select_good_frac_min", "warpSkyfile.good_frac", ">=");177 189 178 190 PXOPT_LOOKUP_BOOL(rerun, config->args, "-rerun", false); … … 180 192 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 181 193 182 psString select = pxDataGet("xcfftool_definebyquery.sql"); 183 if (!select) { 194 psString select = NULL; 195 196 psString query_pt1 = pxDataGet("xcfftool_definebyquery_pt1.sql"); 197 if (!query_pt1) { 184 198 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 185 199 psFree(xccalWhereMD); … … 188 202 } 189 203 204 // query_pt1 has 4 places where the xcamera database name must be supplied 205 psStringAppend (&select, query_pt1, xcamera, xcamera, xcamera, xcamera); 206 psFree (query_pt1); 207 208 if (!rerun) { 209 psStringAppend(&select, "LEFT JOIN xcForceRun ON (xcForceRun.xccal_id = %s.xccalRun.xccal_id) AND (xcForceRun.label = '%s')\n", xcamera, label); 210 } 211 212 psString query_pt2 = pxDataGet("xcfftool_definebyquery_pt2.sql"); 213 if (!query_pt2) { 214 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 215 psFree(xccalWhereMD); 216 psFree(warpWhereMD); 217 psFree(select); 218 return false; 219 } 220 221 // query_pt2 has 3 places where the xcamera database name must be supplied and 1 for this camera 222 psStringAppend (&select, query_pt2, xcamera, (long long) camera_id, xcamera, xcamera); 223 psFree (query_pt2); 224 190 225 psString where = NULL; 191 226 psString whereClause = psDBGenerateWhereConditionSQL(xccalWhereMD, NULL); 192 psStringAppend(&where, "\nAND %s", whereClause); 193 psStringAppend(&select, " %s", where); 227 psStringAppend(&select, "\n AND %s", whereClause); 194 228 195 229 psFree(whereClause); 196 230 psFree(xccalWhereMD); 197 231 198 psString joinHook = NULL; 199 if (!rerun) { 200 psStringAppend(&joinHook, "\nLEFT JOIN xcForceRun ON xcForceRun.xccal_id = %s.xccalRun.xccal_id", xcamera); 201 } 202 203 psStringAppend(&joinHook, "\n %s, where); 204 205 if ( 206 psStringAppend(&joinHook, "\n %s\nAND xcForceRun.label = '%s'", where, label); 207 psStringAppend(&select, "\nAND ff_id IS NULL"); 208 } 209 210 // XXX need to add the xcamera name here to match definebyquery.sql 211 if (!p_psDBRunQueryF(config->dbh, select, joinHook)) { 232 // accept only the entries without a match in the target label 233 if (!rerun) psStringAppend(&select, "\n AND xcff_id IS NULL\n"); 234 235 if (!p_psDBRunQuery(config->dbh, select)) { 212 236 psError(PS_ERR_UNKNOWN, false, "database error"); 213 237 psFree(select); … … 215 239 } 216 240 psFree(select); 217 psFree(joinHook);218 241 219 242 psArray *output = p_psDBFetchResult(config->dbh); … … 251 274 } 252 275 276 // this query selects all of the warps where were inputs to the given stackRun, 277 // with restrictions based on (quality, fault, warpRun.state, and other supplied conditions) 278 // there is no limit to the version of the warp analyss, to 253 279 psString warpQueryTemplate = pxDataGet("xcfftool_definebyquery_select_warps.sql"); 254 280 255 281 whereClause = psDBGenerateWhereConditionSQL(warpWhereMD, NULL); 256 psStringAppend(&warpQueryTemplate, "\n AND %s", whereClause);282 psStringAppend(&warpQueryTemplate, "\n AND %s", whereClause); 257 283 258 284 for (long i = 0; i < output->n; i++) { … … 268 294 // psS64 warp_id = psMetadataLookupS64(&status, row, "warp_id"); 269 295 psS64 xccal_id = psMetadataLookupS64(&status, row, "xccal_id"); 270 271 psString path_base = NULL; 272 if (sources_path_base) { 273 path_base = sources_path_base; 274 } else { 275 path_base = psMetadataLookupStr(&status, row, "path_base"); 276 psAssert(status, "failed to find xccal path_base?"); 277 } 278 296 psS64 stack_id = psMetadataLookupS64(&status, row, "stack_id"); 297 psString path_base = psMetadataLookupStr(&status, row, "path_base"); 279 298 psString xccal_data_group = psMetadataLookupStr(&status, row, "data_group"); 280 299 psString tess_id = psMetadataLookupStr(&status, row, "tess_id"); 281 300 psString skycell_id = psMetadataLookupStr(&status, row, "skycell_id"); 282 psString filter = psMetadataLookupStr(&status, row, "filter");283 301 284 302 psString query = NULL; 285 psStringAppend(&query, warpQueryTemplate, tess_id, skycell_id, filter);303 psStringAppend(&query, warpQueryTemplate, (long long) stack_id); 286 304 287 305 if (!p_psDBRunQuery(config->dbh, query)) { … … 315 333 // create an xcForceRun 316 334 if (!xcForceRunInsert(config->dbh, 317 0x0, // ff_id 318 xccal_id, 319 path_base, 320 "new", // state 321 workdir, 322 label, 323 data_group ? data_group : (xccal_data_group ? xccal_data_group : label), 324 dist_group, 325 note, 326 reduction, 327 NULL // registered 335 0x0, // xcff_id 336 xccal_id, 337 path_base, 338 "new", // state 339 workdir, 340 label, 341 skycell_id, 342 tess_id, 343 data_group ? data_group : (xccal_data_group ? xccal_data_group : label), 344 dist_group, 345 note, 346 reduction, 347 NULL // registered 328 348 ) 329 349 ) { … … 342 362 psS64 warp_id = psMetadataLookupS64(&status, warpRow, "warp_id"); 343 363 344 if (!xcForceInputInsert(config->dbh, ff_id, warp_id, xcamera_id) 345 ) { 364 if (!xcForceInputInsert(config->dbh, xcff_id, warp_id, xcamera_id)) { 346 365 if (!psDBRollback(config->dbh)) { 347 366 psError(PS_ERR_UNKNOWN, false, "database error failed to rollback transaction"); … … 372 391 373 392 psMetadata *where = psMetadataAlloc(); 374 PXOPT_COPY_S64(config->args, where, "-xcff_id", "xcff_id", "=="); 375 PXOPT_COPY_STR(config->args, where, "-label", "xcForceRun.label", "=="); 376 PXOPT_COPY_STR(config->args, where, "-data_group", "xcForceRun.data_group", "=="); 377 PXOPT_COPY_STR(config->args, where, "-state", "xcForceRun.state", "=="); 378 PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "=="); 393 PXOPT_COPY_S64(config->args, where, "-xcff_id", "xcff_id", "=="); 394 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 395 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 396 PXOPT_COPY_STR(config->args, where, "-data_group", "data_group", "=="); 397 PXOPT_COPY_STR(config->args, where, "-dist_group", "dist_group", "=="); 398 PXOPT_COPY_STR(config->args, where, "-skycell_id", "skycell_id", "=="); 399 PXOPT_COPY_STR(config->args, where, "-tess_id", "tess_id", "=="); 379 400 if (!pxskycellAddWhere(config, where)) { 380 401 psError(PXTOOLS_ERR_CONFIG, false, "failed to add skycell search arguments"); … … 387 408 } 388 409 389 psString query = pxDataGet("xcfftool_updaterun.sql"); 390 if (!select) { 391 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 392 return false; 393 } 410 psString query = psStringCopy ("UPDATE xcForceRun JOIN skycell USING(tess_id, skycell_id)"); 394 411 395 412 // pxUpdateRun gets parameters from config->args and updates 396 bool result = pxUpdateRun(config, where, &query, "xcForceRun", " ff_id", "xcForceResult", true, false);413 bool result = pxUpdateRun(config, where, &query, "xcForceRun", "xcff_id", "xcForceResult", true, false); 397 414 psFree(query); 398 415 psFree(where); … … 407 424 408 425 psMetadata *whereMD = psMetadataAlloc(); 409 PXOPT_COPY_S64(config->args, whereMD, "- ff_id", "ff_id", "==");410 pxAddLabelSearchArgs (config, whereMD, "-label", "xcForceRun.label", "==");426 PXOPT_COPY_S64(config->args, whereMD, "-xcff_id", "xcff_id", "=="); 427 pxAddLabelSearchArgs (config, whereMD, "-label", "xcForceRun.label", "=="); 411 428 pxskycellAddWhere(config, whereMD); 412 429 … … 482 499 PS_ASSERT_PTR_NON_NULL(config, false); 483 500 // required 484 PXOPT_LOOKUP_S64( ff_id, config->args, "-ff_id", true, false);501 PXOPT_LOOKUP_S64(xcff_id, config->args, "-xcff_id", true, false); 485 502 PXOPT_LOOKUP_S64(warp_id, config->args, "-warp_id", true, false); 486 503 … … 497 514 // XXX not sure we need a transaction here... 498 515 if (!xcForceResultInsert(config->dbh, 499 ff_id,516 xcff_id, 500 517 warp_id, 501 518 path_base, … … 521 538 522 539 psMetadata *where = psMetadataAlloc(); 523 PXOPT_COPY_S64(config->args, where, "- ff_id", "xcForceRun.ff_id", "==");540 PXOPT_COPY_S64(config->args, where, "-xcff_id", "xcForceRun.xcff_id", "=="); 524 541 PXOPT_COPY_S64(config->args, where, "-warp_id", "xcForceResult.warp_id", "=="); 525 542 PXOPT_COPY_S64(config->args, where, "-exp_id", "rawExp.exp_id", "=="); … … 608 625 609 626 psMetadata *where = psMetadataAlloc(); 610 PXOPT_COPY_S64(config->args, where, "- ff_id", "xcForceRun.ff_id", "==");627 PXOPT_COPY_S64(config->args, where, "-xcff_id", "xcForceRun.ff_id", "=="); 611 628 PXOPT_COPY_S64(config->args, where, "-warp_id", "xcForceResult.warp_id", "=="); 612 629 pxAddLabelSearchArgs(config, where, "-label", "xcForceRun.label", "=="); … … 660 677 661 678 psMetadata *where = psMetadataAlloc(); 662 PXOPT_COPY_S64(config->args, where, "- ff_id", "ff_id", "==");679 PXOPT_COPY_S64(config->args, where, "-xcff_id", "xcff_id", "=="); 663 680 PXOPT_COPY_S64(config->args, where, "-warp_id", "warp_id", "=="); 664 681 … … 672 689 } 673 690 674 static bool setxcForceRunState(pxConfig *config, psS64 ff_id, const char *state)675 {676 psString query = "UPDATE xcForceRun SET state = 'full' WHERE ff_id = %" PRId64;677 if (!p_psDBRunQueryF(config->dbh, query, ff_id)) {678 psError(PS_ERR_UNKNOWN, false, "database error");679 return false;680 }681 682 return true;683 }684 685 691 static bool toadvanceMode(pxConfig *config) { 686 692 PS_ASSERT_PTR_NON_NULL(config, false); 687 693 688 694 psMetadata *whereMD = psMetadataAlloc(); 689 PXOPT_COPY_S64(config->args, whereMD, "- ff_id", "ff_id", "==");695 PXOPT_COPY_S64(config->args, whereMD, "-xcff_id", "xcff_id", "=="); 690 696 pxAddLabelSearchArgs (config, whereMD, "-label", "xcForceRun.label", "=="); 691 697 pxskycellAddWhere(config, whereMD); … … 765 771 PS_ASSERT_PTR_NON_NULL(config, false); 766 772 // required 767 PXOPT_LOOKUP_S64( ff_id, config->args, "-ff_id", true, false);773 PXOPT_LOOKUP_S64(xcff_id, config->args, "-xcff_id", true, false); 768 774 769 775 // optional … … 783 789 784 790 if (!xcForceSummaryInsert(config->dbh, 785 ff_id,791 xcff_id, 786 792 path_base, 787 793 dtime_script, … … 799 805 800 806 if (!fault) { 801 if (!setxcForceRunState(config, ff_id, "full")) {807 if (!setxcForceRunState(config, xcff_id, "full")) { 802 808 if (!psDBRollback(config->dbh)) { 803 809 psError(PS_ERR_UNKNOWN, false, "database error"); … … 817 823 } 818 824 819 static bool revertsummaryMode(pxConfig *config) {820 PS_ASSERT_PTR_NON_NULL(config, false);821 822 psMetadata *where = psMetadataAlloc();823 PXOPT_COPY_S64(config->args, where, "-ff_id", "xcForceRun.ff_id", "==");824 pxAddLabelSearchArgs(config, where, "-label", "xcForceRun.label", "==");825 PXOPT_COPY_S16(config->args, where, "-fault", "xcForceSummary.fault", "==");826 827 if (!pxskycellAddWhere(config, where)) {828 psError(PXTOOLS_ERR_CONFIG, false, "failed to add skycell search arguments");829 return false;830 }831 832 if (!psListLength(where->list)) {833 psFree(where);834 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");835 return false;836 }837 838 // Delete product839 psString delete = pxDataGet("xcfftool_revertsummary.sql");840 if (!delete) {841 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");842 return false;843 }844 845 if (psListLength(where->list)) {846 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);847 psStringAppend(&delete, " AND %s", whereClause);848 psFree(whereClause);849 }850 851 if (!p_psDBRunQuery(config->dbh, delete)) {852 psError(PS_ERR_UNKNOWN, false, "database error");853 psFree(delete);854 psFree(where);855 return false;856 }857 psFree(delete);858 859 int numRows = psDBAffectedRows(config->dbh); // Number of row affected860 psLogMsg("xcfftool", PS_LOG_INFO, "Deleted %d rows", numRows);861 862 psFree(where);863 return true;864 }865 static bool updatesummaryMode(pxConfig *config) {866 PS_ASSERT_PTR_NON_NULL(config, false);867 868 PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);869 PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false);870 871 psMetadata *where = psMetadataAlloc();872 PXOPT_COPY_S64(config->args, where, "-ff_id", "ff_id", "==");873 874 875 if (!pxSetFaultCode(config->dbh, "xcForceSummary", where, fault, quality)) {876 psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");877 psFree (where);878 return false;879 }880 psFree (where);881 return true;882 }883 825 static bool summaryMode(pxConfig *config) { 884 826 PS_ASSERT_PTR_NON_NULL(config, false); 885 827 886 828 psMetadata *where = psMetadataAlloc(); 887 PXOPT_COPY_S64(config->args, where, "-ff_id", "xcForceRun.ff_id", "=="); 888 PXOPT_COPY_S64(config->args, where, "-warp_id", "xcForceInput.warp_id", "=="); 889 PXOPT_COPY_S64(config->args, where, "-exp_id", "rawExp.exp_id", "=="); 890 PXOPT_COPY_STR(config->args, where, "-exp_name", "rawExp.exp_name", "=="); 891 PXOPT_COPY_S64(config->args, where, "-xccal_id", "xcForceRun.xccal_id", "=="); 892 PXOPT_COPY_S64(config->args, where, "-stack_id", "stackRun.stack_id", "=="); 829 PXOPT_COPY_S64(config->args, where, "-xcff_id", "xcForceRun.xcff_id", "=="); 830 PXOPT_COPY_S64(config->args, where, "-xccal_id", "xcForceRun.xccal_id", "=="); 893 831 PXOPT_COPY_STR(config->args, where, "-label", "xcForceRun.label", "=="); 894 832 PXOPT_COPY_STR(config->args, where, "-data_group", "xcForceRun.data_group", "LIKE"); 895 PXOPT_COPY_STR(config->args, where, "-tess_id", "stackRun.tess_id", "LIKE"); 896 PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "LIKE"); 897 PXOPT_COPY_STR(config->args, where, "-filter", "stackRun.filter", "LIKE"); 833 PXOPT_COPY_STR(config->args, where, "-tess_id", "xcForceRun.tess_id", "LIKE"); 834 PXOPT_COPY_STR(config->args, where, "-skycell_id", "xcForceRun.skycell_id", "LIKE"); 898 835 PXOPT_COPY_S16(config->args, where, "-fault", "xcForceSummary.fault", "=="); 899 836 pxskycellAddWhere(config, where); … … 966 903 } 967 904 905 static bool revertsummaryMode(pxConfig *config) { 906 PS_ASSERT_PTR_NON_NULL(config, false); 907 908 psMetadata *where = psMetadataAlloc(); 909 PXOPT_COPY_S64(config->args, where, "-xcff_id", "xcForceRun.xcff_id", "=="); 910 pxAddLabelSearchArgs(config, where, "-label", "xcForceRun.label", "=="); 911 PXOPT_COPY_S16(config->args, where, "-fault", "xcForceSummary.fault", "=="); 912 913 if (!pxskycellAddWhere(config, where)) { 914 psError(PXTOOLS_ERR_CONFIG, false, "failed to add skycell search arguments"); 915 return false; 916 } 917 918 if (!psListLength(where->list)) { 919 psFree(where); 920 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 921 return false; 922 } 923 924 // Delete product 925 psString delete = pxDataGet("xcfftool_revertsummary.sql"); 926 if (!delete) { 927 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 928 return false; 929 } 930 931 if (psListLength(where->list)) { 932 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 933 psStringAppend(&delete, " AND %s", whereClause); 934 psFree(whereClause); 935 } 936 937 if (!p_psDBRunQuery(config->dbh, delete)) { 938 psError(PS_ERR_UNKNOWN, false, "database error"); 939 psFree(delete); 940 psFree(where); 941 return false; 942 } 943 psFree(delete); 944 945 int numRows = psDBAffectedRows(config->dbh); // Number of row affected 946 psLogMsg("xcfftool", PS_LOG_INFO, "Deleted %d rows", numRows); 947 948 psFree(where); 949 return true; 950 } 951 952 static bool updatesummaryMode(pxConfig *config) { 953 PS_ASSERT_PTR_NON_NULL(config, false); 954 955 PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false); 956 PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false); 957 958 psMetadata *where = psMetadataAlloc(); 959 PXOPT_COPY_S64(config->args, where, "-xcff_id", "xcff_id", "=="); 960 961 if (!pxSetFaultCode(config->dbh, "xcForceSummary", where, fault, quality)) { 962 psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag"); 963 psFree (where); 964 return false; 965 } 966 psFree (where); 967 return true; 968 } 969 968 970 bool exportrunMode(pxConfig *config) 969 971 { 970 typedef struct ExportTable {971 char tableName[80];972 char sqlFilename[80];973 } ExportTable;972 typedef struct ExportTable { 973 char tableName[80]; 974 char tableSQL[80]; 975 } ExportTable; 974 976 975 977 PS_ASSERT_PTR_NON_NULL(config, NULL); 976 978 977 // PXOPT_LOOKUP_S64(det_id, config->args, "-warp_id", true, false);978 979 PXOPT_LOOKUP_STR(outfile, config->args, "-outfile", true, false); 979 980 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 980 // PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false);981 981 982 982 FILE *f = fopen (outfile, "w"); … … 994 994 995 995 ExportTable tables [] = { 996 {"xcForceRun", "xcfftool_export_run.sql"},997 {"xcForceInput", "xcfftool_export_input.sql"},998 {"xcForceResult", "xcfftool_export_result.sql"},999 {"xcForceSummary", "xcfftool_export_summary.sql"},996 {"xcForceRun", "SELECT xcForceRun.* FROM xcForceRun"}, 997 {"xcForceInput", "SELECT xcForceInput.* FROM xcForceInput"}, 998 {"xcForceResult", "SELECT xcForceResult.* FROM xcForceResult"}, 999 {"xcForceSummary", "SELECT xcForceSummary.* FROM xcForceSummary"}, 1000 1000 }; 1001 1001 … … 1003 1003 1004 1004 for (int i=0; i < numTables; i++) { 1005 psString query = pxDataGet(tables[i].sqlFilename); 1006 if (!query) { 1007 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1008 return false; 1009 } 1010 1011 if (where && psListLength(where->list)) { 1012 psString whereClause = psDBGenerateWhereSQL(where, NULL); 1013 psStringAppend(&query, " %s", whereClause); 1014 psFree(whereClause); 1015 } 1016 1017 // treat limit == 0 as "no limit" 1018 if (limit) { 1019 psString limitString = psDBGenerateLimitSQL(limit); 1020 psStringAppend(&query, " %s", limitString); 1021 psFree(limitString); 1022 } 1023 1024 if (!p_psDBRunQuery(config->dbh, query)) { 1025 psError(PS_ERR_UNKNOWN, false, "database error"); 1026 psFree(query); 1027 return false; 1028 } 1029 psFree(query); 1030 1031 psArray *output = p_psDBFetchResult(config->dbh); 1032 if (!output) { 1033 psError(PS_ERR_UNKNOWN, false, "database error"); 1034 return false; 1035 } 1036 if (!psArrayLength(output)) { 1037 psError(PS_ERR_UNKNOWN, true, "no rows found"); 1038 psFree(output); 1039 return false; 1040 } 1041 1042 // we must write the export table in non-simple (true) format 1043 if (!ippdbPrintMetadatas(f, output, tables[i].tableName, true)) { 1044 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1045 psFree(output); 1046 return false; 1047 } 1048 psFree(output); 1005 psString query = psStringCopy(tables[i].tableSQL); 1006 1007 if (where && psListLength(where->list)) { 1008 psString whereClause = psDBGenerateWhereSQL(where, NULL); 1009 psStringAppend(&query, " %s", whereClause); 1010 psFree(whereClause); 1011 } 1012 1013 // treat limit == 0 as "no limit" 1014 if (limit) { 1015 psString limitString = psDBGenerateLimitSQL(limit); 1016 psStringAppend(&query, " %s", limitString); 1017 psFree(limitString); 1018 } 1019 1020 if (!p_psDBRunQuery(config->dbh, query)) { 1021 psError(PS_ERR_UNKNOWN, false, "database error"); 1022 psFree(query); 1023 return false; 1024 } 1025 psFree(query); 1026 1027 psArray *output = p_psDBFetchResult(config->dbh); 1028 if (!output) { 1029 psError(PS_ERR_UNKNOWN, false, "database error"); 1030 return false; 1031 } 1032 if (!psArrayLength(output)) { 1033 psError(PS_ERR_UNKNOWN, true, "no rows found"); 1034 psFree(output); 1035 return false; 1036 } 1037 1038 // we must write the export table in non-simple (true) format 1039 if (!ippdbPrintMetadatas(f, output, tables[i].tableName, true)) { 1040 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1041 psFree(output); 1042 return false; 1043 } 1044 psFree(output); 1049 1045 } 1050 1046 … … 1054 1050 } 1055 1051 1052 // XXX this is coded in a very strange way 1056 1053 bool importrunMode(pxConfig *config) 1057 1054 { … … 1067 1064 1068 1065 psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false); 1069 1070 #ifdef notdef1071 fprintf (stderr, "---- input ----\n");1072 psMetadataPrint (stderr, input, 1);1073 #endif1074 1066 1075 1067 if (!pxCheckImportVersion(config, input)) { … … 1143 1135 // We expect the camera to be defined, so an invalid name or a missing camera 1144 1136 // results in a 0 return value which should be treated as an error. 1145 static psS64 getCameraIDfromName(pxConfig *config, const char * camera)1137 static psS64 getCameraIDfromName(pxConfig *config, const char *dbname, const char *camera) 1146 1138 { 1147 1139 PS_ASSERT_PTR_NON_NULL(camera, false); 1148 1140 1149 char *query = "SELECT camera_id FROM xcstackCamera WHERE camera = '%s'";1150 if (!p_psDBRunQueryF(config->dbh, query, camera)) {1151 psError(PS_ERR_UNKNOWN, false, "failed to select camera_id for camera %s ", camera);1141 char *query = "SELECT camera_id FROM %s.xcstackCamera WHERE camera = '%s'"; 1142 if (!p_psDBRunQueryF(config->dbh, query, dbname, camera)) { 1143 psError(PS_ERR_UNKNOWN, false, "failed to select camera_id for camera %s from database %s", camera, dbname); 1152 1144 return 0; 1153 1145 } … … 1197 1189 } 1198 1190 1199 1191 static bool setxcForceRunState(pxConfig *config, psS64 xcff_id, const char *state) 1192 { 1193 psString query = "UPDATE xcForceRun SET state = 'full' WHERE xcff_id = %" PRId64; 1194 if (!p_psDBRunQueryF(config->dbh, query, xcff_id)) { 1195 psError(PS_ERR_UNKNOWN, false, "database error"); 1196 return false; 1197 } 1198 1199 return true; 1200 } 1201
Note:
See TracChangeset
for help on using the changeset viewer.
