00001 package ProdDatabase;
00002
00003
00004
00005 import java.sql.*;
00006 import java.io.*;
00007 import java.util.*;
00008
00009 public class ModuleSCTDAQInfo implements SCTDBInfo {
00010 Statement statement;
00011 ResultSet resultSet;
00012 StringBuffer sqlStat;
00013 SCTDBInterface db;
00014 Map testNameMap;
00015
00016 String moduleSerialNo;
00017 Vector Tests;
00018
00019 java.text.DecimalFormat ivFormatter = new java.text.DecimalFormat("#.###");
00020 java.text.DecimalFormat temperatureFormatter = new java.text.DecimalFormat("#.#");
00021
00022 boolean DEBUG=false;
00023
00024
00025
00026 public ModuleSCTDAQInfo(String moduleSerialNo) {
00027 this.moduleSerialNo=moduleSerialNo;
00028 Tests = new Vector();
00029 testNameMap = new HashMap();
00030 for(int i=0;i<sctdaqDBTestNames.length;i++) testNameMap.put(sctdaqDBTestNames[i],sctdaqNormalTestNames[i]);
00031
00032 db = SCTDBInterface.getInstance();
00033 try {
00034 getCharacterisationList();
00035 getDefects();
00036 getFailedTests();
00037 }catch(Exception e){System.err.println(e.toString());}
00038
00039 }
00040
00041 public int noTests() {
00042 return Tests.size();
00043 }
00044 public SCTDAQCharacterisation getCharacterisation(int index) {
00045 if(index>=Tests.size()) {
00046 System.out.println("Invalid sctdaq test index");
00047 return null;
00048 }
00049 return (SCTDAQCharacterisation) Tests.elementAt(index);
00050 }
00051
00052
00053
00054 private void getCharacterisationList() throws Exception {
00055
00056 if(!db.isConnected()) throw new Exception("No database connection");
00057 StringBuffer sqlStat = new StringBuffer("SELECT tests.ser_no,tests.locn_name,tests.test_date,sct_tstdcsinfo.T0,sct_tstdcsinfo.T1");
00058 sqlStat.append(" FROM tests,sct_tstdcsinfo");
00059 sqlStat.append(" WHERE tests.ser_no = "+moduleSerialNo);
00060 sqlStat.append(" AND tests.test_name = 'HybRC'");
00061 sqlStat.append(" AND sct_tstdcsinfo.test_no=tests.test_no");
00062 sqlStat.append(" ORDER BY tests.test_date,tests.test_no");
00063
00064 statement = db.connection.createStatement();
00065 if(DEBUG) System.out.println(sqlStat.toString());
00066 resultSet = statement.executeQuery(sqlStat.toString());
00067
00068 for(boolean n = resultSet.next() ; n==true ; n=resultSet.next() ){
00069 String sn = resultSet.getString(1);
00070 String locn = resultSet.getString(2);
00071 String date = guiUtilities.DaveUtils.extractDate(resultSet.getString(3));
00072 double T0 = Double.parseDouble(resultSet.getString(4));
00073 double T1 = Double.parseDouble(resultSet.getString(5));
00074 double Tdiff = (T1!=128.0) ? T0-T1 : 0.;
00075 SCTDAQCharacterisation sctdaq = new SCTDAQCharacterisation(locn,date,T0,Tdiff);
00076 Tests.addElement(sctdaq);
00077 }
00078 statement.close();
00079
00080 }
00081
00082
00083 private void getDefects() throws Exception {
00084
00085
00086 for(int i=0;i<Tests.size();i++) {
00087 SCTDAQCharacterisation sctdaq = (SCTDAQCharacterisation)Tests.elementAt(i);
00088 String locn = sctdaq.getLocation();
00089 String date = sctdaq.getDate();
00090 boolean isWarm = (sctdaq.getTemperature()>10.);
00091 if(!db.isConnected()) throw new Exception("No database connection");
00092 StringBuffer sqlStat = new StringBuffer("SELECT chan_1st,chan_last,defect_name");
00093 sqlStat.append(" FROM tests,defects,sct_tstdcsinfo");
00094 sqlStat.append(" WHERE tests.ser_no = "+moduleSerialNo+" AND tests.locn_name='"+locn+"'");
00095 sqlStat.append(" AND tests.test_name LIKE 'Hyb%'");
00096 sqlStat.append(" AND defects.test_no=tests.test_no AND sct_tstdcsinfo.test_no=tests.test_no");
00097 sqlStat.append(" AND tests.test_date='"+date+"'");
00098 if(isWarm) sqlStat.append(" AND sct_tstdcsinfo.T0>10");
00099 else sqlStat.append(" AND sct_tstdcsinfo.T0<=10");
00100 sqlStat.append(" ORDER BY tests.test_date,tests.test_no");
00101
00102 statement = db.connection.createStatement();
00103 if(DEBUG) System.out.println(sqlStat.toString());
00104 resultSet = statement.executeQuery(sqlStat.toString());
00105
00106 int ntot=0;
00107 int ntot_consecutive=0;
00108 int ntot_ex=0;
00109 int ntot_consecutive_ex=0;
00110 Hashtable defectHash = new Hashtable();
00111 Hashtable noTrimDefectHash = new Hashtable();
00112 for(boolean n = resultSet.next() ; n==true ; n=resultSet.next() ){
00113 String chan1 = resultSet.getString(1);
00114 String chan2 = resultSet.getString(2);
00115 String testname = resultSet.getString(3);
00116 boolean isTrim = (testname.indexOf("TR_")!=-1);
00117 int c1 = Integer.parseInt(chan1);
00118 int c2 = Integer.parseInt(chan2);
00119 int ncon = c2-c1+1;
00120 if(ncon>ntot_consecutive) ntot_consecutive=ncon;
00121 if(!isTrim && ncon>ntot_consecutive_ex) ntot_consecutive_ex=ncon;
00122 for(int j=c1;j<=c2;j++) {
00123 Integer thisDefect = new Integer(j);
00124 if(!defectHash.containsKey(thisDefect)) {
00125 defectHash.put(thisDefect,"1");
00126 ntot++;
00127 }
00128 if(!isTrim && !noTrimDefectHash.containsKey(thisDefect)) {
00129 noTrimDefectHash.put(thisDefect,"1");
00130 ntot_ex++;
00131 }
00132 }
00133 }
00134 sctdaq.setDefects(0,ntot);
00135 sctdaq.setDefects(1,ntot_consecutive);
00136 sctdaq.setDefects(2,ntot_ex);
00137 sctdaq.setDefects(3,ntot_consecutive_ex);
00138 Tests.setElementAt(sctdaq,i);
00139 statement.close();
00140 }
00141
00142
00143 }
00144
00145
00146 private void getFailedTests() throws Exception {
00147
00148
00149 for(int i=0;i<Tests.size();i++) {
00150 SCTDAQCharacterisation sctdaq = (SCTDAQCharacterisation)Tests.elementAt(i);
00151 String locn = sctdaq.getLocation();
00152 String date = sctdaq.getDate();
00153 boolean isWarm = (sctdaq.getTemperature()>10.);
00154 if(!db.isConnected()) throw new Exception("No database connection");
00155 StringBuffer sqlStat = new StringBuffer("SELECT test_name FROM tests,sct_tstdcsinfo");
00156 sqlStat.append(" WHERE tests.ser_no = "+moduleSerialNo+" AND tests.locn_name='"+locn+"'");
00157 sqlStat.append(" AND tests.pass='NO'");
00158 sqlStat.append(" AND tests.test_name LIKE 'Hyb%'");
00159 sqlStat.append(" AND sct_tstdcsinfo.test_no=tests.test_no");
00160 sqlStat.append(" AND tests.test_date='"+date+"'");
00161 if(isWarm) sqlStat.append(" AND sct_tstdcsinfo.T0>10");
00162 else sqlStat.append(" AND sct_tstdcsinfo.T0<=10");
00163 sqlStat.append(" ORDER BY tests.test_date,tests.test_no");
00164
00165 statement = db.connection.createStatement();
00166 if(DEBUG) System.out.println(sqlStat.toString());
00167 resultSet = statement.executeQuery(sqlStat.toString());
00168 for(boolean n = resultSet.next() ; n==true ; n=resultSet.next() ){
00169 String name = (String)testNameMap.get(resultSet.getString(1));
00170 if(name!=null) sctdaq.addFailedTest(name);
00171 }
00172 statement.close();
00173 }
00174 }
00175
00176
00177 }