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 
00024 public class Data extends Storeable {
00025     private List<Paper> _papers = new Vector<Paper>();
00026     private Date _timestamp = new Date();
00027 
00028 
00030 
00031 
00033     public Data() {}
00034 
00036     public Data(Paper paper) {
00037         addPaper(paper);
00038     }
00039 
00041     public Data(Collection<Paper> papers) {
00042         setPapers(papers);
00043     }
00044 
00045 
00047 
00048 
00050     public List<Paper> getPapers() {
00051         return _papers;
00052     }
00055     public Paper getFirstPaper() {
00056         Paper p = null;
00057         if (!getPapers().isEmpty()) p = getPapers().get(0);
00058         return p;
00059     }
00061     public Data setPapers(Collection<Paper> papers) {
00062         getPapers().clear();
00063         for (Paper p : papers) {
00064             getPapers().add(p);
00065         }
00066         return this;
00067     }
00069     public Data addPaper(Paper paper) {
00070         getPapers().add(paper);
00071         return this;
00072     }
00074     public Data removePaper(Paper paper) {
00075         getPapers().remove(paper);
00076         return this;
00077     }
00078 
00079 
00081     public Date getTimestamp() {
00082         return _timestamp;
00083     }
00085     public Data setTimestamp(Date timestamp) {
00086         _timestamp = timestamp;
00087         return this;
00088     }
00089 
00090 
00092 
00093 
00095     public String toString() {
00096         StringBuffer s = new StringBuffer();
00097         for (Paper p : getPapers()) {
00098             s.append(p.toString());
00099         }
00100         return s.toString();
00101     }
00102 
00103 
00105 
00106 
00108     public static Data makeExample() {
00109         // Have to get a different logger from the inherited one,
00110         // since this is a static method
00111         Logger log = Logger.getLogger(Data.class);
00112 
00113         log.debug("Making data structure...");
00114         Experiment ex = Data.makeExampleExperiment();
00115         Paper p = Data.makeExamplePaper();
00116         Dataset d = Data.makeExampleDataset();
00117         p.addDataset(d);
00118         for (XAxis x : Data.makeExampleXAxes()) d.addXAxis(x);
00119         for (YAxis y : Data.makeExampleYAxes()) d.addYAxis(y);
00120 
00121         log.debug("Making data container...");
00122         Data data = new Data();
00123         data.addPaper(p);
00124 
00125         return data;
00126     }
00127 
00129     public static Experiment makeExampleExperiment() {
00130         Logger log = Logger.getLogger(Data.class);
00131         log.info("Making experiments");
00132         Experiment ex = new Experiment("CDF1").setInformalName("CDF");
00133         ex.setComment("CDF r00ls, D0 sux!");
00134         return ex;
00135     }
00136 
00138     public static Paper makeExamplePaper() {
00139         Logger log = Logger.getLogger(Data.class);
00140         log.info("Making paper");
00141         Paper p = new Paper("My paper", 54635774);
00142         p.addAuthor("Andy");
00143         log.debug("Making reference");
00144         Reference ref = new Reference(RefType.ARXIV, "hep-ph/foobar");
00145         return p;
00146     }
00147 
00149     public static Dataset makeExampleDataset() {
00150         Logger log = Logger.getLogger(Data.class);
00151         log.info("Making dataset");
00152         Dataset d = new Dataset();
00153         d.addComment("My dataset of physics stuff");
00154         return d;
00155     }
00156 
00158     public static Collection<XAxis> makeExampleXAxes() {
00159         Logger log = Logger.getLogger(Data.class);
00160         log.info("Making x-axes");
00161 
00162         log.debug("Making unit for x-axis");
00163         Unit ux1 = Unit.makeGeV();
00164         log.debug("Making x-axis");
00165         XAxis x1 = new XAxis("X1", ux1).setId(1);
00166 
00167         log.info("Adding bins to x-axis");
00168         x1.addBin(new Bin(0.0));
00169         x1.addBin(new Bin(0.2));
00170         x1.addBin(new Bin(0.4));
00171         x1.addBin(new Bin(0.6));
00172         x1.addBin(new Bin(0.8));
00173 
00174         List<XAxis> xAxes = new Vector<XAxis>();
00175         xAxes.add(x1);
00176         return xAxes;
00177     }
00178 
00180     public static Collection<YAxis> makeExampleYAxes() {
00181         Logger log = Logger.getLogger(Data.class);
00182         log.info("Making y-axes");
00183 
00184         log.debug("Making units for y-axes");
00185         Unit uy1a = new Unit(new UnitTerm(BaseUnit.BARN, SiPrefix.NANO, -1));
00186         Unit uy1b = new Unit(new UnitTerm(BaseUnit.RADIAN, SiPrefix.MILLI, 1));
00187         log.debug("Making observables for y-axes");
00188         Observable o1a = new Observable("Random 1", uy1a.canonicalUnit());
00189         Observable o1b = new Observable("Random 2", uy1b);
00190         log.debug("Making y-axis 1");
00191         YAxis y1a = new YAxis(o1a, "Y1a", uy1a).setId(2);
00192         log.debug("Making y-axis 2");
00193         YAxis y1b = new YAxis(o1b, "Y1b", uy1b).setId(1);
00194 
00195         log.info("Adding points to the y-axes");
00196         log.debug("Adding points to y-axis 1");
00197         y1a.addPoint(new Point(1.0));
00198         y1a.addPoint(new Point(2.0));
00199         y1a.addPoint(new Point(4.0));
00200         y1a.addPoint(new Point(2.0));
00201         y1a.addPoint(new Point(1.0));
00202         log.debug("Adding points to y-axis 2");
00203         y1b.addPoint(new Point(1.0));
00204         y1b.addPoint(new Point(2.0));
00205         y1b.addPoint(new Point(3.0));
00206         y1b.addPoint(new Point(4.0));
00207         y1b.addPoint(new Point(5.0));
00208 
00209         y1a.addError(new AxisError(Math.random(), ErrorSource.SYS, ErrorNorm.FRAC));
00210         y1b.addError(new AxisError(100 * Math.random(), ErrorSource.UNKNOWN, ErrorNorm.PCT));
00211 
00212         for (Point p : y1a.getPoints()) {
00213             PointError pe = new PointError(p, Math.random(), ErrorSource.STAT, ErrorNorm.FRAC);
00214         }
00215         for (Point p : y1b.getPoints()) {
00216             PointError pe = new PointError(p, 100 * Math.random(), 100 * Math.random(), ErrorSource.STAT, ErrorNorm.PCT);
00217         }
00218 
00219         List<YAxis> yAxes = new Vector<YAxis>();
00220         yAxes.add(y1a);
00221         yAxes.add(y1b);
00222         return yAxes;
00223     }
00224 
00225 
00226 }

Generated on Thu Sep 20 11:41:37 2007 by  doxygen 1.5.3