Index: trunk/ippToPsps/jython/detectionbatch.py
===================================================================
--- trunk/ippToPsps/jython/detectionbatch.py	(revision 31821)
+++ trunk/ippToPsps/jython/detectionbatch.py	(revision 31848)
@@ -3,4 +3,5 @@
 import os.path
 import sys
+import time
 import stilts
 from java.lang import *
@@ -32,6 +33,5 @@
                  gpc1Db,
                  ippToPspsDb,
-                 camID, 
-                 inputFile):
+                 camID):
 
        super(DetectionBatch, self).__init__(
@@ -42,9 +42,20 @@
                camID,
                "detection", 
-               inputFile, 
+               gpc1Db.getCameraStageSmf(camID),
                #"MD04") # TODO
                "3PI")
 
        if not self.everythingOK: return
+
+       # get camera meta data
+       meta = self.gpc1Db.getCameraStageMeta(self.id)
+       self.expID = meta[0];
+       self.expName = meta[1];
+       self.distGroup = meta[2];
+       self.analysisVer = meta[3];
+       self.bias = meta[4];
+       self.biasScat = meta[5];
+
+       if not self.analysisVer: self.analysisVer = -999
 
        # create an output filename, which is {expID}.FITS
@@ -89,10 +100,8 @@
         super(DetectionBatch, self).printMe()
 
-        self.logger.info("Cam ID:                 %d" % self.id)
-        self.logger.info("Exp ID:                 %d" % self.expID)
-        self.logger.info("Exp name:               %s" % self.expName)
-        self.logger.info("Distribution group:     %s" % self.distGroup)
-
-
+        self.logger.infoPair("Cam ID", "%d" % self.id)
+        self.logger.infoPair("Exp ID", "%d" % self.expID)
+        self.logger.infoPair("Exp name", "%s" % self.expName)
+        self.logger.infoPair("Distribution group", "%s" % self.distGroup)
 
     '''
@@ -100,5 +109,5 @@
     '''
     def populateFrameMeta(self):
-        self.logger.info("Procesing FrameMeta table")
+        self.logger.infoPair("Proccesing table", "FrameMeta")
 
         sql = "INSERT INTO FrameMeta (\
@@ -287,9 +296,9 @@
                ," + self.safeDictionaryAccess(header, 'CNAXIS1') + " \
                ," + self.safeDictionaryAccess(header, 'CNAXIS2') + " \
-               ," + str((float(self.safeDictionaryAccess(header, 'FWHM_MAJ')) + float(self.safeDictionaryAccess(header, 'FWHM_MIN')))/2.0) + " \
+               , ( " + self.safeDictionaryAccess(header, 'FWHM_MAJ') + " + " + self.safeDictionaryAccess(header, 'FWHM_MIN') + " ) / 2.0 \
                ," + self.safeDictionaryAccess(header, 'FWHM_MAJ') + " \
                ," + self.safeDictionaryAccess(header, 'FWHM_MIN') + " \
                ," + self.safeDictionaryAccess(header, 'ANGLE') + " \
-               ," + str((float(self.safeDictionaryAccess(header, 'IQ_FW1')) + float(self.safeDictionaryAccess(header, 'IQ_FW2')))/2.0) + " \
+               , ( " + self.safeDictionaryAccess(header, 'IQ_FW1') + " + " + self.safeDictionaryAccess(header, 'IQ_FW2') + " ) / 2.0  \
                ," + self.safeDictionaryAccess(header, 'IQ_FW1') + " \
                ," + self.safeDictionaryAccess(header, 'IQ_FW2') + " \
@@ -336,5 +345,7 @@
                )"
 
-        self.scratchDb.execute(sql)
+        try: self.scratchDb.execute(sql)
+        except: print sql
+
         self.scratchDb.updateFilterID(tableName, self.filter)
         self.scratchDb.updateAllRows(tableName, "calibModNum", str(self.calibModNum))
@@ -357,5 +368,5 @@
 
         # insert all detections into table
