IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 6, 2006, 3:17:44 PM (20 years ago)
Author:
jhoblitt
Message:

remove detool -selectrun, -select, -stackedframe, -normalizedframe, -declaremasterframe, -masterframe, & -master
remove disabled, dead code & newly unused helper functions

File:
1 edited

Legend:

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

    r9369 r9371  
    1818static bool rawMode(pxConfig *config);
    1919static bool toprocessMode(pxConfig *config);
    20 //static bool selectrunMode(pxConfig *config);
    21 //static bool selectMode(pxConfig *config);
    2220static bool addprocessedimfileMode(pxConfig *config);
    2321static bool toprocessedexpMode(pxConfig *config);
     
    2826static bool addstackedMode(pxConfig *config);
    2927static bool stackedMode(pxConfig *config);
    30 static bool stacframeMode(pxConfig *config); // needed?
    3128static bool tonormalizeMode(pxConfig *config);
    3229static bool addnormalizedstatMode(pxConfig *config);
     
    3835static bool toresidMode(pxConfig *config);
    3936static bool addresidimfileMode(pxConfig *config);
    40 static bool normalizedimfileMode(pxConfig *config); // needed?
     37static bool normalizedimfileMode(pxConfig *config);
    4138static bool toresidexpMode(pxConfig *config);
    42 static bool normalizedframeMode(pxConfig *config);// neede?
    4339static bool residimfileMode(pxConfig *config);
    4440static bool addresidexpMode(pxConfig *config);
     
    4844static bool adddetrunsummaryMode(pxConfig *config);
    4945static bool updatedetrunMode(pxConfig *config);
    50 static bool declaremasterframeMode(pxConfig *config); // axe?
    51 static bool masterframeMode(pxConfig *config); // axe?
    52 static bool masterMode(pxConfig *config); // axe?
    5346static bool rerunMode(pxConfig *config);
    5447
     
    5952static detResidExpRow *mdToDetResidExp(pxConfig *config, psMetadata *row);
    6053static detRunSummaryRow *mdToDetRunSummary(pxConfig *config, psMetadata *row);
    61 static psArray *validDetInputClassIds(pxConfig *config, const char *det_id);
    62 static psArray *searchInputImfiles(pxConfig *config, const char *det_id);
     54//static psArray *validDetInputClassIds(pxConfig *config, const char *det_id);
     55//static psArray *searchInputImfiles(pxConfig *config, const char *det_id);
    6356static detInputExpRow *rawDetrenTodetInputExpRow(rawDetrendExpRow *rawExp, psS32 det_id, psS32 iteration);
    6457static psArray *searchRawImfiles(pxConfig *config, psMetadata *where);
     
    8780        MODECASE(DETTOOL_MODE_RAW,              rawMode);
    8881        MODECASE(DETTOOL_MODE_TOPROCESS,        toprocessMode);
    89 //        MODECASE(DETTOOL_MODE_SELECTRUN, selectrunMode);
    90 //        MODECASE(DETTOOL_MODE_SELECT, selectMode);
    9182        MODECASE(DETTOOL_MODE_ADDPROCESSEDIMFILE,addprocessedimfileMode);
    9283        MODECASE(DETTOOL_MODE_TOPROCESSEDEXP,   toprocessedexpMode);
     
    9788        MODECASE(DETTOOL_MODE_ADDSTACKED,       addstackedMode);
    9889        MODECASE(DETTOOL_MODE_STACKED,          stackedMode);
    99         MODECASE(DETTOOL_MODE_STACKEDFRAME,     stacframeMode); // needed?
    10090        MODECASE(DETTOOL_MODE_TONORMALIZE,      tonormalizeMode);
    10191        MODECASE(DETTOOL_MODE_ADDNORMALIZEDSTAT,addnormalizedstatMode);
     
    10999        MODECASE(DETTOOL_MODE_ADDRESIDIMFILE,   addresidimfileMode);
    110100        MODECASE(DETTOOL_MODE_TORESIDEXP,       toresidexpMode);
    111         MODECASE(DETTOOL_MODE_NORMALIZEDFRAME,  normalizedframeMode); // needed?
    112101        MODECASE(DETTOOL_MODE_RESIDIMFILE,      residimfileMode);
    113102        MODECASE(DETTOOL_MODE_ADDRESIDEXP,      addresidexpMode);
     
    117106        MODECASE(DETTOOL_MODE_ADDDETRUNSUMMARY, adddetrunsummaryMode);
    118107        MODECASE(DETTOOL_MODE_UPDATEDETRUN,     updatedetrunMode);
    119         MODECASE(DETTOOL_MODE_DECLAREMASTERFRAME, declaremasterframeMode);
    120         MODECASE(DETTOOL_MODE_MASTERFRAME,      masterframeMode);
    121         MODECASE(DETTOOL_MODE_MASTER,           masterMode);
    122108        MODECASE(DETTOOL_MODE_RERUN,            rerunMode);
    123109        default:
     
    606592    return true;
    607593}
    608 
    609 #if 0
    610 static bool selectrunMode(pxConfig *config)
    611 {
    612     PS_ASSERT_PTR_NON_NULL(config, 0);
    613 
    614     // detselect -camera megacam -type flat -time 2005/1/1
    615     // -inst & -dete_type are required
    616     bool status = false;
    617     psString camera = psMetadataLookupStr(&status, config->args, "-inst");
    618     if (!status) {
    619         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -inst");
    620         return false;
    621     }
    622     if (!camera) {
    623         psError(PS_ERR_UNKNOWN, true, "-inst is required");
    624         return false;
    625     }
    626     psString det_type = psMetadataLookupStr(&status, config->args, "-det_type");
    627     if (!status) {
    628         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_type");
    629         return false;
    630     }
    631     if (!det_type) {
    632         psError(PS_ERR_UNKNOWN, true, "-det_type is required");
    633         return false;
    634     }
    635 
    636     char *query = "SELECT detRun.position, det_type, camera FROM detRun JOIN detInputExp where camera = '%s' and det_type = '%s' LIMIT 1";
    637 
    638     if (!p_psDBRunQuery(config->dbh, query, camera, det_type)) {
    639         psError(PS_ERR_UNKNOWN, false, "database error");
    640         return false;
    641     }
    642 
    643     psArray *result = p_psDBFetchResult(config->dbh);
    644     if (!result) {
    645     }
    646 
    647     // sanity check the result
    648     if (psArrayLength(result) != 1) {
    649     }
    650 
    651     // just a view... doesn't need to be free'd
    652     psMetadata *run = result->data[0];
    653 
    654     psS32 det_id = psMetadataLookupS32(&status, run, "position");
    655     if (!status) {
    656         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for position");
    657         psFree(result);
    658         return false;
    659     }
    660 
    661     psFree(result);
    662 
    663     // FLAT CHIP flat.0000 DONE
    664     fprintf(stdout, "FLAT CHIP %d DONE\n", det_id);
    665 
    666     return true;
    667 }
    668 
    669 static bool selectMode(pxConfig *config)
    670 {
    671     PS_ASSERT_PTR_NON_NULL(config, 0);
    672 
    673     // detselect -select -detID flat.0000 -classID ccd00
    674     // -detID & -classID are required
    675     bool status = false;
    676     psString det_id = psMetadataLookupStr(&status, config->args, "-detID");
    677     if (!status) {
    678         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -detID");
    679         return false;
    680     }
    681     if (!det_id) {
    682         psError(PS_ERR_UNKNOWN, true, "-detID is required");
    683         return false;
    684     }
    685     psString class_id = psMetadataLookupStr(&status, config->args, "-classID");
    686     if (!status) {
    687         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -classID");
    688         return false;
    689     }
    690     if (!class_id) {
    691         psError(PS_ERR_UNKNOWN, true, "-classID is required");
    692         return false;
    693     }
    694 
    695     char *query = "SELECT uri FROM detNormalizedImfile"
    696         " WHERE iteration = (SELECT iteration FROM detMasterFrame"
    697         " WHERE det_id = '%s' ORDER BY iteration DESC LIMIT 1)";
    698 
    699     if (!p_psDBRunQuery(config->dbh, query, det_id)) {
    700         psError(PS_ERR_UNKNOWN, false, "database error");
    701         return false;
    702     }
    703 
    704     psArray *result = p_psDBFetchResult(config->dbh);
    705     if (!result) {
    706     }
    707 
    708     // sanity check the result
    709     if (psArrayLength(result) != 1) {
    710     }
    711 
    712     // just a view... doesn't need to be free'd
    713     psMetadata *run = result->data[0];
    714 
    715     psString uri = psMetadataLookupStr(&status, run, "uri");
    716     if (!status) {
    717         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for uri");
    718         psFree(result);
    719         return false;
    720     }
    721     psFree(result);
    722 
    723     // flat.0000 ccd00 flat.split/flat.00.fits DONE
    724 
    725     fprintf(stdout, "%s %s %s DONE\n", det_id, class_id, uri);
    726 
    727     return true;
    728 }
    729 
    730 #endif
    731594
    732595static detInputExpRow *rawDetrenTodetInputExpRow(rawDetrendExpRow *rawExp, psS32 det_id, psS32 iteration)
     
    15991462}
    16001463
    1601 #if 0
    1602 {
    1603     // find all matching detProcessedImfiles where query should be
    1604     // pre-generated the entry for iteration must be pruned from the default
    1605     // search as processed imfiles aren't 'iterated'
    1606     bool status = false;
    1607     psArray *processedImfiles =  NULL;
    1608 
    1609     if (config->where) {
    1610         psMetadata *prunedWhere = psMetadataCopy(NULL, config->where);
    1611         psMetadataLookupS32(&status, prunedWhere, "iteration");
    1612         if (status) {
    1613             if (!psMetadataRemove(prunedWhere, 0, "iteration")) {
    1614                 psError(PS_ERR_UNKNOWN, false, "failed to remove item iteration");
    1615                 return false;
    1616             }
    1617         }
    1618         processedImfiles =
    1619             detProcessedImfileSelectRowObjects(config->dbh, prunedWhere, 0);
    1620         psFree(prunedWhere);
    1621     } else {
    1622         processedImfiles =
    1623             detProcessedImfileSelectRowObjects(config->dbh, NULL, 0);
    1624     }
    1625     if (!processedImfiles) {
    1626         psError(PS_ERR_UNKNOWN, false, "no detProcessedImfile rows found");
    1627         return false;
    1628     }
    1629 
    1630     // remove detStackedImfiles unless -unmask
    1631     if (!psMetadataLookupBool(&status, config->args, "-unmask")) {
    1632         // detStackedImfiles doesn't have an exp_tag so we have to generate the
    1633         // where query ourselves
    1634         bool status = false;
    1635         psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
    1636         if (!status) {
    1637             psError(PS_ERR_UNKNOWN, false,
    1638                     "failed to lookup value for -det_id");
    1639             return false;
    1640         }
    1641         psS32 iteration = psMetadataLookupS32(&status, config->args, "-iteration");
    1642         if (!status) {
    1643             psError(PS_ERR_UNKNOWN, false,
    1644                     "failed to lookup value for -iteration");
    1645             return false;
    1646         }
    1647         psString class_id = psMetadataLookupStr(&status, config->args,
    1648             "-class_id");
    1649         if (!status) {
    1650             psError(PS_ERR_UNKNOWN, false,
    1651                     "failed to lookup value for -class_id");
    1652             return false;
    1653         }
    1654         psMetadata *where = psMetadataAlloc();
    1655         if (det_id) {
    1656             if (!psMetadataAddS32(where, PS_LIST_TAIL, "det_id", 0, "==",
    1657                     (psS32)atoi(det_id))) {
    1658                 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag");
    1659                 psFree(where);
    1660                 return false;
    1661             }
    1662         }
    1663         // iteration always has a value (and it may be 0 anyways)
    1664         if (!psMetadataAddS32(where, PS_LIST_TAIL, "iteration", 0, "==",
    1665                     iteration)) {
    1666             psError(PS_ERR_UNKNOWN, false, "failed to add item iteration");
    1667             psFree(where);
    1668             return false;
    1669         }
    1670         if (class_id) {
    1671             if (!psMetadataAddStr(where, PS_LIST_TAIL, "class_id", 0, "==",
    1672                         class_id)) {
    1673                 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
    1674                 psFree(where);
    1675                 return false;
    1676             }
    1677         }
    1678 
    1679         psArray *stackedImfiles = NULL;
    1680         if (where->list->n) {
    1681             stackedImfiles = detStackedImfileSelectRowObjects(
    1682                 config->dbh, where, 0);
    1683         } else {
    1684             stackedImfiles = detStackedImfileSelectRowObjects(
    1685                 config->dbh, NULL, 0);
    1686         }
    1687         psFree(where);
    1688         // XXX trace the not found case
    1689         if (stackedImfiles) {
    1690             for (long i = 0; i < psArrayLength(processedImfiles); i++) {
    1691                 for (long j = 0; j < psArrayLength(stackedImfiles); j++) {
    1692                     if ((
    1693                     ((detProcessedImfileRow *)processedImfiles->data[i])->det_id
    1694                     ==
    1695                     ((detStackedImfileRow *)stackedImfiles->data[j])->det_id
    1696                     ) && (strcmp(
    1697                     ((detProcessedImfileRow *)processedImfiles->data[i])->class_id,
    1698                     ((detStackedImfileRow *)stackedImfiles->data[j])->class_id)
    1699                     == 0)) {
    1700                         // remove the rawImfiles from the list
    1701                         psArrayRemove(processedImfiles, processedImfiles->data[i]);
    1702                         i--;
    1703                         break;
    1704                     }
    1705                 }
    1706             }
    1707             psFree(stackedImfiles);
    1708         }
    1709     }
    1710 
    1711     // if -chip is specified only return results for complete 'chip' sets.
    1712     // I.e., when all of the same class_id for the input exposures have been
    1713     // processed.  This should be done after detStackedImfiles are masked so we
    1714     // don't have to do this check unless we have to.
    1715     if (psMetadataLookupBool(&status, config->args, "-chip")) {
    1716         // lookup det_id
    1717         bool status = false;
    1718         psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
    1719         if (!status) {
    1720             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");
    1721             return false;
    1722         }
    1723         // get a count of raw imfiles per class_id
    1724         psArray *rawImfiles = searchInputImfiles(config, det_id);
    1725         if (!rawImfiles) {
    1726             psError(PS_ERR_UNKNOWN, false, "no rawImfile row founds");
    1727             return false;
    1728         }
    1729 
    1730         psHash *raw_counts = psHashAlloc(psArrayLength(rawImfiles));
    1731         for (long i = 0; i < psArrayLength(rawImfiles); i++) {
    1732             // check to see if the key already exists
    1733             psU32 *count = psHashLookup(
    1734                 raw_counts,
    1735                 ((rawImfileRow *)rawImfiles->data[i])->class_id
    1736             );
    1737             if (count) {
    1738                 ++(*count);
    1739             } else {
    1740                 psU32 *count = psAlloc(sizeof(psU32));
    1741                 *count = 1;
    1742                 psHashAdd(raw_counts,
    1743                     ((rawImfileRow *)rawImfiles->data[i])->class_id, count
    1744                 );
    1745                 psFree(count);
    1746             }
    1747         }
    1748 
    1749         psFree(rawImfiles);
    1750 
    1751 #if 0
    1752         {
    1753             printf("raw counts:\n");
    1754             psList *keys  = psHashKeyList(raw_counts);
    1755             psListIterator *iter = psListIteratorAlloc(keys, 0, false);
    1756             char *key = NULL;
    1757             while ((key = psListGetAndIncrement(iter))) {
    1758                 psU32 *count = psHashLookup(raw_counts, key);
    1759                 printf("%s: %d\n", key, *count);
    1760             }
    1761             psFree(iter);
    1762             psFree(keys);
    1763         }
    1764 #endif
    1765 
    1766         // get a count of processed imfiles per class_id
    1767         psHash *processed_counts = psHashAlloc(psArrayLength(processedImfiles));
    1768         for (long i = 0; i < psArrayLength(processedImfiles); i++) {
    1769             // check to see if the key already exists
    1770             psU32 *count = psHashLookup(
    1771                 processed_counts,
    1772                 ((detProcessedImfileRow *)processedImfiles->data[i])->class_id
    1773             );
    1774             if (count) {
    1775                 ++(*count);
    1776             } else {
    1777                 psU32 *count = psAlloc(sizeof(psU32));
    1778                 *count = 1;
    1779                 psHashAdd(processed_counts,
    1780             ((detProcessedImfileRow *)processedImfiles->data[i])->class_id,
    1781                 count
    1782                 );
    1783                 psFree(count);
    1784             }
    1785         }
    1786 #if 0
    1787         {
    1788             printf("processed counts:\n");
    1789             psList *keys  = psHashKeyList(processed_counts);
    1790             psListIterator *iter = psListIteratorAlloc(keys, 0, false);
    1791             char *key = NULL;
    1792             while ((key = psListGetAndIncrement(iter))) {
    1793                 psU32 *count = psHashLookup(processed_counts, key);
    1794                 printf("%s: %d\n", key, *count);
    1795             }
    1796             psFree(iter);
    1797             psFree(keys);
    1798         }
    1799 #endif
    1800 
    1801         // compare the two class_id counts for any mismatched counts
    1802         psList *keys  = psHashKeyList(processed_counts);
    1803         psListIterator *iter = psListIteratorAlloc(keys, 0, false);
    1804         char *key = NULL;
    1805         while ((key = psListGetAndIncrement(iter))) {
    1806             psU32 *pcount = psHashLookup(processed_counts, key);
    1807             psU32 *rcount = psHashLookup(raw_counts, key);
    1808             if (*pcount != *rcount) {
    1809                 psError(PS_ERR_UNKNOWN, false,
    1810                     "class_id %s count mismatch - processed: %u raw: %u ",
    1811                     key, *pcount, *rcount
    1812                 );
    1813                 // iterate through processedImfiles and remove *ALL* enteries
    1814                 // with the mismatched class_id
    1815                 for (long i = 0; i < psArrayLength(processedImfiles); i++) {
    1816                     if (((detProcessedImfileRow *)processedImfiles->data[i])->class_id) {
    1817                         psArrayRemove(processedImfiles, processedImfiles->data[i]);
    1818                         --i;
    1819                     }
    1820                 }
    1821 
    1822             }
    1823         }
    1824         psFree(iter);
    1825         psFree(keys);
    1826 
    1827         psFree(raw_counts);
    1828         psFree(processed_counts);
    1829     }
    1830 
    1831     bool simple = false;
    1832     {
    1833         bool status = false;
    1834         simple = psMetadataLookupBool(&status, config->args, "-simple");
    1835         if (!status) {
    1836             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    1837             return false;
    1838         }
    1839     }
    1840 
    1841     // print imfile list
    1842     if (processedImfiles->n) {
    1843         // negative simple so the default is true
    1844         if (!detProcessedImfilePrintObjects(stdout, processedImfiles, !simple)) {
    1845             psError(PS_ERR_UNKNOWN, false, "failed to print array");
    1846             psFree(processedImfiles);
    1847             return false;
    1848         }
    1849     }
    1850 
    1851     psFree(processedImfiles);
    1852 
    1853     return true;
    1854 }
    1855 #endif
    1856 
    18571464static bool addstackedMode(pxConfig *config)
    18581465{
     
    20521659
    20531660    psFree(output);
    2054 
    2055     return true;
    2056 }
    2057 
    2058 static bool stacframeMode(pxConfig *config)
    2059 {
    2060     PS_ASSERT_PTR_NON_NULL(config, false);
    2061 
    2062     // XXX det_id is requried as a simplification
    2063     bool status = false;
    2064     psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
    2065     if (!status) {
    2066         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");
    2067         return false;
    2068     }
    2069     if (!det_id) {
    2070         psError(PS_ERR_UNKNOWN, true, "-det_id is required");
    2071         return false;
    2072     }
    2073 
    2074     // find all detStackedImfile for det_id
    2075     psArray *stackedImfiles =
    2076         detStackedImfileSelectRowObjects(config->dbh, config->where, 0);
    2077     if (!stackedImfiles) {
    2078         psError(PS_ERR_UNKNOWN, false, "no detStackedImfile rows found");
    2079         return NULL;
    2080     }
    2081 
    2082     // find all class_ids for the det_id's associated detInputExps
    2083     psArray *valid_class_ids = validDetInputClassIds(config, det_id);
    2084     if (!valid_class_ids) {
    2085         psError(PS_ERR_UNKNOWN, false, "no detInputExp imfile class_ids found");
    2086         return false;
    2087     }
    2088 
    2089     // check class_ids for validity
    2090     for (long i = 0; i < psArrayLength(stackedImfiles); i++) {
    2091         bool valid = false;
    2092         for (long j = 0; j < psArrayLength(valid_class_ids); j++) {
    2093             if (strcmp(((detStackedImfileRow *)stackedImfiles->data[i])->class_id,
    2094                    (char *)valid_class_ids->data[j]) == 0) {
    2095                 valid = true;
    2096                 if (!psArrayRemove(valid_class_ids, valid_class_ids->data[j])) {
    2097                     psError(PS_ERR_UNKNOWN, false, "psArrayRemove() failed");
    2098                     psFree(stackedImfiles);
    2099                     psFree(valid_class_ids);
    2100                     return false;
    2101                 }
    2102                 j--; // must update loop index
    2103             }
    2104         }
    2105         if (!valid) {
    2106             psError(PS_ERR_UNKNOWN, true,
    2107                 "class_id %s does not corespond to a detInputExp",
    2108                 ((detStackedImfileRow *)stackedImfiles->data[i])->class_id);
    2109             psFree(stackedImfiles);
    2110             psFree(valid_class_ids);
    2111             return false;
    2112         }
    2113     }
    2114 
    2115     // check for residual (unmatched) input imfile class_ids
    2116     if (psArrayLength(valid_class_ids)) {
    2117         psError(PS_ERR_UNKNOWN, true, "det_id frame is missing %ld class_ids",
    2118             psArrayLength(valid_class_ids));
    2119         psFree(valid_class_ids);
    2120         psFree(stackedImfiles);
    2121         return false;
    2122     }
    2123     psFree(valid_class_ids);
    2124 
    2125     bool simple = false;
    2126     {
    2127         bool status = false;
    2128         simple = psMetadataLookupBool(&status, config->args, "-simple");
    2129         if (!status) {
    2130             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    2131             return false;
    2132         }
    2133     }
    2134 
    2135     // negative simple so the default is true
    2136     if (stackedImfiles->n) {
    2137         if (!detStackedImfilePrintObjects(stdout, stackedImfiles, !simple)) {
    2138             psError(PS_ERR_UNKNOWN, false, "failed to print array");
    2139             psFree(stackedImfiles);
    2140             return false;
    2141         }
    2142     }
    2143 
    2144     psFree(stackedImfiles);
    21451661
    21461662    return true;
     
    24421958}
    24431959
     1960#if 0
     1961// XXX this function was left in commented as this method may be useful in the
     1962// future
    24441963static psArray *validDetInputClassIds(pxConfig *config, const char *det_id)
    24451964{
     
    25282047    return rawImfiles;
    25292048}
     2049#endif
    25302050
    25312051static bool addnormalizedimfileMode(pxConfig *config)
     
    31822702
    31832703    psFree(output);
    3184 
    3185     return true;
    3186 }
    3187 
    3188 
    3189 static bool normalizedframeMode(pxConfig *config)
    3190 {
    3191     PS_ASSERT_PTR_NON_NULL(config, false);
    3192 
    3193     // XXX det_id is requried as a simplification
    3194     bool status = false;
    3195     psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
    3196     if (!status) {
    3197         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");
    3198         return false;
    3199     }
    3200     if (!det_id) {
    3201         psError(PS_ERR_UNKNOWN, true, "-det_id is required");
    3202         return false;
    3203     }
    3204 
    3205     // find all detNormalizedIImfile for det_id
    3206     psArray *masterImfiles =
    3207         detNormalizedImfileSelectRowObjects(config->dbh, config->where, 0);
    3208     if (!masterImfiles) {
    3209         psError(PS_ERR_UNKNOWN, false, "no detNormalizedImfile rows found");
    3210         return false;
    3211     }
    3212 
    3213     // find all input class_ids
    3214     psArray *valid_class_ids = validDetInputClassIds(config, det_id);
    3215     if (!valid_class_ids) {
    3216         psError(PS_ERR_UNKNOWN, false, "no detInputExp imfile class_ids found");
    3217         return false;
    3218     }
    3219 
    3220     // check class_ids for validity
    3221     for (long i = 0; i < psArrayLength(masterImfiles); i++) {
    3222         bool valid = false;
    3223         for (long j = 0; j < psArrayLength(valid_class_ids); j++) {
    3224             if (strcmp(((detNormalizedImfileRow *)masterImfiles->data[i])->class_id,
    3225                    (char *)valid_class_ids->data[j]) == 0) {
    3226                 valid = true;
    3227                 if (!psArrayRemove(valid_class_ids, valid_class_ids->data[j])) {
    3228                     psError(PS_ERR_UNKNOWN, false, "psArrayRemove() failed");
    3229                     psFree(masterImfiles);
    3230                     psFree(valid_class_ids);
    3231                     return false;
    3232                 }
    3233                 j--; // must update loop index
    3234             }
    3235         }
    3236         if (!valid) {
    3237             psError(PS_ERR_UNKNOWN, true,
    3238         "class_id %s does not corespond to a detInputExp",
    3239             ((detNormalizedImfileRow *)masterImfiles->data[i])->class_id);
    3240             psFree(masterImfiles);
    3241             psFree(valid_class_ids);
    3242             return false;
    3243         }
    3244     }
    3245 
    3246     // if we nade it this far we must have a complete frame
    3247 
    3248     bool simple = false;
    3249     {
    3250         bool status = false;
    3251         simple = psMetadataLookupBool(&status, config->args, "-simple");
    3252         if (!status) {
    3253             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    3254             return false;
    3255         }
    3256     }
    3257 
    3258     // negative simple so the default is true
    3259     if (masterImfiles->n) {
    3260         if (!detNormalizedImfilePrintObjects(stdout, masterImfiles, !simple)) {
    3261             psError(PS_ERR_UNKNOWN, false, "failed to print array");
    3262             psFree(masterImfiles);
    3263             return false;
    3264         }
    3265     }
    3266 
    3267     psFree(masterImfiles);
    32682704
    32692705    return true;
     
    47194155}
    47204156
    4721 static bool declaremasterframeMode(pxConfig *config)
    4722 {
    4723     PS_ASSERT_PTR_NON_NULL(config, false);
    4724 
    4725     // det_id & iteration are required
    4726     bool status = false;
    4727     psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
    4728     if (!status) {
    4729         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");
    4730         return false;
    4731     }
    4732     if (!det_id) {
    4733         psError(PS_ERR_UNKNOWN, true, "-det_id is required");
    4734         return false;
    4735     }
    4736 
    4737     // iteration has a default value
    4738     psS32 iteration = psMetadataLookupS32(&status, config->args, "-iteration");
    4739     if (!status) {
    4740         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -iteration");
    4741         return false;
    4742     }
    4743     // comment is optional
    4744     psString comment = psMetadataLookupStr(&status, config->args, "-comment");
    4745     if (!status) {
    4746         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -comment");
    4747         return false;
    4748     }
    4749 
    4750     // create a new detMasterFrame row and insert it
    4751     detMasterFrameRow *masterFrame = detMasterFrameRowAlloc(
    4752                 (psS32)atol(det_id),
    4753                 iteration,
    4754                 comment // may be NULL
    4755             );
    4756 
    4757     if (!detMasterFrameInsertObject(config->dbh, masterFrame)) {
    4758         psError(PS_ERR_UNKNOWN, false, "database error");
    4759         psFree(masterFrame);
    4760         return false;
    4761     }
    4762 
    4763     psFree(masterFrame);
    4764 
    4765     return true;
    4766 }
    4767 
    4768 static bool masterframeMode(pxConfig *config)
    4769 {
    4770     PS_ASSERT_PTR_NON_NULL(config, false);
    4771 
    4772     // no options are required... use the default where statement
    4773     psArray *masterFrames= detMasterFrameSelectRowObjects(config->dbh,
    4774             config->where, 0);
    4775     if (!masterFrames) {
    4776         psError(PS_ERR_UNKNOWN, false, "no detMasterFrame rows found");
    4777         return false;
    4778     }
    4779 
    4780     bool simple = false;
    4781     {
    4782         bool status = false;
    4783         simple = psMetadataLookupBool(&status, config->args, "-simple");
    4784         if (!status) {
    4785             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    4786             return false;
    4787         }
    4788     }
    4789 
    4790     // negative simple so the default is true
    4791     if (masterFrames->n) {
    4792         if (!detMasterFramePrintObjects(stdout, masterFrames, !simple)) {
    4793             psError(PS_ERR_UNKNOWN, false, "failed to print array");
    4794             psFree(masterFrames);
    4795             return false;
    4796         }
    4797     }
    4798 
    4799     psFree(masterFrames);
    4800 
    4801     return true;
    4802 }
    4803 
    4804 static bool masterMode(pxConfig *config)
    4805 {
    4806     PS_ASSERT_PTR_NON_NULL(config, false);
    4807 
    4808     // join detMasterFrame & detNormalizedImfile tables
    4809     // no options are required... use the default where statement
    4810     psArray *normalizedImfiles = detNormalizedImfileSelectRowObjects(
    4811             config->dbh, config->where, 0);
    4812     if (!normalizedImfiles) {
    4813         psError(PS_ERR_UNKNOWN, false, "no detNormalizedImfile rows found");
    4814         return false;
    4815     }
    4816 
    4817     bool simple = false;
    4818     {
    4819         bool status = false;
    4820         simple = psMetadataLookupBool(&status, config->args, "-simple");
    4821         if (!status) {
    4822             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    4823             return false;
    4824         }
    4825     }
    4826 
    4827     // negative simple so the default is true
    4828     if (normalizedImfiles->n) {
    4829         if (!detNormalizedImfilePrintObjects(stdout, normalizedImfiles, !simple)) {
    4830             psError(PS_ERR_UNKNOWN, false, "failed to print array");
    4831             psFree(normalizedImfiles);
    4832             return false;
    4833         }
    4834     }
    4835 
    4836     psFree(normalizedImfiles);
    4837 
    4838     return true;
    4839 }
    4840 
    4841 
    48424157static bool rerunMode(pxConfig *config)
    48434158{
Note: See TracChangeset for help on using the changeset viewer.