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

Generated on Thu Feb 10 02:44:27 2005 for SCT DAQ/DCS Software - Java by doxygen 1.3.5