3 added + 4 modified, total 7 files
lcsim/src/org/lcsim/event
diff -u -r1.1 -r1.2
--- GenericObject.java 8 Aug 2005 07:16:19 -0000 1.1
+++ GenericObject.java 9 Aug 2005 01:34:00 -0000 1.2
@@ -8,7 +8,6 @@
public interface GenericObject
{
-
/** Number of integer values stored in this object.
*/
public int getNInt();
@@ -38,18 +37,6 @@
* the lifetime of the object.
*/
public boolean isFixedSize();
-
- /** The type name of the user class (typically the class name)
- * This type name is stored as a collection parameter "TypeName"
- * with every collection of LCGenericObject subclasses.<br>
- *
- */
- public String getTypeName();
-
- /** The description string. A comma separated list of pairs of
- * type identifier, one of 'i','f','d' followed by ':'
- * and an attribute name, e.g. "i:cellId,f:offset,f:gain".
- */
- public String getDataDescription();
+
} // class or interface
lcsim/src/org/lcsim/plugin/browser
diff -N LCGenericObjectTableModel.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ LCGenericObjectTableModel.java 9 Aug 2005 01:34:01 -0000 1.1
@@ -0,0 +1,217 @@
+package org.lcsim.plugin.browser;
+
+import javax.swing.table.AbstractTableModel;
+import java.util.List;
+import java.util.Vector;
+import org.lcsim.event.EventHeader.LCMetaData;
+import org.lcsim.event.GenericObject;
+import org.lcsim.util.lcio.LCIOConstants;
+import org.lcsim.util.lcio.LCIOUtil;
+
+/**
+ * Table model for LCGenericObjects. If the objects are fixed size and have a
+ * valid data description in the collection parameters this is used for
+ * displaying the data. Otherwise the data is displayed in a generic format,
+ * i.e. using nInt, nFloat and nDouble.
+ *
+ * @author gaede
+ * @version $Id: LCGenericObjectTableModel.java,v 1.1 2005/08/09 01:34:01 tonyj Exp $
+ */
+class LCGenericObjectTableModel extends AbstractTableModel implements EventBrowserTableModel
+{
+ private List data;
+ private String[] columns = {"index","nInt","intValues","nFloat","floatValues","nDouble","doubleValues"};
+ private Class[] klasses = { Integer.class, Integer.class , new int[0].getClass(), Integer.class , new float[0].getClass(), Integer.class , new double[0].getClass() };
+ private boolean isFixedSize = false;
+ private int[] indices = null;
+
+ public boolean canDisplay(Class c)
+ {
+ return GenericObject.class.isAssignableFrom(c);
+ }
+ public void setData(LCMetaData meta, List data)
+ {
+ this.data = data;
+ int flags = meta.getFlags();
+
+ String[] desc = meta.getStringParameters().get("DataDescription");
+ isFixedSize = LCIOUtil.bitTest(flags, LCIOConstants.GOBIT_FIXED);
+
+ if( isFixedSize && desc.length != 0 && desc[0].length() != 0 )
+ {
+ // some helper vectors
+ Vector colVec = new Vector() ;
+ Vector klassVec = new Vector() ;
+ Vector indexVec = new Vector() ;
+
+ colVec.add( "index" ) ;
+ klassVec.add( Integer.class ) ;
+
+ try
+ {
+
+ evaluateDataDescription( data, desc[0], colVec, klassVec , indexVec ) ;
+
+ // copy vectors to arrays ...
+ String[] newColumns = new String[ colVec.size() ] ;
+ for(int i=0;i<colVec.size() ;i++)
+ newColumns[i] = (String) colVec.get(i) ;
+ columns = newColumns ;
+
+ Class[] newKlasses = new Class[ klassVec.size() ] ;
+ for(int i=0;i<klassVec.size() ;i++)
+ newKlasses[i] = (Class) klassVec.get(i) ;
+ klasses = newKlasses ;
+
+ indices = new int[ indexVec.size() ] ;
+ for(int i=0;i<indexVec.size() ;i++)
+ indices[i] = ( (Integer) indexVec.get(i) ).intValue() ;
+ }
+ catch( Exception e)
+ {
+ isFixedSize = false ; // sth. went wrong with the data description ...
+ }
+ }
+ else
+ {
+ isFixedSize = false ; // in case ther is no data description ...
+ }
+ fireTableDataChanged();
+ }
+
+ /** Helper method that determines the colums and classes for the table from the data description string */
+ void evaluateDataDescription(List data, String desc, Vector colVec, Vector klassVec, Vector indexVec ) throws Exception
+ {
+
+ int nInt=0, nFloat=0, nDouble=0 ;
+
+ String values[] = desc.split(",") ;
+ for( int i=0 ; i< values.length ; i++)
+ {
+
+ String value[] = values[i].split(":") ;
+
+ if( value[0].equals("i"))
+ {
+ colVec.add( value[1] ) ;
+ klassVec.add( Integer.class ) ;
+ indexVec.add( new Integer( nInt ++ ) ) ;
+ }
+ if( value[0].equals("x"))
+ {
+ colVec.add( value[1] ) ;
+ klassVec.add( String.class ) ; // print hex numbers in table
+ indexVec.add( new Integer( nInt ++ ) ) ;
+ }
+ if( value[0].equals("f"))
+ {
+ colVec.add( value[1] ) ;
+ klassVec.add( Float.class ) ;
+ indexVec.add( new Integer( nFloat ++ ) ) ;
+ }
+ if( value[0].equals("d"))
+ {
+ colVec.add( value[1] ) ;
+ klassVec.add( Double.class ) ;
+ indexVec.add( new Integer( nDouble ++ ) ) ;
+ }
+ }
+
+ // now do some sanity checks:
+
+ GenericObject obj = (GenericObject) data.get(0) ;
+ if( obj.getNInt() != nInt || obj.getNFloat() != nFloat || obj.getNDouble() != nDouble )
+ {
+ throw new Exception("Wrong data description string !"
+ + obj.getNInt()+" : " + nInt
+ + obj.getNFloat()+" : " + nFloat
+ + obj.getNDouble()+" : " + nDouble ) ;
+ }
+ }
+
+ public int getRowCount()
+ {
+ return data == null ? 0 : data.size();
+ }
+ public int getColumnCount()
+ {
+ return columns.length;
+ }
+ public String getColumnName(int index)
+ {
+ return columns[index];
+ }
+ public Class getColumnClass(int index)
+ {
+ return klasses[index];
+ }
+
+ public Object getValueAt(int row, int column)
+ {
+ GenericObject obj = (GenericObject) data.get(row);
+
+ if( isFixedSize )
+ {
+
+ if( column == 0 )
+ return new Integer(row);
+
+ if( klasses[column] == Integer.class )
+ return new Integer( obj.getIntVal( indices[ column-1 ] ) ) ;
+
+ if( klasses[column] == String.class )
+ {
+ String zeros = "0x00000000" ;
+ String hex = Integer.toHexString( obj.getIntVal( indices[ column-1 ] ) ) ;
+ return zeros.substring(0, ( 10 - hex.length() ) ) + hex ;
+ }
+
+ if( klasses[column] == Float.class )
+ return new Float( obj.getFloatVal( indices[ column-1 ] ) );
+
+ if( klasses[column] == Double.class )
+ return new Double( obj.getDoubleVal( indices[ column-1 ] ) ) ;
+
+ }
+ else
+ { // generic format
+
+ switch (column)
+ {
+
+ case 0:
+ return new Integer(row);
+
+ case 1:
+ return new Integer( obj.getNInt() );
+
+ case 2:
+ int[] ints = new int[ obj.getNInt() ] ;
+ for(int i=0;i<obj.getNInt();i++)
+ ints[i] = obj.getIntVal(i) ;
+ return ints ;
+
+ case 3:
+ return new Integer( obj.getNFloat() );
+
+ case 4:
+ float[] floats = new float[ obj.getNFloat() ] ;
+ for(int i=0;i<obj.getNFloat();i++)
+ floats[i] = obj.getFloatVal(i) ;
+ return floats ;
+
+ case 5:
+ return new Integer( obj.getNDouble() );
+
+ case 6:
+ double[] doubles = new double[ obj.getNDouble() ] ;
+ for(int i=0;i<obj.getNDouble();i++)
+ doubles[i] = obj.getDoubleVal(i) ;
+ return doubles ;
+
+ }
+
+ }
+ return " " ;
+ }
+}
lcsim/src/org/lcsim/plugin/browser
diff -u -r1.7 -r1.8
--- LCSimEventBrowser.java 26 Jul 2005 14:44:34 -0000 1.7
+++ LCSimEventBrowser.java 9 Aug 2005 01:34:00 -0000 1.8
@@ -69,6 +69,7 @@
lookup.add(new LCRelationTableModel());
lookup.add(new TrackTableModel());
lookup.add(new ReconstructedParticleTableModel());
+ lookup.add(new LCGenericObjectTableModel());
}
public LCSimEventBrowser(Studio app, SequentialRecordLoop loop)
lcsim/src/org/lcsim/util/lcio
diff -N SIOGenericObjectBlockHandler.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SIOGenericObjectBlockHandler.java 9 Aug 2005 01:34:01 -0000 1.1
@@ -0,0 +1,39 @@
+package org.lcsim.util.lcio;
+
+import hep.lcd.io.sio.SIOInputStream;
+import hep.lcd.io.sio.SIOOutputStream;
+import java.io.IOException;
+
+import org.lcsim.event.GenericObject;
+
+/**
+ *
+ * @author tonyj
+ */
+class SIOGenericObjectBlockHandler extends AbstractBlockHandler
+{
+ public String getType() { return "LCGenericObject"; }
+ public Class getClassForType() { return GenericObject.class; }
+ void addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
+ {
+ int flags = collection.getFlags();
+ if (!LCIOUtil.bitTest(flags,LCIOConstants.GOBIT_FIXED))
+ {
+ int nInt = in.readInt();
+ int nFloat = in.readInt();
+ int nDouble = in.readInt();
+ for (int i = 0; i < n; i++)
+ collection.add(new SIOGenericObject(in, flags, version, nInt, nFloat, nDouble));
+ }
+ else
+ {
+ for (int i = 0; i < n; i++)
+ collection.add(new SIOGenericObject(in, flags, version));
+ }
+ }
+
+ void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
+ {
+ SIOGenericObject.write((GenericObject) element, out, flags);
+ }
+}
lcsim/src/org/lcsim/util/lcio
diff -u -r1.6 -r1.7
--- HandlerManager.java 26 Jul 2005 14:44:34 -0000 1.6
+++ HandlerManager.java 9 Aug 2005 01:34:01 -0000 1.7
@@ -22,7 +22,7 @@
private HandlerManager()
{
// Note: order is important, most specific (e.g. SimCalorimeterHit) must come
- // before less speicifc (e.g. CalorimeterHit).
+ // before less specific (e.g. CalorimeterHit).
register(new SIOSimCalorimeterHitBlockHandler());
register(new SIOSimTrackerHitBlockHandler());
register(new SIOMCParticleBlockHandler());
@@ -34,6 +34,7 @@
register(new SIOLCRelationBlockHandler());
register(new SIOReconstructedParticleBlockHandler());
register(new SIOCalorimeterHitBlockHandler());
+ register(new SIOGenericObjectBlockHandler());
}
static HandlerManager instance()
{
lcsim/src/org/lcsim/util/lcio
diff -u -r1.1 -r1.2
--- SIOGenericObject.java 8 Aug 2005 07:15:40 -0000 1.1
+++ SIOGenericObject.java 9 Aug 2005 01:34:01 -0000 1.2
@@ -9,170 +9,105 @@
/**
*
* @author gaede
- * @version $Id: SIOGenericObject.java,v 1.1 2005/08/08 07:15:40 ngraf Exp $
+ * @version $Id: SIOGenericObject.java,v 1.2 2005/08/09 01:34:01 tonyj Exp $
*/
class SIOGenericObject implements GenericObject
{
- private static int[] nullI = new int[0];
- private static float[] nullF = new float[0];
- private static double[] nullD = new double[0];
-
- protected boolean _isFixedSize ;
- protected int[] _intVec;
- protected float[] _floatVec;
- protected double[] _doubleVec;
-
- // Creates a new instance of SIOGenericObject with variable size
-
- public SIOGenericObject(SIOInputStream in, int flag, int version) throws IOException
- {
- int nInt = nInt = in.readInt();
- int nFloat = in.readInt();
- int nDouble = in.readInt();
- read(in,flag,version,nInt,nFloat,nDouble ) ;
- }
-
-/*
- //Creates a new instance of SIOGenericObject with fixed size
-
- public SIOGenericObject(SIOInputStream in, int flag, int version, int nInt, int nFloat, int nDouble) throws IOException
+ private static int[] nullI = new int[0];
+ private static float[] nullF = new float[0];
+ private static double[] nullD = new double[0];
+
+ private boolean _isFixedSize ;
+ private int[] _intVec;
+ private float[] _floatVec;
+ private double[] _doubleVec;
+
+ // Creates a new instance of SIOGenericObject with variable size
+
+ SIOGenericObject(SIOInputStream in, int flag, int version) throws IOException
{
- read(in,flag,version,nInt,nFloat,nDouble ) ;
+ int nInt = nInt = in.readInt();
+ int nFloat = in.readInt();
+ int nDouble = in.readInt();
+ read(in,flag,version,nInt,nFloat,nDouble);
+ _isFixedSize = false;
+ }
+
+ SIOGenericObject(SIOInputStream in, int flag, int version, int nInt, int nFloat, int nDouble) throws IOException
+ {
+ read(in,flag,version,nInt,nFloat,nDouble);
+ _isFixedSize = true;
+ }
+
+ private void read(SIOInputStream in, int flag, int version, int nInt, int nFloat, int nDouble ) throws IOException
+ {
+ _intVec = new int[nInt] ;
+ for (int i=0; i<nInt; i++)
+ {
+ _intVec[i] = in.readInt();
+ }
+
+ _floatVec = new float[nFloat] ;
+ for (int i=0; i<nFloat; i++)
+ {
+ _floatVec[i] = in.readFloat();
+ }
+
+ _doubleVec = new double[nDouble] ;
+ for (int i=0; i<nDouble; i++)
+ {
+ _doubleVec[i] = in.readDouble();
+ }
+
+ }
+
+ static void write(GenericObject object, SIOOutputStream out, int flag) throws IOException
+ {
+ out.writeInt(object.getNInt());
+ out.writeInt(object.getNFloat());
+ out.writeInt(object.getNDouble());
+
+ for(int i=0;i<object.getNInt();i++)
+ out.writeInt( object.getIntVal(i)) ;
+ for(int i=0;i<object.getNFloat();i++)
+ out.writeFloat( object.getFloatVal(i)) ;
+ for(int i=0;i<object.getNDouble();i++)
+ out.writeDouble( object.getDoubleVal(i)) ;
+
+ out.writePTag(object);
+ }
+ public int getNInt()
+ {
+ return _intVec.length;
}
- */
-
- protected void read(SIOInputStream in, int flag, int version, int nInt, int nFloat, int nDouble ) throws IOException
- {
- _intVec = new int[nInt] ;
- for (int i=0; i<nInt; i++)
- {
- _intVec[i] = in.readInt();
- }
-
- _floatVec = new float[nFloat] ;
- for (int i=0; i<nFloat; i++)
- {
- _floatVec[i] = in.readFloat();
- }
-
- _doubleVec = new double[nDouble] ;
- for (int i=0; i<nDouble; i++)
- {
- _doubleVec[i] = in.readDouble();
- }
-
- }
-
- static void write(GenericObject object, SIOOutputStream out, int flag) throws IOException
- {
- if (object instanceof SIOGenericObject)
- ((SIOGenericObject) object).write(out,flag);
- else
- {
-
- out.writeInt(object.getNInt());
- out.writeInt(object.getNFloat());
- out.writeInt(object.getNDouble());
-
- for(int i=0;i<object.getNInt();i++)
- out.writeInt( object.getIntVal(i)) ;
- for(int i=0;i<object.getNFloat();i++)
- out.writeFloat( object.getFloatVal(i)) ;
- for(int i=0;i<object.getNDouble();i++)
- out.writeDouble( object.getDoubleVal(i)) ;
-
- out.writePTag(object);
- }
- }
- private void write(SIOOutputStream out, int flag) throws IOException
- {
-
- out.writeInt(_intVec.length);
- out.writeInt(_floatVec.length);
- out.writeInt(_doubleVec.length);
-
- for(int i=0;i<_intVec.length;i++)
- out.writeInt( _intVec[i]) ;
- for(int i=0;i<_floatVec.length ;i++)
- out.writeFloat( _floatVec[i] ) ;
- for(int i=0;i<_doubleVec.length;i++)
- out.writeDouble( _doubleVec[i] ) ;
- out.writePTag(this);
- }
-
-
-// GenericObject interface
- /** Number of integer values stored in this object.
- */
- public int getNInt()
- {
- return _intVec.length;
- }
-
- /** Number of float values stored in this object.
- */
- public int getNFloat()
- {
- return _floatVec.length;
- }
-
- /** Number of double values stored in this object.
- */
- public int getNDouble()
- {
- return _doubleVec.length;
- }
-
- /** Returns the integer value for the given index.
- */
- public int getIntVal(int index)
- {
- return _intVec[index];
- }
-
- /** Returns the float value for the given index.
- */
- public float getFloatVal(int index)
- {
- return _floatVec[index];
- }
- /** Returns the double value for the given index.
- */
- public double getDoubleVal(int index)
- {
- return _doubleVec[index];
- }
-
+ public int getNFloat()
+ {
+ return _floatVec.length;
+ }
- /** True if objects of the implementation class have a fixed size, i.e
- * getNInt, getNFloat and getNDouble will return values that are constant during
- * the lifetime of the object.
- */
- public boolean isFixedSize()
- {
- // TODO: fix fixedlength
- return false;
- }
+ public int getNDouble()
+ {
+ return _doubleVec.length;
+ }
- /** The type name of the user class (typically the class name)
- * This type name is stored as a collection parameter "TypeName"
- * with every collection of LCGenericObject subclasses.<br>
- *
- */
- public String getTypeName()
- {
- return "SIOGenericObject";
- }
+ public int getIntVal(int index)
+ {
+ return _intVec[index];
+ }
+
+ public float getFloatVal(int index)
+ {
+ return _floatVec[index];
+ }
+
+ public double getDoubleVal(int index)
+ {
+ return _doubleVec[index];
+ }
- /** The description string. A comma separated list of pairs of
- * type identifier, one of 'i','f','d' followed by ':'
- * and an attribute name, e.g. "i:cellId,f:offset,f:gain".
- */
- public String getDataDescription()
- {
- return "";
- }
-
-
+ public boolean isFixedSize()
+ {
+ return _isFixedSize;
+ }
}
lcsim/src/org/lcsim/plugin/web/examples
diff -N NestedDriverExample.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ NestedDriverExample.java 9 Aug 2005 01:34:01 -0000 1.1
@@ -0,0 +1,29 @@
+package org.lcsim.plugin.web.examples;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+
+public class NestedDriverExample extends Driver
+{
+ public NestedDriverExample()
+ {
+ add(new A());
+ add(new B());
+ }
+ private class A extends Driver
+ {
+ protected void process(EventHeader event)
+ {
+ super.process(event);
+ System.out.println("Hello from a");
+ }
+ }
+ private class B extends Driver
+ {
+ protected void process(EventHeader event)
+ {
+ super.process(event);
+ System.out.println("Hello from b");
+ }
+ }
+}
\ No newline at end of file
CVSspam 0.2.8