IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

merge backtrack branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.