ViewDataset.java

Go to the documentation of this file.
00001 package cedar.hepdata.webapp.pages.dataset;
00002 
00003 import cedar.hepdata.model.*;
00004 import cedar.hepdata.util.*;
00005 import cedar.hepdata.xml.*;
00006 import cedar.hepdata.db.*;
00007 
00008 import org.apache.tapestry5.StreamResponse;
00009 import org.apache.tapestry5.util.TextStreamResponse;
00010 import org.apache.tapestry5.annotations.*;
00011 import org.apache.tapestry5.ioc.annotations.*;
00012 import org.apache.tapestry5.services.*;
00013 
00014 import org.hibernate.*;
00015 import org.hibernate.criterion.*;
00016 import java.util.*;
00017 
00018 import org.antlr.stringtemplate.*;
00019 
00020 
00021 public class ViewDataset {
00022 
00023     @Inject
00024     private RequestGlobals _reqGlobals;
00025 
00026     @Inject
00027     private org.hibernate.Session _session;
00028 
00029 
00030     public StreamResponse onYODA() {
00031         String asYODA = "No valid paper and dataset specified";
00032 
00033         Dataset ds = getDataset();
00034         if (ds != null) {
00035             StringBuffer s = new StringBuffer();
00036             for (XAxis x : ds.getXAxes()) {
00037                 for (YAxis y : ds.getYAxes()) {
00038                     StringTemplate path = new StringTemplate("/HepData/$paperid$/d$did$-x$xid$-y$yid$");
00039                     path.setAttribute("paperid", ds.getPaper().getId());
00040                     path.setAttribute("did", ds.getId());
00041                     path.setAttribute("xid", x.getId());
00042                     path.setAttribute("yid", y.getId());
00043                     s.append("BEGIN HISTO1D "  + path.toString());
00044                     for (int r = 0; r < ds.numPoints(); ++r) {
00045                         StringTemplate row = new StringTemplate("$xlow$\t$xhigh$\t$yval$\t$yerr$");
00046                         Bin b = x.getBin(r);
00047                         Point p = y.getPoint(r);
00048                         if (b != null) {
00049                             Double xlow = null;
00050                             Double xhigh = null;
00051                             if (b.getLowValue() != null) {
00052                                 xlow = b.getLowValue();
00053                                 xhigh = b.getHighValue();
00054                             } else {
00055                                 Double xval = b.getFocus();
00056                                 Double xwidth = b.getWidth();
00057                                 if (xval != null) {
00058                                     xlow = xval;
00059                                     xhigh = xval;
00060                                     if (xwidth != null) {
00061                                         xlow -= xwidth/2.0;
00062                                         xhigh += xwidth/2.0;
00063                                     }
00064                                 }
00065                             }
00066                             row.setAttribute("xlow", xlow);
00067                             row.setAttribute("xhigh", xhigh);
00068                         }
00069                         if (p != null) {
00070                             row.setAttribute("yval", p.getValue());
00071                             double yerr = 0.0;
00072                             if (!p.getErrors().isEmpty()) {
00073                                 try {
00074                                     yerr = p.getErrors().first().getAbsoluteError().getPlusMinus();
00075                             } catch (HDException e) {
00076                                     //
00077                                 }
00078                             }
00079                             row.setAttribute("yerr", yerr);
00080                         }
00081                         s.append(row.toString() + "\n");
00082                     }
00083                     s.append("END HISTO1D " + "\n\n\n");
00084                 }
00085             }
00086             asYODA = s.toString();
00087         }
00088 
00089         return new TextStreamResponse("text/plain", asYODA);
00090     }
00091 
00092 
00093     public StreamResponse onAIDA() {
00094         return new TextStreamResponse("text/plain", "This will be AIDA once I get round to it...");
00095     }
00096 
00097 
00098     public StreamResponse onROOT() {
00099         return new TextStreamResponse("text/plain", "This will be a ROOT macro once I get round to it...");
00100     }
00101 
00102 
00104 
00105 
00106     public String getQueryParam(String param){
00107        return _reqGlobals.getRequest().getParameter(param);
00108     }
00109 
00110 
00111     private Query constructQuery() {
00112         String theIrn = getQueryParam("irn");
00113         String thePaper = getQueryParam("p");
00114         String theDataset = getQueryParam("d");
00115 
00116         // Assuming a paper ID search first, falling back to Spires ID search
00117         Query q = null;
00118         StringBuffer qs = new StringBuffer("select distinct d from Paper p join p._datasets d where d._localId = :did ");
00119         if (thePaper != null) {
00120             qs.append("and p._id = :pid");
00121             q = _session.createQuery(qs.toString());
00122             q.setString("pid", thePaper);
00123         } else if (theIrn != null) {
00124             qs.append("and p._spiresId = :irn");
00125             q = _session.createQuery(qs.toString());
00126             q.setString("irn", theIrn);
00127         }
00128         q.setString("did", theDataset);
00129         return q;
00130     }
00131 
00132 
00133     public Dataset getDataset(){
00134         Dataset ds = (Dataset) constructQuery().uniqueResult();
00135         return ds;
00136     }
00137 
00138 
00139 }

Generated on Tue Apr 21 15:55:00 2009 for HepData Web servlets by  doxygen 1.5.5