Index: trunk/ippToPsps/jython/stackbatch.py
===================================================================
--- trunk/ippToPsps/jython/stackbatch.py	(revision 31292)
+++ trunk/ippToPsps/jython/stackbatch.py	(revision 31298)
@@ -22,9 +22,23 @@
                "stack", 
                inputFile, 
-               "ThreePi") # TODO
+               "MD04") # TODO
 
        self.logger.info("StackBatch constructor. Creating batch from: '" + inputFile + "'")
 
+       # delete PSPS tables
+       self.dropTable("StackMeta")
+       self.dropTable("StackDetection")
+       self.dropTable("StackModelFit")
+       self.dropTable("StackApFlx")
+       self.dropTable("StackToImage")
+
+       # delete IPP tables
+       self.dropTable("SkyChip_psf")
+       self.dropTable("SkyChip_xsrc")
+       self.dropTable("SkyChip_xfit")
+       self.dropTable("SkyChip_xrad")
+
        # obs time makes no sense except for nightly stacks
+       self.logger.info("Stack type: " + self.header['STK_TYPE'])
        if self.header['STK_TYPE'] != "NIGHTLY_STACK": self.header['MJD-OBS'] = "-999"
 
@@ -324,4 +338,5 @@
         self.updateDataRelease("StackDetection")
         self.updateStackTypeID("StackDetection")
+        self.updateDvoIDs("StackDetection")
 
     '''
@@ -336,5 +351,8 @@
                DISTINCT IPP_IDET \
                FROM SkyChip_xrad"
-        self.localStmt.execute(sql)
+
+        try:
+            self.localStmt.execute(sql)
+        except: return
 
         # TODO temporarily loading 1st convolved fluxes into unconvolved fields
@@ -364,4 +382,5 @@
         self.updateDataRelease("StackApFlx")
         self.updateStackTypeID("StackApFlx")
+        self.updateDvoIDs("StackApFlx")
 
     '''
@@ -373,5 +392,9 @@
         # insert all the detections
         sql = "INSERT INTO StackModelFit (ippDetectID) SELECT DISTINCT IPP_IDET from SkyChip_xfit"
-        self.localStmt.execute(sql)
+        try:
+            self.localStmt.execute(sql)
+        except:
+            return
+
 
         # populate model parameters
@@ -388,4 +411,5 @@
         self.updateDataRelease("StackModelFit")
         self.updateStackTypeID("StackModelFit")
+        self.updateDvoIDs("StackModelFit")
 
     '''
@@ -420,4 +444,5 @@
 
     '''
+    Temporary hack to fudge some object IDs
     '''
     def fudgeIDs(self):
@@ -450,8 +475,11 @@
         self.setMinMaxObjID("StackDetection")
 
+
     '''
     Does the processing, i.e. pulling stuff from IPP tables into PSPS tables
     '''
     def populatePspsTables(self):
+
+        self.getIDsFromDVO(self.header['SOURCEID'], self.header['IMAGEID'])
 
         self.populateStackMeta()
@@ -461,9 +489,11 @@
         self.populateStackToImage()
 
+        self.setMinMaxObjID("StackDetection")
+
 
 logging.config.fileConfig("logging.conf")
 logger = logging.getLogger("stackbatch")
 logger.info("Starting")
-sky_id = 299 # TODO
+sky_id = 689 # TODO
 gpc1Db = Gpc1Db(logger)
 cmfFiles = gpc1Db.getStackStageCmfs(sky_id)
@@ -477,7 +507,5 @@
     stackBatch.importIppTables("")
     stackBatch.populatePspsTables()
-    stackBatch.fudgeIDs()
     stackBatch.reportNullsInAllPspsTables(False)
-    #    stackBatch.replaceAllPspsNulls("-999")  
     stackBatch.exportPspsTablesToFits()
     stackBatch.writeBatchManifest()
