Print

Print


Commit in GeomConverter on MAIN
resources/META-INF/services/org.lcsim.geometry.compact.converter.Converter+11.4 -> 1.5
src/org/lcsim/geometry/compact/converter/html/HtmlConverter.java+355added 1.1
                                             /Main.java+89added 1.1
+445
2 added + 1 modified, total 3 files
first version of compact to html converter

GeomConverter/resources/META-INF/services
org.lcsim.geometry.compact.converter.Converter 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- org.lcsim.geometry.compact.converter.Converter	18 Dec 2009 19:32:16 -0000	1.4
+++ org.lcsim.geometry.compact.converter.Converter	4 Jan 2011 21:59:12 -0000	1.5
@@ -2,3 +2,4 @@
 org.lcsim.geometry.compact.converter.lcdd.Main
 org.lcsim.geometry.compact.converter.GODL.Main
 org.lcsim.geometry.compact.converter.pandora.Main
+org.lcsim.geometry.compact.converter.html.Main
\ No newline at end of file

GeomConverter/src/org/lcsim/geometry/compact/converter/html
HtmlConverter.java added at 1.1
diff -N HtmlConverter.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HtmlConverter.java	4 Jan 2011 21:59:13 -0000	1.1
@@ -0,0 +1,355 @@
+package org.lcsim.geometry.compact.converter.html;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.jdom.Element;
+import org.lcsim.geometry.Calorimeter;
+import org.lcsim.geometry.compact.Constant;
+import org.lcsim.geometry.compact.Detector;
+import org.lcsim.geometry.compact.Field;
+import org.lcsim.geometry.compact.Header;
+import org.lcsim.geometry.compact.Segmentation;
+import org.lcsim.geometry.compact.Subdetector;
+import org.lcsim.geometry.field.Solenoid;
+import org.lcsim.geometry.subdetector.AbstractLayeredSubdetector;
+
+/**
+ * Convert a compact description to an html information page.
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: HtmlConverter.java,v 1.1 2011/01/04 21:59:13 jeremy Exp $
+ */
+// TODO add css
+public class HtmlConverter
+{
+    private HtmlConverter()
+    {}
+
+    public static Element convert( Detector d )
+    {
+        // Convert to specific subclass for more method access.
+        Detector detector = ( org.lcsim.geometry.compact.Detector ) d;
+
+        // Root element.
+        Element root = new Element( "html" );
+
+        // Header.
+        Element head = new Element( "head" );
+        String detectorName = detector.getName();
+        Element title = new Element( "title" );
+        title.setText( detectorName );
+        head.addContent( title );
+        root.addContent( head );
+
+        // Body.
+        Element body = new Element( "body" );
+        root.addContent( body );
+
+        // Layout table.
+        Element tbl = new Element( "table" );
+        tbl.setAttribute( "cellspacing", "25" );
+        tbl.setAttribute( "width", "100%" );
+        body.addContent( tbl );
+
+        // Layout row.
+        Element td = addLayoutRow( tbl );
+
+        // Add detector header.
+        detectorHeader( td, detector );
+
+        // Layout row.
+        td = addLayoutRow( tbl );
+
+        // Links to defines and fields at bottom of page.
+        Element p = new Element( "p" );
+        p.addContent( new Link( "Go to Constants", "#defines" ) );
+        td.addContent( p );
+        p = new Element( "p" );
+        p.addContent( new Link( "Go to Fields", "#fields" ) );
+        td.addContent( p );
+
+        // Sort subdetectors alphabetically.
+        List<String> subdets = new ArrayList<String>();
+        subdets.addAll( detector.getSubdetectors().keySet() );
+        java.util.Collections.sort( subdets );
+
+        // Layout row.
+        td = addLayoutRow( tbl );
+
+        // Add subdetector index.
+        subdetectorIndex( td, detector, subdets );
+
+        // Header.
+        addHeader2( td, "Subdetector Details" );
+
+        // Add subdetectors.
+        for ( String subdetName : subdets )
+        {
+            // Layout row.
+            td = addLayoutRow( tbl );
+
+            // Add subdetector info.
+            subdetector( td, detector.getSubdetector( subdetName ) );
+        }
+
+        // Layout row.
+        td = addLayoutRow( tbl );
+
+        // Constants.
+        defines( td, detector );
+
+        // Layout row.
+        td = addLayoutRow( tbl );
+
+        // Fields.
+        fields( td, detector );
+
+        return root;
+    }
+
+    private static void subdetectorIndex( Element parent, Detector detector, List<String> names )
+    {
+        // Header.
+        addHeader2( parent, "Subdetector Table" );
+
+        // Table.
+        Element tbl = new Element( "table" );
+        tbl.setAttribute( "border", "1" );
+        tbl.setAttribute( "cellpadding", "2" );
+        parent.addContent( tbl );
+
+        // todo: addHeaderRow method
+        addRow( tbl, new Element( "b" ).setText( "Subdetector" ), new Element( "b" ).setText( "Readout" ), new Element( "b" ).setText( "System ID" ) );
+
+        for ( String subdetName : names )
+        {
+            Subdetector subdet = detector.getSubdetector( subdetName );
+            String readoutName = "-";
+            if ( subdet.getReadout() != null )
+            {
+                readoutName = subdet.getReadout().getName();
+            }
+
+            addRow( tbl, new Link( subdetName, "#" + subdetName ), readoutName, subdet.getSystemID() );
+        }
+    }
+
+    private static void detectorHeader( Element parent, Detector detector )
+    {
+        addHeader2( parent, "Summary" );
+
+        Element tbl = new Element( "table" );
+        tbl.setAttribute( "border", "1" );
+        tbl.setAttribute( "cellpadding", "2" );
+        parent.addContent( tbl );
+
+        Header header = detector.getHeader();
+
+        addLabeledRow( tbl, "Detector", detector.getName() );
+        addLabeledRow( tbl, "Title", header.getTitle() );
+        addLabeledRow( tbl, "Comment", header.getComment() );
+        addLabeledRow( tbl, "Author", header.getAuthor() );
+        addLabeledRow( tbl, "Status", header.getStatus() );
+        addLabeledRow( tbl, "Version", header.getVersion() );
+        addLabeledRow( tbl, "Documentation", new Link( header.getURL() ) );
+        addLabeledRow( tbl, "Zip File", new Link( "http://www.lcsim.org/detectors/" + detector.getName() + ".zip" ) );
+    }
+
+    private static void subdetector( Element parent, Subdetector subdet )
+    {
+        // Make bookmark in page.
+        bookmark( parent, subdet.getName() );
+
+        // Subdetector data table.
+        Element tbl = new Element( "table" );
+        tbl.setAttribute( "border", "1" );
+        tbl.setAttribute( "width", "80%" );
+        tbl.setAttribute( "cellpadding", "2" );
+        parent.addContent( tbl );
+
+        // Basic info.
+        addLabeledRow( tbl, "Subdetector", subdet.getName() );
+        addLabeledRow( tbl, "System ID", subdet.getSystemID() );
+        addLabeledRow( tbl, "Type", subdet.isCalorimeter() ? "Calorimeter" : "Tracker" );
+        addLabeledRow( tbl, "Class", subdet.getClass().getSimpleName() );
+        addLabeledRow( tbl, "Endcap", subdet.isEndcap() ? true : false );
+        addLabeledRow( tbl, "Readout", subdet.getReadout() != null ? subdet.getReadout().getName() : "NONE" );
+        addLabeledRow( tbl, "Tracking Vol", subdet.isInsideTrackingVolume() );
+        addLabeledRow( tbl, "ID Description", subdet.getReadout() != null ? subdet.getIDDecoder().getIDDescription().toString() : "NONE" );
+
+        if ( subdet instanceof AbstractLayeredSubdetector )
+        {
+            AbstractLayeredSubdetector layers = ( AbstractLayeredSubdetector ) subdet;
+
+            addLabeledRow( tbl, "Number Of Layers", layers.getNumberOfLayers() );
+            addLabeledRow( tbl, "Interaction Lengths", layers.getInteractionLengths() );
+            addLabeledRow( tbl, "Radiation Lengths", layers.getRadiationLengths() );
+        }
+
+        // Calorimeter info.
+        if ( subdet instanceof Calorimeter )
+        {
+            Calorimeter cal = ( Calorimeter ) subdet;
+            addLabeledRow( tbl, "Calorimeter Type", cal.getCalorimeterType().toString() );
+            addLabeledRow( tbl, "Number Of Sides", cal.getNumberOfSides() );
+            addLabeledRow( tbl, "Inner Radius", cal.getInnerRadius() + " mm" );
+            addLabeledRow( tbl, "Outer Radius", cal.getOuterRadius() + " mm" );
+            addLabeledRow( tbl, "Z Length", cal.getZLength() + " mm" );
+            addLabeledRow( tbl, "Inner Z", cal.getInnerZ() + " mm" );
+            addLabeledRow( tbl, "Outer Z", cal.getOuterZ() + " mm" );
+            addLabeledRow( tbl, "Section Phi", cal.getSectionPhi() + " radians" );
+            if ( subdet.getReadout() != null && subdet.getReadout().getIDDecoder() instanceof Segmentation )
+            {
+                Segmentation seg = ( Segmentation ) subdet.getReadout().getIDDecoder();
+                addLabeledRow( tbl, "Segmentation Type", seg.getClass().getSimpleName() );
+            }
+            addLabeledRow( tbl, "Cell Size U", subdet.getReadout() != null ? cal.getCellSizeU() + " mm" : "NA" );
+            addLabeledRow( tbl, "Cell Size V", subdet.getReadout() != null ? cal.getCellSizeV() + " mm" : "NA" );
+        }
+    }
+    
+    private static void defines( Element parent, Detector detector )
+    {
+        bookmark( parent, "defines" );
+
+        addHeader2( parent, "Constants" );
+
+        Element tbl = new Element( "table" );
+        tbl.setAttribute( "border", "1" );
+        tbl.setAttribute( "width", "50%" );
+        tbl.setAttribute( "cellpadding", "1" );
+        parent.addContent( tbl );
+
+        // Alpha sort.
+        Map<String, Constant> cmap = detector.getConstants();
+        List<String> constants = new ArrayList<String>( cmap.keySet() );
+        java.util.Collections.sort( constants );
+
+        for ( String key : constants )
+        {
+            addLabeledRow( tbl, key, cmap.get( key ).getValue() );
+        }
+    }
+
+    private static void fields( Element parent, Detector detector )
+    {
+        bookmark( parent, "fields" );
+
+        addHeader2( parent, "Fields" );
+
+        Element tbl = new Element( "table" );
+        parent.addContent( tbl );
+        tbl.setAttribute( "border", "1" );
+        tbl.setAttribute( "width", "50%" );
+
+        for ( Map.Entry<String, Field> entry : detector.getFields().entrySet() )
+        {
+            Field field = entry.getValue();
+            addLabeledRow( tbl, "Field", entry.getKey() );
+            addLabeledRow( tbl, "Type", field.getClass().getSimpleName() );
+            if ( field instanceof Solenoid )
+            {
+                Solenoid solenoid = ( Solenoid ) field;
+                addLabeledRow( tbl, "Inner Field", solenoid.getInnerField()[ 2 ] + " TeV" );
+                addLabeledRow( tbl, "Outer Field", solenoid.getOuterField()[ 2 ] + " TeV" );
+                addLabeledRow( tbl, "Z Max", solenoid.getZMax() + " mm" );
+                addLabeledRow( tbl, "Outer Radius 2", solenoid.getOuterRadius2() + " mm" );
+            }
+        }
+    }
+
+    private static void addHeader2( Element parent, String text )
+    {
+        Element h = new Element( "h2" );
+        h.setText( text );
+        parent.addContent( h );
+    }
+
+    private static Element addLayoutRow( Element tbl )
+    {
+        Element tr = new Element( "tr" );
+        tbl.addContent( tr );
+        Element td = new Element( "td" );
+        tr.addContent( td );
+        return td;
+    }
+
+    
+    private static void addRow( Element table, Object... values )
+    {
+        if ( !table.getName().equals( "table" ) )
+        {
+            throw new RuntimeException( "Element is not a <table>." );
+        }
+
+        Element tr = new Element( "tr" );
+        table.addContent( tr );
+
+        for ( Object value : values )
+        {
+            Element td = new Element( "td" );
+            if ( value instanceof String )
+                td.setText( ( String ) value );
+            else if ( value instanceof Element )
+                td.addContent( ( Element ) value );
+            else
+                td.setText( value.toString() );
+            tr.addContent( td );
+        }
+    }
+
+    private static void addLabeledRow( Element table, String label, Object value )
+    {
+        if ( !table.getName().equals( "table" ) )
+        {
+            throw new RuntimeException( "Element is not a <table>." );
+        }
+
+        Element tr = new Element( "tr" );
+        table.addContent( tr );
+
+        // Label.
+        Element td = new Element( "td" );
+        td.setAttribute( "width", "30%" );
+        Element b = new Element( "b" );
+        td.addContent( b );
+        b.setText( label );
+        tr.addContent( td );
+
+        // Value.
+        td = new Element( "td" );
+        tr.addContent( td );
+        if ( value instanceof String )
+            td.setText( ( String ) value );
+        else if ( value instanceof Element )
+            td.addContent( ( Element ) value );
+        else
+            td.setText( value.toString() );
+    }
+
+    private static void bookmark( Element parent, String text )
+    {
+        Element a = new Element( "a" );
+        a.setAttribute( "name", text );
+        parent.addContent( a );
+    }
+
+    private static class Link extends Element
+    {
+        Link( String label, String url )
+        {
+            super( "a" );
+            this.setAttribute( "href", url );
+            this.setText( label );
+        }
+
+        Link( String url )
+        {
+            super( "a" );
+            this.setAttribute( "href", url );
+            this.setText( url );
+        }
+    }
+}
\ No newline at end of file

