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

ConfigurationInterface.java

00001 
00006 package DisplayGUI;
00007 import org.omg.CORBA.IntHolder;
00008 import ipc.*;
00009 //import java.util.Hashtable;
00010 //import java.util.Vector;
00011 import java.util.*;
00012 import GuiComponents.System.*;
00013 
00014 public class ConfigurationInterface implements displayParams, SCTInfo {
00015     private static ConfigurationInterface instance = new ConfigurationInterface();
00016     private int maxWidth=0;
00017     private int midX=0, midY=0;
00018     private int moduleCount=0;
00019     private java.awt.Polygon polygon;
00020 //    ModuleCell[][][] moduleCells = new ModuleCell[sctViews][][];
00021     ModuleCell[][][] moduleCells;
00022     double[] radius = {0.,0.,0.,0.,0.,0.};
00023     int[] xPoints = {0,0,0,0};
00024     int[] yPoints = {0,0,0,0};
00025     long fillsn=3000;
00026 
00027 //    private Hashtable[] serialNumberMap = new Hashtable[sctViews];
00028     private SortedMap[] serialNumberMap = new TreeMap[sctViews];
00029 
00030     private Map snMap;
00031     private boolean dcsAvailable;
00032 
00033     sctConf.Configuration h;
00034 
00035     private ConfigurationInterface() {
00036         Refresh();
00037 //        for(int i=0;i<sctViews;i++) serialNumberMap[i]=new Hashtable();
00038 //        moduleCount=0;
00039         }
00040 
00041     public static ConfigurationInterface getInstance() {
00042         return instance;
00043     }
00044 
00045    public void setWindowSize(int maxWidth, int maxHeight) {
00046         this.maxWidth=maxWidth;
00047         midX=maxWidth/2;
00048         midY=maxHeight/2;
00049         maxWidth*=0.95;
00050         radius[0]=0.35 * (double)maxWidth/2.;
00051         radius[1]=0.52 * (double)maxWidth/2.;
00052         radius[2]= 0.5 * (double)maxWidth/2.;
00053         radius[3]= 0.76* (double)maxWidth/2.;
00054         radius[4]= 0.74  * (double)maxWidth/2.;
00055         radius[5]= maxWidth/2.;
00056         }
00057 
00058     public void Refresh() {
00059        for(int i=0;i<sctViews;i++) serialNumberMap[i]=new TreeMap();
00060        moduleCells = new ModuleCell[sctViews][][];
00061        snMap = new HashMap();
00062        dcsAvailable=false;
00063         moduleCount=0;   
00064      }
00065 
00066      public boolean isConfigured() {
00067          return (moduleCount>0);
00068          }
00069 
00070      public void getConfiguration() {
00071          getConfiguration(-1);
00072          }
00073 
00074      public void getConfiguration(int moduleGroup) {
00075         h = SystemInterface.getInstance().getConfigurationService();
00076         if(h==null) {
00077                System.err.println("Hardware configuration unavailable - is config_server running?");
00078                return;
00079                }
00080         try {
00081             int[] parts = h.listPartitions();
00082             for(int p=0; p<parts.length; p++) {
00083 //                System.out.println("Partition " + p + " " + parts[p]);
00084                 int[] crates = h.listCratesInPartition(parts[p]);
00085                 for(int c=0; c<crates.length; c++) {
00086 //                    System.out.println("Crate " + c + " " + crates[c]);
00087                     int[] rods = h.listRodsInCrate(parts[p], crates[c]);
00088                     for(int r=0; r<rods.length; r++) {
00089 //                        System.out.println("Rod " + r + " " + rods[r]);
00090                         //sct.RodConfig rodConf = h.getRodConfig(parts[p], crates[c], rods[r]);
00091                         //System.out.println(rodConf.slaves[0].emifFile);
00092 
00093                         int[] MURs = h.listMURSInRod(parts[p], crates[c], rods[r]);
00094                         for(int mur=0; mur<MURs.length; mur++) {
00095 //                            System.out.println("MUR " + mur + " " + MURs[mur]);
00096                             String[] modules = h.listModulesInMUR(parts[p], MURs[mur]);
00097 
00098                             for(int m=0; m<modules.length; m++) {
00099  //                               System.out.println("Module " + m + " " + modules[m]);
00100 
00101                                 IntHolder MUR = new IntHolder(), num = new IntHolder();
00102                                 h.translateFromSN(modules[m], MUR, num);
00103 
00104                                 IntHolder partition = new IntHolder(), crate = new IntHolder(), rodno=new IntHolder(), channel=new IntHolder() ;
00105                                 h.translateToROD(MUR.value, num.value, partition, crate, rodno, channel);
00106 
00107                                 SNInfo snInfo = (SNInfo) snMap.get(modules[m]);
00108                                 if(snInfo==null) snInfo = new SNInfo();
00109                                 snInfo.set(SNInfo.PARTITION,Integer.toString(partition.value));
00110                                 snInfo.set(SNInfo.ROD_CRATE,Integer.toString(crate.value));
00111                                 snInfo.set(SNInfo.ROD_NUMBER,Integer.toString(rodno.value));
00112                                 snInfo.set(SNInfo.ROD_CHANNEL,Integer.toString(channel.value));
00113                                 snMap.put(modules[m],snInfo);   
00114  
00115                                 try {
00116                                     moduleGroup = h.getModuleGroup(modules[m]);
00117                                 }catch(Exception groupE){
00118                                     System.err.println("SctGUI::ConfigurationInterface - can't retrieve moduleGroup : "+groupE.toString());
00119                                     moduleGroup=0;
00120                                     }                 
00121 
00122                                 IntHolder barrel = new IntHolder(), row = new IntHolder(), number = new IntHolder();
00123                                 try {
00124                                   h.translateToBarrel(MUR.value, num.value, barrel, row, number);
00125                                   defineBarrelModuleGraphicsCell(barrel.value, row.value, number.value, MUR.value, moduleGroup, modules[m]);
00126                                 } catch(sctConf.ConfigurationException eConfig) {
00127                                   h.translateToEndcap(MUR.value, num.value, barrel, row, number);
00128                                   defineEndCapModuleGraphicsCell(barrel.value, row.value, number.value, MUR.value, moduleGroup, modules[m]);
00129                                   }
00130                                 try {
00131                                   h.translateToPowerSupply(MUR.value, num.value,partition,crate,channel);
00132                                   definePowerSupplyMapping(crate.value,channel.value,modules[m]);
00133                                 }catch(Exception ee) {}
00134 //               System.out.println("Module "+modules[m]+", Barrel " + barrel.value + ", Row " + row.value + ", Number " + number.value+", MUR "+MUR.value);
00135 
00136                             }
00137                         }
00138                     }
00139                 }
00140             }
00141         } catch(sctConf.ConfigurationException eConfig) {
00142             System.err.println("Configuration exception retrieving configuration " + eConfig.detail);
00143             eConfig.printStackTrace();
00144         } catch(Exception e) {
00145             System.err.println("Non-configuration exception retrieving configuration ..." + e);
00146             e.printStackTrace();
00147         }
00148 
00149      writeLookUpTable();
00150 //        definePowerSupplyMapping(1,5,"20220330200020"); // dummy for test
00151 //        definePowerSupplyMapping(1,6,"20220330200019"); // dummy for test
00152     }
00153 
00154    public void definePowerSupplyMapping(int crate, int channel, String sn) {
00155 
00156       dcsAvailable=true;
00157       SNInfo snInfo = (SNInfo) snMap.get(sn);
00158       if(snInfo==null) snInfo = new SNInfo();
00159 
00160       String crateString = Integer.toString(crate);
00161       snInfo.set(SNInfo.DCS_CRATE,crateString);
00162       String channelString = Integer.toString(channel);
00163       snInfo.set(SNInfo.DCS_CHANNEL,channelString);
00164 
00165       if(crateString.length()==1) crateString="0"+crateString;
00166       if(channelString.length()==1) channelString="0"+channelString;
00167       snInfo.set(SNInfo.DCS_HEADER,"Crate"+crateString+".Channel"+channelString+".");
00168       snInfo.set(SNInfo.IV_FILE_HEADER,"CRATE"+crateString+"CHAN"+channelString);
00169 
00170       snMap.put(sn,snInfo);
00171     
00172       }
00173    public String getSNInfo(String sn, int index) {
00174       SNInfo snInfo = (SNInfo) snMap.get(sn);
00175       if(snInfo==null) return "-1";
00176       return snInfo.get(index);
00177       }
00178 
00179     public boolean isDCSAvailable() {
00180       return dcsAvailable;
00181       }
00182 
00183 
00184     public String addModule(int barrel, int row, int number, int MUR, int moduleGroup, String serialNo) {
00185 
00186         for(int i=0;i<sctViews;i++) {
00187            if(serialNumberMap[i].containsKey(serialNo)) return "Module "+serialNo+" is already defined in "+SCTViewNames[i]; 
00188            } 
00189 
00190         for (Iterator i=serialNumberMap[barrel].entrySet().iterator(); i.hasNext(); ) {
00191               Map.Entry e = (Map.Entry) i.next();
00192               String thisSerialNo = (String)e.getKey();
00193               ModuleCell thisCell = (ModuleCell)e.getValue();
00194               if(thisCell.getRow()==row && thisCell.getModulePosition()==number) return "That location already taken by "+thisCell.getSerialNo();
00195               }
00196       int thisSCTView = barrel;
00197 
00198       try {
00199          moduleGroup = h.getModuleGroup(serialNo);
00200       }catch(Exception ee){System.err.println("SctGUI::ConfigurationInterface - can't retrieve moduleGroup : "+ee.toString());}
00201 
00202       if(barrel<4) {
00203             thisSCTView+=3;
00204             defineBarrelModuleGraphicsCell(thisSCTView, row, number, MUR, moduleGroup, serialNo);
00205             }
00206       else if(barrel>12) {
00207             thisSCTView-=12;
00208             defineEndCapModuleGraphicsCell(thisSCTView, row, number, MUR, moduleGroup, serialNo);
00209             }
00210       else {
00211             thisSCTView-=3;
00212             thisSCTView*=-1;
00213             defineEndCapModuleGraphicsCell(thisSCTView, row, number, MUR, moduleGroup, serialNo);
00214             }
00215       return null;
00216       }
00217 
00218     private void defineBarrelModuleGraphicsCell(int barrel, int row, int number, int MUR, int moduleGroup, String serialNo) {
00219         for(int i=0;i<sctViews;i++) {
00220            if(serialNumberMap[i].containsKey(serialNo)) {
00221               System.out.println("** Module "+serialNo+" defined more than once!");
00222               return;
00223               }   
00224            } 
00225         if(barrel < 3 || barrel > 6) {
00226             System.out.println("** Module "+serialNo+" reported to be in nonexistant barrel " + barrel + "!");
00227             return;
00228         }
00229 
00230         int thisSCTView=barrel-3;
00231         int moduleIndex = number;
00232         moduleIndex+=6;   // concert -6 to -1 to 0 thru 5, and 1 to 6 to 7 thru 12
00233         if(moduleIndex>5) moduleIndex--;  // bring it to 0 thru 11
00234         int thisRow=row;
00235         if(moduleCells[thisSCTView]==null) moduleCells[thisSCTView] = new ModuleCell[barrelRows[thisSCTView]][];
00236         if(moduleCells[thisSCTView][thisRow]==null) moduleCells[thisSCTView][thisRow] = new ModuleCell[12];
00237 
00238 // uncomment next line to put -z on left
00239 //        int xloc=maxWidth/2 + number*boxWidth;
00240 // and next line to put -z on right
00241         int xloc=maxWidth/2 - number*boxWidth;   
00242 //        int yloc = yOffSet + (yOffSetCount[thisSCTView] + row)*boxHeight;
00243         int yloc = yOffSet + (yOffSetCount[thisSCTView] + barrelRows[thisSCTView] - row - 1)*boxHeight;
00244 
00245 //        int yloc = yOffSet + (1 + row)*boxHeight;
00246         int[] xPoints = {xloc,xloc,xloc+boxWidth,xloc+boxWidth};
00247         int[] yPoints = {yloc,yloc+boxHeight,yloc+boxHeight,yloc};
00248 
00249         moduleCells[thisSCTView][thisRow][moduleIndex] = new ModuleCell(serialNo,thisSCTView,row,number,MUR,moduleGroup,xPoints,yPoints,4);
00250         serialNumberMap[thisSCTView].put(serialNo,moduleCells[thisSCTView][thisRow][moduleIndex]);
00251         moduleCount++;
00252     }
00253 
00254     private void defineEndCapModuleGraphicsCell(int disk, int quadrant, int number, int MUR, int moduleGroup, String serialNo) {
00255         for(int i=0;i<sctViews;i++) {
00256            if(serialNumberMap[i].containsKey(serialNo)) {
00257               System.out.println("** Module "+serialNo+" defined more than once!");
00258               return;
00259               }   
00260            } 
00261 // end cap disks -1 to -9 map to sctViews 4 to 12
00262 // end cap disks 1 to 9 map to sctViews 13 to 21
00263         int thisSCTView = (disk<0) ? 3-disk : 12+disk;
00264         if(moduleCells[thisSCTView]==null) moduleCells[thisSCTView] = new ModuleCell[4][];
00265         if(moduleCells[thisSCTView][quadrant]==null) moduleCells[thisSCTView][quadrant] = new ModuleCell[33];
00266 
00267         calculatePolygon(thisSCTView,quadrant,number);
00268 
00269         moduleCells[thisSCTView][quadrant][number] = new ModuleCell(serialNo,thisSCTView,quadrant,number,MUR,moduleGroup,xPoints,yPoints,4);
00270         serialNumberMap[thisSCTView].put(serialNo,moduleCells[thisSCTView][quadrant][number]);
00271         moduleCount++;
00272     }
00273 
00274 
00275 
00276     public ModuleCell getCell(int sctView, int x, int y) {
00277 // return cell for positition x,y for given barrel
00278 // index    0  1  2  3  4  5  6  7  8  9  10  11
00279 // xIndex  -5 -4 -3 -2 -1  0  1  2  3  4  5   6
00280         if(sctView<4) {
00281 //          int yIndex = (y-yOffSet-(yOffSetCount[sctView]*boxHeight))/boxHeight;
00282           int yIndex =  ((yOffSetCount[sctView]+barrelRows[sctView])*boxHeight - y + yOffSet)/boxHeight;
00283           if(yIndex<0 || yIndex>barrelRows[sctView]-1) return null;
00284           int diff = x -maxWidth/2;
00285 
00286           int xIndex = diff/boxWidth;
00287           if(diff>0 && xIndex==0) return null;  // inside middle gap
00288 //********************************************************
00289 // following 2 lines reverses ordering in x, ie -z on right
00290           xIndex*=-1;
00291           xIndex+=6;
00292 //********************************************************
00293 // otherwise uncomment this to revert to -z on left
00294 //          xIndex+=5; // convert -5 to -0 to 0 thru 5, and 1 to 6 to 6 thru 11
00295 
00296           if(xIndex<0 || xIndex>11) return null;   
00297           if(moduleCells[sctView]!=null && moduleCells[sctView][yIndex]!=null) {
00298               if(moduleCells[sctView][yIndex][xIndex]!=null) return moduleCells[sctView][yIndex][xIndex];
00299               }
00300           }
00301         else {
00302           // for endsaps, just enumerate through for the moment.
00303           // probably quicker than calculating explicity from x and y?
00304             for (Iterator i=serialNumberMap[sctView].entrySet().iterator(); i.hasNext(); ) {
00305                Map.Entry e = (Map.Entry) i.next();
00306                ModuleCell thisCell = (ModuleCell)e.getValue();
00307                if(thisCell.contains(x,y)) return thisCell;
00308                }
00309           } 
00310           return null;
00311     }
00312 
00313     public Hashtable getSerialNumberMap(int sctView) {
00314         return new Hashtable(serialNumberMap[sctView]);
00315         }
00316     public SortedMap[] getSerialNumberMap() {
00317         return serialNumberMap;
00318         }
00319     public int getNumberOfModules(int sctView) {
00320         return serialNumberMap[sctView].size();
00321         }
00322     public int getTotalNumberOfModules() {
00323        return moduleCount;
00324        }
00325     public Set getSortedVector(int sctView) {
00326         return serialNumberMap[sctView].keySet();
00327       }
00328     public ModuleCell getModuleCell(int sctView, String serialNo) {
00329       return (ModuleCell)serialNumberMap[sctView].get(serialNo);
00330       }
00331 
00332     public void drawSCTViewOutline(java.awt.Graphics2D g2,int selection) {
00333         g2.setColor(java.awt.Color.lightGray);
00334         g2.setFont(displayTextFont);
00335         java.awt.FontMetrics metrics = g2.getFontMetrics();
00336         int rowNo=0;
00337 
00338         switch(selection) {
00339           case Barrel3:
00340           case Barrel4:
00341           case Barrel5:
00342             int x1 = midX-100;
00343             int x2 = midX+120;
00344             int yy = yOffSetCount[selection];
00345             int y1 = yOffSet +((yy-2)*boxHeight);
00346             g2.drawLine(x1,y1,x2,y1);
00347             g2.drawLine(x1,y1,x1+5,y1-5);
00348             g2.drawLine(x1,y1,x1+5,y1+5);
00349             g2.drawLine(x2,y1,x2-5,y1-5);
00350             g2.drawLine(x2,y1,x2-5,y1+5);
00351             g2.drawString("Z+",x1-20,y1);
00352             g2.drawString("Z-",x2+10,y1);
00353           case Barrel6:
00354             int ilow = yOffSetCount[selection];
00355 //            int ilow = 1;
00356             int ihigh = ilow+barrelRows[selection];
00357             int midX= maxWidth/2;
00358 
00359 //            for(int y=ilow;y<ihigh;y++) {
00360             for(int y=ihigh-1;y>=ilow;y--) {
00361               String rowLabel = Integer.toString(rowNo);
00362               int labelWidth = metrics.stringWidth(rowLabel);
00363               int xLabel = midX - 6*boxWidth - labelWidth -8;
00364 
00365               int thisRow = rowNo;
00366               boolean rowUsed = (moduleCells[selection]!=null && moduleCells[selection][thisRow]!=null);
00367               g2.setColor(java.awt.Color.lightGray);
00368               for(int x=-6;x<=6;x++) {
00369                 if(x==0) continue;                 
00370                 g2.drawRect(midX+(boxWidth*x),yOffSet+(y*boxHeight), boxWidth, boxHeight);
00371                 }
00372               java.awt.Color labelColor = rowUsed ? java.awt.Color.black : java.awt.Color.lightGray;  
00373               g2.setColor(labelColor);
00374               g2.drawString(rowLabel,xLabel,yOffSet+y*boxHeight+boxHeight);
00375               rowNo++;
00376               }
00377               g2.setColor(java.awt.Color.lightGray);
00378               g2.drawRect(midX - 6*boxWidth, yOffSet, 13*boxWidth, 56*boxHeight); //outer line for barrels 3,4,5
00379               break;
00380            case EndCap1a:
00381            case EndCap1c:
00382            case EndCap7a:
00383            case EndCap7c:
00384            case EndCap8a:
00385            case EndCap8c:
00386               for(int quadrant=0;quadrant<4;quadrant++) {
00387                  for(int number=13;number<23;number++) {
00388                      calculatePolygon(selection,quadrant,number);
00389                      if(polygon!=null) {
00390                         g2.setColor(java.awt.Color.white);
00391                         g2.fill(polygon);
00392                         g2.setColor(java.awt.Color.lightGray);
00393                         g2.draw(polygon);
00394                         }
00395                      }
00396                   }
00397               for(int quadrant=0;quadrant<4;quadrant++) {
00398                  for(int number=0;number<13;number++) {
00399                      calculatePolygon(selection,quadrant,number);
00400                      if(polygon!=null) {
00401                         g2.setColor(java.awt.Color.white);
00402                         g2.fill(polygon);
00403                         g2.setColor(java.awt.Color.lightGray);
00404                         g2.draw(polygon);
00405                         }
00406                      }
00407                  }
00408               break;
00409            case EndCap2a:
00410            case EndCap2c:
00411            case EndCap3a:
00412            case EndCap3c:
00413            case EndCap4a:
00414            case EndCap4c:
00415            case EndCap5a:
00416            case EndCap5c:   
00417            case EndCap6a:
00418            case EndCap6c:   
00419               for(int quadrant=0;quadrant<4;quadrant++) {
00420                  for(int number=13;number<23;number++) {
00421                      calculatePolygon(selection,quadrant,number);
00422                      if(polygon!=null) {
00423                         g2.setColor(java.awt.Color.white);
00424                         g2.fill(polygon);
00425                         g2.setColor(java.awt.Color.lightGray);
00426                         g2.draw(polygon);
00427                         }
00428                      }
00429                   }
00430               for(int quadrant=0;quadrant<4;quadrant++) {
00431                  for(int number=0;number<33;number++) {
00432                      if(number>=13 && number<23) continue;
00433                      calculatePolygon(selection,quadrant,number);
00434                      if(polygon!=null) {
00435                         g2.setColor(java.awt.Color.white);
00436                         g2.fill(polygon);
00437                         g2.setColor(java.awt.Color.lightGray);
00438                         g2.draw(polygon);
00439                         }
00440                      }
00441                  }
00442               break;     
00443            case EndCap9a:
00444            case EndCap9c:
00445               for(int quadrant=0;quadrant<4;quadrant++) {
00446                  for(int number=0;number<13;number++) {
00447                      calculatePolygon(selection,quadrant,number);
00448                      if(polygon!=null) g2.draw(polygon);
00449                      }
00450                  }
00451               break;
00452            default:     
00453 
00454             }
00455 
00456  
00457     }
00458 
00459   private void calculatePolygon(int view, int quadrant, int number) {
00460         double thetaOffset=0.;
00461         double theta=0.;
00462         int rindex=0;
00463         int segment=0;
00464         int modules=0;
00465         if(number<13) {
00466              thetaOffset = Math.PI/52.;
00467              theta = Math.PI/26.;
00468              rindex=4;
00469              segment=number;
00470              modules=13;
00471 //********************************
00472 // encap 9 disks - module numbering in each MUR is reversed
00473 // ie 0<-->5, 1<-->4 etc
00474 // 6 special case
00475 // 7 <-->12, 8<-->11 etc
00476 //********************************
00477              if((view==EndCap9a || view==EndCap9c) && segment!=6) {
00478                if(segment<6) segment = Math.abs(segment-5);
00479                else segment = Math.abs(segment-19);
00480                }
00481              }
00482         else if(number>=13 && number<23) {
00483              thetaOffset=0.;
00484              theta = Math.PI/20.;
00485              rindex=2;
00486              segment=number-13;
00487              modules=10;
00488              }
00489         else {
00490              thetaOffset=Math.PI/40.;
00491              theta = Math.PI/20.;
00492              rindex=0;
00493              segment=number-23;
00494              modules=10;
00495              }
00496         segment += quadrant*modules;
00497 
00498         xPoints[0] = midX+(int)(radius[rindex]*Math.sin(segment*theta+thetaOffset));
00499         xPoints[1] = midX+(int)(radius[rindex]*Math.sin((segment+1)*theta+thetaOffset));
00500         xPoints[2] = midX+(int)(radius[rindex+1]*Math.sin((segment+1)*theta+thetaOffset));
00501         xPoints[3] = midX+(int)(radius[rindex+1]*Math.sin(segment*theta+thetaOffset));
00502 
00503         yPoints[0] = midY-(int)(radius[rindex]*Math.cos(segment*theta+thetaOffset));
00504         yPoints[1] = midY-(int)(radius[rindex]*Math.cos((segment+1)*theta+thetaOffset));
00505         yPoints[2] = midY-(int)(radius[rindex+1]*Math.cos((segment+1)*theta+thetaOffset));
00506         yPoints[3] = midY-(int)(radius[rindex+1]*Math.cos(segment*theta+thetaOffset));
00507         polygon = new java.awt.Polygon(xPoints,yPoints,4);
00508 //        for(int i=0;i<4;i++) System.out.println("Polygon : Quadrant="+quadrant+" number="+number+" XY("+i+") : "+xPoly[i]+","+yPoly[i]);
00509         }
00510 
00511    public void updateModuleGroups(List cellList) {
00512        for(int i=0;i<cellList.size();i++) {
00513            ModuleCell thisCell = (ModuleCell)cellList.get(i);
00514            try {
00515               h.setModuleGroup(thisCell.getSerialNo(),(short)thisCell.getModuleGroup());
00516            }catch(Exception e){System.err.println("Exception setting modulegroup for module "+thisCell.getSerialNo()+" : "+e.toString());}
00517            }
00518        }
00519    private void writeLookUpTable() {
00520        String directory = Preferences.PreferencesInterface.getInstance().getPreference(Preferences.PreferencesInterface.WEB_LOOKUP_DIR);
00521        if(directory.equals(Preferences.PreferencesInterface.unDefinedString)) return;
00522 
00523 //       Map lookupMap = getLookUpMap(directory);
00524 
00525        for(int i=0;i<SCTViewNames.length;i++) {
00526           Map lookupMap = new HashMap();
00527           Set moduleList = getSortedVector(i);
00528           for (java.util.Iterator m = moduleList.iterator(); m.hasNext(); ) {
00529              String thisSN=(String)m.next();
00530              ModuleCell thisCell = getModuleCell(i,thisSN);
00531              String desc = SCTViewNames[i]+", Row "+thisCell.getRow()+", Position "+thisCell.getPosition();
00532              lookupMap.put(thisSN,desc);
00533              }
00534              if(lookupMap.size()>0) saveLookUpMap(i,directory,lookupMap);
00535           }
00536 //        lookupMap=null; // might be large!!
00537 
00538         }
00539    private Map getLookUpMap(String directory) {
00540         Map thisMap = new HashMap();
00541         java.util.regex.Pattern p = java.util.regex.Pattern.compile("(\\d{14})=(.*)");
00542         java.io.File lookupFile = new java.io.File(directory,"moduleMap.txt");
00543         try {
00544           if(lookupFile.exists()) {
00545             java.io.BufferedReader in = new java.io.BufferedReader(new java.io.FileReader(lookupFile));
00546             String line;
00547             while((line=in.readLine())!=null) {
00548                java.util.regex.Matcher matcher = p.matcher(line);
00549                if(matcher.matches()) thisMap.put(line.substring(matcher.start(1),matcher.end(1)),line.substring(matcher.start(2),matcher.end(2)));
00550                }
00551             in.close();
00552            }
00553          }catch(Exception e){System.err.println("SctGUI::ConfigurationInterface - Exception reading in "+lookupFile.getName()+" - "+e.toString());}
00554          return thisMap;
00555          }
00556    private void saveLookUpMap(int view,String directory,Map thisMap) {
00557         java.io.File lookupFile = new java.io.File(directory,"moduleMap"+Integer.toString(view)+".txt");
00558         int lineCount=0;
00559         try {
00560           java.io.BufferedWriter out = new java.io.BufferedWriter(new java.io.FileWriter(lookupFile));
00561           String line;
00562           for (Iterator i=thisMap.entrySet().iterator(); i.hasNext(); ) {
00563             Map.Entry e = (Map.Entry) i.next();
00564             out.write((String)e.getKey()+"="+(String)e.getValue());
00565             out.newLine();
00566             lineCount++;
00567             }
00568            out.close();
00569 //           System.out.println("SctGUI::ConfigurationInterface - wrote "+lineCount+" records to "+lookupFile.getName());
00570          }catch(Exception e){System.err.println("SctGUI::ConfigurationInterface - Exception writing to "+lookupFile.getName()+" - "+e.toString());}         
00571          }
00572          
00573           
00574            
00575 
00576 
00577         
00578 
00579 
00580 }

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