Changeset 26927 for trunk/ippTools/src/difftool.c
- Timestamp:
- Feb 12, 2010, 12:21:48 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/difftool.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/difftool.c
r26909 r26927 43 43 static bool definewarpstackMode(pxConfig *config); 44 44 static bool definewarpwarpMode(pxConfig *config); 45 static bool definestackstackMode(pxConfig *config); 45 46 static bool pendingcleanuprunMode(pxConfig *config); 46 47 static bool pendingcleanupskyfileMode(pxConfig *config); … … 89 90 MODECASE(DIFFTOOL_MODE_DEFINEWARPSTACK, definewarpstackMode); 90 91 MODECASE(DIFFTOOL_MODE_DEFINEWARPWARP, definewarpwarpMode); 92 MODECASE(DIFFTOOL_MODE_DEFINESTACKSTACK, definestackstackMode); 91 93 MODECASE(DIFFTOOL_MODE_PENDINGCLEANUPRUN, pendingcleanuprunMode); 92 94 MODECASE(DIFFTOOL_MODE_PENDINGCLEANUPSKYFILE, pendingcleanupskyfileMode); … … 1831 1833 } 1832 1834 1835 static bool definestackstackMode(pxConfig *config) { 1836 PS_ASSERT_PTR_NON_NULL(config, false); 1837 1838 psMetadata *stack1Where = psMetadataAlloc(); 1839 psMetadata *stack2Where = psMetadataAlloc(); 1840 1841 PXOPT_COPY_STR(config->args, stack1Where, "-tess_id", "stackRun.tess_id", "=="); 1842 PXOPT_COPY_STR(config->args, stack2Where, "-tess_id", "stackRun.tess_id", "=="); 1843 PXOPT_COPY_STR(config->args, stack1Where, "-filter", "stackRun.filter", "=="); 1844 PXOPT_COPY_STR(config->args, stack2Where, "-filter", "stackRun.filter", "=="); 1845 PXOPT_COPY_STR(config->args, stack1Where, "-skycell_id", "stackRun.skycell_id", "=="); 1846 PXOPT_COPY_STR(config->args, stack2Where, "-skycell_id", "stackRun.skycell_id", "=="); 1847 PXOPT_COPY_STR(config->args, stack1Where, "-input_label", "stackRun.label","=="); 1848 PXOPT_COPY_STR(config->args, stack2Where, "-template_label", "stackRun.label","=="); 1849 PXOPT_COPY_F32(config->args, stack1Where, "-good_frac", "stackSumSkyfile.good_frac", ">="); 1850 PXOPT_COPY_F32(config->args, stack2Where, "-good_frac", "stackSumSkyfile.good_frac", ">="); 1851 1852 PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false); // required option 1853 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); // option 1854 PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false); // option 1855 PXOPT_LOOKUP_TIME(registered, config->args, "-set_registered", false, false); 1856 PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false); 1857 PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false); 1858 PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false); 1859 1860 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1861 PXOPT_LOOKUP_BOOL(reRun, config->args, "-rerun", false); 1862 PXOPT_LOOKUP_BOOL(newTemplates,config->args,"-new-templates", false); 1863 1864 PXOPT_LOOKUP_BOOL(available, config->args, "-available", false); 1865 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 1866 1867 if (!(label)) { 1868 PXOPT_LOOKUP_STR(label,config->args, "-input_label",true,false); 1869 } 1870 1871 // Organize the config information into queries. 1872 psString stack1Query = NULL; 1873 psString stack2Query = NULL; 1874 1875 if (psListLength(stack1Where->list)) { 1876 psString whereClause = psDBGenerateWhereConditionSQL(stack1Where, NULL); 1877 psStringAppend(&stack1Query, "\n AND %s", whereClause); 1878 psFree(whereClause); 1879 } else { 1880 stack1Query = psStringCopy("\n"); 1881 } 1882 psFree(stack1Where); 1883 1884 if (psListLength(stack2Where->list)) { 1885 psString whereClause = psDBGenerateWhereConditionSQL(stack2Where, NULL); 1886 psStringAppend(&stack2Query, "\n AND %s", whereClause); 1887 psFree(whereClause); 1888 } else { 1889 stack2Query = psStringCopy("\n"); 1890 } 1891 psFree(stack2Where); 1892 1893 // don't queue for stacks that have already been diffed unless requested 1894 psString diffQuery = NULL; 1895 if (! (reRun || newTemplates) ) { 1896 psStringAppend(&diffQuery, "\n AND diff_id IS NULL"); 1897 } else { 1898 diffQuery = psStringCopy("\n"); 1899 } 1900 1901 // find the distinct set of data_groups and filters 1902 psString query = pxDataGet("difftool_definestackstack_part0.sql"); 1903 if (!query) { 1904 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1905 return(false); 1906 } 1907 1908 if (!psDBTransaction(config->dbh)) { 1909 psError(PS_ERR_UNKNOWN, false, "database error"); 1910 return(false); 1911 } 1912 1913 if (!p_psDBRunQueryF(config->dbh, query, stack2Query, diffQuery, stack1Query, stack1Query)) { 1914 psError(PS_ERR_UNKNOWN, false, "database error"); 1915 psFree(query); 1916 if (!psDBRollback(config->dbh)) { 1917 psError(PS_ERR_UNKNOWN, false, "database error"); 1918 } 1919 return false; 1920 } 1921 psFree(query); 1922 1923 psArray *output = p_psDBFetchResult(config->dbh); 1924 if (!output) { 1925 psErrorCode err = psErrorCodeLast(); 1926 switch (err) { 1927 case PS_ERR_DB_CLIENT: 1928 psError(PXTOOLS_ERR_SYS, false, "database error"); 1929 break; 1930 case PS_ERR_DB_SERVER: 1931 psError(PXTOOLS_ERR_PROG, false, "database error"); 1932 break; 1933 default: 1934 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1935 break; 1936 } 1937 if (!psDBRollback(config->dbh)) { 1938 psError(PS_ERR_UNKNOWN, false, "database error"); 1939 } 1940 return false; 1941 } 1942 if (!psArrayLength(output)) { 1943 psTrace("difftool", PS_LOG_INFO, "no rows found"); 1944 psFree(output); 1945 if (!psDBCommit(config->dbh)) { 1946 psError(PS_ERR_UNKNOWN, false, "database error"); 1947 return false; 1948 } 1949 return true; 1950 } 1951 1952 query = pxDataGet("difftool_definestackstack_part1.sql"); 1953 if (pretend) { 1954 // negative simple so the default is true 1955 if (!ippdbPrintMetadatas(stdout, output, "diffRunTemp", !simple)) { 1956 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1957 psFree(output); 1958 return false; 1959 } 1960 psFree(output); 1961 return true; 1962 } 1963 1964 for (long i = 0; i < output->n; i++) { 1965 psMetadata *row = output->data[i]; // Output row from query 1966 bool mdok; // Status of MD lookup 1967 1968 psString tess_id = psMetadataLookupStr(&mdok,row,"INPUT_tess_id"); 1969 psString this_data_group = psMetadataLookupStr(&mdok,row,"INPUT_data_group"); 1970 psString this_dist_group = psMetadataLookupStr(&mdok,row,"INPUT_dist_group"); 1971 psString this_label = psMetadataLookupStr(&mdok,row,"INPUT_label"); 1972 1973 psString this_stack1Query = psStringCopy(stack1Query); 1974 1975 psString thisWhere = psDBGenerateWhereConditionSQL(row,NULL); 1976 psStringSubstitute(&thisWhere,"stackRun.","INPUT_"); 1977 psStringAppend(&this_stack1Query,"\n AND %s", thisWhere); 1978 psFree(thisWhere); 1979 1980 /* psTrace("difftool",1, query,stack2Query,diffQuery,this_stack1Query,this_stack1Query); */ 1981 if (!psDBTransaction(config->dbh)) { 1982 psError(PS_ERR_UNKNOWN, false, "database error"); 1983 return(false); 1984 } 1985 1986 if (!p_psDBRunQueryF(config->dbh, query, stack2Query, diffQuery, this_stack1Query, this_stack1Query)) { 1987 psError(PS_ERR_UNKNOWN, false, "database error"); 1988 psFree(query); 1989 if (!psDBRollback(config->dbh)) { 1990 psError(PS_ERR_UNKNOWN, false, "database error"); 1991 } 1992 return false; 1993 } 1994 psFree(this_stack1Query); 1995 1996 psArray *diff_id_output = p_psDBFetchResult(config->dbh); 1997 if (!diff_id_output) { 1998 psErrorCode err = psErrorCodeLast(); 1999 switch (err) { 2000 case PS_ERR_DB_CLIENT: 2001 psError(PXTOOLS_ERR_SYS, false, "database error"); 2002 break; 2003 case PS_ERR_DB_SERVER: 2004 psError(PXTOOLS_ERR_PROG, false, "database error"); 2005 break; 2006 default: 2007 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 2008 break; 2009 } 2010 if (!psDBRollback(config->dbh)) { 2011 psError(PS_ERR_UNKNOWN, false, "database error"); 2012 } 2013 return false; 2014 } 2015 if (!psArrayLength(diff_id_output)) { 2016 psTrace("difftool", PS_LOG_INFO, "no rows found"); 2017 psFree(diff_id_output); 2018 if (!psDBCommit(config->dbh)) { 2019 psError(PS_ERR_UNKNOWN, false, "database error"); 2020 return false; 2021 } 2022 return true; 2023 } 2024 2025 // ok we've got one create the diffRun 2026 diffRunRow *run = diffRunRowAlloc( 2027 0, // ID 2028 "reg", // state 2029 workdir, 2030 label ? label : this_label, 2031 data_group ? data_group : this_data_group, 2032 dist_group ? dist_group : this_dist_group, 2033 reduction, 2034 NULL, // dvodb 2035 registered, 2036 tess_id, 2037 false, // bothways 2038 false, // exposure 2039 0, // magicked 2040 note 2041 ); 2042 // Commit to database 2043 if (!diffRunInsertObject(config->dbh, run)) { 2044 psError(PS_ERR_UNKNOWN, false, "database error"); 2045 psFree(run); 2046 if (!psDBRollback(config->dbh)) { 2047 psError(PS_ERR_UNKNOWN, false, "database error"); 2048 } 2049 return false; 2050 } 2051 // diffRunPrintObject(stdout,run,1); 2052 run->diff_id = psDBLastInsertID(config->dbh); 2053 for (long j = 0; j < diff_id_output->n; j++) { 2054 psMetadata *input_row = diff_id_output->data[j]; // Output row from query 2055 bool mdok; 2056 psString in_skycell_id = psMetadataLookupStr(&mdok,input_row,"skycell_id"); 2057 psS64 in_input_stack_id = psMetadataLookupS64(&mdok,input_row,"stack_id"); 2058 psS64 in_template_stack_id = psMetadataLookupS64(&mdok,input_row,"max_stack_id"); 2059 psString in_tess_id = psMetadataLookupStr(&mdok,input_row,"tess_id"); 2060 psTrace("difftool",1,"%s %ld %ld %s\n",in_skycell_id,in_input_stack_id,in_template_stack_id,in_tess_id); 2061 diffInputSkyfileRow *input = diffInputSkyfileRowAlloc( 2062 run->diff_id, // ID 2063 in_skycell_id, 2064 0, // warp1_id 2065 in_input_stack_id, // stack1 2066 0, // warp2_id 2067 in_template_stack_id, // stack2 2068 in_tess_id, 2069 0 // diff_skyfile_id 2070 ); 2071 // Commit to database the input 2072 if (!diffInputSkyfileInsertObject(config->dbh, input)) { 2073 psError(PS_ERR_UNKNOWN, false, "database error"); 2074 psFree(input); 2075 if (!psDBRollback(config->dbh)) { 2076 psError(PS_ERR_UNKNOWN, false, "database error"); 2077 } 2078 return false; 2079 } 2080 // diffInputSkyfilePrintObject(stdout,input,1); 2081 psFree(input); 2082 } 2083 psFree(run); 2084 } 2085 psFree(query); 2086 psFree(stack1Query); 2087 psFree(stack2Query); 2088 psFree(diffQuery); 2089 psFree(output); 2090 2091 return(true); 2092 } 1833 2093 1834 2094 static bool pendingcleanuprunMode(pxConfig *config) … … 1840 2100 1841 2101 psMetadata *where = psMetadataAlloc(); 1842 pxAddLabelSearchArgs (config, where, "-label", " label", "==");2102 pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "=="); 1843 2103 1844 2104 psString query = pxDataGet("difftool_pendingcleanuprun.sql"); … … 1847 2107 return false; 1848 2108 } 1849 2109 // pxDataGet/psStringSubstitute workaround 2110 psString queryCopy = psStringCopy(query); 2111 psFree(query); 2112 query = queryCopy; 2113 1850 2114 if (where && psListLength(where->list)) { 1851 2115 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1852 psStringAppend(&query, " AND %s", whereClause); 2116 psStringAppend(&whereClause, " AND "); 2117 psStringSubstitute(&query,whereClause,"@INNERCONSTRAINT@"); 1853 2118 psFree(whereClause); 2119 } 2120 else { 2121 psStringSubstitute(&query,NULL,"@INNERCONSTRAINT@"); 1854 2122 } 1855 2123 psFree(where); … … 1861 2129 psFree(limitString); 1862 2130 } 1863 1864 2131 // fprintf(stderr,"%s",query); 2132 2133 //fprintf(stderr,"%s",query); 1865 2134 if (!p_psDBRunQuery(config->dbh, query)) { 1866 2135 psError(PS_ERR_UNKNOWN, false, "database error");
Note:
See TracChangeset
for help on using the changeset viewer.
