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