IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14018


Ignore:
Timestamp:
Jul 5, 2007, 10:15:41 AM (19 years ago)
Author:
jhoblitt
Message:

merge backtrack branch

Location:
trunk/ippTools
Files:
8 added
3 deleted
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/scripts/camtest.sh

    r12188 r14018  
    88camtool -pendingimfile || exit 1
    99
    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 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 -nastro 42 -path_base file:///foo -zp_mean 1 -zp_stdev 2 || exit 1
     10camtool -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
     11camtool -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  
    88
    99for 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 1
     10    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
    1111done;
    1212
    1313for 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 1
     14    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
    1515done;
    1616
  • trunk/ippTools/scripts/difftest.sh

    r12533 r14018  
    1212difftool -todiffskyfile || exit 1
    1313difftool -inputskyfile || exit 1
    14 difftool -adddiffskyfile -diff_id 1 -uri file:///tmp/diff/skyfile -bg 1 -bg_stdev 2 || exit 1
     14difftool -adddiffskyfile -diff_id 1 -uri file:///tmp/diff/skyfile -path_base file://lalaland -bg 1 -bg_stdev 2 || exit 1
    1515difftool -diffskyfile -diff_id 1 || exit 1
    1616difftool -updaterun -state stop -diff_id 1 || exit 1
  • trunk/ippTools/scripts/regtest.sh

    r12259 r14018  
    1111
    1212for ID in `seq 0 3`; do
    13     $inject -newImfile -exp_tag $exp_tag1 -class OTA -class_id $ID -uri file://$ID || exit 1
     13    $inject -newImfile -exp_tag $exp_tag1 -class_id $ID -uri file://$ID || exit 1
    1414done;
     15
     16$inject -updatenewExp -exp_tag $exp_tag1 -state run
    1517
    1618exp_tag2=`$inject -newExp -exp_id t11 -inst gpc -telescope ps1 -imfiles 4 -workdir file::///some/path -simple` || exit 1
    1719
    1820for ID in `seq 0 3`; do
    19     $inject -newImfile -exp_tag $exp_tag2 -class OTA -class_id $ID -uri file://$ID || exit 1
     21    $inject -newImfile -exp_tag $exp_tag2 -class_id $ID -uri file://$ID || exit 1
    2022done;
     23
     24$inject -updatenewExp -exp_tag $exp_tag2 -state run
    2125
    2226$regtool -pendingimfile || exit 1
  • trunk/ippTools/scripts/warptest.sh

    r12131 r14018  
    2424warptool -towarped || exit 1
    2525
    26 warptool -addwarped -warp_id 1 -skycell_id foo1 -tess_id bar -uri file:///tmp/foo -bg 1 -bg_stdev 2 || exit 1
    27 warptool -addwarped -warp_id 1 -skycell_id foo2 -tess_id bar -uri file:///tmp/foo -bg 1 -bg_stdev 2 || exit 1
     26warptool -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
     27warptool -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
    2828
    2929warptool -warped -warp_id 1 || exit 1
  • trunk/ippTools/share/camtool_find_pendingexp.sql

    r12259 r14018  
    33-- "cleaner" to use the same query for both cases
    44SELECT
    5     camPendingExp.*,
     5    camRun.*,
    66    rawExp.exp_tag,
    77    rawExp.exp_id,
     
    99    rawExp.telescope,
    1010    rawExp.filelevel
    11 FROM camPendingExp
    12 JOIN chipProcessedExp
     11FROM camRun
     12JOIN chipRun
     13    USING(chip_id)
     14JOIN chipProcessedImfile
    1315    USING(chip_id)
    1416JOIN rawExp
    15     ON chipProcessedExp.exp_tag = rawExp.exp_tag
     17    ON chipProcessedImfile.exp_tag = rawExp.exp_tag
    1618LEFT JOIN camProcessedExp
    17     ON camPendingExp.cam_id = camProcessedExp.cam_id
     19    ON camRun.cam_id = camProcessedExp.cam_id
    1820LEFT JOIN camMask
    19     ON camPendingExp.label = camMask.label
     21    ON camRun.label = camMask.label
    2022WHERE
    21     camProcessedExp.cam_id IS NULL
     23    chipRun.state = 'stop'
     24    AND camRun.state = 'run'
    2225    AND camMask.label IS NULL
     26    AND camProcessedExp.cam_id IS NULL
  • trunk/ippTools/share/camtool_queue_chip_id.sql

    r12237 r14018  
    11-- camtool only operates on exposures so we can safely queue more then one at a
    22-- time without worrying about losing the track of the generated cam_id
    3 INSERT INTO camPendingExp
     3INSERT INTO camRun
    44    SElECT
    55        0,              -- cam_id
    66        chip_id,        -- chip_id
     7        '%s',           -- state
    78        '%s',           -- workdir
     9        '%s',           -- workdir_state
    810        '%s',           -- label
    9         '%s',           -- recipe
     11        '%s',           -- reduction
    1012        '%s',           -- expgroup
    1113        '%s'            -- dvodb
    12     FROM chipProcessedExp
     14    FROM chipRun
    1315    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
    62SELECT 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
     11FROM
     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  
    11SELECT DISTINCT
    2    chipPendingImfile.*
    3 FROM chipPendingImfile
     2   chipInputImfile.*
     3FROM chipInputImfile
    44LEFT JOIN chipProcessedImfile
    55    USING(chip_id, class_id)
  • trunk/ippTools/share/chiptool_pendingimfile.sql

    r12259 r14018  
    11SELECT
    2     chipPendingExp.*,
    3     chipPendingImfile.class_id,
    4     chipPendingImfile.uri,
     2    chipRun.*,
     3    chipInputImfile.exp_tag,
     4    chipInputImfile.class_id,
     5    rawImfile.uri,
    56    rawExp.exp_id,
    67    rawExp.camera,
    78    rawExp.telescope,
    89    rawExp.filelevel
    9 FROM chipPendingImfile
    10 JOIN chipPendingExp
     10FROM chipRun
     11JOIN chipInputImfile
    1112    USING(chip_id)
     13LEFT 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
     17JOIN rawImfile
     18    ON chipInputImfile.exp_tag = rawImfile.exp_tag
     19    AND chipInputImfile.class_id = rawImfile.class_id
    1220JOIN rawExp
    13     ON chipPendingExp.exp_tag = rawExp.exp_tag
     21    ON rawImfile.exp_tag = rawExp.exp_tag
    1422LEFT JOIN chipMask
    15     ON chipPendingExp.label = chipMask.label
     23    ON chipRun.label = chipMask.label
    1624WHERE
    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 chipPendingImfile
     1INSERT INTO chipInputImfile
    22    SELECT
    3         chipPendingExp.chip_id,
    4         rawImfile.class_id,
    5         rawImfile.uri
    6     FROM chipPendingExp
    7     JOIN rawImfile
     3        LAST_INSERT_ID(),
     4        rawImfile.exp_tag,
     5        rawImfile.class_id
     6    FROM rawImfile
     7    JOIN newExp
    88        USING(exp_tag)
    99    WHERE
    1010        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)
     1SELECT 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
    815WHERE
    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
     1SELECT 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'
    811        AND rawExp.exp_tag IS NULL) as Foo
  • trunk/ippTools/share/regtool_pendingexp.sql

    r12086 r14018  
    22    newExp.*
    33FROM newExp
    4 LEFT JOIN newImfile
     4JOIN newImfile
    55    USING(exp_tag)
    66LEFT JOIN rawExp
    77    USING(exp_tag)
    88WHERE
    9     newImfile.exp_tag IS NULL
     9    newExp.state = 'run'
    1010    AND rawExp.exp_tag IS NULL
    1111    AND newExp.imfiles =
  • trunk/ippTools/src/Makefile.am

    r12190 r14018  
    1515        pztool
    1616
    17 include_HEADERS = \
     17pkginclude_HEADERS = \
    1818        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 \
    1927        pxtools.h
    2028
     
    2937        difftool.h \
    3038        stacktool.h \
    31         pxadmin.h \
    3239        pxinject.h \
    33         pxdata.h \
    34         pxio.h \
    35         pxtag.h \
    3640        pzgetexp.h \
    3741        pzgetimfiles.h \
     
    5155        pxio.c \
    5256        pxtag.c \
    53         chipqueue.c \
    54         camqueue.c
     57        pxregister.c \
     58        pxchip.c \
     59        pxcam.c
    5560
    5661# for pxtools.h
  • trunk/ippTools/src/camtool.c

    r13937 r14018  
    203203
    204204    // 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    }
    206211
    207212    if (where) {
    208         psString whereClause = psDBGenerateWhereSQL(where, "chipProcessedExp");
     213        psString whereClause = psDBGenerateWhereSQL(where, "");
    209214        psFree(where);
    210215        psStringAppend(&query, " %s", whereClause);
     
    245250        psMetadata *md = output->data[i];
    246251
    247         chipProcessedExpRow *row = chipProcessedExpObjectFromMetadata(md);
     252        chipRunRow *row = chipRunObjectFromMetadata(md);
    248253        if (!row) {
    249             psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipProcessedExp");
     254            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipRun");
    250255            psFree(output);
    251256            return false;
     
    253258
    254259        // queue the exp
    255         if (!camQueueChipID(config,
     260        if (!pxcamQueueByChipID(config,
    256261                    row->chip_id,
    257262                    workdir     ? workdir   : row->workdir,
     
    601606    }
    602607
    603     // start a transaction so we don't end up with an exp_tag is both
    604     // camPendingExp & camProcessedExp
    605608    if (!psDBTransaction(config->dbh)) {
    606609        psError(PS_ERR_UNKNOWN, false, "database error");
     
    609612    }
    610613
    611     camPendingExpRow *pendingRow = camPendingExpObjectFromMetadata(output->data[0]);
     614    camRunRow *pendingRow = camRunObjectFromMetadata(output->data[0]);
    612615    psFree(output);
    613616    // create a new camProcessedImfile object
     
    615618        pendingRow->cam_id,
    616619        pendingRow->chip_id,
    617         pendingRow->workdir,
    618         pendingRow->label,
    619         pendingRow->reduction,
    620         pendingRow->expgroup,
    621         pendingRow->dvodb,
    622620        uri,
    623621        bg,
     
    637635        code
    638636    );
     637    psFree(pendingRow);
    639638
    640639    // insert the new row into the camProcessedImfile table
     
    646645        psError(PS_ERR_UNKNOWN, false, "database error");
    647646        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
    651657    psFree(row);
    652658
    653     // delete the camPendingExp row from the database
    654     if (!camPendingExpDeleteObject(config->dbh, pendingRow)) {
    655         // rollback
    656         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 -> camProcessedExp
    667659    if (!psDBCommit(config->dbh)) {
    668660        psError(PS_ERR_UNKNOWN, false, "database error");
  • trunk/ippTools/src/camtool.h

    r12237 r14018  
    3838pxConfig *camtoolConfig(pxConfig *config, int argc, char **argv);
    3939
    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 
    4840#endif // CAMTOOL_H
  • trunk/ippTools/src/chiptool.c

    r13937 r14018  
    3030#include "pxtools.h"
    3131#include "pxdata.h"
     32
    3233#include "chiptool.h"
    3334#include "camtool.h"
     
    4243static bool unblockMode(pxConfig *config);
    4344
    44 static chipProcessedImfileRow *chipPendingToProcessedImfile(pxConfig *config, chipPendingImfileRow *imfile);
    45 static chipProcessedExpRow *chipPendingToProcessedExp(pxConfig *config, chipPendingExpRow *pendingExp);
    4645static bool chipProcessedCompleteExp(pxConfig *config);
    4746
     
    243242
    244243        // 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)) {
    246245            if (!psDBRollback(config->dbh)) {
    247246                psError(PS_ERR_UNKNOWN, false, "database error");
     
    283282
    284283    if (config->where) {
    285         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "chipPendingImfile");
     284        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "chipInputImfile");
    286285        psStringAppend(&query, " AND %s", whereClause);
    287286        psFree(whereClause);
     
    330329
    331330    // negative simple so the default is true
    332     if (!ippdbPrintMetadatas(stdout, output, "chipPendingImfile", !simple)) {
     331    if (!ippdbPrintMetadatas(stdout, output, "chipInputImfile", !simple)) {
    333332        psError(PS_ERR_UNKNOWN, false, "failed to print array");
    334333        psFree(output);
     
    346345    PS_ASSERT_PTR_NON_NULL(config, false);
    347346
    348     // select * from chipProcessedImfiles
    349     // where
    350     // exp_tag & class_id are not in chipPendingImfile
    351 
    352     // add the completed imfile to
    353     // the chipProcessedeImfile tables
    354     // remove corresponding entries from the
    355     // chipPendingImfile table
    356     // check to see if any chipPendingExps have no
    357     // associated chipPendingImfiles
    358     // if so move the chipPendingExp(s) to chipProcessedExp
    359 
    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 here
    420         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 iteration
    426     // count but no detInputExps
    427     if (!psDBTransaction(config->dbh)) {
    428         psError(PS_ERR_UNKNOWN, false, "database error");
    429         psFree(output);
    430         return false;
    431     }
    432 
    433     // insert into chipProcessedImfile
    434     // remove chipPendingImfile entry
    435     for (long i = 0; i < psArrayLength(output); i++) {
    436         psMetadata *row = output->data[i];
    437         // convert metadata into a chipPendingImfile object
    438         chipPendingImfileRow *object = chipPendingImfileObjectFromMetadata(row);
    439         // convert chipPendingImfile object into a chipProcessedImfile object
    440         chipProcessedImfileRow *imfile = chipPendingToProcessedImfile(config, object);
    441         if (!imfile) {
    442             // rollback
    443             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 database
    452         if (!chipProcessedImfileInsertObject(config->dbh, imfile)) {
    453             // rollback
    454             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 database
    465         if (!chipPendingImfileDeleteObject(config->dbh, object)) {
    466             // there must be atleast 1 Imfile to get this far
    467             // rollback
    468             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 as
    482     // well.  Otherwise, if the last imfile in an exp is moved and the exp
    483     // migration fails then the data base is left in a satuation where the exp
    484     // migration can't happen.
    485 
    486     if (!chipProcessedCompleteExp(config)) {
    487         // rollback
    488         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 -> chipProcessedImfile
    496     // point of no return for chipPendingExp -> chipProcessedExp
    497     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 
    510347    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
    835379    psString uri = psMetadataLookupStr(&status, config->args, "-uri");
    836380    if (!status) {
     
    961505    }
    962506
    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,
    966516        uri,
    967517        bg,
     
    985535        path_base,
    986536        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
     581static bool processedimfileMode(pxConfig *config)
    992582{
    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
     674static 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
     698static 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
     722static 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
     775static 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
     802static 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  
    3838pxConfig *chiptoolConfig(pxConfig *config, int argc, char **argv);
    3939
    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 
    4840#endif // CHIPTOOL_H
  • trunk/ippTools/src/chiptoolConfig.c

    r13937 r14018  
    127127    psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-chip_id",  0,
    128128            "define chip ID (required)", NULL);
     129    psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-exp_tag",  0,
     130            "define exposure ID", NULL);
    129131    psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-class_id",  0,
    130132            "define class ID (requied)", NULL);
  • trunk/ippTools/src/pxdata.h

    r12075 r14018  
    2424
    2525psString pxDataGet(const char *filename);
     26psString pxDataGetCached(const char *filename);
    2627
    2728#endif // PXDATA_H
  • trunk/ippTools/src/pxinject.c

    r11854 r14018  
    2424#include <stdlib.h>
    2525#include <ippdb.h>
     26#include <string.h>
    2627
    2728#include "pxtools.h"
    28 #include "pxtag.h"
    2929#include "pxinject.h"
    3030
    3131static bool newExpMode(pxConfig *config);
    3232static bool newImfileMode(pxConfig *config);
     33static bool updatenewExpMode(pxConfig *config);
    3334
    3435# define MODECASE(caseName, func) \
     
    5253        MODECASE(PXINJECT_MODE_NEWEXP, newExpMode);
    5354        MODECASE(PXINJECT_MODE_NEWIMFILE, newImfileMode);
     55        MODECASE(PXINJECT_MODE_UPDATENEWEXP, updatenewExpMode);
    5456        default:
    5557            psAbort("invalid option (this should not happen)");
     
    134136                exp_tag,
    135137                exp_id,
     138                "reg", // state
    136139                camera,
    137140                telescope,
    138141                imfiles,
    139                 workdir
     142                workdir,
     143                "dirty"
    140144            )
    141145        ) {
     
    191195        return false;
    192196    }
     197#if 0
    193198    psString class = psMetadataLookupStr(&status, config->args, "-class");
    194199    if (!status) {
     
    200205        return false;
    201206    }
     207#endif
    202208    psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
    203209    if (!status) {
     
    220226
    221227    // 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)) {
    223229        psError(PS_ERR_UNKNOWN, false, "database error");
    224230        return false;
     
    227233    return true;
    228234}
     235
     236
     237static 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  
    2626    PXINJECT_MODE_NONE           = 0x0,
    2727    PXINJECT_MODE_NEWEXP,
    28     PXINJECT_MODE_NEWIMFILE
     28    PXINJECT_MODE_NEWIMFILE,
     29    PXINJECT_MODE_UPDATENEWEXP
    2930} pxinjectMode;
    3031
  • trunk/ippTools/src/pxinjectConfig.c

    r13578 r14018  
    4646    psMetadata *newExpArgs = psMetadataAlloc();
    4747    psMetadataAddStr(newExpArgs, PS_LIST_TAIL, "-exp_id",  0,
    48         "define the exp_id (required)", NULL);
     48            "define the exp_id (required)", NULL);
    4949    psMetadataAddStr(newExpArgs, PS_LIST_TAIL, "-inst",  0,
    50         "define the camera name (required)", NULL);
     50            "define the camera name (required)", NULL);
    5151    psMetadataAddStr(newExpArgs, PS_LIST_TAIL, "-telescope",  0,
    52         "define the telescope name (required)", NULL);
     52            "define the telescope name (required)", NULL);
    5353    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);
    5555    psMetadataAddStr(newExpArgs, PS_LIST_TAIL, "-workdir",  0,
    56         "define workdir (required)", 0);
     56            "define workdir (required)", 0);
    5757    psMetadataAddBool(newExpArgs, PS_LIST_TAIL, "-simple",  0,
    58         "use the simple output format", false);
     58            "use the simple output format", false);
    5959
    6060    // -newImfile
    6161    psMetadata *newImfileArgs = psMetadataAlloc();
    6262    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
    6465    psMetadataAddStr(newImfileArgs, PS_LIST_TAIL, "-class",  0,
    65         "define the class (required)", NULL);
     66            "define the class (required)", NULL);
     67#endif
    6668    psMetadataAddStr(newImfileArgs, PS_LIST_TAIL, "-class_id",  0,
    67         "define the class ID (required)", NULL);
     69            "define the class ID (required)", NULL);
    6870    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
    7080
    7181    psMetadata *argSets = psMetadataAlloc();
     
    7484    PXTOOL_ADD_MODE("-newExp",      "", PXINJECT_MODE_NEWEXP,       newExpArgs);
    7585    PXTOOL_ADD_MODE("-newImfile",   "", PXINJECT_MODE_NEWIMFILE,    newImfileArgs);
     86    PXTOOL_ADD_MODE("-updatenewExp",   "", PXINJECT_MODE_UPDATENEWEXP,    updatenewExpArgs);
    7687
    7788    if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
  • trunk/ippTools/src/pxtables.c

    r12530 r14018  
    6060    CREATE_TABLE(rawImfileCreateTable);
    6161    CREATE_TABLE(guidePendingExpCreateTable);
    62     CREATE_TABLE(chipPendingExpCreateTable);
    63     CREATE_TABLE(chipPendingImfileCreateTable);
    64     CREATE_TABLE(chipProcessedExpCreateTable);
     62    CREATE_TABLE(chipRunCreateTable);
     63    CREATE_TABLE(chipInputImfileCreateTable);
    6564    CREATE_TABLE(chipProcessedImfileCreateTable);
    6665    CREATE_TABLE(chipMaskCreateTable);
    67     CREATE_TABLE(camPendingExpCreateTable);
     66    CREATE_TABLE(camRunCreateTable);
    6867    CREATE_TABLE(camProcessedExpCreateTable);
    6968    CREATE_TABLE(camMaskCreateTable);
     
    142141    DROP_TABLE(rawImfileDropTable);
    143142    DROP_TABLE(guidePendingExpDropTable);
    144     DROP_TABLE(chipPendingExpDropTable);
    145     DROP_TABLE(chipPendingImfileDropTable);
    146     DROP_TABLE(chipProcessedExpDropTable);
     143    DROP_TABLE(chipRunDropTable);
     144    DROP_TABLE(chipInputImfileDropTable);
    147145    DROP_TABLE(chipProcessedImfileDropTable);
    148146    DROP_TABLE(chipMaskDropTable);
    149     DROP_TABLE(camPendingExpDropTable);
     147    DROP_TABLE(camRunDropTable);
    150148    DROP_TABLE(camProcessedExpDropTable);
    151149    DROP_TABLE(camMaskDropTable);
  • trunk/ippTools/src/pxtag.h

    r10114 r14018  
    2121#define PXTAG_H 1
    2222
    23 #include "pxtools.h"
     23#include <pslib.h>
     24
     25#include "pxconfig.h"
    2426
    2527psString pxGenExpTag(pxConfig *config, const char *exp_id);
  • trunk/ippTools/src/pxtools.h

    r13583 r14018  
    2121#define PXTOOLS_H 1
    2222
    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>
     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>
    2929
    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"
    3338
    3439# define MAX_ROWS 10e9
    3540# define PXTOOL_MODE_NONE 0x0
    3641
    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);
    4942bool pxCreateTables (pxConfig *config);
    5043bool pxDeleteTables (pxConfig *config);
  • trunk/ippTools/src/regtool.c

    r13617 r14018  
    4444// static guidePendingExpRow *newToP1PendingExp(newExpRow *newExp);
    4545//static chipPendingExpRow *newTochipPendingExp(pxConfig *config, newExpRow *newExp);
    46 //static chipPendingImfileRow *rawImfileTochipPendingImfile(pxConfig *config, psS64 chip_id, rawImfileRow *rawImfile);
     46//static chipInputImfileRow *rawImfileTochipInputImfile(pxConfig *config, psS64 chip_id, rawImfileRow *rawImfile);
    4747
    4848static rawExpRow *newToRawExp(pxConfig *config, newExpRow *exp);
     
    282282                return false;
    283283            }
     284            psFree(object);
    284285            // insert the rawImfile object into the database
    285286            if (!rawImfileInsertObject(config->dbh, imfile)) {
     
    290291                psError(PS_ERR_UNKNOWN, false, "failed to insert row into the database");
    291292                psFree(imfile);
    292                 psFree(object);
    293293                psFree(output);
    294294                return false;
    295295            }
    296296            psFree(imfile);
    297             // remove the neImfile object from the database
    298             if (!newImfileDeleteObject(config->dbh, object)) {
    299                 // rollback
    300                 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);
    309297        }
    310298
     
    573561    }
    574562    if (!psArrayLength(output)) {
    575         psTrace("regtool", PS_LOG_INFO, "no rows found");
     563        psError(PS_ERR_UNKNOWN, false, "no pending newExp rows found");
    576564        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
    582568    if (!psDBTransaction(config->dbh)) {
    583569        psError(PS_ERR_UNKNOWN, false, "database error");
     
    603589            return false;
    604590        }
     591        psFree(newExp);
    605592
    606593        // insert the rawExp object into the database
     
    612599            psError(PS_ERR_UNKNOWN, false, "database error");
    613600            psFree(rawExp);
    614             psFree(newExp);
    615601            psFree(output);
    616602            return false;
     
    618604        psFree(rawExp);
    619605
    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")) {
    622625            // rollback
    623626            if (!psDBRollback(config->dbh)) {
    624627                psError(PS_ERR_UNKNOWN, false, "database error");
    625628            }
    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);
    628630            psFree(output);
    629631            return false;
    630632        }
    631633
    632         psFree(newExp);
    633 
    634         // if this is a detrend image don't put it in the chip queue (and we're
    635         // done)
    636         if (detrend) {
    637             continue;
    638         }
    639 
    640634        // 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)) {
    642637            // rollback
    643638            if (!psDBRollback(config->dbh)) {
     
    649644        }
    650645    }
    651 
    652646    psFree(output);
    653647
     
    828822
    829823
    830 static chipPendingImfileRow *rawImfileTochipPendingImfile(pxConfig *config, psS64 chip_id, rawImfileRow *rawImfile)
    831 {
    832     return chipPendingImfileRowAlloc(
     824static chipInputImfileRow *rawImfileTochipInputImfile(pxConfig *config, psS64 chip_id, rawImfileRow *rawImfile)
     825{
     826    return chipInputImfileRowAlloc(
    833827            chip_id,
    834828            rawImfile->class_id,
Note: See TracChangeset for help on using the changeset viewer.