Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

Reader.java

00001 package SummaryReader;
00002 //
00003 // @Author Dave Robinson
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;
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 //    public Reader(String resultString) {
00026 //            testMapping = getTestMapping();
00027 //            getTestInfo(null,resultString, null);
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 //***************************************************************************8
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; // shouldn't be necessary
00085 //          System.out.println(line);
00086 
00087 // check for new test
00088              if(line.matches("^%NewTest")) {
00089                 testObject = new Test();
00090                 continue;
00091              }
00092 
00093              if(testObject==null) continue;
00094 
00095 // first the serial No
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 // then the run number and scan number
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 // then the date
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 // now passed or fail status
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 // now the test type
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();
00169                             break;
00170                          case TEST_RXTHRESHOLDBASEDONCONFIGREGISTER:
00171                             linkInfo = new LinkInfo();
00172                             break;
00173                           case TEST_RXDELAY: 
00174                             linkInfo = new LinkInfo();
00175                             break;
00176                           case TEST_IV:
00177                             ivData = new IVData(testObject.getSerialNo());
00178                             break;
00179                           default:
00180                           }
00181                         continue;
00182                         }
00183 //
00184                  matcher = spacerPattern.matcher(line);
00185                  if(matcher.matches()) line=line.substring(matcher.start(1),matcher.end(1));
00186                  switch(testno) {
00187                     case TEST_IV:
00188                          Matcher matcher2 = ivDataPattern.matcher(line);
00189                          if(matcher2.matches()) ivData.add(line.substring(matcher2.start(1),matcher2.end(1)),line.substring(matcher2.start(2),matcher2.end(2)));
00190                          break;
00191                     case TEST_PIPELINE:
00192                          if(nextLineIsLink0Data || nextLineIsLink1Data) {
00193                            String[] dataLine = line.split("\\s+");
00194                            if(dataLine.length!=6) break;
00195                            for(int j=0;j<dataLine.length;j++) {
00196                                       int index = nextLineIsLink1Data ? j+6 : j;
00197                                        try {  // subtract 128 from Ngood into N-notGood
00198                                           int thisData = Integer.parseInt(dataLine[j]);
00199                                           thisData=128-thisData;
00200                                           dataLine[j]=Integer.toString(thisData);
00201                                        }catch(Exception e2){};
00202                                       dataBlock.add(index,0,dataLine[j]);
00203                                       }
00204                            }
00205                           nextLineIsLink0Data = line.startsWith("#M0");
00206                           nextLineIsLink1Data = line.startsWith("#M8");
00207                           break;
00208                     case TEST_FULLBYPASS:
00209 //  byPassChipOffset   chip0  chip0   chip1  chip1
00210 //                 0   data0  data1   data0  data1
00211 //                 1   data0  data1   data0  data1
00212 //          ...
00213 // where chip0=m0,s2 etc for byPassChipOffset=0,1 etc
00214 //       chip1=s1,s3 etc for byPassChipOffset=0,1 etc
00215                          if(line.matches("^#Comment$")) {
00216                                 byPassSection=1;
00217                                 byPassChipOffset=-1;
00218                                 }
00219                          if(line.matches("^#token\\s+r_tkn\\s+token\\s+r_tkn$")) byPassSection=0;
00220                          if(byPassSection<0) break;
00221                           
00222                          if(byPassChipOffset!=-1) {
00223                            String[] dataLine = (byPassSection==1) ? line.split("\\t+") : line.split("\\s+");
00224                            if(dataLine.length!=4) break;
00225                            int colOffset = byPassSection*2;
00226                            // remove any " from comments
00227                            dataBlock.add((byPassChipOffset*2),0+colOffset,dataLine[0].replaceAll("\"","")); 
00228                            dataBlock.add((byPassChipOffset*2),1+colOffset,dataLine[1].replaceAll("\"",""));   
00229                            dataBlock.add((byPassChipOffset*2)+1,0+colOffset,dataLine[2].replaceAll("\"","")); 
00230                            dataBlock.add((byPassChipOffset*2)+1,1+colOffset,dataLine[3].replaceAll("\"",""));                        
00231                            }
00232                          byPassChipOffset=-1;
00233                          for(int offset=0;offset<6;offset++) {
00234                              if(line.matches(fullBypassChipPattern[offset])) {
00235                                    byPassChipOffset=offset;
00236                                    break;
00237                                    }
00238                              }
00239                          break;
00240 
00241                     case TEST_STROBEDELAY:
00242                          if(nextLineIsLink0Data || nextLineIsLink1Data) {
00243                            String[] dataLine = line.split("\\s+");
00244                            if(dataLine.length!=6) break;
00245                            for(int j=0;j<dataLine.length;j++) {
00246                                       int index = nextLineIsLink1Data ? j+6 : j;
00247                                       dataBlock.add(index,0,dataLine[j]);
00248                                       }
00249                            }
00250                           nextLineIsLink0Data = line.startsWith("#M0");
00251                           nextLineIsLink1Data = line.startsWith("#M8");
00252                           break;
00253                     case TEST_3PTGAIN:
00254                     case TEST_NPTGAIN:
00255                          if(line.startsWith("#LoopA")) {
00256                              dataBlock = new DataBlock("Fit Parameters",4,testno);
00257                              dataBlock.add(0,"Function");
00258                              dataBlock.add(1,"P0");
00259                              dataBlock.add(2,"P1");
00260                              dataBlock.add(3,"P2");         
00261                              continue;
00262                              }
00263                          if(line.startsWith("#LoopB")) {
00264                              if(dataBlock!=null) testObject.add(dataBlock);
00265                              dataBlock = new DataBlock("NPtGain Data",testParameters[testno].length-parameterOffset,testno);
00266                              for(int header=parameterOffset;header<testParameters[testno].length;header++) dataBlock.add(header-parameterOffset,testParameters[testno][header]);
00267                              continue;
00268                              }
00269                          for(int j=0;j<12;j++) {
00270                               if(nextLineIsChipData[j]) {
00271                                 String[] dataLine = line.split("\\s+");
00272                                 for(int k=0;k<dataLine.length;k++) {
00273                                          dataBlock.add(j,k,dataLine[k]);
00274                                          }
00275                                 }
00276                               nextLineIsChipData[j] = (line.matches(chipNames[j]));
00277                           }
00278                           break;
00279                     case TEST_TRIM:
00280                          for(int j=0;j<12;j++) {
00281                             if(nextLineIsChipData[j]) {
00282                                 String[] dataLine = line.split("\\s+");
00283                                 try {  // subtract 128 from Ntrimmed to turn it into Nuntrimmed
00284                                           int thisData = Integer.parseInt(dataLine[2]);
00285                                           thisData=128-thisData;
00286                                           dataLine[2]=Integer.toString(thisData);
00287                                 }catch(Exception e2){};
00288                                 for(int k=0;k<dataLine.length;k++) dataBlock.add(j,k,dataLine[k]);
00289                                 }
00290                              nextLineIsChipData[j] = (line.matches(chipNames[j]));
00291                              }
00292                           break;
00293                     case TEST_NOISE:
00294                           for(int j=0;j<12;j++) {
00295                             if(nextLineIsChipData[j]) {
00296                                 String[] dataLine = line.split("\\s+");
00297                                 for(int k=0;k<dataLine.length;k++) {
00298                                         try {
00299                                           if(k==1 || k==2) dataLine[k]= (new java.text.DecimalFormat("0.##E0")).format(Double.parseDouble(dataLine[k]));
00300                                         }catch(Exception ne){dataLine[k]="0.";} // if not a number, save as 0. for now...
00301                                         dataBlock.add(j,k,dataLine[k]);
00302                                         }
00303                                 }
00304                              nextLineIsChipData[j] = (line.matches(chipNames[j]));
00305                              }
00306                           break;
00307                     case TEST_TIMEWALK:
00308                          if(line.startsWith("#TW")) parameterIndex=0;     // 0 = TimeWalk data; 1 = TCal data
00309                          if(line.startsWith("#TCAL")) parameterIndex=1;
00310 //                         if(parameterIndex!=parameterType) break;
00311                          if(nextLineIsLink0Data || nextLineIsLink1Data) {
00312                            String[] dataLine = line.split("\\s+");
00313                            if(dataLine.length!=6) break;
00314                            for(int j=0;j<dataLine.length;j++) {
00315                                       int index = nextLineIsLink1Data ? j+6 : j;
00316                                       dataBlock.add(index,parameterIndex,dataLine[j]);
00317                                       }
00318                            }
00319                           nextLineIsLink0Data = line.startsWith("#M0");
00320                           nextLineIsLink1Data = line.startsWith("#M8");
00321                           break;
00322                     case TEST_RXTHRESHOLD:
00323                          if(nextLineIsData) {
00324                            Matcher matcher = bocPattern.matcher(line);
00325                            if(matcher.matches()) {
00326                               String s = line.substring(matcher.start(1),matcher.end(1));
00327                               linkInfo.add(0,s);
00328                               s = line.substring(matcher.start(2),matcher.end(2));
00329                               linkInfo.add(1,s);
00330                               }
00331                             }
00332                           nextLineIsData = line.startsWith("#Thresholds");
00333                           break;
00334                     case TEST_RXTHRESHOLDBASEDONCONFIGREGISTER:
00335                         matcher = rxthrconfigPattern.matcher(line);
00336                         if(matcher.matches()) {
00337                             linkData = Integer.parseInt(line.substring(matcher.start(1),matcher.end(1)));
00338                             if(linkData<0 || linkData>1) {
00339                                System.err.println("sctGUI:: Invalid link number in summaryWriter string");
00340                                linkData=-1;
00341                                }
00342                             }
00343                         if(linkData!=-1) {
00344                            Matcher matcher = rxthrconfigDataPattern.matcher(line);
00345                            if(matcher.matches()) {
00346                               String s = line.substring(matcher.start(1),matcher.end(1));
00347                               linkInfo.add(linkData,s);
00348                               linkData=-1;
00349                               }
00350                             }
00351                           break;
00352                          
00353                     case TEST_RXDELAY:
00354                          if(nextLineIsData) {
00355                            Matcher matcher = bocPattern.matcher(line);
00356                            if(matcher.matches()) {
00357                               String s = line.substring(matcher.start(1),matcher.end(1));
00358                               linkInfo.add(0,s);
00359                               s = line.substring(matcher.start(2),matcher.end(2));
00360                               linkInfo.add(1,s);
00361                               }
00362                             }
00363                           nextLineIsData = line.startsWith("#Delays");
00364                           break;
00365                     default:
00366                     }     
00367           if(nextLineIsScanPoints) {
00368              if(line.startsWith("%") || line.startsWith("#")) {
00369                   nextLineIsScanPoints=false;
00370                   continue;
00371                   }
00372              try {
00373                 String[] scanPoints = line.split("\\s+");
00374                 for(int k=0;k<scanPoints.length;k++) {
00375                        scanInfo.setScanPoint(scanCount+k,scanPoints[k]);
00376                        }
00377                  scanCount+=scanPoints.length;
00378                  continue;
00379              }catch(Exception e3){}
00380           }
00381 
00382           matcher = defectNamePattern.matcher(line);
00383           if(matcher.matches()) {
00384              defectInfo = new DefectInfo();
00385              defectInfo.setName(line.substring(matcher.start(1),matcher.end(1)));
00386              continue;
00387              }
00388           matcher = defectNameDefect0.matcher(line);
00389           if(matcher.matches()) {
00390              defectInfo.setFirstChannel(line.substring(matcher.start(1),matcher.end(1)));
00391              continue;
00392              }
00393           matcher = defectNameDefect1.matcher(line);
00394           if(matcher.matches()) {
00395              defectInfo.setLastChannel(line.substring(matcher.start(1),matcher.end(1)));
00396              testObject.add(defectInfo);
00397              continue;
00398              }
00399 
00400          if(nextLineIsComment) {
00401              matcher = commentsPattern.matcher(line);
00402              if(matcher.matches()) testObject.addComment(line.substring(matcher.start(1),matcher.end(1)));
00403              }
00404 
00405              
00406           if(nextLineIsVersion) daqInfo.put(DAQInfo.VERSION,line);
00407           if(nextLineIsTime) daqInfo.put(DAQInfo.TIME,line.replaceAll("\"",""));
00408           if(nextLineIsHost) daqInfo.put(DAQInfo.HOST,line.replaceAll("\"",""));
00409           if(nextLineIsScanType) scanInfo.setType(line);
00410           if(nextLineIsNoScans) scanInfo.setPoints(line);
00411 
00412           if(nextLineIsT0T1) {
00413             String[] data = line.split("[\\s\\r\\n]");
00414             if(data.length==2) {
00415               if(dcsInfo==null) dcsInfo=new DCSInfo();
00416               try {
00417                 dcsInfo.put(DCSInfo.T0,nf.format(Double.parseDouble(data[0])));
00418                 dcsInfo.put(DCSInfo.T1,nf.format(Double.parseDouble(data[1])));
00419                 }catch(Exception e){}
00420               }
00421             } 
00422           if(nextLineIsVCCICC) {
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.VCC,nf.format(Double.parseDouble(data[0])));
00428                 dcsInfo.put(DCSInfo.ICC,nf.format(Double.parseDouble(data[1])));
00429                 }catch(Exception e){}
00430               }
00431             } 
00432           if(nextLineIsVDDIDD) {
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.VDD,nf.format(Double.parseDouble(data[0])));
00438                 dcsInfo.put(DCSInfo.IDD,nf.format(Double.parseDouble(data[1])));
00439                 }catch(Exception e){}
00440               }
00441             } 
00442           if(nextLineIsVDETIDET) {
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.VDET,nf.format(Double.parseDouble(data[0])));
00448                 dcsInfo.put(DCSInfo.IDET,nf.format(Double.parseDouble(data[1])));
00449                 }catch(Exception e){}
00450               }
00451             } 
00452  
00453           nextLineIsVersion = line.matches("^[\\s#]?VERSION.*");
00454           nextLineIsTime = line.matches("^#TIME$");
00455           nextLineIsHost = line.matches("^#HOST$");      
00456           nextLineIsScanType = line.matches("^#POINT_TYPE$");
00457           nextLineIsNoScans = line.matches("^#N_POINTS$");    
00458           nextLineIsScanPoints = line.matches("^#POINTS$");
00459           nextLineIsComment = line.matches("^%Comment$");
00460           nextLineIsT0T1 = line.matches("^#T0\\s+T1.*");
00461           nextLineIsVDETIDET = line.matches("^#VDET\\s+IDET.*");
00462           nextLineIsVCCICC = line.matches("^#VCC\\s+ICC.*");
00463           nextLineIsVDDIDD = line.matches("^#VDD\\s+IDD.*");
00464 
00465 
00466           }
00467        if(dataBlock!=null) testObject.add(dataBlock);
00468        if(ivData!=null) testObject.add(ivData);
00469        if(dcsInfo!=null) testObject.add(dcsInfo);
00470        if(linkInfo!=null) testObject.add(linkInfo);
00471        testObject.add(testInfo);
00472        testObject.add(daqInfo);
00473        testObject.add(scanInfo);
00474    }
00475 
00476   private Map getTestMapping() {
00477       Map mapping = new HashMap();
00478       for(int i=0;i<resultFileKeyNames.length;i++) {
00479          if(!resultFileKeyNames[i].equals("")) mapping.put(resultFileKeyNames[i],new Integer(i));
00480        }
00481       return mapping;
00482 }
00483 
00484      
00485 
00486 
00487 
00488 }

Generated on Fri Jan 14 12:49:55 2005 for SCT DAQ/DCS Software - Java by doxygen 1.3.5