- Timestamp:
- Apr 21, 2014, 5:42:34 AM (12 years ago)
- Location:
- branches/eam_branches/ps2-tc3-20130727
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (2 props)
-
ippTools/src/staticskytool.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ps2-tc3-20130727
- Property svn:mergeinfo changed
-
branches/eam_branches/ps2-tc3-20130727/ippTools/src
- Property svn:ignore
-
old new 47 47 sctool 48 48 releasetool 49 fftool 50 remotetool 51
-
- Property svn:mergeinfo deleted
- Property svn:ignore
-
branches/eam_branches/ps2-tc3-20130727/ippTools/src/staticskytool.c
r35194 r36680 50 50 static bool revertskycalresultMode(pxConfig *config); 51 51 static bool updateskycalresultMode(pxConfig *config); 52 static bool exportskycalrunMode(pxConfig *config); 53 static bool importskycalrunMode(pxConfig *config); 52 54 53 55 static bool setstaticskyRunState(pxConfig *config, psS64 sky_id, const char *state); … … 88 90 MODECASE(STATICSKYTOOL_MODE_REVERTSKYCALRESULT,revertskycalresultMode); 89 91 MODECASE(STATICSKYTOOL_MODE_SKYCALRESULT, skycalresultMode); 92 MODECASE(STATICSKYTOOL_MODE_EXPORTSKYCALRUN, exportskycalrunMode); 93 MODECASE(STATICSKYTOOL_MODE_IMPORTSKYCALRUN, importskycalrunMode); 90 94 default: 91 95 psAbort("invalid option (this should not happen)"); … … 895 899 bool importrunMode(pxConfig *config) 896 900 { 897 # if (0) 898 unsigned int nFail; 899 900 int numImportTables = 2; 901 902 char tables[2] [80] = {"stackInputSkyfile", "stackSumSkyfile"}; 901 return false; 902 } 903 904 bool exportskycalrunMode(pxConfig *config) 905 { 906 typedef struct ExportTable { 907 char tableName[80]; 908 char sqlFilename[80]; 909 } ExportTable; 910 911 int numExportTables = 2; 903 912 904 913 PS_ASSERT_PTR_NON_NULL(config, NULL); 905 914 906 PXOPT_LOOKUP_STR(infile, config->args, "-infile", true, false); 907 908 psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false); 909 910 #ifdef notdef 911 fprintf (stderr, "---- input ----\n"); 912 psMetadataPrint (stderr, input, 1); 913 #endif 914 915 if (!pxCheckImportVersion(config, input)) { 916 psError(PS_ERR_UNKNOWN, false, "pxCheckImportVersion failed"); 915 // XXX unused PXOPT_LOOKUP_S64(det_id, config->args, "-sky_id", true, false); 916 PXOPT_LOOKUP_STR(outfile, config->args, "-outfile", true, false); 917 PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false); 918 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 919 920 FILE *f = fopen (outfile, "w"); 921 if (f == NULL) { 922 psError(PS_ERR_UNKNOWN, false, "failed to open output file"); 917 923 return false; 918 924 } 919 psMetadataItem *item = psMetadataLookup (input, "stackRun"); 920 psAssert (item, "entry not in input?"); 921 psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?"); 922 923 psMetadataItem *entry = psListGet (item->data.list, 0); 924 assert (entry); 925 assert (entry->type == PS_DATA_METADATA); 926 stackRunRow *stackRun = stackRunObjectFromMetadata (entry->data.md); 927 stackRunInsertObject (config->dbh, stackRun); 928 929 // fprintf (stdout, "---- stack run ----\n"); 930 // psMetadataPrint (stderr, entry->data.md, 1); 931 932 for (int i = 0; i < numImportTables; i++) { 933 psMetadataItem *item = psMetadataLookup (input, tables[i]); 934 psAssert (item, "entry not in input?"); 935 psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?"); 936 937 switch (i) { 938 case 0: 939 for (int i = 0; i < item->data.list->n; i++) { 940 entry = psListGet (item->data.list, i); 941 assert (entry); 942 assert (entry->type == PS_DATA_METADATA); 943 stackInputSkyfileRow *stackInputSkyfile = stackInputSkyfileObjectFromMetadata (entry->data.md); 944 stackInputSkyfileInsertObject (config->dbh, stackInputSkyfile); 945 946 // fprintf (stdout, "---- row %d ----\n", i); 947 // psMetadataPrint (stderr, entry->data.md, 1); 948 } 949 break; 950 951 case 1: 952 for (int i = 0; i < item->data.list->n; i++) { 953 entry = psListGet (item->data.list, i); 954 assert (entry); 955 assert (entry->type == PS_DATA_METADATA); 956 stackSumSkyfileRow *stackSumSkyfile = stackSumSkyfileObjectFromMetadata (entry->data.md); 957 stackSumSkyfileInsertObject (config->dbh, stackSumSkyfile); 958 959 // fprintf (stdout, "---- row %d ----\n", i); 960 // psMetadataPrint (stderr, entry->data.md, 1); 961 } 962 break; 963 } 925 926 if (!pxExportVersion(config, f)) { 927 psError(PS_ERR_UNKNOWN, false, "failed to write dbversion output file"); 928 return false; 964 929 } 965 966 # endif 967 return true; 930 psMetadata *where = psMetadataAlloc(); 931 PXOPT_COPY_S64(config->args, where, "-skycal_id", "skycal_id", "=="); 932 933 ExportTable tables [] = { 934 {"skycalRun", "staticskytool_export_skycalrun.sql"}, 935 {"skycalResult", "staticskytool_export_skycalresult.sql"}, 936 }; 937 938 for (int i=0; i < numExportTables; i++) { 939 psString query = pxDataGet(tables[i].sqlFilename); 940 if (!query) { 941 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 942 return false; 943 } 944 945 if (where && psListLength(where->list)) { 946 psString whereClause = psDBGenerateWhereSQL(where, NULL); 947 psStringAppend(&query, " %s", whereClause); 948 psFree(whereClause); 949 } 950 951 // treat limit == 0 as "no limit" 952 if (limit) { 953 psString limitString = psDBGenerateLimitSQL(limit); 954 psStringAppend(&query, " %s", limitString); 955 psFree(limitString); 956 } 957 958 if (!p_psDBRunQuery(config->dbh, query)) { 959 psError(PS_ERR_UNKNOWN, false, "database error"); 960 psFree(query); 961 return false; 962 } 963 psFree(query); 964 965 psArray *output = p_psDBFetchResult(config->dbh); 966 if (!output) { 967 psError(PS_ERR_UNKNOWN, false, "database error"); 968 return false; 969 } 970 if (!psArrayLength(output)) { 971 psError(PS_ERR_UNKNOWN, true, "no rows found"); 972 psFree(output); 973 return false; 974 } 975 976 if (clean) { 977 if (!strcmp(tables[i].tableName, "skycalRun")) { 978 if (!pxSetStateCleaned("skycalRun", "state", output)) { 979 psFree(output); 980 psError(PS_ERR_UNKNOWN, false, "pxSetStateClean failed for table %s", tables[i].tableName); 981 return false; 982 } 983 } 984 } 985 986 // we must write the export table in non-simple (true) format 987 if (!ippdbPrintMetadatas(f, output, tables[i].tableName, true)) { 988 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 989 psFree(output); 990 return false; 991 } 992 993 psFree(output); 994 } 995 996 fclose (f); 997 998 return true; 999 } 1000 1001 bool importskycalrunMode(pxConfig *config) 1002 { 1003 return false; 968 1004 } 969 1005 … … 986 1022 987 1023 } 988 989 # if (0)990 // now we need to loop over all requested filters and check that each is found991 // XXX is this needed? haven't we required that we only match the requested filters992 // and that N unique filters are found?993 994 psVector *found = psVectorAlloc(inputs->n, PS_TYPE_U8);995 psVectorInit (found, 0);996 997 psMetadataItem *filter = NULL;998 psListIterator *iter = psListIteratorAlloc (filters->data.list, PS_LIST_HEAD, false);999 while ((filter = psListGetAndIncrement(iter))) {1000 1001 bool foundOne = false;1002 1003 psAssert (filter->type == PS_DATA_STR, "filter is not a string?");1004 for (int j = 0; !foundOne && (j < inputs->n); j++) {1005 if (found->data.U8[j]) continue;1006 psMetadata *inputRow = inputs->data[j]; // Row from select1007 1008 // pull out the skycell_id, tess_id, filter1009 psString inFilter = psMetadataLookupStr(&status, row, "filter");1010 psAssert (status);1011 1012 found->data.U8[j] = true;1013 foundOne = true;1014 }1015 if (!foundOne) {1016 // this required filter was not found in the inputs, skip the entry1017 skip();1018 }1019 }1020 # endif1021 1024 1022 1025 static bool defineskycalrunMode(pxConfig *config) … … 1042 1045 PXOPT_COPY_STR(config->args, whereMD, "-select_skycell_id", "stackRun.skycell_id", "=="); 1043 1046 PXOPT_COPY_STR(config->args, whereMD, "-select_tess_id", "stackRun.tess_id", "=="); 1047 pxAddLabelSearchArgs(config, whereMD, "-select_filter", "stackRun.filter", "LIKE"); 1044 1048 PXOPT_COPY_F32(config->args, whereMD, "-select_good_frac_min", "stackSumSkyfile.good_frac", ">="); 1045 1049 pxAddLabelSearchArgs(config, whereMD, "-select_label", "staticskyRun.label", "LIKE"); 1046 1050 pxAddLabelSearchArgs(config, whereMD, "-select_data_group", "staticskyRun.data_group", "LIKE"); 1047 pxAddLabelSearchArgs(config, whereMD, "-select_filter", "stackRun.filter", "LIKE");1048 1051 if (!pxskycellAddWhere(config, whereMD)) { 1049 1052 psError(PXTOOLS_ERR_CONFIG, false, "failed to add skycell search arguments");
Note:
See TracChangeset
for help on using the changeset viewer.
