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