IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 8, 2009, 5:09:53 PM (17 years ago)
Author:
eugene
Message:

updates to the addstar stage; modify flatcorr to interact correctly with the addstar stage

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/addtool.c

    r25789 r25816  
    4040static bool maskedMode(pxConfig *config);
    4141static bool unblockMode(pxConfig *config);
    42 static bool pendingcleanuprunMode(pxConfig *config);
    43 static bool pendingcleanupexpMode(pxConfig *config);
    44 static bool donecleanupMode(pxConfig *config);
    45 static bool exportrunMode(pxConfig *config);
    46 static bool importrunMode(pxConfig *config);
    4742
    4843# define MODECASE(caseName, func) \
     
    7469        MODECASE(ADDTOOL_MODE_MASKED,               maskedMode);
    7570        MODECASE(ADDTOOL_MODE_UNBLOCK,              unblockMode);
    76         MODECASE(ADDTOOL_MODE_PENDINGCLEANUPRUN,    pendingcleanuprunMode);
    77         MODECASE(ADDTOOL_MODE_PENDINGCLEANUPEXP,    pendingcleanupexpMode);
    78         MODECASE(ADDTOOL_MODE_DONECLEANUP,          donecleanupMode);
    79         MODECASE(ADDTOOL_MODE_EXPORTRUN,            exportrunMode);
    80         MODECASE(ADDTOOL_MODE_IMPORTRUN,            importrunMode);
    8171        default:
    8272            psAbort("invalid option (this should not happen)");
     
    118108    }
    119109
    120     PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", false, false);
    121     PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
    122     PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false);
    123     PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", false, false);
    124     PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
    125     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     110    PXOPT_LOOKUP_STR(workdir,     config->args, "-set_workdir", false, false);
     111    PXOPT_LOOKUP_STR(dvodb,       config->args, "-set_dvodb", false, false);
     112    PXOPT_LOOKUP_STR(label,       config->args, "-set_label", false, false);
     113    PXOPT_LOOKUP_STR(reduction,   config->args, "-set_reduction", false, false);
     114    PXOPT_LOOKUP_BOOL(image_only, config->args, "-image_only", false);
     115    PXOPT_LOOKUP_BOOL(pretend,    config->args, "-pretend", false);
     116    PXOPT_LOOKUP_BOOL(simple,     config->args, "-simple", false);
    126117
    127118    // find the cam_id of all the exposures that we want to queue up.
     
    170161    }
    171162
     163    // loop over our list of camRun rows to check the supplied and selected dvodb and workdir values:
     164    for (long i = 0; i < psArrayLength(output); i++) {
     165        psMetadata *md = output->data[i];
     166
     167        camRunRow *row = camRunObjectFromMetadata(md);
     168        if (!row) {
     169            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
     170            psFree(output);
     171            return false;
     172        }
     173
     174        if (!dvodb && !row->dvodb) {
     175            psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, cam_id %" PRId64, row->label, row->cam_id);
     176            psFree(output);
     177            return false;
     178        }
     179        if (!workdir && !row->workdir) {
     180            psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, cam_id %" PRId64, row->label, row->cam_id);
     181            psFree(output);
     182            return false;
     183        }
     184
     185        psFree(row);
     186    }
     187
    172188    // start a transaction so we don't end up with an exp without any associted
    173189    // imfiles
     
    183199    // old values in place (i.e., passing the values through).
    184200
    185 
    186     // loop over our list of addRun rows
     201    // loop over our list of camRun rows
    187202    for (long i = 0; i < psArrayLength(output); i++) {
    188203        psMetadata *md = output->data[i];
     
    190205        camRunRow *row = camRunObjectFromMetadata(md);
    191206        if (!row) {
    192             psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into addRun");
     207            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
    193208            psFree(output);
    194209            return false;
     
    199214                               row->cam_id,
    200215                               workdir     ? workdir   : row->workdir,
     216                               reduction   ? reduction : row->reduction,
    201217                               label       ? label     : row->label,
    202                                "RECIPE",
    203                                dvodb       ? dvodb     : row->dvodb
    204                                
     218                               dvodb       ? dvodb     : row->dvodb,
     219                               image_only
    205220        )) {
    206221            if (!psDBRollback(config->dbh)) {
     
    234249    PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id", "==");
    235250    pxcamGetSearchArgs (config, where); // most search arguments based on camera
    236 
    237251    PXOPT_COPY_STR(config->args, where, "-label",     "addRun.label", "==");
    238252    PXOPT_COPY_STR(config->args, where, "-state",     "addRun.state", "==");
     
    287301    pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "==");
    288302    PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "==");
    289 
    290303    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    291304    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     
    349362
    350363    // optional
    351     PXOPT_LOOKUP_F32(dtime_addstar, config->args,  "-dtime_addstar", false, false);
    352     PXOPT_LOOKUP_S32(n_stars, config->args,        "-n_stars", false, false);
    353     PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false);
    354     PXOPT_LOOKUP_S64(magicked, config->args, "-magicked", false, false);
     364    PXOPT_LOOKUP_STR(path_base,     config->args, "-path_base", false, false);
     365    PXOPT_LOOKUP_F32(dtime_addstar, config->args, "-dtime_addstar", false, false);
     366    PXOPT_LOOKUP_S16(fault,         config->args, "-fault", false, false);
    355367
    356368    // generate restrictions
     
    401413        pendingRow->add_id,
    402414        dtime_addstar,
    403         n_stars,
    404415        path_base,
    405         0
     416        fault
    406417        );
    407418
     
    418429
    419430    // since there is only one exp per 'new' set addRun.state = 'full'
    420     if (!pxaddRunSetState(config, row->add_id, "full", magicked)) {
     431    if (!pxaddRunSetState(config, row->add_id, "full")) {
    421432        psError(PS_ERR_UNKNOWN, false, "failed to change addRun.state for add_id: %" PRId64, row->add_id);
    422433        psFree(row);
     
    439450{
    440451    PS_ASSERT_PTR_NON_NULL(config, false);
    441 
    442     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    443     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    444     PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
    445452
    446453    // generate restrictions
     
    451458    pxAddLabelSearchArgs (config, where, "-label",    "addRun.label",     "==");
    452459    PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "==");
     460
     461    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     462    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     463    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
    453464
    454465    if (!psListLength(where->list) &&
     
    628639    PS_ASSERT_PTR_NON_NULL(config, false);
    629640
    630     PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
    631 
    632641    psMetadata *where = psMetadataAlloc();
    633642    PXOPT_COPY_S64(config->args, where, "-add_id",   "add_id",   "==");
    634643    PXOPT_COPY_S64(config->args, where, "-cam_id",  "cam_id",  "==");
     644    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
    635645
    636646    if (!pxSetFaultCode(config->dbh, "addProcessedExp", where, fault)) {
     
    713723    return true;
    714724}
    715 
    716 static bool pendingcleanuprunMode(pxConfig *config)
    717 {
    718     PS_ASSERT_PTR_NON_NULL(config, NULL);
    719 
    720     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    721     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    722 
    723     psMetadata *where = psMetadataAlloc();
    724     pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "==");
    725 
    726     psString query = pxDataGet("addtool_pendingcleanuprun.sql");
    727     if (!query) {
    728         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    729         return false;
    730     }
    731 
    732     if (where && psListLength(where->list)) {
    733         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    734         psStringAppend(&query, " AND %s", whereClause);
    735         psFree(whereClause);
    736     }
    737     psFree(where);
    738 
    739     // treat limit == 0 as "no limit"
    740     if (limit) {
    741         psString limitString = psDBGenerateLimitSQL(limit);
    742         psStringAppend(&query, " %s", limitString);
    743         psFree(limitString);
    744     }
    745 
    746     if (!p_psDBRunQuery(config->dbh, query)) {
    747         psError(PS_ERR_UNKNOWN, false, "database error");
    748         psFree(query);
    749         return false;
    750     }
    751     psFree(query);
    752 
    753     psArray *output = p_psDBFetchResult(config->dbh);
    754     if (!output) {
    755         psError(PS_ERR_UNKNOWN, false, "database error");
    756         return false;
    757     }
    758     if (!psArrayLength(output)) {
    759         psTrace("addtool", PS_LOG_INFO, "no rows found");
    760         psFree(output);
    761         return true;
    762     }
    763 
    764     // negative simple so the default is true
    765     if (!ippdbPrintMetadatas(stdout, output, "addPendingCleanupRun", !simple)) {
    766         psError(PS_ERR_UNKNOWN, false, "failed to print array");
    767         psFree(output);
    768         return false;
    769     }
    770 
    771     psFree(output);
    772 
    773     return true;
    774 }
    775 
    776 
    777 static bool pendingcleanupexpMode(pxConfig *config)
    778 {
    779     PS_ASSERT_PTR_NON_NULL(config, NULL);
    780 
    781     PXOPT_LOOKUP_S64(add_id, config->args, "-add_id", false, false);
    782     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    783     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    784 
    785     psMetadata *where = psMetadataAlloc();
    786     if (add_id) {
    787         PXOPT_COPY_S64(config->args, where, "-add_id", "add_id", "==");
    788     }
    789     pxAddLabelSearchArgs (config, where, "-label", "label", "==");
    790 
    791     psString query = pxDataGet("addtool_pendingcleanupexp.sql");
    792     if (!query) {
    793         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    794         return false;
    795     }
    796 
    797     if (where && psListLength(where->list)) {
    798         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    799         psStringAppend(&query, " AND %s", whereClause);
    800         psFree(whereClause);
    801     }
    802     psFree(where);
    803 
    804     // treat limit == 0 as "no limit"
    805     if (limit) {
    806         psString limitString = psDBGenerateLimitSQL(limit);
    807         psStringAppend(&query, " %s", limitString);
    808         psFree(limitString);
    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     // negative simple so the default is true
    830     if (!ippdbPrintMetadatas(stdout, output, "addPendingCleanupExp", !simple)) {
    831         psError(PS_ERR_UNKNOWN, false, "failed to print array");
    832         psFree(output);
    833         return false;
    834     }
    835 
    836     psFree(output);
    837 
    838     return true;
    839 }
    840 
    841 
    842 static bool donecleanupMode(pxConfig *config)
    843 {
    844     PS_ASSERT_PTR_NON_NULL(config, NULL);
    845 
    846     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    847     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    848 
    849     psMetadata *where = psMetadataAlloc();
    850     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
    851 
    852     psString query = pxDataGet("addtool_donecleanup.sql");
    853     if (!query) {
    854         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    855         return false;
    856     }
    857 
    858     if (where && psListLength(where->list)) {
    859         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    860         psStringAppend(&query, " AND %s", whereClause);
    861         psFree(whereClause);
    862     }
    863     psFree(where);
    864 
    865     // treat limit == 0 as "no limit"
    866     if (limit) {
    867         psString limitString = psDBGenerateLimitSQL(limit);
    868         psStringAppend(&query, " %s", limitString);
    869         psFree(limitString);
    870     }
    871 
    872     if (!p_psDBRunQuery(config->dbh, query)) {
    873         psError(PS_ERR_UNKNOWN, false, "database error");
    874         psFree(query);
    875         return false;
    876     }
    877     psFree(query);
    878 
    879     psArray *output = p_psDBFetchResult(config->dbh);
    880     if (!output) {
    881         psError(PS_ERR_UNKNOWN, false, "database error");
    882         return false;
    883     }
    884     if (!psArrayLength(output)) {
    885         psTrace("addtool", PS_LOG_INFO, "no rows found");
    886         psFree(output);
    887         return true;
    888     }
    889 
    890     // negative simple so the default is true
    891     if (!ippdbPrintMetadatas(stdout, output, "addDoneCleanup", !simple)) {
    892         psError(PS_ERR_UNKNOWN, false, "failed to print array");
    893         psFree(output);
    894         return false;
    895     }
    896 
    897     psFree(output);
    898 
    899     return true;
    900 }
    901 
    902 bool exportrunMode(pxConfig *config)
    903 {
    904   typedef struct ExportTable {
    905     char tableName[80];
    906     char sqlFilename[80];
    907   } ExportTable;
    908 
    909   int numExportTables = 2;
    910 
    911   PS_ASSERT_PTR_NON_NULL(config, NULL);
    912 
    913   PXOPT_LOOKUP_S64(det_id, config->args, "-add_id", true,  false);
    914   PXOPT_LOOKUP_STR(outfile, config->args, "-outfile", true,  false);
    915   PXOPT_LOOKUP_U64(limit,   config->args, "-limit",   false, false);
    916   PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false);
    917 
    918   FILE *f = fopen (outfile, "w");
    919   if (f == NULL) {
    920     psError(PS_ERR_UNKNOWN, false, "failed to open output file");
    921     return false;
    922   }
    923 
    924   psMetadata *where = psMetadataAlloc();
    925   PXOPT_COPY_S64(config->args, where, "-add_id", "add_id", "==");
    926 
    927   ExportTable tables [] = {
    928     {"addRun", "addtool_export_run.sql"},
    929     {"addProcessedExp", "addtool_export_processed_exp.sql"},
    930   };
    931 
    932   for (int i=0; i < numExportTables; i++) {
    933     psString query = pxDataGet(tables[i].sqlFilename);
    934     if (!query) {
    935       psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    936       return false;
    937     }
    938 
    939     if (where && psListLength(where->list)) {
    940       psString whereClause = psDBGenerateWhereSQL(where, NULL);
    941       psStringAppend(&query, " %s", whereClause);
    942       psFree(whereClause);
    943     }
    944 
    945     // treat limit == 0 as "no limit"
    946     if (limit) {
    947       psString limitString = psDBGenerateLimitSQL(limit);
    948       psStringAppend(&query, " %s", limitString);
    949       psFree(limitString);
    950     }
    951 
    952     if (!p_psDBRunQuery(config->dbh, query)) {
    953       psError(PS_ERR_UNKNOWN, false, "database error");
    954       psFree(query);
    955       return false;
    956     }
    957     psFree(query);
    958 
    959     psArray *output = p_psDBFetchResult(config->dbh);
    960     if (!output) {
    961       psError(PS_ERR_UNKNOWN, false, "database error");
    962       return false;
    963     }
    964     if (!psArrayLength(output)) {
    965       psError(PS_ERR_UNKNOWN, true, "no rows found");
    966       psFree(output);
    967       return false;
    968     }
    969 
    970     if (clean) {
    971         if (!strcmp(tables[i].tableName, "addRun")) {
    972             if (!pxSetStateCleaned("addRun", "state", output)) {
    973                 psFree(output);
    974                 psError(PS_ERR_UNKNOWN, false, "pxSetStateClean failed for table %s",  tables[i].tableName);
    975                 return false;
    976             }
    977         }
    978     }
    979 
    980     // we must write the export table in non-simple (true) format
    981     if (!ippdbPrintMetadatas(f, output, tables[i].tableName, true)) {
    982       psError(PS_ERR_UNKNOWN, false, "failed to print array");
    983       psFree(output);
    984       return false;
    985     }
    986     psFree(output);
    987   }
    988 
    989   fclose (f);
    990 
    991   return true;
    992 }
    993 
    994 bool importrunMode(pxConfig *config)
    995 {
    996   unsigned int nFail;
    997 
    998   PS_ASSERT_PTR_NON_NULL(config, NULL);
    999 
    1000   PXOPT_LOOKUP_STR(infile, config->args, "-infile", true,  false);
    1001 
    1002   psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);
    1003 
    1004   fprintf (stdout, "---- input ----\n");
    1005   psMetadataPrint (stderr, input, 1);
    1006 
    1007   psMetadataItem *item = psMetadataLookup (input, "addRun");
    1008   psAssert (item, "entry not in input?");
    1009   psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
    1010 
    1011   psMetadataItem *entry = psListGet (item->data.list, 0);
    1012   assert (entry);
    1013   assert (entry->type == PS_DATA_METADATA);
    1014   addRunRow *addRun = addRunObjectFromMetadata (entry->data.md);
    1015   addRunInsertObject (config->dbh, addRun);
    1016 
    1017   // fprintf (stdout, "---- add run ----\n");
    1018   // psMetadataPrint (stderr, entry->data.md, 1);
    1019 
    1020   item = psMetadataLookup (input, "addProcessedExp");
    1021   psAssert (item, "entry not in input?");
    1022   psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
    1023 
    1024   for (int i = 0; i < item->data.list->n; i++) {
    1025     psMetadataItem *entry = psListGet (item->data.list, i);
    1026     assert (entry);
    1027     assert (entry->type == PS_DATA_METADATA);
    1028     addProcessedExpRow *addProcessedExp = addProcessedExpObjectFromMetadata (entry->data.md);
    1029     addProcessedExpInsertObject (config->dbh, addProcessedExp);
    1030 
    1031     // fprintf (stdout, "---- row %d ----\n", i);
    1032     // psMetadataPrint (stderr, entry->data.md, 1);
    1033   }
    1034 
    1035   return true;
    1036 }
Note: See TracChangeset for help on using the changeset viewer.