ISCounter.java

00001 package DisplayGUI;
00002 
00003 import java.util.regex.*;
00004 import java.util.*;
00005 import is.*;
00006 import Sct.Serializable;
00007 import Sct.IS.*;
00008 import Sct_CalibrationController.TestData;
00009 
00010 /*
00011  * ISCounter.java
00012  *
00013  */
00014 
00019 public class ISCounter {
00020         final java.util.regex.Pattern objectPattern = java.util.regex.Pattern.compile(".*TestData\\.[0-9]+\\.[0-9]+");
00021         List masterList = new ArrayList();
00022         String[] serverNames = {SctNames.getEventISServer(),SctNames.getFitISServer(),SctNames.getTestISServer(),
00023                                 "RetrievedData","RetrievedData","RetrievedData"};
00024         String[] serverRegexs = {
00025          SctNames.getEventISServer()+".*SctData",
00026          SctNames.getFitISServer()+".*SctData",
00027          SctNames.getTestISServer()+".*SctData",
00028          "RetrievedData.*SctData::RawScanResult",
00029          "RetrievedData.*SctData::FitScanResult",
00030          "RetrievedData.*SctData.*TestResult" 
00031          };
00032 
00033          
00034         HashMap m;
00035         Pattern oPattern = Pattern.compile("(.*)\\.SctData::.*\\.(\\d+\\.\\d+)\\.(\\d{14})");
00036 
00037         private boolean requestUpdate=false;
00038         
00039         Set dcsList = new HashSet();
00040 
00041         public ISCounter() {
00042            m = new HashMap();
00043            masterList = new ArrayList();
00044            }
00045         public void refresh(String regex) {
00046            m = new HashMap();
00047            masterList = new ArrayList();
00048            readIS(regex);
00049            }          
00050 
00051         public synchronized void readIS(String regex) {
00052 
00053 // regex is ".*(runNo.ScanNo1|runNo.ScanNo2|runNo.ScanNo3)"
00054            GuiComponents.System.ISInterface is = GuiComponents.System.ISInterface.getInstance();
00055 
00056 
00057            String[] objects;
00058 
00059 // first get the list of control objects
00060 
00061            for(int j=0;j<serverRegexs.length;j++) {
00062              m.put(serverRegexs[j]+regex+"(\\d{14})", new HashMap());
00063              }
00064 
00065 
00066 
00067 // now go through the data
00068            for(int j=0;j<serverNames.length;j++) {
00069              switch(j) { 
00070                 case 3:
00071                   objects = is.getISObjects(serverNames[j],".*RawScanResult.*"+regex+".*");
00072                   break;
00073                 case 4:
00074                   objects = is.getISObjects(serverNames[j],".*FitScanResult.*"+regex+".*");
00075                   break;
00076                 case 5:
00077                   objects = is.getISObjects(serverNames[j],".*TestResult.*"+regex+".*");
00078                   break;
00079                 default:
00080                   objects = is.getISObjects(serverNames[j],regex+".*");
00081                 }
00082              for(int o=0;o<objects.length;o++) {
00083                Matcher matcher2 = oPattern.matcher(objects[o]);
00084                if(!matcher2.matches()) continue;   // a non-data object
00085                masterList.add(objects[o]);  
00086                String regexKey=null;   
00087                String sn=null;
00088                ILOOP:   
00089                for (Iterator i=m.entrySet().iterator(); i.hasNext(); ) {
00090                  Map.Entry e = (Map.Entry)i.next();
00091                  String thisRegex = (String)e.getKey();
00092                  Pattern rPattern = Pattern.compile(thisRegex);
00093                  Matcher matcher = rPattern.matcher(objects[o]);
00094                  if(matcher.matches()) {
00095                     sn=objects[o].substring(matcher.start(2),matcher.end(2));
00096                     regexKey = thisRegex;
00097                     break ILOOP;
00098                     }
00099                  }
00100                 if(regexKey==null || sn==null) {
00101                    System.out.println("SctGUI::ISCounter: No key/sn found for "+objects[o]+" !!!");
00102                    continue;
00103                    }
00104                 Map sm = (HashMap)m.get(regexKey);
00105                 List snList = (List)sm.get(sn);
00106                 if(snList==null) snList = new ArrayList();
00107                 snList.add(objects[o]);
00108 //                System.out.println("Added "+objects[o]+" to snList, whcih now has size "+snList.size());
00109                 sm.put(sn,snList);
00110                 masterList.add(objects[o]);
00111                 }
00112               }
00113 
00114 
00115          }
00116 
00117     public synchronized Map getModuleMap(int serverIndex,String regex, boolean isRetrievedData) {
00118         if(regex==null) return null;
00119         if(isRetrievedData) serverIndex+=3;
00120         String mRegex = serverRegexs[serverIndex]+regex+"(\\d{14})";
00121         return (Map)m.get(mRegex);
00122 
00123         }
00124     public synchronized List getModuleList(int serverIndex, String regex, String sn, boolean isRetrievedData) {
00125         if(regex==null) return null;
00126         if(isRetrievedData) serverIndex+=3;
00127         String mRegex = serverRegexs[serverIndex]+regex+"(\\d{14})";
00128 
00129         Map sm = (HashMap)m.get(mRegex);
00130         if(sm==null) return null;
00131         return (List)sm.get(sn);
00132         }
00133         
00134     public synchronized Set getDCSObjectList() {
00135         Set newSet = new HashSet(dcsList);
00136         dcsList.clear();
00137         return newSet;
00138         }
00139         
00140    public synchronized void clearDCSObjectList() {
00141        dcsList.clear();
00142        }
00143         
00144     public synchronized void updateObject(String objectName) {
00145         if(objectName.startsWith("SCTDCS")) dcsList.add(objectName);
00146         }
00147 
00148     public synchronized void addObject(String objectName) {
00149     
00150         if(objectName.startsWith("SCTDCS")) {
00151            dcsList.add(objectName);
00152            return;
00153            }
00154 
00155         Matcher matcher2 = oPattern.matcher(objectName);
00156         if(!matcher2.matches()) return;   // a non-data object
00157         if(masterList.contains(objectName)) return;
00158         String regexKey=null,sn=null;
00159         for (Iterator i=m.entrySet().iterator(); i.hasNext(); ) {
00160                  Map.Entry e = (Map.Entry)i.next();
00161                  String regex = (String)e.getKey();
00162                  Pattern rPattern = Pattern.compile(regex);
00163                  Matcher matcher = rPattern.matcher(objectName);
00164                  if(matcher.matches()) {
00165                     sn=objectName.substring(matcher.start(2),matcher.end(2));
00166                     regexKey = regex;
00167                     break;
00168                     }
00169                  }
00170         if(regexKey==null || sn==null) {
00171 //                   System.out.println("SctGUI::ISCounter: No key/sn found for "+objectName+" !!!");
00172                    return;
00173                    }
00174         Map sm = (Map)m.get(regexKey);
00175         List snList = (List)sm.get(sn);
00176         if(snList==null) snList = new ArrayList();
00177         snList.add(objectName);
00178         sm.put(sn,snList);
00179         masterList.add(objectName);
00180         }
00181 
00182     public synchronized boolean archivedObjectsRetrievedOk(int serverIndex, String regex) {
00183 
00184         GuiComponents.System.ISInterface is = GuiComponents.System.ISInterface.getInstance();
00185 
00186         if(!m.containsKey(serverRegexs[serverIndex+3]+regex+"(\\d{14})")) {
00187            System.out.println("SctGUI::IsCounter - ERROR No key for "+serverRegexs[serverIndex+3]+regex+"(\\d{14})");
00188            return false;
00189            }
00190         Map sm = (HashMap)m.get(serverRegexs[serverIndex+3]+regex+"(\\d{14})");
00191         return (sm.size()>0);
00192         }
00193 
00194 
00195 }
00196                   
00197           
00198 
00199                    
00200 
00201 
00202  

Generated on Mon Feb 6 14:12:13 2006 for SCT DAQ/DCS Software - Java by  doxygen 1.4.6