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

SctApiInfo.java

00001 package DisplayGUI;
00002 import GuiComponents.System.*;
00003 import Sct_SctApi.*;
00004 
00005 public class SctApiInfo {
00006     private static SctApiInfo instance = new SctApiInfo();
00007     Sct_SctApi.SctApiIPC api;
00008     ConfigurationInterface guiConfig=null;
00009     java.util.Map probeHash, countHash;
00010     String[] dTypes ={"0","1","2","J","E"};
00011 
00012 
00013     public static SctApiInfo getInstance() {
00014         return instance;
00015     }
00016 
00017    private SctApiInfo() {
00018       probeHash = new java.util.HashMap();
00019       countHash = new java.util.HashMap();
00020       }
00021       
00022    public void probe(int selectedView) {
00023 
00024    countHash = new java.util.HashMap();
00025    probeHash = new java.util.HashMap();
00026 
00027    api = SystemInterface.getInstance().getSctApi();
00028    guiConfig = ConfigurationInterface.getInstance();
00029    sctConf.Configuration h = SystemInterface.getInstance().getConfigurationService();
00030    if(h==null) {
00031       javax.swing.JOptionPane.showMessageDialog(null,"Configuration Service is not available.");
00032       return;
00033       }
00034 
00035    java.util.Map chanMap = new java.util.HashMap();
00036    java.util.regex.Pattern keyPattern = java.util.regex.Pattern.compile("(\\d+)\\*(\\d+)\\*(\\d+)");
00037    java.util.Vector chanList;
00038    // first loop trough all modules to determine which RODs we need to probe, and their channels
00039    for(java.util.Enumeration e = guiConfig.getSerialNumberMap(selectedView).elements(); e.hasMoreElements();) {
00040            ModuleCell thisCell = (ModuleCell) e.nextElement();
00041            String sn = thisCell.getSerialNo();
00042            String crate = guiConfig.getSNInfo(sn,SNInfo.ROD_CRATE);
00043            String rod = guiConfig.getSNInfo(sn,SNInfo.ROD_NUMBER);
00044            String chan = guiConfig.getSNInfo(sn,SNInfo.ROD_CHANNEL);
00045            String partition = guiConfig.getSNInfo(sn,SNInfo.PARTITION);
00046            
00047            String key = partition+"*"+crate+"*"+rod;
00048            if(chanMap.containsKey(key)) chanList = (java.util.Vector)chanMap.get(key);
00049            else chanList =  new java.util.Vector();
00050            chanList.addElement(chan);
00051            chanMap.put(key,chanList);
00052            }
00053     // now chanMap is map of parition*crate*rod to vector of channels in that rod
00054     // iterate through chanMap
00055     for (java.util.Iterator i=chanMap.entrySet().iterator(); i.hasNext(); ) {
00056            java.util.Map.Entry e = (java.util.Map.Entry) i.next();
00057            String key = (String)e.getKey();
00058            chanList = (java.util.Vector)e.getValue();
00059 
00060            java.util.regex.Matcher matcher = keyPattern.matcher(key);
00061            if(!matcher.matches()) {
00062               System.err.println("**ERROR no key match in SctApiInfo");
00063               continue;
00064               }
00065 
00066            String partition = key.substring(matcher.start(1),matcher.end(1));
00067            String crate = key.substring(matcher.start(2),matcher.end(2));
00068            String rod = key.substring(matcher.start(3),matcher.end(3));
00069 
00070            int icrate = Integer.valueOf(crate).intValue();
00071            int irod = Integer.valueOf(rod).intValue();
00072            int ipartition = Integer.valueOf(partition).intValue();
00073 
00074            // probe rod
00075            short[] results;
00076            byte[] mappings;
00077            try {
00078              results = api.probe(ipartition, icrate, irod);
00079              if(results.length!=96) {
00080                 System.err.println("Got "+results.length+" values from api.probe?");
00081                 continue;
00082                 }
00083            // get fibre mappings for rod, in case any are set explicitly in xml file
00084              mappings = h.getFibreMappings(ipartition,icrate,irod);
00085          //    System.out.println("Got "+mappings.length+" mappings from getFibreMappings for rod "+irod);
00086              }catch(Exception ee){System.err.println("**sctGUI Exception in SctapiInfo::probe - "+ee.toString()); continue;}
00087            
00088            for(int j=0;j<chanList.size();j++) {
00089                 String chan = (String)chanList.elementAt(j);
00090                 int ichan = Integer.valueOf(chan).intValue();
00091 
00092                 LinkData linkData = new LinkData();
00093                 
00094         //      System.out.println("Key "+key+" channel "+chan);
00095                 
00096                 for(int link=0;link<2;link++) {
00097                 
00098                    int index = ichan*3 + link + 1;
00099                    byte mappingIndex = mappings[index];
00100                 //   System.out.println("Key "+key+" Link "+link+" channel "+chan+" maps to "+mappingIndex);
00101                    if(mappingIndex<0) {  // link switched off?
00102         //             System.out.println("*** mappingIndex "+mappingIndex+" for key "+key+" channel "+chan);
00103                        continue;
00104                        }
00105                 
00106                    short value = (mappingIndex>=0) ? results[mappingIndex] : 48;
00107 
00108 
00109                    String thisChar = Character.toString((char)value);
00110                    if(!countHash.containsKey(thisChar)) countHash.put(thisChar, new Integer(1));
00111                    else {
00112                         int thiscount = ((Integer)countHash.get(thisChar)).intValue();
00113                         thiscount++;
00114                         countHash.put(thisChar, new Integer(thiscount));
00115                         }
00116 
00117 
00118                    Double data = new Double(5.0);
00119                    switch(value) {
00120                         case 48:
00121                                 data = new Double(0.0);  // 0
00122                                 break;
00123                         case 49:
00124                                 data = new Double(1.0);  // 1
00125                                 break;
00126                         case 50:
00127                                 data = new Double(2.0);  // 2
00128                                 break;
00129                         case 69:
00130                                 data = new Double(4.0);  // E
00131                                  break;
00132                         case 74:
00133                                 data = new Double(3.0);  // J
00134                                 break;
00135                         default:
00136                         }
00137                     linkData.put(link,data);
00138                     } // link loop
00139                     String thisKey = partition+"*"+crate+"*"+rod+"*"+chan;
00140                     probeHash.put(thisKey,linkData);
00141                 }  // chan loop
00142           } // rod loop
00143      }
00144          
00145      public Double getProbeData(String sn, int link) {
00146          if(guiConfig==null) return null;
00147          String crate = guiConfig.getSNInfo(sn,SNInfo.ROD_CRATE);
00148          String rod = guiConfig.getSNInfo(sn,SNInfo.ROD_NUMBER);
00149          String chan = guiConfig.getSNInfo(sn,SNInfo.ROD_CHANNEL);
00150          String partition = guiConfig.getSNInfo(sn,SNInfo.PARTITION);
00151          String key = partition+"*"+crate+"*"+rod+"*"+chan;
00152          if(!probeHash.containsKey(key)) return null;
00153          LinkData lData = (LinkData)probeHash.get(key);
00154          return lData.getData(link);
00155          }
00156      public java.util.Vector getCountVector() {
00157          java.util.Vector table = new java.util.Vector();
00158          java.util.Vector theLine = new java.util.Vector();
00159          theLine.addElement("Result");
00160          theLine.addElement("Count");
00161          table.addElement(theLine);
00162 
00163          for (int i=0;i<dTypes.length;i++) {
00164             theLine = new java.util.Vector();
00165             theLine.addElement(dTypes[i]);
00166             if(!countHash.containsKey(dTypes[i])) theLine.addElement(new Integer(0));
00167             else theLine.addElement((Integer)countHash.get(dTypes[i]));
00168             table.addElement(theLine);
00169             }
00170         return table;
00171         }
00172      public void checkProbe() {
00173         try  {
00174             String txt = javax.swing.JOptionPane.showInputDialog(null,"Probe Pattern?","E");
00175             txt.toUpperCase();
00176             if(SystemInterface.getInstance().getSctApi().checkAllModulesProbe(txt)) {
00177                 javax.swing.JOptionPane.showMessageDialog(null, "Check modules succeeded");
00178             } else {
00179                 javax.swing.JOptionPane.showMessageDialog(null, "Check modules failed, see MRS for details");
00180             }
00181         } catch(Sct_SctApi.SctApiException s) {
00182             javax.swing.JOptionPane.showMessageDialog(null, "Check modules aborted: " + s);
00183         }
00184     }
00185 
00186 
00187 }
00188 

Generated on Fri Sep 16 18:06:01 2005 for SCT DAQ/DCS Software - Java by doxygen 1.3.5