Data.java

Go to the documentation of this file.
00001 package cedar.hepdata.model;
00002 
00003 import java.util.Collection;
00004 import java.util.List;
00005 import java.util.Vector;
00006 import java.util.Date;
00007 
00008 import cedar.hepdata.util.*;
00009 
00010 import javax.persistence.*;
00011 
00012 import org.apache.log4j.*;
00013 
00014 
00025 public class Data extends Storeable {
00026     private List<Paper> _papers = new Vector<Paper>();
00027     private Date _timestamp = new Date();
00028 
00029 
00031 
00032 
00034     public Data() {}
00035 
00037     public Data(Paper paper) {
00038         addPaper(paper);
00039     }
00040 
00042     public Data(Collection<Paper> papers) {
00043         setPapers(papers);
00044     }
00045 
00046 
00048 
00049 
00051     public List<Paper> getPapers() {
00052         return _papers;
00053     }
00056     public Paper getFirstPaper() {
00057         Paper p = null;
00058         if (!getPapers().isEmpty()) p = getPapers().get(0);
00059         return p;
00060     }
00062     public Data setPapers(Collection<Paper> papers) {
00063         getPapers().clear();
00064         for (Paper p : papers) {
00065             getPapers().add(p);
00066         }
00067         return this;
00068     }
00070     public Data addPaper(Paper paper) {
00071         getPapers().add(paper);
00072         return this;
00073     }
00075     public Data removePaper(Paper paper) {
00076         getPapers().remove(paper);
00077         return this;
00078     }
00079 
00080 
00082     public Date getTimestamp() {
00083         return _timestamp;
00084     }
00086     public Data setTimestamp(Date timestamp) {
00087         _timestamp = timestamp;
00088         return this;
00089     }
00090 
00091 
00093 
00094 
00096     public String toString() {
00097         StringBuffer s = new StringBuffer();
00098         for (Paper p : getPapers()) {
00099             s.append(p.toString());
00100         }
00101         return s.toString();
00102     }
00103 
00104 
00106 
00107 
00109     public static Data makeExample() {
00110         // Have to get a different logger from the inherited one,
00111         // since this is a static method
00112         Logger log = Logger.getLogger(Data.class);
00113 
00114         log.debug("Making data structure...");
00115         Experiment ex = Data.makeExampleExperiment();
00116         Paper p = Data.makeExamplePaper();
00117         Dataset d = Data.makeExampleDataset();
00118         p.addDataset(d);
00119         for (XAxis x : Data.makeExampleXAxes()) d.addXAxis(x);
00120         for (YAxis y : Data.makeExampleYAxes()) d.addYAxis(y);
00121 
00122         log.debug("Making data container...");
00123         Data data = new Data();
00124         data.addPaper(p);
00125 
00126         return data;
00127     }
00128 
00130     public static Experiment makeExampleExperiment() {
00131         Logger log = Logger.getLogger(Data.class);
00132         log.info("Making experiments");
00133         Experiment ex = new Experiment("CDF1").setInformalName("CDF");
00134         ex.setComment("CDF r00ls, D0 sux!");
00135         return ex;
00136     }
00137 
00139     public static Paper makeExamplePaper() {
00140         Logger log = Logger.getLogger(Data.class);
00141         log.info("Making paper");
00142         Paper p = new Paper("My paper", 54635774);
00143         p.addAuthor("Andy");
00144         log.debug("Making reference");
00145         Reference ref = new Reference(RefType.ARXIV, "hep-ph/foobar");
00146         return p;
00147     }
00148 
00150     public static Dataset makeExampleDataset() {
00151         Logger log = Logger.getLogger(Data.class);
00152         log.info("Making dataset");
00153         Dataset d = new Dataset();
00154         d.addComment("My dataset of physics stuff");
00155         return d;
00156     }
00157 
00159     public static Collection<XAxis> makeExampleXAxes() {
00160         Logger log = Logger.getLogger(Data.class);
00161         log.info("Making x-axes");
00162 
00163         log.debug("Making unit for x-axis");
00164         Unit ux1 = Unit.makeGeV();
00165         log.debug("Making x-axis");
00166         XAxis x1 = new XAxis("X1", ux1).setId(1);
00167 
00168         log.info("Adding bins to x-axis");
00169         double bincentres[] = { 0.0, 0.2, 0.4, 0.6, 0.8 };
00170         x1.setBins(bincentres);
00171 
00172         List<XAxis> xAxes = new Vector<XAxis>();
00173         xAxes.add(x1);
00174         return xAxes;
00175     }
00176 
00178     public static Collection<YAxis> makeExampleYAxes() {
00179         Logger log = Logger.getLogger(Data.class);
00180         log.info("Making y-axes");
00181 
00182         log.debug("Making units for y-axes");
00183         Unit uy1a = new Unit(new UnitTerm(BaseUnit.BARN, SiPrefix.NANO, -1));
00184         Unit uy1b = new Unit(new UnitTerm(BaseUnit.RADIAN, SiPrefix.MILLI, 1));
00185         log.debug("Making y-axis 2");
00186         YAxis y1a = new YAxis("Y1a", "RandomObs2", uy1a).setId(2);
00187         log.debug("Making y-axis 1");
00188         YAxis y1b = new YAxis("Y1b", "RandomObs1", uy1b).setId(1);
00189 
00190         log.info("Adding points to the y-axes");
00191         log.debug("Adding points to y-axis 1");
00192         double pointvals1[] = { 1.0, 2.0, 4.0, 2.0, 1.0 };
00193         y1a.setPoints(pointvals1);
00194         log.debug("Adding points to y-axis 2");
00195         double pointvals2[] = { 1.0, 2.0, 3.0, 4.0, 5.0 };
00196         y1b.setPoints(pointvals2);
00197 
00198         y1a.addError(new AxisError(Math.random(), ErrorSource.SYS, ErrorNorm.FRAC));
00199         y1b.addError(new AxisError(100 * Math.random(), ErrorSource.UNKNOWN, ErrorNorm.PCT));
00200 
00201         for (Point p : y1a.getPoints()) {
00202             PointError pe = new PointError(p, Math.random(), ErrorSource.STAT, ErrorNorm.FRAC);
00203         }
00204         for (Point p : y1b.getPoints()) {
00205             PointError pe = new PointError(p, 100 * Math.random(), 100 * Math.random(), ErrorSource.STAT, ErrorNorm.PCT);
00206         }
00207 
00208         List<YAxis> yAxes = new Vector<YAxis>();
00209         yAxes.add(y1a);
00210         yAxes.add(y1b);
00211         return yAxes;
00212     }
00213 
00214 
00215 }

Generated on Tue Apr 21 15:54:38 2009 for HepData object model by  doxygen 1.5.5