Changeset 9301
- Timestamp:
- Oct 5, 2006, 11:32:26 AM (20 years ago)
- Location:
- trunk/ippdb
- Files:
-
- 18 edited
-
Makefile.am (modified) (2 diffs)
-
configure.ac (modified) (1 diff)
-
src/ippdb.c (modified) (2 diffs)
-
src/ippdb.h (modified) (1 diff)
-
tests/alloc.c (modified) (1 diff)
-
tests/createtable.c (modified) (1 diff)
-
tests/dbcleanup.c (modified) (1 diff)
-
tests/dbsetup.c (modified) (1 diff)
-
tests/droptable.c (modified) (1 diff)
-
tests/insert.c (modified) (1 diff)
-
tests/insertfits.c (modified) (1 diff)
-
tests/insertobject.c (modified) (1 diff)
-
tests/metadatafromobject.c (modified) (1 diff)
-
tests/objectfrommetadata.c (modified) (1 diff)
-
tests/pop.c (modified) (1 diff)
-
tests/popfits.c (modified) (1 diff)
-
tests/popobject.c (modified) (1 diff)
-
tests/selectrowsfits.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippdb/Makefile.am
r9149 r9301 32 32 $(top_builddir)/docs/man/man3/p2ProcessedImfileRow.3 \ 33 33 $(top_builddir)/docs/man/man3/p3PendingExpRow.3 \ 34 $(top_builddir)/docs/man/man3/p3ProcessedExpRow.3 \ 34 35 $(top_builddir)/docs/man/man3/detRunRow.3 \ 35 36 $(top_builddir)/docs/man/man3/detInputExpRow.3 \ … … 47 48 48 49 49 docs/man/man3/ippdb.3 docs/man/man3/weatherRow.3 docs/man/man3/skyp_transparencyRow.3 docs/man/man3/skyp_absorptionRow.3 docs/man/man3/skyp_emissionRow.3 docs/man/man3/dimmRow.3 docs/man/man3/skyp_irRow.3 docs/man/man3/domeRow.3 docs/man/man3/telescopeRow.3 docs/man/man3/summitExpRow.3 docs/man/man3/pzPendingExpRow.3 docs/man/man3/pzPendingImfileRow.3 docs/man/man3/newExpRow.3 docs/man/man3/newImfileRow.3 docs/man/man3/rawDetrendExpRow.3 docs/man/man3/rawScienceExpRow.3 docs/man/man3/rawImfileRow.3 docs/man/man3/p1PendingExpRow.3 docs/man/man3/p2PendingExpRow.3 docs/man/man3/p2PendingImfileRow.3 docs/man/man3/p2ProcessedExpRow.3 docs/man/man3/p2ProcessedImfileRow.3 docs/man/man3/p3PendingExpRow.3 docs/man/man3/ detRunRow.3 docs/man/man3/detInputExpRow.3 docs/man/man3/detProcessedImfileRow.3 docs/man/man3/detProcessedExpRow.3 docs/man/man3/detStackedImfileRow.3 docs/man/man3/detNormalizedStatImfileRow.3 docs/man/man3/detNormalizedImfileRow.3 docs/man/man3/detNormalizedExpRow.3 docs/man/man3/detMasterFrameRow.3 docs/man/man3/detMasterImfileRow.3 docs/man/man3/detResidImfileRow.3 docs/man/man3/detResidExpRow.3 docs/man/man3/detRunSummaryRow.3:50 docs/man/man3/ippdb.3 docs/man/man3/weatherRow.3 docs/man/man3/skyp_transparencyRow.3 docs/man/man3/skyp_absorptionRow.3 docs/man/man3/skyp_emissionRow.3 docs/man/man3/dimmRow.3 docs/man/man3/skyp_irRow.3 docs/man/man3/domeRow.3 docs/man/man3/telescopeRow.3 docs/man/man3/summitExpRow.3 docs/man/man3/pzPendingExpRow.3 docs/man/man3/pzPendingImfileRow.3 docs/man/man3/newExpRow.3 docs/man/man3/newImfileRow.3 docs/man/man3/rawDetrendExpRow.3 docs/man/man3/rawScienceExpRow.3 docs/man/man3/rawImfileRow.3 docs/man/man3/p1PendingExpRow.3 docs/man/man3/p2PendingExpRow.3 docs/man/man3/p2PendingImfileRow.3 docs/man/man3/p2ProcessedExpRow.3 docs/man/man3/p2ProcessedImfileRow.3 docs/man/man3/p3PendingExpRow.3 docs/man/man3/p3ProcessedExpRow.3 docs/man/man3/detRunRow.3 docs/man/man3/detInputExpRow.3 docs/man/man3/detProcessedImfileRow.3 docs/man/man3/detProcessedExpRow.3 docs/man/man3/detStackedImfileRow.3 docs/man/man3/detNormalizedStatImfileRow.3 docs/man/man3/detNormalizedImfileRow.3 docs/man/man3/detNormalizedExpRow.3 docs/man/man3/detMasterFrameRow.3 docs/man/man3/detMasterImfileRow.3 docs/man/man3/detResidImfileRow.3 docs/man/man3/detResidExpRow.3 docs/man/man3/detRunSummaryRow.3: 50 51 $(DOXYGEN) 51 52 -
trunk/ippdb/configure.ac
r9242 r9301 7 7 AC_PREREQ(2.59) 8 8 9 AC_INIT([ippdb], [0.0.4 6], [pan-starrs.ifa.hawaii.edu])9 AC_INIT([ippdb], [0.0.47], [pan-starrs.ifa.hawaii.edu]) 10 10 AC_CONFIG_SRCDIR([ippdb.pc.in]) 11 11 -
trunk/ippdb/src/ippdb.c
r9247 r9301 57 57 #define P3PENDINGEXP_TABLE_NAME "p3PendingExp" 58 58 #define P3PENDINGEXP_INDEX_NAME IPPDB_DEFAULT_INDEX_NAME 59 #define P3PROCESSEDEXP_TABLE_NAME "p3ProcessedExp" 60 #define P3PROCESSEDEXP_INDEX_NAME IPPDB_DEFAULT_INDEX_NAME 59 61 #define DETRUN_TABLE_NAME "detRun" 60 62 #define DETRUN_INDEX_NAME IPPDB_DEFAULT_INDEX_NAME … … 12858 12860 return true; 12859 12861 } 12862 static void p3ProcessedExpRowFree(p3ProcessedExpRow *object); 12863 12864 p3ProcessedExpRow *p3ProcessedExpRowAlloc(const char *exp_tag, const char *uri, const char *recipe, psF64 bg, psF64 bg_stdev, psF64 bg_mean_stdev, psF32 sigma_ra, psF32 sigma_dec, psS32 nastro, const char *b1_uri, const char *b2_uri, psS32 p2_version, psS32 p3_version) 12865 { 12866 p3ProcessedExpRow *_object; 12867 12868 _object = psAlloc(sizeof(p3ProcessedExpRow)); 12869 psMemSetDeallocator(_object, (psFreeFunc)p3ProcessedExpRowFree); 12870 12871 _object->exp_tag = psStringCopy(exp_tag); 12872 _object->uri = psStringCopy(uri); 12873 _object->recipe = psStringCopy(recipe); 12874 _object->bg = bg; 12875 _object->bg_stdev = bg_stdev; 12876 _object->bg_mean_stdev = bg_mean_stdev; 12877 _object->sigma_ra = sigma_ra; 12878 _object->sigma_dec = sigma_dec; 12879 _object->nastro = nastro; 12880 _object->b1_uri = psStringCopy(b1_uri); 12881 _object->b2_uri = psStringCopy(b2_uri); 12882 _object->p2_version = p2_version; 12883 _object->p3_version = p3_version; 12884 12885 return _object; 12886 } 12887 12888 static void p3ProcessedExpRowFree(p3ProcessedExpRow *object) 12889 { 12890 psFree(object->exp_tag); 12891 psFree(object->uri); 12892 psFree(object->recipe); 12893 psFree(object->b1_uri); 12894 psFree(object->b2_uri); 12895 } 12896 12897 bool p3ProcessedExpCreateTable(psDB *dbh) 12898 { 12899 psMetadata *md; 12900 bool status; 12901 12902 md = psMetadataAlloc(); 12903 if (!psMetadataAdd(md, PS_LIST_TAIL, P3PROCESSEDEXP_INDEX_NAME, PS_DATA_S32, "AUTO_INCREMENT", 0.0)) { 12904 psError(PS_ERR_UNKNOWN, false, "failed to add item %s", P3PROCESSEDEXP_INDEX_NAME); 12905 psFree(md); 12906 return false; 12907 } 12908 if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, "Primary Key", "64")) { 12909 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 12910 psFree(md); 12911 return false; 12912 } 12913 if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "255")) { 12914 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 12915 psFree(md); 12916 return false; 12917 } 12918 if (!psMetadataAddStr(md, PS_LIST_TAIL, "recipe", 0, NULL, "64")) { 12919 psError(PS_ERR_UNKNOWN, false, "failed to add item recipe"); 12920 psFree(md); 12921 return false; 12922 } 12923 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, 0.0)) { 12924 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 12925 psFree(md); 12926 return false; 12927 } 12928 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_stdev", 0, NULL, 0.0)) { 12929 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev"); 12930 psFree(md); 12931 return false; 12932 } 12933 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_mean_stdev", 0, NULL, 0.0)) { 12934 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev"); 12935 psFree(md); 12936 return false; 12937 } 12938 if (!psMetadataAddF32(md, PS_LIST_TAIL, "sigma_ra", 0, NULL, 0.0)) { 12939 psError(PS_ERR_UNKNOWN, false, "failed to add item sigma_ra"); 12940 psFree(md); 12941 return false; 12942 } 12943 if (!psMetadataAddF32(md, PS_LIST_TAIL, "sigma_dec", 0, NULL, 0.0)) { 12944 psError(PS_ERR_UNKNOWN, false, "failed to add item sigma_dec"); 12945 psFree(md); 12946 return false; 12947 } 12948 if (!psMetadataAddS32(md, PS_LIST_TAIL, "nastro", 0, NULL, 0)) { 12949 psError(PS_ERR_UNKNOWN, false, "failed to add item nastro"); 12950 psFree(md); 12951 return false; 12952 } 12953 if (!psMetadataAddStr(md, PS_LIST_TAIL, "b1_uri", 0, NULL, "255")) { 12954 psError(PS_ERR_UNKNOWN, false, "failed to add item b1_uri"); 12955 psFree(md); 12956 return false; 12957 } 12958 if (!psMetadataAddStr(md, PS_LIST_TAIL, "b2_uri", 0, NULL, "255")) { 12959 psError(PS_ERR_UNKNOWN, false, "failed to add item b2_uri"); 12960 psFree(md); 12961 return false; 12962 } 12963 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p2_version", 0, NULL, 0)) { 12964 psError(PS_ERR_UNKNOWN, false, "failed to add item p2_version"); 12965 psFree(md); 12966 return false; 12967 } 12968 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, 0)) { 12969 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 12970 psFree(md); 12971 return false; 12972 } 12973 12974 status = psDBCreateTable(dbh, P3PROCESSEDEXP_TABLE_NAME, md); 12975 12976 psFree(md); 12977 12978 return status; 12979 } 12980 12981 bool p3ProcessedExpDropTable(psDB *dbh) 12982 { 12983 return psDBDropTable(dbh, P3PROCESSEDEXP_TABLE_NAME); 12984 } 12985 12986 bool p3ProcessedExpInsert(psDB * dbh, const char *exp_tag, const char *uri, const char *recipe, psF64 bg, psF64 bg_stdev, psF64 bg_mean_stdev, psF32 sigma_ra, psF32 sigma_dec, psS32 nastro, const char *b1_uri, const char *b2_uri, psS32 p2_version, psS32 p3_version) 12987 { 12988 psMetadata *md; 12989 bool status; 12990 12991 md = psMetadataAlloc(); 12992 if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, exp_tag)) { 12993 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 12994 psFree(md); 12995 return false; 12996 } 12997 if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, uri)) { 12998 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 12999 psFree(md); 13000 return false; 13001 } 13002 if (!psMetadataAddStr(md, PS_LIST_TAIL, "recipe", 0, NULL, recipe)) { 13003 psError(PS_ERR_UNKNOWN, false, "failed to add item recipe"); 13004 psFree(md); 13005 return false; 13006 } 13007 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, bg)) { 13008 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 13009 psFree(md); 13010 return false; 13011 } 13012 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_stdev", 0, NULL, bg_stdev)) { 13013 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev"); 13014 psFree(md); 13015 return false; 13016 } 13017 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_mean_stdev", 0, NULL, bg_mean_stdev)) { 13018 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev"); 13019 psFree(md); 13020 return false; 13021 } 13022 if (!psMetadataAddF32(md, PS_LIST_TAIL, "sigma_ra", 0, NULL, sigma_ra)) { 13023 psError(PS_ERR_UNKNOWN, false, "failed to add item sigma_ra"); 13024 psFree(md); 13025 return false; 13026 } 13027 if (!psMetadataAddF32(md, PS_LIST_TAIL, "sigma_dec", 0, NULL, sigma_dec)) { 13028 psError(PS_ERR_UNKNOWN, false, "failed to add item sigma_dec"); 13029 psFree(md); 13030 return false; 13031 } 13032 if (!psMetadataAddS32(md, PS_LIST_TAIL, "nastro", 0, NULL, nastro)) { 13033 psError(PS_ERR_UNKNOWN, false, "failed to add item nastro"); 13034 psFree(md); 13035 return false; 13036 } 13037 if (!psMetadataAddStr(md, PS_LIST_TAIL, "b1_uri", 0, NULL, b1_uri)) { 13038 psError(PS_ERR_UNKNOWN, false, "failed to add item b1_uri"); 13039 psFree(md); 13040 return false; 13041 } 13042 if (!psMetadataAddStr(md, PS_LIST_TAIL, "b2_uri", 0, NULL, b2_uri)) { 13043 psError(PS_ERR_UNKNOWN, false, "failed to add item b2_uri"); 13044 psFree(md); 13045 return false; 13046 } 13047 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p2_version", 0, NULL, p2_version)) { 13048 psError(PS_ERR_UNKNOWN, false, "failed to add item p2_version"); 13049 psFree(md); 13050 return false; 13051 } 13052 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, p3_version)) { 13053 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 13054 psFree(md); 13055 return false; 13056 } 13057 13058 status = psDBInsertOneRow(dbh, P3PROCESSEDEXP_TABLE_NAME, md); 13059 psFree(md); 13060 13061 return status; 13062 } 13063 13064 long long p3ProcessedExpDelete(psDB *dbh, const psMetadata *where, unsigned long long limit) 13065 { 13066 long long deleted = 0; 13067 13068 long long count = psDBDeleteRows(dbh, P3PROCESSEDEXP_TABLE_NAME, where, limit); 13069 if (count < 0) { 13070 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p3ProcessedExp"); 13071 return count; 13072 13073 deleted += count; 13074 } 13075 13076 return deleted; 13077 } 13078 bool p3ProcessedExpPop(psDB *dbh, char **exp_tag, char **uri, char **recipe, psF64 *bg, psF64 *bg_stdev, psF64 *bg_mean_stdev, psF32 *sigma_ra, psF32 *sigma_dec, psS32 *nastro, char **b1_uri, char **b2_uri, psS32 *p2_version, psS32 *p3_version) 13079 { 13080 psArray *rowSet; 13081 psMetadata *row; 13082 psMetadata *popped; 13083 long deleted; 13084 bool status; 13085 int rowID; 13086 13087 rowSet = psDBSelectRows(dbh, P3PROCESSEDEXP_TABLE_NAME, NULL, 1); 13088 if (!rowSet) { 13089 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item %s", P3PROCESSEDEXP_INDEX_NAME); 13090 psFree(rowSet); 13091 return NULL; 13092 } 13093 13094 row = psArrayGet(rowSet, 0); 13095 psMemIncrRefCounter(row); 13096 if (!row) { 13097 psError(PS_ERR_UNKNOWN, true, "database error or table is empty"); 13098 return NULL; 13099 } 13100 psFree(rowSet); 13101 13102 rowID = psMetadataLookupS32(&status, row, P3PROCESSEDEXP_INDEX_NAME); 13103 if (!status) { 13104 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item %s", P3PROCESSEDEXP_INDEX_NAME); 13105 psFree(row); 13106 return NULL; 13107 } 13108 13109 popped = psMetadataAlloc(); 13110 psMetadataAddS32(popped, PS_LIST_TAIL, P3PROCESSEDEXP_INDEX_NAME, 0, NULL, rowID); 13111 13112 deleted = psDBDeleteRows(dbh, P3PROCESSEDEXP_TABLE_NAME, popped, 0); 13113 if (deleted != 1) { 13114 psError(PS_ERR_UNKNOWN, false, "database failed to delete row"); 13115 psFree(popped); 13116 psFree(row); 13117 return NULL; 13118 } 13119 13120 psFree(popped); 13121 13122 *exp_tag = psMetadataLookupPtr(&status, row, "exp_tag"); 13123 if (!status) { 13124 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag"); 13125 psFree(row); 13126 return false; 13127 } 13128 *uri = psMetadataLookupPtr(&status, row, "uri"); 13129 if (!status) { 13130 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri"); 13131 psFree(row); 13132 return false; 13133 } 13134 *recipe = psMetadataLookupPtr(&status, row, "recipe"); 13135 if (!status) { 13136 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item recipe"); 13137 psFree(row); 13138 return false; 13139 } 13140 *bg = psMetadataLookupF64(&status, row, "bg"); 13141 if (!status) { 13142 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg"); 13143 psFree(row); 13144 return false; 13145 } 13146 *bg_stdev = psMetadataLookupF64(&status, row, "bg_stdev"); 13147 if (!status) { 13148 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_stdev"); 13149 psFree(row); 13150 return false; 13151 } 13152 *bg_mean_stdev = psMetadataLookupF64(&status, row, "bg_mean_stdev"); 13153 if (!status) { 13154 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_mean_stdev"); 13155 psFree(row); 13156 return false; 13157 } 13158 *sigma_ra = psMetadataLookupF32(&status, row, "sigma_ra"); 13159 if (!status) { 13160 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item sigma_ra"); 13161 psFree(row); 13162 return false; 13163 } 13164 *sigma_dec = psMetadataLookupF32(&status, row, "sigma_dec"); 13165 if (!status) { 13166 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item sigma_dec"); 13167 psFree(row); 13168 return false; 13169 } 13170 *nastro = psMetadataLookupS32(&status, row, "nastro"); 13171 if (!status) { 13172 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item nastro"); 13173 psFree(row); 13174 return false; 13175 } 13176 *b1_uri = psMetadataLookupPtr(&status, row, "b1_uri"); 13177 if (!status) { 13178 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item b1_uri"); 13179 psFree(row); 13180 return false; 13181 } 13182 *b2_uri = psMetadataLookupPtr(&status, row, "b2_uri"); 13183 if (!status) { 13184 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item b2_uri"); 13185 psFree(row); 13186 return false; 13187 } 13188 *p2_version = psMetadataLookupS32(&status, row, "p2_version"); 13189 if (!status) { 13190 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p2_version"); 13191 psFree(row); 13192 return false; 13193 } 13194 *p3_version = psMetadataLookupS32(&status, row, "p3_version"); 13195 if (!status) { 13196 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version"); 13197 psFree(row); 13198 return false; 13199 } 13200 13201 psFree(row); 13202 13203 return true; 13204 } 13205 13206 bool p3ProcessedExpInsertObject(psDB *dbh, p3ProcessedExpRow *object) 13207 { 13208 return p3ProcessedExpInsert(dbh, object->exp_tag, object->uri, object->recipe, object->bg, object->bg_stdev, object->bg_mean_stdev, object->sigma_ra, object->sigma_dec, object->nastro, object->b1_uri, object->b2_uri, object->p2_version, object->p3_version); 13209 } 13210 13211 bool p3ProcessedExpInsertObjects(psDB *dbh, psArray *objects) 13212 { 13213 for (long i = 0; i < psArrayLength(objects); i++) { 13214 if (!p3ProcessedExpInsertObject(dbh, objects->data[i])) { 13215 return false; 13216 } 13217 } 13218 13219 return true; 13220 } 13221 13222 p3ProcessedExpRow *p3ProcessedExpPopObject(psDB *dbh) 13223 { 13224 char exp_tag[256]; 13225 char uri[256]; 13226 char recipe[256]; 13227 psF64 bg; 13228 psF64 bg_stdev; 13229 psF64 bg_mean_stdev; 13230 psF32 sigma_ra; 13231 psF32 sigma_dec; 13232 psS32 nastro; 13233 char b1_uri[256]; 13234 char b2_uri[256]; 13235 psS32 p2_version; 13236 psS32 p3_version; 13237 13238 if (!p3ProcessedExpPop(dbh, (char **)&exp_tag, (char **)&uri, (char **)&recipe, &bg, &bg_stdev, &bg_mean_stdev, &sigma_ra, &sigma_dec, &nastro, (char **)&b1_uri, (char **)&b2_uri, &p2_version, &p3_version)) { 13239 psError(PS_ERR_UNKNOWN, false, "failed to pop a database row"); 13240 return NULL; 13241 } 13242 13243 return p3ProcessedExpRowAlloc(exp_tag, uri, recipe, bg, bg_stdev, bg_mean_stdev, sigma_ra, sigma_dec, nastro, b1_uri, b2_uri, p2_version, p3_version); 13244 } 13245 13246 bool p3ProcessedExpInsertFits(psDB *dbh, const psFits *fits) 13247 { 13248 psArray *rowSet; 13249 13250 // move to (the first?) extension named P3PROCESSEDEXP_TABLE_NAME 13251 if (!psFitsMoveExtName(fits, P3PROCESSEDEXP_TABLE_NAME)) { 13252 psError(PS_ERR_UNKNOWN, true, "failed to find FITS extension %s", P3PROCESSEDEXP_TABLE_NAME); 13253 return false; 13254 } 13255 13256 // check HDU type 13257 if (psFitsGetExtType(fits) != PS_FITS_TYPE_BINARY_TABLE) { 13258 psError(PS_ERR_UNKNOWN, true, "FITS HDU type is not PS_FITS_TYPE_BINARY_TABLE"); 13259 return false; 13260 } 13261 13262 // read fits table 13263 rowSet = psFitsReadTable(fits); 13264 if (!rowSet) { 13265 psError(PS_ERR_UNKNOWN, true, "FITS read error or FITS table is empty"); 13266 psFree(rowSet); 13267 return false; 13268 } 13269 13270 if (!psDBInsertRows(dbh, P3PROCESSEDEXP_TABLE_NAME, rowSet)) { 13271 psError(PS_ERR_UNKNOWN, false, "databse insert failed"); 13272 psFree(rowSet); 13273 return false; 13274 } 13275 13276 psFree(rowSet); 13277 13278 return true; 13279 } 13280 13281 bool p3ProcessedExpPopFits(psDB *dbh, psFits *fits, unsigned long long limit) 13282 { 13283 char query[MAX_STRING_LENGTH]; 13284 13285 if (!p3ProcessedExpSelectRowsFits(dbh, fits, NULL, limit)) { 13286 psError(PS_ERR_UNKNOWN, true, "database error or table is empty"); 13287 return false; 13288 } 13289 13290 // remove limit rows from the end of the database 13291 if (snprintf(query, MAX_STRING_LENGTH, 13292 "DELETE FROM %s ORDER BY %s DESC LIMIT %lld", 13293 P3PROCESSEDEXP_TABLE_NAME, P3PROCESSEDEXP_INDEX_NAME, limit) < 0) { 13294 psError(PS_ERR_UNKNOWN, true, "query value attempted to exceed %d bytes", MAX_STRING_LENGTH); 13295 return false; 13296 } 13297 13298 if (!p_psDBRunQuery(dbh, query)) { 13299 psError(PS_ERR_UNKNOWN, false, "database query failed"); 13300 return false; 13301 } 13302 13303 return true; 13304 } 13305 13306 bool p3ProcessedExpSelectRowsFits(psDB *dbh, psFits *fits, const psMetadata *where, unsigned long long limit) 13307 { 13308 psArray *rowSet; 13309 psU64 i; 13310 13311 rowSet = psDBSelectRows(dbh, P3PROCESSEDEXP_TABLE_NAME, where, limit); 13312 if (!rowSet) { 13313 return false; 13314 } 13315 13316 // strip index column 13317 for (i = 0; i < rowSet->n; i++) { 13318 if (!psMetadataRemove((psMetadata *)rowSet->data[i], 0, P3PROCESSEDEXP_INDEX_NAME)) { 13319 psError(PS_ERR_UNKNOWN, true, "failed to remove item %s", P3PROCESSEDEXP_INDEX_NAME); 13320 psFree(rowSet); 13321 return false; 13322 } 13323 } 13324 13325 // output to fits 13326 if (!psFitsWriteTable(fits, NULL, rowSet, P3PROCESSEDEXP_TABLE_NAME)) { 13327 psError(PS_ERR_UNKNOWN, false, "FITS table write failed"); 13328 psFree(rowSet); 13329 return false; 13330 } 13331 13332 psFree(rowSet); 13333 13334 return true; 13335 } 13336 13337 psMetadata *p3ProcessedExpMetadataFromObject(const p3ProcessedExpRow *object) 13338 { 13339 psMetadata *md; 13340 13341 md = psMetadataAlloc(); 13342 if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, object->exp_tag)) { 13343 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_tag"); 13344 psFree(md); 13345 return NULL; 13346 } 13347 if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, object->uri)) { 13348 psError(PS_ERR_UNKNOWN, false, "failed to add item uri"); 13349 psFree(md); 13350 return NULL; 13351 } 13352 if (!psMetadataAddStr(md, PS_LIST_TAIL, "recipe", 0, NULL, object->recipe)) { 13353 psError(PS_ERR_UNKNOWN, false, "failed to add item recipe"); 13354 psFree(md); 13355 return NULL; 13356 } 13357 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, object->bg)) { 13358 psError(PS_ERR_UNKNOWN, false, "failed to add item bg"); 13359 psFree(md); 13360 return NULL; 13361 } 13362 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_stdev", 0, NULL, object->bg_stdev)) { 13363 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_stdev"); 13364 psFree(md); 13365 return NULL; 13366 } 13367 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_mean_stdev", 0, NULL, object->bg_mean_stdev)) { 13368 psError(PS_ERR_UNKNOWN, false, "failed to add item bg_mean_stdev"); 13369 psFree(md); 13370 return NULL; 13371 } 13372 if (!psMetadataAddF32(md, PS_LIST_TAIL, "sigma_ra", 0, NULL, object->sigma_ra)) { 13373 psError(PS_ERR_UNKNOWN, false, "failed to add item sigma_ra"); 13374 psFree(md); 13375 return NULL; 13376 } 13377 if (!psMetadataAddF32(md, PS_LIST_TAIL, "sigma_dec", 0, NULL, object->sigma_dec)) { 13378 psError(PS_ERR_UNKNOWN, false, "failed to add item sigma_dec"); 13379 psFree(md); 13380 return NULL; 13381 } 13382 if (!psMetadataAddS32(md, PS_LIST_TAIL, "nastro", 0, NULL, object->nastro)) { 13383 psError(PS_ERR_UNKNOWN, false, "failed to add item nastro"); 13384 psFree(md); 13385 return NULL; 13386 } 13387 if (!psMetadataAddStr(md, PS_LIST_TAIL, "b1_uri", 0, NULL, object->b1_uri)) { 13388 psError(PS_ERR_UNKNOWN, false, "failed to add item b1_uri"); 13389 psFree(md); 13390 return NULL; 13391 } 13392 if (!psMetadataAddStr(md, PS_LIST_TAIL, "b2_uri", 0, NULL, object->b2_uri)) { 13393 psError(PS_ERR_UNKNOWN, false, "failed to add item b2_uri"); 13394 psFree(md); 13395 return NULL; 13396 } 13397 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p2_version", 0, NULL, object->p2_version)) { 13398 psError(PS_ERR_UNKNOWN, false, "failed to add item p2_version"); 13399 psFree(md); 13400 return NULL; 13401 } 13402 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, object->p3_version)) { 13403 psError(PS_ERR_UNKNOWN, false, "failed to add item p3_version"); 13404 psFree(md); 13405 return NULL; 13406 } 13407 13408 return md; 13409 } 13410 13411 p3ProcessedExpRow *p3ProcessedExpObjectFromMetadata(psMetadata *md) 13412 { 13413 bool status; 13414 char *exp_tag; 13415 char *uri; 13416 char *recipe; 13417 psF64 bg; 13418 psF64 bg_stdev; 13419 psF64 bg_mean_stdev; 13420 psF32 sigma_ra; 13421 psF32 sigma_dec; 13422 psS32 nastro; 13423 char *b1_uri; 13424 char *b2_uri; 13425 psS32 p2_version; 13426 psS32 p3_version; 13427 13428 exp_tag = psMetadataLookupPtr(&status, md, "exp_tag"); 13429 if (!status) { 13430 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item exp_tag"); 13431 return false; 13432 } 13433 uri = psMetadataLookupPtr(&status, md, "uri"); 13434 if (!status) { 13435 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item uri"); 13436 return false; 13437 } 13438 recipe = psMetadataLookupPtr(&status, md, "recipe"); 13439 if (!status) { 13440 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item recipe"); 13441 return false; 13442 } 13443 bg = psMetadataLookupF64(&status, md, "bg"); 13444 if (!status) { 13445 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg"); 13446 return false; 13447 } 13448 bg_stdev = psMetadataLookupF64(&status, md, "bg_stdev"); 13449 if (!status) { 13450 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_stdev"); 13451 return false; 13452 } 13453 bg_mean_stdev = psMetadataLookupF64(&status, md, "bg_mean_stdev"); 13454 if (!status) { 13455 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item bg_mean_stdev"); 13456 return false; 13457 } 13458 sigma_ra = psMetadataLookupF32(&status, md, "sigma_ra"); 13459 if (!status) { 13460 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item sigma_ra"); 13461 return false; 13462 } 13463 sigma_dec = psMetadataLookupF32(&status, md, "sigma_dec"); 13464 if (!status) { 13465 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item sigma_dec"); 13466 return false; 13467 } 13468 nastro = psMetadataLookupS32(&status, md, "nastro"); 13469 if (!status) { 13470 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item nastro"); 13471 return false; 13472 } 13473 b1_uri = psMetadataLookupPtr(&status, md, "b1_uri"); 13474 if (!status) { 13475 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item b1_uri"); 13476 return false; 13477 } 13478 b2_uri = psMetadataLookupPtr(&status, md, "b2_uri"); 13479 if (!status) { 13480 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item b2_uri"); 13481 return false; 13482 } 13483 p2_version = psMetadataLookupS32(&status, md, "p2_version"); 13484 if (!status) { 13485 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p2_version"); 13486 return false; 13487 } 13488 p3_version = psMetadataLookupS32(&status, md, "p3_version"); 13489 if (!status) { 13490 psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item p3_version"); 13491 return false; 13492 } 13493 13494 return p3ProcessedExpRowAlloc(exp_tag, uri, recipe, bg, bg_stdev, bg_mean_stdev, sigma_ra, sigma_dec, nastro, b1_uri, b2_uri, p2_version, p3_version); 13495 } 13496 psArray *p3ProcessedExpSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit) 13497 { 13498 psArray *rowSet; 13499 psArray *returnSet; 13500 psU64 i; 13501 13502 rowSet = psDBSelectRows(dbh, P3PROCESSEDEXP_TABLE_NAME, where, limit); 13503 if (!rowSet) { 13504 return NULL; 13505 } 13506 13507 // strip index column 13508 for (i = 0; i < rowSet->n; i++) { 13509 if (!psMetadataRemove((psMetadata *)(rowSet->data[i]), 0, P3PROCESSEDEXP_INDEX_NAME)) { 13510 psError(PS_ERR_UNKNOWN, true, "failed to remove item %s", P3PROCESSEDEXP_INDEX_NAME); 13511 psFree(rowSet); 13512 return false; 13513 } 13514 } 13515 13516 // convert psMetadata rows to row objects 13517 13518 returnSet = psArrayAlloc(rowSet->n); 13519 returnSet->n = 0; 13520 13521 for (i = 0; i < rowSet->n; i++) { 13522 p3ProcessedExpRow *object = p3ProcessedExpObjectFromMetadata(rowSet->data[i]); 13523 psArrayAdd(returnSet, 0, object); 13524 psFree(object); 13525 } 13526 13527 psFree(rowSet); 13528 13529 return returnSet; 13530 } 13531 bool p3ProcessedExpDeleteObject(psDB *dbh, const p3ProcessedExpRow *object) 13532 { 13533 psMetadata *where = p3ProcessedExpMetadataFromObject(object); 13534 long long count = psDBDeleteRows(dbh, P3PROCESSEDEXP_TABLE_NAME, where, 0); 13535 psFree(where) 13536 if (count < 0) { 13537 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p3ProcessedExp"); 13538 return false; 13539 } 13540 if (count > 1) { 13541 // XXX should this be a psAbort() instead? It is possible that 13542 // having an object match multiple rows was by design. 13543 psError(PS_ERR_UNKNOWN, true, "p3ProcessedExpRow object matched more then one row. Check your database schema"); 13544 return false; 13545 } 13546 13547 return true; 13548 } 13549 long long p3ProcessedExpDeleteRowObjects(psDB *dbh, const psArray *objects, unsigned long long limit) 13550 { 13551 long long deleted = 0; 13552 13553 for (long long i = 0; i < objects->n; i++) { 13554 p3ProcessedExpRow *object = objects->data[i]; 13555 psMetadata *where = p3ProcessedExpMetadataFromObject(object); 13556 long long count = psDBDeleteRows(dbh, P3PROCESSEDEXP_TABLE_NAME, where, limit); 13557 psFree(where) 13558 if (count < 0) { 13559 psError(PS_ERR_UNKNOWN, true, "failed to delete row from p3ProcessedExp"); 13560 return count; 13561 } 13562 13563 deleted += count; 13564 } 13565 13566 return deleted; 13567 } 13568 bool p3ProcessedExpPrintObjects(FILE *stream, psArray *objects, bool mdcf) 13569 { 13570 PS_ASSERT_PTR_NON_NULL(objects, false); 13571 13572 psMetadata *output = psMetadataAlloc(); 13573 for (long i = 0; i < psArrayLength(objects); i++) { 13574 psMetadata *md = p3ProcessedExpMetadataFromObject(objects->data[i]); 13575 if (!psMetadataAddMetadata( 13576 output, 13577 PS_LIST_TAIL, 13578 P3PROCESSEDEXP_TABLE_NAME, 13579 PS_META_DUPLICATE_OK, 13580 NULL, 13581 md 13582 )) { 13583 psError(PS_ERR_UNKNOWN, false, "failed to add metadata"); 13584 psFree(md); 13585 psFree(output); 13586 return false; 13587 } 13588 psFree(md); 13589 } 13590 13591 if (!ippdbPrintMetadataRaw(stream, output, mdcf)) { 13592 psError(PS_ERR_UNKNOWN, false, "failed to print metadata"); 13593 psFree(output); 13594 } 13595 psFree(output); 13596 13597 return true; 13598 } 12860 13599 static void detRunRowFree(detRunRow *object); 12861 13600 -
trunk/ippdb/src/ippdb.h
r9242 r9301 5399 5399 bool mdcf ///< format as mdconfig or simple 5400 5400 ); 5401 /** p3ProcessedExpRow data structure 5402 * 5403 * Structure for representing a single row of p3ProcessedExp table data. 5404 */ 5405 5406 typedef struct { 5407 char *exp_tag; 5408 char *uri; 5409 char *recipe; 5410 psF64 bg; 5411 psF64 bg_stdev; 5412 psF64 bg_mean_stdev; 5413 psF32 sigma_ra; 5414 psF32 sigma_dec; 5415 psS32 nastro; 5416 char *b1_uri; 5417 char *b2_uri; 5418 psS32 p2_version; 5419 psS32 p3_version; 5420 } p3ProcessedExpRow; 5421 5422 /** Creates a new p3ProcessedExpRow object 5423 * 5424 * @return A new p3ProcessedExpRow object or NULL on failure. 5425 */ 5426 5427 p3ProcessedExpRow *p3ProcessedExpRowAlloc( 5428 const char *exp_tag, 5429 const char *uri, 5430 const char *recipe, 5431 psF64 bg, 5432 psF64 bg_stdev, 5433 psF64 bg_mean_stdev, 5434 psF32 sigma_ra, 5435 psF32 sigma_dec, 5436 psS32 nastro, 5437 const char *b1_uri, 5438 const char *b2_uri, 5439 psS32 p2_version, 5440 psS32 p3_version 5441 ); 5442 5443 /** Creates a new p3ProcessedExp table 5444 * 5445 * @return true on success 5446 */ 5447 5448 bool p3ProcessedExpCreateTable( 5449 psDB *dbh ///< Database handle 5450 ); 5451 5452 /** Deletes a p3ProcessedExp table 5453 * 5454 * @return true on success 5455 */ 5456 5457 bool p3ProcessedExpDropTable( 5458 psDB *dbh ///< Database handle 5459 ); 5460 5461 /** Insert a single row into a table 5462 * 5463 * This function constructs and inserts a single row based on it's parameters. 5464 * 5465 * @return true on success 5466 */ 5467 5468 bool p3ProcessedExpInsert( 5469 psDB *dbh, ///< Database handle 5470 const char *exp_tag, 5471 const char *uri, 5472 const char *recipe, 5473 psF64 bg, 5474 psF64 bg_stdev, 5475 psF64 bg_mean_stdev, 5476 psF32 sigma_ra, 5477 psF32 sigma_dec, 5478 psS32 nastro, 5479 const char *b1_uri, 5480 const char *b2_uri, 5481 psS32 p2_version, 5482 psS32 p3_version 5483 ); 5484 5485 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 5486 * 5487 * @return A The number of rows removed or a negative value on error 5488 */ 5489 5490 long long p3ProcessedExpDelete( 5491 psDB *dbh, ///< Database handle 5492 const psMetadata *where, ///< Row match criteria 5493 unsigned long long limit ///< Maximum number of elements to delete 5494 ); 5495 5496 /** Removes the last row from the database and returns it 5497 * 5498 * @return true on success 5499 */ 5500 5501 bool p3ProcessedExpPop( 5502 psDB *dbh, ///< Database handle 5503 char **exp_tag, 5504 char **uri, 5505 char **recipe, 5506 psF64 *bg, 5507 psF64 *bg_stdev, 5508 psF64 *bg_mean_stdev, 5509 psF32 *sigma_ra, 5510 psF32 *sigma_dec, 5511 psS32 *nastro, 5512 char **b1_uri, 5513 char **b2_uri, 5514 psS32 *p2_version, 5515 psS32 *p3_version 5516 ); 5517 5518 /** Insert a single p3ProcessedExpRow object into a table 5519 * 5520 * This function constructs and inserts a single row based on it's parameters. 5521 * 5522 * @return true on success 5523 */ 5524 5525 bool p3ProcessedExpInsertObject( 5526 psDB *dbh, ///< Database handle 5527 p3ProcessedExpRow *object ///< p3ProcessedExpRow object 5528 ); 5529 5530 /** Insert an array of p3ProcessedExpRow object into a table 5531 * 5532 * This function constructs and inserts multiple rows based on it's parameters. 5533 * 5534 * @return true on success 5535 */ 5536 5537 bool p3ProcessedExpInsertObjects( 5538 psDB *dbh, ///< Database handle 5539 psArray *objects ///< array of p3ProcessedExpRow objects 5540 ); 5541 5542 /** Removes the last row from the database and returns it 5543 * 5544 * @return A new p3ProcessedExpRow on success or NULL on failure. 5545 */ 5546 5547 p3ProcessedExpRow *p3ProcessedExpPopObject( 5548 psDB *dbh ///< Database handle 5549 ); 5550 5551 /** Insert data from a binary FITS table p3ProcessedExpRow into the database 5552 * 5553 * This function expects a psFits object with a FITS table as the first 5554 * extension. The table must have at least one row of data in it, that is of 5555 * the appropriate format (number of columns and their type). All other 5556 * extensions are ignored. 5557 * 5558 * @return true on success 5559 */ 5560 5561 bool p3ProcessedExpInsertFits( 5562 psDB *dbh, ///< Database handle 5563 const psFits *fits ///< psFits object 5564 ); 5565 5566 /** Removes the last limit row from the database and returns them in a binary FITS table. 5567 * 5568 * This function assumes an empty psFits object and will create a FITS table as 5569 * the first extension. 5570 * 5571 * @return true on success 5572 */ 5573 5574 bool p3ProcessedExpPopFits( 5575 psDB *dbh, ///< Database handle 5576 psFits *fits, ///< psFits object 5577 unsigned long long limit ///< Maximum number of elements to return 5578 ); 5579 5580 /** Selects up to limit from the database and returns them in a binary FITS table 5581 * 5582 * This function assumes an empty psFits object and will create a FITS table 5583 * as the first extension. 5584 * 5585 * See psDBSelectRows() for documentation on the format of where. 5586 * 5587 * @return true on success 5588 */ 5589 5590 bool p3ProcessedExpSelectRowsFits( 5591 psDB *dbh, ///< Database handle 5592 psFits *fits, ///< psFits object 5593 const psMetadata *where, ///< Row match criteria 5594 unsigned long long limit ///< Maximum number of elements to return 5595 ); 5596 5597 /** Convert a p3ProcessedExpRow into an equivalent psMetadata 5598 * 5599 * @return A psMetadata pointer or NULL on error 5600 */ 5601 5602 psMetadata *p3ProcessedExpMetadataFromObject( 5603 const p3ProcessedExpRow *object ///< fooRow to convert into a psMetadata 5604 ); 5605 5606 /** Convert a psMetadata into an equivalent fooRow 5607 * 5608 * @return A p3ProcessedExpRow pointer or NULL on error 5609 */ 5610 5611 p3ProcessedExpRow *p3ProcessedExpObjectFromMetadata( 5612 psMetadata *md ///< psMetadata to convert into a fooRow 5613 ); 5614 /** Selects up to limit rows from the database and returns as p3ProcessedExpRow objects in a psArray 5615 * 5616 * See psDBSelectRows() for documentation on the format of where. 5617 * 5618 * @return A psArray pointer or NULL on error 5619 */ 5620 5621 psArray *p3ProcessedExpSelectRowObjects( 5622 psDB *dbh, ///< Database handle 5623 const psMetadata *where, ///< Row match criteria 5624 unsigned long long limit ///< Maximum number of elements to return 5625 ); 5626 /** Deletes a row from the database coresponding to an p3ProcessedExp 5627 * 5628 * Note that a 'where' search psMetadata is constructed from each object and 5629 * used to find rows to delete. 5630 * 5631 * @return A The number of rows removed or a negative value on error 5632 */ 5633 5634 bool p3ProcessedExpDeleteObject( 5635 psDB *dbh, ///< Database handle 5636 const p3ProcessedExpRow *object ///< Object to delete 5637 ); 5638 /** Deletes up to limit rows from the database and returns the number of rows actually deleted. 5639 * 5640 * Note that a 'where' search psMetadata is constructed from each object and 5641 * used to find rows to delete. 5642 * 5643 * @return A The number of rows removed or a negative value on error 5644 */ 5645 5646 long long p3ProcessedExpDeleteRowObjects( 5647 psDB *dbh, ///< Database handle 5648 const psArray *objects, ///< Array of objects to delete 5649 unsigned long long limit ///< Maximum number of elements to delete 5650 ); 5651 /** Formats and prints an array of p3ProcessedExpRow objects 5652 * 5653 * When mdcf is set the formated output is in psMetadataConfig 5654 * format, otherwise it is in a simple tabular format. 5655 * 5656 * @return true on success 5657 */ 5658 5659 bool p3ProcessedExpPrintObjects( 5660 FILE *stream, ///< a stream 5661 psArray *objects, ///< An array of p3ProcessedExpRow objects 5662 bool mdcf ///< format as mdconfig or simple 5663 ); 5401 5664 /** detRunRow data structure 5402 5665 * -
trunk/ippdb/tests/alloc.c
r9242 r9301 947 947 948 948 { 949 p3ProcessedExpRow *object; 950 951 object = p3ProcessedExpRowAlloc("a string", "a string", "a string", 64.64, 64.64, 64.64, 32.32, 32.32, -32, "a string", "a string", -32, -32 ); 952 953 if (!object) { 954 exit(EXIT_FAILURE); 955 } 956 957 if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) { 958 psFree(object); 959 exit(EXIT_FAILURE); 960 } 961 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 962 psFree(object); 963 exit(EXIT_FAILURE); 964 } 965 if (strncmp(object->recipe, "a string", MAX_STRING_LENGTH)) { 966 psFree(object); 967 exit(EXIT_FAILURE); 968 } 969 if (!object->bg == 64.64) { 970 psFree(object); 971 exit(EXIT_FAILURE); 972 } 973 if (!object->bg_stdev == 64.64) { 974 psFree(object); 975 exit(EXIT_FAILURE); 976 } 977 if (!object->bg_mean_stdev == 64.64) { 978 psFree(object); 979 exit(EXIT_FAILURE); 980 } 981 if (!object->sigma_ra == 32.32) { 982 psFree(object); 983 exit(EXIT_FAILURE); 984 } 985 if (!object->sigma_dec == 32.32) { 986 psFree(object); 987 exit(EXIT_FAILURE); 988 } 989 if (!object->nastro == -32) { 990 psFree(object); 991 exit(EXIT_FAILURE); 992 } 993 if (strncmp(object->b1_uri, "a string", MAX_STRING_LENGTH)) { 994 psFree(object); 995 exit(EXIT_FAILURE); 996 } 997 if (strncmp(object->b2_uri, "a string", MAX_STRING_LENGTH)) { 998 psFree(object); 999 exit(EXIT_FAILURE); 1000 } 1001 if (!object->p2_version == -32) { 1002 psFree(object); 1003 exit(EXIT_FAILURE); 1004 } 1005 if (!object->p3_version == -32) { 1006 psFree(object); 1007 exit(EXIT_FAILURE); 1008 } 1009 1010 psFree(object); 1011 } 1012 1013 { 949 1014 detRunRow *object; 950 1015 -
trunk/ippdb/tests/createtable.c
r9149 r9301 343 343 } 344 344 345 if(!p3ProcessedExpCreateTable(dbh)) { 346 exit(EXIT_FAILURE); 347 } 348 349 psDBCleanup(dbh); 350 } 351 352 { 353 psDB *dbh; 354 355 dbh = psDBInit("localhost", "test", NULL, "test"); 356 if (!dbh) { 357 exit(EXIT_FAILURE); 358 } 359 345 360 if(!detRunCreateTable(dbh)) { 346 361 exit(EXIT_FAILURE); -
trunk/ippdb/tests/dbcleanup.c
r9149 r9301 33 33 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p2ProcessedImfile"); 34 34 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p3PendingExp"); 35 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p3ProcessedExp"); 35 36 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detRun"); 36 37 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detInputExp"); -
trunk/ippdb/tests/dbsetup.c
r9149 r9301 79 79 p3PendingExpCreateTable(dbh); 80 80 81 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS p3ProcessedExp"); 82 p3ProcessedExpCreateTable(dbh); 83 81 84 p_psDBRunQuery(dbh, "DROP TABLE IF EXISTS detRun"); 82 85 detRunCreateTable(dbh); -
trunk/ippdb/tests/droptable.c
r9149 r9301 343 343 } 344 344 345 if (!p3ProcessedExpDropTable(dbh)) { 346 exit(EXIT_FAILURE); 347 } 348 349 psDBCleanup(dbh); 350 } 351 352 { 353 psDB *dbh; 354 355 dbh = psDBInit("localhost", "test", NULL, "test"); 356 if (!dbh) { 357 exit(EXIT_FAILURE); 358 } 359 345 360 if (!detRunDropTable(dbh)) { 346 361 exit(EXIT_FAILURE); -
trunk/ippdb/tests/insert.c
r9229 r9301 343 343 } 344 344 345 if (!p3ProcessedExpInsert(dbh, "a string", "a string", "a string", 64.64, 64.64, 64.64, 32.32, 32.32, -32, "a string", "a string", -32, -32)) { 346 exit(EXIT_FAILURE); 347 } 348 349 psDBCleanup(dbh); 350 } 351 352 { 353 psDB *dbh; 354 355 dbh = psDBInit("localhost", "test", NULL, "test"); 356 if (!dbh) { 357 exit(EXIT_FAILURE); 358 } 359 345 360 if (!detRunInsert(dbh, -32, "a string", "a string")) { 346 361 exit(EXIT_FAILURE); -
trunk/ippdb/tests/insertfits.c
r9149 r9301 596 596 } 597 597 598 if (!p3ProcessedExpInsertFits(dbh, fits)) { 599 exit(EXIT_FAILURE); 600 } 601 602 if (!psFitsClose(fits)) { 603 exit(EXIT_FAILURE); 604 } 605 606 psDBCleanup(dbh); 607 } 608 609 { 610 psDB *dbh; 611 psFits *fits; 612 613 dbh = psDBInit("localhost", "test", NULL, "test"); 614 if (!dbh) { 615 exit(EXIT_FAILURE); 616 } 617 618 // open a temp 619 fits = psFitsOpen(TMP_FILENAME, "r"); 620 if (!fits) { 621 exit(EXIT_FAILURE); 622 } 623 598 624 if (!detRunInsertFits(dbh, fits)) { 599 625 exit(EXIT_FAILURE); -
trunk/ippdb/tests/insertobject.c
r9229 r9301 491 491 { 492 492 psDB *dbh; 493 p3ProcessedExpRow *object; 494 495 dbh = psDBInit("localhost", "test", NULL, "test"); 496 if (!dbh) { 497 exit(EXIT_FAILURE); 498 } 499 500 object = p3ProcessedExpRowAlloc("a string", "a string", "a string", 64.64, 64.64, 64.64, 32.32, 32.32, -32, "a string", "a string", -32, -32); 501 if (!object) { 502 exit(EXIT_FAILURE); 503 } 504 505 if (!p3ProcessedExpInsertObject(dbh, object)) { 506 exit(EXIT_FAILURE); 507 } 508 509 psFree(object); 510 psDBCleanup(dbh); 511 } 512 513 { 514 psDB *dbh; 493 515 detRunRow *object; 494 516 -
trunk/ippdb/tests/metadatafromobject.c
r9242 r9301 1124 1124 { 1125 1125 psMetadata *md; 1126 p3ProcessedExpRow *object; 1127 bool status; 1128 1129 object = p3ProcessedExpRowAlloc("a string", "a string", "a string", 64.64, 64.64, 64.64, 32.32, 32.32, -32, "a string", "a string", -32, -32); 1130 if (!object) { 1131 exit(EXIT_FAILURE); 1132 } 1133 1134 md = p3ProcessedExpMetadataFromObject(object); 1135 if (!md) { 1136 exit(EXIT_FAILURE); 1137 } 1138 1139 psFree(object); 1140 1141 if (strncmp(psMetadataLookupPtr(&status, md, "exp_tag"), "a string", MAX_STRING_LENGTH)) { 1142 psFree(md); 1143 exit(EXIT_FAILURE); 1144 } 1145 if (strncmp(psMetadataLookupPtr(&status, md, "uri"), "a string", MAX_STRING_LENGTH)) { 1146 psFree(md); 1147 exit(EXIT_FAILURE); 1148 } 1149 if (strncmp(psMetadataLookupPtr(&status, md, "recipe"), "a string", MAX_STRING_LENGTH)) { 1150 psFree(md); 1151 exit(EXIT_FAILURE); 1152 } 1153 if (!psMetadataLookupF64(&status, md, "bg") == 64.64) { 1154 psFree(md); 1155 exit(EXIT_FAILURE); 1156 } 1157 if (!psMetadataLookupF64(&status, md, "bg_stdev") == 64.64) { 1158 psFree(md); 1159 exit(EXIT_FAILURE); 1160 } 1161 if (!psMetadataLookupF64(&status, md, "bg_mean_stdev") == 64.64) { 1162 psFree(md); 1163 exit(EXIT_FAILURE); 1164 } 1165 if (!psMetadataLookupF32(&status, md, "sigma_ra") == 32.32) { 1166 psFree(md); 1167 exit(EXIT_FAILURE); 1168 } 1169 if (!psMetadataLookupF32(&status, md, "sigma_dec") == 32.32) { 1170 psFree(md); 1171 exit(EXIT_FAILURE); 1172 } 1173 if (!psMetadataLookupS32(&status, md, "nastro") == -32) { 1174 psFree(md); 1175 exit(EXIT_FAILURE); 1176 } 1177 if (strncmp(psMetadataLookupPtr(&status, md, "b1_uri"), "a string", MAX_STRING_LENGTH)) { 1178 psFree(md); 1179 exit(EXIT_FAILURE); 1180 } 1181 if (strncmp(psMetadataLookupPtr(&status, md, "b2_uri"), "a string", MAX_STRING_LENGTH)) { 1182 psFree(md); 1183 exit(EXIT_FAILURE); 1184 } 1185 if (!psMetadataLookupS32(&status, md, "p2_version") == -32) { 1186 psFree(md); 1187 exit(EXIT_FAILURE); 1188 } 1189 if (!psMetadataLookupS32(&status, md, "p3_version") == -32) { 1190 psFree(md); 1191 exit(EXIT_FAILURE); 1192 } 1193 1194 psFree(md); 1195 } 1196 1197 { 1198 psMetadata *md; 1126 1199 detRunRow *object; 1127 1200 bool status; -
trunk/ippdb/tests/objectfrommetadata.c
r9242 r9301 1710 1710 { 1711 1711 psMetadata *md; 1712 p3ProcessedExpRow *object; 1713 1714 md = psMetadataAlloc(); 1715 if (!psMetadataAddStr(md, PS_LIST_TAIL, "exp_tag", 0, NULL, "a string")) { 1716 psFree(md); 1717 exit(EXIT_FAILURE); 1718 } 1719 if (!psMetadataAddStr(md, PS_LIST_TAIL, "uri", 0, NULL, "a string")) { 1720 psFree(md); 1721 exit(EXIT_FAILURE); 1722 } 1723 if (!psMetadataAddStr(md, PS_LIST_TAIL, "recipe", 0, NULL, "a string")) { 1724 psFree(md); 1725 exit(EXIT_FAILURE); 1726 } 1727 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg", 0, NULL, 64.64)) { 1728 psFree(md); 1729 exit(EXIT_FAILURE); 1730 } 1731 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_stdev", 0, NULL, 64.64)) { 1732 psFree(md); 1733 exit(EXIT_FAILURE); 1734 } 1735 if (!psMetadataAddF64(md, PS_LIST_TAIL, "bg_mean_stdev", 0, NULL, 64.64)) { 1736 psFree(md); 1737 exit(EXIT_FAILURE); 1738 } 1739 if (!psMetadataAddF32(md, PS_LIST_TAIL, "sigma_ra", 0, NULL, 32.32)) { 1740 psFree(md); 1741 exit(EXIT_FAILURE); 1742 } 1743 if (!psMetadataAddF32(md, PS_LIST_TAIL, "sigma_dec", 0, NULL, 32.32)) { 1744 psFree(md); 1745 exit(EXIT_FAILURE); 1746 } 1747 if (!psMetadataAddS32(md, PS_LIST_TAIL, "nastro", 0, NULL, -32)) { 1748 psFree(md); 1749 exit(EXIT_FAILURE); 1750 } 1751 if (!psMetadataAddStr(md, PS_LIST_TAIL, "b1_uri", 0, NULL, "a string")) { 1752 psFree(md); 1753 exit(EXIT_FAILURE); 1754 } 1755 if (!psMetadataAddStr(md, PS_LIST_TAIL, "b2_uri", 0, NULL, "a string")) { 1756 psFree(md); 1757 exit(EXIT_FAILURE); 1758 } 1759 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p2_version", 0, NULL, -32)) { 1760 psFree(md); 1761 exit(EXIT_FAILURE); 1762 } 1763 if (!psMetadataAddS32(md, PS_LIST_TAIL, "p3_version", 0, NULL, -32)) { 1764 psFree(md); 1765 exit(EXIT_FAILURE); 1766 } 1767 1768 object = p3ProcessedExpObjectFromMetadata(md); 1769 if (!object) { 1770 psFree(md); 1771 exit(EXIT_FAILURE); 1772 } 1773 1774 psFree(md); 1775 1776 if (strncmp(object->exp_tag, "a string", MAX_STRING_LENGTH)) { 1777 psFree(object); 1778 exit(EXIT_FAILURE); 1779 } 1780 if (strncmp(object->uri, "a string", MAX_STRING_LENGTH)) { 1781 psFree(object); 1782 exit(EXIT_FAILURE); 1783 } 1784 if (strncmp(object->recipe, "a string", MAX_STRING_LENGTH)) { 1785 psFree(object); 1786 exit(EXIT_FAILURE); 1787 } 1788 if (!object->bg == 64.64) { 1789 psFree(object); 1790 exit(EXIT_FAILURE); 1791 } 1792 if (!object->bg_stdev == 64.64) { 1793 psFree(object); 1794 exit(EXIT_FAILURE); 1795 } 1796 if (!object->bg_mean_stdev == 64.64) { 1797 psFree(object); 1798 exit(EXIT_FAILURE); 1799 } 1800 if (!object->sigma_ra == 32.32) { 1801 psFree(object); 1802 exit(EXIT_FAILURE); 1803 } 1804 if (!object->sigma_dec == 32.32) { 1805 psFree(object); 1806 exit(EXIT_FAILURE); 1807 } 1808 if (!object->nastro == -32) { 1809 psFree(object); 1810 exit(EXIT_FAILURE); 1811 } 1812 if (strncmp(object->b1_uri, "a string", MAX_STRING_LENGTH)) { 1813 psFree(object); 1814 exit(EXIT_FAILURE); 1815 } 1816 if (strncmp(object->b2_uri, "a string", MAX_STRING_LENGTH)) { 1817 psFree(object); 1818 exit(EXIT_FAILURE); 1819 } 1820 if (!object->p2_version == -32) { 1821 psFree(object); 1822 exit(EXIT_FAILURE); 1823 } 1824 if (!object->p3_version == -32) { 1825 psFree(object); 1826 exit(EXIT_FAILURE); 1827 } 1828 1829 psFree(object); 1830 } 1831 1832 { 1833 psMetadata *md; 1712 1834 detRunRow *object; 1713 1835 -
trunk/ippdb/tests/pop.c
r9242 r9301 500 500 { 501 501 psDB *dbh; 502 char exp_tag[256]; 503 char uri[256]; 504 char recipe[256]; 505 psF64 bg; 506 psF64 bg_stdev; 507 psF64 bg_mean_stdev; 508 psF32 sigma_ra; 509 psF32 sigma_dec; 510 psS32 nastro; 511 char b1_uri[256]; 512 char b2_uri[256]; 513 psS32 p2_version; 514 psS32 p3_version; 515 516 dbh = psDBInit("localhost", "test", NULL, "test"); 517 if (!dbh) { 518 exit(EXIT_FAILURE); 519 } 520 521 if (!p3ProcessedExpPop(dbh, (char **)&exp_tag, (char **)&uri, (char **)&recipe, &bg, &bg_stdev, &bg_mean_stdev, &sigma_ra, &sigma_dec, &nastro, (char **)&b1_uri, (char **)&b2_uri, &p2_version, &p3_version)) { 522 exit(EXIT_FAILURE); 523 } 524 525 psDBCleanup(dbh); 526 } 527 528 { 529 psDB *dbh; 502 530 psS32 iteration; 503 531 char det_type[256]; -
trunk/ippdb/tests/popfits.c
r9149 r9301 596 596 } 597 597 598 if (!p3ProcessedExpPopFits(dbh, fits, 1)) { 599 exit(EXIT_FAILURE); 600 } 601 602 if (!psFitsClose(fits)) { 603 exit(EXIT_FAILURE); 604 } 605 606 psDBCleanup(dbh); 607 } 608 609 { 610 psDB *dbh; 611 psFits *fits; 612 613 dbh = psDBInit("localhost", "test", NULL, "test"); 614 if (!dbh) { 615 exit(EXIT_FAILURE); 616 } 617 618 // allocate a temp 619 fits = psFitsOpen(TMP_FILENAME, "w"); 620 if (!fits) { 621 exit(EXIT_FAILURE); 622 } 623 598 624 if (!detRunPopFits(dbh, fits, 1)) { 599 625 exit(EXIT_FAILURE); -
trunk/ippdb/tests/popobject.c
r9149 r9301 403 403 { 404 404 psDB *dbh; 405 p3ProcessedExpRow *object; 406 407 dbh = psDBInit("localhost", "test", NULL, "test"); 408 if (!dbh) { 409 exit(EXIT_FAILURE); 410 } 411 412 object = p3ProcessedExpPopObject(dbh); 413 if (!object) { 414 exit(EXIT_FAILURE); 415 } 416 417 psFree(object); 418 psDBCleanup(dbh); 419 } 420 421 { 422 psDB *dbh; 405 423 detRunRow *object; 406 424 -
trunk/ippdb/tests/selectrowsfits.c
r9149 r9301 505 505 } 506 506 507 if (!p3ProcessedExpSelectRowsFits(dbh, fits, NULL, 1)) { 508 exit(EXIT_FAILURE); 509 } 510 511 psFree(fits); 512 psDBCleanup(dbh); 513 } 514 515 { 516 psDB *dbh; 517 psFits *fits; 518 519 dbh = psDBInit("localhost", "test", NULL, "test"); 520 if (!dbh) { 521 exit(EXIT_FAILURE); 522 } 523 524 fits = psFitsOpen(TMP_FILENAME, "w"); 525 if (!fits) { 526 exit(EXIT_FAILURE); 527 } 528 507 529 if (!detRunSelectRowsFits(dbh, fits, NULL, 1)) { 508 530 exit(EXIT_FAILURE);
Note:
See TracChangeset
for help on using the changeset viewer.
