Changeset 15499 for trunk/ippTools/src/magictool.c
- Timestamp:
- Nov 7, 2007, 6:06:07 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/magictool.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/magictool.c
r15348 r15499 31 31 #include "magictool.h" 32 32 33 static bool queueMode(pxConfig *config); 33 34 static psS64 definerunMode(pxConfig *config); 34 35 static bool updaterunMode(pxConfig *config); … … 63 64 64 65 switch (config->mode) { 66 MODECASE(MAGICTOOL_MODE_QUEUE, queueMode); 65 67 MODECASE(MAGICTOOL_MODE_DEFINERUN, definerunMode); 66 68 MODECASE(MAGICTOOL_MODE_UPDATERUN, updaterunMode); … … 92 94 93 95 exit(exit_status); 96 } 97 98 static bool queueMode(pxConfig *config) 99 { 100 PS_ASSERT_PTR_NON_NULL(config, false); 101 102 // create warped skycells temp table 103 { 104 char *query = 105 "CREATE TEMPORARY TABLE warpComplete\n" 106 " (warp_id BIGINT, skycell_id VARCHAR(64), tess_id VARCHAR(64),\n" 107 " PRIMARY KEY(warp_id, skycell_id, tess_id)) ENGINE=MEMORY\n"; 108 109 if (!p_psDBRunQuery(config->dbh, query)) { 110 psError(PS_ERR_UNKNOWN, false, "database error"); 111 return false; 112 } 113 } 114 115 // find warped skycells 116 { 117 psString query = pxDataGet("magictool_find_complete_warpruns.sql"); 118 if (!query) { 119 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 120 return false; 121 } 122 123 if (!p_psDBRunQuery(config->dbh, query)) { 124 psError(PS_ERR_UNKNOWN, false, "database error"); 125 psFree(query); 126 return false; 127 } 128 psFree(query); 129 } 130 131 // find the diff_id's of the warped skycells 132 { 133 psString query = pxDataGet("magictool_find_complete_diffed_exposures.sql"); 134 if (!query) { 135 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 136 return false; 137 } 138 139 if (!p_psDBRunQuery(config->dbh, query)) { 140 psError(PS_ERR_UNKNOWN, false, "database error"); 141 psFree(query); 142 return false; 143 } 144 psFree(query); 145 } 146 psArray *output = p_psDBFetchResult(config->dbh); 147 if (!output) { 148 psErrorCode err = psErrorCodeLast(); 149 switch (err) { 150 case PS_ERR_DB_CLIENT: 151 psError(PXTOOLS_ERR_SYS, false, "database error"); 152 case PS_ERR_DB_SERVER: 153 psError(PXTOOLS_ERR_PROG, false, "database error"); 154 default: 155 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 156 } 157 158 return false; 159 } 160 if (!psArrayLength(output)) { 161 psTrace("magictool", PS_LOG_INFO, "no rows found"); 162 psFree(output); 163 return true; 164 } 165 166 // pre-allocate enough hash buckets for 1 unique warp_id per row 167 psHash *groups = psHashAlloc(psArrayLength(output)); 168 // iterate over result set, and group by warp_id 169 for (long i = 0; i < psArrayLength(output); i++) { 170 // lookup the key we're grouping by 171 bool status = false; 172 psS64 warp_id = psMetadataLookupS64(&status, output->data[i], "warp_id"); 173 if (!status) { 174 psAbort("failed to lookup value for warp_id"); 175 } 176 177 psString key = psDBIntToString(warp_id); 178 // look to see if there is a bin for this key 179 psArray *groupBin = psHashLookup(groups, key); 180 if (!groupBin) { 181 // if not, create one 182 groupBin = psArrayAlloc(0); 183 psHashAdd(groups, key, groupBin); 184 } 185 psFree(key); 186 187 // add this row to the bin 188 psArrayAdd(groupBin, 0, output->data[i]); 189 psFree(groupBin); 190 } 191 psFree(output); 192 193 // create a magic run 194 psArray *grouped = psHashToArray(groups); 195 psFree(groups); 196 197 // iterate over array of grouped warp_ids 198 for (long i = 0; i < psArrayLength(grouped); i++) { 199 psArray *group = grouped->data[i]; 200 201 // create a new magicRun for this group 202 // XXX This need to have options passed through to it 203 204 magicRunRow *run = magicRunRowAlloc( 205 0, // ID 206 "reg", // state 207 NULL, // workdir 208 "dirty", // workdir_state 209 NULL, // label 210 NULL, // dvodb 211 NULL // registered 212 ); 213 if (!run) { 214 psAbort("failed to alloc magicRun object"); 215 } 216 if (!magicRunInsertObject(config->dbh, run)) { 217 psError(PS_ERR_UNKNOWN, false, "database error"); 218 psFree(run); 219 psFree(grouped); 220 return false; 221 } 222 223 // get the assigned warp_id 224 psS64 magic_id = psDBLastInsertID(config->dbh); 225 226 // insert all rows in this bin into the new magicRun 227 for (long j = 0; j < psArrayLength(group); j++) { 228 psMetadata *row = group->data[j]; 229 230 bool status = false; 231 psS64 diff_id = psMetadataLookupS64(&status, row, "diff_id"); 232 if (!status) { 233 psAbort("failed to lookup value for diff_id"); 234 } 235 psString node = psMetadataLookupStr(&status, row, "skycell_id"); 236 if (!status) { 237 psAbort("failed to lookup value for diff_id"); 238 } 239 240 if (!magicInputSkyfileInsert(config->dbh, 241 magic_id, 242 diff_id, 243 node)) { 244 psError(PS_ERR_UNKNOWN, false, "database error"); 245 psFree(grouped); 246 return false; 247 } 248 } 249 250 // set magicRun.state to 'run' 251 return setmagicRunState(config, magic_id, "run"); 252 } 253 254 return true; 94 255 } 95 256
Note:
See TracChangeset
for help on using the changeset viewer.
