00001 package SummaryReader;
00002
00003
00004
00005 import java.io.*;
00006 import java.util.*;
00007 import java.util.regex.*;
00008 import java.text.*;
00009
00010 public class Reader implements regExpressions, DisplayGUI.TestDataInfo {
00011
00012
00013 Matcher matcher,matcher2;
00014 Test testObject;
00015 Vector testObjects;
00016 int parameterType;
00017 int testType;
00018 Map testMapping;
00019 java.text.DecimalFormat nf = new java.text.DecimalFormat("#.##");
00020 Pattern testregex;
00021
00022 public Reader(String serialNo,String resultString, DCSInfo dcsInfo) {
00023 testMapping = getTestMapping();
00024 getTestInfo(serialNo,resultString, dcsInfo);
00025 }
00026
00027
00028
00029
00030
00031
00032 public String getData(int index) {
00033 return testObject.getData(index);
00034 }
00035 public String getData() {
00036 return testObject.getData(-1);
00037 }
00038 public Test getTest() {
00039 return testObject;
00040 }
00041
00042
00043
00044
00045 public void getTestInfo(String serialNo,String resultString, DCSInfo dcsInfo) {
00046 boolean[] nextLineIsChipData = {false,false,false,false,false,false,false,false,false,false,false,false};
00047 boolean loopB=false;
00048 boolean nextLineIsLink0Data=false;
00049 boolean nextLineIsLink1Data=false;
00050 boolean nextLineIsVersion=false;
00051 boolean nextLineIsTime=false;
00052 boolean nextLineIsHost=false;
00053 boolean nextLineIsNoScans=false;
00054 boolean nextLineIsScanType=false;
00055 boolean nextLineIsScanPoints=false;
00056 boolean nextLineIsComment=false;
00057 boolean nextLineIsData=false;
00058 boolean nextLineIsT0T1=false;
00059 boolean nextLineIsVDETIDET=false;
00060 boolean nextLineIsVCCICC=false;
00061 boolean nextLineIsVDDIDD=false;
00062
00063 int linkData=-1;
00064
00065 int scanCount=0;
00066 int parameterIndex=-1;
00067 int byPassSection=-1;
00068 int byPassChipOffset=-1;
00069
00070
00071 testObject = new Test();
00072 IVData ivData=null;
00073 DataBlock dataBlock=null;
00074 LinkInfo linkInfo=null;
00075 DAQInfo daqInfo = new DAQInfo();
00076 TestInfo testInfo = new TestInfo();
00077 ScanInfo scanInfo = new ScanInfo();
00078 DefectInfo defectInfo = new DefectInfo();
00079 int testno=999;
00080
00081 int loopNo=-1;
00082
00083 String[] lines = resultString.split("\\n");
00084
00085 for(int i=0;i<lines.length;i++) {
00086 String line = lines[i];
00087 if(line.equals("")) continue;
00088
00089
00090
00091 if(line.matches("^%NewTest")) {
00092 testObject = new Test();
00093 continue;
00094 }
00095
00096 if(testObject==null) continue;
00097
00098
00099 matcher = serialNoPattern.matcher(line);
00100 if(matcher.matches()) {
00101 String thisSerialNo = line.substring(matcher.start(1),matcher.end(1));
00102 if(!thisSerialNo.startsWith("CRATE") && !thisSerialNo.equals(serialNo)) System.err.println("Invalid serial in SummaryWriter String");
00103 testObject.setSerialNo(serialNo);
00104 continue;
00105 }
00106
00107
00108 matcher = runPattern.matcher(line);
00109 if(matcher.matches()) {
00110 String runString = line.substring(matcher.start(1),matcher.end(1));
00111 matcher = scanNoPattern.matcher(runString);
00112 if(matcher.matches()) {
00113 testInfo.setRunNo(runString.substring(matcher.start(1),matcher.end(1)));
00114 testInfo.setScanNo(runString.substring(matcher.start(2),matcher.end(2)));
00115 }
00116 else {
00117 testInfo.setRunNo(runString);
00118 testInfo.setScanNo("None");
00119 }
00120 continue;
00121 }
00122
00123 matcher = testDatePattern.matcher(line);
00124 if(matcher.matches()) {
00125 daqInfo.put(DAQInfo.DATE,line.substring(matcher.start(1),matcher.end(1)));
00126 continue;
00127 }
00128
00129 matcher = passedPattern.matcher(line);
00130 if(matcher.matches()) {
00131 testInfo.setPassed(line.substring(matcher.start(1),matcher.end(1)));
00132 continue;
00133 }
00134 matcher = problemPattern.matcher(line);
00135 if(matcher.matches()) {
00136 testInfo.setProblem(line.substring(matcher.start(1),matcher.end(1)));
00137 continue;
00138 }
00139
00140 matcher = testregex.matcher(line);
00141 if(matcher.matches()) {
00142 String theTestType = line.substring(matcher.start()+1,matcher.end());
00143 testInfo.setName(theTestType);
00144 if(testMapping.containsKey(theTestType)) testno = ((Integer)testMapping.get(theTestType)).intValue();
00145 switch(testno) {
00146 case TEST_PIPELINE:
00147 dataBlock = new DataBlock("Number of Defective pipelines",1,testno);
00148 dataBlock.add(0,"#Channels");
00149 break;
00150 case TEST_FULLBYPASS:
00151 dataBlock = new DataBlock("FullBypass Data",testParameters[testno].length-parameterOffset,testno);
00152 for(int header=parameterOffset;header<testParameters[testno].length;header++) dataBlock.add(header-parameterOffset,testParameters[testno][header]);
00153 break;
00154 case TEST_STROBEDELAY:
00155 dataBlock = new DataBlock("Optimum Strobe Delays",1,testno);
00156 dataBlock.add(0,"Delay");
00157 break;
00158 case TEST_TRIM:
00159 dataBlock = new DataBlock("Trim Data",testParameters[testno].length-parameterOffset,testno);
00160 for(int header=parameterOffset;header<testParameters[testno].length;header++) dataBlock.add(header-parameterOffset,testParameters[testno][header]);
00161 break;
00162 case TEST_NOISE:
00163 dataBlock = new DataBlock("Noise Data",testParameters[testno].length-parameterOffset,testno);
00164 for(int header=parameterOffset;header<testParameters[testno].length;header++) dataBlock.add(header-parameterOffset,testParameters[testno][header]);
00165 break;
00166 case TEST_TIMEWALK:
00167 dataBlock = new DataBlock("TimeWalk Data",testParameters[testno].length-parameterOffset,testno);
00168 for(int header=parameterOffset;header<testParameters[testno].length;header++) dataBlock.add(header-parameterOffset,testParameters[testno][header]);
00169 break;
00170 case TEST_RXTHRESHOLD:
00171 linkInfo = new LinkInfo(1);
00172 for(int header=parameterOffset;header<testParameters[testno].length;header++) linkInfo.addTitle(header-parameterOffset,testParameters[testno][header]);
00173 break;
00174 case TEST_RXTHRESHOLDBASEDONCONFIGREGISTER:
00175 linkInfo = new LinkInfo(3);
00176 for(int header=parameterOffset;header<testParameters[testno].length;header++) linkInfo.addTitle(header-parameterOffset,testParameters[testno][header]);
00177 break;
00178 case TEST_TXCURRENT:
00179 linkInfo = new LinkInfo(3);
00180 for(int header=parameterOffset;header<testParameters[testno].length;header++) linkInfo.addTitle(header-parameterOffset,testParameters[testno][header]);
00181 break;
00182 case TEST_RXDELAY:
00183 linkInfo = new LinkInfo(1);
00184 for(int header=parameterOffset;header<testParameters[testno].length;header++) linkInfo.addTitle(header-parameterOffset,testParameters[testno][header]);
00185 break;
00186 case TEST_IV:
00187 ivData = new IVData(testObject.getSerialNo());
00188 break;
00189 default:
00190 }
00191 continue;
00192 }
00193
00194
00195 matcher = spacerPattern.matcher(line);
00196 if(matcher.matches()) line=line.substring(matcher.start(1),matcher.end(1));
00197 switch(testno) {
00198 case TEST_IV:
00199 Matcher matcher2 = ivDataPattern.matcher(line);
00200 if(matcher2.matches()) ivData.add(line.substring(matcher2.start(1),matcher2.end(1)),line.substring(matcher2.start(2),matcher2.end(2)));
00201 break;
00202 case TEST_PIPELINE:
00203 if(nextLineIsLink0Data || nextLineIsLink1Data) {
00204 String[] dataLine = line.split("\\s+");
00205 if(dataLine.length!=6) break;
00206 for(int j=0;j<dataLine.length;j++) {
00207 int index = nextLineIsLink1Data ? j+6 : j;
00208 try {
00209 int thisData = Integer.parseInt(dataLine[j]);
00210 thisData=128-thisData;
00211 dataLine[j]=Integer.toString(thisData);
00212 }catch(Exception e2){};
00213 dataBlock.add(index,0,dataLine[j]);
00214 }
00215 }
00216 nextLineIsLink0Data = line.startsWith("#M0");
00217 nextLineIsLink1Data = line.startsWith("#M8");
00218 break;
00219 case TEST_FULLBYPASS:
00220
00221
00222
00223
00224
00225
00226 if(line.matches("^#Comment$")) {
00227 byPassSection=1;
00228 byPassChipOffset=-1;
00229 }
00230 if(line.matches("^#token\\s+r_tkn\\s+token\\s+r_tkn$")) byPassSection=0;
00231 if(byPassSection<0) break;
00232
00233 if(byPassChipOffset!=-1) {
00234 String[] dataLine = (byPassSection==1) ? line.split("\\t+") : line.split("\\s+");
00235 if(dataLine.length!=4) break;
00236 int colOffset = byPassSection*2;
00237
00238 dataBlock.add((byPassChipOffset*2),0+colOffset,dataLine[0].replaceAll("\"",""));
00239 dataBlock.add((byPassChipOffset*2),1+colOffset,dataLine[1].replaceAll("\"",""));
00240 dataBlock.add((byPassChipOffset*2)+1,0+colOffset,dataLine[2].replaceAll("\"",""));
00241 dataBlock.add((byPassChipOffset*2)+1,1+colOffset,dataLine[3].replaceAll("\"",""));
00242 }
00243 byPassChipOffset=-1;
00244 for(int offset=0;offset<6;offset++) {
00245 if(line.matches(fullBypassChipPattern[offset])) {
00246 byPassChipOffset=offset;
00247 break;
00248 }
00249 }
00250 break;
00251
00252 case TEST_STROBEDELAY:
00253 if(nextLineIsLink0Data || nextLineIsLink1Data) {
00254 String[] dataLine = line.split("\\s+");
00255 if(dataLine.length!=6) break;
00256 for(int j=0;j<dataLine.length;j++) {
00257 int index = nextLineIsLink1Data ? j+6 : j;
00258 dataBlock.add(index,0,dataLine[j]);
00259 }
00260 }
00261 nextLineIsLink0Data = line.startsWith("#M0");
00262 nextLineIsLink1Data = line.startsWith("#M8");
00263 break;
00264 case TEST_3PTGAIN:
00265 case TEST_NPTGAIN:
00266 if(line.startsWith("#LoopA")) {
00267 loopNo++;
00268 dataBlock = new DataBlock("Fit Parameters",4,testno);
00269 dataBlock.add(0,"Function");
00270 dataBlock.add(1,"P0");
00271 dataBlock.add(2,"P1");
00272 dataBlock.add(3,"P2");
00273 continue;
00274 }
00275 if(line.startsWith("#LoopB")) {
00276 loopNo++;
00277 if(dataBlock!=null) testObject.add(dataBlock);
00278 dataBlock = new DataBlock("NPtGain Data",testParameters[testno].length-parameterOffset,testno);
00279 for(int header=parameterOffset;header<testParameters[testno].length;header++) dataBlock.add(header-parameterOffset,testParameters[testno][header]);
00280 continue;
00281 }
00282 for(int j=0;j<12;j++) {
00283 if(nextLineIsChipData[j]) {
00284 String[] dataLine = line.split("\\s+");
00285 if(dataLine.length==4 && loopNo==1) {
00286 for(int k=1;k<dataLine.length;k++) dataBlock.add(j,k+8,dataLine[k]);
00287 }
00288 else {
00289 for(int k=0;k<dataLine.length;k++) dataBlock.add(j,k,dataLine[k]);
00290 }
00291 }
00292 nextLineIsChipData[j] = (line.matches(chipNames[j]));
00293 }
00294 break;
00295 case TEST_TRIM:
00296 for(int j=0;j<12;j++) {
00297 if(nextLineIsChipData[j]) {
00298 String[] dataLine = line.split("\\s+");
00299 try {
00300 int thisData = Integer.parseInt(dataLine[2]);
00301 thisData=128-thisData;
00302 dataLine[2]=Integer.toString(thisData);
00303 }catch(Exception e2){};
00304 for(int k=0;k<dataLine.length;k++) dataBlock.add(j,k,dataLine[k]);
00305 }
00306 nextLineIsChipData[j] = (line.matches(chipNames[j]));
00307 }
00308 break;
00309 case TEST_NOISE:
00310 for(int j=0;j<12;j++) {
00311 if(nextLineIsChipData[j]) {
00312 matcher2 = opeToolPattern.matcher(line);
00313 if(matcher2.matches()) line=line.substring(matcher2.start(1),matcher2.end(1));
00314 String[] dataLine = line.split("\\s+");
00315 for(int k=0;k<dataLine.length;k++) {
00316 try {
00317 if(k==1 || k==2) dataLine[k]= (new java.text.DecimalFormat("0.##E0")).format(Double.parseDouble(dataLine[k]));
00318 }catch(Exception ne){dataLine[k]="0.";}
00319 if(dataLine.length==4) dataBlock.add(j,k,dataLine[k]);
00320 else if(dataLine.length==2) dataBlock.add(j,k+4,dataLine[k]);
00321 else {System.err.println("SctGUI SummaryReader::Reader - Invalid data in summaryWriter String");}
00322 }
00323 }
00324 nextLineIsChipData[j] = (line.matches(chipNames[j]));
00325 }
00326 break;
00327 case TEST_TIMEWALK:
00328 if(line.startsWith("#TW")) parameterIndex=0;
00329 if(line.startsWith("#TCAL")) parameterIndex=1;
00330
00331 if(nextLineIsLink0Data || nextLineIsLink1Data) {
00332 String[] dataLine = line.split("\\s+");
00333 if(dataLine.length!=6) break;
00334 for(int j=0;j<dataLine.length;j++) {
00335 int index = nextLineIsLink1Data ? j+6 : j;
00336 dataBlock.add(index,parameterIndex,dataLine[j]);
00337 }
00338 }
00339 nextLineIsLink0Data = line.startsWith("#M0");
00340 nextLineIsLink1Data = line.startsWith("#M8");
00341 break;
00342 case TEST_RXTHRESHOLD:
00343 if(nextLineIsData) {
00344 Matcher matcher = bocPattern.matcher(line);
00345 if(matcher.matches()) {
00346 String s = line.substring(matcher.start(1),matcher.end(1));
00347 linkInfo.add(0,s);
00348 s = line.substring(matcher.start(2),matcher.end(2));
00349 linkInfo.add(1,s);
00350 }
00351 }
00352 nextLineIsData = line.startsWith("#Thresholds");
00353 break;
00354 case TEST_RXTHRESHOLDBASEDONCONFIGREGISTER:
00355 matcher = linkInfoPattern.matcher(line);
00356 if(matcher.matches()) {
00357 linkData = Integer.parseInt(line.substring(matcher.start(1),matcher.end(1)));
00358 if(linkData<0 || linkData>1) {
00359 System.err.println("sctGUI:: Invalid link number in summaryWriter string");
00360 linkData=-1;
00361 }
00362 }
00363 if(linkData!=-1) {
00364 Matcher matcher = rxthrconfigDataPattern.matcher(line);
00365 if(matcher.matches()) {
00366 for(int match=0;match<3;match++) {
00367 String value = line.substring(matcher.start(match+1),matcher.end(match+1));
00368 linkInfo.add(linkData,match,value);
00369 }
00370 linkData=-1;
00371 }
00372 }
00373 break;
00374 case TEST_TXCURRENT:
00375 matcher = linkInfoPattern.matcher(line);
00376 if(matcher.matches()) {
00377 linkData = Integer.parseInt(line.substring(matcher.start(1),matcher.end(1)));
00378 if(linkData<0 || linkData>1) {
00379 System.err.println("sctGUI:: Invalid link number in summaryWriter string");
00380 linkData=-1;
00381 }
00382 }
00383 if(linkData!=-1) {
00384 Matcher matcher = txcurrentDataPattern.matcher(line);
00385 if(matcher.matches()) {
00386 for(int match=0;match<3;match++) {
00387 String value = line.substring(matcher.start(match+1),matcher.end(match+1));
00388 linkInfo.add(linkData,match,value);
00389 }
00390 linkData=-1;
00391 }
00392 }
00393 break;
00394
00395 case TEST_RXDELAY:
00396 if(nextLineIsData) {
00397 Matcher matcher = bocPattern.matcher(line);
00398 if(matcher.matches()) {
00399 String s = line.substring(matcher.start(1),matcher.end(1));
00400 linkInfo.add(0,s);
00401 s = line.substring(matcher.start(2),matcher.end(2));
00402 linkInfo.add(1,s);
00403 }
00404 }
00405 nextLineIsData = line.startsWith("#Delays");
00406 break;
00407 default:
00408 }
00409 if(nextLineIsScanPoints) {
00410 if(line.startsWith("%") || line.startsWith("#")) {
00411 nextLineIsScanPoints=false;
00412 continue;
00413 }
00414 try {
00415 String[] scanPoints = line.split("\\s+");
00416 for(int k=0;k<scanPoints.length;k++) {
00417 scanInfo.setScanPoint(scanCount+k,scanPoints[k]);
00418 }
00419 scanCount+=scanPoints.length;
00420 continue;
00421 }catch(Exception e3){}
00422 }
00423
00424 matcher = defectNamePattern.matcher(line);
00425 if(matcher.matches()) {
00426 defectInfo = new DefectInfo();
00427 defectInfo.setName(line.substring(matcher.start(1),matcher.end(1)));
00428 continue;
00429 }
00430 matcher = defectNameDefect0.matcher(line);
00431 if(matcher.matches()) {
00432 defectInfo.setFirstChannel(line.substring(matcher.start(1),matcher.end(1)));
00433 continue;
00434 }
00435 matcher = defectNameDefect1.matcher(line);
00436 if(matcher.matches()) {
00437 defectInfo.setLastChannel(line.substring(matcher.start(1),matcher.end(1)));
00438 testObject.add(defectInfo);
00439 continue;
00440 }
00441
00442 if(nextLineIsComment) {
00443 matcher = commentsPattern.matcher(line);
00444 if(matcher.matches()) testObject.addComment(line.substring(matcher.start(1),matcher.end(1)));
00445 }
00446
00447
00448 if(nextLineIsVersion) daqInfo.put(DAQInfo.VERSION,line);
00449 if(nextLineIsTime) daqInfo.put(DAQInfo.TIME,line.replaceAll("\"",""));
00450 if(nextLineIsHost) daqInfo.put(DAQInfo.HOST,line.replaceAll("\"",""));
00451 if(nextLineIsScanType) scanInfo.setType(line);
00452 if(nextLineIsNoScans) scanInfo.setPoints(line);
00453
00454 if(nextLineIsT0T1) {
00455 String[] data = line.split("[\\s\\r\\n]");
00456 if(data.length==2) {
00457 if(dcsInfo==null) dcsInfo=new DCSInfo();
00458 try {
00459 dcsInfo.put(DCSInfo.T0,nf.format(Double.parseDouble(data[0])));
00460 dcsInfo.put(DCSInfo.T1,nf.format(Double.parseDouble(data[1])));
00461 }catch(Exception e){}
00462 }
00463 }
00464 if(nextLineIsVCCICC) {
00465 String[] data = line.split("[\\s\\r\\n]");
00466 if(data.length==2) {
00467 if(dcsInfo==null) dcsInfo=new DCSInfo();
00468 try {
00469 dcsInfo.put(DCSInfo.VCC,nf.format(Double.parseDouble(data[0])));
00470 dcsInfo.put(DCSInfo.ICC,nf.format(Double.parseDouble(data[1])));
00471 }catch(Exception e){}
00472 }
00473 }
00474 if(nextLineIsVDDIDD) {
00475 String[] data = line.split("[\\s\\r\\n]");
00476 if(data.length==2) {
00477 if(dcsInfo==null) dcsInfo=new DCSInfo();
00478 try {
00479 dcsInfo.put(DCSInfo.VDD,nf.format(Double.parseDouble(data[0])));
00480 dcsInfo.put(DCSInfo.IDD,nf.format(Double.parseDouble(data[1])));
00481 }catch(Exception e){}
00482 }
00483 }
00484 if(nextLineIsVDETIDET) {
00485 String[] data = line.split("[\\s\\r\\n]");
00486 if(data.length==2) {
00487 if(dcsInfo==null) dcsInfo=new DCSInfo();
00488 try {
00489 dcsInfo.put(DCSInfo.VDET,nf.format(Double.parseDouble(data[0])));
00490 dcsInfo.put(DCSInfo.IDET,nf.format( Double.valueOf(data[1]).doubleValue()/1000. ));
00491 }catch(Exception e){}
00492 }
00493 }
00494
00495 nextLineIsVersion = line.matches("^[\\s#]?VERSION.*");
00496 nextLineIsTime = line.matches("^#TIME$");
00497 nextLineIsHost = line.matches("^#HOST$");
00498 nextLineIsScanType = line.matches("^#POINT_TYPE$");
00499 nextLineIsNoScans = line.matches("^#N_POINTS$");
00500 nextLineIsScanPoints = line.matches("^#POINTS$");
00501 nextLineIsComment = line.matches("^%Comment$");
00502 nextLineIsT0T1 = line.matches("^#T0\\s+T1.*");
00503 nextLineIsVDETIDET = line.matches("^#VDET\\s+IDET.*");
00504 nextLineIsVCCICC = line.matches("^#VCC\\s+ICC.*");
00505 nextLineIsVDDIDD = line.matches("^#VDD\\s+IDD.*");
00506
00507
00508 }
00509 if(dataBlock!=null) testObject.add(dataBlock);
00510 if(ivData!=null) testObject.add(ivData);
00511 if(dcsInfo!=null) testObject.add(dcsInfo);
00512 if(linkInfo!=null) testObject.add(linkInfo);
00513 testObject.add(testInfo);
00514 testObject.add(daqInfo);
00515 testObject.add(scanInfo);
00516 }
00517
00518 private Map getTestMapping() {
00519 Map mapping = new HashMap();
00520 StringBuffer testregExpr = new StringBuffer();
00521 int count=0;
00522 for(int i=0;i<resultFileKeyNames.length;i++) {
00523 if(!resultFileKeyNames[i].equals("")) {
00524 mapping.put(resultFileKeyNames[i],new Integer(i));
00525 if(count>0) testregExpr.append("|");
00526 testregExpr.append("%"+resultFileKeyNames[i]);
00527 count++;
00528 }
00529 }
00530 String theTestRegex = "("+testregExpr.toString()+")";
00531
00532 testregex=Pattern.compile(theTestRegex);
00533 return mapping;
00534 }
00535
00536
00537
00538
00539
00540 }
00541