IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 19, 2012, 5:24:19 PM (14 years ago)
Author:
mhuber
Message:

merging latest r34040 trunk changes to branch

Location:
branches/meh_branches/ppstack_test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/meh_branches/ppstack_test

  • branches/meh_branches/ppstack_test/ippToPsps/jython/loader.py

    r33415 r34041  
    1616from datastore import Datastore
    1717from batch import Batch
    18 from dvo import Dvo
     18from dvodetections import DvoDetections
    1919
    2020from initbatch import InitBatch
    2121from stackbatch import StackBatch
    2222from detectionbatch import DetectionBatch
     23from objectbatch import ObjectBatch
    2324
    2425'''
     
    3132    '''
    3233    def __init__(self, argv):
    33         super(Loader, self).__init__(argv)
     34        super(Loader, self).__init__(argv, 1, 1)
    3435
    3536        # create gpc1 database objects
     
    4445                self.scratchDb.disconnect()
    4546                continue
    46             self.logger.infoPair("Using scratch Db", self.scratchDb.dbName)
    4747            break
    4848
    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 object
    54         self.dvo.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)
    5555
    5656        # if an IN batch is requested, create and quit
    5757        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)
    5959           if batchID > 0:
    6060               batch = InitBatch(self.logger,
     
    6565                       batchID)
    6666               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               
    6871           self.exitProgram("init batch created")
    6972   
    7073
    71         # set a poll time of about 1 minutes
     74        # set a poll time of about 1 minute
    7275        self.parsePollTimeArg("0.0166")
    7376
     
    7578
    7679    '''
    77     Overrides base-class version
     80    Overrides base-class version so we can ensure our scratch Db is using the right DVO Db
    7881    '''
    7982    def refreshConfig(self):
    8083
    8184        ret = super(Loader, self).refreshConfig()
    82         self.dvo = Dvo(self.logger, self.config)
    83         try: self.dvo.setScratchDb(self.scratchDb.dbName)
    84         except: pass
    85         self.datastore = 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)
    8689
    8790        return ret
    8891
    8992    '''
     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    '''
    90107    Main processing loop
    91108    '''
    92109    def run(self):
    93110
     111        if not self.scratchDb.connected: return
     112
     113        numAttempts = 0
    94114        while True:
    95115
    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               
    115143                    if len(ids) < 1:
    116144                        self.logger.debugPair("No " + batchType + " items found in this box", "skipping")
    117145                        continue
    118            
     146               
    119147                    self.logger.infoSeparator()
     148                    self.logger.infoTitle("New box")
    120149                    self.logger.infoPair("Box dimensions", "%.1f / %.1f / %.1f" % (boxDim['RA'], boxDim['DEC'], boxDim['SIDE']))
    121150                    self.logger.infoPair(batchType + " items found in this box", "%d" % len(ids))
    122151                    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 = 999999999
    128                     else: smfsPerGB = len(ids)/sizeToBeIngested
    129                     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                             continue
    137152     
    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               
    141172                    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
    146179
    147180       
     
    158191        for id in ids:
    159192   
    160             batchID = self.ippToPspsDb.createNewBatch(batchType, id, self.config)
     193            batchID = self.ippToPspsDb.createNewBatch(batchType, id)
    161194           
    162195            if batchID < 0:
     
    165198   
    166199            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
    191241   
    192242            self.ippToPspsDb.lockBatchTable()
    193243   
    194244            self.logger.infoSeparator()
    195    
    196             # if in test mode, then quit after one batch
    197             if self.config.test: break
    198245   
    199246        self.ippToPspsDb.unlockTables()
    200247        self.logger.infoPair("Unattempted batches", "%d" % unattemptedCount)
     248
     249        return True
    201250   
    202251    '''
     
    204253    '''
    205254    def printUsage(self):
    206         super(Cleanup, self).printUsage()
    207         print " [init]"
     255        super(Cleanup, self).printUsage("<[init]>")
    208256
    209257   
     
    214262    loader = Loader(sys.argv)
    215263    loader.run()
    216     loader.exitProgram("finished")
     264    loader.exitProgram("completed")
    217265except Exception, e:
    218266    print str(e)
    219     traceback.print_exc()
     267    traceback.print_exc()
     268
Note: See TracChangeset for help on using the changeset viewer.