SctApiInfo.java

00001 package DisplayGUI;
00002 import GuiComponents.System.*;
00003 import Sct_SctApi.*;
00004 
00005 public class SctApiInfo implements TestDataInfo {
00006         private static SctApiInfo instance = new SctApiInfo();
00007         Sct_SctApi.SctApiIPC api;
00008         sctConf.Configuration sctconf;
00009         ConfigurationInterface guiConfig=null;
00010         java.util.Map probeHash, countHash, chanMap, chanMap2;
00011         String[] dTypes ={"0","1","2","J","E"};
00012         java.util.regex.Pattern keyPattern = java.util.regex.Pattern.compile("(\\d+)\\*(\\d+)\\*(\\d+)");
00013         java.util.Vector chanList;
00014         java.util.Set errorModuleList;
00015 
00016 
00017 public static SctApiInfo getInstance() {
00018       return instance;
00019         }
00020 
00021 private SctApiInfo() {
00022       probeHash = new java.util.HashMap();
00023       countHash = new java.util.HashMap();
00024       }
00025 
00026 public boolean refreshChannelMap(int viewCategory, int selectedView) {
00027 
00028         sctconf = SystemInterface.getInstance().getConfigurationService();
00029         if(sctconf==null) {
00030         javax.swing.JOptionPane.showMessageDialog(null,"Configuration Service is not available.");
00031         return false;
00032         }
00033       api = SystemInterface.getInstance().getSctApi();
00034         if(api==null) {
00035         javax.swing.JOptionPane.showMessageDialog(null,"SctApi is not available.");
00036         return false;
00037         }
00038 
00039         chanMap = new java.util.HashMap();
00040         chanMap2 = new java.util.HashMap();
00041    // first loop trough all modules to determine which RODs we need to probe, and their channels
00042       guiConfig = ConfigurationInterface.getInstance();
00043       for (java.util.Iterator m = guiConfig.getSerialNumberList(viewCategory,selectedView).iterator(); m.hasNext(); ) {
00044         String sn=(String)m.next();
00045                 String crate = guiConfig.getSNInfo(sn,SNInfo.ROD_CRATE);
00046                 String rod = guiConfig.getSNInfo(sn,SNInfo.ROD_NUMBER);
00047                 String chan = guiConfig.getSNInfo(sn,SNInfo.ROD_CHANNEL);
00048                 String partition = guiConfig.getSNInfo(sn,SNInfo.PARTITION);
00049                 String key = partition+"*"+crate+"*"+rod;
00050                 if(chanMap.containsKey(key)) chanList = (java.util.Vector)chanMap.get(key);
00051                 else chanList =  new java.util.Vector();
00052                 chanList.addElement(chan);
00053                 chanMap.put(key,chanList);
00054                 chanMap2.put(key+"*"+chan,sn);
00055                 }
00056     // now chanMap is map of parition*crate*rod to vector of channels in that rod
00057     // chanMap2 is a map of partition*crate*rod*chan to serial number
00058     return true;
00059         }
00060 
00061 public void probeConfig(int viewCategory, int selectedView, int BOCParameter) {
00062 
00063         sctConf.BOCChannelConfig [] block;
00064         byte[] mappings;
00065 
00066         probeHash = new java.util.HashMap();
00067 
00068         if(!refreshChannelMap(viewCategory,selectedView)) return;
00069 
00070     // iterate through chanMap
00071         for (java.util.Iterator i=chanMap.entrySet().iterator(); i.hasNext(); ) {
00072                 java.util.Map.Entry e = (java.util.Map.Entry) i.next();
00073                 String key = (String)e.getKey();
00074                 chanList = (java.util.Vector)e.getValue();
00075 
00076                 java.util.regex.Matcher matcher = keyPattern.matcher(key);
00077                 if(!matcher.matches()) {
00078                 System.err.println("**ERROR no key match in SctApiInfo");
00079                 continue;
00080                 }
00081 
00082                 String partition = key.substring(matcher.start(1),matcher.end(1));
00083                 String crate = key.substring(matcher.start(2),matcher.end(2));
00084                 String rod = key.substring(matcher.start(3),matcher.end(3));
00085 
00086                 int icrate = Integer.valueOf(crate).intValue();
00087                 int irod = Integer.valueOf(rod).intValue();
00088                 int ipartition = Integer.valueOf(partition).intValue();
00089 
00090                 try {
00091                         block = api.currentBOCSetup(ipartition, icrate, irod);
00092                         if(block.length!=48) {
00093                                 System.err.println("Got "+block.length+" values from api.currentBOCSetup?");
00094                                 continue;
00095                                 }
00096                         // mappings:
00097                         // [0,1,2] is chan0 TX Stream0 Stream1 fibre mapping
00098                         // [3,4,5] is chan1 TX Stream0 Stream1 fibre mapping ...etc
00099                         // eg 0,0,1  1,2,3  2,4,5  3,6,7 etc
00100                         mappings = sctconf.getFibreMappings(ipartition,icrate,irod);
00101                         }
00102                 catch(Exception ee) {javax.swing.JOptionPane.showMessageDialog(null,"Exception from SctApi: "+ee.toString()); return;}
00103 
00104                 for(int j=0;j<chanList.size();j++) {
00105                         String chan = (String)chanList.elementAt(j);
00106                 int ichan = Integer.valueOf(chan).intValue();
00107                         Double data = null;
00108 
00109                         LinkData linkData = new LinkData();
00110 
00111                         byte mappingIndex;
00112 
00113                 switch(BOCParameter) {
00114                                 case 1: // TX Current
00115                                         mappingIndex = mappings[ichan*3];
00116                                         //System.out.println("chan="+chan+" mappingindex="+mappingIndex);
00117                                         if(mappingIndex>=0) linkData.put(0,Double.valueOf((double)block[mappingIndex].current));
00118                                         break;
00119                                 case 2:// TX Coarse Delay
00120                                         mappingIndex = mappings[ichan*3];
00121                                         //System.out.println("chan="+chan+" mappingindex="+mappingIndex);
00122                                         if(mappingIndex>=0) linkData.put(0,Double.valueOf((double)((block[mappingIndex].delay & 0xff00) >> 8)));
00123                                         break;
00124                                 case 3: // TX Fine Delay
00125                                         mappingIndex = mappings[ichan*3];
00126                                         //System.out.println("chan="+chan+" mappingindex="+mappingIndex);
00127                                         if(mappingIndex>=0) linkData.put(0,Double.valueOf((double)(block[mappingIndex].delay & 0xff)));
00128                                         break;
00129                                 case 4: // Mark Space Ratio
00130                                         mappingIndex = mappings[ichan*3];
00131                                         //System.out.println("chan="+chan+" mappingindex="+mappingIndex);
00132                                         if(mappingIndex>=0) linkData.put(0,Double.valueOf((double)block[mappingIndex].markSpace));
00133                                         break;
00134                                 case 5: // RX Threshold 0
00135                                 case 7: // RX Threshold 1
00136                                         mappingIndex = mappings[ichan*3 + 1];
00137                                         if(mappingIndex>=0) {
00138                                                 int newchan = mappingIndex/2;
00139                                                 //System.out.println("chan="+chan+" mappingIndex="+mappingIndex+" actual chan="+newchan);
00140                                                 linkData.put(0,Double.valueOf((double)block[newchan].threshold0));
00141                                                 }
00142                                         mappingIndex = mappings[ichan*3 + 2];
00143                                         if(mappingIndex>=0) {
00144                                                 int newchan = mappingIndex/2;
00145                                                 //System.out.println("chan="+chan+" mappingIndex="+mappingIndex+" actual chan="+newchan);
00146                                                 linkData.put(1,Double.valueOf((double)block[newchan].threshold1));
00147                                                 }
00148                                         break;
00149                                 case 6: // RX Delay 0
00150                                 case 8: // RX Delay 1
00151                                         mappingIndex = mappings[ichan*3 + 1];
00152                                         if(mappingIndex>=0) {
00153                                                 int newchan = mappingIndex/2;
00154                                                 //System.out.println("chan="+chan+" mappingIndex="+mappingIndex+" actual chan="+newchan);
00155                                                 linkData.put(0,Double.valueOf((double)block[newchan].delay0));
00156                                                 }
00157                                         mappingIndex = mappings[ichan*3 + 2];
00158                                         if(mappingIndex>=0) {
00159                                                 int newchan = mappingIndex/2;
00160                                                 //System.out.println("chan="+chan+" mappingIndex="+mappingIndex+" actual chan="+newchan);
00161                                                 linkData.put(1,Double.valueOf((double)block[newchan].delay1));
00162                                                 }
00163                                         break;
00164                                 default:
00165                         }
00166 
00167                     String thisKey = partition+"*"+crate+"*"+rod+"*"+chan;
00168                     probeHash.put(thisKey,linkData);
00169                         } // chan loop
00170                 } // rod loop
00171         }
00172 
00173    public void probe(int viewCategory, int selectedView) {
00174         probe(viewCategory, selectedView, false);
00175         }
00176 
00177 
00178    public void probe(int viewCategory, int selectedView, boolean listBadModules) {
00179 
00180    countHash = new java.util.HashMap();
00181    probeHash = new java.util.HashMap();
00182    errorModuleList = new java.util.HashSet();
00183 
00184    if(!refreshChannelMap(viewCategory,selectedView)) return;
00185 
00186     // iterate through chanMap
00187     for (java.util.Iterator i=chanMap.entrySet().iterator(); i.hasNext(); ) {
00188            java.util.Map.Entry e = (java.util.Map.Entry) i.next();
00189            String key = (String)e.getKey();
00190            chanList = (java.util.Vector)e.getValue();
00191 
00192            java.util.regex.Matcher matcher = keyPattern.matcher(key);
00193            if(!matcher.matches()) {
00194               System.err.println("**sctGUI: ERROR no key match in SctApiInfo for key "+key);
00195               continue;
00196               }
00197 
00198            String partition = key.substring(matcher.start(1),matcher.end(1));
00199            String crate = key.substring(matcher.start(2),matcher.end(2));
00200            String rod = key.substring(matcher.start(3),matcher.end(3));
00201 
00202            int icrate = Integer.valueOf(crate).intValue();
00203            int irod = Integer.valueOf(rod).intValue();
00204            int ipartition = Integer.valueOf(partition).intValue();
00205 
00206            // probe rod
00207            short[] results;
00208            byte[] mappings;
00209            try {
00210              results = api.probe(ipartition, icrate, irod);
00211              if(results.length!=96) {
00212                 System.err.println("**sctGUI: Got "+results.length+" values from api.probe?");
00213                 continue;
00214                 }
00215            // get fibre mappings for rod, in case any are set explicitly in xml file
00216              mappings = sctconf.getFibreMappings(ipartition,icrate,irod);
00217          //    System.out.println("Got "+mappings.length+" mappings from getFibreMappings for rod "+irod);
00218              }catch(Exception ee){System.err.println("**sctGUI Exception in SctapiInfo::probe - "+ee.toString()); continue;}
00219            
00220            for(int j=0;j<chanList.size();j++) {
00221                 String chan = (String)chanList.elementAt(j);
00222               int ichan = Integer.valueOf(chan).intValue();
00223 
00224               LinkData linkData = new LinkData();
00225                 String thisKey = partition+"*"+crate+"*"+rod+"*"+chan;
00226 
00227                 for(int link=0;link<2;link++) {
00228 
00229                         int index = ichan*3 + link + 1;
00230                         byte mappingIndex = mappings[index];
00231                 //   System.out.println("Key "+key+" Link "+link+" channel "+chan+" maps to "+mappingIndex);
00232                         if(mappingIndex<0) continue;  // link switched off?
00233 
00234                         short value = (mappingIndex>=0) ? results[mappingIndex] : 48;
00235                 String thisChar = Character.toString((char)value);
00236                 if(!countHash.containsKey(thisChar)) countHash.put(thisChar, new Integer(1));
00237                 else {
00238                         int thiscount = ((Integer)countHash.get(thisChar)).intValue();
00239                                 thiscount++;
00240                                 countHash.put(thisChar, new Integer(thiscount));
00241                                 }
00242 
00243 
00244                    Double data = new Double(5.0);
00245                    switch(value) {
00246                         case 48:
00247                                 data = new Double(0.0);  // 0
00248                                 break;
00249                         case 49:
00250                                 data = new Double(1.0);  // 1
00251                                 break;
00252                         case 50:
00253                                 data = new Double(2.0);  // 2
00254                                 break;
00255                 case 69:
00256                                 data = new Double(4.0);  // E
00257                                  break;
00258                 case 74:
00259                                 data = new Double(3.0);  // J
00260                                 break;
00261                         default:
00262                         }
00263 
00264                     if(errorModuleList!=null && value!=69) errorModuleList.add((String)chanMap2.get(thisKey));
00265                     linkData.put(link,data);
00266                     } // link loop
00267                     probeHash.put(thisKey,linkData);
00268                 }  // chan loop
00269           } // rod loop
00270      }
00271 
00272      public java.util.Set getErrorModuleList() {return errorModuleList;}
00273          
00274      public Double getProbeData(String sn, int link) {
00275         if(guiConfig==null) return null;
00276                 String crate = guiConfig.getSNInfo(sn,SNInfo.ROD_CRATE);
00277                 String rod = guiConfig.getSNInfo(sn,SNInfo.ROD_NUMBER);
00278                 String chan = guiConfig.getSNInfo(sn,SNInfo.ROD_CHANNEL);
00279                 String partition = guiConfig.getSNInfo(sn,SNInfo.PARTITION);
00280                 String key = partition+"*"+crate+"*"+rod+"*"+chan;
00281         if(!probeHash.containsKey(key)) return null;
00282                 LinkData lData = (LinkData)probeHash.get(key);
00283                 return lData.getData(link);
00284                 }
00285      public java.util.Vector getCountVector() {
00286         java.util.Vector table = new java.util.Vector();
00287                 java.util.Vector theLine = new java.util.Vector();
00288                 theLine.addElement("Result");
00289                 theLine.addElement("Count");
00290                 table.addElement(theLine);
00291 
00292          for (int i=0;i<dTypes.length;i++) {
00293             theLine = new java.util.Vector();
00294             theLine.addElement(dTypes[i]);
00295             if(!countHash.containsKey(dTypes[i])) theLine.addElement(new Integer(0));
00296             else theLine.addElement((Integer)countHash.get(dTypes[i]));
00297             table.addElement(theLine);
00298             }
00299         return table;
00300         }
00301      public void checkProbe() {
00302         try  {
00303             String txt = javax.swing.JOptionPane.showInputDialog(null,"Probe Pattern?","E");
00304             txt.toUpperCase();
00305             if(SystemInterface.getInstance().getSctApi().checkAllModulesProbe(txt)) {
00306                 javax.swing.JOptionPane.showMessageDialog(null, "Check modules succeeded");
00307             } else {
00308                 javax.swing.JOptionPane.showMessageDialog(null, "Check modules failed, see MRS for details");
00309             }
00310         } catch(Sct_SctApi.SctApiException s) {
00311             javax.swing.JOptionPane.showMessageDialog(null, "Check modules aborted: " + s);
00312         }
00313     }
00314 
00315 
00316 }
00317 

Generated on Mon Feb 6 14:12:18 2006 for SCT DAQ/DCS Software - Java by  doxygen 1.4.6