lcsim/src/org/lcsim/util/lcio
diff -N SIOGenericObject.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SIOGenericObject.java 8 Aug 2005 07:15:40 -0000 1.1
@@ -0,0 +1,178 @@
+package org.lcsim.util.lcio;
+
+import hep.lcd.io.sio.SIOInputStream;
+import hep.lcd.io.sio.SIOOutputStream;
+import org.lcsim.event.GenericObject;
+
+import java.io.IOException;
+
+/**
+ *
+ * @author gaede
+ * @version $Id: SIOGenericObject.java,v 1.1 2005/08/08 07:15:40 ngraf 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
+ {
+ read(in,flag,version,nInt,nFloat,nDouble ) ;
+ }
+ */
+
+ 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];
+ }
+
+
+ /** 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;
+ }
+
+ /** 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";
+ }
+
+ /** 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 "";
+ }
+
+
+}