Changeset 17655
- Timestamp:
- May 13, 2008, 11:37:57 AM (18 years ago)
- Location:
- trunk/ippTools/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pztool.c
r17611 r17655 2 2 * pztool.c 3 3 * 4 * Copyright (C) 2006 Joshua Hoblitt4 * Copyright (C) 2006-2008 Joshua Hoblitt 5 5 * 6 6 * This program is free software; you can redistribute it and/or modify it … … 27 27 #include <inttypes.h> 28 28 29 #include "pslib.h" 29 30 #include "pxtools.h" 30 31 #include "pxdata.h" … … 41 42 static bool updatecopiedMode(pxConfig *config); 42 43 static bool revertcopiedMode(pxConfig *config); 44 static bool advanceMode(pxConfig *config); 43 45 44 46 static bool copydoneCompleteExp(pxConfig *config, const char *exp_name, const char *camera, const char *telescope); … … 75 77 MODECASE(PZTOOL_MODE_UPDATECOPIED, updatecopiedMode); 76 78 MODECASE(PZTOOL_MODE_REVERTCOPIED, revertcopiedMode); 79 MODECASE(PZTOOL_MODE_ADVANCE, advanceMode); 77 80 default: 78 81 psAbort("invalid option (this should not happen)"); … … 360 363 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 361 364 362 // need to know exp_name, camera, telescope, class, class_id (to find the 363 // pzDownloadImfile entry and the URI for the newImfile entry. 365 if (!pzDownloadImfileInsert(config->dbh, 366 exp_name, 367 camera, 368 telescope, 369 class, 370 class_id, 371 uri, 372 code 373 )) { 374 psError(PS_ERR_UNKNOWN, false, "database error"); 375 return false; 376 } 364 377 365 378 // start a transaction so it's all rows or nothing … … 367 380 psError(PS_ERR_UNKNOWN, false, "database error"); 368 381 return false; 369 }370 371 // cp the imfile into pzDownloadImfile372 {373 char *query =374 "INSERT INTO pzDownloadImfile"375 " SELECT"376 " exp_name,"377 " camera,"378 " telescope,"379 " class,"380 " class_id,"381 " '%s'," // uri of downloaded file382 " '%d'" // fault code383 " FROM summitImfile"384 " WHERE"385 " summitImfile.exp_name = '%s'"386 " AND summitImfile.camera = '%s'"387 " AND summitImfile.telescope = '%s'"388 " AND summitImfile.class = '%s'"389 " AND summitImfile.class_id = '%s'";390 391 if (!p_psDBRunQuery(config->dbh, query, uri, code, exp_name, camera, telescope, class, class_id)) {392 // rollback393 if (!psDBRollback(config->dbh)) {394 psError(PS_ERR_UNKNOWN, false, "database error");395 }396 psError(PS_ERR_UNKNOWN, false, "database error");397 return false;398 }399 400 // sanity check: we should have inserted only one row401 psU64 affected = psDBAffectedRows(config->dbh);402 if (psDBAffectedRows(config->dbh) != 1) {403 // rollback404 if (!psDBRollback(config->dbh)) {405 psError(PS_ERR_UNKNOWN, false, "database error");406 }407 psError(PS_ERR_UNKNOWN, false, "should have affected 1 row but %" PRIu64 " rows were modified", affected);408 return false;409 }410 382 } 411 383 … … 434 406 static bool copydoneCompleteExp(pxConfig *config, const char *exp_name, const char *camera, const char *telescope) 435 407 { 408 // THIS FUNCTION MUST BE INVOKED FROM INSIDE A TRANSACTION!!! 409 436 410 PS_ASSERT_PTR_NON_NULL(config, false); 437 411 … … 440 414 // these options are thrown away unless we just -copydone'd the last imfile 441 415 // in an exp. 442 // This function MUST NOT be invoked from anywhere but copydoneMode().443 416 444 417 // optional … … 457 430 } 458 431 459 psStringAppend(&query, "WHERE exp_name = '%s' AND telescope = '%s' AND camera = '%s'", 460 exp_name, telescope, camera); 432 psMetadata *where = psMetadataAlloc(); 433 if (exp_name) { 434 if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_name", 0, "==", exp_name)) { 435 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_name"); 436 psFree(where); 437 return false; 438 } 439 } 440 441 if (camera) { 442 if (!psMetadataAddStr(where, PS_LIST_TAIL, "camera", 0, "==", camera)) { 443 psError(PS_ERR_UNKNOWN, false, "failed to add item camera"); 444 psFree(where); 445 return false; 446 } 447 } 448 449 if (telescope) { 450 if (!psMetadataAddStr(where, PS_LIST_TAIL, "telescope", 0, "==", telescope)) { 451 psError(PS_ERR_UNKNOWN, false, "failed to add item telescope"); 452 psFree(where); 453 return false; 454 } 455 } 456 457 if (config->where) { 458 psString whereClause = psDBGenerateWhereSQL(where, NULL); 459 psStringAppend(&query, " %s", whereClause); 460 psFree(whereClause); 461 } 462 psFree(where); 461 463 462 464 if (!p_psDBRunQuery(config->dbh, query)) { … … 736 738 737 739 740 static bool advanceMode(pxConfig *config) 741 { 742 PS_ASSERT_PTR_NON_NULL(config, false); 743 744 // start a transaction so it's all rows or nothing 745 if (!psDBTransaction(config->dbh)) { 746 psError(PS_ERR_UNKNOWN, false, "database error"); 747 return false; 748 } 749 750 if (!copydoneCompleteExp(config, NULL, NULL, NULL)) { 751 // rollback 752 if (!psDBRollback(config->dbh)) { 753 psError(PS_ERR_UNKNOWN, false, "database error"); 754 } 755 psError(PS_ERR_UNKNOWN, false, "copydoneCompleteExp() failed"); 756 return false; 757 } 758 759 // point of no return 760 if (!psDBCommit(config->dbh)) { 761 // rollback 762 if (!psDBRollback(config->dbh)) { 763 psError(PS_ERR_UNKNOWN, false, "database error"); 764 } 765 psError(PS_ERR_UNKNOWN, false, "database error"); 766 return false; 767 } 768 769 770 return true; 771 } 772 773 738 774 static bool pzDownloadExpSetState(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, const char *state) 739 775 { -
trunk/ippTools/src/pztool.h
r16360 r17655 33 33 PZTOOL_MODE_COPIED, 34 34 PZTOOL_MODE_UPDATECOPIED, 35 PZTOOL_MODE_REVERTCOPIED 35 PZTOOL_MODE_REVERTCOPIED, 36 PZTOOL_MODE_ADVANCE 36 37 } pztoolMode; 37 38 -
trunk/ippTools/src/pztoolConfig.c
r16509 r17655 176 176 "search by fault code", 0); 177 177 178 // -advance 179 psMetadata *advanceArgs = psMetadataAlloc(); 180 psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-workdir", 0, 181 "define the \"default\" workdir for this exposure", NULL); 182 psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-dvodb", 0, 183 "define the dvodb for the next processing step", NULL); 184 psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-tess_id", 0, 185 "define the tess_id for the next processing step", NULL); 186 psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-end_stage", 0, 187 "define the end goal processing step", NULL); 188 psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-label", 0, 189 "define the label for the chip stage", NULL); 190 178 191 psMetadata *argSets = psMetadataAlloc(); 179 192 psMetadata *modes = psMetadataAlloc(); … … 188 201 PXOPT_ADD_MODE("-updatecopied", "", PZTOOL_MODE_UPDATECOPIED,updatecopiedArgs); 189 202 PXOPT_ADD_MODE("-revertcopied", "", PZTOOL_MODE_REVERTCOPIED,revertcopiedArgs); 203 PXOPT_ADD_MODE("-advance", "", PZTOOL_MODE_ADVANCE, advanceArgs); 190 204 191 205 if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
Note:
See TracChangeset
for help on using the changeset viewer.
