|
[HepData-svn] r1409 - trunk/hepdata-webapp/src/main/java/cedar/hepdata/formatsblackhole at projects.hepforge.org blackhole at projects.hepforge.orgThu Oct 14 14:00:15 BST 2010
Author: whalley Date: Thu Oct 14 14:00:14 2010 New Revision: 1409 Log: adding jhepwork formatter plus small mods to others Added: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/JhepworkFormatter.java Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/BdmsFormatter.java trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/PlainFormatter.java Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/BdmsFormatter.java ============================================================================== --- trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/BdmsFormatter.java Thu Oct 14 13:57:36 2010 (r1408) +++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/BdmsFormatter.java Thu Oct 14 14:00:14 2010 (r1409) @@ -180,9 +180,9 @@ } else { s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getLowValue() + " TO " + ds.getXAxis(nx+1).getBin(i+1).getHighValue()); } - } - } catch(Exception e){ - System.out.println("Exception i=" + i + " nx=" + nx); + } + } catch(Exception e){ + s.append(" " + ds.getXAxis(nx+1).getBin(i+1).getDescription()); } s.append(";"); } Added: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/JhepworkFormatter.java ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/JhepworkFormatter.java Thu Oct 14 14:00:14 2010 (r1409) @@ -0,0 +1,152 @@ +package cedar.hepdata.formats; + +import cedar.hepdata.model.*; +import cedar.hepdata.util.*; +import cedar.hepdata.xml.*; +import cedar.hepdata.db.*; + +import java.util.*; + +import org.antlr.stringtemplate.*; + + +public class JhepworkFormatter { + + + public static String format(Paper p) { + return format(p); + } + + + public static String format(Paper p, Integer xid, Integer yid) { + if (p == null) return null; + return format(p.getDatasets(), xid, yid); + } + + + public static String format(Collection<Dataset> ds) { + StringBuffer s = new StringBuffer(); + for (Dataset d : ds) { + String dstr = format(d); + if (dstr != null) s.append(dstr); + } + return s.toString(); + } + + + public static String format(Collection<Dataset> ds, Integer xid, Integer yid) { + StringBuffer s = new StringBuffer(); + for (Dataset d : ds) { + s.append(format(d, xid, yid)); + } + return s.toString(); + } + + + public static String format(Dataset d) { + return format(d, null, null); + } + + + /** Format a dataset with optional pickiness about which x and y axes to render. */ + public static String format(Dataset d, Integer xid, Integer yid) { + String out = null; + if (d != null) { + StringBuffer s = new StringBuffer(); + for (XAxis x : d.getXAxes()) { +// if (xid == null || x.getId().equals(xid)) { + if (x.getId().equals(1)) { + for (YAxis y : d.getYAxes()) { + if (yid == null || y.getId().equals(yid)) { + s.append(format(x, y)); + s.append("\n"); + } + } + } + } + out = s.toString(); + } + return out; + } + + + public static String format(XAxis x, YAxis y) { + String out = ""; + if (x != null && y != null) { + StringBuffer s = new StringBuffer(); + StringTemplate path = new StringTemplate("/HepData/$paperid$/d$did$-x$xid$-y$yid$"); + Dataset d = x.getDataset(); + path.setAttribute("paperid", d.getPaper().getId()); + path.setAttribute("did", d.getId()); + path.setAttribute("xid", x.getId()); + path.setAttribute("yid", y.getId()); +// s.append("Path: " + path.toString() + "\n"); + s.append("p1=P1D('" + path.toString() + "')" + "\n"); + for (int r = 1; r <= d.getMaxPointId(); ++r) { + StringTemplate row = new StringTemplate(); + String template = "p1.add($xfocus$,$yval$,$xup$,$xdn$,$statup$,$statdn$,$xup$,$xdn$,$systup$,$systdn$);"; + Bin b = x.getBin(r); + Point p = y.getPoint(r); + if (b != null && p != null) { + Double xlow = b.getLowValue(); + Double xhigh = b.getHighValue(); + Double xfocus = b.getFocus(); + Double xup = xhigh - xfocus; + Double xdn = xfocus - xlow; + Double yval = p.getValue(); + Double statdn = null; + Double statup = null; + Double systdn = null; + Double systup = null; + int n = p.getErrors().size(); + if(n > 0) { + int nc = 0; + for (Uncertainty e : p.getErrors()){ + nc += 1; + if(nc == 2) { + systup = 0.0; + systdn = 0.0; + } + try{ + Uncertainty ae = e.getAbsoluteError(p); + if(nc == 1){ + statup = ae.getPlus(); + statdn = ae.getMinus(); + } + else { + systup += ae.getPlus()*ae.getPlus(); + systdn += ae.getMinus()*ae.getMinus(); + } + } catch (HDException hde){ + if(nc == 1) { + statup = null; + statdn = null; + } + } + } + if(systup != null) { systup = Math.sqrt(systup) ; } + if(systdn != null) { systdn = Math.sqrt(systdn) ; } + } + + row.setTemplate(template); + row.setAttribute("xfocus", xfocus); + row.setAttribute("xup", xup); + row.setAttribute("xdn", xdn); + row.setAttribute("yval", yval); + row.setAttribute("statup", statup); + row.setAttribute("statdn", statdn); + row.setAttribute("systup", systup); + row.setAttribute("systdn", systdn); + s.append(row.toString()); + } + s.append("\n"); + } + + + + out = s.toString(); + } + return out; + } + +} Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/PlainFormatter.java ============================================================================== --- trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/PlainFormatter.java Thu Oct 14 13:57:36 2010 (r1408) +++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/PlainFormatter.java Thu Oct 14 14:00:14 2010 (r1409) @@ -141,7 +141,6 @@ row.setAttribute("xlow", xlow); row.setAttribute("xhigh", xhigh); for (int ix=1; ix<x.getDataset().getXAxes().size(); ix++){ - System.out.println("x " + x.getDataset().getXAxis(ix+1).getBin(r).getFocus()); row.setAttribute("val" + Integer.toString(ix),x.getDataset().getXAxis(ix+1).getBin(r).getFocus()); } Double yval = p.getValue();
More information about the HepData-svn mailing list |