[HepData-svn] r1494 - trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Fri Dec 9 12:55:56 GMT 2011


Author: whalley
Date: Fri Dec  9 12:55:56 2011
New Revision: 1494

Log:
improvements to Plain formatter

Modified:
   trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/PlainFormatter.java

Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/PlainFormatter.java
==============================================================================
--- trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/PlainFormatter.java	Wed Nov 30 10:55:24 2011	(r1493)
+++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/PlainFormatter.java	Fri Dec  9 12:55:56 2011	(r1494)
@@ -11,7 +11,7 @@
 import org.antlr.stringtemplate.*;
 
 
-public class PlainFormatter {
+public class Plain2Formatter {
 
 
     public static String format(Paper p) {
@@ -57,8 +57,10 @@
             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)) {
+//                   for (YAxis y : d.getYAxes()) {
+                    if (d.getYAxes().size()>0) {
+                         YAxis y = d.getYAxis(1);
+                         if (yid == null || y.getId().equals(yid)) {
                             s.append(format(x, y));
                             s.append("\n");
                         }
@@ -85,31 +87,86 @@
             for (String c : x.getDataset().getComments()) {
                 s.append(c + "\n");
             }
-            for (String c : y.getComments()) {
-                s.append(c + "\n");
-            }
-            for (Property p : y.getProperties()) {
-                /// @todo Do better matching on "SQRT(S)" etc.
-                if (! p.getName().toLowerCase().equals("sqrts")) {
-                    s.append(p.getName() + " : ");
-                    if (p.getLowValue() != null && p.getHighValue() != null &&
-                        p.getLowValue().equals(p.getHighValue())) {
-                        s.append(p.getLowValue().toString());
-                    } else {
-                        s.append(p.getLowValue().toString() + " - " + p.getHighValue().toString());
+            int nstore = d.getYAxis(1).getComments().size() + d.getYAxis(1).getProperties().size();
+            String[][] store = new String[d.getYAxes().size()][nstore];
+
+            boolean hassqrt = false;
+            for (int ny=1; ny<=d.getYAxes().size(); ny++ ) {
+                List <String> storelist = new ArrayList();
+                for (String c : d.getYAxis(ny).getComments()) {
+                    storelist.add(c);
+                }
+                Collections.sort(storelist);
+                for(int i=0; i<storelist.size(); i++){
+                    store[ny-1][i]=storelist.get(i);
+                }
+//                storelist.clear();
+//            }
+//
+//
+//            for (int ny=1; ny<=d.getYAxes().size(); ny++ ) {
+//                List <String> storelist = new ArrayList();
+                for (Property p : d.getYAxis(ny).getProperties()) {
+                    /// @todo Do better matching on "SQRT(S)" etc.
+                    String str = "";
+                    if (! p.getName().toLowerCase().equals("sqrts")) {
+                        str.concat(p.getName() + " : ");
+                        if (p.getLowValue() != null && p.getHighValue() != null &&
+                            p.getLowValue().equals(p.getHighValue())) {
+                            str.concat(p.getLowValue().toString());
+                        } else {
+                            str.concat(p.getLowValue().toString() + " - " + p.getHighValue().toString());
+                        }
+                        if (!p.getUnit().isDimensionless()) {
+                            str.concat(" " + p.getUnit().toString());
+                        }
+                        storelist.add(str);
                     }
-                    if (!p.getUnit().isDimensionless()) {
-                        s.append(" " + p.getUnit().toString());
+                    else {
+                        hassqrt = true;    
+                    }       
+             
+                }
+                Collections.sort(storelist);
+                for(int i=0; i<storelist.size(); i++){
+                    store[ny-1][i]=storelist.get(i);
+                }
+                storelist.clear();
+            }
+
+            if(hassqrt) { nstore -= 1; }
+            for(int i=0; i<nstore; i++){
+                s.append(store[0][i]);
+                for (int ny=2; ny<=d.getYAxes().size(); ny++ ) {
+                    if(!store[ny-1][i].equals(store[0][i])){
+                        s.append(" " + store[ny-1][i].substring(store[ny-1][i].indexOf(":")));
                     }
-                    s.append("\n");
                 }
+                s.append("\n");
             }
+
             s.append("x: " + x.getHeader() + "\n");
             for (int ix=1; ix<x.getDataset().getXAxes().size(); ix++){
                 s.append("x" + Integer.toString(ix+1) + ": " + x.getDataset().getXAxis(ix+1).getHeader() + "\n");
             } 
-            s.append("y: " + y.getHeader() + "\n");
-//            s.append("\n");
+            s.append("y");
+            
+            boolean allsame = true;
+            if(d.getYAxis(1).getHeader() != null && !d.getYAxis(1).getHeader().equals("")){
+                String test = d.getYAxis(1).getHeader();
+                for (int ny=2; ny<=d.getYAxes().size(); ny++ ) {
+                    if(!d.getYAxis(ny).getHeader().equals(test)) {  allsame = false; }
+                }
+            }
+            if(allsame){
+                s.append(" : " + d.getYAxis(1).getHeader());
+            } 
+            else {
+                for (int ny=1; ny<=d.getYAxes().size(); ny++ ) {
+                    s.append(" : " + d.getYAxis(ny).getHeader());
+                }
+            }
+            s.append("\n");
 
             // Column key
             
@@ -118,10 +175,12 @@
             s.append("xlow\t");
             s.append("xhigh\t");
             for (int ix=1; ix<x.getDataset().getXAxes().size(); ix++){s.append("x" + Integer.toString(ix+1) + "\t");} 
-            s.append("y\t");
-            for (int e = 0; e < numyerrs; ++e) {
-                s.append("dy+\tdy-\t");
-            }
+            for ( YAxis yax : d.getYAxes()){
+               s.append("y\t");
+               for (int e = 0; e < yax.getPoints().first().getErrors().size(); ++e) {
+                   s.append("dy+\tdy-\t");
+               }
+            }   
             s.append("\n");
 
             for (int r = 1; r <= d.getMaxPointId(); ++r) {
@@ -137,7 +196,7 @@
                     for (int ix=1; ix<x.getDataset().getXAxes().size(); ix++){
                         template=template.concat("\t$val" + Integer.toString(ix) + "$");
                     } 
-                    template=template.concat("\t$yval$");
+//                    template=template.concat("\t$yval$");
                     row.setTemplate(template);
                     row.setAttribute("xfocus", xfocus);
                     row.setAttribute("xlow", xlow);
@@ -145,10 +204,14 @@
                     for (int ix=1; ix<x.getDataset().getXAxes().size(); ix++){
                         row.setAttribute("val" + Integer.toString(ix),x.getDataset().getXAxis(ix+1).getBin(r).getFocus());
                     } 
-                    Double yval = p.getValue();
-                    row.setAttribute("yval", yval);
                     s.append(row.toString());
-                    for (Uncertainty e : p.getErrors()) {
+                    for (int ny=1; ny<=p.getYAxis().getDataset().getYAxes().size(); ny++ ) {
+                    try {
+                        Double yval = p.getYAxis().getDataset().getYAxis(ny).getPoint(r).getValue();
+                  //  Double yval = p.getValue();
+                        s.append("\t" + yval); 
+//                    row.setAttribute("yval", yval);
+                        for (Uncertainty e : p.getYAxis().getDataset().getYAxis(ny).getPoint(r).getErrors()) {
                         try {
                             Uncertainty ae = e.getAbsoluteError(p);
                             if(ae.isSymmetricReversed()){
@@ -189,7 +252,9 @@
                             s.append("\t+?\t?");
                         }
                     }
-                    s.append("\n");
+                    } catch (Exception  ex) { s.append("\t-"); }
+                  }
+                  s.append("\n");
                 }
             }
             out = s.toString();


More information about the HepData-svn mailing list