Changeset 31434 for branches/czw_branch/20110406/ippToPsps/jython/gpc1db.py
- Timestamp:
- May 4, 2011, 3:20:38 PM (15 years ago)
- Location:
- branches/czw_branch/20110406
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippToPsps/jython/gpc1db.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20110406
- Property svn:mergeinfo changed
-
branches/czw_branch/20110406/ippToPsps/jython/gpc1db.py
r31253 r31434 7 7 import logging 8 8 9 from mysql import MySql 9 10 from java.sql import * 10 from xml.etree.ElementTree import ElementTree11 11 12 12 … … 14 14 Class for GPC1 database connectivity 15 15 ''' 16 class Gpc1Db(object): 17 18 driverName="com.mysql.jdbc.Driver" 16 class Gpc1Db(MySql): 19 17 20 18 ''' 21 19 Constructor 22 23 20 ''' 24 21 def __init__(self, logger): 25 26 # setup logging 27 self.logger = logger 28 self.logger.debug("Gpc1Db constructor") 29 30 # open config 31 doc = ElementTree(file="config.xml") 32 33 # set up JDBC connection 34 dbName = doc.find("gpc1database/name").text 35 dbHost = doc.find("gpc1database/host").text 36 dbUser = doc.find("gpc1database/user").text 37 dbPass = doc.find("gpc1database/password").text 38 self.url = "jdbc:mysql://"+dbHost+"/"+dbName+"?user="+dbUser+"&password="+dbPass 39 self.con = DriverManager.getConnection(self.url) 40 self.stmt = self.con.createStatement() 22 super(Gpc1Db, self).__init__(logger,"gpc1database") 41 23 42 24 ''' … … 46 28 47 29 self.logger.debug("Gpc1Db destructor") 48 self.stmt.close() 49 self.con.close() 50 51 52 ''' 53 Gets all cmf files for this sky_id. handles both absolute paths and neb paths 54 ''' 55 def getStackStageCmfs(self, skyID): 56 57 self.logger.debug("Querying for stack cmf files") 58 59 sql = "SELECT path_base, num_inputs \ 60 FROM staticskyResult \ 61 WHERE sky_id = %d" % skyID 62 try: 63 rs = self.stmt.executeQuery(sql) 64 rs.first() 65 except: 66 self.logger.exception("Can't query for stack cmfs") 30 31 ''' 32 Gets a list of ids in this DVO database for this stage, could be cam or staticsky (so far) 33 ''' 34 def getIDsInThisDVODbForThisStage(self, dvoDb, stage): 35 36 sql = "SELECT DISTINCT stage_id \ 37 FROM addRun \ 38 WHERE stage = '" + stage + "' \ 39 AND dvodb = '" + dvoDb + "'" 40 41 try: 42 rs = self.stmt.executeQuery(sql) 43 except: 44 self.logger.exception("Can't query for ids in DVO") 45 46 ids = [] 47 while (rs.next()): 48 ids.append(rs.getInt(1)) 49 50 rs.close() 51 52 self.logger.debug("Found %d items in DVO database '%s' for stage='%s'" % (len(ids), dvoDb, stage)) 53 54 return ids 55 56 ''' 57 Gets a list of PSPS image IDs for this stack ID 58 ''' 59 def getImageIDsForThisStackID(self, stackID): 60 61 self.logger.debug("Querying GPC1 for image IDs for stack ID: " + str(stackID)) 62 63 sql = "SELECT DISTINCT CONCAT(exp_id, SUBSTR(class_id, 3, 4)) FROM ( \ 64 SELECT DISTINCT exp_id,class_id \ 65 FROM warpSkyCellMap \ 66 JOIN warpRun USING(warp_id) \ 67 JOIN stackInputSkyfile USING(warp_id) \ 68 JOIN stackRun USING(stack_id,skycell_id) \ 69 JOIN fakeRun USING(fake_id) \ 70 JOIN camRun USING(cam_id) \ 71 JOIN chipRun USING(chip_id) \ 72 WHERE stackRun.stack_id = " + str(stackID) + ") AS a" 73 74 try: 75 rs = self.stmt.executeQuery(sql) 76 except: 77 self.logger.exception("Can't query for imageIDs") 78 79 imageIDs = [] 80 while (rs.next()): 81 imageIDs.append(rs.getString(1)) 82 rs.close() 83 84 return imageIDs 85 86 ''' 87 Gets some stack-stage meta data for this sky_id # TODO this SQL could surely be improved 88 ''' 89 def getStackStageMeta(self, skyID, filter): 90 91 self.logger.debug("Querying GPC1 for stack meta data") 92 93 meta = [] 94 sql = "SELECT \ 95 stackRun.stack_id,\ 96 stackRun.skycell_id \ 97 FROM \ 98 staticskyInput, staticskyRun, stackRun, staticskyResult \ 99 WHERE staticskyRun.sky_id = staticskyInput.sky_id \ 100 AND staticskyInput.stack_id = stackRun.stack_id \ 101 AND staticskyInput.sky_id = staticskyResult.sky_id \ 102 and staticskyInput.sky_id = %d \ 103 and filter = '%s'" % (skyID, filter) 104 105 106 try: 107 rs = self.stmt.executeQuery(sql) 108 rs.first() 109 meta.append(rs.getInt(1)) 110 meta.append(rs.getString(2)) 111 except: 112 self.logger.exception("Can't query for stack meta") 113 114 return meta 115 ''' 116 Gets some camera-stage meta data for this cam_id 117 ''' 118 def getCameraStageMeta(self, camID): 119 120 self.logger.debug("Querying GPC1 for camera meta data") 121 122 meta = [] 123 sql = "SELECT exp_id, exp_name, camRun.dist_group \ 124 FROM camRun \ 125 JOIN chipRun USING(chip_id) \ 126 JOIN rawExp USING(exp_id) WHERE camRun.cam_id = %d" % camID 127 128 try: 129 rs = self.stmt.executeQuery(sql) 130 rs.first() 131 meta.append(rs.getInt(1)) 132 meta.append(rs.getString(2)) 133 meta.append(rs.getString(3)) 134 except: 135 self.logger.exception("Can't query for camera meta") 136 137 return meta 138 139 ''' 140 Gets a camera-stage smf for this cam_id 141 ''' 142 def getCameraStageSmf(self, camID): 143 144 self.logger.debug("Querying GPC1 for camera smf files with cam_id = " + str(camID)) 145 146 sql = "SELECT path_base \ 147 FROM camProcessedExp \ 148 JOIN camRun USING(cam_id) \ 149 WHERE camRun.cam_id = %d" % camID 150 151 try: 152 rs = self.stmt.executeQuery(sql) 153 rs.first() 154 except: 155 self.logger.exception("Can't query for camera smfs") 67 156 68 157 # get path to base dir of cmf files … … 74 163 if path.startswith("neb"): 75 164 76 f=os.popen("neb-ls -p "+path+"/% cmf")165 f=os.popen("neb-ls -p "+path+"/%smf") 77 166 for i in f.readlines(): 78 167 files.append(i.rstrip()) … … 82 171 files = glob.glob(path + "/*.cmf") 83 172 173 return files[0] # TODO just returning first file - check 174 175 176 ''' 177 Gets all cmf files for this sky_id. handles both absolute paths and neb paths 178 ''' 179 def getStackStageCmfs(self, skyID): 180 181 self.logger.debug("Querying GPC1 for stack cmf files") 182 183 sql = "SELECT path_base, num_inputs \ 184 FROM staticskyResult \ 185 WHERE sky_id = %d" % skyID 186 187 try: 188 rs = self.stmt.executeQuery(sql) 189 rs.first() 190 except: 191 self.logger.exception("Can't query for stack cmfs") 192 193 # get path to base dir of cmf files 194 path = rs.getString(1) 195 #path = path[0:path.rfind("/")] 196 197 # list all cmf files if a neb path 198 files = [] 199 if path.startswith("neb"): 200 201 f=os.popen("neb-ls -p "+path+"%cmf") 202 print "neb-ls -p "+path+"%cmf" 203 for i in f.readlines(): 204 files.append(i.rstrip()) 205 print i.rstrip() 206 207 # or not a neb path 208 else: 209 files = glob.glob(path + "*.cmf") 210 84 211 return files 85 212
Note:
See TracChangeset
for help on using the changeset viewer.
