IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13990


Ignore:
Timestamp:
Jun 28, 2007, 12:01:22 PM (19 years ago)
Author:
jhoblitt
Message:

refactor chiptool & db to preserve metadata history

Location:
branches/backtrack/ippTools
Files:
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • branches/backtrack/ippTools/scripts/chiptest.sh

    r12174 r13990  
    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
  • branches/backtrack/ippTools/share/chiptool_completely_processed_exp.sql

    r13403 r13990  
    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 DISTINCT
     13        chipRun.*,
     14        rawExp.imfiles,
     15        chipProcessedImfile.exp_tag,
     16        chipProcessedImfile.class_id
     17    FROM chipRun
     18    JOIN chipPendingImfile
     19        USING(chip_id)
     20    JOIN rawExp
     21        ON chipPendingImfile.exp_tag = rawExp.exp_tag
     22    LEFT JOIN chipProcessedImfile
     23        USING(chip_id)
     24    WHERE
     25        chipProcessedImfile.chip_id IS NOT NULL
     26        AND chipProcessedImfile.exp_tag IS NOT NULL
     27        AND chipProcessedImfile.class_id IS NOT NULL
     28        AND chipProcessedImfile.fault = 0
     29    GROUP BY
     30        chipProcessedImfile.class_id,
     31        chipProcessedImfile.exp_tag
     32    HAVING rawExp.imfiles = COUNT(chipProcessedImfile.class_id)) as Foo
  • branches/backtrack/ippTools/share/chiptool_pendingimfile.sql

    r12259 r13990  
    11SELECT
    2     chipPendingExp.*,
     2    chipRun.*,
     3    chipPendingImfile.exp_tag,
    34    chipPendingImfile.class_id,
    4     chipPendingImfile.uri,
     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 chipPendingImfile
    1112    USING(chip_id)
     13LEFT JOIN chipProcessedImfile
     14    ON chipPendingImfile.chip_id = chipProcessedImfile.chip_id
     15    AND chipPendingImfile.exp_tag = chipProcessedImfile.exp_tag
     16    AND chipPendingImfile.class_id = chipProcessedImfile.class_id
     17JOIN rawImfile
     18    ON chipPendingImfile.exp_tag = rawImfile.exp_tag
     19    AND chipPendingImfile.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
  • branches/backtrack/ippTools/share/chiptool_queuerawimfile.sql

    r12174 r13990  
    11INSERT INTO chipPendingImfile
    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
  • branches/backtrack/ippTools/src/chipqueue.c

    r12232 r13990  
    2323
    2424#include "pxtools.h"
    25 #include "pxdata.h"
    2625#include "chiptool.h"
    2726
     
    3029                     psString workdir,
    3130                     psString label,
    32                      psString recipe,
     31                     psString reduction,
    3332                     psString expgroup,
    3433                     psString dvodb)
     
    3635    PS_ASSERT_PTR_NON_NULL(config, false);
    3736
    38     // load the SQL to enqueue our exp_tags from disk once
    39     static psString queuerawexp_query = NULL;
    40     if (!queuerawexp_query) {
    41         queuerawexp_query = pxDataGet("chiptool_queuerawexp.sql");
    42         psMemSetPersistent(queuerawexp_query, true);
    43         if (!queuerawexp_query) {
    44             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    45             return false;
     37    // start a transaction
     38    if (!psDBTransaction(config->dbh)) {
     39        psError(PS_ERR_UNKNOWN, false, "database error");
     40        return false;
     41    }
     42   
     43    // create a chipRun
     44    if (!chipRunInsert(config->dbh,
     45            0x0,
     46            "run",      // state               
     47            workdir,
     48            "dirty",    // workdir_state
     49            label,
     50            reduction,
     51            expgroup,
     52            dvodb)
     53    ) {
     54        // rollback
     55        if (!psDBRollback(config->dbh)) {
     56            psError(PS_ERR_UNKNOWN, false, "database error");
    4657        }
     58        psError(PS_ERR_UNKNOWN, false, "database error");
     59        return false;
    4760    }
    4861
    49     static psString queuerawimfile_query = NULL;
    50     if (!queuerawimfile_query) {
    51         queuerawimfile_query = pxDataGet("chiptool_queuerawimfile.sql");
    52         psMemSetPersistent(queuerawimfile_query, true);
    53         if (!queuerawexp_query) {
    54             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    55             return false;
    56         }
     62#if 0
     63    // get the chip_id
     64    long chip_id = psDBLastInsertID(config->dbh);
     65#endif
     66
     67    // populate the chipPendingImfile table from rawImfile based on exp_tag,
     68    // where the coresponding newExp.state entry is set to stop
     69    psString query = pxDataGetCached("chiptool_queuerawimfile.sql");
     70    if (!query) {
     71        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     72        return false;
    5773    }
    5874
    59     // queue the exp
    60     if (!p_psDBRunQuery(config->dbh, queuerawexp_query,
    61                 workdir  ? workdir  : "NULL",
    62                 label    ? label    : "NULL",
    63                 recipe   ? recipe   : "NULL",
    64                 expgroup ? expgroup : "NULL",
    65                 dvodb    ? dvodb    : "NULL",
    66                 exp_tag
    67     )) {
     75    // queue the imfiles for the exp_tag
     76    if (!p_psDBRunQuery(config->dbh, query, exp_tag)) {
    6877        psError(PS_ERR_UNKNOWN, false, "database error");
    6978        return false;
     
    7786    }
    7887
    79     // queue the imfiles for the exp we just queued
    80     if (!p_psDBRunQuery(config->dbh, queuerawimfile_query)) {
     88    // point of no return
     89    if (!psDBCommit(config->dbh)) {
    8190        psError(PS_ERR_UNKNOWN, false, "database error");
    82         return false;
    83     }
    84 
    85     // just to be safe, we should have changed at least one row
    86     if (psDBAffectedRows(config->dbh) < 1) {
    87         psError(PS_ERR_UNKNOWN, false,
    88                 "no rows affected - should have changed at least one row");
    8991        return false;
    9092    }
  • branches/backtrack/ippTools/src/chiptool.c

    r13937 r13990  
    4242static bool unblockMode(pxConfig *config);
    4343
    44 static chipProcessedImfileRow *chipPendingToProcessedImfile(pxConfig *config, chipPendingImfileRow *imfile);
    45 static chipProcessedExpRow *chipPendingToProcessedExp(pxConfig *config, chipPendingExpRow *pendingExp);
    4644static bool chipProcessedCompleteExp(pxConfig *config);
    4745
     
    346344    PS_ASSERT_PTR_NON_NULL(config, false);
    347345
    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 
    510346    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;
     347    // chip_id, ext_tag, class_id are required
     348    psString chip_id = psMetadataLookupStr(&status, config->args, "-chip_id");
     349    if (!status) {
     350        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -chip_id");
     351        return false;
     352    }
     353    if (!chip_id) {
     354        psError(PS_ERR_UNKNOWN, true, "-chip_id is required");
     355        return false;
     356    }
     357
     358    psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");
     359    if (!status) {
     360        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag");
     361        return false;
     362    }
     363    if (!exp_tag) {
     364        psError(PS_ERR_UNKNOWN, true, "-exp_tag is required");
     365        return false;
     366    }
     367
     368    psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
     369    if (!status) {
     370        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
     371        return false;
     372    }
     373    if (!class_id) {
     374        psError(PS_ERR_UNKNOWN, true, "-class_id is required");
     375        return false;
     376    }
     377
    835378    psString uri = psMetadataLookupStr(&status, config->args, "-uri");
    836379    if (!status) {
     
    961504    }
    962505
    963     return chipProcessedImfileRowAlloc(
    964         imfile->chip_id,
    965         imfile->class_id,
     506    if (!psDBTransaction(config->dbh)) {
     507        psError(PS_ERR_UNKNOWN, false, "database error");
     508        return false;
     509    }
     510
     511    chipProcessedImfileRow *imfile = chipProcessedImfileRowAlloc(
     512        (psU64)atoll(chip_id),
     513        exp_tag,
     514        class_id,
    966515        uri,
    967516        bg,
     
    985534        path_base,
    986535        code
    987         );
    988 }
    989 
    990 
    991 static chipProcessedExpRow *chipPendingToProcessedExp(pxConfig *config, chipPendingExpRow *pendingExp)
     536    );
     537    if (!imfile) {
     538        // rollback
     539        if (!psDBRollback(config->dbh)) {
     540            psError(PS_ERR_UNKNOWN, false, "database error");
     541        }
     542        psError(PS_ERR_UNKNOWN, false, "failed to alloc chipProcessedImfileRow object");
     543        return false;
     544    }
     545    if (!chipProcessedImfileInsertObject(config->dbh, imfile)) {
     546        // rollback
     547        if (!psDBRollback(config->dbh)) {
     548            psError(PS_ERR_UNKNOWN, false, "database error");
     549        }
     550        psError(PS_ERR_UNKNOWN, false, "database error");
     551        psFree(imfile);
     552        return false;
     553    }
     554
     555    // XXX I've decided to make the transaction cover the Exp migration as
     556    // well.  Otherwise, if the last imfile in an exp is moved and the exp
     557    // migration fails then the data base is left in a satuation where the exp
     558    // migration can't happen.
     559
     560    if (!chipProcessedCompleteExp(config)) {
     561        // rollback
     562        if (!psDBRollback(config->dbh)) {
     563            psError(PS_ERR_UNKNOWN, false, "database error");
     564        }
     565        psError(PS_ERR_UNKNOWN, false, "database error");
     566        return false;
     567    }
     568
     569    if (!psDBCommit(config->dbh)) {
     570        psError(PS_ERR_UNKNOWN, false, "database error");
     571        return false;
     572    }
     573
     574    return true;
     575}
     576
     577
     578static bool processedimfileMode(pxConfig *config)
    992579{
    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 }
     580    PS_ASSERT_PTR_NON_NULL(config, NULL);
     581
     582    bool status = false;
     583    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
     584    if (!status) {
     585        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
     586        return false;
     587    }
     588
     589    bool faulted = psMetadataLookupU64(&status, config->args, "-faulted");
     590    if (!status) {
     591        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -faulted");
     592        return false;
     593    }
     594
     595    // XXX does this need to be constrained so that it won't return any results
     596    // if a match chipPendingExp hasn't been registered?
     597    psString query = pxDataGet("chiptool_processedimfile.sql");
     598    if (!query) {
     599        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     600        return false;
     601    }
     602
     603    if (config->where) {
     604        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "chipProcessedImfile");
     605        psStringAppend(&query, " AND %s", whereClause);
     606        psFree(whereClause);
     607    }
     608
     609    if (faulted) {
     610        // list only faulted rows
     611        psStringAppend(&query, " %s", "AND chipProcessedImfile.fault != 0");
     612    } else {
     613        // don't list faulted rows
     614        psStringAppend(&query, " %s", "AND chipProcessedImfile.fault = 0");
     615    }
     616
     617    // treat limit == 0 as "no limit"
     618    if (limit) {
     619        psString limitString = psDBGenerateLimitSQL(limit);
     620        psStringAppend(&query, " %s", limitString);
     621        psFree(limitString);
     622    }
     623
     624    if (!p_psDBRunQuery(config->dbh, query)) {
     625        psError(PS_ERR_UNKNOWN, false, "database error");
     626        psFree(query);
     627        return false;
     628    }
     629    psFree(query);
     630
     631    psArray *output = p_psDBFetchResult(config->dbh);
     632    if (!output) {
     633        psError(PS_ERR_UNKNOWN, false, "database error");
     634        return false;
     635    }
     636    if (!psArrayLength(output)) {
     637        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     638        psFree(output);
     639        return true;
     640    }
     641
     642    bool simple = false;
     643    {
     644        bool status = false;
     645        simple = psMetadataLookupBool(&status, config->args, "-simple");
     646        if (!status) {
     647            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
     648            return false;
     649        }
     650    }
     651
     652    if (!convertIdToStr(output)) {
     653        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
     654        psFree(output);
     655        return false;
     656    }
     657
     658    // negative simple so the default is true
     659    if (!ippdbPrintMetadatas(stdout, output, "chipProcessedImfile", !simple)) {
     660        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     661        psFree(output);
     662        return false;
     663    }
     664
     665    psFree(output);
     666
     667    return true;
     668}
     669
     670
     671static bool updateprocessedimfileMode(pxConfig *config)
     672{
     673    PS_ASSERT_PTR_NON_NULL(config, false);
     674
     675    bool status = false;
     676    psS16 code = psMetadataLookupS16(&status, config->args, "-code");
     677    if (!status) {
     678        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -code");
     679        return false;
     680    }
     681    if (code == INT16_MAX) {
     682        psError(PS_ERR_UNKNOWN, true, "-code is required");
     683        return false;
     684    }
     685
     686    if (!pxSetFaultCode(config->dbh, "chipProcessedImfile", config->where, code)) {
     687        psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
     688        return false;
     689    }
     690
     691    return true;
     692}
     693
     694
     695static bool blockMode(pxConfig *config)
     696{
     697    PS_ASSERT_PTR_NON_NULL(config, false);
     698
     699    bool status = false;
     700    psString label = psMetadataLookupStr(&status, config->args, "-label");
     701    if (!status) {
     702        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -label");
     703        return false;
     704    }
     705    if (!label) {
     706        psError(PS_ERR_UNKNOWN, true, "-label is required");
     707        return false;
     708    }
     709
     710    if (!chipMaskInsert(config->dbh, label)) {
     711        psError(PS_ERR_UNKNOWN, false, "database error");
     712        return false;
     713    }
     714
     715    return true;
     716}
     717
     718
     719static bool maskedMode(pxConfig *config)
     720{
     721    PS_ASSERT_PTR_NON_NULL(config, false);
     722
     723    psString query = psStringCopy("SELECT * FROM chipMask");
     724
     725    if (!p_psDBRunQuery(config->dbh, query)) {
     726        psError(PS_ERR_UNKNOWN, false, "database error");
     727        psFree(query);
     728        return false;
     729    }
     730    psFree(query);
     731
     732    psArray *output = p_psDBFetchResult(config->dbh);
     733    if (!output) {
     734        psError(PS_ERR_UNKNOWN, false, "database error");
     735        return false;
     736    }
     737    if (!psArrayLength(output)) {
     738        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     739        psFree(output);
     740        return true;
     741    }
     742
     743    bool simple = false;
     744    {
     745        bool status = false;
     746        simple = psMetadataLookupBool(&status, config->args, "-simple");
     747        if (!status) {
     748            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
     749            return false;
     750        }
     751    }
     752
     753    if (!convertIdToStr(output)) {
     754        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
     755        psFree(output);
     756        return false;
     757    }
     758
     759    // negative simple so the default is true
     760    if (!ippdbPrintMetadatas(stdout, output, "chipMask", !simple)) {
     761        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     762        psFree(output);
     763        return false;
     764    }
     765
     766    psFree(output);
     767
     768    return true;
     769}
     770
     771
     772static bool unblockMode(pxConfig *config)
     773{
     774    PS_ASSERT_PTR_NON_NULL(config, false);
     775
     776    bool status = false;
     777    psString label = psMetadataLookupStr(&status, config->args, "-label");
     778    if (!status) {
     779        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -label");
     780        return false;
     781    }
     782    if (!label) {
     783        psError(PS_ERR_UNKNOWN, true, "-label is required");
     784        return false;
     785    }
     786
     787    char *query = "DELETE FROM chipMask WHERE label = '%s'";
     788
     789    if (!p_psDBRunQuery(config->dbh, query, label)) {
     790        psError(PS_ERR_UNKNOWN, false, "database error");
     791        psFree(query);
     792        return false;
     793    }
     794
     795    return true;
     796}
     797
     798
     799static bool chipProcessedCompleteExp(pxConfig *config)
     800{
     801    PS_ASSERT_PTR_NON_NULL(config, false);
     802
     803    // look for completed chipPendingExp
     804    // migrate them to chipProccessedExp & camPendingExp
     805    psString query = pxDataGet("chiptool_completely_processed_exp.sql");
     806    if (!query) {
     807        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     808        return false;
     809    }
     810
     811    if (!p_psDBRunQuery(config->dbh, query)) {
     812        psError(PS_ERR_UNKNOWN, false, "database error");
     813        psFree(query);
     814        return false;
     815    }
     816    psFree(query);
     817
     818    psArray *output = p_psDBFetchResult(config->dbh);
     819    if (!output) {
     820        psError(PS_ERR_UNKNOWN, false, "database error");
     821        return false;
     822    }
     823    if (!psArrayLength(output)) {
     824        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     825        psFree(output);
     826        return true;
     827    }
     828
     829    // insert into camPendingExp
     830    for (long i = 0; i < psArrayLength(output); i++) {
     831        psMetadata *row = output->data[i];
     832
     833        chipRunRow *chipRun = chipRunObjectFromMetadata(row);
     834
     835        // camQueueChipID() can only be run after the chipProcessedExp entry
     836        // has been inserted.
     837        // queue the chip_id in the camPendingExp table
     838        if (!camQueueChipID(config,
     839                    chipRun->chip_id,
     840                    chipRun->workdir,
     841                    chipRun->label,
     842                    chipRun->reduction,
     843                    chipRun->expgroup,
     844                    chipRun->dvodb
     845        )) {
     846            // rollback
     847            if (!psDBRollback(config->dbh)) {
     848                psError(PS_ERR_UNKNOWN, false, "database error");
     849            }
     850            psError(PS_ERR_UNKNOWN, false, "failed to queue camPendingExp");
     851            psFree(chipRun);
     852            psFree(output);
     853            return false;
     854        }
     855        psFree(chipRun);
     856    }
     857
     858    psFree(output);
     859
     860    return true;
     861}
  • branches/backtrack/ippTools/src/chiptoolConfig.c

    r13937 r13990  
    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);
  • branches/backtrack/ippTools/src/pxdata.h

    r12075 r13990  
    2424
    2525psString pxDataGet(const char *filename);
     26psString pxDataGetCached(const char *filename);
    2627
    2728#endif // PXDATA_H
  • branches/backtrack/ippTools/src/pxtables.c

    r12530 r13990  
    6060    CREATE_TABLE(rawImfileCreateTable);
    6161    CREATE_TABLE(guidePendingExpCreateTable);
    62     CREATE_TABLE(chipPendingExpCreateTable);
     62    CREATE_TABLE(chipRunCreateTable);
    6363    CREATE_TABLE(chipPendingImfileCreateTable);
    64     CREATE_TABLE(chipProcessedExpCreateTable);
    6564    CREATE_TABLE(chipProcessedImfileCreateTable);
    6665    CREATE_TABLE(chipMaskCreateTable);
     
    142141    DROP_TABLE(rawImfileDropTable);
    143142    DROP_TABLE(guidePendingExpDropTable);
    144     DROP_TABLE(chipPendingExpDropTable);
     143    DROP_TABLE(chipRunDropTable);
    145144    DROP_TABLE(chipPendingImfileDropTable);
    146     DROP_TABLE(chipProcessedExpDropTable);
    147145    DROP_TABLE(chipProcessedImfileDropTable);
    148146    DROP_TABLE(chipMaskDropTable);
  • branches/backtrack/ippTools/src/regtool.c

    r13967 r13990  
    620620        }
    621621
    622         // insert an entry into the chipPendingExp table
    623         if (!chipQueueExpTag(config, exp_tag, NULL, NULL, NULL, NULL, NULL)) {
    624             // rollback
    625             if (!psDBRollback(config->dbh)) {
    626                 psError(PS_ERR_UNKNOWN, false, "database error");
    627             }
    628             psError(PS_ERR_UNKNOWN, false, "failed to queue chipPendingExp");
    629             psFree(output);
    630             return false;
    631         }
    632622
    633623        // set the state for the newExp to stop
     
    638628            }
    639629            psError(PS_ERR_UNKNOWN, false, "failed to change newExp.state for exp_tag: %s", exp_tag);
     630            psFree(output);
     631            return false;
     632        }
     633
     634        // insert an entry into the chipPendingExp table
     635        // this can only be run as the newExp's state has been set to stop
     636        if (!chipQueueExpTag(config, exp_tag, NULL, NULL, NULL, NULL, NULL)) {
     637            // rollback
     638            if (!psDBRollback(config->dbh)) {
     639                psError(PS_ERR_UNKNOWN, false, "database error");
     640            }
     641            psError(PS_ERR_UNKNOWN, false, "failed to queue chipPendingExp");
    640642            psFree(output);
    641643            return false;
Note: See TracChangeset for help on using the changeset viewer.