-        sql = "INSERT INTO " + tableName + " ( \
+        sql = "INSERT IGNORE INTO " + tableName + " ( \
                ippDetectID \
                ,xPos \
@@ -483,6 +494,6 @@
     def alterPspsTables(self):
 
-        self.logger.info("Altering PSPS tables")
-        self.logger.info("Creating indexes on PSPS tables")
+        self.logger.debug("Altering PSPS tables")
+        self.logger.debug("Creating indexes on PSPS tables")
         self.scratchDb.makeColumnUnique("Detection", "objID")
         self.scratchDb.makeColumnPrimaryKey("Detection", "ippDetectID")
@@ -493,5 +504,5 @@
     def indexIppTables(self):
 
-        self.logger.info("Creating indexes on IPP tables")
+        self.logger.infoPair("Creating indexes on", "IPP tables")
 
         for x in range(self.startX, self.endX):
@@ -567,8 +578,7 @@
         imageIDs = {}
 
-        file = open(self.inputFitsPath, 'r')
-
         # loop through all OTAs and populate ImageMeta extensions
-        self.logger.info("Reading all fits headers and populating ImageMeta tables")
+        self.logger.infoPair("Reading", "FITS headers")
+        self.logger.infoPair("Populating table", "ImageMeta")
         for x in range(self.startX, self.endX):
             for y in range(self.startY, self.endY):
@@ -583,9 +593,8 @@
                 
                 # load corresponding header into memory
-                header = self.findAndReadFITSHeader(ota + ".hdr", file)
+                header = self.fits.findAndReadHeader(ota + ".hdr")
                 if not header:
                     self.logger.error("No header found for OTA " + ota)
                     continue
-
 
                 # store sourceID/imageID combo in Db so DVO can look up later
@@ -626,5 +635,5 @@
                 if ota not in sourceIDs: continue
 
-                self.logger.info("******************* Dealing with OTA " + ota + " *******************")
+                self.logger.infoMiniSeparator()
 
                 # populate remainder of tables
@@ -639,5 +648,5 @@
                 # check we have something in this Detection table
                 if self.scratchDb.getRowCount("Detection_" + ota) < 1:
-                    self.logger.info("Empty tables for ota " + ota + ". Skipping.")
+                    self.logger.infoPair("Skipping empty table for ota", ota)
                     continue;
 
@@ -682,23 +691,4 @@
 
     '''
-    Checks whether this batch has already been processed and published
-    '''
-    def alreadyProcessed(self):
-
-        meta = self.gpc1Db.getCameraStageMeta(self.id)
-        self.expID = meta[0];
-        self.expName = meta[1];
-        self.distGroup = meta[2];
-        self.analysisVer = meta[3];
-        self.bias = meta[4];
-        self.biasScat = meta[5];
-
-        if not self.analysisVer: self.analysisVer = -999
-
-        #return self.ippToPspsDb.alreadyProcessed("detection", "exp_id", self.expID)
-        return 0
-
-
-    '''
     Overriding this method
     '''
@@ -728,30 +718,2 @@
        return super(DetectionBatch, self).exportPspsTablesToFits("([a-zA-Z]+)")
 
-
-logging.config.fileConfig("logging.conf")
-logger = logging.getLogger("ippToPspsLog")
-logger.setLevel(logging.INFO)
-logger.info("Starting")
-
-configDoc = ElementTree(file="config.xml")
-dvoGpc1Label = configDoc.find("dvo/gpc1Label").text
-
-gpc1Db = Gpc1Db(logger)
-ippToPspsDb = IppToPspsDb(logger)
-
-ids = gpc1Db.getIDsInThisDVODbForThisStage(dvoGpc1Label, "cam")
-for id in ids:
-
-    if not int(configDoc.find("options/force").text) and ippToPspsDb.alreadyProcessed(id): continue
-
-    file = gpc1Db.getCameraStageSmf(id)
-
-    detectionBatch = DetectionBatch(logger,
-                                    configDoc,
-                                    gpc1Db,
-                                    ippToPspsDb,
-                                    id, 
-                                    file)
-    detectionBatch.printMe()
-    detectionBatch.run()
-
