DerivedMetric.java
Go to the documentation of this file.00001
00004 package edu.rice.cs.hpc.data.experiment.metric;
00005
00006 import edu.rice.cs.hpc.data.experiment.Experiment;
00007 import edu.rice.cs.hpc.data.experiment.scope.*;
00008
00009
00010 import com.graphbuilder.math.*;
00011
00016 public class DerivedMetric extends BaseMetric {
00017
00018
00019
00020
00021
00022 private Expression expression;
00023
00024 private double dRootValue = 0.0;
00025
00026 private ExtFuncMap fctMap;
00027
00028 private MetricVarMap varMap;
00029
00030 private Experiment experiment;
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 public DerivedMetric(Experiment experiment, Expression e, String sName, String sID, int index, AnnotationType annotationType, MetricType objType) {
00051
00052
00053
00054 super(sID, sName, true, null, annotationType, index, index, objType);
00055
00056 this.expression = e;
00057 this.experiment = experiment;
00058
00059
00060 this.fctMap = new ExtFuncMap();
00061
00062 RootScope root = (RootScope) experiment.getRootScope().getSubscope(0);
00063
00064 BaseMetric []metrics = experiment.getMetrics();
00065 this.fctMap.init(metrics);
00066
00067
00068 this.varMap = new MetricVarMap(experiment);
00069
00070
00071 this.dRootValue = getAggregateMetrics(root);
00072 if(this.dRootValue == 0.0)
00073 this.annotationType = AnnotationType.NONE ;
00074 }
00075
00076
00077
00078
00079
00080
00081 public void setExpression( Expression expr ) {
00082 this.expression = expr;
00083
00084
00085 RootScope root = (RootScope) experiment.getRootScope().getSubscope(0);
00086 dRootValue = getAggregateMetrics(root);
00087 }
00088
00089
00090
00091
00092
00098 private double getAggregateMetrics(RootScope scopeRoot) {
00099 try {
00100 Double objSum = this.getDoubleValue(scopeRoot);
00101 if (objSum != null)
00102 return objSum.doubleValue();
00103 } catch (Exception e) {
00104
00105 }
00106 return Double.MIN_VALUE;
00107 }
00108
00109
00110
00111
00112
00118 public Double getDoubleValue(Scope scope) {
00119 Double objResult = null;
00120 this.varMap.setScope(scope);
00121 try {
00122 double dValue = this.expression.eval(this.varMap, this.fctMap);
00123 objResult = new Double(dValue);
00124 } catch(java.lang.Exception e) {
00125
00126 }
00127 return objResult;
00128 }
00129
00134 @Override
00135 public MetricValue getValue(Scope scope) {
00136 double dVal;
00137
00138 if(scope instanceof RootScope) {
00139 dVal = dRootValue;
00140 } else {
00141
00142 Double objVal = this.getDoubleValue(scope);
00143 if(objVal == null)
00144 return MetricValue.NONE;
00145 dVal = objVal.doubleValue();
00146 }
00147 if(this.getAnnotationType() == AnnotationType.PERCENT){
00148 return new MetricValue(dVal, ((float) dVal/this.dRootValue));
00149 } else {
00150 return new MetricValue(dVal);
00151 }
00152 }
00153
00154
00155
00156
00157
00158
00159 public Expression getFormula() {
00160 return expression;
00161 }
00162
00163
00164 public BaseMetric duplicate() {
00165 return new DerivedMetric(experiment, expression, displayName, shortName, index, annotationType, metricType);
00166 }
00167
00168 }