00001 package edu.rice.cs.hpc.remote.data; 00002 00003 import java.io.DataOutputStream; 00004 import java.io.IOException; 00005 import java.util.ArrayList; 00006 00007 import edu.rice.cs.hpc.data.experiment.extdata.Filter; 00008 import edu.rice.cs.hpc.data.experiment.extdata.FilterSet; 00009 import edu.rice.cs.hpc.data.experiment.extdata.IFilteredData; 00010 import edu.rice.cs.hpc.data.experiment.extdata.TraceName; 00011 00012 00013 00014 00015 public class RemoteFilteredBaseData implements IFilteredData { 00016 00017 private static final int FILTER = 0x464C5452; 00018 private final TraceName[] allNames; 00019 private int[] indexes; 00020 private final int headerSize; 00021 private final DataOutputStream server; 00022 FilterSet filter; 00023 00024 public RemoteFilteredBaseData(TraceName[] names, int _headerSz, DataOutputStream server) { 00025 allNames = names; 00026 headerSize = _headerSz; 00027 this.server = server; 00028 filter = new FilterSet(); 00029 indexes = new int[names.length]; 00030 for (int i = 0; i < indexes.length; i++) { 00031 indexes[i] = i; 00032 } 00033 } 00034 @Override 00035 public void setFilter(FilterSet filter) { 00036 this.filter = filter; 00037 applyFilter(); 00038 } 00039 00040 00041 private void applyFilter() { 00042 ArrayList<Integer> lindexes = new ArrayList<Integer>(); 00043 00044 00045 for (int i = 0; i < allNames.length; i++) { 00046 if (filter.include(allNames[i])) 00047 lindexes.add(i); 00048 } 00049 00050 indexes = new int[lindexes.size()]; 00051 for (int i = 0; i < indexes.length; i++) { 00052 indexes[i] = lindexes.get(i); 00053 } 00054 00055 try { 00056 server.writeInt(FILTER); 00057 ArrayList<Filter> pat = filter.getPatterns(); 00058 server.write(0); 00059 server.write(filter.isShownMode()? 0 : 1); 00060 server.writeShort(pat.size()); 00061 for (Filter filter : pat) { 00062 filter.serializeSelfToStream(server); 00063 } 00064 server.flush(); 00065 00066 } catch (IOException e) { 00067 // TODO Auto-generated catch block 00068 e.printStackTrace(); 00069 } 00070 00071 } 00072 @Override 00073 public FilterSet getFilter() { 00074 return filter; 00075 } 00076 00077 @Override 00078 public int getHeaderSize() { 00079 return headerSize; 00080 } 00081 00082 @Override 00083 public String[] getListOfRanks() { 00084 //This is already an O(n) operation so it's okay that we are recomputing the strings. 00085 String[] list = new String[getNumberOfRanks()]; 00086 for (int i = 0; i < list.length; i++) { 00087 list[i] = allNames[indexes[i]].toString(); 00088 } 00089 return list; 00090 } 00091 00092 @Override 00093 public int getNumberOfRanks() { 00094 return indexes.length; 00095 } 00096 00097 @Override 00098 public void dispose() { 00099 // Do nothing. The local version disposes the BaseDataFile. The rough 00100 // equivalent would be to dispose the RemoteDataRetriever, but that is 00101 // done elsewhere. Plus, because RemoteDataRetriever is in traceviewer, 00102 // we can't access it here. 00103 } 00104 00105 @Override 00106 public boolean isGoodFilter() { 00107 return getNumberOfRanks() > 0; 00108 } 00109 @Override 00110 public int getFirstIncluded() { 00111 return indexes[0]; 00112 } 00113 @Override 00114 public int getLastIncluded() { 00115 return indexes[indexes.length-1]; 00116 } 00117 @Override 00118 public boolean isDenseBetweenFirstAndLast() { 00119 return indexes[indexes.length-1] == indexes.length-1; 00120 } 00121 @Override 00122 public boolean isHybridRank() { 00123 return allNames[0].toString().contains("."); 00124 } 00125 }