Changeset 12200 for trunk/ippTools/src/camtool.c
- Timestamp:
- Mar 2, 2007, 4:21:29 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/camtool.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/camtool.c
r12189 r12200 23 23 24 24 #include <stdlib.h> 25 #include <inttypes.h> 25 26 26 27 #include "pxtools.h" 27 28 #include "camtool.h" 28 29 30 static bool queueMode(pxConfig *config); 29 31 static bool pendingexpMode(pxConfig *config); 30 32 static bool pendingimfileMode(pxConfig *config); … … 54 56 55 57 switch (config->mode) { 56 MODECASE(CAMTOOL_MODE_PENDINGEXP, pendingexpMode); 57 MODECASE(CAMTOOL_MODE_PENDINGIMFILE, pendingimfileMode); 58 MODECASE(CAMTOOL_MODE_ADDPROCESSEDEXP, addprocessedexpMode); 59 MODECASE(CAMTOOL_MODE_PROCESSEDEXP, processedexpMode); 60 MODECASE(CAMTOOL_MODE_UPDATEPROCESSEDEXP,updateprocessedexpMode); 61 MODECASE(CAMTOOL_MODE_BLOCK, blockMode); 62 MODECASE(CAMTOOL_MODE_MASKED, maskedMode); 63 MODECASE(CAMTOOL_MODE_UNBLOCK, unblockMode); 58 MODECASE(CAMTOOL_MODE_QUEUE, queueMode); 59 MODECASE(CAMTOOL_MODE_PENDINGEXP, pendingexpMode); 60 MODECASE(CAMTOOL_MODE_PENDINGIMFILE, pendingimfileMode); 61 MODECASE(CAMTOOL_MODE_ADDPROCESSEDEXP, addprocessedexpMode); 62 MODECASE(CAMTOOL_MODE_PROCESSEDEXP, processedexpMode); 63 MODECASE(CAMTOOL_MODE_UPDATEPROCESSEDEXP, updateprocessedexpMode); 64 MODECASE(CAMTOOL_MODE_BLOCK, blockMode); 65 MODECASE(CAMTOOL_MODE_MASKED, maskedMode); 66 MODECASE(CAMTOOL_MODE_UNBLOCK, unblockMode); 64 67 default: 65 68 psAbort("invalid option (this should not happen)"); … … 81 84 82 85 exit(exit_status); 86 } 87 88 89 #define ADDPARAMSTR(from, to, name) \ 90 { \ 91 bool status = false; \ 92 psString str = psMetadataLookupStr(&status, from, "-" name); \ 93 if (!status) { \ 94 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -" name); \ 95 return false; \ 96 } \ 97 if (str) { \ 98 if (!psMetadataAddStr(to, PS_LIST_TAIL, name, 0, "==", str)) { \ 99 psError(PS_ERR_UNKNOWN, false, "failed to add item " name); \ 100 psFree(to); \ 101 return false; \ 102 } \ 103 } \ 104 } 105 106 107 #define ADDPARAMF(from, to, type, name) \ 108 { \ 109 bool status = false; \ 110 ps##type var = psMetadataLookup##type(&status, from, "-" name); \ 111 if (!status) { \ 112 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -" name); \ 113 return false; \ 114 } \ 115 if (!isnan(var)) { \ 116 if (!psMetadataAdd##type(to, PS_LIST_TAIL, #name, 0, "==", var)) { \ 117 psError(PS_ERR_UNKNOWN, false, "failed to add item " name); \ 118 psFree(to); \ 119 return false; \ 120 } \ 121 } \ 122 } 123 124 static bool queueMode(pxConfig *config) 125 { 126 PS_ASSERT_PTR_NON_NULL(config, NULL); 127 128 psMetadata *where = psMetadataAlloc(); 129 { 130 bool status = false; 131 psString var = psMetadataLookupStr(&status, config->args, "-chip_id"); 132 if (!status) { 133 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -chip_id"); 134 return false; 135 } 136 if (var) { 137 if (!psMetadataAddS64(where, PS_LIST_TAIL, "chip_id", 0, "==", (psS64)atoll(var))) { 138 psError(PS_ERR_UNKNOWN, false, "failed to add item chip_id"); 139 psFree(where); 140 return false; 141 } 142 } 143 } 144 145 ADDPARAMSTR(config->args, where, "exp_tag"); 146 ADDPARAMSTR(config->args, where, "exp_id"); 147 ADDPARAMSTR(config->args, where, "inst"); 148 ADDPARAMSTR(config->args, where, "telescope"); 149 ADDPARAMSTR(config->args, where, "dateobs"); 150 ADDPARAMSTR(config->args, where, "exp_type"); 151 ADDPARAMSTR(config->args, where, "imfiles"); 152 ADDPARAMSTR(config->args, where, "workdir"); 153 ADDPARAMSTR(config->args, where, "filter"); 154 ADDPARAMF(config->args, where, F32, "airmass"); 155 ADDPARAMF(config->args, where, F32, "ra"); 156 ADDPARAMF(config->args, where, F32, "decl"); 157 ADDPARAMF(config->args, where, F32, "exp_time"); 158 ADDPARAMF(config->args, where, F64, "bg"); 159 ADDPARAMF(config->args, where, F64, "bg_stdev"); 160 ADDPARAMF(config->args, where, F64, "bg_mean_stdev"); 161 ADDPARAMF(config->args, where, F64, "alt"); 162 ADDPARAMF(config->args, where, F64, "az"); 163 ADDPARAMF(config->args, where, F32, "ccd_temp"); 164 ADDPARAMF(config->args, where, F64, "posang"); 165 ADDPARAMSTR(config->args, where, "object"); 166 167 if (where->list->n < 1) { 168 psFree(where); 169 where = NULL; 170 } 171 172 bool status = false; 173 psString label = psMetadataLookupStr(&status, config->args, "-set_label"); 174 if (!status) { 175 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_label"); 176 return false; 177 } 178 179 psString recipe = psMetadataLookupStr(&status, config->args, "-set_recipe"); 180 if (!status) { 181 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_recipe"); 182 return false; 183 } 184 185 psString expgroup = psMetadataLookupStr(&status, config->args, "-set_expgroup"); 186 if (!status) { 187 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_expgroup"); 188 return false; 189 } 190 191 psString dvodb = psMetadataLookupStr(&status, config->args, "-set_dvodb"); 192 if (!status) { 193 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_dvodb"); 194 return false; 195 } 196 197 // find the chipProcessedExp exposures that we want to queue up. 198 psString query = psStringCopy("SELECT * FROM chipProcessedExp"); 199 200 if (where) { 201 psString whereClause = psDBGenerateWhereSQL(where, "chipProcessedExp"); 202 psFree(where); 203 psStringAppend(&query, " %s", whereClause); 204 psFree(whereClause); 205 } 206 207 if (!p_psDBRunQuery(config->dbh, query)) { 208 psError(PS_ERR_UNKNOWN, false, "database error"); 209 psFree(query); 210 return false; 211 } 212 psFree(query); 213 214 psArray *output = p_psDBFetchResult(config->dbh); 215 if (!output) { 216 psError(PS_ERR_UNKNOWN, false, "database error"); 217 return false; 218 } 219 if (!psArrayLength(output)) { 220 psTrace("chiptool", PS_LOG_INFO, "no rows found"); 221 psFree(output); 222 return true; 223 } 224 225 if (!psDBTransaction(config->dbh)) { 226 psError(PS_ERR_UNKNOWN, false, "database error"); 227 psFree(output); 228 return false; 229 } 230 231 // would could do this "all in the database" if we didn't want the option 232 // of changing the label/recipe/expgroup/dvodb/etc. So we're pulling the 233 // data out so we have the option of changing these values or leaving the 234 // old values in place (i.e., passing the values through). 235 236 // loop over our list of chipProcessedExp rows 237 for (long i = 0; i < psArrayLength(output); i++) { 238 psMetadata *md = output->data[i]; 239 240 chipProcessedExpRow *row = chipProcessedExpObjectFromMetadata(md); 241 if (!row) { 242 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipProcessedExp"); 243 psFree(output); 244 return false; 245 } 246 247 // queue the exp 248 if (!camQueueChipID(config, 249 row->chip_id, 250 label ? label : row->label, 251 recipe ? recipe : row->recipe, 252 expgroup ? expgroup : row->expgroup, 253 dvodb ? dvodb : row->dvodb 254 )) { 255 if (!psDBRollback(config->dbh)) { 256 psError(PS_ERR_UNKNOWN, false, "database error"); 257 } 258 psError(PS_ERR_UNKNOWN, false, 259 "failed to trying to queue chip_id: %" PRId64, row->chip_id); 260 psFree(row); 261 psFree(output); 262 return false; 263 } 264 psFree(row); 265 } 266 psFree(output); 267 268 if (!psDBCommit(config->dbh)) { 269 psError(PS_ERR_UNKNOWN, false, "database error"); 270 return false; 271 } 272 273 return true; 83 274 } 84 275
Note:
See TracChangeset
for help on using the changeset viewer.
