|
[HepData-svn] r1859 - in trunk/hepdata-webapp/src/main/java/cedar/hepdata: formats webapp/pagesblackhole at projects.hepforge.org blackhole at projects.hepforge.orgTue May 5 19:07:41 BST 2015
Author: watt Date: Tue May 5 19:07:41 2015 New Revision: 1859 Log: Added variant of YODA formatter with only statistical uncertainties Added: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YodaStatFormatter.java Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YodaFormatter.java trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/View.java Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YodaFormatter.java ============================================================================== --- trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YodaFormatter.java Tue Apr 28 15:37:46 2015 (r1858) +++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YodaFormatter.java Tue May 5 19:07:41 2015 (r1859) @@ -76,7 +76,7 @@ Bin b = x.getBin(r); Point p = y.getPoint(r); if (b != null && p != null) { - Double focus = b.getFocus(); + Double focus = b.getFocus(); row.setAttribute("focus", focus); Double dplus = b.getDPlus(); row.setAttribute("dplus", dplus); Added: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YodaStatFormatter.java ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YodaStatFormatter.java Tue May 5 19:07:41 2015 (r1859) @@ -0,0 +1,114 @@ +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 YodaStatFormatter { + + static public String _padId(Integer id) { + StringBuffer s = new StringBuffer(); + if (id < 10) s.append(0); + s.append(id); + return s.toString(); + } + + public static String format(Paper p,String stype) { + if (p == null) return null; + return format(p.getDatasets(),stype); + } + + + public static String format(Collection<Dataset> ds,String stype) { + StringBuffer s = new StringBuffer(); + for (Dataset d : ds) { + String dstr = YodaStatFormatter.format(d,stype); + if (dstr != null) s.append(dstr); + } + return s.toString(); + } + + + public static String format(Dataset d,String stype) { + String asYODAstat = null; + try { + if (d != null) { + StringBuffer s = new StringBuffer(); + Paper pp = d.getPaper(); + String expts = ""; + for (Experiment e : pp.getExperiments()){ + expts += e.getInformalName().toUpperCase() + "_"; + } + if (expts.length() == 0) expts = "EXPT_"; + String year = "XXXX"; + for (Reference ref : pp.getReferences()) { + year = ref.getDate(); + if (ref.getType().equals("JOUR")) break; + } + StringTemplate t_pname = new StringTemplate("$expts$$year$_$inspireId$"); + t_pname.setAttribute("expts", expts); + t_pname.setAttribute("year", year); + if(stype.equals("i")) { t_pname.setAttribute("inspireId", "I"+d.getPaper().getInspireId()); } + else if (stype.equals("s")) { t_pname.setAttribute("inspireId", "S"+d.getPaper().getSpiresId()); } + else { t_pname.setAttribute("inspireId", "0000000"); } + String pname = t_pname.toString(); + + for (XAxis x : d.getXAxes()) { + for (YAxis y : d.getYAxes()) { + StringTemplate path = new StringTemplate("/REF/"+pname+"/d$did$-x$xid$-y$yid$"); + + path.setAttribute("paperid", d.getPaper().getId()); + path.setAttribute("did", _padId(d.getId())); + path.setAttribute("xid", _padId(x.getId())); + path.setAttribute("yid", _padId(y.getId())); + s.append("# BEGIN YODA_SCATTER2D " + path.toString() + "\n"); + s.append("Path=" + path.toString() + "\n"); + s.append("Type=Scatter2D\n"); + s.append("# xval xerr- xerr+ yval yerr- yerr+\n"); + for (int r = 1; r <= d.getMaxPointId(); ++r) { + StringTemplate row = new StringTemplate("$focus$\t$dminus$\t$dplus$\t$xlow$\t$xhigh$\t$yval$\t$yerrminus$\t$yerrplus$"); + Bin b = x.getBin(r); + Point p = y.getPoint(r); + if (b != null && p != null) { + Double focus = b.getFocus(); + row.setAttribute("focus", focus); + Double dplus = b.getDPlus(); + row.setAttribute("dplus", dplus); + Double dminus = b.getDMinus(); + row.setAttribute("dminus", dminus); + Double yval = p.getValue(); + String ydesc = p.getDescription(); + if (ydesc != null) { + row.setAttribute("yval", p.getDescription()); + } + else { + row.setAttribute("yval", p.getValue()); + } + //Double yerrminus = p.getQuadCombinedMinusError(); + Double yerrminus = p.getStatMinusError(); + row.setAttribute("yerrminus", yerrminus); + //Double yerrplus = p.getQuadCombinedPlusError(); + Double yerrplus = p.getStatPlusError(); + row.setAttribute("yerrplus", yerrplus); + } + s.append(row.toString() + "\n"); + } + s.append("# END YODA_SCATTER2D " + "\n\n\n"); + } + } + asYODAstat = s.toString(); + } + } catch (NullPointerException npe) { + asYODAstat = "# Can't render this plot, due to missing/incompatible information\n\n"; + } + + return asYODAstat; + } + +} Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/View.java ============================================================================== --- trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/View.java Tue Apr 28 15:37:46 2015 (r1858) +++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/View.java Tue May 5 19:07:41 2015 (r1859) @@ -42,7 +42,7 @@ parseBaseViewContext(context); // Handle pattern parsing separately - Pattern patt = Pattern.compile("\\A" + "(short|long|full|plain.txt|yoda|aida|pyroot.py|root|mpl|bdms|hepml|scavis.py|input|marcxml|json|yaml)" + "\\Z", + Pattern patt = Pattern.compile("\\A" + "(short|long|full|plain.txt|yoda|yodastat|aida|pyroot.py|root|mpl|bdms|hepml|scavis.py|input|marcxml|json|yaml)" + "\\Z", Pattern.CASE_INSENSITIVE); Pattern patt2 = Pattern.compile("\\A" + "(irn\\d+)" + "\\Z",Pattern.CASE_INSENSITIVE); String stype = "i"; @@ -74,6 +74,7 @@ if (fmt.equals("aida")) return asAIDA(stype); if (fmt.equals("pyroot.py")) return asPyROOT(); if (fmt.equals("yoda")) return asYODA(stype); + if (fmt.equals("yodastat")) return asYODAstat(stype); if (fmt.equals("root")) return asROOT(); if (fmt.equals("mpl")) return asMatplotlib(); //if (fmt.equals("gnuplot")) return asPlain(); @@ -209,6 +210,19 @@ } + public Object getYodaStatContext() { + return formatContext("yodastat"); + } + public StreamResponse asYODAstat(String stype) { + Set<Dataset> ds = getDatasets(); + String asYODAstat = YodaStatFormatter.format(ds,stype); + if (asYODAstat == null) { + asYODAstat = "No valid paper and dataset specified"; + } + return new TextStreamResponse("text/plain", asYODAstat); + } + + public Object getAidaContext() { return formatContext("aida"); }
More information about the HepData-svn mailing list |