GeomConverter/src/org/lcsim/geometry/compact/converter/html
Main.java added at 1.1
diff -N Main.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Main.java	4 Jan 2011 21:59:13 -0000	1.1
@@ -0,0 +1,89 @@
+/**
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: Main.java,v 1.1 2011/01/04 21:59:13 jeremy Exp $
+ */
+package org.lcsim.geometry.compact.converter.html;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.swing.filechooser.FileFilter;
+
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.GeometryReader;
+import org.lcsim.geometry.compact.converter.Converter;
+
+public class Main implements Converter
+{
+    /**
+     * @param args the command line arguments
+     */
+    public static void main( String[] args ) throws Exception
+    {
+        if ( args.length < 1 || args.length > 2 )
+            usage();
+        InputStream in = new BufferedInputStream( new FileInputStream( args[ 0 ] ) );
+        OutputStream out = args.length == 1 ? System.out : new BufferedOutputStream( new FileOutputStream( args[ 1 ] ) );
+        new Main().convert( args[ 0 ], in, out );
+    }
+
+    public Main()
+    {}
+
+    public void convert( String inputFileName, InputStream in, OutputStream out ) throws Exception
+    {
+        // Read in detector.
+        GeometryReader reader = new GeometryReader();
+        Detector detector = reader.read( in );
+
+        // Create the HTML.
+        Element root = HtmlConverter.convert( detector );
+
+        // Create the document.
+        Document doc = new Document();
+        doc.setRootElement( root );
+
+        // Write out the document.
+        XMLOutputter outputter = new XMLOutputter();
+        outputter.setFormat( Format.getPrettyFormat() );
+        outputter.output( doc, out );
+        out.close();
+    }
+
+    private static void usage()
+    {
+        System.out.println( "java " + Main.class.getName() + " <compact> [<html>]" );
+        System.exit( 0 );
+    }
+
+    public FileFilter getFileFilter()
+    {
+        return new HepRepFileFilter();
+    }
+
+    public String getOutputFormat()
+    {
+        return "html";
+    }
+
+    private static class HepRepFileFilter extends FileFilter
+    {
+        public boolean accept( java.io.File file )
+        {
+            return file.isDirectory() || file.getName().endsWith( ".html" );
+        }
+
+        public String getDescription()
+        {
+            return "HTML file (*.html)";
+        }
+    }
+}
\ No newline at end of file
CVSspam 0.2.8