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

Generated on Thu Jul 15 09:55:47 2004 for SCT DAQ/DCS Software - Java by doxygen 1.3.5