Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

MergedPlot.java

Go to the documentation of this file.
00001 package cedar.jetweb.model.plots;
00002 
00003 import cedar.jetweb.JetWebException;
00004 import cedar.jetweb.model.MCProcessType;
00005 import cedar.jetweb.db.DBManager;
00006 
00007 import java.util.HashMap;
00008 import java.util.Vector;
00009 import java.util.Collection;
00010 
00016 public class MergedPlot extends DataPlot{
00017 
00018     private Integer runSeriesCollectionId_=-1;
00019 
00020     //The predicted plots, indexed by their runseries id
00021     private HashMap<Integer, PredictedPlot> predictedPlots_ = 
00022     new HashMap<Integer, PredictedPlot>();
00023     
00024     private boolean mergePts_ = true;
00025 
00026     public MergedPlot(){
00027 
00028     }
00029 
00030     public MergedPlot(Integer runSeriesCollectionId){
00031 
00032     runSeriesCollectionId_ = runSeriesCollectionId;
00033 
00034     }
00035 
00036     public MergedPlot(PredictedPlot plot){
00037     try{
00038         addPlot(plot);
00039     }catch(JetWebException err){
00040         System.out.println
00041         ("MergedPlot: cannot instantiate MergedPlot " + 
00042          "from PredictedPlot");
00043         System.out.println(err.getMessage());
00044     }
00045     }
00046 
00047     public MCProcessType getMCProcessType(){
00048 
00049     return new MCProcessType();
00050     }
00051 
00052     public int getProcIdWanted(){
00053 
00054     return -1;
00055     }
00056 
00057     public Integer getRunSeriesCollectionId(){
00058     return runSeriesCollectionId_;
00059     }
00060     
00061 
00063     public MergedPlot addPlot(PredictedPlot plot) 
00064     throws JetWebException{
00065     
00066     addPlot(plot, true);
00067 
00068     return this;
00069     }
00071     public MergedPlot addPlot(PredictedPlot plot, boolean merge)
00072     throws JetWebException{
00073         if(predictedPlots_.size()!=0 && plot.getId()!= getId()){
00074         throw new JetWebException
00075         ("MergedPlot: Cannot add Predicted plot " + plot.getId() +  
00076          "that doesn't match existing plots " + getId(), plot.toString());
00077     }
00078 
00079     if(predictedPlots_.size()==0){
00080         setId(plot.getId());
00081         setNumber(plot.getNumber());
00082         setCollisionId(plot.getCollisionId());
00083         setLogarithmic(plot.isLogarithmic());
00084         setTitle(plot.getTitle());
00085         setYLabel(plot.getYLabel());
00086         setXLabel(plot.getXLabel());
00087         setShape(plot.isShape());
00088         setPaperId(plot.getPaperId());
00089         proc = plot.getMCProcessType();
00090 
00091         if(cuts_==null){
00092         setCutCollection(plot.getCutCollection());
00093         }else if(!cuts_.equals(plot.getCutCollection())){
00094         setCutCollection(plot.getCutCollection().union(cuts_));
00095         }
00096 
00097     }
00098 
00099     predictedPlots_.put(plot.getRunSeriesId(), plot);
00100     if(merge) mergePoints();
00101 
00102     return this;
00103     }
00105 
00106     public MergedPlot add(MergedPlot plot)
00107     throws JetWebException{
00108 
00109     if(plot.getId()>0 && getId() > 0 &&
00110        plot.getId()!= getId()){
00111         System.out.println
00112         ("MergedPlot: Cannot add two merged plots with different ids");
00113     }
00114 
00115     for(PredictedPlot pPlot: plot.getPredictedPlots()){
00116         addPlot(pPlot, false);
00117     }
00118 
00119     mergePoints();
00120     return this;
00121     }
00123     public Collection<PredictedPlot> getPredictedPlots(){
00124     return predictedPlots_.values();
00125     }
00126 
00127     public PredictedPlot getPredictedPlot(Integer runSeriesId){
00128     return predictedPlots_.get(runSeriesId);
00129     }
00130 
00132     public MergedPlot mergePoints()throws JetWebException{
00133 
00134     HashMap<Integer, DataPoint> foundPts = 
00135         new HashMap<Integer, DataPoint>();
00136 
00137     for(PredictedPlot plot: getPredictedPlots()){
00138         for(DataPoint pt: plot.getDataPoints()){
00139         DataPoint existingPt = foundPts.get(pt.getNumber());
00140         if(existingPt!=null){
00141             existingPt.add(pt);
00142             foundPts.put(pt.getNumber(), existingPt);
00143         }else{
00144             foundPts.put(pt.getNumber(), pt);
00145         }
00146         }
00147         setShape(plot.isShape());
00148     }
00149 
00150     dataPoints = new Vector<DataPoint>(foundPts.values());
00151 
00152     Vector<Integer> runseriesIds = 
00153         new Vector<Integer>(predictedPlots_.keySet());
00154 
00155     DBManager.getRunSeriesCollectionId(runseriesIds);
00156     setHasData(true);
00157     
00158 
00159     return this;
00160     }
00162 }

Generated Wed Jan 17 09:14:27 GMT 2007