GeomConverter/src/org/lcsim/geometry/compact/converter/html
diff -u -r1.4 -r1.5
--- HtmlConverter.java 10 Jan 2011 23:17:58 -0000 1.4
+++ HtmlConverter.java 12 Jan 2011 00:37:53 -0000 1.5
@@ -17,20 +17,26 @@
import org.lcsim.geometry.compact.Segmentation;
import org.lcsim.geometry.compact.Subdetector;
import org.lcsim.geometry.field.Solenoid;
+import org.lcsim.geometry.layer.Layer;
+import org.lcsim.geometry.layer.LayerSlice;
+import org.lcsim.geometry.layer.LayerStack;
import org.lcsim.geometry.subdetector.AbstractLayeredSubdetector;
+import org.lcsim.geometry.subdetector.PolyconeSupport;
+import org.lcsim.geometry.subdetector.TubeSegment;
/**
* Convert a compact description to an html information page.
*
* @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: HtmlConverter.java,v 1.4 2011/01/10 23:17:58 jeremy Exp $
+ * @version $Id: HtmlConverter.java,v 1.5 2011/01/12 00:37:53 jeremy Exp $
*/
// TODO add css
-// TODO add timestamp at bottom including generation date, user name, and compact file
-// used;
-// maybe some of this info should be at top summary
public class HtmlConverter
{
+ static DecimalFormat layerForm = new DecimalFormat( "#.##" );
+ static DecimalFormat lenForm = new DecimalFormat( "#.######" );
+ static DecimalFormat geomForm = new DecimalFormat( "#.##");
+
private HtmlConverter()
{}
@@ -140,19 +146,78 @@
return root;
}
+ private static Element layers( Subdetector subdet )
+ {
+ Element tbl = null;
+ if ( subdet instanceof AbstractLayeredSubdetector )
+ {
+ AbstractLayeredSubdetector layered = ( AbstractLayeredSubdetector ) subdet;
+ LayerStack layers = layered.getLayering().getLayerStack();
+ if ( layers.getNumberOfLayers() > 0 )
+ {
+ tbl = new Element( "table" );
+ tbl.setAttribute( "border", "1" );
+
+ Layer currentLayer = null;
+ int bottomLayer = 0;
+ int topLayer = 0;
+ for ( int i = 0, nlayers = layers.getNumberOfLayers(); i < nlayers; i++ )
+ {
+ if ( currentLayer == null )
+ {
+ currentLayer = layers.getLayer( i );
+ }
+
+ // FIXME Use a better way than thickness to determine if different layer.
+ if ( currentLayer.getThickness() != layers.getLayer( i )
+ .getThickness() || i == nlayers - 1 )
+ {
+ topLayer = i - 1;
+
+ // Special case of only one layer.
+ if ( topLayer == -1 )
+ topLayer = 0;
+
+ Element sliceTbl = new Element( "table" );
+ sliceTbl.setAttribute( "cellpadding", "2" );
+
+ for ( LayerSlice slice : currentLayer.getSlices() )
+ {
+ addRow( sliceTbl,
+ layerForm.format( slice.getThickness() ) + " mm",
+ slice.getMaterial().getName(),
+ slice.isSensitive() ? new Element("i").addContent( "sensor") : " " );
+ }
+
+ addRow( tbl, bottomLayer + " - " + topLayer, sliceTbl );
+
+ bottomLayer = i;
+ topLayer = i;
+ currentLayer = layers.getLayer( i );
+ }
+ }
+ }
+ }
+
+ return tbl;
+ }
+
private static void timestamp( Element parent )
{
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
- String ts = new String( "Generated by GeomConverter at " + sdf.format( cal.getTime() ) + " by user " + System.getProperty( "user.name" ) + "." );
+ String ts = new String( "Generated by GeomConverter at " + sdf.format( cal
+ .getTime() ) + " by user " + System.getProperty( "user.name" ) + "." );
parent.addContent( new Element( "p" ).setText( ts ) );
}
- private static void lengthTable( Element parent, Detector detector, List<String> subdets )
+ private static void lengthTable( Element parent,
+ Detector detector,
+ List<String> subdets )
{
// Header.
- addHeader2( parent, "Radiation and Interaction Lengths Table" );
+ addHeader2( parent, "Radiation and Interaction Lengths" );
Element tbl = new Element( "table" );
parent.addContent( tbl );
@@ -160,9 +225,10 @@
tbl.setAttribute( "cellpadding", "2" );
// Table header row.
- addRow( tbl, new Element( "b" ).setText( "Subdetector" ), new Element( "b" ).setText( "Radiation Lengths" ), new Element( "b" ).setText( "Interaction Lengths" ) );
-
- DecimalFormat dec = new DecimalFormat( "#.######" );
+ addRow( tbl,
+ new Element( "b" ).setText( "Subdetector" ),
+ new Element( "b" ).setText( "Radiation Lengths" ),
+ new Element( "b" ).setText( "Interaction Lengths" ) );
for ( String subdetName : subdets )
{
@@ -171,7 +237,10 @@
if ( subdet instanceof AbstractLayeredSubdetector )
{
layers = ( AbstractLayeredSubdetector ) subdet;
- addRow( tbl, new Link( subdetName, "#" + subdetName ), dec.format( layers.getRadiationLengths() ), dec.format( layers.getInteractionLengths() ) );
+ addRow( tbl,
+ new Link( subdetName, "#" + subdetName ),
+ lenForm.format( layers.getRadiationLengths() ),
+ lenForm.format( layers.getInteractionLengths() ) );
}
}
}
@@ -179,7 +248,7 @@
private static void sysIdIndex( Element parent, Detector detector )
{
// Header.
- addHeader2( parent, "SysId Index" );
+ addHeader2( parent, "Subdetectors by System ID" );
// Table
Element tbl = new Element( "table" );
@@ -188,7 +257,8 @@
parent.addContent( tbl );
// Table header row.
- addRow( tbl, new Element( "b" ).setText( "Sys Id" ), new Element( "b" ).setText( "Subdetector" ) );
+ addRow( tbl, new Element( "b" ).setText( "Sys Id" ), new Element( "b" )
+ .setText( "Subdetector" ) );
// Make system ID list, only including non-zero values.
List<Integer> systemIds = new ArrayList<Integer>();
@@ -211,10 +281,12 @@
}
}
- private static void subdetectorIndex( Element parent, Detector detector, List<String> names )
+ private static void subdetectorIndex( Element parent,
+ Detector detector,
+ List<String> names )
{
// Header.
- addHeader2( parent, "Subdetector Index" );
+ addHeader2( parent, "Components" );
// Table.
Element tbl = new Element( "table" );
@@ -241,7 +313,7 @@
private static void readoutIndex( Element parent, Detector detector )
{
// Header.
- addHeader2( parent, "Readout Index" );
+ addHeader2( parent, "Readouts" );
// Table
Element tbl = new Element( "table" );
@@ -250,10 +322,15 @@
parent.addContent( tbl );
// Table header row.
- addRow( tbl, new Element( "b" ).setText( "Readout" ), new Element( "b" ).setText( "Subdetectors" ) );
+ addRow( tbl,
+ new Element( "b" ).setText( "Readout" ),
+ new Element( "b" ).setText( "Subdetectors" ),
+ new Element( "b" ).setText( "ID Description" ),
+ new Element( "b" ).setText( "Cell Size U x V" ));
// Alpha sort on readout name.
- List<String> readoutNames = new ArrayList<String>( detector.getReadouts().keySet() );
+ List<String> readoutNames = new ArrayList<String>( detector.getReadouts()
+ .keySet() );
java.util.Collections.sort( readoutNames );
// Process Readouts by name.
@@ -276,9 +353,27 @@
span.addContent( new Link( subdetName, "#" + subdetName ) );
}
}
+
+ String cellSizes = "NA";
+ try
+ {
+ if ( readout.getIDDecoder() instanceof Segmentation )
+ {
+ Segmentation seg = (Segmentation) readout.getIDDecoder();
+ cellSizes = seg.getCellSizeU() + " mm x " + seg.getCellSizeV() + " mm";
+ }
+ }
+ catch ( Exception x )
+ {
+ // Ignore.
+ }
// Add row for this Readout.
- addRow( tbl, readout.getName(), span );
+ addRow( tbl,
+ readout.getName(),
+ span,
+ readout.getIDDecoder().getIDDescription().toString(),
+ cellSizes );
}
}
@@ -299,8 +394,12 @@
addLabeledRow( tbl, "Author", header.getAuthor() );
addLabeledRow( tbl, "Status", header.getStatus() );
addLabeledRow( tbl, "Version", header.getVersion() );
- addLabeledRow( tbl, "Documentation", header.getURL().equals("NONE") ? "NONE" : new Link( header.getURL() ) );
- addLabeledRow( tbl, "Zip File", new Link( "http://www.lcsim.org/detectors/" + detector.getName() + ".zip" ) );
+ addLabeledRow( tbl,
+ "Documentation",
+ header.getURL().equals( "NONE" ) ? "NONE" : 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 )
@@ -321,17 +420,19 @@
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, "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" );
+ 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() );
+ addLabeledRow( tbl, "Interaction Lengths", lenForm.format( layers.getInteractionLengths() ) );
+ addLabeledRow( tbl, "Radiation Lengths", lenForm.format( layers.getRadiationLengths() ) );
}
// Calorimeter info.
@@ -340,28 +441,70 @@
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" );
+ addLabeledRow( tbl, "Inner Radius", geomForm.format( cal.getInnerRadius() ) + " mm" );
+ addLabeledRow( tbl, "Outer Radius", geomForm.format( cal.getOuterRadius() ) + " mm" );
+ addLabeledRow( tbl, "Z Length", geomForm.format( cal.getZLength() ) + " mm" );
+ addLabeledRow( tbl, "Inner Z", geomForm.format( cal.getInnerZ() ) + " mm" );
+ addLabeledRow( tbl, "Outer Z", geomForm.format( cal.getOuterZ() ) + " mm" );
+ addLabeledRow( tbl, "Section Phi", geomForm.format( 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() );
}
-
- try
+
+ try
{
- addLabeledRow( tbl, "Cell Size U", subdet.getReadout() != null ? cal.getCellSizeU() + " mm" : "NA" );
- addLabeledRow( tbl, "Cell Size V", subdet.getReadout() != null ? cal.getCellSizeV() + " mm" : "NA" );
+ addLabeledRow( tbl, "Cell Size U", subdet.getReadout() != null ? cal
+ .getCellSizeU() + " mm" : "NA" );
+ addLabeledRow( tbl, "Cell Size V", subdet.getReadout() != null ? cal
+ .getCellSizeV() + " mm" : "NA" );
}
- catch (IndexOutOfBoundsException x)
+ catch ( IndexOutOfBoundsException x )
{
- // This can happen sometimes with a few types of Segmentation that have no cell U/V defined.
+ // This can happen sometimes with a few types of Segmentation that have no
+ // cell U/V defined.
+ }
+
+ // Layering information.
+ if ( subdet.getLayering() != null && subdet.getLayering().getNumberOfLayers() > 0 )
+ {
+ Element layerTbl = layers( subdet );
+
+ addLabeledRow( tbl, "Layers", layerTbl );
}
}
+ else if ( subdet instanceof TubeSegment )
+ {
+ TubeSegment tube = (TubeSegment) subdet;
+ addLabeledRow( tbl, "Inner Radius", geomForm.format( tube.getInnerRadius() ) + " mm" );
+ addLabeledRow( tbl, "Outer Radius", geomForm.format( tube.getOuterRadius() ) + " mm" );
+ addLabeledRow( tbl, "Z Half Length", geomForm.format( tube.getZHalfLength() ) + " mm" );
+ }
+ else if ( subdet instanceof PolyconeSupport )
+ {
+ Element planesTbl = new Element("table");
+ planesTbl.setAttribute( "border", "1" );
+ planesTbl.setAttribute( "cellpadding", "2");
+
+ PolyconeSupport poly = (PolyconeSupport) subdet;
+
+ // Table header row.
+ addRow( planesTbl,
+ new Element( "b" ).setText( "R Min" ),
+ new Element( "b" ).setText( "R Max" ),
+ new Element( "b" ).setText( "Z" ) );
+
+ for ( int i = 0, nplanes = poly.getNumberOfZPlanes(); i < nplanes; i++ )
+ {
+ addRow( planesTbl,
+ geomForm.format( poly.getZPlane( i ).getRMin() ),
+ geomForm.format( poly.getZPlane( i ).getRMax() ),
+ geomForm.format( poly.getZPlane( i ).getZ() ) );
+ }
+
+ addLabeledRow( tbl, "Z Planes", planesTbl );
+ }
}
private static void defines( Element parent, Detector detector )
@@ -443,6 +586,7 @@
for ( Object value : values )
{
Element td = new Element( "td" );
+ td.setAttribute( "valign", "top" );
if ( value instanceof String )
td.setText( ( String ) value );
else if ( value instanceof Element )
@@ -465,7 +609,8 @@
// Label.
Element td = new Element( "td" );
- td.setAttribute( "width", "30%" );
+ td.setAttribute( "width", "25%" );
+ td.setAttribute( "valign", "top" );
Element b = new Element( "b" );
td.addContent( b );
b.setText( label );
@@ -473,6 +618,7 @@
// Value.
td = new Element( "td" );
+ td.setAttribute( "valign", "top" );
tr.addContent( td );
if ( value instanceof String )
td.setText( ( String ) value );
@@ -503,6 +649,6 @@
super( "a" );
this.setAttribute( "href", url );
this.setText( url );
- }
+ }
}
}
\ No newline at end of file