- Timestamp:
- Mar 5, 2013, 2:23:09 PM (13 years ago)
- Location:
- branches/eam_branches/ipp-20130207/ippToPsps
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
jython/ipptopspsdb.py (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130207/ippToPsps
- Property svn:mergeinfo changed
/trunk/ippToPsps (added) merged: 35170-35171,35173-35175,35177-35179,35181-35188,35190-35191,35203-35204,35216-35218,35222-35226,35232-35233
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20130207/ippToPsps/jython/ipptopspsdb.py
r35097 r35235 4 4 import sys 5 5 import os 6 import math 6 7 import logging 7 8 … … 997 998 998 999 self.skychunk.boxSize = rs.getDouble(10) 999 self.skychunk.halfBox = self.skychunk.boxSize/2.01000 self.skychunk.boxSizeWithBorder = self.skychunk.boxSize + (self.skychunk.BORDER * 2)1000 # self.skychunk.halfBox = self.skychunk.boxSize/2.0 1001 # self.skychunk.boxSizeWithBorder = self.skychunk.boxSize + (self.skychunk.BORDER * 2) 1001 1002 1002 1003 self.skychunk.basePath = rs.getString(11) … … 1031 1032 ''' 1032 1033 Gets id of box with these coords 1034 XXX EAM : this code implies we can have multiple boxes at the same location for the same 1035 XXX EAM : skychunk distinguished by having different sizes. that seems quite bad 1033 1036 ''' 1034 1037 def getBoxId(self, ra, dec): 1038 1039 # for the float comparison, need to use a small window 1040 minRA = ra - 0.01 1041 maxRA = ra + 0.01 1042 minDEC = dec - 0.01 1043 maxDEC = dec + 0.01 1035 1044 1036 1045 sql = "SELECT id FROM box \ 1037 1046 WHERE skychunk = '" + self.skychunk.name + "' \ 1038 AND ra_center = " + str(ra) + " \ 1039 AND dec_center = " + str(dec) + " \ 1040 AND box_side = " + str(self.skychunk.boxSize) 1041 1047 AND ra_center BETWEEN " + str(minRA) + " AND " + str(maxRA) + " \ 1048 AND dec_center BETWEEN " + str(minDEC) + " AND " + str(maxDEC) 1049 1050 # AND box_side = " + str(self.skychunk.boxSize) 1051 1052 # print "sql for boxid: ", sql 1053 1042 1054 id = -1 1043 1055 try: … … 1079 1091 Inserts new box into box table. If it already exisits, it returns existing box id 1080 1092 ''' 1081 def isBoxIngested(self, id ):1093 def isBoxIngested(self, id, host): 1082 1094 1083 1095 # set the field 'ingested' to 1 for this box … … 1088 1100 print "no matching boxes for ", str(id) 1089 1101 raise 1090 status = rs.getInt(1) 1102 value = rs.getString(1) 1103 except: 1104 print "failed to find box for ", str(id) 1105 raise 1106 1107 if value == host: 1108 return 1 1109 1110 if value == "none": 1111 return 0 1112 1113 if value is None: 1114 return 0 1115 1116 print "box ingested host ", value, " does not match db host ", host 1117 raise 1118 1119 ''' 1120 Inserts new box into box table. If it already exisits, it returns existing box id 1121 ''' 1122 def setIngestedBox(self, id, host): 1123 1124 # set the field 'ingested' to 1 for this box 1125 sql = "update box set ingested = '" + host + "' where id = " + str(id) 1126 try: 1127 self.execute(sql) 1091 1128 except: 1092 1129 print "failed to set box ", str(id), "as ingested" 1093 1130 raise 1094 1131 1095 return status 1096 ''' 1097 Inserts new box into box table. If it already exisits, it returns existing box id 1098 ''' 1099 def setIngestedBox(self, id): 1132 ''' 1133 Clear ingested flag for boxes owned by this host 1134 ''' 1135 def clearIngestedBoxes(self, host): 1100 1136 1101 1137 # set the field 'ingested' to 1 for this box 1102 sql = "update box set ingested = 1 where id = " + str(id)1138 sql = "update box set ingested = 'none' where ingested = '" + host + "'" 1103 1139 try: 1104 1140 self.execute(sql) 1105 1141 except: 1106 print "failed to set box ", str(id), "as ingested"1142 print "failed to clear ingested state for boxes owned by host ", host 1107 1143 raise 1108 1144 1109 1145 ''' 1110 Inserts new box into box table. If it already exisits, it returns existing box id1111 '''1112 def clearIngestedBoxes(self):1113 1114 # set the field 'ingested' to 1 for this box1115 sql = "update box set ingested = 0"1116 try:1117 self.execute(sql)1118 except:1119 print "failed to clear boxes as ingested"1120 raise1121 1122 '''1123 1146 Inserts new box ids into the pending table 1124 1147 ''' 1125 1148 def insertPending(self, box_id, batchType, ids): 1149 1150 # print "starting insert pending" 1126 1151 1127 1152 # first delete old pending items … … 1129 1154 WHERE box_id = " + str(box_id) + " \ 1130 1155 AND batch_type = '" + batchType + "'") 1156 1157 # print "deleted old items" 1131 1158 1132 1159 for id in ids: … … 1136 1163 (" + str(box_id) + ", '" + batchType + "', " + str(id) + ")" 1137 1164 1165 # print "sql: ", sql 1138 1166 self.execute(sql) 1139 1167 … … 1168 1196 rs.close() 1169 1197 except: 1170 self.logger.errorPair("No free stripes", "trying to s hare withother client...")1198 self.logger.errorPair("No free stripes", "trying to steal boxes from other client...") 1171 1199 sql = "SELECT ra_center, COUNT(*) AS numPending\ 1172 1200 FROM box \ … … 1184 1212 rs.close() 1185 1213 except: 1186 self.logger.errorPair("No available stripes to share", "no stripe obtained") 1214 self.logger.errorPair("No outstanding boxes to steal", "no stripe obtained") 1215 1216 # tests against ra_center need to use a finite box 1217 minRA = raCenter - 0.01 1218 maxRA = raCenter + 0.01 1187 1219 1188 1220 self.logger.infoPair("Using RA stripe", "%f" % raCenter) … … 1190 1222 FROM box \ 1191 1223 JOIN pending ON (id = box_id) \ 1192 WHERE ra_center = " + str(raCenter) + " \1224 WHERE ra_center BETWEEN " + str(minRA) + " AND " + str(maxRA) + " \ 1193 1225 AND batch_type = '" + batchType + "' \ 1194 1226 AND skychunk = '" + self.skychunk.name + "' \ … … 1203 1235 1204 1236 self.registerStripe(host, pid, raCenter) 1237 1238 self.unlockTables() 1239 1240 return ids 1241 1242 ''' 1243 Returns ids for all boxes with pending items in a stripe of RA not already being processed 1244 by another client. If none are available, then it uses the stripe already used by another 1245 client that has the most pending items 1246 ''' 1247 def getStripeBoxIdsAnyBatch(self, host, pid): 1248 1249 self.execute("LOCK TABLES box READ, pending READ, stripe WRITE, clients WRITE") 1250 1251 ids = [] 1252 raCenter = -1.0 1253 sql = "SELECT ra_center \ 1254 FROM box \ 1255 JOIN pending ON (id = box_id) \ 1256 WHERE skychunk = '" + self.skychunk.name + "' \ 1257 AND ra_center NOT IN \ 1258 (SELECT ra_center \ 1259 FROM stripe \ 1260 WHERE skychunk = '" + self.skychunk.name + "') \ 1261 GROUP BY ra_center LIMIT 1" 1262 1263 try: 1264 rs = self.executeQuery(sql) 1265 rs.first() 1266 raCenter = rs.getFloat(1) 1267 rs.close() 1268 except: 1269 self.logger.errorPair("No free stripes", "trying to steal boxes from other client...") 1270 sql = "SELECT ra_center, COUNT(*) AS numPending\ 1271 FROM box \ 1272 JOIN pending ON (id = box_id) \ 1273 WHERE skychunk = '" + self.skychunk.name + "' \ 1274 GROUP BY ra_center \ 1275 ORDER BY numPending \ 1276 DESC LIMIT 1" 1277 1278 try: 1279 rs = self.executeQuery(sql) 1280 rs.first() 1281 raCenter = rs.getFloat(1) 1282 rs.close() 1283 except: 1284 self.logger.errorPair("No outstanding boxes to steal", "no stripe obtained") 1285 1286 # tests against ra_center need to use a finite box 1287 minRA = raCenter - 0.01 1288 maxRA = raCenter + 0.01 1289 1290 self.logger.infoPair("Using RA stripe", "%f" % raCenter) 1291 sql = "SELECT DISTINCT id \ 1292 FROM box \ 1293 JOIN pending ON (id = box_id) \ 1294 WHERE ra_center BETWEEN " + str(minRA) + " AND " + str(maxRA) + " \ 1295 AND skychunk = '" + self.skychunk.name + "' \ 1296 ORDER BY dec_center DESC" 1297 1298 try: 1299 rs = self.executeQuery(sql) 1300 while (rs.next()): ids.append(rs.getInt(1)) 1301 rs.close() 1302 except: 1303 self.logger.errorPair("Can't get stripe boxes", sql) 1205 1304 1206 1305 self.unlockTables() … … 1250 1349 boxDim['DEC'] = rs.getFloat(2) 1251 1350 boxDim['SIDE'] = rs.getFloat(3) 1351 1352 # SIDE is the linear full-width of the box 1353 1354 # XXX EAM : need to do something special at the poles... 1355 if (boxDim['DEC'] > 85): raise 1356 1357 # a given box centered at RA,DEC with (linear) size of SIDE has the following bounds 1358 dR = 0.5*boxDim['SIDE'] / math.cos(math.radians(boxDim['DEC'])) 1359 dD = 0.5*boxDim['SIDE'] 1360 1361 boxDim['minRA'] = boxDim['RA'] - dR 1362 boxDim['maxRA'] = boxDim['RA'] + dR 1363 boxDim['minDEC'] = boxDim['DEC'] - dD 1364 boxDim['maxDEC'] = boxDim['DEC'] + dD 1252 1365 1253 1366 return boxDim … … 1363 1476 Gets all items in the all_pending temporary table within the bounds of this box 1364 1477 ''' 1365 def getItemsInThisThisBox(self, ra, dec): 1366 1367 halfSide = self.skychunk.boxSize/2.0 1368 minRa = ra-halfSide 1369 maxRa = ra+halfSide 1370 minDec = dec-halfSide 1371 maxDec = dec+halfSide 1478 def getItemsInThisBox(self, minRA, maxRA, minDEC, maxDEC): 1479 1480 # the old linear size is ill-conceived 1481 ## XX halfSide = self.skychunk.boxSize/2.0 1482 ## XX minRa = ra-halfSide 1483 ## XX maxRa = ra+halfSide 1484 ## XX minDec = dec-halfSide 1485 ## XX maxDec = dec+halfSide 1372 1486 1373 1487 ids = [] … … 1375 1489 sql = "SELECT DISTINCT stage_id \ 1376 1490 FROM all_pending \ 1377 WHERE ra_bore BETWEEN " + str(minR a) + " AND " + str(maxRa) + " \1378 AND dec_bore BETWEEN " + str(minD ec) + " AND " + str(maxDec)1491 WHERE ra_bore BETWEEN " + str(minRA) + " AND " + str(maxRA) + " \ 1492 AND dec_bore BETWEEN " + str(minDEC) + " AND " + str(maxDEC) 1379 1493 1380 1494 try:
Note:
See TracChangeset
for help on using the changeset viewer.
