00001 package edu.rice.cs.hpc.data.experiment.extdata; 00002 00003 import java.io.IOException; 00004 import java.util.ArrayList; 00005 00006 00007 /****************************************************************** 00008 * 00009 * Filtered version for accessing a raw data file 00010 * A data file can either thread level data metric, or trace data 00011 * @see IBaseData 00012 * @see AbstractBaseData 00013 * @see FileDB2 00014 *******************************************************************/ 00015 public class FilteredBaseData extends AbstractBaseData implements IFilteredData { 00016 00017 private FilterSet filter; 00018 private String []filteredRanks; 00019 private int []indexes; 00020 00021 /***** 00022 * construct a filtered data 00023 * The user is responsible to make sure the filter has been set with setFilters() 00024 * 00025 * @param filename 00026 * @param headerSize 00027 * @throws IOException 00028 */ 00029 public FilteredBaseData(String filename, int headerSize, int recordSz) throws IOException 00030 { 00031 super( filename, headerSize, recordSz); 00032 filter = new FilterSet(); 00033 } 00034 00035 /**** 00036 * start to filter the ranks 00037 */ 00038 private void applyFilter() { 00039 if (baseDataFile == null) 00040 throw new RuntimeException("Fatal error: cannot find data."); 00041 00042 String data[] = baseDataFile.getRankLabels(); 00043 00044 filteredRanks = null; 00045 00046 ArrayList<Integer> lindexes = new ArrayList<Integer>(); 00047 00048 if (filter.hasAnyFilters()) { 00049 for (int i = 0; i < data.length; i++) { 00050 if (filter.includes(data[i])) 00051 lindexes.add(i); 00052 } 00053 //Convert ArrayList to array 00054 indexes = new int[lindexes.size()]; 00055 for (int i = 0; i < indexes.length; i++) { 00056 indexes[i] = lindexes.get(i); 00057 } 00058 } else { 00059 // no glob pattern to filter 00060 // warning: not optimized code 00061 indexes = new int[data.length]; 00062 for(int i=0; i<data.length; i++) { 00063 indexes[i] = i; 00064 } 00065 } 00066 } 00067 00068 /**** 00069 * set oatterns to filter ranks 00070 * @param filters 00071 */ 00072 public void setFilter(FilterSet filter) { 00073 this.filter = filter; 00074 applyFilter(); 00075 } 00076 00077 00078 public FilterSet getFilter() { 00079 return filter; 00080 } 00081 00082 00083 /* 00084 * (non-Javadoc) 00085 * @see edu.rice.cs.hpc.data.experiment.extdata.IBaseData#getListOfRanks() 00086 */ 00087 public String[] getListOfRanks() { 00088 if (filteredRanks == null) { 00089 filteredRanks = new String[indexes.length]; 00090 final String ranks[] = baseDataFile.getRankLabels(); 00091 00092 for(int i=0; i<indexes.length; i++) { 00093 filteredRanks[i] = ranks[indexes[i]]; 00094 } 00095 } 00096 return filteredRanks; 00097 } 00098 00099 /* 00100 * (non-Javadoc) 00101 * @see edu.rice.cs.hpc.data.experiment.extdata.IBaseData#getNumberOfRanks() 00102 */ 00103 public int getNumberOfRanks() { 00104 return indexes.length; 00105 } 00106 00107 00108 /* 00109 * (non-Javadoc) 00110 * @see edu.rice.cs.hpc.data.experiment.extdata.IBaseData#getMinLoc(int) 00111 */ 00112 public long getMinLoc(int rank) { 00113 int filteredRank = indexes[rank]; 00114 final long offsets[] = baseDataFile.getOffsets(); 00115 return offsets[filteredRank] + headerSize; 00116 } 00117 00118 /* 00119 * (non-Javadoc) 00120 * @see edu.rice.cs.hpc.data.experiment.extdata.IBaseData#getMaxLoc(int) 00121 */ 00122 public long getMaxLoc(int rank, int recordSize) { 00123 int filteredRank = indexes[rank]; 00124 final long offsets[] = baseDataFile.getOffsets(); 00125 long maxloc = ( (filteredRank+1<baseDataFile.getNumberOfRanks())? 00126 offsets[filteredRank+1] : baseDataFile.getMasterBuffer().size()-SIZE_OF_END_OF_FILE_MARKER ) 00127 - recordSize; 00128 return maxloc; 00129 } 00130 00131 @Override 00132 public boolean isGoodFilter() { 00133 return getNumberOfRanks() > 0; 00134 } 00135 00136 @Override 00137 public int getFirstIncluded() { 00138 return indexes[0]; 00139 } 00140 00141 @Override 00142 public int getLastIncluded() { 00143 return indexes[indexes.length-1]; 00144 } 00145 00146 @Override 00147 public boolean isDenseBetweenFirstAndLast() { 00148 return indexes[indexes.length-1]-indexes[0] == indexes.length-1; 00149 } 00150 00151 }