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 private List subscriptionList;
00034
00035 int listFilterIndex;
00036
00037 private final String eventServerRegex = ".*RawScanResult.*[0-9]+\\.[0-9]+(\\.[0-9]{14})?";
00038 private final String fitServerRegex = ".*FitScanResult.*[0-9]+\\.[0-9]+(\\.[0-9]{14})?";
00039 private final String controlObjectRegex = ".*TestData\\.[0-9]+\\.[0-9]+(.*Test)?";
00040 private final String rControlObjectRegex = ".*TestData\\.[0-9]+\\.[0-9]+.*Test";
00041 private final String dbControlObjectRegex = ".*SctRodDaqRefData.*";
00042 private final String testServerRegex = ".*Result.*[0-9]+\\.[0-9]+(\\.[0-9]{14})?";
00043 private final String resultObjectRegex = ".*(Summary).*";
00044 private final String ivscanRegex = ".*IVScanData.*";
00045 private final String ivscanControlRegex = ".*ControlIVScanData.*";
00046
00047 private final Pattern objectPattern = Pattern.compile(".*TestData\\.[0-9]+\\.[0-9]+");
00048 private final Pattern rObjectPattern = Pattern.compile(".*\\.[0-9]+\\.[0-9]+.*Test");
00049 public static final Pattern defectPattern = Pattern.compile("(\\d+)-(\\d+)\\s*:\\s*(\\w+)");
00050 public static final Pattern SctRodDaqRefPattern = Pattern.compile(".*SctRodDaqRefData\\.(.*)\\.(.*)\\.(\\d+)\\.(\\d+)");
00051
00052
00053 String eventServer;
00054 String fitServer;
00055 String testServer;
00056 String controlServer;
00057 String SCTDBServer;
00058 String retrievedArchiveServer;
00059
00060 String testLocation;
00061
00062 int serverIndex=0;
00063
00064 boolean infoListenersAreActive=true;
00065
00066 java.util.Map moduleCount = new HashMap();
00067
00068
00069 public static final int LOCATION=2;
00070 public static final int TESTNAME=1;
00071 public static final int RUNNO=3;
00072 public static final int SCANNO=4;
00073
00074 guiUtilities.Cache cache=null;
00075 Map dcsCache=null;
00076 Map dcsMap = new HashMap();
00077
00078 java.text.DecimalFormat nf = new java.text.DecimalFormat("#.###");
00079 java.text.DecimalFormat nfe = new java.text.DecimalFormat("#.##E0");
00080
00081 Preferences.PreferencesInterface prefs;
00082
00083 PlotOptionsFrame plotOptionsFrame=null;
00084
00085 public ISInterface(gui parent) {
00086 guiControl=parent;
00087
00088 prefs = Preferences.PreferencesInterface.getInstance();
00089
00090 isRequestBuffer = new ISRequestBuffer(guiControl);
00091
00092 isCounter = new ISCounter();
00093 listFilterIndex=-1;
00094
00095
00096 eventServer = SctNames.getEventISServer();
00097 fitServer = SctNames.getFitISServer();
00098 testServer = SctNames.getTestISServer();
00099 controlServer = SctNames.getControlISServer();
00100 SCTDBServer = "SCTDBData";
00101 retrievedArchiveServer = "RetrievedData";
00102
00103 testLocation="Any";
00104
00105 if(cache==null) setCacheSize(700);
00106 if(dcsCache==null) dcsCache = new HashMap(672*9);
00107
00108
00109 }
00110 protected void subscribe() {
00111 subscribe(-1);
00112 }
00113
00114 public void setISCounter(String regex) {
00115 isCounter.refresh(regex);
00116 }
00117
00118 protected void subscribe(int testType) {
00119 listFilterIndex=testType;
00120 String[] objects;
00121 Vector ISTests = new Vector();
00122
00123 is = GuiComponents.System.ISInterface.getInstance();
00124
00125 subscriptionList = new ArrayList();
00126
00127 try {
00128
00129 switch(guiControl.displayStatus.getStatus()) {
00130 case DisplayStatus.SCTDB_RODDAQ_DATA:
00131 objects = is.getISObjects(SCTDBServer,dbControlObjectRegex);
00132 for(int i=0;i<objects.length;i++) ISTests.addElement(objects[i]);
00133 break;
00134 case DisplayStatus.IV_DATA:
00135 objects = is.getISObjects(retrievedArchiveServer,ivscanControlRegex);
00136 for(int i=0;i<objects.length;i++) ISTests.addElement(objects[i]);
00137 break;
00138 default:
00139 objects = is.getISObjects(retrievedArchiveServer,rControlObjectRegex);
00140 for(int i=0;i<objects.length;i++) ISTests.addElement(objects[i]);
00141 objects = is.getISObjects(controlServer,controlObjectRegex);
00142 for(int i=0;i<objects.length;i++) ISTests.addElement(objects[i]);
00143 }
00144
00145 if(guiControl.displayStatus.getStatus()!=DisplayStatus.IV_DATA) {
00146 for(int j=ISTests.size()-1;j>=0;j--) {
00147 String controlObject = (String)ISTests.elementAt(j);
00148 Matcher matcher = objectPattern.matcher(controlObject);
00149 Matcher matcher2 = rObjectPattern.matcher(controlObject);
00150 if(!matcher.matches() && !matcher2.matches() && !controlObject.matches(dbControlObjectRegex)) {
00151 ISTests.removeElementAt(j);
00152 continue;
00153 }
00154 if(listFilterIndex==-1) continue;
00155 else {
00156 TestData testData = new TestData();
00157 is.getRepository().getValue(controlObject, testData);
00158 String thisTestName = (listFilterIndex==TEST_3PTGAIN) ? testNames[TEST_NPTGAIN] : testNames[listFilterIndex];
00159 if(testData.testName.indexOf(thisTestName)==-1) ISTests.removeElementAt(j);
00160 }
00161 }
00162 }
00163
00164 }catch(Exception e){System.out.println("SctGUI::ISInterface - Error subscribing to test data");}
00165 guiControl.tablesDisplayPane.setTestTable(ISTests);
00166
00167 try {
00168 switch(guiControl.displayStatus.getStatus()) {
00169 case DisplayStatus.IS_MONITOR:
00170
00171
00172 subscriptionList.add(new Subscription(eventServer, eventServerRegex));
00173 subscriptionList.add(new Subscription(fitServer, fitServerRegex));
00174 subscriptionList.add(new Subscription(testServer, testServerRegex));
00175 subscriptionList.add(new Subscription(controlServer, controlObjectRegex));
00176
00177 subscriptionList.add(new Subscription("RetrievedData",".*"));
00178
00179
00180
00181
00182 break;
00183 case DisplayStatus.TEST_DATA:
00184 subscriptionList.add(new Subscription(testServer, resultObjectRegex));
00185 subscriptionList.add(new Subscription(controlServer, controlObjectRegex));
00186 subscriptionList.add(new Subscription(retrievedArchiveServer, ".*"));
00187
00188
00189 break;
00190 case DisplayStatus.SCTDB_DATA:
00191 subscriptionList.add(new Subscription(controlServer, controlObjectRegex));
00192 subscriptionList.add(new Subscription(SCTDBServer, ".*"));
00193 break;
00194 case DisplayStatus.SCTDB_RODDAQ_DATA:
00195 subscriptionList.add(new Subscription(SCTDBServer, ".*"));
00196 break;
00197 case DisplayStatus.IV_DATA:
00198 subscriptionList.add(new Subscription(retrievedArchiveServer, ivscanRegex));
00199 break;
00200 case DisplayStatus.DCS_DATA:
00201 isCounter.clearDCSObjectList();
00202 int pIndex = guiControl.selectorPane.getDisplayParameterIndex();
00203 String dcsServer =prefs.getPreference(prefs.DCS_SERVER_NAME);
00204 switch(pIndex) {
00205 case 8:
00206 subscriptionList.add(new Subscription(dcsServer, ".*"+dcsParams[2]+".*"));
00207 subscriptionList.add(new Subscription(dcsServer, ".*"+dcsParams[3]+".*"));
00208 refillDCSCache(2);
00209 refillDCSCache(3);
00210 break;
00211 case 9:
00212 for(int k=0;k<8;k++) {
00213 if(k==2 || k==3) continue;
00214 subscriptionList.add(new Subscription(dcsServer, ".*"+dcsParams[k]+".*"));
00215 refillDCSCache(k);
00216 }
00217 break;
00218 case 10:
00219
00220 subscriptionList.add(new Subscription(dcsServer, ".*"+dcsParams[8]+".*"));
00221 refillDCSCache(8);
00222 break;
00223 default:
00224 subscriptionList.add(new Subscription(dcsServer,".*"+dcsParams[pIndex]+".*"));
00225 refillDCSCache(pIndex);
00226 }
00227
00228 break;
00229 default:
00230 }
00231
00232 for (ListIterator i = subscriptionList.listIterator(); i.hasNext(); ) {
00233 Subscription s = (Subscription)i.next();
00234
00235 if(!is.subscribe(s.getServer(),s.getRegex(),this).matches(".*successful.*")) System.out.println("SctGUI ERROR - failed to subscribe to server "+s.getServer()+" with regex "+s.getRegex());
00236 }
00237
00238
00239
00240 } catch (RuntimeException e) {
00241 System.err.println("SctGUI::ISInterface: Exception in IS subscription: " + e.toString());
00242 }
00243
00244
00245 }
00246
00247 protected void unsubscribe() {
00248
00249 if(subscriptionList==null) return;
00250 is = GuiComponents.System.ISInterface.getInstance();
00251
00252 for (ListIterator i = subscriptionList.listIterator(); i.hasNext(); ) {
00253 Subscription s = (Subscription)i.next();
00254
00255
00256 if(is.unsubscribe(s.getServer(),s.getRegex()).matches(".*successful.*")) i.remove();
00257 }
00258
00259 for (ListIterator i = subscriptionList.listIterator(); i.hasNext(); ) {
00260 Subscription s = (Subscription)i.next();
00261 System.out.println("sctGUI ERROR - unsubscribe to server "+s.getServer()+" with regex "+s.getRegex()+" FAILED!");
00262 }
00263 }
00264
00265 public void clearSubscriptions() {
00266 if(subscriptionList!=null) subscriptionList.clear();
00267 }
00268
00269 public String[] getDBISObjects(int testIndex) {
00270 return GuiComponents.System.ISInterface.getInstance().getISObjects(SCTDBServer,".*SctRodDaqRefData."+testNames[testIndex]+".*");
00271 }
00272
00273 public javax.swing.tree.DefaultMutableTreeNode getISTree() {
00274
00275 is = GuiComponents.System.ISInterface.getInstance();
00276
00277 String[] servers = is.getISServers();
00278
00279
00280
00281 javax.swing.tree.DefaultMutableTreeNode top = new javax.swing.tree.DefaultMutableTreeNode("IS Servers");
00282 javax.swing.tree.DefaultMutableTreeNode server;
00283 javax.swing.tree.DefaultMutableTreeNode object;
00284 for (int i=0; i<servers.length; i++) {
00285 server = new javax.swing.tree.DefaultMutableTreeNode(servers[i]);
00286 String[] objects = is.getISObjects(servers[i],".*");
00287 for (int j=0; j<objects.length; j++) {
00288 object = new javax.swing.tree.DefaultMutableTreeNode(objects[j]);
00289 server.add(object);
00290 }
00291 top.add(server);
00292 }
00293 return top;
00294
00295 }
00296
00300 abstract class StringRunnable implements Runnable {
00301 protected String name;
00302 StringRunnable(String name) {
00303 this.name = name;
00304 }
00305 }
00306
00307 public void infoCreated(InfoEvent e) {
00308
00309 isCounter.addObject(e.getName());
00310 javax.swing.SwingUtilities.invokeLater(new StringRunnable(e.getName()) {
00311 public void run() {
00312
00313 isRequestBuffer.queueObject(name,true);
00314 }
00315 });
00316 }
00317
00318
00319 public void infoDeleted(InfoEvent e) {
00320
00321 javax.swing.SwingUtilities.invokeLater(new StringRunnable(e.getName()) {
00322 public void run() {
00323 if(!infoListenersAreActive) return;
00324 if(name.startsWith("ControlData")) guiControl.tablesDisplayPane.removeTest(name);
00325
00326 guiControl.displayPane.setDisplayColors();
00327 guiControl.displayPane.refreshDisplay();
00328 }
00329 });
00330 }
00331
00332 public void infoUpdated(InfoEvent e) {
00333
00334 isCounter.updateObject(e.getName());
00335 javax.swing.SwingUtilities.invokeLater(new StringRunnable(e.getName()) {
00336 public void run() {
00337
00338 isRequestBuffer.queueObject(name,false);
00339 }
00340 });
00341 }
00342
00343
00344 public void removeTests(Vector testObjectNames, int minRow, int maxRow) {
00345
00346
00347
00348
00349 infoListenersAreActive=false;
00350
00351 is = GuiComponents.System.ISInterface.getInstance();
00352
00353 for(int i=maxRow;i>=minRow;i--) {
00354 String testObjectName = (String)testObjectNames.elementAt(i);
00355 TestData thisTestData = new TestData();
00356 is.getRepository().getValue(testObjectName, thisTestData);
00357
00358 int runNo = thisTestData.runNumber;
00359 int startScanNumber = thisTestData.startScanNumber;
00360
00361 StringBuffer regex = new StringBuffer(".*(");
00362 for(int k=thisTestData.startScanNumber;k<thisTestData.startScanNumber+thisTestData.nScans;k++) {
00363 if(k>thisTestData.startScanNumber) regex.append("|");
00364 regex.append("\\.");
00365 regex.append(Integer.toString(runNo));
00366 regex.append("\\.");
00367 regex.append(Integer.toString(k));
00368 regex.append("\\.");
00369 }
00370 regex.append(").*");
00371
00372 String[] deletionObjects;
00373
00374 if(testObjectName.matches("RetrievedData.*")) {
00375 deletionObjects = is.getISObjects("RetrievedData",regex.toString());
00376 for(int j=0;j<deletionObjects.length;j++) System.out.println(is.remove(deletionObjects[j]));
00377 }
00378 else if(testObjectName.matches("SCTDBData.*")) {
00379 deletionObjects = is.getISObjects("SCTDBData",regex.toString());
00380 for(int j=0;j<deletionObjects.length;j++) System.out.println(is.remove(deletionObjects[j]));
00381 }
00382 else {
00383 deletionObjects = is.getISObjects(SctNames.getEventISServer(),regex.toString());
00384 for(int j=0;j<deletionObjects.length;j++) System.out.println(is.remove(deletionObjects[j]));
00385 deletionObjects = is.getISObjects(SctNames.getFitISServer(),regex.toString());
00386 for(int j=0;j<deletionObjects.length;j++) System.out.println(is.remove(deletionObjects[j]));
00387 deletionObjects = is.getISObjects(SctNames.getTestISServer(),regex.toString());
00388 for(int j=0;j<deletionObjects.length;j++) System.out.println(is.remove(deletionObjects[j]));
00389 }
00390
00391
00392
00393
00394 System.out.println(is.remove(testObjectName));
00395 guiControl.tablesDisplayPane.removeTest(testObjectName);
00396 }
00397
00398 infoListenersAreActive=true;
00399
00400 }
00401
00402 public void removeObjects(Vector objectNames) {
00403 is = GuiComponents.System.ISInterface.getInstance();
00404 for(int i=0;i<objectNames.size();i++) System.out.println(is.remove((String)objectNames.elementAt(i)));
00405 }
00406
00407 public int getListFilterIndex() {
00408 return listFilterIndex;
00409 }
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420 private String getIsFilterHeader() {
00421 String isFilterHeader = "SctData::Result";
00422 int serverIndex = guiControl.selectorPane.getDisplayParameterIndex();
00423 switch(serverIndex) {
00424 case 0:
00425 isFilterHeader = "SctData::RawScanResult";
00426 break;
00427 case 1:
00428 isFilterHeader = "SctData::FitScanResult";
00429 break;
00430 case 2:
00431 default:
00432 TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00433 if(testSelection!=null) {
00434 String testName;
00435 if((testName=testSelection.getTestName())!=null) isFilterHeader="SctData::"+testName+"Result";
00436 }
00437 break;
00438 }
00439 return isFilterHeader;
00440 }
00441 private String getIsFilterRunInfo() {
00442 String isFilterRunInfo="none";
00443 TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00444 if(testSelection==null || testSelection.getTestData()==null) return isFilterRunInfo;
00445 StringBuffer regex = new StringBuffer("\\."+Integer.toString(testSelection.getRunNo())+"\\.(");
00446 int startScanNo = testSelection.getStartScanNumber();
00447 for(int k=startScanNo;k<startScanNo+testSelection.getNoScans();k++) {
00448 if(k>startScanNo) regex.append("|");
00449 regex.append(Integer.toString(k));
00450 regex.append("\\.");
00451 }
00452 regex.append(").*");
00453 return regex.toString();
00454 }
00455 private String getServerName() {
00456 int serverIndex = guiControl.selectorPane.getDisplayParameterIndex();
00457 String serverName=SctNames.getEventISServer();
00458 switch(serverIndex) {
00459 case 0:
00460 serverName=SctNames.getEventISServer();
00461 break;
00462 case 1:
00463 serverName=SctNames.getFitISServer();
00464 break;
00465 case 2:
00466 default:
00467 serverName=SctNames.getTestISServer();
00468 break;
00469 }
00470 return serverName;
00471 }
00472
00473
00474 public String[] getISObjects(String serialNo) {
00475 return GuiComponents.System.ISInterface.getInstance().getISObjects(getServerName(),getIsFilterHeader()+getIsFilterRunInfo()+serialNo);
00476 }
00477
00478 public Hashtable getModuleISCounts() {
00479 String serverName = getServerName();
00480 Pattern snPattern = Pattern.compile(serverName+"\\."+getIsFilterHeader()+getIsFilterRunInfo()+"(\\d{14}).*");
00481 Hashtable thisHash = new Hashtable();
00482 String[] objects = GuiComponents.System.ISInterface.getInstance().getISObjects(serverName,getIsFilterHeader()+getIsFilterRunInfo()+".*");
00483 for(int i=0;i<objects.length;i++) {
00484 Matcher matcher = snPattern.matcher(objects[i]);
00485 if(matcher.matches()) {
00486 String sn = objects[i].substring(matcher.start(2),matcher.end(2));
00487 if(thisHash.containsKey(sn)) {
00488 int count = ((Integer)thisHash.get(sn)).intValue();
00489 count++;
00490 thisHash.put(sn,new Integer(count));
00491 }
00492 else thisHash.put(sn,new Integer(1));
00493 }
00494 }
00495 return thisHash;
00496 }
00497
00498 public Vector getDataObjectList(String sn, int type) {
00499
00500
00501
00502 java.util.SortedMap m = new java.util.TreeMap();
00503 TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00504 if(testSelection==null || testSelection.getRunScanRegex()==null) {
00505 return null;
00506 }
00507
00508 java.util.List isList = (java.util.List)isCounter.getModuleList(type,testSelection.getRunScanRegex(),sn,testSelection.isRetrievedData());
00509 if(isList==null) {
00510 setISCounter(testSelection.getRunScanRegex());
00511 isList = (java.util.List)isCounter.getModuleList(type,testSelection.getRunScanRegex(),sn,testSelection.isRetrievedData());
00512 }
00513 if(isList==null) {
00514 return null;
00515 }
00516
00517 for (ListIterator i = isList.listIterator(); i.hasNext(); ) {
00518 String object = (String)i.next();
00519 String[] objectParts = object.split("\\.");
00520 Integer runNo = Integer.valueOf(objectParts[2]);
00521 Integer scanNo = Integer.valueOf(objectParts[3]);
00522 String fname = objectParts[1];
00523 m.put(new Integer(runNo.intValue()*10000 + scanNo.intValue()),object);
00524 }
00525 return new Vector(m.values());
00526 }
00527
00528
00529
00530
00531
00532 public void launchExternalViewer(String name) {
00533 try {
00534 ExternalProcess p = new ExternalProcess("DataDisplayer " + name);
00535 } catch (Exception ioe) {
00536 System.out.println(ioe.getMessage());
00537 ioe.printStackTrace();
00538 }
00539
00540 }
00541
00542 public void launchExternalViewerWithOptions(String name) {
00543 if(plotOptionsFrame==null) plotOptionsFrame = new PlotOptionsFrame();
00544 plotOptionsFrame.showFrame(name);
00545 }
00546
00547
00548 public void viewISData(String name) {
00549 try {
00550 Serializable ob = ObjectManagerIS.getInstance().readObject(name);
00551 InspectorPanel p = new InspectorPanel(name, ob);
00552
00553
00554
00555
00556
00557 JFrame frame2 = new JFrame("TreeTable");
00558 frame2.getContentPane().add(new JScrollPane(p.treeTable));
00559 frame2.pack();
00560 frame2.show();
00561
00562 } catch (java.io.IOException ioe) {
00563 System.err.println("Error reading object from IS: " + ioe + " " +ioe.getMessage() +"\n");
00564 }
00565 }
00566
00567 public void downloadTests(int index) {
00568 TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00569 if(testSelection==null || testSelection.getTestIndex()==-1) {
00570 javax.swing.JOptionPane.showMessageDialog(null,"You must select a test in ordre to download sctdaq reference data.");
00571 return;
00572 }
00573 boolean refresh=false;
00574 if(index==-1) {
00575 index=testSelection.getTestIndex();
00576 refresh=true;
00577 }
00578 if(index==-1) return;
00579 if(!testIsSCTDAQ[index]) {
00580 javax.swing.JOptionPane.showMessageDialog(null,"The selected test is not SCTDAQ compatible, so reference data cannot be downloaded.");
00581 return;
00582 }
00583 SCTDBTestDownloader d = new SCTDBTestDownloader(new Vector(ConfigurationInterface.getInstance().getSerialNumberList(guiControl.selectorPane.getViewCategoryIndex(),guiControl.selectorPane.getViewIndex())),index,testLocation,true,refresh);
00584 if(d.downloadsRequired() && d.isOkToStart()) d.start();
00585 }
00586 public void setLocation(String location) {
00587 testLocation=location;
00588 TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00589 if(testSelection!=null) testSelection.setSCTDBLocation(testLocation);
00590 }
00591 public String getLocation() {
00592 return testLocation;
00593 }
00594 public void uploadAssemblyInfo() {
00595
00596 ConfigurationInterface conf = ConfigurationInterface.getInstance();
00597
00598 if(conf.getTotalNumberOfModules()<1) return;
00599
00600 Preferences.PreferencesInterface prefs = Preferences.PreferencesInterface.getInstance();
00601 String uploadDir = prefs.getPreference(Preferences.PreferencesInterface.UPLOAD_DIR);
00602 String institute = prefs.getPreference(Preferences.PreferencesInterface.INSTITUTE);
00603 String password = prefs.getPreference(Preferences.PreferencesInterface.PASSWORD);
00604 String undefinedstring = Preferences.PreferencesInterface.unDefinedString;
00605
00606 SCTDBAssemblyChecker a = new SCTDBAssemblyChecker(guiControl,conf.buildSerialNumberMap(), uploadDir, institute, password, undefinedstring);
00607 if(a.isOkToStart()) a.start();
00608 }
00609
00610
00611 public Double getSCTDBData(String resultObject, int testIndex) {
00612 if(testIndex==-1) return null;
00613 int parameterIndex = guiControl.selectorPane.getDisplayParameterIndex();
00614 int option = guiControl.selectorPane.getMouseClickIndex();
00615 if(parameterIndex<0) return null;
00616 if(!isSCTDAQCompatible[testIndex][parameterIndex]) return null;
00617 SummaryReader.Test testResult = getSCTDBTest(resultObject);
00618 if(testResult==null) return null;
00619 Double theData=readTestData(testResult,-1,parameterIndex,option);
00620 return theData;
00621 }
00622
00623
00624 public Test getSCTDBTest(String resultObject) {
00625
00626 SummaryReader.Test testObject;
00627
00628 testObject = (SummaryReader.Test)cache.get(resultObject);
00629 if(testObject!=null) return testObject;
00630
00631
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
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
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
00675 DAQInfo daqInfo = new DAQInfo();
00676 for(int i=0;i<5;i++) daqInfo.put(i,result.daqInfo[i]);
00677 testObject.add(daqInfo);
00678
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:
00705 theData = testResult.getTestInfo().getTestStatusData();
00706 break;
00707 case 1:
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:
00719 theData = testResult.getTestInfo().getTestStatusData();
00720 break;
00721 case 1:
00722 theData = testResult.noDefects();
00723 break;
00724 case 2:
00725 theData = testResult.getNoBadChannels();
00726 break;
00727 case 3:
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 || testIndex==TEST_TXCURRENT) ? testResult.getLinkInfo().get(option,parameterIndex-4) : testResult.getLastDataBlock().get(option,parameterIndex-4);
00733 }
00734 }
00735 return theData;
00736 }
00737
00738
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:
00757 theData = testResult.getTestInfo().getTestStatusData();
00758 break;
00759 case 1:
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:
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:
00778 theData = testResult.noDefects();
00779 if(theData==null) dataLine.addElement(new Double(-1.0));
00780 else dataLine.addElement(theData);
00781 break;
00782 case 2:
00783 theData = testResult.getNoBadChannels();
00784 if(theData==null) dataLine.addElement(new Double(-1.0));
00785 else dataLine.addElement(theData);
00786 break;
00787 case 3:
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 || testIndex==TEST_TXCURRENT ) {
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
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 (java.util.Iterator m = config.getSerialNumberList(guiControl.selectorPane.getViewCategoryIndex(),guiControl.selectorPane.getViewIndex()).iterator(); m.hasNext(); ) {
00857 String sn=(String)m.next();
00858 SummaryReader.DCSInfo dcsInfo = new SummaryReader.DCSInfo();
00859 for(int i=0;i<dcsParams.length;i++) {
00860 Double thisData = readDCSData(sn,i);
00861 if(thisData!=null) dcsInfo.put(i,thisData.doubleValue());
00862 }
00863 snMap.put(sn,dcsInfo);
00864 }
00865 dcsMap.put(objectName,snMap);
00866 }catch(Exception e){System.err.println("SctGUI: Failed to extract DCS data");}
00867
00868 }
00869
00870
00871 public Double getDCSData(String sn, int parameterIndex) {
00872 switch(parameterIndex) {
00873 case 8:
00874 SummaryReader.DCSInfo dcsInfo = new SummaryReader.DCSInfo();
00875 for(int i=2;i<=3;i++) {
00876 Double thisData = readDCSData(sn,i);
00877 if(thisData!=null) dcsInfo.put(i,thisData.doubleValue());
00878 }
00879 return dcsInfo.get(parameterIndex);
00880
00881 case 9:
00882 dcsInfo = new SummaryReader.DCSInfo();
00883 for(int i=0;i<dcsParams.length;i++) {
00884 if(i==2 || i==3) continue;
00885 Double thisData = readDCSData(sn,i);
00886 if(thisData!=null) dcsInfo.put(i,thisData.doubleValue());
00887 }
00888 return dcsInfo.get(parameterIndex);
00889 case 10:
00890 return readDCSData(sn,8);
00891 default:
00892 return readDCSData(sn,parameterIndex);
00893 }
00894 }
00895
00896
00897
00898
00899 public Double readDCSData(String sn, int parameterIndex) {
00900 String dcsHeader = ConfigurationInterface.getInstance().getSNInfo(sn,SNInfo.DCS_HEADER);
00901 if(dcsHeader==null) return null;
00902 String ISObject = prefs.getPreference(prefs.DCS_SERVER_NAME)+"."+dcsHeader+dcsParams[parameterIndex]+".Recv";
00903 Double dcsData = readDCSData(ISObject);
00904 if(dcsData!=null && parameterIndex==SummaryReader.DCSInfo.IDET) {
00905 double iInMicroAmps = dcsData.doubleValue()/1000.;
00906 try {
00907 dcsData = Double.valueOf(nf.format(iInMicroAmps));
00908 }catch(Exception e){dcsData=null;}
00909 }
00910 return dcsData;
00911 }
00912
00913 public Double readDCSData(String ISObjectName) {
00914
00915
00916
00917 Double theData = (Double)dcsCache.get(ISObjectName);
00918 if(theData==null) {
00919
00920 try {
00921 ConfigurationInterface config = ConfigurationInterface.getInstance();
00922 if(!config.isDCSAvailable()) return null;
00923
00924 is.AnyInfo theValue = new is.AnyInfo();
00925 Sct.IS.SctNames.getISRepository().getValue(ISObjectName, theValue);
00926 double dData = ((Float)theValue.getAttribute(theValue.getAttributeCount()-1)).doubleValue();
00927 theData = Double.valueOf(nf.format(dData));
00928 if(theData!=null) dcsCache.put(ISObjectName,theData);
00929 }catch(Exception e){return null;}
00930 }
00931
00932 return theData;
00933 }
00934
00935 public void fillDCSCache() {
00936
00937 try {
00938 Set newDCSDataSet = isCounter.getDCSObjectList();
00939
00940 for (Iterator i = newDCSDataSet.iterator(); i.hasNext(); ) {
00941 String ISObject = (String)i.next();
00942 if(!Sct.IS.SctNames.getISRepository().contains(ISObject)) continue;
00943
00944 is.AnyInfo theValue = new is.AnyInfo();
00945 Sct.IS.SctNames.getISRepository().getValue(ISObject, theValue);
00946 double theData = ((Float)theValue.getAttribute(theValue.getAttributeCount()-1)).doubleValue();
00947 dcsCache.put(ISObject,Double.valueOf(nf.format(theData)));
00948 }
00949 }catch(Exception e){System.err.println("Exception filling DCS cache - "+e.toString());}
00950 }
00951
00952 public void refillDCSCache(int parameterIndex) {
00953
00954 ConfigurationInterface config = ConfigurationInterface.getInstance();
00955 String DCS_Server_Name = prefs.getPreference(prefs.DCS_SERVER_NAME);
00956 try {
00957 for (java.util.Iterator m = config.getSerialNumberList(guiControl.selectorPane.getViewCategoryIndex(),guiControl.selectorPane.getViewIndex()).iterator(); m.hasNext(); ) {
00958 String sn=(String)m.next();
00959 String dcsHeader = config.getSNInfo(sn,SNInfo.DCS_HEADER);
00960 if(dcsHeader==null) continue;
00961 String ISObject = DCS_Server_Name+"."+dcsHeader+dcsParams[parameterIndex]+".Recv";
00962 if(!Sct.IS.SctNames.getISRepository().contains(ISObject)) continue;
00963
00964 is.AnyInfo theValue = new is.AnyInfo();
00965 Sct.IS.SctNames.getISRepository().getValue(ISObject, theValue);
00966 double theData = ((Float)theValue.getAttribute(theValue.getAttributeCount()-1)).doubleValue();
00967 dcsCache.put(ISObject,Double.valueOf(nf.format(theData)));
00968 }
00969 }
00970 catch(Exception ee) {System.err.println("SctGUI::ISInterface - exception retrieving DCS Data: "+ee.toString());}
00971 }
00972
00973
00974
00975 public Map getDCSMap(String controlObjectName) {
00976 return (Map)dcsMap.get(controlObjectName);
00977 }
00978 public void setCacheSize(int size) {
00979 cache = new guiUtilities.Cache(size);
00980 }
00981
00982
00983
00984
00985 private GuiComponents.System.ISInterface is;
00986
00987
00988 }
00989
00990
00991