- Timestamp:
- Jun 19, 2012, 5:24:19 PM (14 years ago)
- Location:
- branches/meh_branches/ppstack_test
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippToPsps/jython/loader.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/meh_branches/ppstack_test
- Property svn:mergeinfo changed
-
branches/meh_branches/ppstack_test/ippToPsps/jython/loader.py
r33415 r34041 16 16 from datastore import Datastore 17 17 from batch import Batch 18 from dvo import Dvo18 from dvodetections import DvoDetections 19 19 20 20 from initbatch import InitBatch 21 21 from stackbatch import StackBatch 22 22 from detectionbatch import DetectionBatch 23 from objectbatch import ObjectBatch 23 24 24 25 ''' … … 31 32 ''' 32 33 def __init__(self, argv): 33 super(Loader, self).__init__(argv )34 super(Loader, self).__init__(argv, 1, 1) 34 35 35 36 # create gpc1 database objects … … 44 45 self.scratchDb.disconnect() 45 46 continue 46 self.logger.infoPair("Using scratch Db", self.scratchDb.dbName)47 47 break 48 48 49 if not self.scratchDb.connected: 50 self. logger.errorPair("Cannot connect to a", "scratch database")51 raise Exception("No scratch Db")52 53 # now pass scratch Db to dvo object54 self.d vo.setScratchDb(self.scratchDb.dbName)49 if not self.scratchDb.connected: 50 self.exitProgram("Cannot connect to a scratch database") 51 raise 52 53 # create Datastore objects 54 self.datastore = Datastore(self.logger, self.config, self.ippToPspsDb) 55 55 56 56 # if an IN batch is requested, create and quit 57 57 if len(sys.argv) > 2 and sys.argv[2] == "init": 58 batchID = self.ippToPspsDb.createNewBatch("IN", 0 , self.config)58 batchID = self.ippToPspsDb.createNewBatch("IN", 0) 59 59 if batchID > 0: 60 60 batch = InitBatch(self.logger, … … 65 65 batchID) 66 66 batch.run() 67 67 else: 68 self.logger.errorPair("Could not create batch ID", "%d" % batchID) 69 self.exitProgram("failed to create init batch") 70 68 71 self.exitProgram("init batch created") 69 72 70 73 71 # set a poll time of about 1 minute s74 # set a poll time of about 1 minute 72 75 self.parsePollTimeArg("0.0166") 73 76 … … 75 78 76 79 ''' 77 Overrides base-class version 80 Overrides base-class version so we can ensure our scratch Db is using the right DVO Db 78 81 ''' 79 82 def refreshConfig(self): 80 83 81 84 ret = super(Loader, self).refreshConfig() 82 self.dvo = Dvo(self.logger, self.config)83 try: self.dvo.setScratchDb(self.scratchDb.dbName)84 except: pass85 self.d atastore = Datastore(self.logger, self.config, self.ippToPspsDb)85 try: self.scratchDb 86 except: return ret 87 88 self.dvoDetections = DvoDetections(self.logger, self.config, self.scratchDb.dbName) 86 89 87 90 return ret 88 91 89 92 ''' 93 Overrides base_class version so we can break out of processing loops if the config changes 94 ''' 95 def checkClientStatus(self): 96 97 oldConfigName = self.config.name 98 super(Loader, self).checkClientStatus() 99 if oldConfigName != self.config.name: 100 self.logger.infoPair("Config changed", "from '" + oldConfigName + "' to '" + self.config.name + "'") 101 self.config.printAll() 102 return False 103 104 return True 105 106 ''' 90 107 Main processing loop 91 108 ''' 92 109 def run(self): 93 110 111 if not self.scratchDb.connected: return 112 113 numAttempts = 0 94 114 while True: 95 115 96 boxIds = self.ippToPspsDb.getBoxIds(self.config.name) 97 98 self.logger.infoPair("Boxes with unprocessed data", "%d" % len(boxIds)) 99 100 for boxId in boxIds: 101 102 self.checkClientStatus() 103 104 # get box info. if boxes have changed, break and start again 105 try: 106 boxDim = self.ippToPspsDb.getBoxDimensions(boxId) 107 except: 108 self.logger.infoPair("Can't get details for this box", "%d" % boxId) 109 break 110 111 for batchType in self.config.batchTypes: 112 113 ids = self.ippToPspsDb.getPendingIds(boxId, batchType) 114 116 abort = False 117 for batchType in self.config.batchTypes: 118 119 # get a stripe's worth of box IDs 120 boxIds = self.ippToPspsDb.getStripeBoxIds(self.HOST, self.PID, batchType) 121 122 numAttempts += 1 123 124 self.logger.infoPair("Boxes with unprocessed data", "%d" % len(boxIds)) 125 126 if len(boxIds) > 0: numAttempts = 0 127 128 for boxId in boxIds: 129 130 if not self.checkClientStatus(): 131 abort = True 132 break 133 134 # get box info. if boxes have changed, break and start again 135 try: 136 boxDim = self.ippToPspsDb.getBoxDimensions(boxId) 137 except: 138 self.logger.infoPair("Can't get details for this box", "%d" % boxId) 139 break 140 141 ids = self.ippToPspsDb.getPendingIdsForThisBox(boxId, batchType) 142 115 143 if len(ids) < 1: 116 144 self.logger.debugPair("No " + batchType + " items found in this box", "skipping") 117 145 continue 118 146 119 147 self.logger.infoSeparator() 148 self.logger.infoTitle("New box") 120 149 self.logger.infoPair("Box dimensions", "%.1f / %.1f / %.1f" % (boxDim['RA'], boxDim['DEC'], boxDim['SIDE'])) 121 150 self.logger.infoPair(batchType + " items found in this box", "%d" % len(ids)) 122 151 boxSizeWithBorder = boxDim['SIDE'] + (self.config.BORDER * 2) 123 124 # look in DVO for this box (with extra border)125 self.dvo.setSkyAreaAsBox(boxDim['RA'], boxDim['DEC'], boxSizeWithBorder)126 sizeToBeIngested = self.dvo.getDiskSizeOfRegionsToBeIngested()127 if sizeToBeIngested == 0.0: smfsPerGB = 999999999128 else: smfsPerGB = len(ids)/sizeToBeIngested129 self.logger.infoPair("DVO to be ingested", "%.1f GB" % sizeToBeIngested)130 self.logger.infoPair("smfs-per-GB", "%.1f" % smfsPerGB)131 132 # should do we pre-ingest stuff from DVO?133 if smfsPerGB > 40:134 if not self.dvo.sync():135 self.logger.errorPair("Could not sync DVO with MySQL", "skipping")136 continue137 152 138 useFullTables = 1 139 else: useFullTables = 0 140 153 useFullTables = 0 154 if batchType != "OB": 155 # look in DVO for this box (with extra border) 156 self.logger.infoPair("Querying DVO for this sky area", "") 157 self.dvoDetections.setSkyAreaAsBox(boxDim['RA'], boxDim['DEC'], boxSizeWithBorder) 158 #self.dvoDetections.setSkyArea() 159 sizeToBeIngested = self.dvoDetections.getDiskSizeOfRegionsToBeIngested() 160 if sizeToBeIngested == 0.0: smfsPerGB = 999999999 161 else: smfsPerGB = len(ids)/sizeToBeIngested 162 self.logger.infoPair("DVO to be ingested", "%.1f GB" % sizeToBeIngested) 163 self.logger.infoPair("smfs-per-GB", "%.1f" % smfsPerGB) 164 # should do we pre-ingest stuff from DVO? 165 if batchType == 'P2' and smfsPerGB > 30: 166 if not self.dvoDetections.sync(): 167 self.logger.errorPair("Could not sync DVO with MySQL", "skipping") 168 continue 169 170 useFullTables = 1 171 141 172 self.logger.infoBool("Using pre-ingested DVO data?", useFullTables) 142 self.processTheseItems(batchType, ids, useFullTables) 143 144 self.checkClientStatus() 145 if not self.waitForPollTime(): break 173 if not self.processTheseItems(batchType, ids, useFullTables): 174 abort = True 175 break 176 177 if abort or not self.checkClientStatus(): abort = True 178 elif numAttempts > 1 and not self.waitForPollTime(): break 146 179 147 180 … … 158 191 for id in ids: 159 192 160 batchID = self.ippToPspsDb.createNewBatch(batchType, id , self.config)193 batchID = self.ippToPspsDb.createNewBatch(batchType, id) 161 194 162 195 if batchID < 0: … … 165 198 166 199 self.ippToPspsDb.unlockTables() 167 168 if batchType == "P2": 169 batch = DetectionBatch(self.logger, 170 self.config, 171 self.gpc1Db, 172 self.ippToPspsDb, 173 self.scratchDb, 174 id, 175 batchID, 176 useFullTables) 177 elif batchType == "ST": 178 batch = StackBatch(self.logger, 179 self.config, 180 self.gpc1Db, 181 self.ippToPspsDb, 182 self.scratchDb, 183 id, 184 batchID, 185 useFullTables) 186 187 batch.run() 188 189 # check that we should continue 190 self.checkClientStatus() 200 self.ippToPspsDb.deletePendingItem(batchType, id) 201 202 # catch any raised exceptions in batch constructors 203 try: 204 if batchType == "P2": 205 batch = DetectionBatch(self.logger, 206 self.config, 207 self.gpc1Db, 208 self.ippToPspsDb, 209 self.scratchDb, 210 id, 211 batchID, 212 useFullTables) 213 elif batchType == "ST": 214 batch = StackBatch(self.logger, 215 self.config, 216 self.gpc1Db, 217 self.ippToPspsDb, 218 self.scratchDb, 219 id, 220 batchID, 221 useFullTables) 222 223 elif batchType == "OB": 224 batch = ObjectBatch(self.logger, 225 self.config, 226 self.gpc1Db, 227 self.ippToPspsDb, 228 self.scratchDb, 229 id, 230 batchID, 231 useFullTables) 232 233 batch.run() 234 235 # if batch fails, ignore and move on to the next one 236 except: 237 self.logger.errorPair("Problem with this %s batch (%d)" % (batchType, id), "skipping") 238 pass 239 240 if not self.checkClientStatus(): return False 191 241 192 242 self.ippToPspsDb.lockBatchTable() 193 243 194 244 self.logger.infoSeparator() 195 196 # if in test mode, then quit after one batch197 if self.config.test: break198 245 199 246 self.ippToPspsDb.unlockTables() 200 247 self.logger.infoPair("Unattempted batches", "%d" % unattemptedCount) 248 249 return True 201 250 202 251 ''' … … 204 253 ''' 205 254 def printUsage(self): 206 super(Cleanup, self).printUsage() 207 print " [init]" 255 super(Cleanup, self).printUsage("<[init]>") 208 256 209 257 … … 214 262 loader = Loader(sys.argv) 215 263 loader.run() 216 loader.exitProgram(" finished")264 loader.exitProgram("completed") 217 265 except Exception, e: 218 266 print str(e) 219 traceback.print_exc() 267 traceback.print_exc() 268
Note:
See TracChangeset
for help on using the changeset viewer.
