Changeset 14600
- Timestamp:
- Aug 21, 2007, 4:27:42 PM (19 years ago)
- Location:
- trunk/ippTools
- Files:
-
- 1 added
- 7 edited
-
share/Makefile.am (modified) (1 diff)
-
share/pztool_find_completed_exp.sql (added)
-
src/Makefile.am (modified) (2 diffs)
-
src/pzgetexpConfig.c (modified) (2 diffs)
-
src/pzgetimfiles.c (modified) (2 diffs)
-
src/pzgetimfilesConfig.c (modified) (2 diffs)
-
src/pztool.c (modified) (4 diffs)
-
src/pztoolConfig.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/share/Makefile.am
r14269 r14600 38 38 difftool_todiffskyfile.sql \ 39 39 difftool_revertdiffskyfile.sql \ 40 pztool_find_completed_exp.sql \ 40 41 regtool_pendingexp.sql \ 41 42 regtool_pendingimfile.sql \ -
trunk/ippTools/src/Makefile.am
r14512 r14600 14 14 warptool \ 15 15 pzgetimfiles \ 16 ttree \ 16 17 pztool 17 18 … … 65 66 # for pxtools.h 66 67 AM_CPPFLAGS = -I$(top_srcdir)/src$ 68 69 70 ttree_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS) 71 ttree_LDADD = $(PSLIB_LIBS) $(PSMODULES_LIBS) $(IPPDB_LIBS) libpxtools.la 72 ttree_SOURCES = \ 73 ttree.c 67 74 68 75 pztool_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS) -
trunk/ippTools/src/pzgetexpConfig.c
r11857 r14600 46 46 psMetadata *args = psMetadataAlloc(); 47 47 psMetadataAddStr(args , PS_LIST_TAIL, "-uri", 0, 48 "DataStore product URI ", "");48 "DataStore product URI (required)", ""); 49 49 psMetadataAddStr(args , PS_LIST_TAIL, "-inst", 0, 50 "camera name ", "");50 "camera name (required)", ""); 51 51 psMetadataAddStr(args , PS_LIST_TAIL, "-telescope", 0, 52 "telescope name ", "");52 "telescope name (required)", ""); 53 53 54 54 bool status = false; … … 60 60 ) { 61 61 fprintf(stderr, "error parsing arguments\n"); 62 printf("\nPan-STARRS Phase Z SearchTool\n");62 printf("\nPan-STARRS Phase Z Get Exposures Tool\n"); 63 63 printf("Usage: %s -uri <uri> -inst <camera> -telescope <telescope>\n\n", 64 64 argv[0]); -
trunk/ippTools/src/pzgetimfiles.c
r14023 r14600 274 274 " incoming.telescope," 275 275 " incoming.class," 276 " incoming.class_id," 277 " NULL" // exp_id, will be assigned later 276 " incoming.class_id" 278 277 " FROM incoming" 279 278 " JOIN pzPendingExp" … … 367 366 } 368 367 369 // copy the summitExp row into newExp in order to create a new exp_id370 {371 psString exp_id = pxGenExpTag(config, filesetid);372 if (!exp_id) {373 // rollback374 if (!psDBRollback(config->dbh)) {375 psError(PS_ERR_UNKNOWN, false, "database error");376 }377 psError(PS_ERR_UNKNOWN, false, "database error");378 return false;379 }380 381 char *query =382 "INSERT INTO newExp"383 " SElECT"384 " '%s'," // exp_id385 " summitExp.exp_name,"386 " summitExp.camera,"387 " summitExp.telescope,"388 " summitExp.dateobs,"389 " summitExp.exp_type,"390 " summitExp.imfiles,"391 " 0" // error flags392 " FROM summitExp"393 " WHERE"394 " summitExp.exp_name = '%s'"395 " AND summitExp.camera = '%s'"396 " AND summitExp.telescope = '%s'";397 398 if (!p_psDBRunQuery(config->dbh, query, exp_id, filesetid, camera, telescope)) {399 // rollback400 if (!psDBRollback(config->dbh)) {401 psError(PS_ERR_UNKNOWN, false, "database error");402 }403 psError(PS_ERR_UNKNOWN, false, "database error");404 psFree(exp_id);405 return false;406 }407 psFree(exp_id);408 409 // sanity check: we should have inserted only one row410 psU64 affected = psDBAffectedRows(config->dbh);411 if (psDBAffectedRows(config->dbh) != 1) {412 // rollback413 if (!psDBRollback(config->dbh)) {414 psError(PS_ERR_UNKNOWN, false, "database error");415 }416 psError(PS_ERR_UNKNOWN, false, "should have affected 1 row but %" PRIu64 " rows were modified", affected);417 return false;418 }419 }420 421 // set the exp_id for the imfiles (files) in the exposure (fileset) that422 // we are investigating423 {424 char *query =425 "UPDATE pzPendingImfile"426 " SET exp_id = (SELECT exp_id from newExp"427 " WHERE exp_name = '%s'"428 " AND camera = '%s'"429 " AND telescope = '%s')"430 " WHERE"431 " exp_name = '%s'"432 " AND camera = '%s'"433 " AND telescope = '%s'";434 if (!p_psDBRunQuery(config->dbh, query, filesetid, camera, telescope, filesetid, camera, telescope)) {435 // rollback436 if (!psDBRollback(config->dbh)) {437 psError(PS_ERR_UNKNOWN, false, "database error");438 }439 psError(PS_ERR_UNKNOWN, false, "database error");440 return false;441 }442 }443 444 368 // cp the pzPendingExp entry to pzDoneExp 445 369 { -
trunk/ippTools/src/pzgetimfilesConfig.c
r11859 r14600 46 46 psMetadata *args = psMetadataAlloc(); 47 47 psMetadataAddStr(args , PS_LIST_TAIL, "-uri", 0, 48 "DataStore FileSet URI ", "");48 "DataStore FileSet URI (required)", NULL); 49 49 psMetadataAddStr(args , PS_LIST_TAIL, "-filesetid", 0, 50 "FileSet ID ", "");50 "FileSet ID (required)", NULL); 51 51 psMetadataAddStr(args, PS_LIST_TAIL, "-inst", 0, 52 " search by camera", NULL);52 "Camera ID (required)", NULL); 53 53 psMetadataAddStr(args, PS_LIST_TAIL, "-telescope", 0, 54 " search by telescope", NULL);54 "Telescope ID (required)", NULL); 55 55 56 56 … … 58 58 if (!psArgumentParse(args, &argc, argv) 59 59 || argc != 1 60 || strcmp(psMetadataLookupStr(&status, args, "-uri"), "") == 0 61 || strcmp(psMetadataLookupStr(&status, args, "-filesetid"), "") == 0 60 || (psMetadataLookupStr(&status, args, "-uri") == NULL) 61 || (psMetadataLookupStr(&status, args, "-filesetid") == NULL) 62 || (psMetadataLookupStr(&status, args, "-inst") == NULL) 63 || (psMetadataLookupStr(&status, args, "-telescope") == NULL) 62 64 ) { 63 65 fprintf(stderr, "error parsing arguments\n"); 64 printf("\nPan-STARRS Phase Z SearchTool\n");66 printf("\nPan-STARRS Phase Z Get Imfiles Tool\n"); 65 67 printf("Usage: %s -uri <uri> -filesetid <id>\n\n", argv[0]); 66 68 psArgumentHelp(args); -
trunk/ippTools/src/pztool.c
r14023 r14600 35 35 static bool copydoneMode(pxConfig *config); 36 36 37 static bool copydoneCompleteExp(pxConfig *config); 38 37 39 # define MODECASE(caseName, func) \ 38 40 case caseName: \ … … 196 198 psString query = psStringCopy( 197 199 "SELECT" 198 " summitImfile.*," 199 " pzPendingImfile.exp_id" 200 " summitImfile.*" 200 201 " FROM pzPendingImfile" 201 202 " JOIN summitImfile" … … 324 325 } 325 326 326 // insert new imfile into newImfile327 {328 char *query =329 "INSERT INTO newImfile"330 " SElECT"331 " pzPendingImfile.exp_id,"332 " pzPendingImfile.class,"333 " pzPendingImfile.class_id,"334 " '%s'," // uri of downloaded file335 " 0" // error flags336 " FROM pzPendingImfile"337 " WHERE"338 " pzPendingImfile.exp_name = '%s'"339 " AND pzPendingImfile.camera = '%s'"340 " AND pzPendingImfile.telescope = '%s'"341 " AND pzPendingImfile.class = '%s'"342 " AND pzPendingImfile.class_id = '%s'";343 344 if (!p_psDBRunQuery(config->dbh, query, uri, exp_name, camera, telescope, class, class_id)) {345 // rollback346 if (!psDBRollback(config->dbh)) {347 psError(PS_ERR_UNKNOWN, false, "database error");348 }349 psError(PS_ERR_UNKNOWN, false, "database error");350 return false;351 }352 353 // sanity check: we should have inserted only one row354 psU64 affected = psDBAffectedRows(config->dbh);355 if (psDBAffectedRows(config->dbh) != 1) {356 // rollback357 if (!psDBRollback(config->dbh)) {358 psError(PS_ERR_UNKNOWN, false, "database error");359 }360 psError(PS_ERR_UNKNOWN, false, "should have affected 1 row but %" PRIu64 " rows were modified", affected);361 return false;362 }363 }364 327 365 328 // cp the imfile into pzDoneImfile … … 441 404 } 442 405 406 if (!copydoneCompleteExp(config)) { 407 psError(PS_ERR_UNKNOWN, false, "copydoneCompleteExp() failed"); 408 return false; 409 } 410 443 411 return true; 444 412 } 413 414 static bool copydoneCompleteExp(pxConfig *config) 415 { 416 PS_ASSERT_PTR_NON_NULL(config, false); 417 418 // find all exposures that have had all of their imfiles downloaded but do 419 // not appear in newExp 420 psString query = pxDataGet("pztool_find_completed_exp.sql"); 421 if (!query) { 422 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 423 return false; 424 } 425 426 if (!p_psDBRunQuery(config->dbh, query)) { 427 psError(PS_ERR_UNKNOWN, false, "database error"); 428 psFree(query); 429 return false; 430 } 431 psFree(query); 432 433 psArray *output = p_psDBFetchResult(config->dbh); 434 if (!output) { 435 psError(PS_ERR_UNKNOWN, false, "database error"); 436 return false; 437 } 438 if (!psArrayLength(output)) { 439 psTrace("pztool", PS_LOG_INFO, "no rows found"); 440 psFree(output); 441 return true; 442 } 443 444 // start a transaction so all newExp's can start off with a state of run 445 if (!psDBTransaction(config->dbh)) { 446 psError(PS_ERR_UNKNOWN, false, "database error"); 447 psFree(output); 448 return false; 449 } 450 451 452 for (long i = 0; i < psArrayLength(output); i++) { 453 psMetadata *row = output->data[i]; 454 455 pzDoneExpRow *doneExp = pzDoneExpObjectFromMetadata(row); 456 457 if (!newExpInsert(config->dbh, 458 0x0, // exp_id 459 doneExp->exp_name, // tmp_exp_name 460 doneExp->camera, // tmp_camera 461 doneExp->telescope, // tmp_telescope 462 "run", // state 463 NULL, // workdir 464 "dirty", // workdir state 465 NULL // reduction class 466 ) 467 ) { 468 // rollback 469 if (!psDBRollback(config->dbh)) { 470 psError(PS_ERR_UNKNOWN, false, "database error"); 471 } 472 psError(PS_ERR_UNKNOWN, false, "database error"); 473 psFree(doneExp); 474 psFree(output); 475 return false; 476 } 477 478 psS64 exp_id = psDBLastInsertID(config->dbh); 479 480 // insert new pzDoneImfile into newImfile 481 { 482 char *query = 483 "INSERT INTO newImfile" 484 " SElECT" 485 " %" PRId64 "," // exp_id 486 " pzDoneImfile.class_id," // tmp_class_id 487 " pzDoneImfile.uri" // uri 488 " FROM pzDoneImfile" 489 " WHERE" 490 " pzDoneImfile.exp_name = '%s'" 491 " AND pzDoneImfile.camera = '%s'" 492 " AND pzDoneImfile.telescope = '%s'"; 493 494 if (!p_psDBRunQuery(config->dbh, query, exp_id, doneExp->exp_name, doneExp->camera, doneExp->telescope)) { 495 // rollback 496 if (!psDBRollback(config->dbh)) { 497 psError(PS_ERR_UNKNOWN, false, "database error"); 498 } 499 psError(PS_ERR_UNKNOWN, false, "database error"); 500 psFree(doneExp); 501 psFree(output); 502 return false; 503 } 504 505 // sanity check: we should have inserted only one row 506 psU64 affected = psDBAffectedRows(config->dbh); 507 if (psDBAffectedRows(config->dbh) != 1) { 508 // rollback 509 if (!psDBRollback(config->dbh)) { 510 psError(PS_ERR_UNKNOWN, false, "database error"); 511 } 512 psError(PS_ERR_UNKNOWN, false, "should have affected 1 row but %" PRIu64 " rows were modified", affected); 513 psFree(doneExp); 514 psFree(output); 515 return false; 516 } 517 } 518 519 psFree(doneExp); 520 } 521 522 psFree(output); 523 524 if (!psDBCommit(config->dbh)) { 525 psError(PS_ERR_UNKNOWN, false, "database error"); 526 return false; 527 } 528 529 return true; 530 } -
trunk/ippTools/src/pztoolConfig.c
r14023 r14600 45 45 // -seen 46 46 psMetadata *seenArgs = psMetadataAlloc(); 47 psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-exp_ id", 0,47 psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-exp_name", 0, 48 48 "define exposure ID", NULL); 49 49 psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-inst", 0, … … 58 58 // -pendingexp 59 59 psMetadata *pendingexpArgs = psMetadataAlloc(); 60 psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-exp_ id", 0,60 psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-exp_name", 0, 61 61 "define exposure ID", NULL); 62 62 psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-inst", 0, … … 71 71 // -pendingimfile 72 72 psMetadata *pendingimfileArgs = psMetadataAlloc(); 73 psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-exp_ id", 0,73 psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-exp_name", 0, 74 74 "define exposure ID", NULL); 75 75 psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-inst", 0, … … 117 117 118 118 psMetadata *argSets = psMetadataAlloc(); 119 // find which mode we're running under 120 PXTOOL_MODE("-seen", PZTOOL_MODE_SEEN, seenArgs); 121 PXTOOL_MODE("-pendingexp", PZTOOL_MODE_PENDINGEXP, pendingexpArgs); 122 PXTOOL_MODE("-pendingimfile", PZTOOL_MODE_PENDINGIMFILE,pendingimfileArgs); 123 PXTOOL_MODE("-copydone", PZTOOL_MODE_COPYDONE, copydoneArgs); 119 psMetadata *modes = psMetadataAlloc(); 124 120 125 bool argErr = false; 126 if (config->mode == PZTOOL_MODE_NONE) { 127 argErr = true; 128 fprintf (stderr, "mode argument is required\n"); 129 } else if (! psArgumentParse(config->args, &argc, argv) || argc != 1) { 130 argErr = true; 131 fprintf (stderr, "error parsing arguments\n"); 132 } 121 PXTOOL_ADD_MODE("-seen", "", PZTOOL_MODE_SEEN, seenArgs); 122 PXTOOL_ADD_MODE("-pendingexp", "", PZTOOL_MODE_PENDINGEXP, pendingexpArgs); 123 PXTOOL_ADD_MODE("-pendingimfile", "", PZTOOL_MODE_PENDINGIMFILE,pendingimfileArgs); 124 PXTOOL_ADD_MODE("-copydone", "", PZTOOL_MODE_COPYDONE, copydoneArgs); 133 125 134 if (argErr) { 135 printf("\nPan-STARRS Detrend Tool\n"); 136 printf("Usage: %s <mode> [<options>]\n\n", argv[0]); 137 printf(" <mode> :\n\n"); 138 139 psMetadataIterator *iter = psMetadataIteratorAlloc(argSets, 0, NULL); 140 psMetadataItem *item = NULL; 141 while ((item = psMetadataGetAndIncrement(iter))) { 142 if (!item->type == PS_DATA_METADATA) { 143 psAbort("all options must be specified as a metadata"); 144 } 145 146 fprintf(stdout, "%s ", item->name); 147 psArgumentHelp(item->data.md); 148 } 149 psFree(iter); 150 126 if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) { 127 psError(PS_ERR_UNKNOWN, true, "option parsing failed"); 151 128 psFree(argSets); 129 psFree(modes); 152 130 psFree(config); 153 131 return NULL; … … 155 133 156 134 psFree(argSets); 135 psFree(modes); 157 136 158 137 // setup search criterion … … 173 152 config->where = psMetadataAlloc(); 174 153 175 addWhereStr(exp_ id);154 addWhereStr(exp_name); 176 155 addWhereStr(telescope); 177 156 // convert '-inst' to 'camera' … … 206 185 } 207 186 208 // save argv/argc209 config->argv = argv;210 config->argc = argc;211 212 187 return config; 213 188 }
Note:
See TracChangeset
for help on using the changeset viewer.
