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

ISInterface.java

00001 package DisplayGUI;
00002 
00003 import java.io.*;
00004 import java.util.*;
00005 import javax.swing.*;
00006 import javax.swing.text.*;
00007 import java.util.regex.*;
00008 import is.*;
00009 import Sct.Serializable;
00010 import Sct.IS.*;
00011 import GuiComponents.Console.ExternalProcess;
00012 import GuiComponents.Inspector.InspectorPanel;
00013 import Sct_CalibrationController.TestData;
00014 import GuiComponents.System.*;
00015 import SummaryReader.*;
00016 
00017 /*
00018  * ISInterface.java
00019  *
00020  */
00021 
00026 public class ISInterface implements TestDataInfo,InfoListener {
00027     
00028     gui guiControl;
00029  
00030     ISRequestBuffer isRequestBuffer;
00031     ISCounter isCounter;
00032 
00033     Hashtable serverHash;  // hash to keep track of which servers we are subscribed to...
00034     String theObjectName;
00035 //    String isFilterHeader;
00036 //    String isFilterRunInfo;
00037     TestData testData;       // the currently selected test
00038     String serverName;       // the currently selected server name
00039     int noScans;             // the number of scans in the currently selected test
00040 
00041     int listFilterIndex;
00042 
00043     String eventServerRegex;      // regex for event server objects
00044     String fitServerRegex;        //regex for fit server objects
00045     String controlObjectRegex;          //regex for control data
00046     String rControlObjectRegex;
00047     String dbControlObjectRegex;   // regex for database control data
00048     String testServerRegex;          //regex for test server objects
00049     Pattern objectPattern, rObjectPattern;
00050     String resultObjectRegex;     // regex for test Summary objects
00051     String ivscanRegex;  // regex for ivscan objects
00052     String ivscanControlRegex;
00053 
00054     String eventServer;
00055     String fitServer;
00056     String testServer;
00057     String controlServer;
00058     String SCTDBServer;
00059     String retrievedArchiveServer;
00060 
00061     String testLocation;     // the test location for SCTDB downloads
00062 
00063     int serverIndex=0;        // the currently selected server
00064 
00065     boolean infoListenersAreActive=true;
00066 
00067 //    Vector infoListenerQueue = new Vector();
00068 
00069     java.util.Map moduleCount = new HashMap();
00070 
00071     Pattern defectPattern = Pattern.compile("(\\d+)-(\\d+)\\s*:\\s*(\\w+)");
00072     
00073     static final java.util.regex.Pattern SctRodDaqRefPattern = java.util.regex.Pattern.compile(".*SctRodDaqRefData\\.(.*)\\.(.*)\\.(\\d+)\\.(\\d+)");
00074     static final int LOCATION=2;
00075     static final int TESTNAME=1;
00076     static final int RUNNO=3;
00077     static final int SCANNO=4;
00078 
00079     guiUtilities.Cache cache=null;
00080     Map dcsCache=null;
00081     Map dcsMap = new HashMap();
00082     
00083     java.text.DecimalFormat nf = new java.text.DecimalFormat("#.###");
00084     java.text.DecimalFormat nfe = new java.text.DecimalFormat("#.##E0");
00085 
00086     Preferences.PreferencesInterface prefs;
00087 
00088     PlotOptionsFrame plotOptionsFrame=null;
00089 
00090     public ISInterface(gui parent) {
00091         guiControl=parent;
00092 
00093         prefs = Preferences.PreferencesInterface.getInstance();
00094 
00095         isRequestBuffer = new ISRequestBuffer(guiControl);
00096 
00097         is = GuiComponents.System.ISInterface.getInstance();
00098         isCounter = new ISCounter();
00099         serverHash = new Hashtable();
00100         noScans=0;
00101         listFilterIndex=-1;
00102 
00103         eventServerRegex = ".*RawScanResult.*[0-9]+\\.[0-9]+(\\.[0-9]{14})?";
00104         fitServerRegex = ".*FitScanResult.*[0-9]+\\.[0-9]+(\\.[0-9]{14})?";
00105         testServerRegex = ".*Result.*[0-9]+\\.[0-9]+(\\.[0-9]{14})?";
00106         controlObjectRegex = "TestData\\.[0-9]+\\.[0-9]+(.*Test)?";
00107         rControlObjectRegex = "TestData\\.[0-9]+\\.[0-9]+.*Test";
00108         dbControlObjectRegex = ".*SctRodDaqRefData.*";
00109         resultObjectRegex = ".*(Summary).*";
00110         ivscanRegex = ".*IVScanData.*";
00111         ivscanControlRegex = ".*ControlIVScanData.*";
00112 
00113         objectPattern = Pattern.compile(".*TestData\\.[0-9]+\\.[0-9]+");
00114         rObjectPattern = Pattern.compile(".*\\.[0-9]+\\.[0-9]+.*Test");
00115 
00116         eventServer = SctNames.getEventISServer();
00117         fitServer = SctNames.getFitISServer();
00118         testServer = SctNames.getTestISServer();
00119         controlServer = SctNames.getControlISServer();
00120         SCTDBServer = "SCTDBData";
00121         retrievedArchiveServer = "RetrievedData";
00122 
00123         testLocation="Any";
00124 
00125         if(cache==null) setCacheSize(700);  // make it at least barrel 6 worth of modules
00126         if(dcsCache==null) dcsCache = new HashMap(672*9); // 680 modules worth
00127 
00128 
00129     }
00130     protected void subscribe() {
00131         subscribe(-1);
00132         }
00133 
00134     public void setISCounter(String regex) {
00135         isCounter.refresh(regex);
00136         }
00137         
00138     protected void subscribe(int testType) {
00139         listFilterIndex=testType;
00140         String[] objects;
00141         Vector ISTests = new Vector();
00142  
00143         try {
00144 
00145         switch(guiControl.displayStatus.getStatus()) {
00146            case DisplayStatus.SCTDB_RODDAQ_DATA:
00147               objects = is.getISObjects(SCTDBServer,dbControlObjectRegex);
00148               for(int i=0;i<objects.length;i++) ISTests.addElement(objects[i]);
00149               break;
00150            case DisplayStatus.IV_DATA:
00151               objects = is.getISObjects(retrievedArchiveServer,ivscanControlRegex);
00152               for(int i=0;i<objects.length;i++) ISTests.addElement(objects[i]);
00153               break;
00154             default:
00155               objects = is.getISObjects(retrievedArchiveServer,rControlObjectRegex);
00156               for(int i=0;i<objects.length;i++) ISTests.addElement(objects[i]);
00157               objects = is.getISObjects(controlServer,controlObjectRegex);
00158               for(int i=0;i<objects.length;i++) ISTests.addElement(objects[i]);
00159               }
00160 
00161          if(guiControl.displayStatus.getStatus()!=DisplayStatus.IV_DATA) {
00162            for(int j=ISTests.size()-1;j>=0;j--) {
00163               String controlObject = (String)ISTests.elementAt(j);
00164               Matcher matcher = objectPattern.matcher(controlObject);
00165               Matcher matcher2 = rObjectPattern.matcher(controlObject);
00166               if(!matcher.matches() && !matcher2.matches() && !controlObject.matches(dbControlObjectRegex)) {
00167                  ISTests.removeElementAt(j);
00168                  continue;
00169                  }
00170               if(listFilterIndex==-1) continue;
00171               else {
00172                  TestData testData = new TestData(); 
00173                  is.getRepository().getValue(controlObject, testData); 
00174                  String thisTestName = (listFilterIndex==TEST_3PTGAIN) ? testNames[TEST_NPTGAIN] : testNames[listFilterIndex];
00175                  if(testData.testName.indexOf(thisTestName)==-1) ISTests.removeElementAt(j);
00176                  }
00177               }  
00178              }
00179         guiControl.tablesDisplayPane.setTestTable(ISTests);
00180 
00181          switch(guiControl.displayStatus.getStatus()) {
00182           case DisplayStatus.IS_MONITOR:
00183 
00184 
00185             if(!serverHash.containsKey(eventServer)) {
00186               is.subscribe(eventServer, eventServerRegex, true, this);
00187               serverHash.put(eventServer, eventServerRegex);
00188               }
00189             if(!serverHash.containsKey(fitServer)) {
00190               is.subscribe(fitServer, fitServerRegex, true, this);
00191               serverHash.put(fitServer, fitServerRegex);
00192               }
00193             if(!serverHash.containsKey(testServer)) {
00194               is.subscribe(testServer, testServerRegex, true, this);
00195               serverHash.put(testServer, testServerRegex);
00196               }
00197             if(!serverHash.containsKey(controlServer)) {
00198              is.subscribe(controlServer, controlObjectRegex, true, this);
00199              serverHash.put(controlServer, controlObjectRegex);
00200              }
00201             if(!serverHash.containsKey(retrievedArchiveServer)) {
00202              List subscriptions = new ArrayList();
00203              subscriptions.add(rControlObjectRegex);
00204              subscriptions.add(fitServerRegex);
00205              subscriptions.add(eventServerRegex);
00206              subscriptions.add(testServerRegex);  
00207              for (ListIterator i = subscriptions.listIterator(); i.hasNext(); ) {
00208                 is.subscribe(retrievedArchiveServer, (String)i.next(), true, this);
00209                 }           
00210              serverHash.put(retrievedArchiveServer, subscriptions);
00211              }
00212 
00213             break;
00214 
00215           case DisplayStatus.TEST_DATA:
00216              if(!serverHash.containsKey(testServer)) {
00217                is.subscribe(testServer, resultObjectRegex, true, this);
00218                serverHash.put(testServer, resultObjectRegex);
00219              }
00220              if(!serverHash.containsKey(controlServer)) {
00221                is.subscribe(controlServer, controlObjectRegex, true, this);
00222                serverHash.put(controlServer, controlObjectRegex);
00223                }
00224             if(!serverHash.containsKey(retrievedArchiveServer)) {
00225              List subscriptions = new ArrayList();
00226              subscriptions.add(resultObjectRegex);
00227              subscriptions.add(rControlObjectRegex);
00228              for (ListIterator i = subscriptions.listIterator(); i.hasNext(); ) {
00229                 is.subscribe(retrievedArchiveServer, (String)i.next(), true, this);
00230                 }
00231              serverHash.put(retrievedArchiveServer, subscriptions);
00232              }
00233 
00234 
00235 
00236              break;
00237           case DisplayStatus.SCTDB_DATA:
00238              if(!serverHash.containsKey(controlServer)) {
00239                is.subscribe(controlServer, controlObjectRegex, true, this);
00240                serverHash.put(controlServer, controlObjectRegex);
00241                }
00242              if(!serverHash.containsKey(SCTDBServer)) {
00243                is.subscribe(SCTDBServer, ".*", true, this);
00244                serverHash.put(SCTDBServer, ".*");
00245                }
00246               break;
00247           case DisplayStatus.SCTDB_RODDAQ_DATA:
00248              if(!serverHash.containsKey(SCTDBServer)) {
00249                is.subscribe(SCTDBServer, ".*", true, this);
00250                serverHash.put(SCTDBServer, ".*");
00251                }
00252               break;
00253           case DisplayStatus.IV_DATA:
00254              if(!serverHash.containsKey(retrievedArchiveServer)) {
00255                List subscriptions = new ArrayList();
00256                subscriptions.add(ivscanRegex);
00257                is.subscribe(retrievedArchiveServer, ivscanRegex, true, this);
00258                serverHash.put(retrievedArchiveServer, subscriptions);
00259                }
00260               break;
00261           case DisplayStatus.DCS_DATA:
00262                 isCounter.clearDCSObjectList();       // clear the buffer in ISCounter
00263                 List subscriptions = new ArrayList();
00264                 int pIndex = guiControl.selectorPane.getDisplayParameterIndex();
00265                 switch(pIndex) {
00266                   case 8: // T0 and T1
00267                       subscriptions.add(".*"+dcsParams[2]+".*");
00268                       subscriptions.add(".*"+dcsParams[3]+".*");
00269                       refillDCSCache(2);
00270                       refillDCSCache(3);
00271                       break;
00272                   case 9:
00273                       for(int k=0;k<8;k++) {
00274                           if(k==2 || k==3) continue;
00275                           subscriptions.add(".*"+dcsParams[k]+".*");
00276                           refillDCSCache(k);
00277                           }
00278                       break;
00279                   case 10:
00280                   // special case IPIN
00281                       subscriptions.add(".*"+dcsParams[8]+".*");
00282                       refillDCSCache(8);
00283                       break;
00284                   default:
00285                       subscriptions.add(".*"+dcsParams[pIndex]+".*");
00286                       refillDCSCache(pIndex);
00287                   }
00288                 for (ListIterator i = subscriptions.listIterator(); i.hasNext(); ) {
00289                     String thisRegex = (String)i.next();
00290 //                  System.out.println("(Re)subscribing to "+thisRegex);
00291                     is.subscribe(prefs.getPreference(prefs.DCS_SERVER_NAME), thisRegex, true, this);
00292                     }
00293                 serverHash.put(prefs.getPreference(prefs.DCS_SERVER_NAME), subscriptions);
00294 
00295                 break;
00296            default:
00297            }
00298 
00299 
00300 
00301         } catch (RuntimeException e) {
00302             System.err.println("SctGUI::ISInterface: Exception in IS subscription: " + e.toString());
00303         }
00304 //        guiControl.displayPane.setDisplayColors();
00305 //        guiControl.displayPane.refreshDisplay();   
00306     }
00307 
00308     protected void unsubscribe() {
00309             if(serverHash.containsKey(retrievedArchiveServer)) {
00310                 List subscriptions = (List)serverHash.get(retrievedArchiveServer);
00311                 for (ListIterator i = subscriptions.listIterator(); i.hasNext(); ) {
00312                   is.unsubscribe(retrievedArchiveServer, (String)i.next());
00313 //                 System.out.println(is.unsubscribe(retrievedArchiveServer, (String)i.next()));
00314                   }
00315                 serverHash.remove(retrievedArchiveServer);
00316                 }
00317             if(serverHash.containsKey(prefs.getPreference(prefs.DCS_SERVER_NAME))) {
00318                 List subscriptions = (List)serverHash.get(prefs.getPreference(prefs.DCS_SERVER_NAME));
00319                 for (ListIterator i = subscriptions.listIterator(); i.hasNext(); ) {
00320                   is.unsubscribe(prefs.getPreference(prefs.DCS_SERVER_NAME), (String)i.next());
00321 //                 System.out.println(is.unsubscribe(retrievedArchiveServer, (String)i.next()));
00322                   }
00323                 serverHash.remove(prefs.getPreference(prefs.DCS_SERVER_NAME));
00324                 }
00325 
00326             for(Enumeration e = serverHash.keys(); e.hasMoreElements();) {
00327                String server = (String)e.nextElement();
00328                String pattern = (String)serverHash.get(server);
00329                is.unsubscribe(server, pattern);
00330 //               System.out.println(is.unsubscribe(server, pattern));
00331                }
00332             serverHash = new Hashtable();
00333     }
00334     
00335     public String[] getDBISObjects(int testIndex) {
00336          return is.getISObjects(SCTDBServer,".*SctRodDaqRefData."+testNames[testIndex]+".*");
00337          }
00338 
00339     public javax.swing.tree.DefaultMutableTreeNode getISTree() {
00340 
00341         String[] servers = is.getISServers();        
00342         
00343         //Setup tree
00344         
00345         javax.swing.tree.DefaultMutableTreeNode top = new javax.swing.tree.DefaultMutableTreeNode("IS Servers");
00346         javax.swing.tree.DefaultMutableTreeNode server;
00347         javax.swing.tree.DefaultMutableTreeNode object;
00348         for (int i=0; i<servers.length; i++) {
00349             server = new javax.swing.tree.DefaultMutableTreeNode(servers[i]);
00350             String[] objects = is.getISObjects(servers[i],".*");
00351             for (int j=0; j<objects.length; j++) {
00352                 object = new javax.swing.tree.DefaultMutableTreeNode(objects[j]);
00353                 server.add(object);
00354             }
00355             top.add(server);
00356         }
00357         return top;
00358 //        trISServers.setModel(new DefaultTreeModel(top));
00359     }
00360     
00364     abstract class StringRunnable implements Runnable {
00365         protected String name;
00366         StringRunnable(String name) {
00367             this.name = name;
00368         }       
00369     }
00370 
00371     public void infoCreated(InfoEvent e) {
00372 //       System.out.println("created "+e.getName());
00373        isCounter.addObject(e.getName());
00374        javax.swing.SwingUtilities.invokeLater(new StringRunnable(e.getName()) {
00375           public void run() {
00376 //                 System.out.println("queueing object "+name);
00377                    isRequestBuffer.queueObject(name,true);
00378              }
00379         });
00380     }
00381 
00382 
00383     public void infoDeleted(InfoEvent e) {
00384 //       System.out.println("deleted "+e.getName());
00385        javax.swing.SwingUtilities.invokeLater(new StringRunnable(e.getName()) {
00386           public void run() {
00387              if(!infoListenersAreActive) return;
00388              if(name.startsWith("ControlData")) guiControl.tablesDisplayPane.removeTest(name);
00389 //           System.out.println("ISInteferca infoDeleted, name "+name);
00390              guiControl.displayPane.setDisplayColors();
00391              guiControl.displayPane.refreshDisplay();  // just refresh the display
00392           }
00393         });
00394     }
00395 
00396     public void infoUpdated(InfoEvent e) {
00397 //           System.out.println("updated "+e.getName());
00398         isCounter.updateObject(e.getName());
00399         javax.swing.SwingUtilities.invokeLater(new StringRunnable(e.getName()) {
00400           public void run() {  
00401 //          System.out.println("queueing object "+name);
00402             isRequestBuffer.queueObject(name,false);
00403             }
00404         });
00405     }
00406 
00407 //***************************************************************************
00408    public void removeTests(Vector testObjectNames, int minRow, int maxRow) {
00409 // remove tests from IS
00410 // firstRowNo is the first row number in the test JTable
00411 // lastTestNo is the last
00412 
00413       infoListenersAreActive=false;
00414 
00415       for(int i=maxRow;i>=minRow;i--) {
00416          String testObjectName = (String)testObjectNames.elementAt(i);
00417          TestData thisTestData = new TestData(); 
00418          is.getRepository().getValue(testObjectName, thisTestData); 
00419 // first extract the run number, and scan numbers
00420          int runNo = thisTestData.runNumber;
00421          int startScanNumber = thisTestData.startScanNumber;
00422 // form a regular espression
00423          StringBuffer regex = new StringBuffer(".*(");
00424          for(int k=thisTestData.startScanNumber;k<thisTestData.startScanNumber+thisTestData.nScans;k++) {
00425            if(k>thisTestData.startScanNumber) regex.append("|");
00426            regex.append("\\.");
00427            regex.append(Integer.toString(runNo));
00428            regex.append("\\.");
00429            regex.append(Integer.toString(k));
00430            regex.append("\\.");
00431          }
00432          regex.append(").*");
00433       
00434          String[] deletionObjects;
00435 // check if all data objects are in RetrievedData server or not...
00436          if(testObjectName.matches("RetrievedData.*")) {
00437            deletionObjects = is.getISObjects("RetrievedData",regex.toString());
00438            for(int j=0;j<deletionObjects.length;j++) System.out.println(is.remove(deletionObjects[j]));
00439            }
00440          else if(testObjectName.matches("SCTDBData.*")) {
00441            deletionObjects = is.getISObjects("SCTDBData",regex.toString());
00442            for(int j=0;j<deletionObjects.length;j++) System.out.println(is.remove(deletionObjects[j]));
00443            }
00444          else {
00445            deletionObjects = is.getISObjects(SctNames.getEventISServer(),regex.toString());
00446            for(int j=0;j<deletionObjects.length;j++) System.out.println(is.remove(deletionObjects[j]));
00447            deletionObjects = is.getISObjects(SctNames.getFitISServer(),regex.toString());
00448            for(int j=0;j<deletionObjects.length;j++) System.out.println(is.remove(deletionObjects[j]));
00449            deletionObjects = is.getISObjects(SctNames.getTestISServer(),regex.toString());
00450            for(int j=0;j<deletionObjects.length;j++) System.out.println(is.remove(deletionObjects[j]));
00451            }
00452 
00453     
00454 // finally, the control object itself
00455 // the object names in the control server do not have a final '.' after the first scan no 
00456          System.out.println(is.remove(testObjectName)); 
00457          guiControl.tablesDisplayPane.removeTest(testObjectName);
00458         }
00459 
00460        infoListenersAreActive=true;
00461         
00462      }
00463 //***************************************************8
00464         public void removeObjects(Vector objectNames) {
00465            for(int i=0;i<objectNames.size();i++) System.out.println(is.remove((String)objectNames.elementAt(i)));
00466            }
00467 //***************************************************8
00468      public int getListFilterIndex() {
00469            return listFilterIndex;
00470            }
00471         
00472 //****************************************************************************
00473 //     public void setTestFilter(String testObjectName) {
00474 //          if(testObjectName==null) testSelection=null;
00475 //          else testSelection = new TestSelection(testObjectName,testLocation);
00476 //          setIsFilterHeader();
00477 //          setIsFilterRunInfo();
00478 //          if(guiControl.displayStatus.getStatus()==DisplayStatus.IS_MONITOR) resetModuleCount();
00479 //          } 
00480 //*******************************************************
00481     private String getIsFilterHeader() {
00482          String isFilterHeader = "SctData::Result";
00483          int serverIndex = guiControl.selectorPane.getDisplayParameterIndex();
00484          switch(serverIndex) {
00485             case 0:
00486                 isFilterHeader = "SctData::RawScanResult";
00487                break;
00488             case 1:
00489                 isFilterHeader = "SctData::FitScanResult";
00490                break;
00491             case 2:
00492             default:
00493                TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00494                if(testSelection!=null) {
00495                   String testName;
00496                   if((testName=testSelection.getTestName())!=null) isFilterHeader="SctData::"+testName+"Result";
00497                   }
00498                break;
00499             } 
00500          return isFilterHeader;
00501      }
00502     private String getIsFilterRunInfo() {
00503          String isFilterRunInfo="none";
00504          TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00505          if(testSelection==null || testSelection.getTestData()==null) return isFilterRunInfo;
00506          StringBuffer regex = new StringBuffer("\\."+Integer.toString(testSelection.getRunNo())+"\\.(");
00507          int startScanNo = testSelection.getStartScanNumber();
00508          for(int k=startScanNo;k<startScanNo+testSelection.getNoScans();k++) {
00509            if(k>startScanNo) regex.append("|");
00510            regex.append(Integer.toString(k));
00511            regex.append("\\.");
00512          }
00513          regex.append(").*"); 
00514          return regex.toString();
00515          }
00516     private String getServerName() {
00517          int serverIndex = guiControl.selectorPane.getDisplayParameterIndex();
00518          String serverName=SctNames.getEventISServer();
00519          switch(serverIndex) {
00520             case 0:
00521                serverName=SctNames.getEventISServer();
00522                break;
00523             case 1:
00524                serverName=SctNames.getFitISServer();
00525                break;
00526             case 2:
00527             default:
00528                serverName=SctNames.getTestISServer();
00529                break;
00530             }
00531           return serverName;
00532           }
00533 
00534 //**************************************************************************
00535       public String[] getISObjects(String serialNo) {
00536          return is.getISObjects(getServerName(),getIsFilterHeader()+getIsFilterRunInfo()+serialNo);
00537          }
00538 //**********************************************************************
00539     public Hashtable getModuleISCounts() {
00540        String serverName = getServerName();
00541        Pattern snPattern = Pattern.compile(serverName+"\\."+getIsFilterHeader()+getIsFilterRunInfo()+"(\\d{14}).*");
00542        Hashtable thisHash = new Hashtable();
00543        String[] objects = is.getISObjects(serverName,getIsFilterHeader()+getIsFilterRunInfo()+".*");
00544        for(int i=0;i<objects.length;i++) {
00545            Matcher matcher = snPattern.matcher(objects[i]);
00546            if(matcher.matches()) {
00547                String sn = objects[i].substring(matcher.start(2),matcher.end(2));
00548                if(thisHash.containsKey(sn)) {
00549                    int count = ((Integer)thisHash.get(sn)).intValue();
00550                    count++;
00551                    thisHash.put(sn,new Integer(count));
00552                    }
00553                else thisHash.put(sn,new Integer(1));
00554                }
00555             }
00556         return thisHash;
00557         }
00558         //*****************************************************
00559      public Vector getDataObjectList(String sn, int type) {
00560         // return a list of raw data or fitted data objects for module thisCell
00561         // type=0 raw data, =1 fitted data
00562 
00563        java.util.SortedMap m = new java.util.TreeMap();
00564        TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00565        if(testSelection==null || testSelection.getRunScanRegex()==null) {
00566           return null;
00567           }
00568 
00569        java.util.List isList = (java.util.List)isCounter.getModuleList(type,testSelection.getRunScanRegex(),sn,testSelection.isRetrievedData());
00570        if(isList==null) {  // if not present, probably the iscounter has not yet been invoked
00571               setISCounter(testSelection.getRunScanRegex());
00572               isList = (java.util.List)isCounter.getModuleList(type,testSelection.getRunScanRegex(),sn,testSelection.isRetrievedData());
00573               }
00574        if(isList==null) {
00575           return null; // ok there really IS no data
00576           }
00577 
00578        for (ListIterator i = isList.listIterator(); i.hasNext(); ) {
00579             String object = (String)i.next();
00580             String[] objectParts = object.split("\\.");
00581             Integer runNo = Integer.valueOf(objectParts[2]);
00582             Integer scanNo = Integer.valueOf(objectParts[3]);
00583             String fname = objectParts[1];
00584             m.put(new Integer(runNo.intValue()*10000 + scanNo.intValue()),object);
00585             }
00586          return new Vector(m.values());
00587         }
00588 
00589 
00590 
00591 //*********************************************************************
00592 
00593    public void launchExternalViewer(String name) {
00594         try {
00595             ExternalProcess p = new ExternalProcess("DataDisplayer " + name);
00596         } catch (Exception ioe) {
00597             System.out.println(ioe.getMessage());
00598             ioe.printStackTrace();
00599         }
00600 
00601     }
00602 
00603    public void launchExternalViewerWithOptions(String name) {
00604             if(plotOptionsFrame==null) plotOptionsFrame = new PlotOptionsFrame();
00605             plotOptionsFrame.showFrame(name);
00606     }
00607     
00608 
00609     public void viewISData(String name) {
00610         try {
00611             Serializable ob = ObjectManagerIS.getInstance().readObject(name);
00612             InspectorPanel p = new InspectorPanel(name, ob);
00613             //JFrame frame = new JFrame("InspectorPanel");
00614             //frame.getContentPane().add(p, java.awt.BorderLayout.CENTER);
00615             //frame.pack();
00616             //frame.show();
00617 
00618             JFrame frame2 = new JFrame("TreeTable");                    
00619             frame2.getContentPane().add(new JScrollPane(p.treeTable));
00620             frame2.pack();
00621             frame2.show();
00622 
00623         } catch (java.io.IOException ioe) {
00624             System.err.println("Error reading object from IS: " + ioe + "  " +ioe.getMessage() +"\n");
00625         }
00626     }
00627 
00628    public void downloadTests(int index) {
00629          TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00630          if(testSelection==null || testSelection.getTestIndex()==-1) {
00631               javax.swing.JOptionPane.showMessageDialog(null,"You must select a test in ordre to download sctdaq reference data.");
00632               return;
00633               }
00634          boolean refresh=false;
00635          if(index==-1) {
00636            index=testSelection.getTestIndex();
00637            refresh=true;
00638            }
00639          if(index==-1) return;
00640          if(!testIsSCTDAQ[index]) {
00641             javax.swing.JOptionPane.showMessageDialog(null,"The selected test is not SCTDAQ compatible, so reference data cannot be downloaded.");
00642             return;
00643             }
00644          SCTDBTestDownloader d = new SCTDBTestDownloader(new Vector(guiControl.config.getSortedVector(guiControl.displayPane.getSCTView())),index,testLocation,true,refresh);
00645          if(d.downloadsRequired() && d.isOkToStart()) d.start();
00646          }
00647    public void setLocation(String location) {
00648         testLocation=location;
00649         TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00650         if(testSelection!=null) testSelection.setSCTDBLocation(testLocation);
00651         }
00652    public String getLocation() {
00653         return testLocation;
00654         }
00655    public void uploadAssemblyInfo() {
00656    
00657              if(ConfigurationInterface.getInstance().getTotalNumberOfModules()<1) return;
00658    
00659              Preferences.PreferencesInterface prefs = Preferences.PreferencesInterface.getInstance();
00660              String uploadDir = prefs.getPreference(Preferences.PreferencesInterface.UPLOAD_DIR);
00661              String institute = prefs.getPreference(Preferences.PreferencesInterface.INSTITUTE);
00662              String password = prefs.getPreference(Preferences.PreferencesInterface.PASSWORD);
00663              String undefinedstring = Preferences.PreferencesInterface.unDefinedString;
00664              SCTDBAssemblyChecker a = new SCTDBAssemblyChecker(guiControl,ConfigurationInterface.getInstance().getSerialNumberMap(), uploadDir, institute, password, undefinedstring);
00665              if(a.isOkToStart()) a.start();
00666              }
00667 
00668 
00669    public Double getSCTDBData(String resultObject, int testIndex) {
00670              if(testIndex==-1) return null;
00671              int parameterIndex = guiControl.selectorPane.getDisplayParameterIndex();
00672              int option = guiControl.selectorPane.getMouseClickIndex();
00673              if(parameterIndex<0) return null;
00674              if(!isSCTDAQCompatible[testIndex][parameterIndex]) return null;
00675              SummaryReader.Test testResult = getSCTDBTest(resultObject);
00676              if(testResult==null) return null;
00677              Double theData=readTestData(testResult,-1,parameterIndex,option);
00678               return theData;
00679               }
00680 
00681 
00682    public Test getSCTDBTest(String resultObject) {
00683 
00684         SummaryReader.Test testObject;
00685 
00686         testObject = (SummaryReader.Test)cache.get(resultObject);
00687         if(testObject!=null) return testObject;
00688         
00689 //      System.out.println(resultObject+" not in cache!");
00690 
00691         try {
00692         if(!Sct.IS.SctNames.getISRepository().contains(resultObject)) return null;
00693         SCTDB_Data result = new SCTDB_Data(); 
00694         Sct.IS.SctNames.getISRepository().getValue(resultObject, result);
00695 
00696         testObject = new Test();
00697 
00698         int blockSize = result.data_m0.length;
00699         DataBlock dataBlock = new DataBlock("Chip Data",result.data_m0.length,result.testIndex);
00700         for(int i=0;i<blockSize;i++) {
00701           dataBlock.add(0,i,result.data_m0[i]);
00702           dataBlock.add(1,i,result.data_s1[i]);
00703           dataBlock.add(2,i,result.data_s2[i]);
00704           dataBlock.add(3,i,result.data_s3[i]);
00705           dataBlock.add(4,i,result.data_s4[i]);
00706           dataBlock.add(5,i,result.data_e5[i]);
00707           dataBlock.add(6,i,result.data_m8[i]);
00708           dataBlock.add(7,i,result.data_s9[i]);
00709           dataBlock.add(8,i,result.data_s10[i]);
00710           dataBlock.add(9,i,result.data_s11[i]);
00711           dataBlock.add(10,i,result.data_s12[i]);
00712           dataBlock.add(11,i,result.data_e13[i]);
00713           }
00714          testObject.add(dataBlock);
00715          // DCS
00716          DCSInfo dcsInfo = new DCSInfo();
00717          for(int i=0;i<8;i++) if(result.dcsinfo[i]!=SCTDBTestDownloader.NODATA) dcsInfo.put(i,result.dcsinfo[i]);
00718          testObject.add(dcsInfo);
00719          // Defects
00720          for(int i=0;i<result.noDefectChannels;i++) {
00721            String defectLine = result.defectList[i];
00722            Matcher matcher = defectPattern.matcher(defectLine);
00723            if(matcher.matches()) {
00724               DefectInfo defectInfo = new DefectInfo();
00725               defectInfo.setFirstChannel(defectLine.substring(matcher.start(1),matcher.end(1)));
00726               defectInfo.setLastChannel(defectLine.substring(matcher.start(2),matcher.end(2)));
00727               defectInfo.setName(defectLine.substring(matcher.start(3),matcher.end(3)));
00728               testObject.add(defectInfo);
00729               }
00730            else System.err.println("Unrecognised defect descriptor: "+defectLine);
00731            }
00732          // DAQ info
00733          DAQInfo daqInfo = new DAQInfo();
00734          for(int i=0;i<5;i++) daqInfo.put(i,result.daqInfo[i]);
00735          testObject.add(daqInfo);
00736          // Test Status
00737          TestInfo testInfo = new TestInfo();
00738          testInfo.setStatus(new Double(result.status));
00739          testObject.add(testInfo);
00740          cache.put(resultObject,testObject);
00741          return testObject;
00742          }catch(Exception e){System.err.println("SctGUI: Failed to extract "+resultObject+" : "+e.toString());}
00743          return null;
00744          }
00745 
00746      public Double getTestData(String resultObjectHeader, String serialNo,int testIndex, SummaryReader.DCSInfo dcsInfo) {
00747                   if(testIndex==-1) return null;
00748                   int parameterIndex = guiControl.selectorPane.getDisplayParameterIndex();
00749                   int option = guiControl.selectorPane.getMouseClickIndex();
00750                   if(parameterIndex<0) return null;
00751                   SummaryReader.Test testResult = getTest(resultObjectHeader,serialNo,dcsInfo);
00752                   if(testResult==null) return null;
00753                   Double theData=readTestData(testResult,testIndex,parameterIndex,option);
00754                   return theData;
00755                   }
00756 
00757      public Double readTestData(SummaryReader.Test testResult, int testIndex, int parameterIndex, int option) {
00758                  Double theData=null;
00759                   switch(guiControl.displayStatus.getStatus()) {
00760                      case DisplayStatus.IV_DATA:
00761                          switch(parameterIndex) {
00762                             case 0: // test status
00763                               theData = testResult.getTestInfo().getTestStatusData();
00764                               break;
00765                              case 1: // Current
00766                               theData = testResult.getIVData().getCurrent(option);
00767                               break;
00768                              case 2:
00769                               SummaryReader.DCSInfo dcsInfo = testResult.getDCSInfo();
00770                               if(dcsInfo!=null) theData = dcsInfo.get(option);
00771                               break;
00772                              }
00773                             break;
00774                       default:
00775                          switch(parameterIndex) {
00776                            case 0: // test status
00777                              theData = testResult.getTestInfo().getTestStatusData();
00778                              break;
00779                            case 1: // defect count
00780                              theData = testResult.noDefects();
00781                              break;
00782                            case 2: // bad channel count
00783                              theData = testResult.getNoBadChannels();
00784                              break;
00785                            case 3: // DCS conditions
00786                              SummaryReader.DCSInfo dcsInfo = testResult.getDCSInfo();
00787                              if(dcsInfo!=null) theData = dcsInfo.get(option);
00788                              break;
00789                            default:
00790                              theData = (testIndex==TEST_RXTHRESHOLD || testIndex==TEST_RXTHRESHOLDBASEDONCONFIGREGISTER || testIndex==TEST_RXDELAY || testIndex==TEST_TXCURRENT) ? testResult.getLinkInfo().get(option,parameterIndex-4) : testResult.getLastDataBlock().get(option,parameterIndex-4);
00791                              }
00792                        }
00793                    return theData;
00794                    }
00795 //
00796 // get test data as a single table line
00797 //
00798      public Vector getTestDataLine(String resultObjectHeader, String serialNo,int testIndex, SummaryReader.DCSInfo dcsInfo) {
00799                   Vector dataLine = new Vector();
00800                   dataLine.addElement(serialNo);
00801 
00802                   if(testIndex==-1) return null;
00803                   int parameterIndex = guiControl.selectorPane.getDisplayParameterIndex();
00804                   if(parameterIndex<0) return null;
00805                   SummaryReader.Test testResult = getTest(resultObjectHeader,serialNo,dcsInfo);
00806                   if(testResult==null) return null;
00807                   
00808                   int option = guiControl.selectorPane.getMouseClickIndex();
00809 
00810                   Double theData=null;
00811                   switch(guiControl.displayStatus.getStatus()) {
00812                      case DisplayStatus.IV_DATA:
00813                          switch(parameterIndex) {
00814                             case 0: // test status
00815                               theData = testResult.getTestInfo().getTestStatusData();
00816                               break;
00817                              case 1: // Current
00818                               theData = testResult.getIVData().getCurrent(option);
00819                               break;
00820                              case 2:
00821                               dcsInfo = testResult.getDCSInfo();
00822                               if(dcsInfo!=null) theData = dcsInfo.get(option);
00823                               break;
00824                              }
00825                             if(theData==null) dataLine.addElement(new Double(-1.0));
00826                             else dataLine.addElement(theData);
00827                             break;
00828                       default:
00829                          switch(parameterIndex) {
00830                            case 0: // test status
00831                              theData = testResult.getTestInfo().getTestStatusData();
00832                             if(theData==null) dataLine.addElement(new Double(-1.0));
00833                             else dataLine.addElement(theData);
00834                              break;
00835                            case 1: // defect count
00836                              theData = testResult.noDefects();
00837                             if(theData==null) dataLine.addElement(new Double(-1.0));
00838                             else dataLine.addElement(theData);
00839                              break;
00840                            case 2: // bad channel count
00841                              theData = testResult.getNoBadChannels();
00842                             if(theData==null) dataLine.addElement(new Double(-1.0));
00843                             else dataLine.addElement(theData);
00844                              break;
00845                            case 3: // DCS conditions
00846                              dcsInfo = testResult.getDCSInfo();
00847                              if(dcsInfo!=null) theData = dcsInfo.get(option);
00848                             if(theData==null) dataLine.addElement(new Double(-1.0));
00849                             else dataLine.addElement(theData);
00850                              break;
00851                            default:
00852                              if(testIndex==TEST_RXTHRESHOLD || testIndex==TEST_RXDELAY || testIndex==TEST_RXTHRESHOLDBASEDONCONFIGREGISTER || testIndex==TEST_TXCURRENT ) {
00853                                  LinkInfo linkInfo = testResult.getLinkInfo();
00854                                  for(int d=0;d<linkInfo.getSize();d++) {
00855                                    theData = linkInfo.get(option,d);
00856                                    if(theData==null) dataLine.addElement(new Double(-1.0));
00857                                    else dataLine.addElement(theData);
00858                                    }
00859                                }
00860 
00861                              else {
00862                                for(int j=0;j<12;j++) {
00863                                  theData = testResult.getLastDataBlock().get(j+4,parameterIndex-4);
00864                                  // if occupancy data, want results as strings
00865                                  if(parameterIndex==5 && testIndex==TEST_NOISE) {
00866                                      if(theData==null) dataLine.addElement(new Double(-1.0));
00867                                      else dataLine.addElement(nfe.format(theData.doubleValue()));
00868                                      }
00869                                  else {
00870                                    if(theData==null) dataLine.addElement(new Double(-1.0));
00871                                    else dataLine.addElement(theData);
00872                                    }
00873                                  }
00874                                 }
00875 
00876                              }
00877                        }
00878                    return dataLine;
00879                    }
00880 
00881 
00882      public SummaryReader.IVData getIVData(String resultObjectHeader,String serialNo) {
00883 
00884                   SummaryReader.Test testResult = getTest(resultObjectHeader,serialNo,null);
00885                   if(testResult==null) return null;
00886                   else return testResult.getIVData();
00887 
00888                    }
00889 
00890 
00891     public Test getTest(String resultObjectHeader, String serialNo,SummaryReader.DCSInfo dcsInfo) {
00892              String resultObject = resultObjectHeader+serialNo;
00893              SummaryReader.Test testObject = (SummaryReader.Test)cache.get(resultObject);
00894              if(testObject!=null) return testObject;
00895 
00896 
00897              try {
00898                if(!Sct.IS.SctNames.getISRepository().contains(resultObject)) return null;
00899                TestSummaryIS result = new TestSummaryIS();
00900                Sct.IS.SctNames.getISRepository().getValue(resultObject, result);
00901                SummaryReader.Reader reader = new SummaryReader.Reader(serialNo,result.dataString,dcsInfo);
00902                cache.put(resultObject,reader.getTest());
00903                return reader.getTest();
00904                }catch(Exception e){System.err.println("SctGUI: Failed to extract "+resultObject+" : "+e.toString());}
00905              return null;
00906              }
00907 
00908 
00909    public void fillDCSMap(String objectName) {
00910       ConfigurationInterface config = ConfigurationInterface.getInstance();
00911       if(!config.isDCSAvailable()) return;
00912       try {
00913       Map snMap = new HashMap();
00914       for(Enumeration e = config.getSerialNumberMap(guiControl.displayPane.getSCTView()).elements(); e.hasMoreElements();) {
00915            ModuleCell thisCell = (ModuleCell) e.nextElement();
00916            String sn = thisCell.getSerialNo();
00917            SummaryReader.DCSInfo dcsInfo = new SummaryReader.DCSInfo();
00918            for(int i=0;i<dcsParams.length;i++) {
00919                 Double thisData = readDCSData(sn,i);
00920                 if(thisData!=null) dcsInfo.put(i,thisData.doubleValue());
00921                 }
00922            snMap.put(sn,dcsInfo);
00923            }
00924        dcsMap.put(objectName,snMap);
00925       }catch(Exception e){System.err.println("SctGUI: Failed to extract DCS data");}
00926 
00927       }
00928       
00929 
00930   public Double getDCSData(String sn, int parameterIndex) {
00931          switch(parameterIndex) {
00932            case 8:
00933               SummaryReader.DCSInfo dcsInfo = new SummaryReader.DCSInfo();
00934               for(int i=2;i<=3;i++) {
00935                  Double thisData = readDCSData(sn,i);
00936                  if(thisData!=null) dcsInfo.put(i,thisData.doubleValue());
00937                  }
00938               return dcsInfo.get(parameterIndex);
00939 
00940            case 9: // for TDiff and Power, need to read all params
00941               dcsInfo = new SummaryReader.DCSInfo();
00942               for(int i=0;i<dcsParams.length;i++) {
00943                 if(i==2 || i==3) continue;    // dont need T0 and T1
00944                 Double thisData = readDCSData(sn,i);
00945                 if(thisData!=null) dcsInfo.put(i,thisData.doubleValue());
00946                 }
00947                return dcsInfo.get(parameterIndex);
00948            case 10:
00949                 return readDCSData(sn,8);
00950            default:
00951                return readDCSData(sn,parameterIndex);
00952            }
00953         }
00954 
00955 
00956 
00957 
00958    public Double readDCSData(String sn, int parameterIndex) {
00959          String dcsHeader = ConfigurationInterface.getInstance().getSNInfo(sn,SNInfo.DCS_HEADER);
00960          if(dcsHeader==null) return null;
00961          String ISObject = prefs.getPreference(prefs.DCS_SERVER_NAME)+"."+dcsHeader+dcsParams[parameterIndex]+".Recv";
00962          Double dcsData = readDCSData(ISObject);
00963          if(dcsData!=null && parameterIndex==SummaryReader.DCSInfo.IDET) {  // convert from nA to uA
00964                   double iInMicroAmps = dcsData.doubleValue()/1000.;
00965                   try {
00966                     dcsData =  Double.valueOf(nf.format(iInMicroAmps));
00967                     }catch(Exception e){dcsData=null;}
00968                   }
00969          return dcsData;
00970          }
00971 
00972    public Double readDCSData(String ISObjectName) {
00973    // get the DCS data from the dcsCache
00974    // if it is not there, read it from IS and update the dcsCache
00975    
00976          Double theData = (Double)dcsCache.get(ISObjectName);
00977          if(theData==null) {
00978 
00979             try {
00980               ConfigurationInterface config = ConfigurationInterface.getInstance();
00981               if(!config.isDCSAvailable()) return null;
00982  //             if(!Sct.IS.SctNames.getISRepository().contains(ISObjectName)) return null;
00983               is.AnyInfo theValue = new is.AnyInfo();
00984               Sct.IS.SctNames.getISRepository().getValue(ISObjectName, theValue);
00985               double dData = ((Float)theValue.getAttribute(theValue.getAttributeCount()-1)).doubleValue();
00986               theData =  Double.valueOf(nf.format(dData));
00987               if(theData!=null) dcsCache.put(ISObjectName,theData);
00988             }catch(Exception e){return null;}
00989            }
00990 
00991          return theData;
00992          }
00993 
00994    public void fillDCSCache() {
00995 //         System.out.println("fill DCS cache ");
00996          try {
00997          Set newDCSDataSet = isCounter.getDCSObjectList();
00998 //       System.out.println("size of update = "+newDCSDataSet.size());
00999          for (Iterator i = newDCSDataSet.iterator(); i.hasNext(); ) {
01000                 String ISObject = (String)i.next();
01001                 if(!Sct.IS.SctNames.getISRepository().contains(ISObject)) continue;
01002 //              System.out.println("filling DCS Cache for object "+ISObject);
01003                 is.AnyInfo theValue = new is.AnyInfo();
01004                 Sct.IS.SctNames.getISRepository().getValue(ISObject, theValue);
01005                 double theData = ((Float)theValue.getAttribute(theValue.getAttributeCount()-1)).doubleValue();
01006                 dcsCache.put(ISObject,Double.valueOf(nf.format(theData)));
01007                 }
01008          }catch(Exception e){System.err.println("Exception filling DCS cache - "+e.toString());}
01009          }
01010 
01011     public void refillDCSCache(int parameterIndex) {
01012 //        System.out.println("refilling DCS Cache");
01013         ConfigurationInterface config = ConfigurationInterface.getInstance();
01014         String DCS_Server_Name = prefs.getPreference(prefs.DCS_SERVER_NAME);
01015         try {
01016             for(Enumeration e = config.getSerialNumberMap(guiControl.displayPane.getSCTView()).elements(); e.hasMoreElements();) {
01017                ModuleCell thisCell = (ModuleCell) e.nextElement();
01018                String dcsHeader = config.getSNInfo(thisCell.getSerialNo(),SNInfo.DCS_HEADER);
01019                if(dcsHeader==null) continue;
01020                String ISObject = DCS_Server_Name+"."+dcsHeader+dcsParams[parameterIndex]+".Recv";
01021                if(!Sct.IS.SctNames.getISRepository().contains(ISObject)) continue;
01022 //             System.out.println("Refilling DCS Cache for object "+ISObject);
01023                is.AnyInfo theValue = new is.AnyInfo();
01024                Sct.IS.SctNames.getISRepository().getValue(ISObject, theValue);
01025                double theData = ((Float)theValue.getAttribute(theValue.getAttributeCount()-1)).doubleValue();
01026                dcsCache.put(ISObject,Double.valueOf(nf.format(theData)));
01027                }
01028             }
01029         catch(Exception ee) {System.err.println("SctGUI::ISInterface - exception retrieving DCS Data: "+ee.toString());}
01030         }
01031 
01032 
01033 
01034     public Map getDCSMap(String controlObjectName) {
01035        return (Map)dcsMap.get(controlObjectName);
01036        }
01037     public void setCacheSize(int size) {
01038        cache = new guiUtilities.Cache(size);
01039        }
01040  
01041 
01042 
01043 
01044      private GuiComponents.System.ISInterface is;
01045 
01046 
01047 }
01048 
01049 
01050 

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