Changeset 14018
- Timestamp:
- Jul 5, 2007, 10:15:41 AM (19 years ago)
- Location:
- trunk/ippTools
- Files:
-
- 8 added
- 3 deleted
- 28 edited
-
scripts/camtest.sh (modified) (1 diff)
-
scripts/chiptest.sh (modified) (1 diff)
-
scripts/difftest.sh (modified) (1 diff)
-
scripts/regtest.sh (modified) (1 diff)
-
scripts/warptest.sh (modified) (1 diff)
-
share/camtool_find_chip_id.sql (added)
-
share/camtool_find_pendingexp.sql (modified) (2 diffs)
-
share/camtool_queue_chip_id.sql (modified) (1 diff)
-
share/chiptool_completely_processed_exp.sql (modified) (1 diff)
-
share/chiptool_find_unprocessed_imfile.pl (modified) (1 diff)
-
share/chiptool_pendingimfile.sql (modified) (1 diff)
-
share/chiptool_queuerawexp.sql (deleted)
-
share/chiptool_queuerawimfile.sql (modified) (1 diff)
-
share/regtool_find_unprocessed_exp.sql (modified) (1 diff)
-
share/regtool_find_unprocessed_imfile.sql (modified) (1 diff)
-
share/regtool_pendingexp.sql (modified) (1 diff)
-
src/Makefile.am (modified) (3 diffs)
-
src/camqueue.c (deleted)
-
src/camtool.c (modified) (8 diffs)
-
src/camtool.h (modified) (1 diff)
-
src/chipqueue.c (deleted)
-
src/chiptool.c (modified) (8 diffs)
-
src/chiptool.h (modified) (1 diff)
-
src/chiptoolConfig.c (modified) (1 diff)
-
src/pxcam.c (added)
-
src/pxcam.h (added)
-
src/pxchip.c (added)
-
src/pxchip.h (added)
-
src/pxconfig.h (added)
-
src/pxdata.h (modified) (1 diff)
-
src/pxinject.c (modified) (7 diffs)
-
src/pxinject.h (modified) (1 diff)
-
src/pxinjectConfig.c (modified) (2 diffs)
-
src/pxregister.c (added)
-
src/pxregister.h (added)
-
src/pxtables.c (modified) (2 diffs)
-
src/pxtag.h (modified) (1 diff)
-
src/pxtools.h (modified) (1 diff)
-
src/regtool.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/scripts/camtest.sh
r12188 r14018 8 8 camtool -pendingimfile || exit 1 9 9 10 camtool -addprocessedexp -cam_id 1 -uri file:///cam -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -sigma_ra 1 -sigma_dec 2 - nastro 42 -path_base file:///foo -zp_mean 1 -zp_stdev 2|| exit 111 camtool -addprocessedexp -cam_id 2 -uri file:///cam -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -sigma_ra 1 -sigma_dec 2 - nastro 42 -path_base file:///foo -zp_mean 1 -zp_stdev 2|| exit 110 camtool -addprocessedexp -cam_id 1 -uri file:///cam -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -sigma_ra 1 -sigma_dec 2 -zp_mean 10 -zp_stdev 2 -fwhm 42 -fwhm_range 100 -n_stars 2 -n_extended 0 -n_astrom 42 -n_cr 10000000 -path_base file:///foo || exit 1 11 camtool -addprocessedexp -cam_id 2 -uri file:///cam -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -sigma_ra 1 -sigma_dec 2 -zp_mean 10 -zp_stdev 2 -fwhm 42 -fwhm_range 100 -n_stars 2 -n_extended 0 -n_astrom 42 -n_cr 10000000 -path_base file:///foo || exit 1 -
trunk/ippTools/scripts/chiptest.sh
r12174 r14018 8 8 9 9 for ID in `seq 0 3`; do 10 chiptool -addprocessedimfile -chip_id 1 - class_id $ID -uri file://chipp-t10.$ID -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -path_base file:///foo || exit 110 chiptool -addprocessedimfile -chip_id 1 -exp_tag t10.1 -class_id $ID -uri file://chipp-t10.$ID -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -path_base file:///foo || exit 1 11 11 done; 12 12 13 13 for ID in `seq 0 3`; do 14 chiptool -addprocessedimfile -chip_id 2 - class_id $ID -uri file://chipp-t11.$ID -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -path_base file:///foo || exit 114 chiptool -addprocessedimfile -chip_id 2 -exp_tag t11.2 -class_id $ID -uri file://chipp-t11.$ID -bg 1 -bg_stdev 2 -bg_mean_stdev 3 -path_base file:///foo || exit 1 15 15 done; 16 16 -
trunk/ippTools/scripts/difftest.sh
r12533 r14018 12 12 difftool -todiffskyfile || exit 1 13 13 difftool -inputskyfile || exit 1 14 difftool -adddiffskyfile -diff_id 1 -uri file:///tmp/diff/skyfile - bg 1 -bg_stdev 2 || exit 114 difftool -adddiffskyfile -diff_id 1 -uri file:///tmp/diff/skyfile -path_base file://lalaland -bg 1 -bg_stdev 2 || exit 1 15 15 difftool -diffskyfile -diff_id 1 || exit 1 16 16 difftool -updaterun -state stop -diff_id 1 || exit 1 -
trunk/ippTools/scripts/regtest.sh
r12259 r14018 11 11 12 12 for ID in `seq 0 3`; do 13 $inject -newImfile -exp_tag $exp_tag1 -class OTA -class_id $ID -uri file://$ID || exit 113 $inject -newImfile -exp_tag $exp_tag1 -class_id $ID -uri file://$ID || exit 1 14 14 done; 15 16 $inject -updatenewExp -exp_tag $exp_tag1 -state run 15 17 16 18 exp_tag2=`$inject -newExp -exp_id t11 -inst gpc -telescope ps1 -imfiles 4 -workdir file::///some/path -simple` || exit 1 17 19 18 20 for ID in `seq 0 3`; do 19 $inject -newImfile -exp_tag $exp_tag2 -class OTA -class_id $ID -uri file://$ID || exit 121 $inject -newImfile -exp_tag $exp_tag2 -class_id $ID -uri file://$ID || exit 1 20 22 done; 23 24 $inject -updatenewExp -exp_tag $exp_tag2 -state run 21 25 22 26 $regtool -pendingimfile || exit 1 -
trunk/ippTools/scripts/warptest.sh
r12131 r14018 24 24 warptool -towarped || exit 1 25 25 26 warptool -addwarped -warp_id 1 -skycell_id foo1 -tess_id bar -uri file:///tmp/foo - bg 1 -bg_stdev 2 || exit 127 warptool -addwarped -warp_id 1 -skycell_id foo2 -tess_id bar -uri file:///tmp/foo - bg 1 -bg_stdev 2 || exit 126 warptool -addwarped -warp_id 1 -skycell_id foo1 -tess_id bar -uri file:///tmp/foo -path_base file://wonderland -bg 1 -bg_stdev 2 || exit 1 27 warptool -addwarped -warp_id 1 -skycell_id foo2 -tess_id bar -uri file:///tmp/foo -path_base file://wonderland -bg 1 -bg_stdev 2 || exit 1 28 28 29 29 warptool -warped -warp_id 1 || exit 1 -
trunk/ippTools/share/camtool_find_pendingexp.sql
r12259 r14018 3 3 -- "cleaner" to use the same query for both cases 4 4 SELECT 5 cam PendingExp.*,5 camRun.*, 6 6 rawExp.exp_tag, 7 7 rawExp.exp_id, … … 9 9 rawExp.telescope, 10 10 rawExp.filelevel 11 FROM camPendingExp 12 JOIN chipProcessedExp 11 FROM camRun 12 JOIN chipRun 13 USING(chip_id) 14 JOIN chipProcessedImfile 13 15 USING(chip_id) 14 16 JOIN rawExp 15 ON chipProcessed Exp.exp_tag = rawExp.exp_tag17 ON chipProcessedImfile.exp_tag = rawExp.exp_tag 16 18 LEFT JOIN camProcessedExp 17 ON cam PendingExp.cam_id = camProcessedExp.cam_id19 ON camRun.cam_id = camProcessedExp.cam_id 18 20 LEFT JOIN camMask 19 ON cam PendingExp.label = camMask.label21 ON camRun.label = camMask.label 20 22 WHERE 21 camProcessedExp.cam_id IS NULL 23 chipRun.state = 'stop' 24 AND camRun.state = 'run' 22 25 AND camMask.label IS NULL 26 AND camProcessedExp.cam_id IS NULL -
trunk/ippTools/share/camtool_queue_chip_id.sql
r12237 r14018 1 1 -- camtool only operates on exposures so we can safely queue more then one at a 2 2 -- time without worrying about losing the track of the generated cam_id 3 INSERT INTO cam PendingExp3 INSERT INTO camRun 4 4 SElECT 5 5 0, -- cam_id 6 6 chip_id, -- chip_id 7 '%s', -- state 7 8 '%s', -- workdir 9 '%s', -- workdir_state 8 10 '%s', -- label 9 '%s', -- re cipe11 '%s', -- reduction 10 12 '%s', -- expgroup 11 13 '%s' -- dvodb 12 FROM chip ProcessedExp14 FROM chipRun 13 15 WHERE 14 chipProcessedExp.chip_id = %lld 16 chipRun.state = 'stop' 17 AND chipRun.chip_id = %lld -
trunk/ippTools/share/chiptool_completely_processed_exp.sql
r13403 r14018 1 -- select * from chipPendingExp 2 -- where exp_tag is not in chipProcessedExp 3 -- where exp_tag is not in chipPendingImfile 4 -- where the number of entries in chipProccessedImfile matches the .imfiles 5 -- entry in rawExp 1 -- the output of this query must match the format of chipRun row 6 2 SELECT DISTINCT 7 chipPendingExp.*, 8 rawExp.imfiles, 9 chipProcessedImfile.class_id 10 FROM chipPendingExp 11 JOIN rawExp 12 ON chipPendingExp.exp_tag = rawExp.exp_tag 13 LEFT JOIN chipProcessedExp 14 ON chipPendingExp.chip_id = chipProcessedExp.chip_id 15 LEFT JOIN chipPendingImfile 16 ON chipPendingExp.chip_id = chipPendingImfile.chip_id 17 LEFT JOIN chipProcessedImfile 18 ON chipPendingExp.chip_id = chipProcessedImfile.chip_id 19 WHERE 20 chipProcessedExp.chip_id IS NULL 21 AND chipPendingImfile.chip_id IS NULL 22 AND chipProcessedImfile.chip_id IS NOT NULL 23 AND chipProcessedImfile.fault = 0 24 GROUP BY 25 chipPendingExp.chip_id 26 HAVING rawExp.imfiles = COUNT(chipProcessedImfile.class_id) 3 chip_id, 4 state, 5 workdir, 6 workdir_state, 7 label, 8 reduction, 9 expgroup, 10 dvodb 11 FROM 12 (SELECT 13 chipRun.*, 14 rawExp.imfiles, 15 chipProcessedImfile.class_id 16 FROM chipRun 17 JOIN chipInputImfile 18 USING(chip_id) 19 JOIN rawExp 20 ON chipInputImfile.exp_tag = rawExp.exp_tag 21 JOIN chipProcessedImfile 22 ON chipInputImfile.chip_id = chipProcessedImfile.chip_id 23 AND chipInputImfile.exp_tag = chipProcessedImfile.exp_tag 24 AND chipInputImfile.class_id = chipProcessedImfile.class_id 25 WHERE 26 chipRun.state = 'run' 27 AND chipProcessedImfile.fault = 0 28 GROUP BY 29 chipInputImfile.chip_id, 30 chipInputImfile.exp_tag 31 HAVING rawExp.imfiles = COUNT(chipProcessedImfile.class_id)) as Foo -
trunk/ippTools/share/chiptool_find_unprocessed_imfile.pl
r12174 r14018 1 1 SELECT DISTINCT 2 chip PendingImfile.*3 FROM chip PendingImfile2 chipInputImfile.* 3 FROM chipInputImfile 4 4 LEFT JOIN chipProcessedImfile 5 5 USING(chip_id, class_id) -
trunk/ippTools/share/chiptool_pendingimfile.sql
r12259 r14018 1 1 SELECT 2 chipPendingExp.*, 3 chipPendingImfile.class_id, 4 chipPendingImfile.uri, 2 chipRun.*, 3 chipInputImfile.exp_tag, 4 chipInputImfile.class_id, 5 rawImfile.uri, 5 6 rawExp.exp_id, 6 7 rawExp.camera, 7 8 rawExp.telescope, 8 9 rawExp.filelevel 9 FROM chip PendingImfile10 JOIN chip PendingExp10 FROM chipRun 11 JOIN chipInputImfile 11 12 USING(chip_id) 13 LEFT JOIN chipProcessedImfile 14 ON chipInputImfile.chip_id = chipProcessedImfile.chip_id 15 AND chipInputImfile.exp_tag = chipProcessedImfile.exp_tag 16 AND chipInputImfile.class_id = chipProcessedImfile.class_id 17 JOIN rawImfile 18 ON chipInputImfile.exp_tag = rawImfile.exp_tag 19 AND chipInputImfile.class_id = rawImfile.class_id 12 20 JOIN rawExp 13 ON chipPendingExp.exp_tag = rawExp.exp_tag21 ON rawImfile.exp_tag = rawExp.exp_tag 14 22 LEFT JOIN chipMask 15 ON chip PendingExp.label = chipMask.label23 ON chipRun.label = chipMask.label 16 24 WHERE 17 chipMask.label IS NULL 25 chipRun.state = 'run' 26 AND chipProcessedImfile.chip_id IS NULL 27 AND chipProcessedImfile.exp_tag IS NULL 28 AND chipProcessedImfile.class_id IS NULL 29 AND chipMask.label IS NULL -
trunk/ippTools/share/chiptool_queuerawimfile.sql
r12174 r14018 1 INSERT INTO chip PendingImfile1 INSERT INTO chipInputImfile 2 2 SELECT 3 chipPendingExp.chip_id,4 rawImfile. class_id,5 rawImfile. uri6 FROM chipPendingExp7 JOIN rawImfile3 LAST_INSERT_ID(), 4 rawImfile.exp_tag, 5 rawImfile.class_id 6 FROM rawImfile 7 JOIN newExp 8 8 USING(exp_tag) 9 9 WHERE 10 10 rawImfile.fault = 0 11 AND chipPendingExp.chip_id = LAST_INSERT_ID() 11 AND newExp.state = 'stop' 12 AND rawImfile.exp_tag = '%s' 13 -
trunk/ippTools/share/regtool_find_unprocessed_exp.sql
r12086 r14018 1 SELECT 2 newExp.* 3 FROM newExp 4 LEFT JOIN newImfile 5 USING(exp_tag) 6 LEFT JOIN rawExp 7 USING(exp_tag) 1 SELECT DISTINCT * FROM 2 (SELECT 3 newExp.* 4 FROM newExp 5 JOIN newImfile 6 USING(exp_tag) 7 LEFT JOIN rawExp 8 USING(exp_tag) 9 WHERE 10 newExp.state = 'run' 11 AND rawExp.exp_tag IS NULL 12 AND newExp.imfiles = 13 (SELECT COUNT(exp_tag) FROM rawImfile 14 WHERE rawImfile.exp_tag = newExp.exp_tag)) as Foo 8 15 WHERE 9 newExp.exp_tag IS NOT NULL 10 AND newImfile.exp_tag IS NULL 11 AND rawExp.exp_tag IS NULL 12 AND newExp.imfiles = 13 (SELECT COUNT(exp_tag) FROM rawImfile 14 WHERE rawImfile.exp_tag = newExp.exp_tag) 15 AND newExp.exp_tag = '%s' 16 exp_tag = '%s' -
trunk/ippTools/share/regtool_find_unprocessed_imfile.sql
r12086 r14018 1 SELECT 2 * 3 FROM 4 (SELECT newImfile.* FROM newImfile 5 LEFT JOIN newExp USING(exp_tag) 6 LEFT JOIN rawExp USING(exp_tag) 7 WHERE newExp.exp_tag IS NOT NULL 1 SELECT DISTINCT * FROM 2 (SELECT 3 newImfile.* 4 FROM newImfile 5 JOIN newExp 6 USING(exp_tag) 7 LEFT JOIN rawExp 8 USING(exp_tag) 9 WHERE 10 newExp.state = 'run' 8 11 AND rawExp.exp_tag IS NULL) as Foo -
trunk/ippTools/share/regtool_pendingexp.sql
r12086 r14018 2 2 newExp.* 3 3 FROM newExp 4 LEFTJOIN newImfile4 JOIN newImfile 5 5 USING(exp_tag) 6 6 LEFT JOIN rawExp 7 7 USING(exp_tag) 8 8 WHERE 9 new Imfile.exp_tag IS NULL9 newExp.state = 'run' 10 10 AND rawExp.exp_tag IS NULL 11 11 AND newExp.imfiles = -
trunk/ippTools/src/Makefile.am
r12190 r14018 15 15 pztool 16 16 17 include_HEADERS = \17 pkginclude_HEADERS = \ 18 18 pxtoolsErrorCodes.h \ 19 pxadmin.h \ 20 pxdata.h \ 21 pxio.h \ 22 pxtag.h \ 23 pxregister.h \ 24 pxchip.h \ 25 pxcam.h \ 26 pxconfig.h \ 19 27 pxtools.h 20 28 … … 29 37 difftool.h \ 30 38 stacktool.h \ 31 pxadmin.h \32 39 pxinject.h \ 33 pxdata.h \34 pxio.h \35 pxtag.h \36 40 pzgetexp.h \ 37 41 pzgetimfiles.h \ … … 51 55 pxio.c \ 52 56 pxtag.c \ 53 chipqueue.c \ 54 camqueue.c 57 pxregister.c \ 58 pxchip.c \ 59 pxcam.c 55 60 56 61 # for pxtools.h -
trunk/ippTools/src/camtool.c
r13937 r14018 203 203 204 204 // find the chipProcessedExp exposures that we want to queue up. 205 psString query = psStringCopy("SELECT * FROM chipProcessedExp"); 205 // psString query = psStringCopy("SELECT * FROM chipRun WHERE chipRun.state = 'stop'"); 206 psString query = pxDataGet("camtool_find_chip_id.sql"); 207 if (!query) { 208 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 209 return false; 210 } 206 211 207 212 if (where) { 208 psString whereClause = psDBGenerateWhereSQL(where, " chipProcessedExp");213 psString whereClause = psDBGenerateWhereSQL(where, ""); 209 214 psFree(where); 210 215 psStringAppend(&query, " %s", whereClause); … … 245 250 psMetadata *md = output->data[i]; 246 251 247 chip ProcessedExpRow *row = chipProcessedExpObjectFromMetadata(md);252 chipRunRow *row = chipRunObjectFromMetadata(md); 248 253 if (!row) { 249 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chip ProcessedExp");254 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipRun"); 250 255 psFree(output); 251 256 return false; … … 253 258 254 259 // queue the exp 255 if (! camQueueChipID(config,260 if (!pxcamQueueByChipID(config, 256 261 row->chip_id, 257 262 workdir ? workdir : row->workdir, … … 601 606 } 602 607 603 // start a transaction so we don't end up with an exp_tag is both604 // camPendingExp & camProcessedExp605 608 if (!psDBTransaction(config->dbh)) { 606 609 psError(PS_ERR_UNKNOWN, false, "database error"); … … 609 612 } 610 613 611 cam PendingExpRow *pendingRow = camPendingExpObjectFromMetadata(output->data[0]);614 camRunRow *pendingRow = camRunObjectFromMetadata(output->data[0]); 612 615 psFree(output); 613 616 // create a new camProcessedImfile object … … 615 618 pendingRow->cam_id, 616 619 pendingRow->chip_id, 617 pendingRow->workdir,618 pendingRow->label,619 pendingRow->reduction,620 pendingRow->expgroup,621 pendingRow->dvodb,622 620 uri, 623 621 bg, … … 637 635 code 638 636 ); 637 psFree(pendingRow); 639 638 640 639 // insert the new row into the camProcessedImfile table … … 646 645 psError(PS_ERR_UNKNOWN, false, "database error"); 647 646 psFree(row); 648 psFree(pendingRow); 649 return false; 650 } 647 return false; 648 } 649 650 // since there is only one exp per 'run' set camRun.state = 'stop' 651 if (!pxcamRunSetState(config, row->cam_id, "stop")) { 652 psError(PS_ERR_UNKNOWN, false, "failed to change camRun.state for cam_id: %" PRId64, row->cam_id); 653 psFree(row); 654 return false; 655 } 656 651 657 psFree(row); 652 658 653 // delete the camPendingExp row from the database654 if (!camPendingExpDeleteObject(config->dbh, pendingRow)) {655 // rollback656 if (!psDBRollback(config->dbh)) {657 psError(PS_ERR_UNKNOWN, false, "database error");658 }659 psError(PS_ERR_UNKNOWN, false, "database error");660 psFree(pendingRow);661 return false;662 }663 664 psFree(pendingRow);665 666 // point of no return for camPendingExp -> camProcessedExp667 659 if (!psDBCommit(config->dbh)) { 668 660 psError(PS_ERR_UNKNOWN, false, "database error"); -
trunk/ippTools/src/camtool.h
r12237 r14018 38 38 pxConfig *camtoolConfig(pxConfig *config, int argc, char **argv); 39 39 40 bool camQueueChipID(pxConfig *config,41 psS64 chip_id,42 psString workdir,43 psString label,44 psString recipe,45 psString expgroup,46 psString dvodb);47 48 40 #endif // CAMTOOL_H -
trunk/ippTools/src/chiptool.c
r13937 r14018 30 30 #include "pxtools.h" 31 31 #include "pxdata.h" 32 32 33 #include "chiptool.h" 33 34 #include "camtool.h" … … 42 43 static bool unblockMode(pxConfig *config); 43 44 44 static chipProcessedImfileRow *chipPendingToProcessedImfile(pxConfig *config, chipPendingImfileRow *imfile);45 static chipProcessedExpRow *chipPendingToProcessedExp(pxConfig *config, chipPendingExpRow *pendingExp);46 45 static bool chipProcessedCompleteExp(pxConfig *config); 47 46 … … 243 242 244 243 // queue the exp 245 if (! chipQueueExpTag(config, exp_tag, workdir, label, reduction, expgroup, dvodb)) {244 if (!pxchipQueueByExpTag(config, exp_tag, workdir, label, reduction, expgroup, dvodb)) { 246 245 if (!psDBRollback(config->dbh)) { 247 246 psError(PS_ERR_UNKNOWN, false, "database error"); … … 283 282 284 283 if (config->where) { 285 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "chip PendingImfile");284 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "chipInputImfile"); 286 285 psStringAppend(&query, " AND %s", whereClause); 287 286 psFree(whereClause); … … 330 329 331 330 // negative simple so the default is true 332 if (!ippdbPrintMetadatas(stdout, output, "chip PendingImfile", !simple)) {331 if (!ippdbPrintMetadatas(stdout, output, "chipInputImfile", !simple)) { 333 332 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 334 333 psFree(output); … … 346 345 PS_ASSERT_PTR_NON_NULL(config, false); 347 346 348 // select * from chipProcessedImfiles349 // where350 // exp_tag & class_id are not in chipPendingImfile351 352 // add the completed imfile to353 // the chipProcessedeImfile tables354 // remove corresponding entries from the355 // chipPendingImfile table356 // check to see if any chipPendingExps have no357 // associated chipPendingImfiles358 // if so move the chipPendingExp(s) to chipProcessedExp359 360 psString query = pxDataGet("chiptool_find_unprocessed_imfile.pl");361 if (!query) {362 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");363 return false;364 }365 366 {367 psMetadata *where = psMetadataAlloc();368 bool status = false;369 psString chip_id = psMetadataLookupStr(&status, config->args, "-chip_id"); if (!status) {370 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -chip_id");371 psFree(query);372 return false;373 }374 if (chip_id) {375 if (!psMetadataAddStr(where, PS_LIST_TAIL, "chip_id", 0, "==", chip_id)) {376 psError(PS_ERR_UNKNOWN, false, "failed to add item chip_id");377 psFree(where);378 psFree(query);379 return false;380 }381 }382 383 psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");384 if (!status) {385 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");386 psFree(query);387 return false;388 }389 if (class_id) {390 if (!psMetadataAddStr(where, PS_LIST_TAIL, "class_id", 0, "==", class_id)) {391 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");392 psFree(where);393 psFree(query);394 return false;395 }396 }397 398 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "chipPendingImfile");399 psFree(where);400 if (whereClause) {401 psStringAppend(&query, " AND %s", whereClause);402 psFree(whereClause);403 }404 }405 406 if (!p_psDBRunQuery(config->dbh, query)) {407 psError(PS_ERR_UNKNOWN, false, "database error");408 psFree(query);409 return false;410 }411 psFree(query);412 413 psArray *output = p_psDBFetchResult(config->dbh);414 if (!output) {415 psError(PS_ERR_UNKNOWN, false, "database error");416 return false;417 }418 if (!psArrayLength(output)) {419 // XXX check psError here420 psError(PS_ERR_UNKNOWN, false, "no chipPendingImfile rows found");421 psFree(output);422 return false;423 }424 425 // start a transaction so we don't end up with an incremented iteration426 // count but no detInputExps427 if (!psDBTransaction(config->dbh)) {428 psError(PS_ERR_UNKNOWN, false, "database error");429 psFree(output);430 return false;431 }432 433 // insert into chipProcessedImfile434 // remove chipPendingImfile entry435 for (long i = 0; i < psArrayLength(output); i++) {436 psMetadata *row = output->data[i];437 // convert metadata into a chipPendingImfile object438 chipPendingImfileRow *object = chipPendingImfileObjectFromMetadata(row);439 // convert chipPendingImfile object into a chipProcessedImfile object440 chipProcessedImfileRow *imfile = chipPendingToProcessedImfile(config, object);441 if (!imfile) {442 // rollback443 if (!psDBRollback(config->dbh)) {444 psError(PS_ERR_UNKNOWN, false, "database error");445 }446 psError(PS_ERR_UNKNOWN, false, "failed to convert chipPendingImfile to chipProcessedImfile");447 psFree(object);448 psFree(output);449 return false;450 }451 // insert chipProccessedImfile object into the database452 if (!chipProcessedImfileInsertObject(config->dbh, imfile)) {453 // rollback454 if (!psDBRollback(config->dbh)) {455 psError(PS_ERR_UNKNOWN, false, "database error");456 }457 psError(PS_ERR_UNKNOWN, false, "database error");458 psFree(imfile);459 psFree(object);460 psFree(output);461 return false;462 }463 psFree(imfile);464 // delete the chipPendingImfile object from the database465 if (!chipPendingImfileDeleteObject(config->dbh, object)) {466 // there must be atleast 1 Imfile to get this far467 // rollback468 if (!psDBRollback(config->dbh)) {469 psError(PS_ERR_UNKNOWN, false, "database error");470 }471 psError(PS_ERR_UNKNOWN, false, "database error");472 psFree(object);473 psFree(output);474 return false;475 }476 psFree(object);477 }478 479 psFree(output);480 481 // XXX I've decided to make the transaction cover the Exp migration as482 // well. Otherwise, if the last imfile in an exp is moved and the exp483 // migration fails then the data base is left in a satuation where the exp484 // migration can't happen.485 486 if (!chipProcessedCompleteExp(config)) {487 // rollback488 if (!psDBRollback(config->dbh)) {489 psError(PS_ERR_UNKNOWN, false, "database error");490 }491 psError(PS_ERR_UNKNOWN, false, "database error");492 return false;493 }494 495 // point of no return for chipPendingImfile -> chipProcessedImfile496 // point of no return for chipPendingExp -> chipProcessedExp497 if (!psDBCommit(config->dbh)) {498 psError(PS_ERR_UNKNOWN, false, "database error");499 return false;500 }501 502 return true;503 }504 505 506 static bool processedimfileMode(pxConfig *config)507 {508 PS_ASSERT_PTR_NON_NULL(config, NULL);509 510 347 bool status = false; 511 psU64 limit = psMetadataLookupU64(&status, config->args, "-limit"); 512 if (!status) { 513 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit"); 514 return false; 515 } 516 517 bool faulted = psMetadataLookupU64(&status, config->args, "-faulted"); 518 if (!status) { 519 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -faulted"); 520 return false; 521 } 522 523 // XXX does this need to be constrained so that it won't return any results 524 // if a match chipPendingExp hasn't been registered? 525 psString query = pxDataGet("chiptool_processedimfile.sql"); 526 if (!query) { 527 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 528 return false; 529 } 530 531 if (config->where) { 532 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "chipProcessedImfile"); 533 psStringAppend(&query, " AND %s", whereClause); 534 psFree(whereClause); 535 } 536 537 if (faulted) { 538 // list only faulted rows 539 psStringAppend(&query, " %s", "AND chipProcessedImfile.fault != 0"); 540 } else { 541 // don't list faulted rows 542 psStringAppend(&query, " %s", "AND chipProcessedImfile.fault = 0"); 543 } 544 545 // treat limit == 0 as "no limit" 546 if (limit) { 547 psString limitString = psDBGenerateLimitSQL(limit); 548 psStringAppend(&query, " %s", limitString); 549 psFree(limitString); 550 } 551 552 if (!p_psDBRunQuery(config->dbh, query)) { 553 psError(PS_ERR_UNKNOWN, false, "database error"); 554 psFree(query); 555 return false; 556 } 557 psFree(query); 558 559 psArray *output = p_psDBFetchResult(config->dbh); 560 if (!output) { 561 psError(PS_ERR_UNKNOWN, false, "database error"); 562 return false; 563 } 564 if (!psArrayLength(output)) { 565 psTrace("chiptool", PS_LOG_INFO, "no rows found"); 566 psFree(output); 567 return true; 568 } 569 570 bool simple = false; 571 { 572 bool status = false; 573 simple = psMetadataLookupBool(&status, config->args, "-simple"); 574 if (!status) { 575 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 576 return false; 577 } 578 } 579 580 if (!convertIdToStr(output)) { 581 psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings"); 582 psFree(output); 583 return false; 584 } 585 586 // negative simple so the default is true 587 if (!ippdbPrintMetadatas(stdout, output, "chipProcessedImfile", !simple)) { 588 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 589 psFree(output); 590 return false; 591 } 592 593 psFree(output); 594 595 return true; 596 } 597 598 599 static bool updateprocessedimfileMode(pxConfig *config) 600 { 601 PS_ASSERT_PTR_NON_NULL(config, false); 602 603 bool status = false; 604 psS16 code = psMetadataLookupS16(&status, config->args, "-code"); 605 if (!status) { 606 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -code"); 607 return false; 608 } 609 if (code == INT16_MAX) { 610 psError(PS_ERR_UNKNOWN, true, "-code is required"); 611 return false; 612 } 613 614 if (!pxSetFaultCode(config->dbh, "chipProcessedImfile", config->where, code)) { 615 psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag"); 616 return false; 617 } 618 619 return true; 620 } 621 622 623 static bool blockMode(pxConfig *config) 624 { 625 PS_ASSERT_PTR_NON_NULL(config, false); 626 627 bool status = false; 628 psString label = psMetadataLookupStr(&status, config->args, "-label"); 629 if (!status) { 630 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -label"); 631 return false; 632 } 633 if (!label) { 634 psError(PS_ERR_UNKNOWN, true, "-label is required"); 635 return false; 636 } 637 638 if (!chipMaskInsert(config->dbh, label)) { 639 psError(PS_ERR_UNKNOWN, false, "database error"); 640 return false; 641 } 642 643 return true; 644 } 645 646 647 static bool maskedMode(pxConfig *config) 648 { 649 PS_ASSERT_PTR_NON_NULL(config, false); 650 651 psString query = psStringCopy("SELECT * FROM chipMask"); 652 653 if (!p_psDBRunQuery(config->dbh, query)) { 654 psError(PS_ERR_UNKNOWN, false, "database error"); 655 psFree(query); 656 return false; 657 } 658 psFree(query); 659 660 psArray *output = p_psDBFetchResult(config->dbh); 661 if (!output) { 662 psError(PS_ERR_UNKNOWN, false, "database error"); 663 return false; 664 } 665 if (!psArrayLength(output)) { 666 psTrace("chiptool", PS_LOG_INFO, "no rows found"); 667 psFree(output); 668 return true; 669 } 670 671 bool simple = false; 672 { 673 bool status = false; 674 simple = psMetadataLookupBool(&status, config->args, "-simple"); 675 if (!status) { 676 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 677 return false; 678 } 679 } 680 681 if (!convertIdToStr(output)) { 682 psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings"); 683 psFree(output); 684 return false; 685 } 686 687 // negative simple so the default is true 688 if (!ippdbPrintMetadatas(stdout, output, "chipMask", !simple)) { 689 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 690 psFree(output); 691 return false; 692 } 693 694 psFree(output); 695 696 return true; 697 } 698 699 700 static bool unblockMode(pxConfig *config) 701 { 702 PS_ASSERT_PTR_NON_NULL(config, false); 703 704 bool status = false; 705 psString label = psMetadataLookupStr(&status, config->args, "-label"); 706 if (!status) { 707 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -label"); 708 return false; 709 } 710 if (!label) { 711 psError(PS_ERR_UNKNOWN, true, "-label is required"); 712 return false; 713 } 714 715 char *query = "DELETE FROM chipMask WHERE label = '%s'"; 716 717 if (!p_psDBRunQuery(config->dbh, query, label)) { 718 psError(PS_ERR_UNKNOWN, false, "database error"); 719 psFree(query); 720 return false; 721 } 722 723 return true; 724 } 725 726 727 static bool chipProcessedCompleteExp(pxConfig *config) 728 { 729 PS_ASSERT_PTR_NON_NULL(config, false); 730 731 // look for completed chipPendingExp 732 // migrate them to chipProccessedExp & camPendingExp 733 psString query = pxDataGet("chiptool_completely_processed_exp.sql"); 734 if (!query) { 735 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 736 return false; 737 } 738 739 if (!p_psDBRunQuery(config->dbh, query)) { 740 psError(PS_ERR_UNKNOWN, false, "database error"); 741 psFree(query); 742 return false; 743 } 744 psFree(query); 745 746 psArray *output = p_psDBFetchResult(config->dbh); 747 if (!output) { 748 psError(PS_ERR_UNKNOWN, false, "database error"); 749 return false; 750 } 751 if (!psArrayLength(output)) { 752 psTrace("chiptool", PS_LOG_INFO, "no rows found"); 753 psFree(output); 754 return true; 755 } 756 757 // insert into chipProcessedExp 758 // insert into camPendingExp 759 // remove chipPendingExp entry 760 for (long i = 0; i < psArrayLength(output); i++) { 761 psMetadata *row = output->data[i]; 762 763 // convert metadata into a chipPendingExp object 764 chipPendingExpRow *pendingExp = chipPendingExpObjectFromMetadata(row); 765 if (!pendingExp) { 766 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipPendingExp"); 767 psFree(output); 768 return false; 769 } 770 771 // convert chipPendingExp object into a chipProcesseExp object 772 chipProcessedExpRow *processedExp = chipPendingToProcessedExp(config, pendingExp); 773 if (!processedExp) { 774 psError(PS_ERR_UNKNOWN, false, "failed to convert chipPendingExp to chipProcessedExp"); 775 psFree(pendingExp); 776 psFree(output); 777 return false; 778 } 779 780 // delete the chipPendingExp object from the database 781 if (!chipPendingExpDeleteObject(config->dbh, pendingExp)) { 782 // there must be atleast 1 Imfile to get this far 783 psError(PS_ERR_UNKNOWN, false, "database error"); 784 psFree(processedExp); 785 psFree(pendingExp); 786 psFree(output); 787 return false; 788 } 789 psFree(pendingExp); 790 791 // insert chipProccessedExp object into the database 792 if (!chipProcessedExpInsertObject(config->dbh, processedExp)) { 793 psError(PS_ERR_UNKNOWN, false, "database error"); 794 psFree(processedExp); 795 psFree(output); 796 return false; 797 } 798 799 // camQueueChipID() can only be run after the chipProcessedExp entry 800 // has been inserted. 801 // queue the chip_id in the camPendingExp table 802 if (!camQueueChipID(config, 803 processedExp->chip_id, 804 processedExp->workdir, 805 processedExp->label, 806 processedExp->reduction, 807 processedExp->expgroup, 808 processedExp->dvodb 809 )) { 810 // rollback 811 if (!psDBRollback(config->dbh)) { 812 psError(PS_ERR_UNKNOWN, false, "database error"); 813 } 814 psError(PS_ERR_UNKNOWN, false, "failed to queue camPendingExp"); 815 psFree(processedExp); 816 psFree(output); 817 return false; 818 } 819 820 psFree(processedExp); 821 } 822 823 psFree(output); 824 825 return true; 826 } 827 828 829 static chipProcessedImfileRow *chipPendingToProcessedImfile(pxConfig *config, chipPendingImfileRow *imfile) 830 { 831 PS_ASSERT_PTR_NON_NULL(config, NULL); 832 PS_ASSERT_PTR_NON_NULL(imfile, NULL); 833 834 bool status = false; 348 // chip_id, ext_tag, class_id are required 349 psString chip_id = psMetadataLookupStr(&status, config->args, "-chip_id"); 350 if (!status) { 351 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -chip_id"); 352 return false; 353 } 354 if (!chip_id) { 355 psError(PS_ERR_UNKNOWN, true, "-chip_id is required"); 356 return false; 357 } 358 359 psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag"); 360 if (!status) { 361 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag"); 362 return false; 363 } 364 if (!exp_tag) { 365 psError(PS_ERR_UNKNOWN, true, "-exp_tag is required"); 366 return false; 367 } 368 369 psString class_id = psMetadataLookupStr(&status, config->args, "-class_id"); 370 if (!status) { 371 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id"); 372 return false; 373 } 374 if (!class_id) { 375 psError(PS_ERR_UNKNOWN, true, "-class_id is required"); 376 return false; 377 } 378 835 379 psString uri = psMetadataLookupStr(&status, config->args, "-uri"); 836 380 if (!status) { … … 961 505 } 962 506 963 return chipProcessedImfileRowAlloc( 964 imfile->chip_id, 965 imfile->class_id, 507 if (!psDBTransaction(config->dbh)) { 508 psError(PS_ERR_UNKNOWN, false, "database error"); 509 return false; 510 } 511 512 chipProcessedImfileRow *imfile = chipProcessedImfileRowAlloc( 513 (psU64)atoll(chip_id), 514 exp_tag, 515 class_id, 966 516 uri, 967 517 bg, … … 985 535 path_base, 986 536 code 987 ); 988 } 989 990 991 static chipProcessedExpRow *chipPendingToProcessedExp(pxConfig *config, chipPendingExpRow *pendingExp) 537 ); 538 if (!imfile) { 539 // rollback 540 if (!psDBRollback(config->dbh)) { 541 psError(PS_ERR_UNKNOWN, false, "database error"); 542 } 543 psError(PS_ERR_UNKNOWN, false, "failed to alloc chipProcessedImfileRow object"); 544 return false; 545 } 546 if (!chipProcessedImfileInsertObject(config->dbh, imfile)) { 547 // rollback 548 if (!psDBRollback(config->dbh)) { 549 psError(PS_ERR_UNKNOWN, false, "database error"); 550 } 551 psError(PS_ERR_UNKNOWN, false, "database error"); 552 psFree(imfile); 553 return false; 554 } 555 556 557 558 // XXX I've decided to make the transaction cover the Exp migration as 559 // well. Otherwise, if the last imfile in an exp is moved and the exp 560 // migration fails then the data base is left in a satuation where the exp 561 // migration can't happen. 562 563 if (!chipProcessedCompleteExp(config)) { 564 // rollback 565 if (!psDBRollback(config->dbh)) { 566 psError(PS_ERR_UNKNOWN, false, "database error"); 567 } 568 psError(PS_ERR_UNKNOWN, false, "database error"); 569 return false; 570 } 571 572 if (!psDBCommit(config->dbh)) { 573 psError(PS_ERR_UNKNOWN, false, "database error"); 574 return false; 575 } 576 577 return true; 578 } 579 580 581 static bool processedimfileMode(pxConfig *config) 992 582 { 993 PS_ASSERT_PTR_NON_NULL(pendingExp, NULL); 994 995 return chipProcessedExpRowAlloc( 996 pendingExp->chip_id, 997 pendingExp->exp_tag, 998 pendingExp->guide_id, 999 pendingExp->workdir, 1000 pendingExp->label, 1001 pendingExp->reduction, 1002 pendingExp->expgroup, 1003 pendingExp->dvodb 1004 ); 1005 } 583 PS_ASSERT_PTR_NON_NULL(config, NULL); 584 585 bool status = false; 586 psU64 limit = psMetadataLookupU64(&status, config->args, "-limit"); 587 if (!status) { 588 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit"); 589 return false; 590 } 591 592 bool faulted = psMetadataLookupU64(&status, config->args, "-faulted"); 593 if (!status) { 594 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -faulted"); 595 return false; 596 } 597 598 // XXX does this need to be constrained so that it won't return any results 599 // if a match chipPendingExp hasn't been registered? 600 psString query = pxDataGet("chiptool_processedimfile.sql"); 601 if (!query) { 602 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 603 return false; 604 } 605 606 if (config->where) { 607 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "chipProcessedImfile"); 608 psStringAppend(&query, " AND %s", whereClause); 609 psFree(whereClause); 610 } 611 612 if (faulted) { 613 // list only faulted rows 614 psStringAppend(&query, " %s", "AND chipProcessedImfile.fault != 0"); 615 } else { 616 // don't list faulted rows 617 psStringAppend(&query, " %s", "AND chipProcessedImfile.fault = 0"); 618 } 619 620 // treat limit == 0 as "no limit" 621 if (limit) { 622 psString limitString = psDBGenerateLimitSQL(limit); 623 psStringAppend(&query, " %s", limitString); 624 psFree(limitString); 625 } 626 627 if (!p_psDBRunQuery(config->dbh, query)) { 628 psError(PS_ERR_UNKNOWN, false, "database error"); 629 psFree(query); 630 return false; 631 } 632 psFree(query); 633 634 psArray *output = p_psDBFetchResult(config->dbh); 635 if (!output) { 636 psError(PS_ERR_UNKNOWN, false, "database error"); 637 return false; 638 } 639 if (!psArrayLength(output)) { 640 psTrace("chiptool", PS_LOG_INFO, "no rows found"); 641 psFree(output); 642 return true; 643 } 644 645 bool simple = false; 646 { 647 bool status = false; 648 simple = psMetadataLookupBool(&status, config->args, "-simple"); 649 if (!status) { 650 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 651 return false; 652 } 653 } 654 655 if (!convertIdToStr(output)) { 656 psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings"); 657 psFree(output); 658 return false; 659 } 660 661 // negative simple so the default is true 662 if (!ippdbPrintMetadatas(stdout, output, "chipProcessedImfile", !simple)) { 663 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 664 psFree(output); 665 return false; 666 } 667 668 psFree(output); 669 670 return true; 671 } 672 673 674 static bool updateprocessedimfileMode(pxConfig *config) 675 { 676 PS_ASSERT_PTR_NON_NULL(config, false); 677 678 bool status = false; 679 psS16 code = psMetadataLookupS16(&status, config->args, "-code"); 680 if (!status) { 681 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -code"); 682 return false; 683 } 684 if (code == INT16_MAX) { 685 psError(PS_ERR_UNKNOWN, true, "-code is required"); 686 return false; 687 } 688 689 if (!pxSetFaultCode(config->dbh, "chipProcessedImfile", config->where, code)) { 690 psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag"); 691 return false; 692 } 693 694 return true; 695 } 696 697 698 static bool blockMode(pxConfig *config) 699 { 700 PS_ASSERT_PTR_NON_NULL(config, false); 701 702 bool status = false; 703 psString label = psMetadataLookupStr(&status, config->args, "-label"); 704 if (!status) { 705 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -label"); 706 return false; 707 } 708 if (!label) { 709 psError(PS_ERR_UNKNOWN, true, "-label is required"); 710 return false; 711 } 712 713 if (!chipMaskInsert(config->dbh, label)) { 714 psError(PS_ERR_UNKNOWN, false, "database error"); 715 return false; 716 } 717 718 return true; 719 } 720 721 722 static bool maskedMode(pxConfig *config) 723 { 724 PS_ASSERT_PTR_NON_NULL(config, false); 725 726 psString query = psStringCopy("SELECT * FROM chipMask"); 727 728 if (!p_psDBRunQuery(config->dbh, query)) { 729 psError(PS_ERR_UNKNOWN, false, "database error"); 730 psFree(query); 731 return false; 732 } 733 psFree(query); 734 735 psArray *output = p_psDBFetchResult(config->dbh); 736 if (!output) { 737 psError(PS_ERR_UNKNOWN, false, "database error"); 738 return false; 739 } 740 if (!psArrayLength(output)) { 741 psTrace("chiptool", PS_LOG_INFO, "no rows found"); 742 psFree(output); 743 return true; 744 } 745 746 bool simple = false; 747 { 748 bool status = false; 749 simple = psMetadataLookupBool(&status, config->args, "-simple"); 750 if (!status) { 751 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 752 return false; 753 } 754 } 755 756 if (!convertIdToStr(output)) { 757 psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings"); 758 psFree(output); 759 return false; 760 } 761 762 // negative simple so the default is true 763 if (!ippdbPrintMetadatas(stdout, output, "chipMask", !simple)) { 764 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 765 psFree(output); 766 return false; 767 } 768 769 psFree(output); 770 771 return true; 772 } 773 774 775 static bool unblockMode(pxConfig *config) 776 { 777 PS_ASSERT_PTR_NON_NULL(config, false); 778 779 bool status = false; 780 psString label = psMetadataLookupStr(&status, config->args, "-label"); 781 if (!status) { 782 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -label"); 783 return false; 784 } 785 if (!label) { 786 psError(PS_ERR_UNKNOWN, true, "-label is required"); 787 return false; 788 } 789 790 char *query = "DELETE FROM chipMask WHERE label = '%s'"; 791 792 if (!p_psDBRunQuery(config->dbh, query, label)) { 793 psError(PS_ERR_UNKNOWN, false, "database error"); 794 psFree(query); 795 return false; 796 } 797 798 return true; 799 } 800 801 802 static bool chipProcessedCompleteExp(pxConfig *config) 803 { 804 PS_ASSERT_PTR_NON_NULL(config, false); 805 806 // look for completed chipPendingExp 807 // migrate them to chipProccessedExp & camPendingExp 808 psString query = pxDataGet("chiptool_completely_processed_exp.sql"); 809 if (!query) { 810 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 811 return false; 812 } 813 814 if (!p_psDBRunQuery(config->dbh, query)) { 815 psError(PS_ERR_UNKNOWN, false, "database error"); 816 psFree(query); 817 return false; 818 } 819 psFree(query); 820 821 psArray *output = p_psDBFetchResult(config->dbh); 822 if (!output) { 823 psError(PS_ERR_UNKNOWN, false, "database error"); 824 return false; 825 } 826 if (!psArrayLength(output)) { 827 psTrace("chiptool", PS_LOG_INFO, "no rows found"); 828 psFree(output); 829 return true; 830 } 831 832 for (long i = 0; i < psArrayLength(output); i++) { 833 psMetadata *row = output->data[i]; 834 835 chipRunRow *chipRun = chipRunObjectFromMetadata(row); 836 // set chipRun.state to 'stop' 837 if (!pxchipRunSetState(config, chipRun->chip_id, "stop")) { 838 psError(PS_ERR_UNKNOWN, false, "failed to change chipRun.state for chip_id: %" PRId64, chipRun->chip_id); 839 psFree(chipRun); 840 psFree(output); 841 return false; 842 } 843 844 // camQueueChipID() can only be run after chipRun.state has been set to 845 // stop 846 if (!pxcamQueueByChipID(config, 847 chipRun->chip_id, 848 chipRun->workdir, 849 chipRun->label, 850 chipRun->reduction, 851 chipRun->expgroup, 852 chipRun->dvodb 853 )) { 854 // rollback 855 if (!psDBRollback(config->dbh)) { 856 psError(PS_ERR_UNKNOWN, false, "database error"); 857 } 858 psError(PS_ERR_UNKNOWN, false, "failed to queue camPendingExp"); 859 psFree(chipRun); 860 psFree(output); 861 return false; 862 } 863 psFree(chipRun); 864 } 865 866 psFree(output); 867 868 return true; 869 } -
trunk/ippTools/src/chiptool.h
r13578 r14018 38 38 pxConfig *chiptoolConfig(pxConfig *config, int argc, char **argv); 39 39 40 bool chipQueueExpTag(pxConfig *config,41 psString exp_tag,42 psString workdir,43 psString label,44 psString recipe,45 psString expgroup,46 psString dvodb);47 48 40 #endif // CHIPTOOL_H -
trunk/ippTools/src/chiptoolConfig.c
r13937 r14018 127 127 psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-chip_id", 0, 128 128 "define chip ID (required)", NULL); 129 psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-exp_tag", 0, 130 "define exposure ID", NULL); 129 131 psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-class_id", 0, 130 132 "define class ID (requied)", NULL); -
trunk/ippTools/src/pxdata.h
r12075 r14018 24 24 25 25 psString pxDataGet(const char *filename); 26 psString pxDataGetCached(const char *filename); 26 27 27 28 #endif // PXDATA_H -
trunk/ippTools/src/pxinject.c
r11854 r14018 24 24 #include <stdlib.h> 25 25 #include <ippdb.h> 26 #include <string.h> 26 27 27 28 #include "pxtools.h" 28 #include "pxtag.h"29 29 #include "pxinject.h" 30 30 31 31 static bool newExpMode(pxConfig *config); 32 32 static bool newImfileMode(pxConfig *config); 33 static bool updatenewExpMode(pxConfig *config); 33 34 34 35 # define MODECASE(caseName, func) \ … … 52 53 MODECASE(PXINJECT_MODE_NEWEXP, newExpMode); 53 54 MODECASE(PXINJECT_MODE_NEWIMFILE, newImfileMode); 55 MODECASE(PXINJECT_MODE_UPDATENEWEXP, updatenewExpMode); 54 56 default: 55 57 psAbort("invalid option (this should not happen)"); … … 134 136 exp_tag, 135 137 exp_id, 138 "reg", // state 136 139 camera, 137 140 telescope, 138 141 imfiles, 139 workdir 142 workdir, 143 "dirty" 140 144 ) 141 145 ) { … … 191 195 return false; 192 196 } 197 #if 0 193 198 psString class = psMetadataLookupStr(&status, config->args, "-class"); 194 199 if (!status) { … … 200 205 return false; 201 206 } 207 #endif 202 208 psString class_id = psMetadataLookupStr(&status, config->args, "-class_id"); 203 209 if (!status) { … … 220 226 221 227 // insert with error flag state set to 0 (no errors) 222 if (!newImfileInsert(config->dbh, exp_tag, class , class_id, uri)) {228 if (!newImfileInsert(config->dbh, exp_tag, class_id, uri)) { 223 229 psError(PS_ERR_UNKNOWN, false, "database error"); 224 230 return false; … … 227 233 return true; 228 234 } 235 236 237 static bool updatenewExpMode(pxConfig *config) 238 { 239 PS_ASSERT_PTR_NON_NULL(config, false); 240 241 bool status = false; 242 psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag"); 243 if (!status) { 244 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag"); 245 return false; 246 } 247 if (!exp_tag) { 248 psError(PS_ERR_UNKNOWN, true, "-exp_tag is required"); 249 return false; 250 } 251 252 psString state = psMetadataLookupStr(&status, config->args, "-state"); 253 if (!status) { 254 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -state"); 255 return false; 256 } 257 if (!state) { 258 psError(PS_ERR_UNKNOWN, true, "-state is required"); 259 return false; 260 } 261 262 if (state) { 263 // set detRun.state to state 264 return pxnewExpSetState(config, exp_tag, state); 265 } 266 267 return true; 268 } -
trunk/ippTools/src/pxinject.h
r9392 r14018 26 26 PXINJECT_MODE_NONE = 0x0, 27 27 PXINJECT_MODE_NEWEXP, 28 PXINJECT_MODE_NEWIMFILE 28 PXINJECT_MODE_NEWIMFILE, 29 PXINJECT_MODE_UPDATENEWEXP 29 30 } pxinjectMode; 30 31 -
trunk/ippTools/src/pxinjectConfig.c
r13578 r14018 46 46 psMetadata *newExpArgs = psMetadataAlloc(); 47 47 psMetadataAddStr(newExpArgs, PS_LIST_TAIL, "-exp_id", 0, 48 "define the exp_id (required)", NULL);48 "define the exp_id (required)", NULL); 49 49 psMetadataAddStr(newExpArgs, PS_LIST_TAIL, "-inst", 0, 50 "define the camera name (required)", NULL);50 "define the camera name (required)", NULL); 51 51 psMetadataAddStr(newExpArgs, PS_LIST_TAIL, "-telescope", 0, 52 "define the telescope name (required)", NULL);52 "define the telescope name (required)", NULL); 53 53 psMetadataAddS32(newExpArgs, PS_LIST_TAIL, "-imfiles", 0, 54 "define the number of imfiles in this exp (required)", 0);54 "define the number of imfiles in this exp (required)", 0); 55 55 psMetadataAddStr(newExpArgs, PS_LIST_TAIL, "-workdir", 0, 56 "define workdir (required)", 0);56 "define workdir (required)", 0); 57 57 psMetadataAddBool(newExpArgs, PS_LIST_TAIL, "-simple", 0, 58 "use the simple output format", false);58 "use the simple output format", false); 59 59 60 60 // -newImfile 61 61 psMetadata *newImfileArgs = psMetadataAlloc(); 62 62 psMetadataAddStr(newImfileArgs, PS_LIST_TAIL, "-exp_tag", 0, 63 "define the exp_tag (required)", NULL); 63 "define the exp_tag (required)", NULL); 64 #if 0 64 65 psMetadataAddStr(newImfileArgs, PS_LIST_TAIL, "-class", 0, 65 "define the class (required)", NULL); 66 "define the class (required)", NULL); 67 #endif 66 68 psMetadataAddStr(newImfileArgs, PS_LIST_TAIL, "-class_id", 0, 67 "define the class ID (required)", NULL);69 "define the class ID (required)", NULL); 68 70 psMetadataAddStr(newImfileArgs, PS_LIST_TAIL, "-uri", 0, 69 "define the URI (required)", NULL); 71 "define the URI (required)", NULL); 72 73 // -updatenewExp 74 psMetadata *updatenewExpArgs = psMetadataAlloc(); 75 psMetadataAddStr(updatenewExpArgs, PS_LIST_TAIL, "-exp_tag", 0, 76 "define the exp_tag (required)", NULL); 77 psMetadataAddStr(updatenewExpArgs, PS_LIST_TAIL, "-state", 0, 78 "set state (required)", NULL); 79 70 80 71 81 psMetadata *argSets = psMetadataAlloc(); … … 74 84 PXTOOL_ADD_MODE("-newExp", "", PXINJECT_MODE_NEWEXP, newExpArgs); 75 85 PXTOOL_ADD_MODE("-newImfile", "", PXINJECT_MODE_NEWIMFILE, newImfileArgs); 86 PXTOOL_ADD_MODE("-updatenewExp", "", PXINJECT_MODE_UPDATENEWEXP, updatenewExpArgs); 76 87 77 88 if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) { -
trunk/ippTools/src/pxtables.c
r12530 r14018 60 60 CREATE_TABLE(rawImfileCreateTable); 61 61 CREATE_TABLE(guidePendingExpCreateTable); 62 CREATE_TABLE(chipPendingExpCreateTable); 63 CREATE_TABLE(chipPendingImfileCreateTable); 64 CREATE_TABLE(chipProcessedExpCreateTable); 62 CREATE_TABLE(chipRunCreateTable); 63 CREATE_TABLE(chipInputImfileCreateTable); 65 64 CREATE_TABLE(chipProcessedImfileCreateTable); 66 65 CREATE_TABLE(chipMaskCreateTable); 67 CREATE_TABLE(cam PendingExpCreateTable);66 CREATE_TABLE(camRunCreateTable); 68 67 CREATE_TABLE(camProcessedExpCreateTable); 69 68 CREATE_TABLE(camMaskCreateTable); … … 142 141 DROP_TABLE(rawImfileDropTable); 143 142 DROP_TABLE(guidePendingExpDropTable); 144 DROP_TABLE(chipPendingExpDropTable); 145 DROP_TABLE(chipPendingImfileDropTable); 146 DROP_TABLE(chipProcessedExpDropTable); 143 DROP_TABLE(chipRunDropTable); 144 DROP_TABLE(chipInputImfileDropTable); 147 145 DROP_TABLE(chipProcessedImfileDropTable); 148 146 DROP_TABLE(chipMaskDropTable); 149 DROP_TABLE(cam PendingExpDropTable);147 DROP_TABLE(camRunDropTable); 150 148 DROP_TABLE(camProcessedExpDropTable); 151 149 DROP_TABLE(camMaskDropTable); -
trunk/ippTools/src/pxtag.h
r10114 r14018 21 21 #define PXTAG_H 1 22 22 23 #include "pxtools.h" 23 #include <pslib.h> 24 25 #include "pxconfig.h" 24 26 25 27 psString pxGenExpTag(pxConfig *config, const char *exp_id); -
trunk/ippTools/src/pxtools.h
r13583 r14018 21 21 #define PXTOOLS_H 1 22 22 23 # include <stdio.h>24 # include <strings.h> // for strcasecmp25 # include <unistd.h> // for unlink26 # include <pslib.h>27 # include <psmodules.h>28 # include <ippdb.h>23 #include <stdio.h> 24 #include <strings.h> // for strcasecmp 25 #include <unistd.h> // for unlink 26 #include <pslib.h> 27 #include <psmodules.h> 28 #include <ippdb.h> 29 29 30 # include "pxtoolsErrorCodes.h" 31 # include "pxio.h" 32 # include "pxdata.h" 30 #include "pxtoolsErrorCodes.h" 31 #include "pxio.h" 32 #include "pxdata.h" 33 #include "pxtag.h" 34 #include "pxregister.h" 35 #include "pxchip.h" 36 #include "pxcam.h" 37 #include "pxconfig.h" 33 38 34 39 # define MAX_ROWS 10e9 35 40 # define PXTOOL_MODE_NONE 0x0 36 41 37 typedef struct {38 char *modeName;39 int mode;40 pmConfig *modules;41 psDB *dbh;42 psMetadata *args;43 psMetadata *where;44 int argc;45 char **argv;46 } pxConfig;47 48 pxConfig *pxConfigAlloc(void);49 42 bool pxCreateTables (pxConfig *config); 50 43 bool pxDeleteTables (pxConfig *config); -
trunk/ippTools/src/regtool.c
r13617 r14018 44 44 // static guidePendingExpRow *newToP1PendingExp(newExpRow *newExp); 45 45 //static chipPendingExpRow *newTochipPendingExp(pxConfig *config, newExpRow *newExp); 46 //static chip PendingImfileRow *rawImfileTochipPendingImfile(pxConfig *config, psS64 chip_id, rawImfileRow *rawImfile);46 //static chipInputImfileRow *rawImfileTochipInputImfile(pxConfig *config, psS64 chip_id, rawImfileRow *rawImfile); 47 47 48 48 static rawExpRow *newToRawExp(pxConfig *config, newExpRow *exp); … … 282 282 return false; 283 283 } 284 psFree(object); 284 285 // insert the rawImfile object into the database 285 286 if (!rawImfileInsertObject(config->dbh, imfile)) { … … 290 291 psError(PS_ERR_UNKNOWN, false, "failed to insert row into the database"); 291 292 psFree(imfile); 292 psFree(object);293 293 psFree(output); 294 294 return false; 295 295 } 296 296 psFree(imfile); 297 // remove the neImfile object from the database298 if (!newImfileDeleteObject(config->dbh, object)) {299 // rollback300 if (!psDBRollback(config->dbh)) {301 psError(PS_ERR_UNKNOWN, false, "database error");302 }303 psError(PS_ERR_UNKNOWN, false, "failed to delete row from the database");304 psFree(object);305 psFree(output);306 return false;307 }308 psFree(object);309 297 } 310 298 … … 573 561 } 574 562 if (!psArrayLength(output)) { 575 ps Trace("regtool", PS_LOG_INFO, "norows found");563 psError(PS_ERR_UNKNOWN, false, "no pending newExp rows found"); 576 564 psFree(output); 577 return true; 578 } 579 580 // start a transaction so we don't end up with an exp in both rawExp & 581 // newExp 565 return false; 566 } 567 582 568 if (!psDBTransaction(config->dbh)) { 583 569 psError(PS_ERR_UNKNOWN, false, "database error"); … … 603 589 return false; 604 590 } 591 psFree(newExp); 605 592 606 593 // insert the rawExp object into the database … … 612 599 psError(PS_ERR_UNKNOWN, false, "database error"); 613 600 psFree(rawExp); 614 psFree(newExp);615 601 psFree(output); 616 602 return false; … … 618 604 psFree(rawExp); 619 605 620 // delete the newExp object from the database 621 if (!newExpDeleteObject(config->dbh, newExp)) { 606 // if this is a detrend image don't put it in the chip queue (and we're 607 // done) 608 if (detrend) { 609 // set the state for the newExp to stop 610 if (!pxnewExpSetState(config, exp_tag, "stop")) { 611 // rollback 612 if (!psDBRollback(config->dbh)) { 613 psError(PS_ERR_UNKNOWN, false, "database error"); 614 } 615 psError(PS_ERR_UNKNOWN, false, "failed to change newExp.state for exp_tag: %s", exp_tag); 616 psFree(output); 617 return false; 618 } 619 continue; 620 } 621 622 623 // set the state for the newExp to stop 624 if (!pxnewExpSetState(config, exp_tag, "stop")) { 622 625 // rollback 623 626 if (!psDBRollback(config->dbh)) { 624 627 psError(PS_ERR_UNKNOWN, false, "database error"); 625 628 } 626 psError(PS_ERR_UNKNOWN, false, "database error"); 627 psFree(newExp); 629 psError(PS_ERR_UNKNOWN, false, "failed to change newExp.state for exp_tag: %s", exp_tag); 628 630 psFree(output); 629 631 return false; 630 632 } 631 633 632 psFree(newExp);633 634 // if this is a detrend image don't put it in the chip queue (and we're635 // done)636 if (detrend) {637 continue;638 }639 640 634 // insert an entry into the chipPendingExp table 641 if (!chipQueueExpTag(config, exp_tag, NULL, NULL, NULL, NULL, NULL)) { 635 // this can only be run as the newExp's state has been set to stop 636 if (!pxchipQueueByExpTag(config, exp_tag, NULL, NULL, NULL, NULL, NULL)) { 642 637 // rollback 643 638 if (!psDBRollback(config->dbh)) { … … 649 644 } 650 645 } 651 652 646 psFree(output); 653 647 … … 828 822 829 823 830 static chip PendingImfileRow *rawImfileTochipPendingImfile(pxConfig *config, psS64 chip_id, rawImfileRow *rawImfile)831 { 832 return chip PendingImfileRowAlloc(824 static chipInputImfileRow *rawImfileTochipInputImfile(pxConfig *config, psS64 chip_id, rawImfileRow *rawImfile) 825 { 826 return chipInputImfileRowAlloc( 833 827 chip_id, 834 828 rawImfile->class_id,
Note:
See TracChangeset
for help on using the changeset viewer.
